Bug 1522565 - Tests for cryptominers and fingerprinters sub-panels. r=nhnt11

Differential Revision: https://phabricator.services.mozilla.com/D18827

--HG--
extra : rebase_source : f1e874a43c204f807259cc5249d4e872e25fba26
This commit is contained in:
Johann Hofmann 2019-02-06 14:12:20 +01:00
parent 5343085d4c
commit 731692a30b
8 changed files with 236 additions and 31 deletions

View File

@ -17,11 +17,13 @@ support-files =
[browser_trackingUI_appMenu.js]
[browser_trackingUI_categories.js]
[browser_trackingUI_cookies_subview.js]
[browser_trackingUI_cryptominers.js]
[browser_trackingUI_fetch.js]
support-files =
file_trackingUI_fetch.html
file_trackingUI_fetch.js
file_trackingUI_fetch.js^headers^
[browser_trackingUI_fingerprinters.js]
[browser_trackingUI_open_preferences.js]
[browser_trackingUI_pbmode_exceptions.js]
[browser_trackingUI_report_breakage.js]

View File

@ -0,0 +1,101 @@
/* eslint-disable mozilla/no-arbitrary-setTimeout */
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TRACKING_PAGE = "http://example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
const CM_PREF = "privacy.trackingprotection.cryptomining.enabled";
add_task(async function setup() {
await SpecialPowers.pushPrefEnv({set: [
[ ContentBlocking.prefIntroCount, ContentBlocking.MAX_INTROS ],
[ "urlclassifier.features.cryptomining.blacklistHosts", "cryptomining.example.com" ],
[ "privacy.trackingprotection.enabled", false ],
[ "privacy.trackingprotection.annotate_channels", false ],
[ "privacy.trackingprotection.fingerprinting.enabled", false ],
]});
});
async function testIdentityState(hasException) {
let promise = BrowserTestUtils.openNewForegroundTab({url: TRACKING_PAGE, gBrowser});
let [tab] = await Promise.all([promise, waitForContentBlockingEvent()]);
ok(!ContentBlocking.content.hasAttribute("detected"), "cryptominers are not detected");
ok(BrowserTestUtils.is_hidden(ContentBlocking.iconBox), "icon box is not visible");
promise = waitForContentBlockingEvent();
await ContentTask.spawn(tab.linkedBrowser, {}, function() {
content.postMessage("cryptomining", "*");
});
await promise;
ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected");
ok(BrowserTestUtils.is_visible(ContentBlocking.iconBox), "icon box is visible");
is(ContentBlocking.iconBox.hasAttribute("hasException"), hasException,
"Shows an exception when appropriate");
BrowserTestUtils.removeTab(tab);
}
async function testSubview(hasException) {
let promise = BrowserTestUtils.openNewForegroundTab({url: TRACKING_PAGE, gBrowser});
let [tab] = await Promise.all([promise, waitForContentBlockingEvent()]);
promise = waitForContentBlockingEvent();
await ContentTask.spawn(tab.linkedBrowser, {}, function() {
content.postMessage("cryptomining", "*");
});
await promise;
await openIdentityPopup();
let categoryItem =
document.getElementById("identity-popup-content-blocking-category-cryptominers");
ok(BrowserTestUtils.is_visible(categoryItem), "TP category item is visible");
let subview = document.getElementById("identity-popup-cryptominersView");
let viewShown = BrowserTestUtils.waitForEvent(subview, "ViewShown");
categoryItem.click();
await viewShown;
let listItems = subview.querySelectorAll(".identity-popup-content-blocking-list-item");
is(listItems.length, 1, "We have 1 item in the list");
let listItem = listItems[0];
ok(BrowserTestUtils.is_visible(listItem), "List item is visible");
is(listItem.querySelector("label").value, "cryptomining.example.com", "Has the correct host");
is(listItem.classList.contains("allowed"), hasException,
"Indicates the miner was blocked or allowed");
let mainView = document.getElementById("identity-popup-mainView");
viewShown = BrowserTestUtils.waitForEvent(mainView, "ViewShown");
let backButton = subview.querySelector(".subviewbutton-back");
backButton.click();
await viewShown;
ok(true, "Main view was shown");
BrowserTestUtils.removeTab(tab);
}
add_task(async function test() {
let uri = Services.io.newURI("https://example.org");
Services.prefs.setBoolPref(CM_PREF, true);
await testIdentityState(false);
Services.perms.add(uri, "trackingprotection", Services.perms.ALLOW_ACTION);
// TODO: This currently fails because of bug 1525458, fixing should allow us to re-enable it.
// await testIdentityState(true);
Services.perms.remove(uri, "trackingprotection");
await testSubview(false);
Services.perms.add(uri, "trackingprotection", Services.perms.ALLOW_ACTION);
// TODO: This currently fails because of bug 1525458, fixing should allow us to re-enable it.
// await testSubview(true);
Services.perms.remove(uri, "trackingprotection");
Services.prefs.clearUserPref(CM_PREF);
});

