diff options
Diffstat (limited to 'toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_whitelist.html')
-rw-r--r-- | toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_whitelist.html | 153 |
1 files changed, 0 insertions, 153 deletions
diff --git a/toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_whitelist.html b/toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_whitelist.html deleted file mode 100644 index 29de0dfed..000000000 --- a/toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_whitelist.html +++ /dev/null @@ -1,153 +0,0 @@ -<!DOCTYPE HTML> -<!-- Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ --> -<html> -<head> - <title>Test Tracking Protection in Private Browsing mode</title> - <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> - <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> -</head> - -<body> -<p id="display"></p> -<div id="content" style="display: none"> -</div> -<pre id="test"> - -<script class="testbody" type="text/javascript"> - -var Cc = SpecialPowers.Cc; -var Ci = SpecialPowers.Ci; - -var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIWebNavigation) - .QueryInterface(Ci.nsIDocShellTreeItem) - .rootTreeItem - .QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIDOMWindow); -var contentPage1 = "http://www.itisatrap.org/tests/toolkit/components/url-classifier/tests/mochitest/whitelistFrame.html"; -var contentPage2 = "http://example.com/tests/toolkit/components/url-classifier/tests/mochitest/whitelistFrame.html"; - -Components.utils.import("resource://gre/modules/Services.jsm"); -Components.utils.import("resource://testing-common/UrlClassifierTestUtils.jsm"); - -function whenDelayedStartupFinished(aWindow, aCallback) { - Services.obs.addObserver(function observer(aSubject, aTopic) { - if (aWindow == aSubject) { - Services.obs.removeObserver(observer, aTopic); - setTimeout(aCallback, 0); - } - }, "browser-delayed-startup-finished", false); -} - -function testOnWindow(contentPage, aCallback) { - var win = mainWindow.OpenBrowserWindow(); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - whenDelayedStartupFinished(win, function() { - win.addEventListener("DOMContentLoaded", function onInnerLoad() { - if (win.content.location.href != contentPage) { - win.gBrowser.loadURI(contentPage); - return; - } - win.removeEventListener("DOMContentLoaded", onInnerLoad, true); - - win.content.addEventListener('load', function innerLoad2() { - win.content.removeEventListener('load', innerLoad2, false); - SimpleTest.executeSoon(function() { aCallback(win); }); - }, false, true); - }, true); - SimpleTest.executeSoon(function() { win.gBrowser.loadURI(contentPage); }); - }); - }, true); -} - -var alwaysbadids = [ - "badscript", -]; - -function checkLoads(aWindow, aWhitelisted) { - var win = aWindow.content; - is(win.document.getElementById("badscript").dataset.touched, "no", "Should not load tracking javascript"); - is(win.document.getElementById("goodscript").dataset.touched, aWhitelisted ? "yes" : "no", "Should load whitelisted tracking javascript"); - - var badids = alwaysbadids.slice(); - if (!aWhitelisted) { - badids.push("goodscript"); - } - is(win.document.blockedTrackingNodeCount, badids.length, "Should identify all tracking elements"); - - var blockedTrackingNodes = win.document.blockedTrackingNodes; - - // Make sure that every node in blockedTrackingNodes exists in the tree - // (that may not always be the case but do not expect any nodes to disappear - // from the tree here) - var allNodeMatch = true; - for (var i = 0; i < blockedTrackingNodes.length; i++) { - var nodeMatch = false; - for (var j = 0; j < badids.length && !nodeMatch; j++) { - nodeMatch = nodeMatch || - (blockedTrackingNodes[i] == win.document.getElementById(badids[j])); - } - - allNodeMatch = allNodeMatch && nodeMatch; - } - is(allNodeMatch, true, "All annotated nodes are expected in the tree"); - - // Make sure that every node with a badid (see badids) is found in the - // blockedTrackingNodes. This tells us if we are neglecting to annotate - // some nodes - allNodeMatch = true; - for (var j = 0; j < badids.length; j++) { - var nodeMatch = false; - for (var i = 0; i < blockedTrackingNodes.length && !nodeMatch; i++) { - nodeMatch = nodeMatch || - (blockedTrackingNodes[i] == win.document.getElementById(badids[j])); - } - - allNodeMatch = allNodeMatch && nodeMatch; - } - is(allNodeMatch, true, "All tracking nodes are expected to be annotated as such"); -} - -SpecialPowers.pushPrefEnv( - {"set" : [["privacy.trackingprotection.enabled", true], - ["channelclassifier.allowlist_example", true]]}, - test); - -function test() { - SimpleTest.registerCleanupFunction(UrlClassifierTestUtils.cleanupTestTrackers); - UrlClassifierTestUtils.addTestTrackers().then(() => { - // Load the test from a URL on the whitelist - testOnWindow(contentPage1, function(aWindow) { - checkLoads(aWindow, true); - aWindow.close(); - - // Load the test from a URL that's NOT on the whitelist - testOnWindow(contentPage2, function(aWindow) { - checkLoads(aWindow, false); - aWindow.close(); - - // Load the test from a URL on the whitelist but without the whitelist - SpecialPowers.pushPrefEnv({"set" : [["urlclassifier.trackingWhitelistTable", ""]]}, - function() { - testOnWindow(contentPage1, function(aWindow) { - checkLoads(aWindow, false); - aWindow.close(); - SimpleTest.finish(); - }); - }); - - }); - }); - }); -} - -SimpleTest.waitForExplicitFinish(); - -</script> - -</pre> -<iframe id="testFrame" width="100%" height="100%" onload=""></iframe> -</body> -</html> |