summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/protectionsUI
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
commitfbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch)
tree4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /browser/base/content/test/protectionsUI
parentReleasing progress-linux version 124.0.1-1~progress7.99u1. (diff)
downloadfirefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz
firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/test/protectionsUI')
-rw-r--r--browser/base/content/test/protectionsUI/browser.toml7
-rw-r--r--browser/base/content/test/protectionsUI/browser_protectionsUI.js119
-rw-r--r--browser/base/content/test/protectionsUI/browser_protectionsUI_report_breakage.js415
3 files changed, 4 insertions, 537 deletions
diff --git a/browser/base/content/test/protectionsUI/browser.toml b/browser/base/content/test/protectionsUI/browser.toml
index 10611cbe8c..f3c64eb67f 100644
--- a/browser/base/content/test/protectionsUI/browser.toml
+++ b/browser/base/content/test/protectionsUI/browser.toml
@@ -59,13 +59,6 @@ https_first_disabled = true
["browser_protectionsUI_pbmode_exceptions.js"]
https_first_disabled = true
-["browser_protectionsUI_report_breakage.js"]
-https_first_disabled = true
-skip-if = [
- "debug", # Bug 1546797
- "asan",
-]
-
["browser_protectionsUI_shield_visibility.js"]
support-files = [
"sandboxed.html",
diff --git a/browser/base/content/test/protectionsUI/browser_protectionsUI.js b/browser/base/content/test/protectionsUI/browser_protectionsUI.js
index 98698e087e..5dc6acebf7 100644
--- a/browser/base/content/test/protectionsUI/browser_protectionsUI.js
+++ b/browser/base/content/test/protectionsUI/browser_protectionsUI.js
@@ -73,85 +73,16 @@ add_task(async function testToggleSwitch() {
console.log(buttonEvents);
is(buttonEvents.length, 1, "recorded telemetry for opening the popup");
- // Check the visibility of the "Site not working?" link.
- ok(
- BrowserTestUtils.isVisible(
- gProtectionsHandler._protectionsPopupTPSwitchBreakageLink
- ),
- "The 'Site not working?' link should be visible."
- );
-
- // The 'Site Fixed?' link should be hidden.
- ok(
- BrowserTestUtils.isHidden(
- gProtectionsHandler._protectionsPopupTPSwitchBreakageFixedLink
- ),
- "The 'Site Fixed?' link should be hidden."
- );
-
- // Navigate through the 'Site Not Working?' flow and back to the main view,
- // checking for telemetry on the way.
- let siteNotWorkingView = document.getElementById(
- "protections-popup-siteNotWorkingView"
- );
- let viewShown = BrowserTestUtils.waitForEvent(
- siteNotWorkingView,
- "ViewShown"
- );
- gProtectionsHandler._protectionsPopupTPSwitchBreakageLink.click();
- await viewShown;
-
- checkClickTelemetry("sitenotworking_link");
-
- let sendReportButton = document.getElementById(
- "protections-popup-siteNotWorkingView-sendReport"
- );
- let sendReportView = document.getElementById(
- "protections-popup-sendReportView"
- );
- viewShown = BrowserTestUtils.waitForEvent(sendReportView, "ViewShown");
- sendReportButton.click();
- await viewShown;
-
- checkClickTelemetry("send_report_link");
-
- viewShown = BrowserTestUtils.waitForEvent(siteNotWorkingView, "ViewShown");
- sendReportView.querySelector(".subviewbutton-back").click();
- await viewShown;
-
- let mainView = document.getElementById("protections-popup-mainView");
-
- viewShown = BrowserTestUtils.waitForEvent(mainView, "ViewShown");
- siteNotWorkingView.querySelector(".subviewbutton-back").click();
- await viewShown;
+ let browserLoadedPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
- ok(
- gProtectionsHandler._protectionsPopupTPSwitch.hasAttribute("pressed"),
- "TP Switch should be on"
- );
let popuphiddenPromise = BrowserTestUtils.waitForEvent(
gProtectionsHandler._protectionsPopup,
"popuphidden"
);
- let browserLoadedPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
- await clickToggle(gProtectionsHandler._protectionsPopupTPSwitch);
-
- // The 'Site not working?' link should be hidden after clicking the TP switch.
- ok(
- BrowserTestUtils.isHidden(
- gProtectionsHandler._protectionsPopupTPSwitchBreakageLink
- ),
- "The 'Site not working?' link should be hidden after TP switch turns to off."
- );
- // Same for the 'Site Fixed?' link
- ok(
- BrowserTestUtils.isHidden(
- gProtectionsHandler._protectionsPopupTPSwitchBreakageFixedLink
- ),
- "The 'Site Fixed?' link should be hidden."
- );
+ await clickToggle(gProtectionsHandler._protectionsPopupTPSwitch);
await popuphiddenPromise;
+
checkClickTelemetry("etp_toggle_off");
// We need to wait toast's popup shown and popup hidden events. It won't fire
@@ -164,41 +95,13 @@ add_task(async function testToggleSwitch() {
// Wait until the ETP state confirmation toast is shown and hides itself.
await toastShown;
+ // Re-open the protections panel and confirm that the toggle is off, then toggle it back on.
await openProtectionsPanel();
ok(
!gProtectionsHandler._protectionsPopupTPSwitch.hasAttribute("pressed"),
"TP Switch should be off"
);
- // The 'Site not working?' link should be hidden if the TP is off.
- ok(
- BrowserTestUtils.isHidden(
- gProtectionsHandler._protectionsPopupTPSwitchBreakageLink
- ),
- "The 'Site not working?' link should be hidden if TP is off."
- );
-
- // The 'Site Fixed?' link should be shown if TP is off.
- ok(
- BrowserTestUtils.isVisible(
- gProtectionsHandler._protectionsPopupTPSwitchBreakageFixedLink
- ),
- "The 'Site Fixed?' link should be visible."
- );
-
- // Check telemetry for 'Site Fixed?' link.
- viewShown = BrowserTestUtils.waitForEvent(sendReportView, "ViewShown");
- gProtectionsHandler._protectionsPopupTPSwitchBreakageFixedLink.click();
- await viewShown;
-
- checkClickTelemetry("sitenotworking_link", "sitefixed");
-
- viewShown = BrowserTestUtils.waitForEvent(mainView, "ViewShown");
- sendReportView.querySelector(".subviewbutton-back").click();
- await viewShown;
-
- // 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);
popuphiddenPromise = BrowserTestUtils.waitForEvent(
@@ -208,20 +111,6 @@ add_task(async function testToggleSwitch() {
await clickToggle(gProtectionsHandler._protectionsPopupTPSwitch);
- ok(
- BrowserTestUtils.isHidden(
- gProtectionsHandler._protectionsPopupTPSwitchBreakageLink
- ),
- `The 'Site not working?' link should be still hidden after toggling TP
- switch to on from off.`
- );
- ok(
- BrowserTestUtils.isHidden(
- gProtectionsHandler._protectionsPopupTPSwitchBreakageFixedLink
- ),
- "The 'Site Fixed?' link should be hidden."
- );
-
// Wait for the protections panel to be hidden as the result of the ETP toggle
// on action.
await popuphiddenPromise;
diff --git a/browser/base/content/test/protectionsUI/browser_protectionsUI_report_breakage.js b/browser/base/content/test/protectionsUI/browser_protectionsUI_report_breakage.js
deleted file mode 100644
index 2ae0d5c9d9..0000000000
--- a/browser/base/content/test/protectionsUI/browser_protectionsUI_report_breakage.js
+++ /dev/null
@@ -1,415 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
-
-"use strict";
-
-const TRACKING_PAGE =
- // eslint-disable-next-line @microsoft/sdl/no-insecure-url
- "http://tracking.example.org/browser/browser/base/content/test/protectionsUI/trackingPage.html";
-const BENIGN_PAGE =
- // eslint-disable-next-line @microsoft/sdl/no-insecure-url
- "http://tracking.example.org/browser/browser/base/content/test/protectionsUI/benignPage.html";
-const COOKIE_PAGE =
- // eslint-disable-next-line @microsoft/sdl/no-insecure-url
- "http://not-tracking.example.com/browser/browser/base/content/test/protectionsUI/cookiePage.html";
-
-const CM_PREF = "privacy.trackingprotection.cryptomining.enabled";
-const FP_PREF = "privacy.trackingprotection.fingerprinting.enabled";
-const TP_PREF = "privacy.trackingprotection.enabled";
-const CB_PREF = "network.cookie.cookieBehavior";
-const GPC_PREF = "privacy.globalprivacycontrol.enabled";
-
-const PREF_REPORT_BREAKAGE_URL = "browser.contentblocking.reportBreakage.url";
-
-let { HttpServer } = ChromeUtils.importESModule(
- "resource://testing-common/httpd.sys.mjs"
-);
-let { CommonUtils } = ChromeUtils.importESModule(
- "resource://services-common/utils.sys.mjs"
-);
-let { Preferences } = ChromeUtils.importESModule(
- "resource://gre/modules/Preferences.sys.mjs"
-);
-
-add_setup(async function () {
- await UrlClassifierTestUtils.addTestTrackers();
-
- // Disable Report Broken Site, as it hides "Site not working?" when enabled.
- await SpecialPowers.pushPrefEnv({
- set: [["ui.new-webcompat-reporter.enabled", false]],
- });
-
- registerCleanupFunction(() => {
- // Clear prefs that are touched in this test again for sanity.
- Services.prefs.clearUserPref(TP_PREF);
- Services.prefs.clearUserPref(CB_PREF);
- Services.prefs.clearUserPref(FP_PREF);
- Services.prefs.clearUserPref(CM_PREF);
- Services.prefs.clearUserPref(GPC_PREF);
- Services.prefs.clearUserPref(PREF_REPORT_BREAKAGE_URL);
-
- UrlClassifierTestUtils.cleanupTestTrackers();
- });
-
- await SpecialPowers.pushPrefEnv({
- set: [
- [
- "urlclassifier.features.fingerprinting.blacklistHosts",
- "fingerprinting.example.com",
- ],
- [
- "urlclassifier.features.fingerprinting.annotate.blacklistHosts",
- "fingerprinting.example.com",
- ],
- ["privacy.trackingprotection.cryptomining.enabled", true],
- [
- "urlclassifier.features.cryptomining.blacklistHosts",
- "cryptomining.example.com",
- ],
- [
- "urlclassifier.features.cryptomining.annotate.blacklistHosts",
- "cryptomining.example.com",
- ],
- ["privacy.globalprivacycontrol.enabled", true],
- ],
- });
-});
-
-add_task(async function testReportBreakageCancel() {
- Services.prefs.setBoolPref(TP_PREF, true);
-
- await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function () {
- await openProtectionsPanel();
- await TestUtils.waitForCondition(() =>
- gProtectionsHandler._protectionsPopup.hasAttribute("blocking")
- );
-
- let siteNotWorkingButton = document.getElementById(
- "protections-popup-tp-switch-breakage-link"
- );
- ok(
- BrowserTestUtils.isVisible(siteNotWorkingButton),
- "site not working button is visible"
- );
- let siteNotWorkingView = document.getElementById(
- "protections-popup-siteNotWorkingView"
- );
- let viewShown = BrowserTestUtils.waitForEvent(
- siteNotWorkingView,
- "ViewShown"
- );
- siteNotWorkingButton.click();
- await viewShown;
-
- let sendReportButton = document.getElementById(
- "protections-popup-siteNotWorkingView-sendReport"
- );
- let sendReportView = document.getElementById(
- "protections-popup-sendReportView"
- );
- viewShown = BrowserTestUtils.waitForEvent(sendReportView, "ViewShown");
- sendReportButton.click();
- await viewShown;
-
- ok(true, "Report breakage view was shown");
-
- viewShown = BrowserTestUtils.waitForEvent(siteNotWorkingView, "ViewShown");
- let cancelButton = document.getElementById(
- "protections-popup-sendReportView-cancel"
- );
- cancelButton.click();
- await viewShown;
-
- ok(true, "Main view was shown");
- });
-
- Services.prefs.clearUserPref(TP_PREF);
-});
-
-add_task(async function testReportBreakageSiteException() {
- Services.prefs.setBoolPref(TP_PREF, true);
-
- let url = TRACKING_PAGE + "?a=b&1=abc&unicode=🦊";
-
- await BrowserTestUtils.withNewTab(url, async browser => {
- let loaded = BrowserTestUtils.browserLoaded(browser, false);
- gProtectionsHandler.disableForCurrentPage();
- await loaded;
-
- await openProtectionsPanel();
-
- let siteFixedButton = document.getElementById(
- "protections-popup-tp-switch-breakage-fixed-link"
- );
- ok(
- BrowserTestUtils.isVisible(siteFixedButton),
- "site fixed button is visible"
- );
- let sendReportView = document.getElementById(
- "protections-popup-sendReportView"
- );
- let viewShown = BrowserTestUtils.waitForEvent(sendReportView, "ViewShown");
- siteFixedButton.click();
- await viewShown;
-
- ok(true, "Report breakage view was shown");
-
- await testReportBreakageSubmit(
- TRACKING_PAGE,
- "trackingprotection",
- false,
- true
- );
-
- // Pass false for shouldReload - there's no need since the tab is going away.
- gProtectionsHandler.enableForCurrentPage(false);
- });
-
- Services.prefs.clearUserPref(TP_PREF);
-});
-
-add_task(async function testNoTracking() {
- await BrowserTestUtils.withNewTab(BENIGN_PAGE, async function () {
- await openProtectionsPanel();
-
- let siteNotWorkingButton = document.getElementById(
- "protections-popup-tp-switch-breakage-link"
- );
- ok(
- BrowserTestUtils.isHidden(siteNotWorkingButton),
- "site not working button is not visible"
- );
- });
-});
-
-add_task(async function testReportBreakageError() {
- Services.prefs.setBoolPref(TP_PREF, true);
- // Make sure that we correctly strip the query.
- let url = TRACKING_PAGE + "?a=b&1=abc&unicode=🦊";
- await BrowserTestUtils.withNewTab(url, async function () {
- await openAndTestReportBreakage(TRACKING_PAGE, "trackingprotection", true);
- });
-
- Services.prefs.clearUserPref(TP_PREF);
-});
-
-add_task(async function testTP() {
- Services.prefs.setBoolPref(TP_PREF, true);
- // Make sure that we correctly strip the query.
- let url = TRACKING_PAGE + "?a=b&1=abc&unicode=🦊";
- await BrowserTestUtils.withNewTab(url, async function () {
- await openAndTestReportBreakage(TRACKING_PAGE, "trackingprotection");
- });
-
- Services.prefs.clearUserPref(TP_PREF);
-});
-
-add_task(async function testCR() {
- Services.prefs.setIntPref(
- CB_PREF,
- Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER
- );
- // Make sure that we correctly strip the query.
- let url = COOKIE_PAGE + "?a=b&1=abc&unicode=🦊";
- await BrowserTestUtils.withNewTab(url, async function () {
- await openAndTestReportBreakage(COOKIE_PAGE, "cookierestrictions");
- });
-
- Services.prefs.clearUserPref(CB_PREF);
-});
-
-add_task(async function testFP() {
- Services.prefs.setIntPref(CB_PREF, Ci.nsICookieService.BEHAVIOR_ACCEPT);
- Services.prefs.setBoolPref(FP_PREF, true);
- // Make sure that we correctly strip the query.
- let url = TRACKING_PAGE + "?a=b&1=abc&unicode=🦊";
- await BrowserTestUtils.withNewTab(url, async function (browser) {
- let promise = waitForContentBlockingEvent();
- await SpecialPowers.spawn(browser, [], function () {
- content.postMessage("fingerprinting", "*");
- });
- await promise;
-
- await openAndTestReportBreakage(TRACKING_PAGE, "fingerprinting", true);
- });
-
- Services.prefs.clearUserPref(FP_PREF);
- Services.prefs.clearUserPref(CB_PREF);
-});
-
-add_task(async function testCM() {
- Services.prefs.setIntPref(CB_PREF, Ci.nsICookieService.BEHAVIOR_ACCEPT);
- Services.prefs.setBoolPref(CM_PREF, true);
- // Make sure that we correctly strip the query.
- let url = TRACKING_PAGE + "?a=b&1=abc&unicode=🦊";
- await BrowserTestUtils.withNewTab(url, async function (browser) {
- let promise = waitForContentBlockingEvent();
- await SpecialPowers.spawn(browser, [], function () {
- content.postMessage("cryptomining", "*");
- });
- await promise;
-
- await openAndTestReportBreakage(TRACKING_PAGE, "cryptomining", true);
- });
-
- Services.prefs.clearUserPref(CM_PREF);
- Services.prefs.clearUserPref(CB_PREF);
-});
-
-async function openAndTestReportBreakage(url, tags, error = false) {
- await openProtectionsPanel();
-
- let siteNotWorkingButton = document.getElementById(
- "protections-popup-tp-switch-breakage-link"
- );
- ok(
- BrowserTestUtils.isVisible(siteNotWorkingButton),
- "site not working button is visible"
- );
- let siteNotWorkingView = document.getElementById(
- "protections-popup-siteNotWorkingView"
- );
- let viewShown = BrowserTestUtils.waitForEvent(
- siteNotWorkingView,
- "ViewShown"
- );
- siteNotWorkingButton.click();
- await viewShown;
-
- let sendReportButton = document.getElementById(
- "protections-popup-siteNotWorkingView-sendReport"
- );
- let sendReportView = document.getElementById(
- "protections-popup-sendReportView"
- );
- viewShown = BrowserTestUtils.waitForEvent(sendReportView, "ViewShown");
- sendReportButton.click();
- await viewShown;
-
- ok(true, "Report breakage view was shown");
-
- await testReportBreakageSubmit(url, tags, error, false);
-}
-
-// This function assumes that the breakage report view is ready.
-async function testReportBreakageSubmit(url, tags, error, hasException) {
- // Setup a mock server for receiving breakage reports.
- let server = new HttpServer();
- server.start(-1);
- let i = server.identity;
- let path =
- i.primaryScheme + "://" + i.primaryHost + ":" + i.primaryPort + "/";
-
- Services.prefs.setStringPref(PREF_REPORT_BREAKAGE_URL, path);
-
- let comments = document.getElementById(
- "protections-popup-sendReportView-collection-comments"
- );
- is(comments.value, "", "Comments textarea should initially be empty");
-
- let submitButton = document.getElementById(
- "protections-popup-sendReportView-submit"
- );
- let reportURL = document.getElementById(
- "protections-popup-sendReportView-collection-url"
- ).value;
-
- is(reportURL, url, "Shows the correct URL in the report UI.");
-
- // Make sure that sending the report closes the identity popup.
- let popuphidden = BrowserTestUtils.waitForEvent(
- gProtectionsHandler._protectionsPopup,
- "popuphidden"
- );
-
- // Check that we're receiving a good report.
- await new Promise(resolve => {
- server.registerPathHandler("/", async (request, response) => {
- is(request.method, "POST", "request was a post");
-
- // Extract and "parse" the form data in the request body.
- let body = CommonUtils.readBytesFromInputStream(request.bodyInputStream);
- let boundary = request
- .getHeader("Content-Type")
- .match(/boundary=-+([^-]*)/i)[1];
- let regex = new RegExp("-+" + boundary + "-*\\s+");
- let sections = body.split(regex);
-
- let prefs = [
- "privacy.trackingprotection.enabled",
- "privacy.trackingprotection.pbmode.enabled",
- "urlclassifier.trackingTable",
- "network.http.referer.defaultPolicy",
- "network.http.referer.defaultPolicy.pbmode",
- "network.cookie.cookieBehavior",
- "privacy.annotate_channels.strict_list.enabled",
- "privacy.restrict3rdpartystorage.expiration",
- "privacy.trackingprotection.fingerprinting.enabled",
- "privacy.trackingprotection.cryptomining.enabled",
- "privacy.globalprivacycontrol.enabled",
- ];
- let prefsBody = "";
-
- for (let pref of prefs) {
- prefsBody += `${pref}: ${Preferences.get(pref)}\r\n`;
- }
-
- Assert.deepEqual(
- sections,
- [
- "",
- `Content-Disposition: form-data; name=\"title\"\r\n\r\n${
- Services.io.newURI(reportURL).host
- }\r\n`,
- 'Content-Disposition: form-data; name="body"\r\n\r\n' +
- `Full URL: ${reportURL + "?"}\r\n` +
- `userAgent: ${navigator.userAgent}\r\n\r\n` +
- "**Preferences**\r\n" +
- `${prefsBody}\r\n` +
- `hasException: ${hasException}\r\n\r\n` +
- "**Comments**\r\n" +
- "This is a comment\r\n",
- 'Content-Disposition: form-data; name="labels"\r\n\r\n' +
- `${hasException ? "" : tags}\r\n`,
- "",
- ],
- "Should send the correct form data"
- );
-
- if (error) {
- response.setStatusLine(request.httpVersion, 500, "Request failed");
- } else {
- response.setStatusLine(request.httpVersion, 201, "Entry created");
- }
-
- resolve();
- });
-
- comments.value = "This is a comment";
- submitButton.click();
- });
-
- let errorMessage = document.getElementById(
- "protections-popup-sendReportView-report-error"
- );
- if (error) {
- await TestUtils.waitForCondition(() =>
- BrowserTestUtils.isVisible(errorMessage)
- );
- is(
- comments.value,
- "This is a comment",
- "Comment not cleared in case of an error"
- );
- gProtectionsHandler._protectionsPopup.hidePopup();
- } else {
- ok(BrowserTestUtils.isHidden(errorMessage), "Error message not shown");
- }
-
- await popuphidden;
-
- // Stop the server.
- await new Promise(r => server.stop(r));
-
- Services.prefs.clearUserPref(PREF_REPORT_BREAKAGE_URL);
-}