View File

@ -0,0 +1,101 @@
/* eslint-disable mozilla/no-arbitrary-setTimeout */
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TRACKING_PAGE = "http://example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
const FP_PREF = "privacy.trackingprotection.fingerprinting.enabled";
add_task(async function setup() {
await SpecialPowers.pushPrefEnv({set: [
[ ContentBlocking.prefIntroCount, ContentBlocking.MAX_INTROS ],
[ "urlclassifier.features.fingerprinting.blacklistHosts", "fingerprinting.example.com" ],
[ "privacy.trackingprotection.enabled", false ],
[ "privacy.trackingprotection.annotate_channels", false ],
[ "privacy.trackingprotection.cryptomining.enabled", false ],
]});
});
async function testIdentityState(hasException) {
let promise = BrowserTestUtils.openNewForegroundTab({url: TRACKING_PAGE, gBrowser});
let [tab] = await Promise.all([promise, waitForContentBlockingEvent()]);
ok(!ContentBlocking.content.hasAttribute("detected"), "fingerprinters are not detected");
ok(BrowserTestUtils.is_hidden(ContentBlocking.iconBox), "icon box is not visible");
promise = waitForContentBlockingEvent();
await ContentTask.spawn(tab.linkedBrowser, {}, function() {
content.postMessage("fingerprinting", "*");
});
await promise;
ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected");
ok(BrowserTestUtils.is_visible(ContentBlocking.iconBox), "icon box is visible");
is(ContentBlocking.iconBox.hasAttribute("hasException"), hasException,
"Shows an exception when appropriate");
BrowserTestUtils.removeTab(tab);
}
async function testSubview(hasException) {
let promise = BrowserTestUtils.openNewForegroundTab({url: TRACKING_PAGE, gBrowser});
let [tab] = await Promise.all([promise, waitForContentBlockingEvent()]);
promise = waitForContentBlockingEvent();
await ContentTask.spawn(tab.linkedBrowser, {}, function() {
content.postMessage("fingerprinting", "*");
});
await promise;
await openIdentityPopup();
let categoryItem =
document.getElementById("identity-popup-content-blocking-category-fingerprinters");
ok(BrowserTestUtils.is_visible(categoryItem), "TP category item is visible");
let subview = document.getElementById("identity-popup-fingerprintersView");
let viewShown = BrowserTestUtils.waitForEvent(subview, "ViewShown");
categoryItem.click();
await viewShown;
let listItems = subview.querySelectorAll(".identity-popup-content-blocking-list-item");
is(listItems.length, 1, "We have 1 item in the list");
let listItem = listItems[0];
ok(BrowserTestUtils.is_visible(listItem), "List item is visible");
is(listItem.querySelector("label").value, "fingerprinting.example.com", "Has the correct host");
is(listItem.classList.contains("allowed"), hasException,
"Indicates the fingerprinter was blocked or allowed");
let mainView = document.getElementById("identity-popup-mainView");
viewShown = BrowserTestUtils.waitForEvent(mainView, "ViewShown");
let backButton = subview.querySelector(".subviewbutton-back");
backButton.click();
await viewShown;
ok(true, "Main view was shown");
BrowserTestUtils.removeTab(tab);
}
add_task(async function test() {
let uri = Services.io.newURI("https://example.org");
Services.prefs.setBoolPref(FP_PREF, true);
await testIdentityState(false);
Services.perms.add(uri, "trackingprotection", Services.perms.ALLOW_ACTION);
// TODO: This currently fails because of bug 1525458, fixing should allow us to re-enable it.
// await testIdentityState(true);
Services.perms.remove(uri, "trackingprotection");
await testSubview(false);
Services.perms.add(uri, "trackingprotection", Services.perms.ALLOW_ACTION);
// TODO: This currently fails because of bug 1525458, fixing should allow us to re-enable it.
// await testSubview(true);
Services.perms.remove(uri, "trackingprotection");
Services.prefs.clearUserPref(FP_PREF);
});

