Skip to content

Commit

Permalink
Bug 1671122 - Fixed bug where second click on HTTPS-Only Mode enable-…
Browse files Browse the repository at this point in the history
…checkbox disables it again. r=ckerschb,preferences-reviewers,Gijs

Differential Revision: https://phabricator.services.mozilla.com/D93519
  • Loading branch information
JulianGaibler committed Oct 15, 2020
1 parent 0fdda83 commit f1ca4d6
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 7 deletions.
3 changes: 1 addition & 2 deletions browser/components/preferences/privacy.inc.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -1005,8 +1005,7 @@
<vbox>
<!-- Please don't remove the wrapping hbox/vbox/box for these elements. It's used to properly compute the search tooltip position. -->
<hbox>
<radiogroup id="httpsOnlyRadioGroup"
preference="dom.security.https_only_mode">
<radiogroup id="httpsOnlyRadioGroup">
<radio id="httpsOnlyRadioEnabled"
data-l10n-id="httpsonly-radio-enabled"
value="enabled"/>
Expand Down
17 changes: 12 additions & 5 deletions browser/components/preferences/privacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
Expand Down
1 change: 1 addition & 0 deletions browser/components/preferences/tests/browser.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
74 changes: 74 additions & 0 deletions browser/components/preferences/tests/browser_https_only_section.js
Original file line number Diff line number Diff line change
@@ -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."
);
}

0 comments on commit f1ca4d6

Please sign in to comment.