Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <html> | |
| 2 <head> | |
| 3 <script src="../inspector-test.js"></script> | |
| 4 <script src="service-workers-test.js"></script> | |
| 5 <script> | |
| 6 | |
| 7 function initializeServiceWorker(script, scope) { | |
| 8 return navigator.serviceWorker.register(script, {scope: scope}) | |
| 9 .then(reg => waitForActivated(reg.installing)); | |
| 10 } | |
| 11 | |
| 12 function waitForActivated(worker) { | |
| 13 if (worker.state === 'activated') | |
| 14 return Promise.resolve(); | |
| 15 if (worker.state === 'redundant') | |
| 16 return Promise.reject(new Error('The worker is redundant')); | |
| 17 return new Promise(resolve => { | |
| 18 worker.addEventListener('statechange', _ => { | |
| 19 if (worker.state === 'activated') | |
| 20 resolve(); | |
| 21 }); | |
| 22 }); | |
| 23 } | |
| 24 | |
| 25 function loadIframe(url) | |
| 26 { | |
| 27 var callback; | |
| 28 var promise = new Promise((fulfill) => callback = fulfill); | |
| 29 var frame = document.createElement('iframe'); | |
| 30 frame.src = url; | |
| 31 frame.onload = callback; | |
| 32 document.body.appendChild(frame); | |
| 33 return promise; | |
| 34 } | |
| 35 | |
| 36 function test() | |
| 37 { | |
| 38 var scriptURL = "http://127.0.0.1:8000/inspector/service-workers/resources/n avigation-preload-worker.php"; | |
| 39 var scope = "http://127.0.0.1:8000/inspector/service-workers/resources/navig ation-preload-scope.php"; | |
| 40 var preloadRequestIDs = {}; | |
| 41 | |
| 42 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.
| |
| 43 "requestWillBeSent", | |
| 44 requestWillBeSent, | |
| 45 true); | |
| 46 InspectorTest.addSniffer(SDK.NetworkDispatcher.prototype, | |
| 47 "responseReceived", | |
| 48 responseReceived, | |
| 49 true); | |
| 50 InspectorTest.addSniffer(SDK.NetworkDispatcher.prototype, | |
| 51 "loadingFailed", | |
| 52 loadingFailed, | |
| 53 true); | |
| 54 InspectorTest.addSniffer(SDK.NetworkDispatcher.prototype, | |
| 55 "loadingFinished", | |
| 56 loadingFinished, | |
| 57 true); | |
| 58 | |
| 59 function requestWillBeSent(requestId, frameId, loaderId, documentURL, reques t, timestamp, wallTime, initiator, redirectResponse, type) | |
| 60 { | |
| 61 if (initiator.type != "preload") { | |
| 62 return; | |
| 63 } | |
| 64 preloadRequestIDs[requestId] = true; | |
| 65 InspectorTest.addResult("requestWillBeSent:"); | |
| 66 InspectorTest.addResult(" url: " + request.url); | |
| 67 InspectorTest.addResult(" initiator.type: " + initiator.type); | |
| 68 } | |
| 69 function responseReceived(requestId, frameId, loaderId, timestamp, type, res ponse) | |
| 70 { | |
| 71 if (!preloadRequestIDs[requestId]) { | |
| 72 return; | |
| 73 } | |
| 74 InspectorTest.addResult("responseReceived:"); | |
| 75 InspectorTest.addResult(" response.url: " + response.url); | |
| 76 InspectorTest.addResult(" response.timing available: " + | |
| 77 !!response.timing); | |
| 78 InspectorTest.addResult(" response.requestHeaders available: " + | |
| 79 !!response.requestHeaders); | |
| 80 if (response.requestHeaders) { | |
| 81 InspectorTest.addResult( | |
| 82 " response.requestHeaders['Service-Worker-Navigation-Preload']: " + | |
| 83 response.requestHeaders['Service-Worker-Navigation-Preload']); | |
| 84 } | |
| 85 | |
| 86 } | |
| 87 function loadingFailed(requestId, timestamp, type, errorText, canceled, bloc kedReason) | |
| 88 { | |
| 89 if (!preloadRequestIDs[requestId]) { | |
| 90 return; | |
| 91 } | |
| 92 InspectorTest.addResult("loadingFailed:"); | |
| 93 InspectorTest.addResult(" errorText: " + errorText); | |
| 94 } | |
| 95 function loadingFinished(requestId, timestamp, encodedDataLength) | |
| 96 { | |
| 97 if (!preloadRequestIDs[requestId]) { | |
| 98 return; | |
| 99 } | |
| 100 InspectorTest.addResult("loadingFinished:"); | |
| 101 } | |
| 102 InspectorTest.callFunctionInPageAsync("initializeServiceWorker", | |
| 103 [ scriptURL, scope ]) | |
| 104 .then(_ => { | |
| 105 InspectorTest.addResult("-----------------"); | |
| 106 InspectorTest.addResult("Loading an iframe."); | |
| 107 return InspectorTest.callFunctionInPageAsync("loadIframe", [ scope ]); | |
| 108 }) | |
| 109 .then(_ => { | |
| 110 InspectorTest.addResult("The iframe loaded."); | |
| 111 InspectorTest.addResult("-----------------"); | |
| 112 InspectorTest.addResult("Loading another iframe."); | |
| 113 return InspectorTest.callFunctionInPageAsync( | |
| 114 "loadIframe", [ scope + "?BrokenChunked"]); | |
| 115 }) | |
| 116 .then(_ => { | |
| 117 InspectorTest.addResult("The iframe loaded."); | |
| 118 InspectorTest.addResult("-----------------"); | |
| 119 InspectorTest.addResult("Loading another iframe."); | |
| 120 return InspectorTest.callFunctionInPageAsync( | |
| 121 "loadIframe", [ scope + "?RedirectError"]); | |
| 122 }) | |
| 123 .then(_ => { | |
| 124 InspectorTest.addResult("The iframe loaded."); | |
| 125 InspectorTest.addResult("-----------------"); | |
| 126 InspectorTest.addResult("Done"); | |
| 127 InspectorTest.completeTest(); | |
| 128 }); | |
| 129 } | |
| 130 | |
| 131 </script> | |
| 132 </head> | |
| 133 <body onload="runTest()"> | |
| 134 <p>Tests the navigation request related events are available in the DevTools</p> | |
| 135 </body> | |
| 136 </html> | |
| OLD | NEW |