Bug 1566985 - Part 4: Update tests and add a test for check visibility of the 'Site not working?' link. r=nhnt11

Differential Revision: https://phabricator.services.mozilla.com/D38638

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tim Huang 2019-07-24 14:19:03 +00:00
parent af5570d7c9
commit 2d0f833a29
3 changed files with 43 additions and 92 deletions

View File

@ -25,6 +25,15 @@ add_task(async function testToggleSwitch() {
"https://example.com"
);
await openProtectionsPanel();
// Check the visibility of the "Site not working?" link.
ok(
BrowserTestUtils.is_visible(
gProtectionsHandler._protectionsPopupTPSwitchBreakageLink
),
"The 'Site not working?' link should be visible."
);
ok(
gProtectionsHandler._protectionsPopupTPSwitch.hasAttribute("enabled"),
"TP Switch should be enabled"
@ -35,6 +44,15 @@ add_task(async function testToggleSwitch() {
);
let browserLoadedPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
gProtectionsHandler._protectionsPopupTPSwitch.click();
// The 'Site not working?' link should be hidden after clicking the TP switch.
ok(
BrowserTestUtils.is_hidden(
gProtectionsHandler._protectionsPopupTPSwitchBreakageLink
),
"The 'Site not working?' link should be hidden after TP switch turns to off."
);
await popuphiddenPromise;
// We need to wait toast's popup shown and popup hidden events. It won't fire
@ -60,6 +78,30 @@ add_task(async function testToggleSwitch() {
!gProtectionsHandler._protectionsPopupTPSwitch.hasAttribute("enabled"),
"TP Switch should be disabled"
);
// The 'Site not working?' link should be hidden if the TP is off.
ok(
BrowserTestUtils.is_hidden(
gProtectionsHandler._protectionsPopupTPSwitchBreakageLink
),
"The 'Site not working?' link should be hidden if TP is off."
);
// Click the TP switch again and check the visibility of the 'Site not
// Working?'. It should be hidden after toggling the TP switch.
browserLoadedPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
gProtectionsHandler._protectionsPopupTPSwitch.click();
ok(
BrowserTestUtils.is_hidden(
gProtectionsHandler._protectionsPopupTPSwitchBreakageLink
),
`The 'Site not working?' link should be still hidden after toggling TP
switch to on from off.`
);
await browserLoadedPromise;
ContentBlockingAllowList.remove(tab.linkedBrowser);
BrowserTestUtils.removeTab(tab);
});

View File

@ -15,8 +15,6 @@ const FP_PREF = "privacy.trackingprotection.fingerprinting.enabled";
const TP_PREF = "privacy.trackingprotection.enabled";
const CB_PREF = "network.cookie.cookieBehavior";
const PREF_REPORT_BREAKAGE_ENABLED =
"browser.contentblocking.reportBreakage.enabled";
const PREF_REPORT_BREAKAGE_URL = "browser.contentblocking.reportBreakage.url";
let { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
@ -34,7 +32,6 @@ add_task(async function setup() {
Services.prefs.clearUserPref(CB_PREF);
Services.prefs.clearUserPref(FP_PREF);
Services.prefs.clearUserPref(CM_PREF);
Services.prefs.clearUserPref(PREF_REPORT_BREAKAGE_ENABLED);
Services.prefs.clearUserPref(PREF_REPORT_BREAKAGE_URL);
UrlClassifierTestUtils.cleanupTestTrackers();
@ -64,93 +61,8 @@ add_task(async function setup() {
});
});
add_task(async function testReportBreakageVisibility() {
let scenarios = [
{
url: TRACKING_PAGE,
prefs: {
"privacy.trackingprotection.enabled": true,
"browser.contentblocking.reportBreakage.enabled": true,
},
buttonVisible: true,
},
{
url: TRACKING_PAGE,
hasException: true,
prefs: {
"privacy.trackingprotection.enabled": true,
"browser.contentblocking.reportBreakage.enabled": true,
},
buttonVisible: true,
},
{
url: TRACKING_PAGE,
prefs: {
"privacy.trackingprotection.enabled": true,
"browser.contentblocking.reportBreakage.enabled": false,
},
buttonVisible: false,
},
{
url: BENIGN_PAGE,
prefs: {
"privacy.trackingprotection.enabled": true,
"browser.contentblocking.reportBreakage.enabled": true,
},
buttonVisible: false,
},
{
url: COOKIE_PAGE,
prefs: {
"privacy.trackingprotection.enabled": false,
"network.cookie.cookieBehavior":
Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER,
"browser.contentblocking.reportBreakage.enabled": false,
"browser.contentblocking.rejecttrackers.reportBreakage.enabled": true,
},
buttonVisible: true,
},
];
for (let scenario of scenarios) {
for (let pref in scenario.prefs) {
Preferences.set(pref, scenario.prefs[pref]);
}
let uri = Services.io.newURI(scenario.url);
if (scenario.hasException) {
Services.perms.add(
uri,
"trackingprotection",
Services.perms.ALLOW_ACTION
);
}
await BrowserTestUtils.withNewTab(scenario.url, async function() {
await openProtectionsPopup();
let reportBreakageButton = document.getElementById(
"protections-popup-tp-switch-breakage-link"
);
await TestUtils.waitForCondition(
() =>
BrowserTestUtils.is_visible(reportBreakageButton) ==
scenario.buttonVisible,
"waiting for correct visibility"
);
ok(true, "report breakage button has the correct visibility");
});
Services.perms.remove(uri, "trackingprotection");
for (let pref in scenario.prefs) {
Services.prefs.clearUserPref(pref);
}
}
});
add_task(async function testReportBreakageCancel() {
Services.prefs.setBoolPref(TP_PREF, true);
Services.prefs.setBoolPref(PREF_REPORT_BREAKAGE_ENABLED, true);
await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function() {
await openProtectionsPopup();
@ -195,7 +107,6 @@ add_task(async function testReportBreakageCancel() {
});
Services.prefs.clearUserPref(TP_PREF);
Services.prefs.clearUserPref(PREF_REPORT_BREAKAGE_ENABLED);
});
add_task(async function testTP() {
@ -265,7 +176,6 @@ async function testReportBreakage(url, tags) {
let path =
i.primaryScheme + "://" + i.primaryHost + ":" + i.primaryPort + "/";
Services.prefs.setBoolPref(PREF_REPORT_BREAKAGE_ENABLED, true);
Services.prefs.setStringPref(PREF_REPORT_BREAKAGE_URL, path);
await openProtectionsPopup();
@ -384,6 +294,5 @@ async function testReportBreakage(url, tags) {
// Stop the server.
await new Promise(r => server.stop(r));
Services.prefs.clearUserPref(PREF_REPORT_BREAKAGE_ENABLED);
Services.prefs.clearUserPref(PREF_REPORT_BREAKAGE_URL);
}

View File

@ -53,7 +53,7 @@ function openProtectionsPopup() {
let mainView = document.getElementById("protections-popup-mainView");
let viewShown = BrowserTestUtils.waitForEvent(mainView, "ViewShown");
// TODO: This should click on the icon once we have it.
gProtectionsHandler.showProtectionsPopup();
gIdentityHandler._trackingProtectionIconContainer.click();
return viewShown;
}