mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-24 02:35:41 +00:00
5dec0e0beb
This patch was autogenerated by my decomponents.py It covers almost every file with the extension js, jsm, html, py, xhtml, or xul. It removes blank lines after removed lines, when the removed lines are preceded by either blank lines or the start of a new block. The "start of a new block" is defined fairly hackily: either the line starts with //, ends with */, ends with {, <![CDATA[, """ or '''. The first two cover comments, the third one covers JS, the fourth covers JS embedded in XUL, and the final two cover JS embedded in Python. This also applies if the removed line was the first line of the file. It covers the pattern matching cases like "var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;". It'll remove the entire thing if they are all either Ci, Cr, Cc or Cu, or it will remove the appropriate ones and leave the residue behind. If there's only one behind, then it will turn it into a normal, non-pattern matching variable definition. (For instance, "const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components" becomes "const CC = Components.Constructor".) MozReview-Commit-ID: DeSHcClQ7cG --HG-- extra : rebase_source : d9c41878036c1ef7766ef5e91a7005025bc1d72b
132 lines
4.1 KiB
JavaScript
132 lines
4.1 KiB
JavaScript
let Cm = Components.manager;
|
|
|
|
let swm = Cc["@mozilla.org/serviceworkers/manager;1"].
|
|
getService(Ci.nsIServiceWorkerManager);
|
|
|
|
const URI = "https://example.com/browser/dom/serviceworkers/test/empty.html";
|
|
const MOCK_CID = Components.ID("{2a0f83c4-8818-4914-a184-f1172b4eaaa7}");
|
|
const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1";
|
|
const USER_CONTEXT_ID = 3
|
|
|
|
let mockAlertsService = {
|
|
showAlert: function(alert, alertListener) {
|
|
ok(true, "Showing alert");
|
|
setTimeout(function () {
|
|
alertListener.observe(null, "alertshow", alert.cookie);
|
|
}, 100);
|
|
setTimeout(function () {
|
|
alertListener.observe(null, "alertclickcallback", alert.cookie);
|
|
}, 100);
|
|
},
|
|
|
|
showAlertNotification: function(imageUrl, title, text, textClickable,
|
|
cookie, alertListener, name, dir, lang, data) {
|
|
this.showAlert();
|
|
},
|
|
|
|
QueryInterface: function(aIID) {
|
|
if (aIID.equals(Ci.nsISupports) || aIID.equals(Ci.nsIAlertsService)) {
|
|
return this;
|
|
}
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
},
|
|
|
|
createInstance: function(aOuter, aIID) {
|
|
if (aOuter != null) {
|
|
throw Cr.NS_ERROR_NO_AGGREGATION;
|
|
}
|
|
return this.QueryInterface(aIID);
|
|
}
|
|
};
|
|
|
|
registerCleanupFunction(() => {
|
|
Cm.QueryInterface(Ci.nsIComponentRegistrar).
|
|
unregisterFactory(MOCK_CID, mockAlertsService);
|
|
});
|
|
|
|
add_task(async function setup() {
|
|
// make sure userContext, SW and notifications are enabled.
|
|
await SpecialPowers.pushPrefEnv({"set": [
|
|
["privacy.userContext.enabled", true],
|
|
["dom.serviceWorkers.exemptFromPerDomainMax", true],
|
|
["dom.serviceWorkers.enabled", true],
|
|
["dom.serviceWorkers.testing.enabled", true],
|
|
["dom.webnotifications.workers.enabled", true],
|
|
["dom.webnotifications.serviceworker.enabled", true],
|
|
["notification.prompt.testing", true],
|
|
["dom.serviceWorkers.disable_open_click_delay", 1000],
|
|
["dom.serviceWorkers.idle_timeout", 299999],
|
|
["dom.serviceWorkers.idle_extended_timeout", 299999],
|
|
["browser.link.open_newwindow", 3],
|
|
]});
|
|
});
|
|
|
|
add_task(async function test() {
|
|
Cm.QueryInterface(Ci.nsIComponentRegistrar).
|
|
registerFactory(MOCK_CID, "alerts service", ALERTS_SERVICE_CONTRACT_ID,
|
|
mockAlertsService);
|
|
|
|
// open the tab in the correct userContextId
|
|
let tab = BrowserTestUtils.addTab(gBrowser, URI, {userContextId: USER_CONTEXT_ID});
|
|
let browser = gBrowser.getBrowserForTab(tab);
|
|
|
|
// select tab and make sure its browser is focused
|
|
gBrowser.selectedTab = tab;
|
|
tab.ownerGlobal.focus();
|
|
|
|
// wait for tab load
|
|
await BrowserTestUtils.browserLoaded(gBrowser.getBrowserForTab(tab));
|
|
|
|
// Waiting for new tab.
|
|
let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, null, true);
|
|
|
|
// here the test.
|
|
let uci = await ContentTask.spawn(browser, URI, uri => {
|
|
let uci = content.document.nodePrincipal.userContextId;
|
|
|
|
// Registration of the SW
|
|
return content.navigator.serviceWorker.register("file_userContextId_openWindow.js")
|
|
|
|
// Activation
|
|
.then(swr => {
|
|
return new content.window.Promise(resolve => {
|
|
let worker = swr.installing;
|
|
worker.addEventListener('statechange', () => {
|
|
if (worker.state === 'activated') {
|
|
resolve(swr);
|
|
}
|
|
});
|
|
});
|
|
})
|
|
|
|
// Ask for an openWindow.
|
|
.then(swr => {
|
|
swr.showNotification("testPopup");
|
|
return uci;
|
|
});
|
|
});
|
|
|
|
is(uci, USER_CONTEXT_ID, "Tab runs with UCI " + USER_CONTEXT_ID);
|
|
|
|
let newTab = await newTabPromise;
|
|
|
|
is(newTab.getAttribute("usercontextid"), USER_CONTEXT_ID, "New tab has UCI equal " + USER_CONTEXT_ID);
|
|
|
|
// wait for SW unregistration
|
|
uci = await ContentTask.spawn(browser, null, () => {
|
|
let uci = content.document.nodePrincipal.userContextId;
|
|
|
|
return content.navigator.serviceWorker.getRegistration(".").then(registration => {
|
|
return registration.unregister();
|
|
})
|
|
.then(() => {
|
|
return uci;
|
|
});
|
|
});
|
|
|
|
is(uci, USER_CONTEXT_ID, "Tab runs with UCI " + USER_CONTEXT_ID);
|
|
|
|
await BrowserTestUtils.removeTab(newTab);
|
|
await BrowserTestUtils.removeTab(tab);
|
|
});
|