зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1157081 - Make tracking protection work when malware and phishing protections are disabled. r=sworkman
--HG-- rename : toolkit/components/url-classifier/tests/mochitest/test_privatebrowsing_trackingprotection.html => toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_bug1157081.html
This commit is contained in:
Родитель
ece36044f6
Коммит
f3ff8f21dc
|
@ -1205,7 +1205,7 @@ nsUrlClassifierDBService::Classify(nsIPrincipal* aPrincipal,
|
|||
NS_ENSURE_ARG(aPrincipal);
|
||||
NS_ENSURE_TRUE(gDbBackgroundThread, NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
if (!(mCheckMalware || mCheckPhishing)) {
|
||||
if (!(mCheckMalware || mCheckPhishing || aTrackingProtectionEnabled)) {
|
||||
*result = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -9,3 +9,4 @@ support-files =
|
|||
[test_classified_annotations.html]
|
||||
[test_allowlisted_annotations.html]
|
||||
[test_privatebrowsing_trackingprotection.html]
|
||||
[test_trackingprotection_bug1157081.html]
|
||||
|
|
|
@ -0,0 +1,138 @@
|
|||
<!DOCTYPE HTML>
|
||||
<!-- Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||
<html>
|
||||
<head>
|
||||
<title>Test Tracking Protection with and without Safe Browsing (Bug #1157081)</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 = "chrome://mochitests/content/chrome/toolkit/components/url-classifier/tests/mochitest/classifiedAnnotatedPBFrame.html"
|
||||
|
||||
Components.utils.import("resource://gre/modules/Services.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(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);
|
||||
}
|
||||
|
||||
// Add some URLs to the tracking database
|
||||
var testData = "tracking.example.com/";
|
||||
var testUpdate =
|
||||
"n:1000\ni:test-track-simple\nad:1\n" +
|
||||
"a:524:32:" + testData.length + "\n" +
|
||||
testData;
|
||||
|
||||
var badids = [
|
||||
"badscript"
|
||||
];
|
||||
|
||||
function checkLoads(aWindow, aBlocked) {
|
||||
var win = aWindow.content;
|
||||
is(win.document.getElementById("badscript").dataset.touched, aBlocked ? "no" : "yes", "Should not load tracking javascript");
|
||||
}
|
||||
|
||||
var dbService = Cc["@mozilla.org/url-classifier/dbservice;1"]
|
||||
.getService(Ci.nsIUrlClassifierDBService);
|
||||
|
||||
function doUpdate(update) {
|
||||
var listener = {
|
||||
QueryInterface: function(iid)
|
||||
{
|
||||
if (iid.equals(Ci.nsISupports) ||
|
||||
iid.equals(Ci.nsIUrlClassifierUpdateObserver))
|
||||
return this;
|
||||
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
},
|
||||
updateUrlRequested: function(url) { },
|
||||
streamFinished: function(status) { },
|
||||
updateError: function(errorCode) {
|
||||
ok(false, "Couldn't update classifier.");
|
||||
// Abort test.
|
||||
SimpleTest.finish();
|
||||
},
|
||||
updateSuccess: function(requestedTimeout) {
|
||||
// Safe Browsing turned OFF, tracking protection should work nevertheless
|
||||
testOnWindow(function(aWindow) {
|
||||
checkLoads(aWindow, true);
|
||||
aWindow.close();
|
||||
|
||||
// Safe Browsing turned ON, tracking protection should still work
|
||||
SpecialPowers.setBoolPref("browser.safebrowsing.enabled", true);
|
||||
testOnWindow(function(aWindow) {
|
||||
checkLoads(aWindow, true);
|
||||
aWindow.close();
|
||||
SimpleTest.finish();
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
dbService.beginUpdate(listener, "test-track-simple", "");
|
||||
dbService.beginStream("", "");
|
||||
dbService.updateStream(update);
|
||||
dbService.finishStream();
|
||||
dbService.finishUpdate();
|
||||
}
|
||||
|
||||
SpecialPowers.pushPrefEnv(
|
||||
{"set" : [["urlclassifier.trackingTable", "test-track-simple"],
|
||||
["privacy.trackingprotection.enabled", true],
|
||||
["browser.safebrowsing.malware.enabled", false],
|
||||
["browser.safebrowsing.enabled", false],
|
||||
["channelclassifier.allowlist_example", true]]},
|
||||
function() { doUpdate(testUpdate); });
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
</script>
|
||||
|
||||
</pre>
|
||||
<iframe id="testFrame" width="100%" height="100%" onload=""></iframe>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче