1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
<!DOCTYPE HTML>
<!-- Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ -->
<html>
<head>
<title>Test Bug 1312515</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 contentPage = "http://www.itisatrap.org/tests/toolkit/components/url-classifier/tests/mochitest/trackingRequest.html";
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://testing-common/UrlClassifierTestUtils.jsm");
ChromeUtils.import("resource://testing-common/TestUtils.jsm");
function testOnWindow(aPrivate, aCallback) {
var win = mainWindow.OpenBrowserWindow({private: aPrivate});
win.addEventListener("load", function() {
TestUtils.topicObserved("browser-delayed-startup-finished",
subject => subject == win).then(() => {
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);
SimpleTest.executeSoon(function() { aCallback(win); });
}, false, true);
}, true);
SimpleTest.executeSoon(function() { win.gBrowser.loadURI(contentPage); });
});
}, {capture: true, once: true});
}
const topic = "http-on-opening-request";
var testUrl;
var testWindow;
var resolve;
function checkLowestPriority(aSubject) {
var channel = aSubject.QueryInterface(Ci.nsIChannel);
info("Channel's url=" + channel.name);
if (channel.name !== testUrl) {
return;
}
var p = aSubject.QueryInterface(Ci.nsISupportsPriority);
is(p.priority, Ci.nsISupportsPriority.PRIORITY_LOWEST, "Priority should be lowest.");
SpecialPowers.removeObserver(checkLowestPriority, topic);
resolve();
}
function testXHR() {
return new Promise(function(aResolve, aReject) {
resolve = aResolve;
SpecialPowers.addObserver(checkLowestPriority, topic);
testUrl = "http://mochi.test:8888/";
testWindow.content.postMessage({type: "doXHR", url: testUrl}, "*");
});
}
function testFetch() {
return new Promise(function(aResolve, aReject) {
resolve = aResolve;
SpecialPowers.addObserver(checkLowestPriority, topic);
testUrl = "http://itisatracker.org/";
testWindow.content.postMessage({type: "doFetch", url: testUrl}, "*");
});
}
function endTest() {
testWindow.close();
testWindow = null;
SimpleTest.finish();
}
SpecialPowers.pushPrefEnv(
{"set": [["urlclassifier.trackingTable", "test-track-simple"],
["privacy.trackingprotection.annotate_channels", true],
["privacy.trackingprotection.lower_network_priority", true],
["channelclassifier.allowlist_example", true]]},
test);
function test() {
SimpleTest.registerCleanupFunction(UrlClassifierTestUtils.cleanupTestTrackers);
UrlClassifierTestUtils.addTestTrackers().then(() => {
testOnWindow(false, function(aWindow) {
testWindow = aWindow;
testXHR().
then(testFetch).
then(endTest);
});
});
}
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>
|