зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1178985 - Show tracking protection section in control center when enabled in private browsing mode;r=ttaubert
--HG-- extra : commitid : BOvYMkPSkBl
This commit is contained in:
Родитель
23db38b143
Коммит
20cdff0134
|
@ -3,7 +3,10 @@
|
|||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
let TrackingProtection = {
|
||||
PREF_ENABLED: "privacy.trackingprotection.enabled",
|
||||
PREF_ENABLED_GLOBALLY: "privacy.trackingprotection.enabled",
|
||||
PREF_ENABLED_IN_PRIVATE_WINDOWS: "privacy.trackingprotection.pbmode.enabled",
|
||||
enabledGlobally: false,
|
||||
enabledInPrivateWindows: false,
|
||||
|
||||
init() {
|
||||
let $ = selector => document.querySelector(selector);
|
||||
|
@ -11,21 +14,32 @@ let TrackingProtection = {
|
|||
this.content = $("#tracking-protection-content");
|
||||
|
||||
this.updateEnabled();
|
||||
Services.prefs.addObserver(this.PREF_ENABLED, this, false);
|
||||
Services.prefs.addObserver(this.PREF_ENABLED_GLOBALLY, this, false);
|
||||
Services.prefs.addObserver(this.PREF_ENABLED_IN_PRIVATE_WINDOWS, this, false);
|
||||
|
||||
this.enabledHistogram.add(this.enabled);
|
||||
this.enabledHistogram.add(this.enabledGlobally);
|
||||
},
|
||||
|
||||
uninit() {
|
||||
Services.prefs.removeObserver(this.PREF_ENABLED, this);
|
||||
Services.prefs.removeObserver(this.PREF_ENABLED_GLOBALLY, this);
|
||||
Services.prefs.removeObserver(this.PREF_ENABLED_IN_PRIVATE_WINDOWS, this);
|
||||
},
|
||||
|
||||
observe() {
|
||||
this.updateEnabled();
|
||||
},
|
||||
|
||||
get enabled() {
|
||||
return this.enabledGlobally ||
|
||||
(this.enabledInPrivateWindows &&
|
||||
PrivateBrowsingUtils.isWindowPrivate(window));
|
||||
},
|
||||
|
||||
updateEnabled() {
|
||||
this.enabled = Services.prefs.getBoolPref(this.PREF_ENABLED);
|
||||
this.enabledGlobally =
|
||||
Services.prefs.getBoolPref(this.PREF_ENABLED_GLOBALLY);
|
||||
this.enabledInPrivateWindows =
|
||||
Services.prefs.getBoolPref(this.PREF_ENABLED_IN_PRIVATE_WINDOWS);
|
||||
this.container.hidden = !this.enabled;
|
||||
},
|
||||
|
||||
|
|
|
@ -413,6 +413,10 @@ support-files =
|
|||
trackingPage.html
|
||||
benignPage.html
|
||||
[browser_trackingUI_2.js]
|
||||
support-files =
|
||||
trackingPage.html
|
||||
benignPage.html
|
||||
[browser_trackingUI_3.js]
|
||||
support-files =
|
||||
trackingPage.html
|
||||
benignPage.html
|
||||
|
|
|
@ -7,34 +7,40 @@
|
|||
// * A page with no tracking elements is loaded.
|
||||
// * A page with tracking elements is loaded and they are blocked.
|
||||
// * A page with tracking elements is loaded and they are not blocked.
|
||||
// See also Bugs 1175327 and 1043801.
|
||||
// See also Bugs 1175327, 1043801, 1178985
|
||||
|
||||
let PREF = "privacy.trackingprotection.enabled";
|
||||
let BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/general/benignPage.html";
|
||||
let TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/general/trackingPage.html";
|
||||
const PREF = "privacy.trackingprotection.enabled";
|
||||
const PB_PREF = "privacy.trackingprotection.pbmode.enabled";
|
||||
const BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/general/benignPage.html";
|
||||
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/general/trackingPage.html";
|
||||
let TrackingProtection = null;
|
||||
let browser = null;
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
TrackingProtection = null;
|
||||
TrackingProtection = browser = null;
|
||||
Services.prefs.clearUserPref(PREF);
|
||||
gBrowser.removeCurrentTab();
|
||||
Services.prefs.clearUserPref(PB_PREF);
|
||||
while (gBrowser.tabs.length > 1) {
|
||||
gBrowser.removeCurrentTab();
|
||||
}
|
||||
});
|
||||
|
||||
function hidden(sel) {
|
||||
let win = gBrowser.ownerGlobal;
|
||||
let win = browser.ownerGlobal;
|
||||
let el = win.document.querySelector(sel);
|
||||
let display = win.getComputedStyle(el).getPropertyValue("display", null);
|
||||
return display === "none";
|
||||
}
|
||||
|
||||
function clickButton(sel) {
|
||||
let win = gBrowser.ownerGlobal;
|
||||
let win = browser.ownerGlobal;
|
||||
let el = win.document.querySelector(sel);
|
||||
el.doCommand();
|
||||
}
|
||||
|
||||
function testBenignPage() {
|
||||
info("Non-tracking content must not be blocked");
|
||||
ok (!TrackingProtection.container.hidden, "The container is visible");
|
||||
ok (!TrackingProtection.content.hasAttribute("block-disabled"), "blocking not disabled");
|
||||
ok (!TrackingProtection.content.hasAttribute("block-active"), "blocking is not active");
|
||||
|
||||
|
@ -49,6 +55,7 @@ function testBenignPage() {
|
|||
|
||||
function testTrackingPage() {
|
||||
info("Tracking content must be blocked");
|
||||
ok (!TrackingProtection.container.hidden, "The container is visible");
|
||||
ok (!TrackingProtection.content.hasAttribute("block-disabled"), "blocking not disabled");
|
||||
ok (TrackingProtection.content.hasAttribute("block-active"), "blocking is active");
|
||||
|
||||
|
@ -63,6 +70,7 @@ function testTrackingPage() {
|
|||
|
||||
function testTrackingPageWhitelisted() {
|
||||
info("Tracking content must be white-listed and not blocked");
|
||||
ok (!TrackingProtection.container.hidden, "The container is visible");
|
||||
ok (TrackingProtection.content.hasAttribute("block-disabled"), "blocking is disabled");
|
||||
ok (!TrackingProtection.content.hasAttribute("block-active"), "blocking is not active");
|
||||
|
||||
|
@ -75,19 +83,7 @@ function testTrackingPageWhitelisted() {
|
|||
ok (hidden("#tracking-blocked"), "labelTrackingBlocked is hidden");
|
||||
}
|
||||
|
||||
add_task(function* () {
|
||||
yield updateTrackingProtectionDatabase();
|
||||
|
||||
let tab = gBrowser.selectedTab = gBrowser.addTab();
|
||||
|
||||
TrackingProtection = gBrowser.ownerGlobal.TrackingProtection;
|
||||
ok (TrackingProtection, "Functionality is attached to the browser window");
|
||||
is (TrackingProtection.enabled, Services.prefs.getBoolPref(PREF),
|
||||
"TP.enabled is based on the original pref value");
|
||||
|
||||
Services.prefs.setBoolPref(PREF, true);
|
||||
ok (TrackingProtection.enabled, "TP is enabled after setting the pref");
|
||||
|
||||
function* testTrackingProtectionForTab(tab) {
|
||||
info("Load a test page not containing tracking elements");
|
||||
yield promiseTabLoadEvent(tab, BENIGN_PAGE);
|
||||
testBenignPage();
|
||||
|
@ -109,4 +105,45 @@ add_task(function* () {
|
|||
info("Wait for tab to reload following TP black-listing");
|
||||
yield promiseTabLoadEvent(tab);
|
||||
testTrackingPage();
|
||||
}
|
||||
|
||||
add_task(function* testNormalBrowsing() {
|
||||
yield updateTrackingProtectionDatabase();
|
||||
|
||||
browser = gBrowser;
|
||||
let tab = browser.selectedTab = browser.addTab();
|
||||
|
||||
TrackingProtection = gBrowser.ownerGlobal.TrackingProtection;
|
||||
ok (TrackingProtection, "TP is attached to the browser window");
|
||||
is (TrackingProtection.enabled, Services.prefs.getBoolPref(PREF),
|
||||
"TP.enabled is based on the original pref value");
|
||||
|
||||
Services.prefs.setBoolPref(PREF, true);
|
||||
ok (TrackingProtection.enabled, "TP is enabled after setting the pref");
|
||||
|
||||
yield testTrackingProtectionForTab(tab);
|
||||
|
||||
Services.prefs.setBoolPref(PREF, false);
|
||||
ok (!TrackingProtection.enabled, "TP is disabled after setting the pref");
|
||||
});
|
||||
|
||||
add_task(function* testPrivateBrowsing() {
|
||||
let privateWin = yield promiseOpenAndLoadWindow({private: true}, true);
|
||||
browser = privateWin.gBrowser;
|
||||
let tab = browser.selectedTab = browser.addTab();
|
||||
|
||||
TrackingProtection = browser.ownerGlobal.TrackingProtection;
|
||||
ok (TrackingProtection, "TP is attached to the private window");
|
||||
is (TrackingProtection.enabled, Services.prefs.getBoolPref(PB_PREF),
|
||||
"TP.enabled is based on the pb pref value");
|
||||
|
||||
Services.prefs.setBoolPref(PB_PREF, true);
|
||||
ok (TrackingProtection.enabled, "TP is enabled after setting the pref");
|
||||
|
||||
yield testTrackingProtectionForTab(tab);
|
||||
|
||||
Services.prefs.setBoolPref(PB_PREF, false);
|
||||
ok (!TrackingProtection.enabled, "TP is disabled after setting the pref");
|
||||
|
||||
privateWin.close();
|
||||
});
|
||||
|
|
|
@ -4,45 +4,73 @@
|
|||
|
||||
// Test that the Tracking Protection section is never visible in the
|
||||
// Control Center when the feature is off.
|
||||
// See also Bugs 1175327 and 1043801.
|
||||
// See also Bugs 1175327, 1043801, 1178985.
|
||||
|
||||
let PREF = "privacy.trackingprotection.enabled";
|
||||
let BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/general/benignPage.html";
|
||||
let TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/general/trackingPage.html";
|
||||
const PREF = "privacy.trackingprotection.enabled";
|
||||
const PB_PREF = "privacy.trackingprotection.pbmode.enabled";
|
||||
const BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/general/benignPage.html";
|
||||
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/general/trackingPage.html";
|
||||
let TrackingProtection = null;
|
||||
let browser = null;
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
TrackingProtection = null;
|
||||
TrackingProtection = browser = null;
|
||||
Services.prefs.clearUserPref(PREF);
|
||||
gBrowser.removeCurrentTab();
|
||||
Services.prefs.clearUserPref(PB_PREF);
|
||||
while (gBrowser.tabs.length > 1) {
|
||||
gBrowser.removeCurrentTab();
|
||||
}
|
||||
});
|
||||
|
||||
function testTrackingPageOff() {
|
||||
ok (TrackingProtection.container.hidden, "The container is hidden");
|
||||
}
|
||||
|
||||
function testBenignPageOff() {
|
||||
ok (TrackingProtection.container.hidden, "The container is hidden");
|
||||
}
|
||||
|
||||
add_task(function* () {
|
||||
add_task(function* testNormalBrowsing() {
|
||||
yield updateTrackingProtectionDatabase();
|
||||
|
||||
let tab = gBrowser.selectedTab = gBrowser.addTab();
|
||||
browser = gBrowser;
|
||||
let tab = browser.selectedTab = browser.addTab();
|
||||
|
||||
TrackingProtection = gBrowser.ownerGlobal.TrackingProtection;
|
||||
TrackingProtection = browser.ownerGlobal.TrackingProtection;
|
||||
ok (TrackingProtection, "TP is attached to the browser window");
|
||||
is (TrackingProtection.enabled, Services.prefs.getBoolPref(PREF),
|
||||
"TP.enabled is based on the original pref value");
|
||||
|
||||
Services.prefs.setBoolPref(PREF, true);
|
||||
ok (TrackingProtection.enabled, "TP is enabled after setting the pref");
|
||||
|
||||
Services.prefs.setBoolPref(PREF, false);
|
||||
ok (!TrackingProtection.enabled, "TP is disabled after setting the pref");
|
||||
|
||||
info("Load a test page containing tracking elements");
|
||||
yield promiseTabLoadEvent(tab, TRACKING_PAGE);
|
||||
testTrackingPageOff();
|
||||
ok (TrackingProtection.container.hidden, "The container is hidden");
|
||||
|
||||
info("Load a test page not containing tracking elements");
|
||||
yield promiseTabLoadEvent(tab, BENIGN_PAGE);
|
||||
testBenignPageOff();
|
||||
ok (TrackingProtection.container.hidden, "The container is hidden");
|
||||
});
|
||||
|
||||
add_task(function* testPrivateBrowsing() {
|
||||
let privateWin = yield promiseOpenAndLoadWindow({private: true}, true);
|
||||
browser = privateWin.gBrowser;
|
||||
let tab = browser.selectedTab = browser.addTab();
|
||||
|
||||
TrackingProtection = browser.ownerGlobal.TrackingProtection;
|
||||
ok (TrackingProtection, "TP is attached to the private window");
|
||||
is (TrackingProtection.enabled, Services.prefs.getBoolPref(PB_PREF),
|
||||
"TP.enabled is based on the pb pref value");
|
||||
|
||||
Services.prefs.setBoolPref(PB_PREF, true);
|
||||
ok (TrackingProtection.enabled, "TP is enabled after setting the pref");
|
||||
|
||||
Services.prefs.setBoolPref(PB_PREF, false);
|
||||
ok (!TrackingProtection.enabled, "TP is disabled after setting the pref");
|
||||
|
||||
info("Load a test page containing tracking elements");
|
||||
yield promiseTabLoadEvent(tab, TRACKING_PAGE);
|
||||
ok (TrackingProtection.container.hidden, "The container is hidden");
|
||||
|
||||
info("Load a test page not containing tracking elements");
|
||||
yield promiseTabLoadEvent(tab, BENIGN_PAGE);
|
||||
ok (TrackingProtection.container.hidden, "The container is hidden");
|
||||
|
||||
privateWin.close();
|
||||
});
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// Test that the Tracking Protection is correctly enabled / disabled
|
||||
// in both normal and private windows given all possible states of the prefs:
|
||||
// privacy.trackingprotection.enabled
|
||||
// privacy.trackingprotection.pbmode.enabled
|
||||
// See also Bug 1178985.
|
||||
|
||||
const PREF = "privacy.trackingprotection.enabled";
|
||||
const PB_PREF = "privacy.trackingprotection.pbmode.enabled";
|
||||
const BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/general/benignPage.html";
|
||||
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/general/trackingPage.html";
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
Services.prefs.clearUserPref(PREF);
|
||||
Services.prefs.clearUserPref(PB_PREF);
|
||||
});
|
||||
|
||||
add_task(function* testNormalBrowsing() {
|
||||
let browser = gBrowser;
|
||||
let TrackingProtection = browser.ownerGlobal.TrackingProtection;
|
||||
ok (TrackingProtection, "TP is attached to the browser window");
|
||||
|
||||
Services.prefs.setBoolPref(PREF, true);
|
||||
Services.prefs.setBoolPref(PB_PREF, false);
|
||||
ok (TrackingProtection.enabled, "TP is enabled (ENABLED=true,PB=false)");
|
||||
Services.prefs.setBoolPref(PB_PREF, true);
|
||||
ok (TrackingProtection.enabled, "TP is enabled (ENABLED=true,PB=true)");
|
||||
|
||||
Services.prefs.setBoolPref(PREF, false);
|
||||
Services.prefs.setBoolPref(PB_PREF, false);
|
||||
ok (!TrackingProtection.enabled, "TP is disabled (ENABLED=false,PB=false)");
|
||||
Services.prefs.setBoolPref(PB_PREF, true);
|
||||
ok (!TrackingProtection.enabled, "TP is disabled (ENABLED=false,PB=true)");
|
||||
});
|
||||
|
||||
add_task(function* testPrivateBrowsing() {
|
||||
let privateWin = yield promiseOpenAndLoadWindow({private: true}, true);
|
||||
let browser = privateWin.gBrowser;
|
||||
|
||||
let TrackingProtection = browser.ownerGlobal.TrackingProtection;
|
||||
ok (TrackingProtection, "TP is attached to the browser window");
|
||||
|
||||
Services.prefs.setBoolPref(PREF, true);
|
||||
Services.prefs.setBoolPref(PB_PREF, false);
|
||||
ok (TrackingProtection.enabled, "TP is enabled (ENABLED=true,PB=false)");
|
||||
Services.prefs.setBoolPref(PB_PREF, true);
|
||||
ok (TrackingProtection.enabled, "TP is enabled (ENABLED=true,PB=true)");
|
||||
|
||||
Services.prefs.setBoolPref(PREF, false);
|
||||
Services.prefs.setBoolPref(PB_PREF, false);
|
||||
ok (!TrackingProtection.enabled, "TP is disabled (ENABLED=false,PB=false)");
|
||||
Services.prefs.setBoolPref(PB_PREF, true);
|
||||
ok (TrackingProtection.enabled, "TP is enabled (ENABLED=false,PB=true)");
|
||||
|
||||
privateWin.close();
|
||||
});
|
Загрузка…
Ссылка в новой задаче