зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1525458 - Part 4: Add a test that verifies that when the top-level page is on the content blocking allow-list, we don't emit unexpected content blocking events inside the content blocking log; r=baku
Differential Revision: https://phabricator.services.mozilla.com/D20877
This commit is contained in:
Родитель
444d31403e
Коммит
3bcc679115
|
@ -24,6 +24,9 @@ support-files =
|
|||
storageAccessAPIHelpers.js
|
||||
!/browser/modules/test/browser/head.js
|
||||
|
||||
[browser_allowListNotifications.js]
|
||||
skip-if = serviceworker_e10s
|
||||
support-files = subResources.sjs
|
||||
[browser_addonHostPermissionIgnoredInTP.js]
|
||||
[browser_allowListSeparationInPrivateAndNormalWindows.js]
|
||||
skip-if = os == "mac" && !debug # Bug 1503778
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
add_task(async function() {
|
||||
info("Starting subResources test");
|
||||
|
||||
await SpecialPowers.flushPrefEnv();
|
||||
await SpecialPowers.pushPrefEnv({"set": [
|
||||
["browser.contentblocking.allowlist.annotations.enabled", true],
|
||||
["browser.contentblocking.allowlist.storage.enabled", true],
|
||||
["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
|
||||
["privacy.trackingprotection.enabled", false],
|
||||
["privacy.trackingprotection.pbmode.enabled", false],
|
||||
["privacy.trackingprotection.annotate_channels", true],
|
||||
]});
|
||||
|
||||
await UrlClassifierTestUtils.addTestTrackers();
|
||||
|
||||
info("Creating a new tab");
|
||||
let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE);
|
||||
gBrowser.selectedTab = tab;
|
||||
|
||||
let browser = gBrowser.getBrowserForTab(tab);
|
||||
await BrowserTestUtils.browserLoaded(browser);
|
||||
|
||||
ContentBlocking.disableForCurrentPage();
|
||||
|
||||
// The previous function reloads the browser, so wait for it to load again!
|
||||
await BrowserTestUtils.browserLoaded(browser);
|
||||
|
||||
// Now load subresources from a few third-party origins.
|
||||
// We should expect to see none of these origins in the content blocking log at the end.
|
||||
await fetch("https://test1.example.com/browser/toolkit/components/antitracking/test/browser/subResources.sjs?result&what=image")
|
||||
.then(r => r.text())
|
||||
.then(text => {
|
||||
is(text, 0, "Cookies received for images");
|
||||
});
|
||||
|
||||
await fetch("https://test2.example.com/browser/toolkit/components/antitracking/test/browser/subResources.sjs?result&what=image")
|
||||
.then(r => r.text())
|
||||
.then(text => {
|
||||
is(text, 0, "Cookies received for images");
|
||||
});
|
||||
|
||||
info("Creating a 3rd party content");
|
||||
await ContentTask.spawn(browser,
|
||||
{ page: TEST_3RD_PARTY_PAGE,
|
||||
blockingCallback: (async _ => {}).toString(),
|
||||
nonBlockingCallback: (async _ => {}).toString(),
|
||||
},
|
||||
async function(obj) {
|
||||
await new content.Promise(resolve => {
|
||||
let ifr = content.document.createElement("iframe");
|
||||
ifr.onload = function() {
|
||||
info("Sending code to the 3rd party content");
|
||||
ifr.contentWindow.postMessage(obj.blockingCallback, "*");
|
||||
};
|
||||
|
||||
content.addEventListener("message", function msg(event) {
|
||||
if (event.data.type == "finish") {
|
||||
content.removeEventListener("message", msg);
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.data.type == "ok") {
|
||||
ok(event.data.what, event.data.msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.data.type == "info") {
|
||||
info(event.data.msg);
|
||||
return;
|
||||
}
|
||||
|
||||
ok(false, "Unknown message");
|
||||
});
|
||||
|
||||
content.document.body.appendChild(ifr);
|
||||
ifr.src = obj.page;
|
||||
});
|
||||
});
|
||||
|
||||
let expectTrackerFound = item => {
|
||||
is(item[0], Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT,
|
||||
"Correct blocking type reported");
|
||||
is(item[1], true,
|
||||
"Correct blocking status reported");
|
||||
ok(item[2] >= 1,
|
||||
"Correct repeat count reported");
|
||||
};
|
||||
|
||||
let log = JSON.parse(await browser.getContentBlockingLog());
|
||||
for (let trackerOrigin in log) {
|
||||
is(trackerOrigin + "/", TEST_3RD_PARTY_DOMAIN, "Correct tracker origin must be reported");
|
||||
let originLog = log[trackerOrigin];
|
||||
is(originLog.length, 1, "We should have 1 entry in the compressed log");
|
||||
expectTrackerFound(originLog[0]);
|
||||
}
|
||||
|
||||
ContentBlocking.enableForCurrentPage();
|
||||
|
||||
// The previous function reloads the browser, so wait for it to load again!
|
||||
await BrowserTestUtils.browserLoaded(browser);
|
||||
|
||||
info("Removing the tab");
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
add_task(async function() {
|
||||
info("Cleaning up.");
|
||||
await new Promise(resolve => {
|
||||
Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
|
||||
});
|
||||
});
|
||||
|
Загрузка…
Ссылка в новой задаче