зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1450073 - Add integration tests for the application panel;r=ladybenko,nchevobbe
MozReview-Commit-ID: 5rkFr7Fvshz --HG-- extra : rebase_source : f5ef3aeb11cb35ed868ea1e5797f3ab1a5d296c6
This commit is contained in:
Родитель
4e050f75ee
Коммит
cbcb31d0c1
|
@ -10,3 +10,5 @@ DevToolsModules(
|
||||||
'application.css',
|
'application.css',
|
||||||
'panel.js'
|
'panel.js'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
BROWSER_CHROME_MANIFESTS += ['test/browser.ini']
|
||||||
|
|
|
@ -31,6 +31,7 @@ class ApplicationPanel {
|
||||||
toolbox: this.toolbox,
|
toolbox: this.toolbox,
|
||||||
panel: this,
|
panel: this,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.emit("ready");
|
this.emit("ready");
|
||||||
this.isReady = true;
|
this.isReady = true;
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
// Extend from the shared list of defined globals for mochitests.
|
||||||
|
"extends": "../../../.eslintrc.mochitests.js"
|
||||||
|
};
|
|
@ -0,0 +1,14 @@
|
||||||
|
[DEFAULT]
|
||||||
|
tags = devtools
|
||||||
|
subsuite = devtools
|
||||||
|
support-files =
|
||||||
|
head.js
|
||||||
|
service-workers/dynamic-registration.html
|
||||||
|
service-workers/empty-sw.js
|
||||||
|
service-workers/scope-page.html
|
||||||
|
service-workers/simple.html
|
||||||
|
!/devtools/client/shared/test/frame-script-utils.js
|
||||||
|
!/devtools/client/shared/test/shared-head.js
|
||||||
|
|
||||||
|
[browser_application_panel_list-several-workers.js]
|
||||||
|
[browser_application_panel_list-single-worker.js]
|
|
@ -0,0 +1,48 @@
|
||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that the application panel can display several service workers applying to the
|
||||||
|
* same domain.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const SIMPLE_URL = URL_ROOT + "service-workers/simple.html";
|
||||||
|
const OTHER_SCOPE_URL = URL_ROOT + "service-workers/scope-page.html";
|
||||||
|
|
||||||
|
add_task(async function() {
|
||||||
|
await enableApplicationPanel();
|
||||||
|
|
||||||
|
let { panel, target } = await openNewTabAndApplicationPanel(SIMPLE_URL);
|
||||||
|
let doc = panel.panelWin.document;
|
||||||
|
|
||||||
|
info("Wait until the service worker appears in the application panel");
|
||||||
|
await waitUntil(() => getWorkerContainers(doc).length === 1);
|
||||||
|
|
||||||
|
info("Wait until the unregister button is displayed for the service worker");
|
||||||
|
await waitUntil(() => getWorkerContainers(doc)[0].querySelector(".unregister-button"));
|
||||||
|
|
||||||
|
ok(true, "First service worker registration is displayed");
|
||||||
|
|
||||||
|
info("Navigate to another page for the same domain with another service worker");
|
||||||
|
await navigate(target, OTHER_SCOPE_URL);
|
||||||
|
|
||||||
|
info("Wait until the service worker appears in the application panel");
|
||||||
|
await waitUntil(() => getWorkerContainers(doc).length === 2);
|
||||||
|
|
||||||
|
info("Wait until the unregister button is displayed for the service worker");
|
||||||
|
await waitUntil(() => getWorkerContainers(doc)[1].querySelector(".unregister-button"));
|
||||||
|
|
||||||
|
ok(true, "Second service worker registration is displayed");
|
||||||
|
|
||||||
|
info("Unregister all service workers");
|
||||||
|
while (getWorkerContainers(doc).length > 0) {
|
||||||
|
let count = getWorkerContainers(doc).length;
|
||||||
|
info("Click on the unregister button for the first service worker");
|
||||||
|
getWorkerContainers(doc)[0].querySelector(".unregister-button").click();
|
||||||
|
|
||||||
|
info("Wait until the service worker is removed from the application panel");
|
||||||
|
await waitUntil(() => getWorkerContainers(doc).length === count - 1);
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,45 @@
|
||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const TAB_URL = URL_ROOT + "service-workers/dynamic-registration.html";
|
||||||
|
|
||||||
|
add_task(async function() {
|
||||||
|
await enableApplicationPanel();
|
||||||
|
|
||||||
|
let { panel, tab } = await openNewTabAndApplicationPanel(TAB_URL);
|
||||||
|
let doc = panel.panelWin.document;
|
||||||
|
|
||||||
|
let isWorkerListEmpty = !!doc.querySelector(".worker-list-empty");
|
||||||
|
ok(isWorkerListEmpty, "No Service Worker displayed");
|
||||||
|
|
||||||
|
info("Register a service worker in the page.");
|
||||||
|
await ContentTask.spawn(tab.linkedBrowser, {}, async function() {
|
||||||
|
content.wrappedJSObject.registerServiceWorker();
|
||||||
|
});
|
||||||
|
|
||||||
|
info("Wait until the service worker appears in the application panel");
|
||||||
|
await waitUntil(() => getWorkerContainers(doc).length > 0);
|
||||||
|
|
||||||
|
let workerContainer = getWorkerContainers(doc)[0];
|
||||||
|
|
||||||
|
info("Wait until the unregister button is displayed for the service worker");
|
||||||
|
await waitUntil(() => workerContainer.querySelector(".unregister-button"));
|
||||||
|
|
||||||
|
let scopeEl = workerContainer.querySelector(".service-worker-scope");
|
||||||
|
let expectedScope = "example.com/browser/devtools/client/application/test/" +
|
||||||
|
"service-workers/";
|
||||||
|
ok(scopeEl.textContent.startsWith(expectedScope),
|
||||||
|
"Service worker has the expected scope");
|
||||||
|
|
||||||
|
info("Unregister the service worker");
|
||||||
|
await ContentTask.spawn(tab.linkedBrowser, {}, async function() {
|
||||||
|
let registration = await content.wrappedJSObject.sw;
|
||||||
|
registration.unregister();
|
||||||
|
});
|
||||||
|
|
||||||
|
info("Wait until the service worker is removed from the application panel");
|
||||||
|
await waitUntil(() => getWorkerContainers(doc).length === 0);
|
||||||
|
});
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
/* eslint-env browser */
|
||||||
|
/* eslint no-unused-vars: [2, {"vars": "local"}] */
|
||||||
|
/* import-globals-from ../../shared/test/shared-head.js */
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// Load the shared-head file first.
|
||||||
|
Services.scriptloader.loadSubScript(
|
||||||
|
"chrome://mochitests/content/browser/devtools/client/shared/test/shared-head.js",
|
||||||
|
this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set all preferences needed to enable service worker debugging and testing.
|
||||||
|
*/
|
||||||
|
async function enableServiceWorkerDebugging() {
|
||||||
|
// Enable service workers.
|
||||||
|
await pushPref("dom.serviceWorkers.enabled", true);
|
||||||
|
// Accept workers from mochitest's http.
|
||||||
|
await pushPref("dom.serviceWorkers.testing.enabled", true);
|
||||||
|
// Force single content process, see Bug 1231208 for the SW refactor that should enable
|
||||||
|
// SW debugging in multi-e10s.
|
||||||
|
await pushPref("dom.ipc.processCount", 1);
|
||||||
|
|
||||||
|
// Wait for dom.ipc.processCount to be updated before releasing processes.
|
||||||
|
Services.ppmm.releaseCachedProcesses();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function enableApplicationPanel() {
|
||||||
|
// Enable all preferences related to service worker debugging.
|
||||||
|
await enableServiceWorkerDebugging();
|
||||||
|
|
||||||
|
// Enable application panel in DevTools.
|
||||||
|
await pushPref("devtools.application.enabled", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getWorkerContainers(doc) {
|
||||||
|
return doc.querySelectorAll(".service-worker-container");
|
||||||
|
}
|
||||||
|
|
||||||
|
function navigate(target, url, waitForTargetEvent = "navigate") {
|
||||||
|
executeSoon(() => target.activeTab.navigateTo(url));
|
||||||
|
return once(target, waitForTargetEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openNewTabAndApplicationPanel(url) {
|
||||||
|
let tab = await addTab(url);
|
||||||
|
let target = TargetFactory.forTab(tab);
|
||||||
|
await target.makeRemote();
|
||||||
|
|
||||||
|
let toolbox = await gDevTools.showToolbox(target, "application");
|
||||||
|
let panel = toolbox.getCurrentPanel();
|
||||||
|
return { panel, tab, target, toolbox };
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
<!-- Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Service worker test</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript">
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
window.registerServiceWorker = function() {
|
||||||
|
window.sw = navigator.serviceWorker.register("empty-sw.js");
|
||||||
|
};
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,4 @@
|
||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
// Empty, just test registering.
|
|
@ -0,0 +1,19 @@
|
||||||
|
<!-- Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Service worker test</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript">
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
window.sw = navigator.serviceWorker.register("empty-sw.js", {
|
||||||
|
scope: "./scope-page.html"
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,15 @@
|
||||||
|
<!-- Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Service worker test</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript">
|
||||||
|
"use strict";
|
||||||
|
window.sw = navigator.serviceWorker.register("empty-sw.js");
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Загрузка…
Ссылка в новой задаче