зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 4dfb2d13513f (bug 1264573) because it blocks the backout of bug 1260931. r=backout on a CLOSED TREE
This commit is contained in:
Родитель
31c5f85098
Коммит
2b562296ef
|
@ -19,9 +19,6 @@ support-files =
|
|||
test_firstParty_iframe_http_redirect.html
|
||||
test_firstParty_postMessage.html
|
||||
window.html
|
||||
worker_blobify.js
|
||||
worker_deblobify.js
|
||||
|
||||
[browser_blobURLIsolation.js]
|
||||
[browser_firstPartyIsolation.js]
|
||||
[browser_localStorageIsolation.js]
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
/**
|
||||
* Bug 1264573 - A test case for blob url isolation.
|
||||
*/
|
||||
|
||||
const TEST_PAGE = "http://mochi.test:8888/browser/browser/components/" +
|
||||
"originattributes/test/browser/file_firstPartyBasic.html";
|
||||
const SCRIPT_WORKER_BLOBIFY = "worker_blobify.js";
|
||||
const SCRIPT_WORKER_DEBLOBIFY = "worker_deblobify.js";
|
||||
|
||||
function page_blobify(browser, input) {
|
||||
return ContentTask.spawn(browser, input, function(input) {
|
||||
return { blobURL: content.URL.createObjectURL(new content.Blob([input])) };
|
||||
});
|
||||
}
|
||||
|
||||
function page_deblobify(browser, blobURL) {
|
||||
return ContentTask.spawn(browser, blobURL, function* (blobURL) {
|
||||
if ("error" in blobURL) {
|
||||
return blobURL;
|
||||
}
|
||||
blobURL = blobURL.blobURL;
|
||||
|
||||
function blobURLtoBlob(blobURL) {
|
||||
return new content.Promise(function (resolve) {
|
||||
let xhr = new content.XMLHttpRequest();
|
||||
xhr.open("GET", blobURL, true);
|
||||
xhr.onload = function () {
|
||||
resolve(xhr.response);
|
||||
};
|
||||
xhr.onerror = function () {
|
||||
resolve("xhr error");
|
||||
};
|
||||
xhr.responseType = "blob";
|
||||
xhr.send();
|
||||
});
|
||||
}
|
||||
|
||||
function blobToString(blob) {
|
||||
return new content.Promise(function (resolve) {
|
||||
let fileReader = new content.FileReader();
|
||||
fileReader.onload = function () {
|
||||
resolve(fileReader.result);
|
||||
};
|
||||
fileReader.readAsText(blob);
|
||||
});
|
||||
}
|
||||
|
||||
let blob = yield blobURLtoBlob(blobURL);
|
||||
if (blob == "xhr error") {
|
||||
return "xhr error";
|
||||
}
|
||||
|
||||
return yield blobToString(blob);
|
||||
});
|
||||
}
|
||||
|
||||
function workerIO(browser, scriptFile, message) {
|
||||
return ContentTask.spawn(browser, {scriptFile, message}, function* (args) {
|
||||
let worker = new content.Worker(args.scriptFile);
|
||||
let promise = new content.Promise(function(resolve) {
|
||||
let listenFunction = function(event) {
|
||||
worker.removeEventListener("message", listenFunction, false);
|
||||
worker.terminate();
|
||||
resolve(event.data);
|
||||
};
|
||||
worker.addEventListener("message", listenFunction, false);
|
||||
});
|
||||
worker.postMessage(args.message);
|
||||
return yield promise;
|
||||
});
|
||||
}
|
||||
|
||||
let worker_blobify = (browser, input) => workerIO(browser, SCRIPT_WORKER_BLOBIFY, input);
|
||||
let worker_deblobify = (browser, blobURL) => workerIO(browser, SCRIPT_WORKER_DEBLOBIFY, blobURL);
|
||||
|
||||
let blobURL = null;
|
||||
function doTest(blobify, deblobify) {
|
||||
return function* (browser, tabNum) {
|
||||
if (blobURL === null) {
|
||||
let input = Math.random().toString();
|
||||
blobURL = yield blobify(browser, input);
|
||||
return input;
|
||||
}
|
||||
let result = yield deblobify(browser, blobURL);
|
||||
blobURL = null;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
for (let blobify of [page_blobify, worker_blobify]) {
|
||||
for (let deblobify of [page_deblobify, worker_deblobify]) {
|
||||
IsolationTestTools.runTests(TEST_PAGE, doTest(blobify, deblobify));
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
// Wait for a string to be posted to this worker.
|
||||
// Create a blob containing this string, and then
|
||||
// post back a blob URL pointing to the blob.
|
||||
self.addEventListener("message", function (e) {
|
||||
try {
|
||||
var blobURL = URL.createObjectURL(new Blob([e.data]));
|
||||
postMessage({ blobURL });
|
||||
} catch (e) {
|
||||
postMessage({ error: e.message });
|
||||
}
|
||||
}, false);
|
|
@ -1,31 +0,0 @@
|
|||
// Wait for a blob URL to be posted to this worker.
|
||||
// Obtain the blob, and read the string contained in it.
|
||||
// Post back the string.
|
||||
|
||||
var postStringInBlob = function (blobObject) {
|
||||
var fileReader = new FileReaderSync();
|
||||
var result = fileReader.readAsText(blobObject);
|
||||
postMessage(result);
|
||||
};
|
||||
|
||||
self.addEventListener("message", function (e) {
|
||||
if ("error" in e.data) {
|
||||
postMessage(e.data);
|
||||
return;
|
||||
}
|
||||
var blobURL = e.data.blobURL,
|
||||
xhr = new XMLHttpRequest();
|
||||
try {
|
||||
xhr.open("GET", blobURL, true);
|
||||
xhr.onload = function () {
|
||||
postStringInBlob(xhr.response);
|
||||
};
|
||||
xhr.onerror = function () {
|
||||
postMessage({ error: "xhr error" });
|
||||
};
|
||||
xhr.responseType = "blob";
|
||||
xhr.send();
|
||||
} catch (e) {
|
||||
postMessage({ error: e.message });
|
||||
}
|
||||
}, false);
|
Загрузка…
Ссылка в новой задаче