Loading toolkit/components/url-classifier/tests/mochitest/test_privatebrowsing_trackingprotection.html +46 −40 Original line number Diff line number Diff line Loading @@ -23,8 +23,9 @@ 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}); function testOnWindow(aPrivate) { return new Promise((resolve, reject) => { let win = mainWindow.OpenBrowserWindow({private: aPrivate}); win.addEventListener("load", function() { TestUtils.topicObserved("browser-delayed-startup-finished", subject => subject == win).then(() => { Loading @@ -37,12 +38,17 @@ function testOnWindow(aPrivate, aCallback) { win.content.addEventListener("load", function innerLoad2() { win.content.removeEventListener("load", innerLoad2); SimpleTest.executeSoon(function() { aCallback(win); }); SimpleTest.executeSoon(function() { resolve(win); }); }, false, true); }, true); SimpleTest.executeSoon(function() { win.gBrowser.loadURI(contentPage); }); SimpleTest.executeSoon(function() { win.gBrowser.loadURI(contentPage); }); }); }, {capture: true, once: true}); }); } var badids = [ Loading Loading @@ -102,29 +108,29 @@ SpecialPowers.pushPrefEnv( ["privacy.trackingprotection.pbmode.enabled", true]]}, test); function test() { async function test() { SimpleTest.registerCleanupFunction(UrlClassifierTestUtils.cleanupTestTrackers); UrlClassifierTestUtils.addTestTrackers().then(() => { await UrlClassifierTestUtils.addTestTrackers(); // Normal mode, with the pref (trackers should be loaded) testOnWindow(false, function(aWindow) { await testOnWindow(false).then(function(aWindow) { checkLoads(aWindow, false); aWindow.close(); }); // Private Browsing, with the pref (trackers should be blocked) testOnWindow(true, function(aWindow1) { checkLoads(aWindow1, true); aWindow1.close(); await testOnWindow(true).then(function(aWindow) { checkLoads(aWindow, true); aWindow.close(); }); // Private Browsing, without the pref (trackers should be loaded) SpecialPowers.setBoolPref("privacy.trackingprotection.pbmode.enabled", false); testOnWindow(true, function(aWindow2) { checkLoads(aWindow2, false); aWindow2.close(); SimpleTest.finish(); }); }); }); await SpecialPowers.setBoolPref("privacy.trackingprotection.pbmode.enabled", false); await testOnWindow(true).then(function(aWindow) { checkLoads(aWindow, false); aWindow.close(); }); SimpleTest.finish(); } SimpleTest.waitForExplicitFinish(); Loading toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_whitelist.html +47 −42 Original line number Diff line number Diff line Loading @@ -24,7 +24,8 @@ ChromeUtils.import("resource://gre/modules/Services.jsm"); ChromeUtils.import("resource://testing-common/UrlClassifierTestUtils.jsm"); ChromeUtils.import("resource://testing-common/TestUtils.jsm"); function testOnWindow(contentPage, aCallback) { function testOnWindow(contentPage) { return new Promise((resolve, reject) => { var win = mainWindow.OpenBrowserWindow(); win.addEventListener("load", function() { TestUtils.topicObserved("browser-delayed-startup-finished", Loading @@ -38,12 +39,17 @@ function testOnWindow(contentPage, aCallback) { win.content.addEventListener("load", function innerLoad2() { win.content.removeEventListener("load", innerLoad2); SimpleTest.executeSoon(function() { aCallback(win); }); SimpleTest.executeSoon(function() { resolve(win); }); }, false, true); }, true); SimpleTest.executeSoon(function() { win.gBrowser.loadURI(contentPage); }); SimpleTest.executeSoon(function() { win.gBrowser.loadURI(contentPage); }); }); }, {capture: true, once: true}); }); } var alwaysbadids = [ Loading Loading @@ -99,32 +105,31 @@ SpecialPowers.pushPrefEnv( ["channelclassifier.allowlist_example", true]]}, test); function test() { async function test() { SimpleTest.registerCleanupFunction(UrlClassifierTestUtils.cleanupTestTrackers); UrlClassifierTestUtils.addTestTrackers().then(() => { await UrlClassifierTestUtils.addTestTrackers(); // Load the test from a URL on the whitelist testOnWindow(contentPage1, function(aWindow) { await testOnWindow(contentPage1).then(function(aWindow) { checkLoads(aWindow, true); aWindow.close(); }); // Load the test from a URL that's NOT on the whitelist testOnWindow(contentPage2, function(aWindow1) { checkLoads(aWindow1, false); aWindow1.close(); await testOnWindow(contentPage2).then(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(aWindow2) { checkLoads(aWindow2, false); aWindow2.close(); SimpleTest.finish(); }); await SpecialPowers.setCharPref("urlclassifier.trackingWhitelistTable", ""); await testOnWindow(contentPage1).then(function(aWindow) { checkLoads(aWindow, false); aWindow.close(); }); await SpecialPowers.clearUserPref("urlclassifier.trackingWhitelistTable"); }); }); }); SimpleTest.finish(); } SimpleTest.waitForExplicitFinish(); Loading Loading
toolkit/components/url-classifier/tests/mochitest/test_privatebrowsing_trackingprotection.html +46 −40 Original line number Diff line number Diff line Loading @@ -23,8 +23,9 @@ 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}); function testOnWindow(aPrivate) { return new Promise((resolve, reject) => { let win = mainWindow.OpenBrowserWindow({private: aPrivate}); win.addEventListener("load", function() { TestUtils.topicObserved("browser-delayed-startup-finished", subject => subject == win).then(() => { Loading @@ -37,12 +38,17 @@ function testOnWindow(aPrivate, aCallback) { win.content.addEventListener("load", function innerLoad2() { win.content.removeEventListener("load", innerLoad2); SimpleTest.executeSoon(function() { aCallback(win); }); SimpleTest.executeSoon(function() { resolve(win); }); }, false, true); }, true); SimpleTest.executeSoon(function() { win.gBrowser.loadURI(contentPage); }); SimpleTest.executeSoon(function() { win.gBrowser.loadURI(contentPage); }); }); }, {capture: true, once: true}); }); } var badids = [ Loading Loading @@ -102,29 +108,29 @@ SpecialPowers.pushPrefEnv( ["privacy.trackingprotection.pbmode.enabled", true]]}, test); function test() { async function test() { SimpleTest.registerCleanupFunction(UrlClassifierTestUtils.cleanupTestTrackers); UrlClassifierTestUtils.addTestTrackers().then(() => { await UrlClassifierTestUtils.addTestTrackers(); // Normal mode, with the pref (trackers should be loaded) testOnWindow(false, function(aWindow) { await testOnWindow(false).then(function(aWindow) { checkLoads(aWindow, false); aWindow.close(); }); // Private Browsing, with the pref (trackers should be blocked) testOnWindow(true, function(aWindow1) { checkLoads(aWindow1, true); aWindow1.close(); await testOnWindow(true).then(function(aWindow) { checkLoads(aWindow, true); aWindow.close(); }); // Private Browsing, without the pref (trackers should be loaded) SpecialPowers.setBoolPref("privacy.trackingprotection.pbmode.enabled", false); testOnWindow(true, function(aWindow2) { checkLoads(aWindow2, false); aWindow2.close(); SimpleTest.finish(); }); }); }); await SpecialPowers.setBoolPref("privacy.trackingprotection.pbmode.enabled", false); await testOnWindow(true).then(function(aWindow) { checkLoads(aWindow, false); aWindow.close(); }); SimpleTest.finish(); } SimpleTest.waitForExplicitFinish(); Loading
toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_whitelist.html +47 −42 Original line number Diff line number Diff line Loading @@ -24,7 +24,8 @@ ChromeUtils.import("resource://gre/modules/Services.jsm"); ChromeUtils.import("resource://testing-common/UrlClassifierTestUtils.jsm"); ChromeUtils.import("resource://testing-common/TestUtils.jsm"); function testOnWindow(contentPage, aCallback) { function testOnWindow(contentPage) { return new Promise((resolve, reject) => { var win = mainWindow.OpenBrowserWindow(); win.addEventListener("load", function() { TestUtils.topicObserved("browser-delayed-startup-finished", Loading @@ -38,12 +39,17 @@ function testOnWindow(contentPage, aCallback) { win.content.addEventListener("load", function innerLoad2() { win.content.removeEventListener("load", innerLoad2); SimpleTest.executeSoon(function() { aCallback(win); }); SimpleTest.executeSoon(function() { resolve(win); }); }, false, true); }, true); SimpleTest.executeSoon(function() { win.gBrowser.loadURI(contentPage); }); SimpleTest.executeSoon(function() { win.gBrowser.loadURI(contentPage); }); }); }, {capture: true, once: true}); }); } var alwaysbadids = [ Loading Loading @@ -99,32 +105,31 @@ SpecialPowers.pushPrefEnv( ["channelclassifier.allowlist_example", true]]}, test); function test() { async function test() { SimpleTest.registerCleanupFunction(UrlClassifierTestUtils.cleanupTestTrackers); UrlClassifierTestUtils.addTestTrackers().then(() => { await UrlClassifierTestUtils.addTestTrackers(); // Load the test from a URL on the whitelist testOnWindow(contentPage1, function(aWindow) { await testOnWindow(contentPage1).then(function(aWindow) { checkLoads(aWindow, true); aWindow.close(); }); // Load the test from a URL that's NOT on the whitelist testOnWindow(contentPage2, function(aWindow1) { checkLoads(aWindow1, false); aWindow1.close(); await testOnWindow(contentPage2).then(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(aWindow2) { checkLoads(aWindow2, false); aWindow2.close(); SimpleTest.finish(); }); await SpecialPowers.setCharPref("urlclassifier.trackingWhitelistTable", ""); await testOnWindow(contentPage1).then(function(aWindow) { checkLoads(aWindow, false); aWindow.close(); }); await SpecialPowers.clearUserPref("urlclassifier.trackingWhitelistTable"); }); }); }); SimpleTest.finish(); } SimpleTest.waitForExplicitFinish(); Loading