fune/browser/base/content/test/trackingUI/browser_trackingUI_appMenu_toggle.js
Johann Hofmann b72851d67d Bug 1476224 - Update the Tracking Protection section in the main menu for Content Blocking. r=nhnt11
Differential Revision: https://phabricator.services.mozilla.com/D2978

--HG--
extra : rebase_source : 0d37900b25bf2e7164ed13e3d6e88bd1bec4e87b
2018-08-09 01:33:38 +02:00

86 lines
2.7 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const CB_PREF = "browser.contentblocking.enabled";
const CB_UI_PREF = "browser.contentblocking.ui.enabled";
ChromeUtils.import("resource://testing-common/CustomizableUITestUtils.jsm", this);
// Test that the app menu toggle correctly flips the TP pref in
// normal windows and private windows.
add_task(async function testGlobalToggle() {
await SpecialPowers.pushPrefEnv({set: [[CB_UI_PREF, true]]});
let panelUIButton = await TestUtils.waitForCondition(() => document.getElementById("PanelUI-menu-button"));
info("Opening main menu");
let promiseShown = BrowserTestUtils.waitForEvent(PanelUI.mainView, "ViewShown");
panelUIButton.click();
await promiseShown;
info("Opened main menu");
let toggle = document.getElementById("appMenu-tp-toggle");
Services.prefs.setBoolPref(CB_PREF, false);
await TestUtils.waitForCondition(() => toggle.getAttribute("enabled") == "false");
Services.prefs.setBoolPref(CB_PREF, true);
await TestUtils.waitForCondition(() => toggle.getAttribute("enabled") == "true");
toggle.click();
is(Services.prefs.getBoolPref(CB_PREF), false);
toggle.click();
is(Services.prefs.getBoolPref(CB_PREF), true);
Services.prefs.clearUserPref(CB_PREF);
});
// Test that the app menu toggle correctly flips the TP pref in
// normal windows and private windows.
add_task(async function testGlobalToggleTP() {
await SpecialPowers.pushPrefEnv({set: [[CB_UI_PREF, false]]});
async function runTest(privateWindow) {
let win = await BrowserTestUtils.openNewBrowserWindow({private: privateWindow});
let panelUIButton = await TestUtils.waitForCondition(() => win.document.getElementById("PanelUI-menu-button"));
let prefName = privateWindow ? "privacy.trackingprotection.pbmode.enabled" :
"privacy.trackingprotection.enabled";
info("Opening main menu");
let promiseShown = BrowserTestUtils.waitForEvent(win.PanelUI.mainView, "ViewShown");
panelUIButton.click();
await promiseShown;
info("Opened main menu");
let toggle = win.document.getElementById("appMenu-tp-toggle");
Services.prefs.setBoolPref(prefName, false);
await TestUtils.waitForCondition(() => toggle.getAttribute("enabled") == "false");
Services.prefs.setBoolPref(prefName, true);
await TestUtils.waitForCondition(() => toggle.getAttribute("enabled") == "true");
toggle.click();
is(Services.prefs.getBoolPref(prefName), false);
toggle.click();
is(Services.prefs.getBoolPref(prefName), true);
Services.prefs.clearUserPref(prefName);
await BrowserTestUtils.closeWindow(win);
}
// Run once in private and once in normal window.
await runTest(true);
await runTest(false);
});