|
| 1 | +import { test, expect } from "@playwright/test"; |
| 2 | +import { getSearchParam } from "../helpers/lux"; |
| 3 | +import RequestInterceptor from "../request-interceptor"; |
| 4 | + |
| 5 | +test.describe("LUX events", () => { |
| 6 | + test("new_page_id", async ({ page }) => { |
| 7 | + const luxRequests = new RequestInterceptor(page).createRequestMatcher("/beacon/"); |
| 8 | + await page.goto( |
| 9 | + "/default.html?injectScript=LUX.auto=false;LUX.on('new_page_id', (id) => window.page_id = id);", |
| 10 | + { waitUntil: "networkidle" }, |
| 11 | + ); |
| 12 | + await luxRequests.waitForMatchingRequest(() => page.evaluate(() => LUX.send())); |
| 13 | + |
| 14 | + const firstPageId = await page.evaluate(() => window.page_id); |
| 15 | + const firstBeacon = luxRequests.getUrl(0)!; |
| 16 | + expect(firstPageId).toEqual(getSearchParam(firstBeacon, "sid")); |
| 17 | + |
| 18 | + await luxRequests.waitForMatchingRequest(() => |
| 19 | + page.evaluate(() => { |
| 20 | + LUX.init(); |
| 21 | + LUX.send(); |
| 22 | + }), |
| 23 | + ); |
| 24 | + |
| 25 | + const secondBeacon = luxRequests.getUrl(1)!; |
| 26 | + const secondPageId = await page.evaluate(() => window.page_id); |
| 27 | + expect(secondPageId).toEqual(getSearchParam(secondBeacon, "sid")); |
| 28 | + }); |
| 29 | + |
| 30 | + test("beacon", async ({ page }) => { |
| 31 | + const luxRequests = new RequestInterceptor(page).createRequestMatcher("/beacon/"); |
| 32 | + await page.goto( |
| 33 | + "/default.html?injectScript=LUX.auto=false;LUX.on('beacon', (url) => window.beacon_url = url);", |
| 34 | + { waitUntil: "networkidle" }, |
| 35 | + ); |
| 36 | + await luxRequests.waitForMatchingRequest(() => page.evaluate(() => LUX.send())); |
| 37 | + |
| 38 | + const beacon = luxRequests.getUrl(0)!; |
| 39 | + let beaconUrl = await page.evaluate(() => window.beacon_url); |
| 40 | + |
| 41 | + // We don't encode the Delivery Type parameter before sending the beacon, but Chromium seems to |
| 42 | + // check that everything is encoded before making the actual request. This is a small hack to |
| 43 | + // allow us to compare the strings. |
| 44 | + beaconUrl = beaconUrl.replace("dt(empty string)_", "dt(empty%20string)_"); |
| 45 | + |
| 46 | + expect(beaconUrl).toEqual(beacon.href); |
| 47 | + }); |
| 48 | +}); |
0 commit comments