From a749d30f0b5f682e0bde3984698ec40ed797b0ce Mon Sep 17 00:00:00 2001 From: Alex Kamaev Date: Mon, 20 Nov 2023 12:29:06 +0400 Subject: [PATCH 1/2] lint --- .../request-pipeline/index.ts | 8 ++-- .../regression/gh-8054/pages/index.html | 46 +++++++++++++++++++ .../fixtures/regression/gh-8054/pages/sw.js | 18 ++++++++ .../fixtures/regression/gh-8054/test.js | 7 +++ .../gh-8054/testcafe-fixtures/index.js | 13 ++++++ 5 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 test/functional/fixtures/regression/gh-8054/pages/index.html create mode 100644 test/functional/fixtures/regression/gh-8054/pages/sw.js create mode 100644 test/functional/fixtures/regression/gh-8054/test.js create mode 100644 test/functional/fixtures/regression/gh-8054/testcafe-fixtures/index.js diff --git a/src/native-automation/request-pipeline/index.ts b/src/native-automation/request-pipeline/index.ts index a0529b340db..3e0cdfa3751 100644 --- a/src/native-automation/request-pipeline/index.ts +++ b/src/native-automation/request-pipeline/index.ts @@ -66,8 +66,9 @@ const ALL_REQUEST_REQUESTS = { requestStage: 'Response' } as RequestPattern; const ALL_REQUESTS_DATA = [ALL_REQUEST_REQUESTS, ALL_REQUEST_RESPONSES]; const TARGET_INFO_TYPE = { - iframe: 'iframe', - worker: 'worker', + iframe: 'iframe', + worker: 'worker', + serviceWorker: 'service_worker', }; export default class NativeAutomationRequestPipeline extends NativeAutomationApiBase { @@ -403,8 +404,9 @@ export default class NativeAutomationRequestPipeline extends NativeAutomationApi await this._client.Target.on('attachedToTarget', async event => { const isIFrame = event.targetInfo.type === TARGET_INFO_TYPE.iframe; const isWorker = event.targetInfo.type === TARGET_INFO_TYPE.worker; + const isServiceWorker = event.targetInfo.type === TARGET_INFO_TYPE.serviceWorker; - if (!isIFrame && !isWorker) + if (!isIFrame && !isWorker && !isServiceWorker) return; await connectionResetGuard(async () => { diff --git a/test/functional/fixtures/regression/gh-8054/pages/index.html b/test/functional/fixtures/regression/gh-8054/pages/index.html new file mode 100644 index 00000000000..f0b08374b11 --- /dev/null +++ b/test/functional/fixtures/regression/gh-8054/pages/index.html @@ -0,0 +1,46 @@ + + + + + gh-8054 + + +

Service worker

+ + + + diff --git a/test/functional/fixtures/regression/gh-8054/pages/sw.js b/test/functional/fixtures/regression/gh-8054/pages/sw.js new file mode 100644 index 00000000000..736e2119827 --- /dev/null +++ b/test/functional/fixtures/regression/gh-8054/pages/sw.js @@ -0,0 +1,18 @@ +self.addEventListener('fetch', event => { + if (event.request.url.indexOf('?test') > -1) { + event.respondWith( + fetch('http://localhost:3000/fixtures/regression/gh-8054/pages/index.html') + .then(response => { + self.clients.matchAll().then((clients) => { + clients.forEach((client) => { + client.postMessage({ + result: 'success', + }); + }); + }); + + return response; + }) + ); + } +}); diff --git a/test/functional/fixtures/regression/gh-8054/test.js b/test/functional/fixtures/regression/gh-8054/test.js new file mode 100644 index 00000000000..9a28eac0c17 --- /dev/null +++ b/test/functional/fixtures/regression/gh-8054/test.js @@ -0,0 +1,7 @@ +const { onlyInNativeAutomation } = require('../../../utils/skip-in'); + +describe('Should not ignore request from service worker (GH-8054)', function () { + onlyInNativeAutomation('Should not ignore request from service worker (GH-8054)', function () { + return runTests('./testcafe-fixtures/index.js'); + }); +}); diff --git a/test/functional/fixtures/regression/gh-8054/testcafe-fixtures/index.js b/test/functional/fixtures/regression/gh-8054/testcafe-fixtures/index.js new file mode 100644 index 00000000000..f8cc4ea807d --- /dev/null +++ b/test/functional/fixtures/regression/gh-8054/testcafe-fixtures/index.js @@ -0,0 +1,13 @@ +import { Selector } from 'testcafe'; + +fixture `GH-8054 - Should not ignore request from service worker` + .page `http://localhost:3000/fixtures/regression/gh-8054/pages/index.html`; + +test(`Recreate invisible element and click`, async t => { + // NOTE: we need this line for the test. For some reason + // service worker is not registered on first loading + await t.eval(() => window.location.reload()); + + await t.click('button'); + await t.expect(Selector('h1').innerText).eql('Success'); +}); From 178a1cb8217e3347f477145c1a3eda0916da40a6 Mon Sep 17 00:00:00 2001 From: Alex Kamaev Date: Mon, 20 Nov 2023 14:39:34 +0400 Subject: [PATCH 2/2] fix after review --- src/native-automation/request-pipeline/index.ts | 4 ++-- .../fixtures/regression/gh-8054/pages/index.html | 12 ++---------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/native-automation/request-pipeline/index.ts b/src/native-automation/request-pipeline/index.ts index 3e0cdfa3751..b30ed06a87b 100644 --- a/src/native-automation/request-pipeline/index.ts +++ b/src/native-automation/request-pipeline/index.ts @@ -402,8 +402,8 @@ export default class NativeAutomationRequestPipeline extends NativeAutomationApi // to intercept some requests. We need to use the `sessionId` option // in continueRequest/continueResponse/fulfillRequest methods await this._client.Target.on('attachedToTarget', async event => { - const isIFrame = event.targetInfo.type === TARGET_INFO_TYPE.iframe; - const isWorker = event.targetInfo.type === TARGET_INFO_TYPE.worker; + const isIFrame = event.targetInfo.type === TARGET_INFO_TYPE.iframe; + const isWorker = event.targetInfo.type === TARGET_INFO_TYPE.worker; const isServiceWorker = event.targetInfo.type === TARGET_INFO_TYPE.serviceWorker; if (!isIFrame && !isWorker && !isServiceWorker) diff --git a/test/functional/fixtures/regression/gh-8054/pages/index.html b/test/functional/fixtures/regression/gh-8054/pages/index.html index f0b08374b11..736a7fe18cf 100644 --- a/test/functional/fixtures/regression/gh-8054/pages/index.html +++ b/test/functional/fixtures/regression/gh-8054/pages/index.html @@ -13,18 +13,10 @@

Service worker

try { const serviceWorkerUrl = '/fixtures/regression/gh-8054/pages/sw.js'; - const registration = await navigator.serviceWorker.register(serviceWorkerUrl, { + await navigator.serviceWorker.register(serviceWorkerUrl, { scope: "/fixtures/regression/gh-8054/pages/", }); - if (registration.installing) { - console.log("Service worker installing"); - } else if (registration.waiting) { - console.log("Service worker installed"); - } else if (registration.active) { - console.log("Service worker active"); - } - } catch (error) { - console.error(`Registration failed with ${error}`); + } catch (err) { } navigator.serviceWorker.addEventListener('message',