Skip to content

Commit

Permalink
Update storage tests for updated test page (#1546)
Browse files Browse the repository at this point in the history
* Update storage tests for updated test page

* Correctly filter tests by manifest version

* Fix manifestVersion detection in another place.
  • Loading branch information
sammacbeth committed Nov 21, 2022
1 parent b21a7ce commit 54cd161
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 22 deletions.
48 changes: 34 additions & 14 deletions integration-test/background/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const thirdPartyDomain = 'good.third-party.site'
const thirdPartyTracker = 'broken.third-party.site'

async function setup () {
const { browser, bgPage, teardown, manifestVersion } = await harness.setup()
const { browser, bgPage, teardown } = await harness.setup()
const page = await browser.newPage()

await backgroundWait.forAllConfiguration(bgPage)
await loadTestConfig(bgPage, 'storage-blocking.json')

return { browser, page, teardown, bgPage, manifestVersion }
return { browser, page, teardown, bgPage }
}

async function waitForAllResults (page) {
Expand All @@ -26,12 +26,9 @@ async function waitForAllResults (page) {
describe('Storage blocking Tests', () => {
describe(`On https://${testPageDomain}/privacy-protections/storage-blocking/`, () => {
let cookies = []
let manifestVersion

beforeAll(async () => {
let page
let teardown
({ page, teardown, manifestVersion } = await setup())
const { page, teardown } = await setup()
try {
// Load the test pages home first to give some time for the extension background to start
// and register the content-script-message handler
Expand All @@ -49,24 +46,47 @@ describe('Storage blocking Tests', () => {
})

it('does not block 1st party HTTP cookies', () => {
const headerCookie = cookies.find(({ name, domain }) => name === 'headerdata' && domain === testPageDomain)
const headerCookie = cookies.find(({ name, domain }) => name === 'top_firstparty_headerdata' && domain === testPageDomain)
expect(headerCookie).toBeTruthy()
expect(headerCookie.expires).toBeGreaterThan(Date.now() / 1000)
})

// FIXME - Once Cookie header blocking is working in the experimental
// Chrome MV3 build of the extension we should remove this
// condition.
if (manifestVersion === 2) {
it('blocks 3rd party HTTP cookies not on block list', () => {
const headerCookie = cookies.find(({ name, domain }) => name === 'headerdata' && domain === thirdPartyDomain)
expect(headerCookie).toBeUndefined()
if (harness.getManifestVersion() !== 3) {
it('allows 3rd party HTTP cookies not on block list', () => {
const headerCookie = cookies.find(({ name, domain }) => name === 'top_thirdparty_headerdata' && domain === thirdPartyDomain)
expect(headerCookie).toBeTruthy()
expect(headerCookie.expires).toBeGreaterThan(Date.now() / 1000)
})

it('blocks 3rd party HTTP cookies for trackers', () => {
const headerCookie = cookies.find(({ name, domain }) => name === 'headerdata' && domain === thirdPartyTracker)
const headerCookie = cookies.find(({ name, domain }) => name === 'top_tracker_headerdata' && domain === thirdPartyTracker)
expect(headerCookie).toBeUndefined()
})

it('allows 1st party HTTP cookies from non-tracker frames', () => {
const headerCookie = cookies.find(({ name, domain }) => name === 'thirdparty_firstparty_headerdata' && domain === thirdPartyDomain)
expect(headerCookie).toBeTruthy()
expect(headerCookie.expires).toBeGreaterThan(Date.now() / 1000)
})

it('blocks 3rd party tracker HTTP cookies from non-tracker frames', () => {
const headerCookie = cookies.find(({ name, domain }) => name === 'thirdparty_tracker_headerdata' && domain === thirdPartyTracker)
expect(headerCookie).toBeUndefined()
})

it('blocks 1st party HTTP cookies from tracker frames', () => {
const headerCookie = cookies.find(({ name, domain }) => name === 'thirdpartytracker_firstparty_headerdata' && domain === thirdPartyTracker)
expect(headerCookie).toBeUndefined()
})

it('allows 3rd party tracker HTTP cookies from tracker frames', () => {
const headerCookie = cookies.find(({ name, domain }) => name === 'thirdpartytracker_thirdparty_headerdata' && domain === thirdPartyDomain)
expect(headerCookie).toBeTruthy()
expect(headerCookie.expires).toBeGreaterThan(Date.now() / 1000)
})
}

it('does not block 1st party JS cookies', () => {
Expand All @@ -75,9 +95,9 @@ describe('Storage blocking Tests', () => {
expect(jsCookie.expires).toBeGreaterThan(Date.now() / 1000)
})

it('does block 3rd party JS cookies not on block list', () => {
it('does not block 3rd party JS cookies not on block list', () => {
const jsCookie = cookies.find(({ name, domain }) => name === 'jsdata' && domain === thirdPartyDomain)
expect(jsCookie).toBeUndefined()
expect(jsCookie).toBeTruthy()
})

it('blocks 3rd party JS cookies from trackers', () => {
Expand Down
5 changes: 2 additions & 3 deletions integration-test/content-scripts/gpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ const frameTests = [
let server
let server2
let teardown
let manifestVersion

describe('Ensure GPC is injected into frames', () => {
beforeAll(async () => {
({ browser, bgPage, teardown, manifestVersion } = await harness.setup())
({ browser, bgPage, teardown } = await harness.setup())
server = setupServer({}, 8080)
server2 = setupServer({}, 8081)

Expand Down Expand Up @@ -75,7 +74,7 @@ describe('Ensure GPC is injected into frames', () => {

// FIXME - chrome.scripting API is not yet injecting into about:blank
// frames correctly. See https://crbug.com/1360392.
if (manifestVersion === 2) {
if (harness.getManifestVersion() === 2) {
it(`${iframeHost} should work with about:blank injected frames`, async () => {
const page = await browser.newPage()
await pageWait.forGoto(page, 'http://127.0.0.1:8080/blank_framer.html')
Expand Down
2 changes: 1 addition & 1 deletion integration-test/data/configs/storage-blocking.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"excludedCookieDomains": [ ],
"trackerCookie": "enabled",
"nonTrackerCookie": "enabled"
"nonTrackerCookie": "disabled"
},
"exceptions": [ ],
"state": "enabled"
Expand Down
12 changes: 8 additions & 4 deletions integration-test/helpers/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ const setup = async (ops) => {
`--user-data-dir=${dataDir}`
]

const manifestVersion =
process.env.npm_lifecycle_event === 'test-int-mv3' ? 3 : 2
const manifestVersion = getManifestVersion()

if (loadExtension) {
let extensionPath = 'build/chrome/dev'
Expand Down Expand Up @@ -93,9 +92,14 @@ const setup = async (ops) => {
spawnSync('rm', ['-rf', dataDir])
}

return { browser, bgPage, requests, teardown, manifestVersion }
return { browser, bgPage, requests, teardown }
}

function getManifestVersion () {
return process.env.npm_lifecycle_event === 'test-int-mv3' ? 3 : 2
}

module.exports = {
setup
setup,
getManifestVersion
}

0 comments on commit 54cd161

Please sign in to comment.