View File

@ -1,44 +1,41 @@
function createIframe(src) {
let ifr = document.createElement("iframe");
ifr.src = src;
document.body.appendChild(ifr);
}
onmessage = event => {
switch (event.data) {
case "tracking": {
let ifr = document.createElement("iframe");
ifr.src = "https://trackertest.org/";
document.body.appendChild(ifr);
}
case "tracking":
createIframe("https://trackertest.org/");
break;
case "more-tracking": {
let ifr = document.createElement("iframe");
ifr.src = "https://itisatracker.org/";
document.body.appendChild(ifr);
}
case "cryptomining":
createIframe("http://cryptomining.example.com/");
break;
case "cookie": {
let ifr = document.createElement("iframe");
ifr.src = "https://trackertest.org/browser/browser/base/content/test/trackingUI/cookieServer.sjs";
document.body.appendChild(ifr);
}
case "fingerprinting":
createIframe("https://fingerprinting.example.com/");
break;
case "first-party-cookie": {
// Since the content blocking log doesn't seem to get updated for
// top-level cookies right now, we just create an iframe with the
// first party domain...
let ifr = document.createElement("iframe");
ifr.src = "http://not-tracking.example.com/browser/browser/base/content/test/trackingUI/cookieServer.sjs";
document.body.appendChild(ifr);
}
case "more-tracking":
createIframe("https://itisatracker.org/");
break;
case "third-party-cookie": {
let ifr = document.createElement("iframe");
ifr.src = "https://test1.example.org/browser/browser/base/content/test/trackingUI/cookieServer.sjs";
document.body.appendChild(ifr);
}
case "cookie":
createIframe("https://trackertest.org/browser/browser/base/content/test/trackingUI/cookieServer.sjs");
break;
case "first-party-cookie":
// Since the content blocking log doesn't seem to get updated for
// top-level cookies right now, we just create an iframe with the
// first party domain...
createIframe("http://not-tracking.example.com/browser/browser/base/content/test/trackingUI/cookieServer.sjs");
break;
case "third-party-cookie":
createIframe("https://test1.example.org/browser/browser/base/content/test/trackingUI/cookieServer.sjs");
break;
case "window-open":
window.win = window.open("http://trackertest.org/browser/browser/base/content/test/trackingUI/cookieServer.sjs", "_blank", "width=100,height=100");
window.win = window.open("http://trackertest.org/browser/browser/base/content/test/trackingUI/cookieServer.sjs", "_blank", "width=100,height=100");
break;
case "window-close":
window.win.close();
window.win = null;
window.win.close();
window.win = null;
break;
}
};

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -167,6 +167,8 @@ https://sub.sectest1.example.org:443
http://malware.example.com:80
http://unwanted.example.com:80
http://tracking.example.com:80
http://cryptomining.example.com:80
http://fingerprinting.example.com:80
http://not-tracking.example.com:80
http://tracking.example.org:80
http://another-tracking.example.net:80
@ -177,6 +179,8 @@ http://trackertest.org:80
https://malware.example.com:443
https://unwanted.example.com:443
https://tracking.example.com:443
https://cryptomining.example.com:443
https://fingerprinting.example.com:443
https://not-tracking.example.com:443
https://tracking.example.org:443
https://another-tracking.example.net:443