зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1515989 - Fix this test to use the service worker manager in the parent. r=asuth
I would have loved to get rid of ServiceWorkerContainer.getScopeForUrl in favor of just doing things in the chrome script, but it's a pain to make it work in both the parent-intercept and non- cases. Once we get rid of non-parent-intercept, we should just remove this test-only API. Differential Revision: https://phabricator.services.mozilla.com/D15218 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
9292b73037
Коммит
1ee3f7ba6b
|
@ -66,7 +66,39 @@
|
|||
|
||||
function testScopes() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var getScope = navigator.serviceWorker.getScopeForUrl.bind(navigator.serviceWorker);
|
||||
function chromeScriptSource() {
|
||||
let swm = Cc["@mozilla.org/serviceworkers/manager;1"]
|
||||
.getService(Ci.nsIServiceWorkerManager);
|
||||
let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"]
|
||||
.getService(Ci.nsIScriptSecurityManager);
|
||||
addMessageListener("getScope", (msg) => {
|
||||
let principal = secMan.createCodebasePrincipalFromOrigin(msg.principal);
|
||||
try {
|
||||
return { scope: swm.getScopeForUrl(principal, msg.path) };
|
||||
} catch (e) {
|
||||
return { exception: e.message };
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let getScope;
|
||||
let parent_intercept_enabled =
|
||||
SpecialPowers.getBoolPref("dom.serviceWorkers.parent_intercept");
|
||||
|
||||
if (parent_intercept_enabled) {
|
||||
let chromeScript = SpecialPowers.loadChromeScript(chromeScriptSource);
|
||||
let docPrincipal = SpecialPowers.wrap(document).nodePrincipal.URI.spec;
|
||||
|
||||
getScope = (path) => {
|
||||
let rv = chromeScript.sendSyncMessage("getScope", { principal: docPrincipal, path })[0][0];
|
||||
if (rv.exception)
|
||||
throw rv.exception;
|
||||
return rv.scope;
|
||||
};
|
||||
} else {
|
||||
getScope = navigator.serviceWorker.getScopeForUrl.bind(navigator.serviceWorker);
|
||||
}
|
||||
|
||||
var base = new URL(".", document.baseURI);
|
||||
|
||||
function p(s) {
|
||||
|
@ -82,13 +114,13 @@
|
|||
}
|
||||
}
|
||||
|
||||
ok(getScope(p("sub.html")) === p("sub"), "Scope should match");
|
||||
ok(getScope(p("sub/dir.html")) === p("sub/dir.html"), "Scope should match");
|
||||
ok(getScope(p("sub/dir")) === p("sub/dir"), "Scope should match");
|
||||
ok(getScope(p("sub/dir/foo")) === p("sub/dir/"), "Scope should match");
|
||||
ok(getScope(p("sub/dir/afoo")) === p("sub/dir/a"), "Scope should match");
|
||||
ok(getScope(p("star*wars")) === p("star*"), "Scope should match");
|
||||
ok(getScope(p("scope/some_file.html")) === p("scope/"), "Scope should match");
|
||||
is(getScope(p("sub.html")), p("sub"), "Scope should match");
|
||||
is(getScope(p("sub/dir.html")), p("sub/dir.html"), "Scope should match");
|
||||
is(getScope(p("sub/dir")), p("sub/dir"), "Scope should match");
|
||||
is(getScope(p("sub/dir/foo")), p("sub/dir/"), "Scope should match");
|
||||
is(getScope(p("sub/dir/afoo")), p("sub/dir/a"), "Scope should match");
|
||||
is(getScope(p("star*wars")), p("star*"), "Scope should match");
|
||||
is(getScope(p("scope/some_file.html")), p("scope/"), "Scope should match");
|
||||
fail("index.html");
|
||||
fail("sua.html");
|
||||
fail("star/a.html");
|
||||
|
|
Загрузка…
Ссылка в новой задаче