mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 930924 - Open workers from xpcshell. r=bent
This commit is contained in:
parent
2fa356509c
commit
6bd6992253
@ -3584,11 +3584,37 @@ WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindow* aWindow,
|
||||
// that is creating us in order for us to use relative URIs later on.
|
||||
JS::RootedScript script(aCx);
|
||||
if (JS_DescribeScriptedCaller(aCx, &script, nullptr)) {
|
||||
rv = NS_NewURI(getter_AddRefs(loadInfo.mBaseURI),
|
||||
JS_GetScriptFilename(aCx, script));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
const char* fileName = JS_GetScriptFilename(aCx, script);
|
||||
|
||||
// In most cases, fileName is URI. In a few other cases
|
||||
// (e.g. xpcshell), fileName is a file path. Ideally, we would
|
||||
// prefer testing whether fileName parses as an URI and fallback
|
||||
// to file path in case of error, but Windows file paths have
|
||||
// the interesting property that they can be parsed as bogus
|
||||
// URIs (e.g. C:/Windows/Tmp is interpreted as scheme "C",
|
||||
// hostname "Windows", path "Tmp"), which defeats this algorithm.
|
||||
// Therefore, we adopt the opposite convention.
|
||||
nsCOMPtr<nsIFile> scriptFile =
|
||||
do_CreateInstance("@mozilla.org/file/local;1", &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = scriptFile->InitWithPath(NS_ConvertUTF8toUTF16(fileName));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = NS_NewFileURI(getter_AddRefs(loadInfo.mBaseURI),
|
||||
scriptFile);
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
// As expected, fileName is not a path, so proceed with
|
||||
// a uri.
|
||||
rv = NS_NewURI(getter_AddRefs(loadInfo.mBaseURI),
|
||||
fileName);
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
loadInfo.mXHRParamsAllowed = true;
|
||||
}
|
||||
|
||||
|
@ -13,3 +13,4 @@ MOCHITEST_MANIFESTS += ['mochitest.ini']
|
||||
|
||||
MOCHITEST_CHROME_MANIFESTS += ['chrome.ini']
|
||||
|
||||
XPCSHELL_TESTS_MANIFESTS += ['xpcshell/xpcshell.ini']
|
||||
|
1
dom/workers/test/xpcshell/data/chrome.manifest
Normal file
1
dom/workers/test/xpcshell/data/chrome.manifest
Normal file
@ -0,0 +1 @@
|
||||
content workers ./
|
7
dom/workers/test/xpcshell/data/worker.js
Normal file
7
dom/workers/test/xpcshell/data/worker.js
Normal file
@ -0,0 +1,7 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
|
||||
self.onmessage = function(msg) {
|
||||
self.postMessage("OK");
|
||||
};
|
44
dom/workers/test/xpcshell/test_workers.js
Normal file
44
dom/workers/test/xpcshell/test_workers.js
Normal file
@ -0,0 +1,44 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
Components.utils.import("resource://gre/modules/Promise.jsm");
|
||||
|
||||
// Worker must be loaded from a chrome:// uri, not a file://
|
||||
// uri, so we first need to load it.
|
||||
let WORKER_SOURCE_URI = "chrome://workers/content/worker.js";
|
||||
do_load_manifest("data/chrome.manifest");
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
function talk_with_worker(worker) {
|
||||
let deferred = Promise.defer();
|
||||
worker.onmessage = function(event) {
|
||||
let success = true;
|
||||
if (event.data == "OK") {
|
||||
deferred.resolve();
|
||||
} else {
|
||||
success = false;
|
||||
deferred.reject(event);
|
||||
}
|
||||
do_check_true(success);
|
||||
worker.terminate();
|
||||
};
|
||||
worker.onerror = function(event) {
|
||||
let error = new Error(event.message, event.filename, event.lineno);
|
||||
worker.terminate();
|
||||
deferred.reject(error);
|
||||
};
|
||||
worker.postMessage("START");
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
add_task(function test_chrome_worker() {
|
||||
return talk_with_worker(new ChromeWorker(WORKER_SOURCE_URI));
|
||||
});
|
||||
|
||||
add_task(function test_worker() {
|
||||
return talk_with_worker(new Worker(WORKER_SOURCE_URI));
|
||||
});
|
8
dom/workers/test/xpcshell/xpcshell.ini
Normal file
8
dom/workers/test/xpcshell/xpcshell.ini
Normal file
@ -0,0 +1,8 @@
|
||||
[DEFAULT]
|
||||
head =
|
||||
tail =
|
||||
support-files =
|
||||
data/worker.js
|
||||
data/chrome.manifest
|
||||
|
||||
[test_workers.js]
|
Loading…
Reference in New Issue
Block a user