From e9c0b01bd091624170e7b8d270427e661a0135bb Mon Sep 17 00:00:00 2001 From: techfg Date: Sat, 4 Nov 2023 18:49:51 -0700 Subject: [PATCH 1/5] multiple page tests for #492 --- tests/index.html | 1 + .../event-forwarding/event-forwarding.spec.ts | 37 +++++++- .../integrations/event-forwarding/index.html | 10 +- .../facebook-pixel/facebook-pixel.spec.ts | 65 ++++++++++++- tests/integrations/gtm/gtm.spec.ts | 65 ++++++++++++- tests/integrations/gtm/index.html | 16 ++-- tests/platform/event/event.spec.ts | 34 +++++-- tests/platform/multiple-pages/index.html | 95 +++++++++++++++++++ .../multiple-pages/multiple-pages.spec.ts | 27 ++++++ tests/platform/window/window.spec.ts | 34 +++++-- 10 files changed, 346 insertions(+), 38 deletions(-) create mode 100644 tests/platform/multiple-pages/index.html create mode 100644 tests/platform/multiple-pages/multiple-pages.spec.ts diff --git a/tests/index.html b/tests/index.html index 37f5f1a6..595a92ec 100644 --- a/tests/index.html +++ b/tests/index.html @@ -95,6 +95,7 @@

