diff --git a/browser/components/preferences/privacy.inc.xhtml b/browser/components/preferences/privacy.inc.xhtml index caa17e2ba4985..ef3369d4250e3 100644 --- a/browser/components/preferences/privacy.inc.xhtml +++ b/browser/components/preferences/privacy.inc.xhtml @@ -1005,8 +1005,7 @@ - + diff --git a/browser/components/preferences/privacy.js b/browser/components/preferences/privacy.js index 93e8077c556f6..b6d9d7ee5ded4 100644 --- a/browser/components/preferences/privacy.js +++ b/browser/components/preferences/privacy.js @@ -455,13 +455,20 @@ var gPrivacyPane = { "https-only-prefs"; link.setAttribute("href", httpsOnlyURL); - setSyncFromPrefListener("httpsOnlyRadioGroup", () => - this.syncFromHttpsOnlyPref() + // Set radio-value based on the pref value + this.syncFromHttpsOnlyPref(); + + // Create event listener for when the user clicks + // on one of the radio buttons + setEventListener( + "httpsOnlyRadioGroup", + "command", + this.syncToHttpsOnlyPref ); - setSyncToPrefListener("httpsOnlyRadioGroup", () => - this.syncToHttpsOnlyPref() + // Update radio-value when the pref changes + Preferences.get("dom.security.https_only_mode").on("change", () => + this.syncFromHttpsOnlyPref() ); - Preferences.get("dom.security.https_only_mode_pbm").on("change", () => this.syncFromHttpsOnlyPref() ); diff --git a/browser/components/preferences/tests/browser.ini b/browser/components/preferences/tests/browser.ini index 3df3433ecb219..ee4af8a226a81 100644 --- a/browser/components/preferences/tests/browser.ini +++ b/browser/components/preferences/tests/browser.ini @@ -64,6 +64,7 @@ skip-if = true || !healthreport # Bug 1185403 for the "true" [browser_homepages_filter_aboutpreferences.js] [browser_homepages_use_bookmark.js] [browser_homepage_default.js] +[browser_https_only_section.js] [browser_extension_controlled.js] skip-if = ccov && (os == 'linux' || os == 'win') # Linux: bug 1613530, Windows: bug 1437051 [browser_languages_subdialog.js] diff --git a/browser/components/preferences/tests/browser_https_only_section.js b/browser/components/preferences/tests/browser_https_only_section.js new file mode 100644 index 0000000000000..5c20d87a66807 --- /dev/null +++ b/browser/components/preferences/tests/browser_https_only_section.js @@ -0,0 +1,74 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Bug 1671122 - Fixed bug where second click on HTTPS-Only Mode enable-checkbox disables it again. +// https://bugzilla.mozilla.org/bug/1671122 +"use strict"; + +const HTTPS_ONLY_ENABLED = "enabled"; +const HTTPS_ONLY_PBM_ONLY = "privateOnly"; +const HTTPS_ONLY_DISABLED = "disabled"; + +add_task(async function httpsOnlyRadioGroupIsWorking() { + // Make sure HTTPS-Only mode is only enabled for PBM + + registerCleanupFunction(async function() { + Services.prefs.clearUserPref("dom.security.https_only_mode"); + Services.prefs.clearUserPref("dom.security.https_only_mode_pbm"); + }); + + await SpecialPowers.setBoolPref("dom.security.https_only_mode", false); + await SpecialPowers.setBoolPref("dom.security.https_only_mode_pbm", true); + + await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true }); + + const doc = gBrowser.selectedBrowser.contentDocument; + const radioGroup = doc.getElementById("httpsOnlyRadioGroup"); + const enableAllRadio = doc.getElementById("httpsOnlyRadioEnabled"); + const enablePbmRadio = doc.getElementById("httpsOnlyRadioEnabledPBM"); + const disableRadio = doc.getElementById("httpsOnlyRadioDisabled"); + + // Check if UI + check(radioGroup, HTTPS_ONLY_PBM_ONLY); + + // Check if UI updated on pref-change + await SpecialPowers.setBoolPref("dom.security.https_only_mode_pbm", false); + check(radioGroup, HTTPS_ONLY_DISABLED); + + // Check if prefs change if clicked on radio button + enableAllRadio.click(); + check(radioGroup, HTTPS_ONLY_ENABLED); + + // Check if prefs stay the same if clicked on same + // radio button again (see bug 1671122) + enableAllRadio.click(); + check(radioGroup, HTTPS_ONLY_ENABLED); + + // Check if prefs are set correctly for PBM-only mode. + enablePbmRadio.click(); + check(radioGroup, HTTPS_ONLY_PBM_ONLY); + + // Check if prefs are set correctly when disabled again. + disableRadio.click(); + check(radioGroup, HTTPS_ONLY_DISABLED); + + BrowserTestUtils.removeTab(gBrowser.selectedTab); +}); + +function check(radioGroupElement, expectedValue) { + is( + radioGroupElement.value, + expectedValue, + "Radio Group value should match expected value" + ); + is( + SpecialPowers.getBoolPref("dom.security.https_only_mode"), + expectedValue === HTTPS_ONLY_ENABLED, + "HTTPS-Only pref should match expected value." + ); + is( + SpecialPowers.getBoolPref("dom.security.https_only_mode_pbm"), + expectedValue === HTTPS_ONLY_PBM_ONLY, + "HTTPS-Only PBM pref should match expected value." + ); +}