зеркало из https://github.com/mozilla/gecko-dev.git
Bug 945152 - Part 3-4: Test case to get array buffor by XHR with app:// URL. r=smaug,fabrice
This commit is contained in:
Родитель
56aca5b483
Коммит
c51a85aa74
|
@ -1,8 +1,12 @@
|
||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
support-files =
|
support-files =
|
||||||
asmjs/*
|
asmjs/*
|
||||||
|
file_bug_945152.html
|
||||||
|
file_bug_945152.sjs
|
||||||
|
|
||||||
[test_apps_service.xul]
|
[test_apps_service.xul]
|
||||||
|
[test_bug_945152.html]
|
||||||
|
run-if = os == 'linux'
|
||||||
[test_operator_app_install.js]
|
[test_operator_app_install.js]
|
||||||
[test_operator_app_install.xul]
|
[test_operator_app_install.xul]
|
||||||
# bug 928262
|
# bug 928262
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script>
|
||||||
|
|
||||||
|
var gData1 = "TEST_DATA_1:ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
var gData2 = "TEST_DATA_2:1234567890";
|
||||||
|
var gPaddingChar = '.';
|
||||||
|
var gPaddingSize = 10000;
|
||||||
|
var gPadding = "";
|
||||||
|
|
||||||
|
for (var i = 0; i < gPaddingSize; i++) {
|
||||||
|
gPadding += gPaddingChar;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendMessage(msg) {
|
||||||
|
alert(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ok(p, msg) {
|
||||||
|
if (p)
|
||||||
|
sendMessage("OK: " + msg);
|
||||||
|
else
|
||||||
|
sendMessage("KO: " + msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testXHR(file, data_head, mapped, cb) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('GET', file);
|
||||||
|
xhr.responseType = 'arraybuffer';
|
||||||
|
xhr.onreadystatechange = function xhrReadystatechange() {
|
||||||
|
if (xhr.readyState !== xhr.DONE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (xhr.status && xhr.status == 200) {
|
||||||
|
var ct = xhr.getResponseHeader("Content-Type");
|
||||||
|
if (mapped) {
|
||||||
|
ok(ct.indexOf("mem-mapped") != -1, "Data is memory-mapped");
|
||||||
|
} else {
|
||||||
|
ok(ct.indexOf("mem-mapped") == -1, "Data is not memory-mapped");
|
||||||
|
}
|
||||||
|
var data = xhr.response;
|
||||||
|
ok(data, "Data is non-null");
|
||||||
|
var str = String.fromCharCode.apply(null, Uint8Array(data));
|
||||||
|
ok(str.length == data_head.length + gPaddingSize, "Data size is correct");
|
||||||
|
ok(str.slice(0, data_head.length) == data_head, "Data head is correct");
|
||||||
|
ok(str.slice(data_head.length) == gPadding, "Data padding is correct");
|
||||||
|
cb();
|
||||||
|
} else {
|
||||||
|
ok(false, "XHR error: " + xhr.status + " - " + xhr.statusText + "\n");
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xhr.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Memory-mapped array buffer.
|
||||||
|
function test_mapped() {
|
||||||
|
testXHR('data_1.txt', gData1, true, runTests);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Non memory-mapped array buffer.
|
||||||
|
function test_non_mapped() {
|
||||||
|
// Make sure array buffer retrieved from compressed file in package is
|
||||||
|
// handled by memory allocation instead of memory mapping.
|
||||||
|
testXHR('data_2.txt', gData2, false, runTests);
|
||||||
|
}
|
||||||
|
|
||||||
|
var tests = [
|
||||||
|
test_mapped,
|
||||||
|
test_non_mapped
|
||||||
|
];
|
||||||
|
|
||||||
|
function runTests() {
|
||||||
|
if (!tests.length) {
|
||||||
|
sendMessage("DONE");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var test = tests.shift();
|
||||||
|
test();
|
||||||
|
}
|
||||||
|
|
||||||
|
function go() {
|
||||||
|
ok(true, "Launched app");
|
||||||
|
runTests();
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body onload="go();">
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,115 @@
|
||||||
|
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
||||||
|
|
||||||
|
// From prio.h
|
||||||
|
const PR_RDWR = 0x04;
|
||||||
|
const PR_CREATE_FILE = 0x08;
|
||||||
|
const PR_TRUNCATE = 0x20;
|
||||||
|
|
||||||
|
Cu.import("resource://gre/modules/FileUtils.jsm");
|
||||||
|
Cu.import("resource://gre/modules/NetUtil.jsm");
|
||||||
|
|
||||||
|
var gBasePath = "chrome/dom/apps/tests/";
|
||||||
|
var gAppPath = gBasePath + "file_bug_945152.html";
|
||||||
|
var gData1 = "TEST_DATA_1:ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
var gData2 = "TEST_DATA_2:1234567890";
|
||||||
|
var gPaddingChar = '.';
|
||||||
|
var gPaddingSize = 10000;
|
||||||
|
var gPackageName = "file_bug_945152.zip";
|
||||||
|
var gManifestData = {
|
||||||
|
name: "Testing app",
|
||||||
|
description: "Testing app",
|
||||||
|
package_path: "http://test/chrome/dom/apps/tests/file_bug_945152.sjs?getPackage=1",
|
||||||
|
launch_path: "/index.html",
|
||||||
|
developer: {
|
||||||
|
name: "devname",
|
||||||
|
url: "http://dev.url"
|
||||||
|
},
|
||||||
|
default_locale: "en-US"
|
||||||
|
};
|
||||||
|
|
||||||
|
function handleRequest(request, response) {
|
||||||
|
var query = getQuery(request);
|
||||||
|
|
||||||
|
// Create the packaged app.
|
||||||
|
if ("createApp" in query) {
|
||||||
|
var zipWriter = Cc["@mozilla.org/zipwriter;1"]
|
||||||
|
.createInstance(Ci.nsIZipWriter);
|
||||||
|
var zipFile = FileUtils.getFile("TmpD", [gPackageName]);
|
||||||
|
zipWriter.open(zipFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||||
|
|
||||||
|
var manifest = JSON.stringify(gManifestData);
|
||||||
|
addZipEntry(zipWriter, manifest, "manifest.webapp", Ci.nsIZipWriter.COMPRESSION_BEST);
|
||||||
|
var app = readFile(gAppPath, false);
|
||||||
|
addZipEntry(zipWriter, app, "index.html", Ci.nsIZipWriter.COMPRESSION_BEST);
|
||||||
|
var padding = "";
|
||||||
|
for (var i = 0; i < gPaddingSize; i++) {
|
||||||
|
padding += gPaddingChar;
|
||||||
|
}
|
||||||
|
var data = gData1 + padding;
|
||||||
|
addZipEntry(zipWriter, data, "data_1.txt", Ci.nsIZipWriter.COMPRESSION_NONE);
|
||||||
|
data = gData2 + padding;
|
||||||
|
addZipEntry(zipWriter, data, "data_2.txt", Ci.nsIZipWriter.COMPRESSION_BEST);
|
||||||
|
|
||||||
|
zipWriter.alignStoredFiles(4096);
|
||||||
|
zipWriter.close();
|
||||||
|
|
||||||
|
response.setHeader("Content-Type", "text/html", false);
|
||||||
|
response.write("OK");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we're generating a webapp manifest.
|
||||||
|
if ("getManifest" in query) {
|
||||||
|
response.setHeader("Content-Type", "application/x-web-app-manifest+json", false);
|
||||||
|
response.write(JSON.stringify(gManifestData));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serve the application package.
|
||||||
|
if ("getPackage" in query) {
|
||||||
|
var resource = readFile(gPackageName, true);
|
||||||
|
response.setHeader("Content-Type",
|
||||||
|
"Content-Type: application/java-archive", false);
|
||||||
|
response.write(resource);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
response.setHeader("Content-type", "text-html", false);
|
||||||
|
response.write("KO");
|
||||||
|
}
|
||||||
|
|
||||||
|
function getQuery(request) {
|
||||||
|
var query = {};
|
||||||
|
request.queryString.split('&').forEach(function (val) {
|
||||||
|
var [name, value] = val.split('=');
|
||||||
|
query[name] = unescape(value);
|
||||||
|
});
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
// File and resources helpers
|
||||||
|
|
||||||
|
function addZipEntry(zipWriter, entry, entryName, compression) {
|
||||||
|
var stream = Cc["@mozilla.org/io/string-input-stream;1"]
|
||||||
|
.createInstance(Ci.nsIStringInputStream);
|
||||||
|
stream.setData(entry, entry.length);
|
||||||
|
zipWriter.addEntryStream(entryName, Date.now(),
|
||||||
|
compression, stream, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function readFile(path, fromTmp) {
|
||||||
|
var dir = fromTmp ? "TmpD" : "CurWorkD";
|
||||||
|
var file = Cc["@mozilla.org/file/directory_service;1"]
|
||||||
|
.getService(Ci.nsIProperties)
|
||||||
|
.get(dir, Ci.nsILocalFile);
|
||||||
|
var fstream = Cc["@mozilla.org/network/file-input-stream;1"]
|
||||||
|
.createInstance(Ci.nsIFileInputStream);
|
||||||
|
var split = path.split("/");
|
||||||
|
for(var i = 0; i < split.length; ++i) {
|
||||||
|
file.append(split[i]);
|
||||||
|
}
|
||||||
|
fstream.init(file, -1, 0, 0);
|
||||||
|
var data = NetUtil.readInputStreamToString(fstream, fstream.available());
|
||||||
|
fstream.close();
|
||||||
|
return data;
|
||||||
|
}
|
|
@ -0,0 +1,164 @@
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<!--
|
||||||
|
https://bugzilla.mozilla.org/show_bug.cgi?id=945152
|
||||||
|
-->
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Test for Bug 945152</title>
|
||||||
|
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
|
||||||
|
<script type="application/javascript;version=1.7">
|
||||||
|
|
||||||
|
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
||||||
|
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
|
||||||
|
const gBaseURL = 'http://test/chrome/dom/apps/tests/';
|
||||||
|
const gSJS = gBaseURL + 'file_bug_945152.sjs';
|
||||||
|
var gGenerator = runTest();
|
||||||
|
|
||||||
|
// When using SpecialPowers.autoConfirmAppInstall, it skips the local
|
||||||
|
// installation, and we need this mock to get correct package path.
|
||||||
|
Cu.import("resource://gre/modules/Services.jsm");
|
||||||
|
Cu.import("resource://gre/modules/WebappOSUtils.jsm");
|
||||||
|
var oldWebappOSUtils = WebappOSUtils;
|
||||||
|
WebappOSUtils.getPackagePath = function(aApp) {
|
||||||
|
return aApp.basePath + "/" + aApp.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleTest.registerCleanupFunction(() => {
|
||||||
|
WebappOSUtils = oldWebappOSUtils;
|
||||||
|
});
|
||||||
|
|
||||||
|
function go() {
|
||||||
|
gGenerator.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
function continueTest() {
|
||||||
|
try { gGenerator.next(); }
|
||||||
|
catch (e) { dump("Got exception: " + e + "\n"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
function mozAppsError() {
|
||||||
|
ok(false, "mozApps error: " + this.error.name);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
function xhrError(event, url) {
|
||||||
|
var xhr = event.target;
|
||||||
|
ok(false, "XHR error loading " + url + ": " + xhr.status + " - " +
|
||||||
|
xhr.statusText);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
function xhrAbort(url) {
|
||||||
|
ok(false, "XHR abort loading " + url);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
function runTest() {
|
||||||
|
// Set up.
|
||||||
|
SpecialPowers.setAllAppsLaunchable(true);
|
||||||
|
SpecialPowers.pushPrefEnv({
|
||||||
|
"set": [
|
||||||
|
["dom.mozBrowserFramesEnabled", true],
|
||||||
|
["dom.mapped_arraybuffer.enabled", true]
|
||||||
|
]
|
||||||
|
}, continueTest);
|
||||||
|
yield undefined;
|
||||||
|
|
||||||
|
SpecialPowers.autoConfirmAppInstall(continueTest);
|
||||||
|
yield undefined;
|
||||||
|
|
||||||
|
// Create app on server side.
|
||||||
|
createApp(continueTest);
|
||||||
|
yield undefined;
|
||||||
|
|
||||||
|
// Install app.
|
||||||
|
var app;
|
||||||
|
navigator.mozApps.mgmt.oninstall = function(e) {
|
||||||
|
ok(true, "Got oninstall event");
|
||||||
|
app = e.application;
|
||||||
|
app.ondownloaderror = mozAppsError;
|
||||||
|
app.ondownloadsuccess = continueTest;
|
||||||
|
};
|
||||||
|
|
||||||
|
var req = navigator.mozApps.installPackage(gSJS + '?getManifest=1');
|
||||||
|
req.onerror = mozAppsError;
|
||||||
|
req.onsuccess = function() {
|
||||||
|
ok(true, "Application installed");
|
||||||
|
};
|
||||||
|
yield undefined;
|
||||||
|
|
||||||
|
// Launch app.
|
||||||
|
launchApp(app, continueTest);
|
||||||
|
yield undefined;
|
||||||
|
|
||||||
|
// Uninstall app.
|
||||||
|
var req = navigator.mozApps.mgmt.uninstall(app);
|
||||||
|
req.onerror = mozAppsError;
|
||||||
|
req.onsuccess = continueTest;
|
||||||
|
yield undefined;
|
||||||
|
|
||||||
|
// All done.
|
||||||
|
ok(true, "All done");
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
function createApp(cb) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
var url = gSJS + '?createApp=1';
|
||||||
|
xhr.addEventListener("load", function() { is(xhr.responseText, "OK", "createApp OK"); cb(); });
|
||||||
|
xhr.addEventListener("error", event => xhrError(event, url));
|
||||||
|
xhr.addEventListener("abort", event => xhrAbort(url));
|
||||||
|
xhr.open('GET', url, true);
|
||||||
|
xhr.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
function launchApp(app, cb) {
|
||||||
|
// Set up the app.
|
||||||
|
var ifr = document.createElement('iframe');
|
||||||
|
ifr.setAttribute('mozbrowser', 'true');
|
||||||
|
ifr.setAttribute('mozapp', app.manifestURL);
|
||||||
|
ifr.setAttribute('src', app.origin + app.manifest.launch_path);
|
||||||
|
var domParent = document.getElementById('container');
|
||||||
|
|
||||||
|
// Set us up to listen for messages from the app.
|
||||||
|
var listener = function(e) {
|
||||||
|
var message = e.detail.message;
|
||||||
|
if (/OK/.exec(message)) {
|
||||||
|
ok(true, "Message from app: " + message);
|
||||||
|
} else if (/KO/.exec(message)) {
|
||||||
|
ok(false, "Message from app: " + message);
|
||||||
|
} else if (/DONE/.exec(message)) {
|
||||||
|
ok(true, "Messaging from app complete");
|
||||||
|
ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
|
||||||
|
domParent.removeChild(ifr);
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This event is triggered when the app calls "alert".
|
||||||
|
ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
|
||||||
|
|
||||||
|
// Add the iframe to the DOM, triggering the launch.
|
||||||
|
domParent.appendChild(ifr);
|
||||||
|
}
|
||||||
|
|
||||||
|
function finish() {
|
||||||
|
SimpleTest.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body onload="go()">
|
||||||
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=945152">Mozilla Bug 945152</a>
|
||||||
|
<p id="display"></p>
|
||||||
|
<div id="content" style="display: none">
|
||||||
|
</div>
|
||||||
|
<pre id="test">
|
||||||
|
</pre>
|
||||||
|
<div id="container"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
Загрузка…
Ссылка в новой задаче