diff --git a/blink/web_tests/VirtualTestSuites b/blink/web_tests/VirtualTestSuites index 61e867617cd..7bf04fc528a 100644 --- a/blink/web_tests/VirtualTestSuites +++ b/blink/web_tests/VirtualTestSuites @@ -467,6 +467,7 @@ "external/wpt/workers", "external/wpt/xhr", "fast/workers", + "http/tests/inspector-protocol/fetch", "http/tests/origin_trials", "http/tests/workers"], "args": ["--enable-features=PlzDedicatedWorker,SharedArrayBuffer"] diff --git a/blink/web_tests/http/tests/inspector-protocol/fetch/dedicated-worker-main-script.js b/blink/web_tests/http/tests/inspector-protocol/fetch/dedicated-worker-main-script.js deleted file mode 100644 index 4eb46e0a720..00000000000 --- a/blink/web_tests/http/tests/inspector-protocol/fetch/dedicated-worker-main-script.js +++ /dev/null @@ -1,33 +0,0 @@ -(async function(testRunner) { - const {page, session, dp} = await testRunner.startBlank( - `Tests that Fetch.requestPaused is emitted for the main script of dedciated worker`); - - await dp.Target.setAutoAttach( - {autoAttach: true, waitForDebuggerOnStart: true, flatten: true}); - - await dp.Fetch.enable({patterns: [{}]}); - dp.Fetch.onRequestPaused(event => { - if (event.params.request.url.endsWith('/worker.js')) { - dp.Fetch.fulfillRequest({ - requestId: event.params.requestId, - responseCode: 200, - responseHeaders: [{name: 'Content-Type', value: 'application/x-javascript'}], - body: btoa(`console.log('PASSED: intercepted script')`) - }) - } - }); - const consoleMessagePromise = new Promise(resolve => { - dp.Target.onAttachedToTarget(async event => { - const wdp = session.createChild(event.params.sessionId).protocol; - wdp.Runtime.enable(); - wdp.Runtime.onConsoleAPICalled(e => { - resolve(e.params.args[0].value); - }) - wdp.Runtime.runIfWaitingForDebugger(); - }); - }); - - session.evaluate(`new Worker('/inspector-protocol/network/resources/worker.js')`); - testRunner.log(await consoleMessagePromise); - testRunner.completeTest(); -}) diff --git a/blink/web_tests/http/tests/inspector-protocol/fetch/resources/service-worker.html b/blink/web_tests/http/tests/inspector-protocol/fetch/resources/empty.html similarity index 100% rename from blink/web_tests/http/tests/inspector-protocol/fetch/resources/service-worker.html rename to blink/web_tests/http/tests/inspector-protocol/fetch/resources/empty.html diff --git a/blink/web_tests/http/tests/inspector-protocol/fetch/resources/shared-worker.js b/blink/web_tests/http/tests/inspector-protocol/fetch/resources/shared-worker.js new file mode 100644 index 00000000000..c1628fa2b2e --- /dev/null +++ b/blink/web_tests/http/tests/inspector-protocol/fetch/resources/shared-worker.js @@ -0,0 +1,6 @@ +self.testToken = 'FAIL: original value'; + +self.addEventListener('connect', e => { + e.ports[0].postMessage('ready'); +}); + diff --git a/blink/web_tests/http/tests/inspector-protocol/fetch/resources/worker.js b/blink/web_tests/http/tests/inspector-protocol/fetch/resources/worker.js index c1628fa2b2e..c17876a2aa1 100644 --- a/blink/web_tests/http/tests/inspector-protocol/fetch/resources/worker.js +++ b/blink/web_tests/http/tests/inspector-protocol/fetch/resources/worker.js @@ -1,6 +1,5 @@ -self.testToken = 'FAIL: original value'; +console.log("Worker"); -self.addEventListener('connect', e => { - e.ports[0].postMessage('ready'); +self.addEventListener('message', e => { + self.postMessage('ready'); }); - diff --git a/blink/web_tests/http/tests/inspector-protocol/fetch/service-worker-interception-expected.txt b/blink/web_tests/http/tests/inspector-protocol/fetch/service-worker-interception-expected.txt index 87952f9aef3..1eac883f045 100644 --- a/blink/web_tests/http/tests/inspector-protocol/fetch/service-worker-interception-expected.txt +++ b/blink/web_tests/http/tests/inspector-protocol/fetch/service-worker-interception-expected.txt @@ -1,9 +1,9 @@ Tests that service worker requests are intercepted. -[browser] Request to http://127.0.0.1:8000/inspector-protocol/fetch/resources/service-worker.html, type: Document +[browser] Request to http://127.0.0.1:8000/inspector-protocol/fetch/resources/empty.html, type: Document [renderer] Request to http://127.0.0.1:8000/inspector-protocol/fetch/resources/service-worker.js, type: Other [browser] Request to http://127.0.0.1:8000/inspector-protocol/fetch/resources/service-worker.js, type: Other -[renderer] Request to http://127.0.0.1:8000/inspector-protocol/fetch/resources/service-worker.html, type: XHR -[browser] Request to http://127.0.0.1:8000/inspector-protocol/fetch/resources/service-worker.html, type: XHR +[renderer] Request to http://127.0.0.1:8000/inspector-protocol/fetch/resources/empty.html, type: XHR +[browser] Request to http://127.0.0.1:8000/inspector-protocol/fetch/resources/empty.html, type: XHR Response fulfilled by service worker: response from service worker [renderer] Request to http://127.0.0.1:8000/inspector-protocol/fetch/resources/fetch-data.txt, type: XHR [browser] Request to http://127.0.0.1:8000/inspector-protocol/fetch/resources/fetch-data.txt, type: XHR diff --git a/blink/web_tests/http/tests/inspector-protocol/fetch/service-worker-interception-late-expected.txt b/blink/web_tests/http/tests/inspector-protocol/fetch/service-worker-interception-late-expected.txt index 683bdde35c6..dbcc877935a 100644 --- a/blink/web_tests/http/tests/inspector-protocol/fetch/service-worker-interception-late-expected.txt +++ b/blink/web_tests/http/tests/inspector-protocol/fetch/service-worker-interception-late-expected.txt @@ -2,7 +2,7 @@ Tests that service worker requests are intercepted when DevTools attached after Response before interception enabled: Fetched for real! [renderer] Request to http://127.0.0.1:8000/inspector-protocol/fetch/resources/service-worker-import.js, type: Script Imported script after interception enabled: overriden imported script! -[renderer] Request to http://127.0.0.1:8000/inspector-protocol/fetch/resources/service-worker.html, type: XHR +[renderer] Request to http://127.0.0.1:8000/inspector-protocol/fetch/resources/empty.html, type: XHR [renderer] Request to http://127.0.0.1:8000/inspector-protocol/fetch/resources/fetch-data.txt, type: XHR Response after interception enabled: overriden response body diff --git a/blink/web_tests/http/tests/inspector-protocol/fetch/service-worker-interception-late.js b/blink/web_tests/http/tests/inspector-protocol/fetch/service-worker-interception-late.js index 9ce62139a4f..aa439be6899 100644 --- a/blink/web_tests/http/tests/inspector-protocol/fetch/service-worker-interception-late.js +++ b/blink/web_tests/http/tests/inspector-protocol/fetch/service-worker-interception-late.js @@ -13,7 +13,7 @@ }); await dp.ServiceWorker.enable(); - await session.navigate("resources/service-worker.html"); + await session.navigate("resources/empty.html"); session.evaluateAsync(` navigator.serviceWorker.register('service-worker.js?defer-install')`); diff --git a/blink/web_tests/http/tests/inspector-protocol/fetch/service-worker-interception.js b/blink/web_tests/http/tests/inspector-protocol/fetch/service-worker-interception.js index f7f4d73cf97..afeb350ceea 100644 --- a/blink/web_tests/http/tests/inspector-protocol/fetch/service-worker-interception.js +++ b/blink/web_tests/http/tests/inspector-protocol/fetch/service-worker-interception.js @@ -20,7 +20,7 @@ }); await dp.ServiceWorker.enable(); - await session.navigate("resources/service-worker.html"); + await session.navigate("resources/empty.html"); session.evaluateAsync(`navigator.serviceWorker.register('service-worker.js')`); async function waitForServiceWorkerActivation() { diff --git a/blink/web_tests/http/tests/inspector-protocol/fetch/worker-interception-expected.txt b/blink/web_tests/http/tests/inspector-protocol/fetch/worker-interception-expected.txt new file mode 100644 index 00000000000..f14ece015f1 --- /dev/null +++ b/blink/web_tests/http/tests/inspector-protocol/fetch/worker-interception-expected.txt @@ -0,0 +1,5 @@ +Tests that dedicated worker requests are intercepted. +[browser] Request to http://127.0.0.1:8000/inspector-protocol/fetch/resources/empty.html, type: Document +[browser] Request to http://127.0.0.1:8000/inspector-protocol/fetch/resources/worker.js, type: Other +worker is ready + diff --git a/blink/web_tests/http/tests/inspector-protocol/fetch/worker-interception.js b/blink/web_tests/http/tests/inspector-protocol/fetch/worker-interception.js new file mode 100644 index 00000000000..ca5eddf7b2f --- /dev/null +++ b/blink/web_tests/http/tests/inspector-protocol/fetch/worker-interception.js @@ -0,0 +1,33 @@ +(async function(testRunner) { + const {page, session, dp} = await testRunner.startBlank( + `Tests that dedicated worker requests are intercepted.`); + + const FetchHelper = await testRunner.loadScript("resources/fetch-test.js"); + const globalFetcher = new FetchHelper(testRunner, testRunner.browserP()); + globalFetcher.setLogPrefix("[browser] "); + await globalFetcher.enable(); + + globalFetcher.onRequest().continueRequest({}); + + await dp.Target.setAutoAttach({ + autoAttach: true, waitForDebuggerOnStart: true, flatten: true}); + dp.Target.onAttachedToTarget(async event => { + const wdp = session.createChild(event.params.sessionId).protocol; + await wdp.Runtime.runIfWaitingForDebugger(); + }); + + await dp.Page.enable(); + await session.navigate("resources/empty.html"); + + const result = await session.evaluateAsync(` + const w = new Worker('/inspector-protocol/fetch/resources/worker.js'); + new Promise((resolve, reject) => { + w.onmessage = e => resolve('worker is ready'); + w.onerror = e => reject(e.message); + w.postMessage('start a worker'); + }) + `); + + testRunner.log(result); + testRunner.completeTest(); +});