Bug 1175858 - Style updates for browser tracking protection tests;r=MattN

This commit is contained in:
Brian Grinstead 2015-07-23 13:55:34 -07:00
parent ac1c9234ae
commit 64f58c9f56
4 changed files with 126 additions and 139 deletions

View File

@ -1,13 +1,11 @@
/* 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 section is visible in the Control Center
// and has the correct state for the cases when:
// * 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, 1043801, 1178985
/*
* Test that the Tracking Protection section is visible in the Control Center
* and has the correct state for the cases when:
* 1) A page with no tracking elements is loaded.
* 2) A page with tracking elements is loaded and they are blocked.
* 3) A page with tracking elements is loaded and they are not blocked.
* See also Bugs 1175327, 1043801, 1178985
*/
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
const PREF = "privacy.trackingprotection.enabled";
@ -15,12 +13,12 @@ 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;
let tabbrowser = null;
let {UrlClassifierTestUtils} = Cu.import("resource://testing-common/UrlClassifierTestUtils.jsm", {});
registerCleanupFunction(function() {
TrackingProtection = browser = null;
TrackingProtection = tabbrowser = null;
UrlClassifierTestUtils.cleanupTestTrackers();
Services.prefs.clearUserPref(PREF);
Services.prefs.clearUserPref(PB_PREF);
@ -30,7 +28,7 @@ registerCleanupFunction(function() {
});
function hidden(sel) {
let win = browser.ownerGlobal;
let win = tabbrowser.ownerGlobal;
let el = win.document.querySelector(sel);
let display = win.getComputedStyle(el).getPropertyValue("display", null);
let opacity = win.getComputedStyle(el).getPropertyValue("opacity", null);
@ -38,37 +36,37 @@ function hidden(sel) {
}
function clickButton(sel) {
let win = browser.ownerGlobal;
let win = tabbrowser.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("state"), "content: no state");
ok (!TrackingProtection.icon.hasAttribute("state"), "icon: no state");
ok(!TrackingProtection.container.hidden, "The container is visible");
ok(!TrackingProtection.content.hasAttribute("state"), "content: no state");
ok(!TrackingProtection.icon.hasAttribute("state"), "icon: no state");
ok (hidden("#tracking-protection-icon"), "icon is hidden");
ok (hidden("#tracking-action-block"), "blockButton is hidden");
ok (hidden("#tracking-action-unblock"), "unblockButton is hidden");
ok(hidden("#tracking-protection-icon"), "icon is hidden");
ok(hidden("#tracking-action-block"), "blockButton is hidden");
ok(hidden("#tracking-action-unblock"), "unblockButton is hidden");
// Make sure that the no tracking elements message appears
ok (!hidden("#tracking-not-detected"), "labelNoTracking is visible");
ok (hidden("#tracking-loaded"), "labelTrackingLoaded is hidden");
ok (hidden("#tracking-blocked"), "labelTrackingBlocked is hidden");
ok(!hidden("#tracking-not-detected"), "labelNoTracking is visible");
ok(hidden("#tracking-loaded"), "labelTrackingLoaded is hidden");
ok(hidden("#tracking-blocked"), "labelTrackingBlocked is hidden");
}
function testTrackingPage(window) {
info("Tracking content must be blocked");
ok (!TrackingProtection.container.hidden, "The container is visible");
is (TrackingProtection.content.getAttribute("state"), "blocked-tracking-content",
ok(!TrackingProtection.container.hidden, "The container is visible");
is(TrackingProtection.content.getAttribute("state"), "blocked-tracking-content",
'content: state="blocked-tracking-content"');
is (TrackingProtection.icon.getAttribute("state"), "blocked-tracking-content",
is(TrackingProtection.icon.getAttribute("state"), "blocked-tracking-content",
'icon: state="blocked-tracking-content"');
ok (!hidden("#tracking-protection-icon"), "icon is visible");
ok (hidden("#tracking-action-block"), "blockButton is hidden");
ok(!hidden("#tracking-protection-icon"), "icon is visible");
ok(hidden("#tracking-action-block"), "blockButton is hidden");
if (PrivateBrowsingUtils.isWindowPrivate(window)) {
@ -80,27 +78,27 @@ function testTrackingPage(window) {
}
// Make sure that the blocked tracking elements message appears
ok (hidden("#tracking-not-detected"), "labelNoTracking is hidden");
ok (hidden("#tracking-loaded"), "labelTrackingLoaded is hidden");
ok (!hidden("#tracking-blocked"), "labelTrackingBlocked is visible");
ok(hidden("#tracking-not-detected"), "labelNoTracking is hidden");
ok(hidden("#tracking-loaded"), "labelTrackingLoaded is hidden");
ok(!hidden("#tracking-blocked"), "labelTrackingBlocked is visible");
}
function testTrackingPageUnblocked() {
info("Tracking content must be white-listed and not blocked");
ok (!TrackingProtection.container.hidden, "The container is visible");
is (TrackingProtection.content.getAttribute("state"), "loaded-tracking-content",
ok(!TrackingProtection.container.hidden, "The container is visible");
is(TrackingProtection.content.getAttribute("state"), "loaded-tracking-content",
'content: state="loaded-tracking-content"');
is (TrackingProtection.icon.getAttribute("state"), "loaded-tracking-content",
is(TrackingProtection.icon.getAttribute("state"), "loaded-tracking-content",
'icon: state="loaded-tracking-content"');
ok (!hidden("#tracking-protection-icon"), "icon is visible");
ok (!hidden("#tracking-action-block"), "blockButton is visible");
ok (hidden("#tracking-action-unblock"), "unblockButton is hidden");
ok(!hidden("#tracking-protection-icon"), "icon is visible");
ok(!hidden("#tracking-action-block"), "blockButton is visible");
ok(hidden("#tracking-action-unblock"), "unblockButton is hidden");
// Make sure that the blocked tracking elements message appears
ok (hidden("#tracking-not-detected"), "labelNoTracking is hidden");
ok (!hidden("#tracking-loaded"), "labelTrackingLoaded is visible");
ok (hidden("#tracking-blocked"), "labelTrackingBlocked is hidden");
ok(hidden("#tracking-not-detected"), "labelNoTracking is hidden");
ok(!hidden("#tracking-loaded"), "labelTrackingLoaded is visible");
ok(hidden("#tracking-blocked"), "labelTrackingBlocked is hidden");
}
function* testTrackingProtectionForTab(tab) {
@ -128,40 +126,40 @@ function* testTrackingProtectionForTab(tab) {
add_task(function* testNormalBrowsing() {
yield UrlClassifierTestUtils.addTestTrackers();
browser = gBrowser;
let tab = browser.selectedTab = browser.addTab();
tabbrowser = gBrowser;
let tab = tabbrowser.selectedTab = tabbrowser.addTab();
TrackingProtection = gBrowser.ownerGlobal.TrackingProtection;
ok (TrackingProtection, "TP is attached to the browser window");
is (TrackingProtection.enabled, Services.prefs.getBoolPref(PREF),
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");
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");
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();
tabbrowser = privateWin.gBrowser;
let tab = tabbrowser.selectedTab = tabbrowser.addTab();
TrackingProtection = browser.ownerGlobal.TrackingProtection;
ok (TrackingProtection, "TP is attached to the private window");
is (TrackingProtection.enabled, Services.prefs.getBoolPref(PB_PREF),
TrackingProtection = tabbrowser.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");
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");
ok(!TrackingProtection.enabled, "TP is disabled after setting the pref");
privateWin.close();
});

View File

@ -1,10 +1,8 @@
/* 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 section is never visible in the
// Control Center when the feature is off.
// See also Bugs 1175327, 1043801, 1178985.
/*
* Test that the Tracking Protection section is never visible in the
* Control Center when the feature is off.
* See also Bugs 1175327, 1043801, 1178985.
*/
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
const PREF = "privacy.trackingprotection.enabled";
@ -12,12 +10,12 @@ 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;
let tabbrowser = null;
let {UrlClassifierTestUtils} = Cu.import("resource://testing-common/UrlClassifierTestUtils.jsm", {});
registerCleanupFunction(function() {
TrackingProtection = browser = null;
TrackingProtection = tabbrowser = null;
UrlClassifierTestUtils.cleanupTestTrackers();
Services.prefs.clearUserPref(PREF);
Services.prefs.clearUserPref(PB_PREF);
@ -29,52 +27,52 @@ registerCleanupFunction(function() {
add_task(function* testNormalBrowsing() {
yield UrlClassifierTestUtils.addTestTrackers();
browser = gBrowser;
let tab = browser.selectedTab = browser.addTab();
tabbrowser = gBrowser;
let tab = tabbrowser.selectedTab = tabbrowser.addTab();
TrackingProtection = browser.ownerGlobal.TrackingProtection;
ok (TrackingProtection, "TP is attached to the browser window");
is (TrackingProtection.enabled, Services.prefs.getBoolPref(PREF),
TrackingProtection = tabbrowser.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");
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");
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");
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");
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();
tabbrowser = privateWin.gBrowser;
let tab = tabbrowser.selectedTab = tabbrowser.addTab();
TrackingProtection = browser.ownerGlobal.TrackingProtection;
ok (TrackingProtection, "TP is attached to the private window");
is (TrackingProtection.enabled, Services.prefs.getBoolPref(PB_PREF),
TrackingProtection = tabbrowser.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");
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");
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");
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");
ok(TrackingProtection.container.hidden, "The container is hidden");
privateWin.close();
});

View File

@ -1,17 +1,13 @@
/* 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.
/*
* 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);
@ -19,41 +15,38 @@ registerCleanupFunction(function() {
});
add_task(function* testNormalBrowsing() {
let browser = gBrowser;
let TrackingProtection = browser.ownerGlobal.TrackingProtection;
ok (TrackingProtection, "TP is attached to the browser window");
let TrackingProtection = gBrowser.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)");
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)");
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)");
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)");
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");
let TrackingProtection = privateWin.gBrowser.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)");
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)");
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)");
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)");
ok(TrackingProtection.enabled, "TP is enabled (ENABLED=false,PB=true)");
privateWin.close();
});

View File

@ -1,10 +1,8 @@
/* 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 icon is properly animated in the identity
// block when loading tabs and switching between tabs.
// See also Bug 1175858.
/*
* Test that the Tracking Protection icon is properly animated in the identity
* block when loading tabs and switching between tabs.
* See also Bug 1175858.
*/
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
const PREF = "privacy.trackingprotection.enabled";
@ -12,12 +10,12 @@ 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;
let tabbrowser = null;
let {UrlClassifierTestUtils} = Cu.import("resource://testing-common/UrlClassifierTestUtils.jsm", {});
registerCleanupFunction(function() {
TrackingProtection = browser = null;
TrackingProtection = tabbrowser = null;
UrlClassifierTestUtils.cleanupTestTrackers();
Services.prefs.clearUserPref(PREF);
Services.prefs.clearUserPref(PB_PREF);
@ -34,76 +32,76 @@ function waitForSecurityChange(numChanges = 1) {
n = n + 1;
info ("Recieved onSecurityChange event " + n + " of " + numChanges);
if (n >= numChanges) {
browser.removeProgressListener(listener);
tabbrowser.removeProgressListener(listener);
resolve();
}
}
};
browser.addProgressListener(listener);
tabbrowser.addProgressListener(listener);
});
}
function* testTrackingProtectionAnimation() {
info("Load a test page not containing tracking elements");
let benignTab = yield BrowserTestUtils.openNewForegroundTab(browser, BENIGN_PAGE);
let benignTab = yield BrowserTestUtils.openNewForegroundTab(tabbrowser, BENIGN_PAGE);
ok (!TrackingProtection.icon.hasAttribute("state"), "icon: no state");
ok (TrackingProtection.icon.hasAttribute("animate"), "icon: animate");
ok(!TrackingProtection.icon.hasAttribute("state"), "icon: no state");
ok(TrackingProtection.icon.hasAttribute("animate"), "icon: animate");
info("Load a test page containing tracking elements");
let trackingTab = yield BrowserTestUtils.openNewForegroundTab(browser, TRACKING_PAGE);
let trackingTab = yield BrowserTestUtils.openNewForegroundTab(tabbrowser, TRACKING_PAGE);
ok (TrackingProtection.icon.hasAttribute("state"), "icon: state");
ok (TrackingProtection.icon.hasAttribute("animate"), "icon: animate");
ok(TrackingProtection.icon.hasAttribute("state"), "icon: state");
ok(TrackingProtection.icon.hasAttribute("animate"), "icon: animate");
info("Switch from tracking -> benign tab");
let securityChanged = waitForSecurityChange();
browser.selectedTab = benignTab;
tabbrowser.selectedTab = benignTab;
yield securityChanged;
ok (!TrackingProtection.icon.hasAttribute("state"), "icon: no state");
ok (!TrackingProtection.icon.hasAttribute("animate"), "icon: no animate");
ok(!TrackingProtection.icon.hasAttribute("state"), "icon: no state");
ok(!TrackingProtection.icon.hasAttribute("animate"), "icon: no animate");
info("Switch from benign -> tracking tab");
securityChanged = waitForSecurityChange();
browser.selectedTab = trackingTab;
tabbrowser.selectedTab = trackingTab;
yield securityChanged;
ok (TrackingProtection.icon.hasAttribute("state"), "icon: state");
ok (!TrackingProtection.icon.hasAttribute("animate"), "icon: no animate");
ok(TrackingProtection.icon.hasAttribute("state"), "icon: state");
ok(!TrackingProtection.icon.hasAttribute("animate"), "icon: no animate");
info("Reload tracking tab");
securityChanged = waitForSecurityChange(2);
browser.reload();
tabbrowser.reload();
yield securityChanged;
ok (TrackingProtection.icon.hasAttribute("state"), "icon: state");
ok (TrackingProtection.icon.hasAttribute("animate"), "icon: animate");
ok(TrackingProtection.icon.hasAttribute("state"), "icon: state");
ok(TrackingProtection.icon.hasAttribute("animate"), "icon: animate");
}
add_task(function* testNormalBrowsing() {
yield UrlClassifierTestUtils.addTestTrackers();
browser = gBrowser;
tabbrowser = gBrowser;
TrackingProtection = gBrowser.ownerGlobal.TrackingProtection;
ok (TrackingProtection, "TP is attached to the browser window");
ok(TrackingProtection, "TP is attached to the browser window");
Services.prefs.setBoolPref(PREF, true);
ok (TrackingProtection.enabled, "TP is enabled after setting the pref");
ok(TrackingProtection.enabled, "TP is enabled after setting the pref");
yield testTrackingProtectionAnimation();
});
add_task(function* testPrivateBrowsing() {
let privateWin = yield promiseOpenAndLoadWindow({private: true}, true);
browser = privateWin.gBrowser;
tabbrowser = privateWin.gBrowser;
TrackingProtection = browser.ownerGlobal.TrackingProtection;
ok (TrackingProtection, "TP is attached to the private window");
TrackingProtection = tabbrowser.ownerGlobal.TrackingProtection;
ok(TrackingProtection, "TP is attached to the private window");
Services.prefs.setBoolPref(PB_PREF, true);
ok (TrackingProtection.enabled, "TP is enabled after setting the pref");
ok(TrackingProtection.enabled, "TP is enabled after setting the pref");
yield testTrackingProtectionAnimation();