diff options
Diffstat (limited to 'dom/workers/test')
-rw-r--r-- | dom/workers/test/serviceworkers/chrome.ini | 3 | ||||
-rw-r--r-- | dom/workers/test/serviceworkers/test_devtools_serviceworker_interception.html | 168 | ||||
-rw-r--r-- | dom/workers/test/serviceworkers/test_serviceworker_interfaces.js | 4 | ||||
-rw-r--r-- | dom/workers/test/test_404.html | 1 | ||||
-rw-r--r-- | dom/workers/test/test_bug1036484.html | 1 | ||||
-rw-r--r-- | dom/workers/test/test_loadError.html | 8 | ||||
-rw-r--r-- | dom/workers/test/test_worker_interfaces.js | 4 |
7 files changed, 177 insertions, 12 deletions
diff --git a/dom/workers/test/serviceworkers/chrome.ini b/dom/workers/test/serviceworkers/chrome.ini index e064e7fd0..6d7dbebd0 100644 --- a/dom/workers/test/serviceworkers/chrome.ini +++ b/dom/workers/test/serviceworkers/chrome.ini @@ -3,6 +3,8 @@ skip-if = os == 'android' support-files = chrome_helpers.js empty.js + fetch.js + hello.html serviceworker.html serviceworkerinfo_iframe.html serviceworkermanager_iframe.html @@ -10,6 +12,7 @@ support-files = worker.js worker2.js +[test_devtools_serviceworker_interception.html] [test_privateBrowsing.html] [test_serviceworkerinfo.xul] [test_serviceworkermanager.xul] diff --git a/dom/workers/test/serviceworkers/test_devtools_serviceworker_interception.html b/dom/workers/test/serviceworkers/test_devtools_serviceworker_interception.html new file mode 100644 index 000000000..d49ebb2c9 --- /dev/null +++ b/dom/workers/test/serviceworkers/test_devtools_serviceworker_interception.html @@ -0,0 +1,168 @@ +<!-- + Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ +--> +<!DOCTYPE HTML> +<html> +<head> + <title>Bug 1168875 - test devtools serviceworker interception.</title> + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" + type="text/css" + href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +</head> +<body> +<p id="display"></p> +<div id="content" style="display: none"></div> +<pre id="test"></pre> +<script class="testbody" type="text/javascript"> + +// Constants +const Ci = Components.interfaces; +const workerScope = "http://mochi.test:8888/chrome/dom/workers/test/serviceworkers/"; +const workerURL = workerScope + "fetch.js"; +const contentPage = workerScope + "hello.html"; + +function createTestWindow(aURL) { + var mainwindow = window.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation) + .QueryInterface(Ci.nsIDocShellTreeItem) + .rootTreeItem + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindow); + var win = mainwindow.OpenBrowserWindow(contentPage); + + return new Promise(aResolve => { + win.addEventListener("DOMContentLoaded", function callback() { + if (win.content.location.href != aURL) { + win.gBrowser.loadURI(aURL); + return; + } + + win.removeEventListener("DOMContentLoaded", callback); + aResolve(win.content); + }); + }); +} + +function executeTest(aWindow) { + var registration; + + return Promise.resolve() + // Should not be intercepted. + .then(_ => fetchAndCheckTimedChannel(aWindow, false, true, "hello.html")) + + // Regist a service worker. + .then(_ => register(aWindow, workerURL, workerScope)) + .then(r => registration = r) + + // Should be intercpeted and synthesized. + .then(_ => fetchAndCheckTimedChannel(aWindow, true, false, "fake.html")) + + // Should be intercepted but still fetch from network. + .then(_ => fetchAndCheckTimedChannel(aWindow, true, true, + "hello.html?ForBypassingHttpCache")) + + // Tear down + .then(_ => registration.unregister()); +} + +function register(aWindow, aURL, aScope) { + return aWindow.navigator.serviceWorker.register(aURL, {scope: aScope}) + .then(r => { + var worker = r.installing; + return new Promise(function(aResolve) { + worker.onstatechange = function() { + if (worker.state == "activated") { + aResolve(r); + } + } + }); + }); +} + +function fetchAndCheckTimedChannel(aWindow, aIntercepted, aFetch, aURL) { + var resolveFunction; + var promise = new Promise(aResolve => resolveFunction = aResolve); + + var topic = aFetch ? "http-on-examine-response" + : "service-worker-synthesized-response"; + + function observer(aSubject) { + var channel = aSubject.QueryInterface(Ci.nsIChannel); + ok(channel.URI.spec.endsWith(aURL)); + + var tc = aSubject.QueryInterface(Ci.nsITimedChannel); + + // Check service worker related timings. + var serviceWorkerTimings = [{start: tc.launchServiceWorkerStartTime, + end: tc.launchServiceWorkerEndTime}, + {start: tc.dispatchFetchEventStartTime, + end: tc.dispatchFetchEventEndTime}, + {start: tc.handleFetchEventStartTime, + end: tc.handleFetchEventEndTime}]; + if (aIntercepted) { + serviceWorkerTimings.reduce((aPreviousTimings, aCurrentTimings) => { + ok(aPreviousTimings.start <= aCurrentTimings.start, + "Start time order check."); + ok(aPreviousTimings.end <= aCurrentTimings.end, + "End time order check."); + ok(aCurrentTimings.start <= aCurrentTimings.end, + "Start time should be smaller than end time."); + return aCurrentTimings; + }); + } else { + serviceWorkerTimings.forEach(aTimings => { + is(aTimings.start, 0); + is(aTimings.end, 0); + }); + } + + // Check network related timings. + var networkTimings = [tc.domainLookupStartTime, + tc.domainLookupEndTime, + tc.connectStartTime, + tc.connectEndTime, + tc.requestStartTime, + tc.responseStartTime, + tc.responseEndTime]; + if (aFetch) { + networkTimings.reduce((aPreviousTiming, aCurrentTiming) => { + ok(aPreviousTiming <= aCurrentTiming); + return aCurrentTiming; + }); + } else { + networkTimings.forEach(aTiming => is(aTiming, 0)); + } + + SpecialPowers.removeObserver(observer, topic); + resolveFunction(); + } + + SpecialPowers.addObserver(observer, topic, false); + + // return promise; + return Promise.all([aWindow.fetch(aURL), promise]); +} + +function runTest() { + return Promise.resolve() + .then(_ => createTestWindow(contentPage)) + .then(w => executeTest(w)) + .catch(e => ok(false, "Some test failed with error " + e)) + .then(_ => SimpleTest.finish()); +} + +SimpleTest.waitForExplicitFinish(); +SpecialPowers.pushPrefEnv({"set": [ + ["dom.serviceWorkers.exemptFromPerDomainMax", true], + ["dom.serviceWorkers.enabled", true], + ["dom.serviceWorkers.testing.enabled", true], +]}, runTest); + +</script> +</pre> +</body> +</html> + diff --git a/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js b/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js index 9dbfcc099..a4d498fb8 100644 --- a/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js +++ b/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js @@ -172,9 +172,9 @@ var interfaceNamesInGlobalScope = // IMPORTANT: Do not change this list without review from a DOM peer! "PerformanceMeasure", // IMPORTANT: Do not change this list without review from a DOM peer! - { name: "PerformanceObserver", nightly: true }, + "PerformanceObserver", // IMPORTANT: Do not change this list without review from a DOM peer! - { name: "PerformanceObserverEntryList", nightly: true }, + "PerformanceObserverEntryList", // IMPORTANT: Do not change this list without review from a DOM peer! "Request", // IMPORTANT: Do not change this list without review from a DOM peer! diff --git a/dom/workers/test/test_404.html b/dom/workers/test/test_404.html index e2e83a35e..15e5ded68 100644 --- a/dom/workers/test/test_404.html +++ b/dom/workers/test/test_404.html @@ -25,7 +25,6 @@ Tests of DOM Worker Threads worker.onerror = function(event) { is(event.target, worker); - is(event.message, 'NetworkError: Failed to load worker script at "nonexistent_worker.js"'); event.preventDefault(); SimpleTest.finish(); }; diff --git a/dom/workers/test/test_bug1036484.html b/dom/workers/test/test_bug1036484.html index 17b9d490f..49c31bbc9 100644 --- a/dom/workers/test/test_bug1036484.html +++ b/dom/workers/test/test_bug1036484.html @@ -25,7 +25,6 @@ function test(script) { worker.onerror = function(event) { is(event.target, worker); - ok(event.message.startsWith("NetworkError: Failed to load worker script")) event.preventDefault(); runTests(); }; diff --git a/dom/workers/test/test_loadError.html b/dom/workers/test/test_loadError.html index dc109b796..b9a215d11 100644 --- a/dom/workers/test/test_loadError.html +++ b/dom/workers/test/test_loadError.html @@ -13,15 +13,13 @@ <script class="testbody" type="text/javascript"> "use strict"; -var loadErrorMessage = 'SecurityError: Failed to load worker script at "about:blank"'; - function nextTest() { (function(){ function workerfunc() { var subworker = new Worker("about:blank"); subworker.onerror = function(e) { e.preventDefault(); - postMessage(e.message); + postMessage("ERROR"); } } var b = new Blob([workerfunc+'workerfunc();']); @@ -37,7 +35,7 @@ function nextTest() { return; } w.onmessage = function(e) { - is(e.data, loadErrorMessage, + is(e.data, "ERROR", "Should catch the error when loading inner script"); if (++i < 2) callworker(i); else SimpleTest.finish(); @@ -54,8 +52,6 @@ try { var worker = new Worker("about:blank"); worker.onerror = function(e) { e.preventDefault(); - is(e.message, loadErrorMessage, - "Should get the right error from the toplevel script"); nextTest(); } diff --git a/dom/workers/test/test_worker_interfaces.js b/dom/workers/test/test_worker_interfaces.js index e0647682c..6fe5fcaff 100644 --- a/dom/workers/test/test_worker_interfaces.js +++ b/dom/workers/test/test_worker_interfaces.js @@ -163,9 +163,9 @@ var interfaceNamesInGlobalScope = // IMPORTANT: Do not change this list without review from a DOM peer! "PerformanceMeasure", // IMPORTANT: Do not change this list without review from a DOM peer! - { name: "PerformanceObserver", nightly: true }, + "PerformanceObserver", // IMPORTANT: Do not change this list without review from a DOM peer! - { name: "PerformanceObserverEntryList", nightly: true }, + "PerformanceObserverEntryList", // IMPORTANT: Do not change this list without review from a DOM peer! "Request", // IMPORTANT: Do not change this list without review from a DOM peer! |