Skip to content

Commit

Permalink
Update @playwright/test dependency to 1.46.0 (#2615)
Browse files Browse the repository at this point in the history
Unfortunately it seems that we no longer get the details of
chrome-extension://* requests from Playwright. Even when for example
website scripts are redirected to shim (aka "surrogate") scripts
provided by the extension. Previously those requests included
allowed/blocked/redirected status and URLs, but now they seem to
always show up as being blocked and with the URL of
chrome-extension://invalid/. The Facebook Click to Load integration
tests need to be simplified therefore, to just check for allowed
vs blocked requests.
  • Loading branch information
kzar authored Aug 9, 2024
1 parent 3544847 commit 4878b9e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 94 deletions.
81 changes: 14 additions & 67 deletions integration-test/click-to-load-facebook.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,25 @@ import { EventEmitter } from 'node:events'

import { test, expect } from './helpers/playwrightHarness'
import backgroundWait from './helpers/backgroundWait'
import { waitForNetworkIdle } from './helpers/pageWait'
import { overridePrivacyConfig, overrideTds } from './helpers/testConfig'
import { routeFromLocalhost } from './helpers/testPages'
import { logPageRequests } from './helpers/requests'

const testSite = 'https://privacy-test-pages.site/privacy-protections/click-to-load/'
const facebookDomains = new Set(['facebook.com', 'facebook.net', 'fbcdn.net'])

function summariseFacebookRequests (requests) {
const facebookSDKRedirect = { checked: false, alwaysRedirected: true }
// Note: Requests to the SDK are not included in counts.
let requestCount = 0
function countFacebookRequests (requests) {
let allowCount = 0
// Note: Does not include the SDK request. Playwright is now reporting that
// as having the URL of chrome://invalid, with no redirection/status
// information.
let blockCount = 0

for (const request of requests) {
const domain = getDomain(request.url.href)

if (request.url.pathname === '/web_accessible_resources/fb-sdk.js') {
facebookSDKRedirect.checked = true
}

if (!domain) {
// Ignore requests with no domain EG: data: URLs.
continue
}

if (facebookDomains.has(domain)) {
if (request.url.pathname === '/en_US/sdk.js') {
facebookSDKRedirect.alwaysRedirected = false
facebookSDKRedirect.checked = true
continue
}

requestCount += 1

if (domain && facebookDomains.has(domain)) {
if (request.status === 'blocked') {
blockCount += 1
} else {
Expand All @@ -48,7 +32,7 @@ function summariseFacebookRequests (requests) {
}
}

return { facebookSDKRedirect, requestCount, allowCount, blockCount }
return { allowCount, blockCount }
}

test.describe('Test Facebook Click To Load', () => {
Expand Down Expand Up @@ -78,31 +62,15 @@ test.describe('Test Facebook Click To Load', () => {
})
const pageRequests = []
const clearRequests = await logPageRequests(page, pageRequests)
let blockingFailed

await page.goto(testSite, { waitUntil: 'networkidle' })
{
const {
requestCount, blockCount, allowCount, facebookSDKRedirect
} = summariseFacebookRequests(pageRequests)

expect(facebookSDKRedirect.checked).toBe(true)
expect(facebookSDKRedirect.alwaysRedirected).toBe(true)
expect(requestCount).toBeGreaterThan(3)
const { allowCount, blockCount } = countFacebookRequests(pageRequests)
expect(allowCount).toEqual(0)
expect(blockCount).toEqual(requestCount)

// Note a failure, so that it's not ignored as pending later.
blockingFailed = allowCount > 0 || blockCount < requestCount ||
facebookSDKRedirect.alwaysRedirected === false
expect(blockCount).toBeGreaterThan(0)
}

// Once the user clicks to load the Facebook content, the SDK should be
// loaded and the content should be unblocked.
clearRequests()
const facebookSDKRequestHappened = new Promise((resolve) => {
facebookRequests.once('sdk', resolve)
})
const buttonCount = await page.evaluate(() => {
globalThis.buttons =
Array.from(document.querySelectorAll('body > div'))
Expand All @@ -118,42 +86,21 @@ test.describe('Test Facebook Click To Load', () => {
await button.click()
} catch (e) { }
}
// wait for a facebook SDK request to happen
await facebookSDKRequestHappened
await waitForNetworkIdle(page, 1000)
{
const {
requestCount, blockCount, allowCount, facebookSDKRedirect
} = summariseFacebookRequests(pageRequests)

expect(facebookSDKRedirect.checked).toBe(true)
expect(facebookSDKRedirect.alwaysRedirected).toBeFalsy()

// The network is too slow for any requests to have been made.
// Better to mark these tests as pending than to consider requests
// to have been blocked (or not blocked).
if (requestCount === 0 && !blockingFailed) {
pending('Timed out waiting for Facebook requests!')
}

expect(requestCount).toBeGreaterThan(0)
const { allowCount, blockCount } = countFacebookRequests(pageRequests)
expect(allowCount).toBeGreaterThan(0)
expect(blockCount).toEqual(0)
expect(allowCount).toEqual(requestCount)
}
// navigate away to allow all requests to complete before we clear request data
await page.goto('https://privacy-test-pages.site/')
// When the page is reloaded, requests should be blocked again.
clearRequests()
await page.goto(testSite, { waitUntil: 'networkidle', timeout: 15000 })
{
const {
requestCount, blockCount, allowCount, facebookSDKRedirect
} = summariseFacebookRequests(pageRequests)

expect(facebookSDKRedirect.checked).toBe(true)
expect(facebookSDKRedirect.alwaysRedirected).toBe(true)
expect(requestCount).toBeGreaterThan(3)
const { allowCount, blockCount } = countFacebookRequests(pageRequests)
expect(allowCount).toEqual(0)
expect(blockCount).toEqual(requestCount)
expect(blockCount).toBeGreaterThan(0)
}
})
})
52 changes: 26 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"devDependencies": {
"@fingerprintjs/fingerprintjs": "^4.4.1",
"@playwright/test": "^1.44.1",
"@playwright/test": "^1.46.0",
"@types/chrome": "^0.0.268",
"@types/jasmine": "^4.3.5",
"@types/node": "^20.14.2",
Expand Down

0 comments on commit 4878b9e

Please sign in to comment.