Index: third_party/WebKit/LayoutTests/http/tests/inspector/service-workers/service-workers-navigation-preload.html |
diff --git a/third_party/WebKit/LayoutTests/http/tests/inspector/service-workers/service-workers-navigation-preload.html b/third_party/WebKit/LayoutTests/http/tests/inspector/service-workers/service-workers-navigation-preload.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3f7b89db8ece2f61af6191601721d177c19e9af1 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/http/tests/inspector/service-workers/service-workers-navigation-preload.html |
@@ -0,0 +1,123 @@ |
+<html> |
+<head> |
+<script src="../inspector-test.js"></script> |
+<script src="service-workers-test.js"></script> |
+<script> |
+ |
+function initializeServiceWorker(script, scope) { |
+ return navigator.serviceWorker.register(script, {scope: scope}) |
+ .then(reg => waitForActivated(reg.installing)); |
+} |
+ |
+function waitForActivated(worker) { |
+ if (worker.state === 'activated') |
+ return Promise.resolve(); |
+ if (worker.state === 'redundant') |
+ return Promise.reject(new Error('The worker is redundant')); |
+ return new Promise(resolve => { |
+ worker.addEventListener('statechange', _ => { |
+ if (worker.state === 'activated') |
+ resolve(); |
+ }); |
+ }); |
+} |
+ |
+function loadIframe(url) |
+{ |
+ var callback; |
+ var promise = new Promise((fulfill) => callback = fulfill); |
+ var frame = document.createElement('iframe'); |
+ frame.src = url; |
+ frame.onload = callback; |
+ document.body.appendChild(frame); |
+ return promise; |
+} |
+ |
+function test() |
+{ |
+ var scriptURL = "http://127.0.0.1:8000/inspector/service-workers/resources/navigation-preload-worker.php"; |
+ var scope = "http://127.0.0.1:8000/inspector/service-workers/resources/navigation-preload-scope.php"; |
+ |
+ InspectorTest.addSniffer(SDK.NetworkDispatcher.prototype, |
+ "navigationPreloadSent", |
+ navigationPreloadSent, |
+ true); |
+ InspectorTest.addSniffer(SDK.NetworkDispatcher.prototype, |
+ "navigationPreloadResponseReceived", |
+ navigationPreloadResponseReceived, |
+ true); |
+ InspectorTest.addSniffer(SDK.NetworkDispatcher.prototype, |
+ "navigationPreloadFailed", |
+ navigationPreloadFailed, |
+ true); |
+ InspectorTest.addSniffer(SDK.NetworkDispatcher.prototype, |
+ "navigationPreloadFinished", |
+ navigationPreloadFinished, |
+ true); |
+ |
+ function navigationPreloadSent(requestId, url, timestamp, wallTime, initiator) |
+ { |
+ InspectorTest.addResult("navigationPreloadSent:"); |
+ InspectorTest.addResult(" url: " + url); |
+ InspectorTest.addResult(" initiator.type: " + initiator.type); |
+ } |
+ function navigationPreloadResponseReceived(requestId, timestamp, response) |
+ { |
+ InspectorTest.addResult("navigationPreloadResponseReceived:"); |
+ InspectorTest.addResult(" response.url: " + response.url); |
+ InspectorTest.addResult(" response.timing available: " + |
+ !!response.timing); |
+ InspectorTest.addResult(" response.requestHeaders available: " + |
+ !!response.requestHeaders); |
+ if (response.requestHeaders) { |
+ InspectorTest.addResult( |
+ " response.requestHeaders['Service-Worker-Navigation-Preload']: " + |
+ response.requestHeaders['Service-Worker-Navigation-Preload']); |
+ } |
+ |
+ } |
+ function navigationPreloadFailed(requestId, timestamp, errorMessage) |
+ { |
+ InspectorTest.addResult("navigationPreloadFailed:"); |
+ InspectorTest.addResult(" errorMessage: " + errorMessage); |
+ } |
+ function navigationPreloadFinished(requestId, timestamp) |
+ { |
+ InspectorTest.addResult("navigationPreloadFinished:"); |
+ } |
+ |
+ InspectorTest.callFunctionInPageAsync("initializeServiceWorker", |
+ [ scriptURL, scope ]) |
+ .then(_ => { |
+ InspectorTest.addResult("-----------------"); |
+ InspectorTest.addResult("Loading an iframe."); |
+ return InspectorTest.callFunctionInPageAsync("loadIframe", [ scope ]); |
+ }) |
+ .then(_ => { |
+ InspectorTest.addResult("The iframe loaded."); |
+ InspectorTest.addResult("-----------------"); |
+ InspectorTest.addResult("Loading another iframe."); |
+ return InspectorTest.callFunctionInPageAsync( |
+ "loadIframe", [ scope + "?BrokenChunked"]); |
+ }) |
+ .then(_ => { |
+ InspectorTest.addResult("The iframe loaded."); |
+ InspectorTest.addResult("-----------------"); |
+ InspectorTest.addResult("Loading another iframe."); |
+ return InspectorTest.callFunctionInPageAsync( |
+ "loadIframe", [ scope + "?RedirectError"]); |
+ }) |
+ .then(_ => { |
+ InspectorTest.addResult("The iframe loaded."); |
+ InspectorTest.addResult("-----------------"); |
+ InspectorTest.addResult("Done"); |
+ InspectorTest.completeTest(); |
+ }); |
+} |
+ |
+</script> |
+</head> |
+<body onload="runTest()"> |
+<p>Tests the navigation request related events are available in the DevTools</p> |
+</body> |
+</html> |