Platform Tests

  • IFrame
  • Image
  • IntersectionObserver
  • +
  • Multiple Pages
  • MutationObserver
  • Navigator
  • Node
  • diff --git a/tests/integrations/event-forwarding/event-forwarding.spec.ts b/tests/integrations/event-forwarding/event-forwarding.spec.ts index aaad4c78..b94797ec 100644 --- a/tests/integrations/event-forwarding/event-forwarding.spec.ts +++ b/tests/integrations/event-forwarding/event-forwarding.spec.ts @@ -1,15 +1,21 @@ -import { test, expect } from '@playwright/test'; - -test('integration event forwarding', async ({ page }) => { - await page.goto('/tests/integrations/event-forwarding/'); - await page.waitForSelector('.completed'); +import { test, expect, Page } from '@playwright/test'; +const testPage = async (page: Page) => { const testFn = page.locator('#testFn'); await expect(testFn).toHaveText('fnReady'); + const testFnInner = page.locator('#testFnInner'); + await expect(testFnInner).toHaveText('fnReady'); + const testArray = page.locator('#testArray'); await expect(testArray).toHaveText('arrayReady'); + const testArrayInner = page.locator('#testArrayInner'); + await expect(testArrayInner).toHaveText('arrayReady'); + + const kiwiSizing = page.locator('#kiwisizing'); + await expect(kiwiSizing).toHaveText('211448987800'); + const buttonForwardEvent = page.locator('#buttonForwardEvent'); await buttonForwardEvent.click(); await expect(testFn).toHaveText('click1'); @@ -21,4 +27,25 @@ test('integration event forwarding', async ({ page }) => { await expect(testArray).toHaveText(JSON.stringify({ mph: 88 })); await buttonArrayPush.click(); await expect(testArray).toHaveText(JSON.stringify({ mph: 89 })); +}; + +test('integration event forwarding', async ({ page }) => { + await page.goto('/tests/integrations/event-forwarding/'); + await page.waitForSelector('.completed'); + await testPage(page); +}); + +test('integration event forwarding multiple tabs', async ({ page, context }) => { + await page.goto('/tests/integrations/event-forwarding/'); + await page.waitForSelector('.completed'); + + const page2 = await context.newPage(); + await page2.goto('/tests/integrations/event-forwarding/'); + await page2.waitForSelector('.completed'); + + await page.bringToFront(); + await testPage(page); + + await page2.bringToFront(); + await testPage(page2); }); diff --git a/tests/integrations/event-forwarding/index.html b/tests/integrations/event-forwarding/index.html index fdb65ad7..be514fc4 100644 --- a/tests/integrations/event-forwarding/index.html +++ b/tests/integrations/event-forwarding/index.html @@ -30,13 +30,16 @@ const testFn = document.getElementById('testFn'); superDuperFunction = function() { + const testFnInner = document.getElementById('testFnInner'); switch (arguments[0]) { case 'fnReady': { testFn.textContent = arguments[0]; + testFnInner.textContent = arguments[0]; break; } case 'testForwardEvent': { testFn.textContent = arguments[1] + (++inc); + testFnInner.textContent = arguments[1] + (inc); break; } } @@ -50,13 +53,16 @@ superArray = []; superArray.push = function() { + const testArrayInner = document.getElementById('testArrayInner'); switch (arguments[0]) { case 'arrayReady': { testArray.textContent = arguments[0]; + testArrayInner.textContent = arguments[0]; break; } default: { testArray.textContent = JSON.stringify(arguments[0]); + testArrayInner.textContent = JSON.stringify(arguments[0]); break; } } @@ -78,7 +84,7 @@ + + + + +

    Multiple Pages

    + + + + +
    +

    All Tests

    + + diff --git a/tests/platform/multiple-pages/multiple-pages.spec.ts b/tests/platform/multiple-pages/multiple-pages.spec.ts new file mode 100644 index 00000000..c4363f38 --- /dev/null +++ b/tests/platform/multiple-pages/multiple-pages.spec.ts @@ -0,0 +1,27 @@ +import { test, expect } from '@playwright/test'; + +test('multiple pages', async ({ page }) => { + await page.goto('/tests/platform/multiple-pages/'); + + await page.waitForSelector('.completed'); + + const testAnchorOpenNewPage = page.locator('#testAnchorOpenNewPage'); + const anchorOpenNewPage = page.locator('#anchorOpenNewPage'); + + await expect(testAnchorOpenNewPage).toHaveText('0'); + + await anchorOpenNewPage.click(); + await expect(testAnchorOpenNewPage).toHaveText('1'); + + await anchorOpenNewPage.click(); + await expect(testAnchorOpenNewPage).toHaveText('2'); + + await anchorOpenNewPage.click(); + await expect(testAnchorOpenNewPage).toHaveText('3'); + + await anchorOpenNewPage.click(); + await expect(testAnchorOpenNewPage).toHaveText('4'); + + await anchorOpenNewPage.click(); + await expect(testAnchorOpenNewPage).toHaveText('5'); +}); \ No newline at end of file diff --git a/tests/platform/window/window.spec.ts b/tests/platform/window/window.spec.ts index 2753d945..3ec3d913 100644 --- a/tests/platform/window/window.spec.ts +++ b/tests/platform/window/window.spec.ts @@ -1,10 +1,6 @@ -import { test, expect } from '@playwright/test'; - -test('window', async ({ page }) => { - await page.goto('/tests/platform/window/'); - - await page.waitForSelector('.completed'); +import { test, expect, Page } from '@playwright/test'; +const testPage = async (page: Page) => { const testWindowName = page.locator('#testWindowName'); await expect(testWindowName).toHaveText('Window'); @@ -113,7 +109,7 @@ test('window', async ({ page }) => { await expect(testDevicePixelRatio).not.toHaveText(''); const testOrigin = page.locator('#testOrigin'); - const origin = new URL(await testOrigin.textContent()); + const origin = new URL((await testOrigin.textContent()) || ''); expect(origin.pathname).toBe('/'); expect(origin.hostname).toBe('localhost'); @@ -154,4 +150,28 @@ test('window', async ({ page }) => { const testVisualViewport = page.locator('#testVisualViewport'); await expect(testVisualViewport).toHaveText('scale:1 VisualViewport'); +}; + +test('window', async ({ page }) => { + await page.goto('/tests/platform/window/'); + + await page.waitForSelector('.completed'); + + await testPage(page); +}); + +test('window multiple tabs', async ({ page, context }) => { + await page.goto('/tests/platform/window/'); + + await page.waitForSelector('.completed'); + + const page2 = await context.newPage(); + + await page2.goto('/tests/platform/window/'); + + await page2.waitForSelector('.completed'); + + await testPage(page); + + await testPage(page2); }); From 4a77b1c2b475b3e062f723ba4fbf5f5ebcca54cb Mon Sep 17 00:00:00 2001 From: techfg Date: Wed, 10 Jan 2024 11:19:45 -0800 Subject: [PATCH 2/5] revert order of operations on tests --- tests/platform/event/event.spec.ts | 20 ++++++++++++++++---- tests/platform/window/window.spec.ts | 20 ++++++++++++++++---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/tests/platform/event/event.spec.ts b/tests/platform/event/event.spec.ts index de4c8aff..b6382b75 100644 --- a/tests/platform/event/event.spec.ts +++ b/tests/platform/event/event.spec.ts @@ -1,9 +1,6 @@ import { Page, expect, test } from '@playwright/test'; const testPage = async (page: Page) => { - await page.goto('/tests/platform/event/'); - await page.waitForSelector('.completed'); - const testAddEventListener = page.locator('#testAddEventListener'); const buttonAddEventListener = page.locator('#buttonAddEventListener'); await buttonAddEventListener.click(); @@ -69,10 +66,25 @@ const testPage = async (page: Page) => { }; test('events', async ({ page }) => { + await page.goto('/tests/platform/event/'); + + await page.waitForSelector('.completed'); + await testPage(page); }); test('events multiple tabs', async ({ page, context }) => { + await page.goto('/tests/platform/event/'); + + await page.waitForSelector('.completed'); + + const page2 = await context.newPage(); + + await page2.goto('/tests/platform/event/'); + + await page2.waitForSelector('.completed'); + await testPage(page); - await testPage(await context.newPage()); + + await testPage(page2); }); diff --git a/tests/platform/window/window.spec.ts b/tests/platform/window/window.spec.ts index cd2f1f8a..e52826c7 100644 --- a/tests/platform/window/window.spec.ts +++ b/tests/platform/window/window.spec.ts @@ -1,9 +1,6 @@ import { Page, expect, test } from '@playwright/test'; const testPage = async (page: Page) => { - await page.goto('/tests/platform/window/'); - await page.waitForSelector('.completed'); - const testWindowName = page.locator('#testWindowName'); await expect(testWindowName).toHaveText('Window'); @@ -159,10 +156,25 @@ const testPage = async (page: Page) => { }; test('window', async ({ page }) => { + await page.goto('/tests/platform/window/'); + + await page.waitForSelector('.completed'); + await testPage(page); }); test('window multiple tabs', async ({ page, context }) => { + await page.goto('/tests/platform/window/'); + + await page.waitForSelector('.completed'); + + const page2 = await context.newPage(); + + await page2.goto('/tests/platform/window/'); + + await page2.waitForSelector('.completed'); + await testPage(page); - await testPage(await context.newPage()); + + await testPage(page2); }); From c9d62765fe2fcd3f377fb61ced7a774da56d6ea1 Mon Sep 17 00:00:00 2001 From: gioboa Date: Sun, 24 Mar 2024 11:48:08 +0100 Subject: [PATCH 3/5] refactor: remove multiple-pages bc multiple-tabs covers the same case --- tests/index.html | 1 - tests/platform/multiple-pages/index.html | 95 ------------------- .../multiple-pages/multiple-pages.spec.ts | 27 ------ 3 files changed, 123 deletions(-) delete mode 100644 tests/platform/multiple-pages/index.html delete mode 100644 tests/platform/multiple-pages/multiple-pages.spec.ts diff --git a/tests/index.html b/tests/index.html index 2b99a908..06f8cab1 100644 --- a/tests/index.html +++ b/tests/index.html @@ -102,7 +102,6 @@

    Platform Tests

  • IFrame
  • Image
  • IntersectionObserver
  • -
  • Multiple Pages
  • Multiple Tabs
  • MutationObserver
  • Navigator
  • diff --git a/tests/platform/multiple-pages/index.html b/tests/platform/multiple-pages/index.html deleted file mode 100644 index dcbf802c..00000000 --- a/tests/platform/multiple-pages/index.html +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - Multiple Pages - - - - - -

    Multiple Pages

    -
      -
    • - Open New Page -
      Opened Pages:
      - -
    • -
    - - - -
    -

    All Tests

    - - diff --git a/tests/platform/multiple-pages/multiple-pages.spec.ts b/tests/platform/multiple-pages/multiple-pages.spec.ts deleted file mode 100644 index c4363f38..00000000 --- a/tests/platform/multiple-pages/multiple-pages.spec.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { test, expect } from '@playwright/test'; - -test('multiple pages', async ({ page }) => { - await page.goto('/tests/platform/multiple-pages/'); - - await page.waitForSelector('.completed'); - - const testAnchorOpenNewPage = page.locator('#testAnchorOpenNewPage'); - const anchorOpenNewPage = page.locator('#anchorOpenNewPage'); - - await expect(testAnchorOpenNewPage).toHaveText('0'); - - await anchorOpenNewPage.click(); - await expect(testAnchorOpenNewPage).toHaveText('1'); - - await anchorOpenNewPage.click(); - await expect(testAnchorOpenNewPage).toHaveText('2'); - - await anchorOpenNewPage.click(); - await expect(testAnchorOpenNewPage).toHaveText('3'); - - await anchorOpenNewPage.click(); - await expect(testAnchorOpenNewPage).toHaveText('4'); - - await anchorOpenNewPage.click(); - await expect(testAnchorOpenNewPage).toHaveText('5'); -}); \ No newline at end of file From 1a50ed4a36196d0477d7ae9410f615a61eacdd67 Mon Sep 17 00:00:00 2001 From: gioboa Date: Sun, 24 Mar 2024 11:50:15 +0100 Subject: [PATCH 4/5] =?UTF-8?q?chore:=20linter=20=F0=9F=A7=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/service-worker/fetch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/service-worker/fetch.ts b/src/lib/service-worker/fetch.ts index e6ff35db..bf7d9567 100644 --- a/src/lib/service-worker/fetch.ts +++ b/src/lib/service-worker/fetch.ts @@ -45,7 +45,7 @@ const getClientByTab = (clients: Client[], msgId: string) => { } return client; -} +}; const sendMessageToSandboxFromServiceWorker = (accessReq: MainAccessRequest) => new Promise(async (resolve) => { From 0c682d7d0d3a306251900d5891f905ffdb4a5d08 Mon Sep 17 00:00:00 2001 From: gioboa Date: Sun, 24 Mar 2024 11:57:02 +0100 Subject: [PATCH 5/5] =?UTF-8?q?chore:=20linter=20=F0=9F=A7=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/service-worker/fetch.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/service-worker/fetch.ts b/src/lib/service-worker/fetch.ts index bf7d9567..cd576f20 100644 --- a/src/lib/service-worker/fetch.ts +++ b/src/lib/service-worker/fetch.ts @@ -1,7 +1,7 @@ -import { debug } from '../utils'; -import type { MainAccessRequest, MainAccessResponse } from '../types'; import Sandbox from '@sandbox'; import SandboxDebug from '@sandbox-debug'; +import type { MainAccessRequest, MainAccessResponse } from '../types'; +import { debug } from '../utils'; export const onFetchServiceWorkerRequest = (ev: FetchEvent) => { const req = ev.request;