Chromium Code Reviews| 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..0805b50b80f06de50e61b30708ff415c0c773d52 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/http/tests/inspector/service-workers/service-workers-navigation-preload.html |
| @@ -0,0 +1,136 @@ |
| +<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"; |
| + var preloadRequestIDs = {}; |
| + |
| + InspectorTest.addSniffer(SDK.NetworkDispatcher.prototype, |
|
pfeldman
2017/01/20 20:41:46
Could you instead listen to the NetworkManager eve
horo
2017/01/23 08:05:32
Done.
|
| + "requestWillBeSent", |
| + requestWillBeSent, |
| + true); |
| + InspectorTest.addSniffer(SDK.NetworkDispatcher.prototype, |
| + "responseReceived", |
| + responseReceived, |
| + true); |
| + InspectorTest.addSniffer(SDK.NetworkDispatcher.prototype, |
| + "loadingFailed", |
| + loadingFailed, |
| + true); |
| + InspectorTest.addSniffer(SDK.NetworkDispatcher.prototype, |
| + "loadingFinished", |
| + loadingFinished, |
| + true); |
| + |
| + function requestWillBeSent(requestId, frameId, loaderId, documentURL, request, timestamp, wallTime, initiator, redirectResponse, type) |
| + { |
| + if (initiator.type != "preload") { |
| + return; |
| + } |
| + preloadRequestIDs[requestId] = true; |
| + InspectorTest.addResult("requestWillBeSent:"); |
| + InspectorTest.addResult(" url: " + request.url); |
| + InspectorTest.addResult(" initiator.type: " + initiator.type); |
| + } |
| + function responseReceived(requestId, frameId, loaderId, timestamp, type, response) |
| + { |
| + if (!preloadRequestIDs[requestId]) { |
| + return; |
| + } |
| + InspectorTest.addResult("responseReceived:"); |
| + 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 loadingFailed(requestId, timestamp, type, errorText, canceled, blockedReason) |
| + { |
| + if (!preloadRequestIDs[requestId]) { |
| + return; |
| + } |
| + InspectorTest.addResult("loadingFailed:"); |
| + InspectorTest.addResult(" errorText: " + errorText); |
| + } |
| + function loadingFinished(requestId, timestamp, encodedDataLength) |
| + { |
| + if (!preloadRequestIDs[requestId]) { |
| + return; |
| + } |
| + InspectorTest.addResult("loadingFinished:"); |
| + } |
| + 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> |