mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Backed out changeset a422cac07967 (bug 1612519) for ESlint failure at browser/components/originattributes/test/browser/worker_blobify.js
This commit is contained in:
parent
167432e4c6
commit
1b1308abac
@ -59,6 +59,7 @@ support-files =
|
||||
window3.html
|
||||
window_redirect.html
|
||||
worker_blobify.js
|
||||
worker_deblobify.js
|
||||
!/toolkit/content/tests/browser/common/mockTransfer.js
|
||||
|
||||
[browser_broadcastChannel.js]
|
||||
|
@ -6,6 +6,7 @@ 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 SpecialPowers.spawn(browser, [input], function(contentInput) {
|
||||
@ -58,35 +59,28 @@ function page_deblobify(browser, blobURL) {
|
||||
});
|
||||
}
|
||||
|
||||
function workerIO(browser, what, message) {
|
||||
return SpecialPowers.spawn(
|
||||
browser,
|
||||
[
|
||||
{
|
||||
scriptFile: SCRIPT_WORKER_BLOBIFY,
|
||||
message: { message, what },
|
||||
},
|
||||
],
|
||||
function(args) {
|
||||
if (!content.worker) {
|
||||
content.worker = new content.Worker(args.scriptFile);
|
||||
}
|
||||
let promise = new content.Promise(function(resolve) {
|
||||
let listenFunction = function(event) {
|
||||
content.worker.removeEventListener("message", listenFunction);
|
||||
resolve(event.data);
|
||||
};
|
||||
content.worker.addEventListener("message", listenFunction);
|
||||
});
|
||||
content.worker.postMessage(args.message);
|
||||
return promise;
|
||||
}
|
||||
);
|
||||
function workerIO(browser, scriptFile, message) {
|
||||
return SpecialPowers.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);
|
||||
worker.terminate();
|
||||
resolve(event.data);
|
||||
};
|
||||
worker.addEventListener("message", listenFunction);
|
||||
});
|
||||
worker.postMessage(args.message);
|
||||
return promise;
|
||||
});
|
||||
}
|
||||
|
||||
let worker_blobify = (browser, input) => workerIO(browser, "blobify", input);
|
||||
let worker_blobify = (browser, input) =>
|
||||
workerIO(browser, SCRIPT_WORKER_BLOBIFY, input);
|
||||
let worker_deblobify = (browser, blobURL) =>
|
||||
workerIO(browser, "deblobify", blobURL);
|
||||
workerIO(browser, SCRIPT_WORKER_DEBLOBIFY, blobURL);
|
||||
|
||||
function doTest(blobify, deblobify) {
|
||||
let blobURL = null;
|
||||
|
@ -1,49 +1,11 @@
|
||||
// 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.
|
||||
|
||||
/* eslint-env worker */
|
||||
|
||||
var postStringInBlob = function(blobObject) {
|
||||
var fileReader = new FileReaderSync();
|
||||
var result = fileReader.readAsText(blobObject);
|
||||
postMessage(result);
|
||||
};
|
||||
|
||||
self.addEventListener("message", e => {
|
||||
if (e.data.what === "blobify") {
|
||||
try {
|
||||
var blobURL = URL.createObjectURL(new Blob([e.data.message]));
|
||||
postMessage({ blobURL });
|
||||
} catch (e) {
|
||||
postMessage({ error: e.message });
|
||||
}
|
||||
return;
|
||||
self.addEventListener("message", function(message) {
|
||||
try {
|
||||
var blobURL = URL.createObjectURL(new Blob([message.data]));
|
||||
postMessage({ blobURL });
|
||||
} catch (e) {
|
||||
postMessage({ error: e.message });
|
||||
}
|
||||
|
||||
if (e.data.what === "deblobify") {
|
||||
if ("error" in e.data.message) {
|
||||
postMessage(e.data.message);
|
||||
return;
|
||||
}
|
||||
var blobURL = e.data.message.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 });
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
postMessage("Invalid operation!");
|
||||
});
|
||||
|
@ -0,0 +1,33 @@
|
||||
// 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.
|
||||
|
||||
/* eslint-env worker */
|
||||
|
||||
var postStringInBlob = function(blobObject) {
|
||||
var fileReader = new FileReaderSync();
|
||||
var result = fileReader.readAsText(blobObject);
|
||||
postMessage(result);
|
||||
};
|
||||
|
||||
self.addEventListener("message", function(message) {
|
||||
if ("error" in message.data) {
|
||||
postMessage(message.data);
|
||||
return;
|
||||
}
|
||||
var blobURL = message.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 });
|
||||
}
|
||||
});
|
@ -48,6 +48,24 @@ class CreateURLRunnable : public WorkerMainThreadRunnable {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mWorkerPrivate->IsSharedWorker() &&
|
||||
!mWorkerPrivate->IsServiceWorker()) {
|
||||
// Walk up to top worker object.
|
||||
WorkerPrivate* wp = mWorkerPrivate;
|
||||
while (WorkerPrivate* parent = wp->GetParent()) {
|
||||
wp = parent;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIScriptContext> sc = wp->GetScriptContext();
|
||||
// We could not have a ScriptContext in JSM code. In this case, we leak.
|
||||
if (sc) {
|
||||
nsCOMPtr<nsIGlobalObject> global = sc->GetGlobalObject();
|
||||
MOZ_ASSERT(global);
|
||||
|
||||
global->RegisterHostObjectURI(url);
|
||||
}
|
||||
}
|
||||
|
||||
mURL = NS_ConvertUTF8toUTF16(url);
|
||||
return true;
|
||||
}
|
||||
@ -81,6 +99,24 @@ class RevokeURLRunnable : public WorkerMainThreadRunnable {
|
||||
BlobURLProtocolHandler::RemoveDataEntry(url);
|
||||
}
|
||||
|
||||
if (!mWorkerPrivate->IsSharedWorker() &&
|
||||
!mWorkerPrivate->IsServiceWorker()) {
|
||||
// Walk up to top worker object.
|
||||
WorkerPrivate* wp = mWorkerPrivate;
|
||||
while (WorkerPrivate* parent = wp->GetParent()) {
|
||||
wp = parent;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIScriptContext> sc = wp->GetScriptContext();
|
||||
// We could not have a ScriptContext in JSM code. In this case, we leak.
|
||||
if (sc) {
|
||||
nsCOMPtr<nsIGlobalObject> global = sc->GetGlobalObject();
|
||||
MOZ_ASSERT(global);
|
||||
|
||||
global->UnregisterHostObjectURI(url);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@ -127,10 +163,12 @@ void URLWorker::CreateObjectURL(const GlobalObject& aGlobal, Blob& aBlob,
|
||||
return;
|
||||
}
|
||||
|
||||
WorkerGlobalScope* scope = workerPrivate->GlobalScope();
|
||||
MOZ_ASSERT(scope);
|
||||
if (workerPrivate->IsSharedWorker() || workerPrivate->IsServiceWorker()) {
|
||||
WorkerGlobalScope* scope = workerPrivate->GlobalScope();
|
||||
MOZ_ASSERT(scope);
|
||||
|
||||
scope->RegisterHostObjectURI(NS_ConvertUTF16toUTF8(aResult));
|
||||
scope->RegisterHostObjectURI(NS_ConvertUTF16toUTF8(aResult));
|
||||
}
|
||||
}
|
||||
|
||||
/* static */
|
||||
@ -147,10 +185,12 @@ void URLWorker::RevokeObjectURL(const GlobalObject& aGlobal,
|
||||
return;
|
||||
}
|
||||
|
||||
WorkerGlobalScope* scope = workerPrivate->GlobalScope();
|
||||
MOZ_ASSERT(scope);
|
||||
if (workerPrivate->IsSharedWorker() || workerPrivate->IsServiceWorker()) {
|
||||
WorkerGlobalScope* scope = workerPrivate->GlobalScope();
|
||||
MOZ_ASSERT(scope);
|
||||
|
||||
scope->UnregisterHostObjectURI(NS_ConvertUTF16toUTF8(aUrl));
|
||||
scope->UnregisterHostObjectURI(NS_ConvertUTF16toUTF8(aUrl));
|
||||
}
|
||||
}
|
||||
|
||||
/* static */
|
||||
|
@ -0,0 +1,4 @@
|
||||
[url-lifetime.html]
|
||||
[Terminating worker revokes its URLs]
|
||||
expected: FAIL
|
||||
|
Loading…
Reference in New Issue
Block a user