Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions injected/integration-test/fingerprint.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ const expectedFingerprintValues = {
};

const pagePath = '/index.html';
const tests = [{ url: `http://localhost:3220${pagePath}` }, { url: `http://127.0.0.1:8383${pagePath}` }];
const TEST_PAGE_SERVER_PORT = 3220;
const tests = [
{ url: `http://localhost:${TEST_PAGE_SERVER_PORT}${pagePath}` },
{ url: `http://127.0.0.1:${TEST_PAGE_SERVER_PORT}${pagePath}` },
];
const enabledCanvasArgs = {
site: {
enabledFeatures: ['fingerprintingCanvas'],
Expand All @@ -37,8 +41,7 @@ const enabledCanvasArgs = {
test.describe.serial('All Fingerprint Defense Tests (must run in serial)', () => {
test.describe.serial('Fingerprint Defense Tests', () => {
for (const _test of tests) {
test(`${_test.url} should include anti-fingerprinting code`, async ({ page, altServerPort }) => {
console.log('running:', altServerPort);
test(`${_test.url} should include anti-fingerprinting code`, async ({ page }) => {
await gotoAndWait(page, _test.url, enabledCanvasArgs);
const values = await page.evaluate(() => {
return {
Expand Down Expand Up @@ -94,8 +97,7 @@ test.describe.serial('All Fingerprint Defense Tests (must run in serial)', () =>
}

for (const testCase of tests) {
test(`Fingerprints should not change amongst page loads test ${testCase.url}`, async ({ page, altServerPort }) => {
console.log('running:', altServerPort);
test(`Fingerprints should not change amongst page loads test ${testCase.url}`, async ({ page }) => {
const result = await runTest(page, testCase);

const result2 = await runTest(page, testCase);
Expand All @@ -104,8 +106,7 @@ test.describe.serial('All Fingerprint Defense Tests (must run in serial)', () =>
});
}

test('Fingerprints should not match across first parties', async ({ page, altServerPort }) => {
console.log('running:', altServerPort);
test('Fingerprints should not match across first parties', async ({ page }) => {
const canvas = new Set();
const plugin = new Set();

Expand All @@ -125,8 +126,7 @@ test.describe.serial('All Fingerprint Defense Tests (must run in serial)', () =>

test.describe.serial('Verify injected script is not visible to the page', () => {
tests.forEach((testCase) => {
test(`Fingerprints should not match across first parties ${testCase.url}`, async ({ page, altServerPort }) => {
console.log('running:', altServerPort);
test(`Fingerprints should not match across first parties ${testCase.url}`, async ({ page }) => {
await gotoAndWait(page, testCase.url, enabledCanvasArgs);

// give it another second just to be sure
Expand Down
40 changes: 1 addition & 39 deletions injected/integration-test/helpers/harness.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* global process */
import { mkdtempSync, rmSync } from 'node:fs';
import { tmpdir } from 'os';
import { join } from 'path';
import { chromium, firefox } from '@playwright/test';
import { fork } from 'node:child_process';
import { polyfillProcessGlobals } from '../../unit-test/helpers/polyfill-process-globals.js';

const DATA_DIR_PREFIX = 'ddg-temp-';
Expand All @@ -15,7 +13,7 @@ const DATA_DIR_PREFIX = 'ddg-temp-';
/**
* A single place
* @param {typeof import("@playwright/test").test} test
* @return {TestType<PlaywrightTestArgs & PlaywrightTestOptions & PlaywrightWorkerArgs & PlaywrightWorkerOptions & { altServerPort: number }, {}>}
* @return {TestType<PlaywrightTestArgs & PlaywrightTestOptions & PlaywrightWorkerArgs & PlaywrightWorkerOptions, {}>}
*/
export function testContextForExtension(test) {
return test.extend({
Expand Down Expand Up @@ -49,42 +47,6 @@ export function testContextForExtension(test) {
// Clean up temporary data directory
rmSync(dataDir, { recursive: true, force: true });
},
altServerPort: async ({ browserName }, use) => {
console.log('browserName:', browserName);
const serverScript = fork('./scripts/server.mjs', {
env: {
...process.env,
SERVER_DIR: 'integration-test/test-pages',
SERVER_PORT: '8383',
},
});
const opened = new Promise((resolve, reject) => {
serverScript.on('message', (/** @type {any} */ resp) => {
if (typeof resp.port === 'number') {
resolve(resp.port);
} else {
reject(resp.port);
}
});
});
const closed = new Promise((resolve, reject) => {
serverScript.on('close', (err) => {
if (err) {
reject(new Error('server did not exit, code: ' + err));
} else {
resolve(null);
}
});
serverScript.on('error', () => {
reject(new Error('server errored'));
});
});

const port = await opened;
await use(port);
serverScript.kill();
await closed;
},
});
}

Expand Down
7 changes: 5 additions & 2 deletions injected/playwright.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* global process */
import { defineConfig, devices } from '@playwright/test';

const TEST_PAGE_SERVER_PORT = 3220;
const TEST_PAGE_SERVER_BASE_URL = `http://localhost:${TEST_PAGE_SERVER_PORT}/`;

export default defineConfig({
projects: [
{
Expand Down Expand Up @@ -102,13 +105,13 @@ export default defineConfig({
reuseExistingServer: true,
ignoreHTTPSErrors: true,
command: 'npm run bundle-entry-points && npm run serve',
port: 3220,
port: TEST_PAGE_SERVER_PORT,
},
use: {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 1000,
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'http://localhost:3220/',
baseURL: TEST_PAGE_SERVER_BASE_URL,
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
video: { mode: 'on-first-retry' },
Expand Down
10 changes: 0 additions & 10 deletions injected/scripts/server.mjs

This file was deleted.