Skip to content

Commit

Permalink
Added negative GPC test (Issue #392)
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverWang13 committed Feb 15, 2023
1 parent a75920f commit beb0da5
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions test/background/gpc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,49 @@
const page = await browser.newPage()
let rules;
//let gpc;
await page.goto(`https://global-privacy-control.glitch.me/`)

//await new Promise(resolve => setTimeout(resolve, 2000));
await page.reload();
//await new Promise(resolve => setTimeout(resolve, 1000));

const gpc = await page.evaluate(async () => {
await page.goto("https://example.org/foo/bar.html")
await page.reload();

const gpc_neg = await page.evaluate(async () => {
await new Promise(resolve => setTimeout(resolve, 2000));

return (async () => {
return navigator.globalPrivacyControl
})()
})

const header = await page.evaluate(async () => {
await page.goto(`https://global-privacy-control.glitch.me/`)

//await new Promise(resolve => setTimeout(resolve, 2000));
await page.reload();
//await new Promise(resolve => setTimeout(resolve, 1000));

const gpc = await page.evaluate(async () => {
await new Promise(resolve => setTimeout(resolve, 2000));

return (async () => {
return navigator.globalPrivacyControl
})()
})

const header = await page.evaluate(async () => {

function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}

return getElementByXpath("/html/body/section[2]/div/div[1]/div/h3").innerText;

})

function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}

return getElementByXpath("/html/body/section[2]/div/div[1]/div/h3").innerText;

})



assert.equal(header, 'Header present \nSec-GPC: "1"');
assert.equal(gpc, true);
assert.equal(gpc_neg, undefined);
})
})

0 comments on commit beb0da5

Please sign in to comment.