зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1462470 - Part 6 - Add tests for the updated tracking protection UI in the identity popup. r=Paolo
This adds tests and moves the browser_trackingUI_1 test to the more general trackingUI directory. The remaining TP tests will be moved in bug 1451307. MozReview-Commit-ID: FHP4ULX0OQG --HG-- rename : browser/base/content/test/general/browser_trackingUI_1.js => browser/base/content/test/trackingUI/browser_trackingUI_state.js extra : rebase_source : 4f58e9f3aa3276536f43097257e312c6719a5cc6
This commit is contained in:
Родитель
657b0dda6c
Коммит
9764429134
|
@ -467,12 +467,6 @@ support-files =
|
|||
[browser_testOpenNewRemoteTabsFromNonRemoteBrowsers.js]
|
||||
run-if = e10s
|
||||
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
|
||||
[browser_trackingUI_1.js]
|
||||
tags = trackingprotection
|
||||
support-files =
|
||||
trackingPage.html
|
||||
benignPage.html
|
||||
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
|
||||
[browser_trackingUI_3.js]
|
||||
tags = trackingprotection
|
||||
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
[DEFAULT]
|
||||
tags = trackingprotection
|
||||
support-files =
|
||||
head.js
|
||||
../general/benignPage.html
|
||||
../general/trackingPage.html
|
||||
|
||||
[browser_trackingUI_appMenu.js]
|
||||
[browser_trackingUI_appMenu_toggle.js]
|
||||
[browser_trackingUI_open_preferences.js]
|
||||
[browser_trackingUI_reload_hint.js]
|
||||
[browser_trackingUI_state.js]
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
const PREF = "privacy.trackingprotection.enabled";
|
||||
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
|
||||
|
||||
var {UrlClassifierTestUtils} = ChromeUtils.import("resource://testing-common/UrlClassifierTestUtils.jsm", {});
|
||||
|
||||
// TODO: replace this once bug 1428847 is done.
|
||||
function hidden(el) {
|
||||
let win = el.ownerGlobal;
|
||||
let display = win.getComputedStyle(el).getPropertyValue("display", null);
|
||||
let opacity = win.getComputedStyle(el).getPropertyValue("opacity", null);
|
||||
return display === "none" || opacity === "0";
|
||||
}
|
||||
|
||||
async function waitAndAssertPreferencesShown() {
|
||||
await BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popuphidden");
|
||||
await TestUtils.waitForCondition(() => gBrowser.currentURI.spec == "about:preferences#privacy",
|
||||
"Should open about:preferences.");
|
||||
|
||||
await ContentTask.spawn(gBrowser.selectedBrowser, {}, async function() {
|
||||
let doc = content.document;
|
||||
let section = await ContentTaskUtils.waitForCondition(
|
||||
() => doc.querySelector(".spotlight"), "The spotlight should appear.");
|
||||
is(section.getAttribute("data-subcategory"), "trackingprotection",
|
||||
"The trackingprotection section is spotlighted.");
|
||||
});
|
||||
|
||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
}
|
||||
|
||||
add_task(async function setup() {
|
||||
await UrlClassifierTestUtils.addTestTrackers();
|
||||
});
|
||||
|
||||
// Tests that pressing the "Enable Tracking Protection" button in the
|
||||
// identity popup links to about:preferences
|
||||
add_task(async function testOpenPreferencesFromBlockButton() {
|
||||
Services.prefs.setBoolPref(PREF, false);
|
||||
|
||||
await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function() {
|
||||
let promisePanelOpen = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popupshown");
|
||||
gIdentityHandler._identityBox.click();
|
||||
await promisePanelOpen;
|
||||
|
||||
let blockButton = document.getElementById("tracking-action-block");
|
||||
|
||||
ok(!hidden(blockButton), "The enable tracking protection button is shown.");
|
||||
ok(hidden(document.getElementById("tracking-protection-preferences-button")),
|
||||
"The preferences button is hidden.");
|
||||
|
||||
let shown = waitAndAssertPreferencesShown();
|
||||
blockButton.click();
|
||||
await shown;
|
||||
});
|
||||
|
||||
Services.prefs.clearUserPref(PREF);
|
||||
});
|
||||
|
||||
// Tests that pressing the preferences icon in the identity popup
|
||||
// links to about:preferences
|
||||
add_task(async function testOpenPreferencesFromPrefsButton() {
|
||||
await BrowserTestUtils.withNewTab("https://example.com", async function() {
|
||||
let promisePanelOpen = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popupshown");
|
||||
gIdentityHandler._identityBox.click();
|
||||
await promisePanelOpen;
|
||||
|
||||
let preferencesButton = document.getElementById("tracking-protection-preferences-button");
|
||||
|
||||
ok(!hidden(preferencesButton), "The enable tracking protection button is shown.");
|
||||
|
||||
let shown = waitAndAssertPreferencesShown();
|
||||
preferencesButton.click();
|
||||
await shown;
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function cleanup() {
|
||||
UrlClassifierTestUtils.cleanupTestTrackers();
|
||||
});
|
|
@ -0,0 +1,86 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
const PREF = "privacy.trackingprotection.enabled";
|
||||
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
|
||||
|
||||
var {UrlClassifierTestUtils} = ChromeUtils.import("resource://testing-common/UrlClassifierTestUtils.jsm", {});
|
||||
|
||||
// TODO: replace this once bug 1428847 is done.
|
||||
function hidden(el) {
|
||||
let win = el.ownerGlobal;
|
||||
let display = win.getComputedStyle(el).getPropertyValue("display", null);
|
||||
let opacity = win.getComputedStyle(el).getPropertyValue("opacity", null);
|
||||
return display === "none" || opacity === "0";
|
||||
}
|
||||
|
||||
add_task(async function setup() {
|
||||
await UrlClassifierTestUtils.addTestTrackers();
|
||||
});
|
||||
|
||||
// Tests that we show the reload hint if the user enables TP on
|
||||
// a site that has already loaded trackers before and that pressing
|
||||
// the reload button reloads the page.
|
||||
add_task(async function testReloadHint() {
|
||||
Services.prefs.setBoolPref(PREF, false);
|
||||
|
||||
await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function() {
|
||||
let promisePanelOpen = BrowserTestUtils.waitForEvent(window.gIdentityHandler._identityPopup, "popupshown");
|
||||
window.gIdentityHandler._identityBox.click();
|
||||
await promisePanelOpen;
|
||||
|
||||
let blockButton = document.getElementById("tracking-action-block");
|
||||
let reloadButton = document.getElementById("tracking-action-reload");
|
||||
let trackingLoaded = document.getElementById("tracking-loaded");
|
||||
let reloadHint = document.getElementById("tracking-reload-required");
|
||||
ok(!hidden(blockButton), "The enable tracking protection button is shown.");
|
||||
ok(!hidden(trackingLoaded), "The tracking loaded info is shown.");
|
||||
ok(hidden(reloadButton), "The reload button is not shown.");
|
||||
ok(hidden(reloadHint), "The reload hint is not shown.");
|
||||
|
||||
Services.prefs.setBoolPref(PREF, true);
|
||||
|
||||
ok(hidden(blockButton), "The enable tracking protection button is not shown.");
|
||||
ok(hidden(trackingLoaded), "The tracking loaded info is not shown.");
|
||||
ok(!hidden(reloadButton), "The reload button is shown.");
|
||||
ok(!hidden(reloadHint), "The reload hint is shown.");
|
||||
|
||||
let reloaded = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false, TRACKING_PAGE);
|
||||
reloadButton.click();
|
||||
await reloaded;
|
||||
});
|
||||
|
||||
Services.prefs.clearUserPref(PREF);
|
||||
});
|
||||
|
||||
// Tests that the reload hint does not appear on a non-tracking page.
|
||||
add_task(async function testReloadHint() {
|
||||
Services.prefs.setBoolPref(PREF, false);
|
||||
|
||||
await BrowserTestUtils.withNewTab("https://example.com", async function() {
|
||||
let promisePanelOpen = BrowserTestUtils.waitForEvent(window.gIdentityHandler._identityPopup, "popupshown");
|
||||
window.gIdentityHandler._identityBox.click();
|
||||
await promisePanelOpen;
|
||||
|
||||
let trackingNotDetected = document.getElementById("tracking-not-detected");
|
||||
let reloadButton = document.getElementById("tracking-action-reload");
|
||||
let reloadHint = document.getElementById("tracking-reload-required");
|
||||
ok(!hidden(trackingNotDetected), "The tracking not detected info is shown.");
|
||||
ok(hidden(reloadButton), "The reload button is not shown.");
|
||||
ok(hidden(reloadHint), "The reload hint is not shown.");
|
||||
|
||||
Services.prefs.setBoolPref(PREF, true);
|
||||
|
||||
ok(!hidden(trackingNotDetected), "The tracking not detected info is shown.");
|
||||
ok(hidden(reloadButton), "The reload button is not shown.");
|
||||
ok(hidden(reloadHint), "The reload hint is not shown.");
|
||||
});
|
||||
|
||||
Services.prefs.clearUserPref(PREF);
|
||||
});
|
||||
|
||||
add_task(async function cleanup() {
|
||||
UrlClassifierTestUtils.cleanupTestTrackers();
|
||||
});
|
|
@ -1,16 +1,23 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* In a normal window as well as a private window,
|
||||
* With TP enabled
|
||||
* 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.
|
||||
* With TP disabled
|
||||
* 1) A page with no tracking elements is loaded.
|
||||
* 2) A page with tracking elements is loaded.
|
||||
*
|
||||
* See also Bugs 1175327, 1043801, 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";
|
||||
const BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/benignPage.html";
|
||||
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
|
||||
var TrackingProtection = null;
|
||||
var tabbrowser = null;
|
||||
|
||||
|
@ -50,6 +57,7 @@ function testBenignPage() {
|
|||
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-preferences-button"), "preferences button is visible");
|
||||
|
||||
// Make sure that the no tracking elements message appears
|
||||
ok(!hidden("#tracking-not-detected"), "labelNoTracking is visible");
|
||||
|
@ -69,6 +77,7 @@ function testTrackingPage(window) {
|
|||
|
||||
ok(!hidden("#tracking-protection-icon"), "icon is visible");
|
||||
ok(hidden("#tracking-action-block"), "blockButton is hidden");
|
||||
ok(!hidden("#tracking-protection-preferences-button"), "preferences button is visible");
|
||||
|
||||
|
||||
if (PrivateBrowsingUtils.isWindowPrivate(window)) {
|
||||
|
@ -90,14 +99,18 @@ function testTrackingPageUnblocked() {
|
|||
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",
|
||||
'icon: state="loaded-tracking-content"');
|
||||
is(TrackingProtection.icon.getAttribute("tooltiptext"),
|
||||
gNavigatorBundle.getString("trackingProtection.icon.disabledTooltip"), "correct tooltip");
|
||||
if (TrackingProtection.enabled) {
|
||||
is(TrackingProtection.icon.getAttribute("state"), "loaded-tracking-content",
|
||||
'icon: state="loaded-tracking-content"');
|
||||
is(TrackingProtection.icon.getAttribute("tooltiptext"),
|
||||
gNavigatorBundle.getString("trackingProtection.icon.disabledTooltip"), "correct tooltip");
|
||||
}
|
||||
|
||||
ok(!hidden("#tracking-protection-icon"), "icon is visible");
|
||||
is(!hidden("#tracking-protection-icon"), TrackingProtection.enabled, "icon is visible if TP is on");
|
||||
ok(!hidden("#tracking-action-block"), "blockButton is visible");
|
||||
ok(hidden("#tracking-action-unblock"), "unblockButton is hidden");
|
||||
is(!hidden("#tracking-protection-preferences-button"), TrackingProtection.enabled,
|
||||
"preferences button is visible if TP is on");
|
||||
|
||||
// Make sure that the blocked tracking elements message appears
|
||||
ok(hidden("#tracking-not-detected"), "labelNoTracking is hidden");
|
||||
|
@ -105,7 +118,7 @@ function testTrackingPageUnblocked() {
|
|||
ok(hidden("#tracking-blocked"), "labelTrackingBlocked is hidden");
|
||||
}
|
||||
|
||||
async function testTrackingProtectionForTab(tab) {
|
||||
async function testTrackingProtectionEnabled(tab) {
|
||||
info("Load a test page not containing tracking elements");
|
||||
await promiseTabLoadEvent(tab, BENIGN_PAGE);
|
||||
testBenignPage();
|
||||
|
@ -127,6 +140,16 @@ async function testTrackingProtectionForTab(tab) {
|
|||
testTrackingPage(tab.ownerGlobal);
|
||||
}
|
||||
|
||||
async function testTrackingProtectionDisabled(tab) {
|
||||
info("Load a test page not containing tracking elements");
|
||||
await promiseTabLoadEvent(tab, BENIGN_PAGE);
|
||||
testBenignPage();
|
||||
|
||||
info("Load a test page containing tracking elements");
|
||||
await promiseTabLoadEvent(tab, TRACKING_PAGE);
|
||||
testTrackingPageUnblocked();
|
||||
}
|
||||
|
||||
add_task(async function testNormalBrowsing() {
|
||||
await UrlClassifierTestUtils.addTestTrackers();
|
||||
|
||||
|
@ -141,14 +164,16 @@ add_task(async function testNormalBrowsing() {
|
|||
Services.prefs.setBoolPref(PREF, true);
|
||||
ok(TrackingProtection.enabled, "TP is enabled after setting the pref");
|
||||
|
||||
await testTrackingProtectionForTab(tab);
|
||||
await testTrackingProtectionEnabled(tab);
|
||||
|
||||
Services.prefs.setBoolPref(PREF, false);
|
||||
ok(!TrackingProtection.enabled, "TP is disabled after setting the pref");
|
||||
|
||||
await testTrackingProtectionDisabled(tab);
|
||||
});
|
||||
|
||||
add_task(async function testPrivateBrowsing() {
|
||||
let privateWin = await promiseOpenAndLoadWindow({private: true}, true);
|
||||
let privateWin = await BrowserTestUtils.openNewBrowserWindow({private: true});
|
||||
tabbrowser = privateWin.gBrowser;
|
||||
let tab = tabbrowser.selectedTab = tabbrowser.addTab();
|
||||
|
||||
|
@ -160,10 +185,12 @@ add_task(async function testPrivateBrowsing() {
|
|||
Services.prefs.setBoolPref(PB_PREF, true);
|
||||
ok(TrackingProtection.enabled, "TP is enabled after setting the pref");
|
||||
|
||||
await testTrackingProtectionForTab(tab);
|
||||
await testTrackingProtectionEnabled(tab);
|
||||
|
||||
Services.prefs.setBoolPref(PB_PREF, false);
|
||||
ok(!TrackingProtection.enabled, "TP is disabled after setting the pref");
|
||||
|
||||
await testTrackingProtectionDisabled(tab);
|
||||
|
||||
privateWin.close();
|
||||
});
|
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* Waits for a load (or custom) event to finish in a given tab. If provided
|
||||
* load an uri into the tab.
|
||||
*
|
||||
* @param tab
|
||||
* The tab to load into.
|
||||
* @param [optional] url
|
||||
* The url to load, or the current url.
|
||||
* @return {Promise} resolved when the event is handled.
|
||||
* @resolves to the received event
|
||||
* @rejects if a valid load event is not received within a meaningful interval
|
||||
*/
|
||||
function promiseTabLoadEvent(tab, url) {
|
||||
info("Wait tab event: load");
|
||||
|
||||
function handle(loadedUrl) {
|
||||
if (loadedUrl === "about:blank" || (url && loadedUrl !== url)) {
|
||||
info(`Skipping spurious load event for ${loadedUrl}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
info("Tab event received: load");
|
||||
return true;
|
||||
}
|
||||
|
||||
let loaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, handle);
|
||||
|
||||
if (url)
|
||||
BrowserTestUtils.loadURI(tab.linkedBrowser, url);
|
||||
|
||||
return loaded;
|
||||
}
|
Загрузка…
Ссылка в новой задаче