Bug 1435786 - ensure Request English checkbox syncs to/from pref r=jaws
authorMyk Melez <myk@mykzilla.org>
Mon, 05 Feb 2018 14:04:43 -0800
changeset 402788 30d6a1c8f1e180272948173d06c6c989d8e26334
parent 402787 9fc3ea5161d685292e6ee17602aee5b159338222
child 402789 dff05b1676b1aef24aca19027ef2b4e87cc4ed46
push id59242
push usermyk@mozilla.com
push dateWed, 07 Feb 2018 17:46:37 +0000
treeherderautoland@30d6a1c8f1e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1435786
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1435786 - ensure Request English checkbox syncs to/from pref r=jaws MozReview-Commit-ID: FVcsPOSS01T
browser/components/preferences/in-content/tests/browser.ini
browser/components/preferences/in-content/tests/browser_languages_subdialog.js
browser/components/preferences/languages.js
browser/components/preferences/languages.xul
--- a/browser/components/preferences/in-content/tests/browser.ini
+++ b/browser/components/preferences/in-content/tests/browser.ini
@@ -45,16 +45,17 @@ skip-if = os != "win" || (os == "win" &&
 [browser_connection.js]
 [browser_connection_bug388287.js]
 [browser_cookies_exceptions.js]
 [browser_defaultbrowser_alwayscheck.js]
 [browser_healthreport.js]
 skip-if = true || !healthreport # Bug 1185403 for the "true"
 [browser_homepages_filter_aboutpreferences.js]
 [browser_extension_controlled.js]
+[browser_languages_subdialog.js]
 [browser_layersacceleration.js]
 [browser_masterpassword.js]
 [browser_notifications_do_not_disturb.js]
 [browser_password_management.js]
 [browser_performance.js]
 skip-if = !e10s
 [browser_performance_e10srollout.js]
 skip-if = !e10s
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_languages_subdialog.js
@@ -0,0 +1,62 @@
+add_task(async function() {
+  await openPreferencesViaOpenPreferencesAPI("general", { leaveOpen: true });
+  // eslint-disable-next-line mozilla/no-cpows-in-tests
+  const contentDocument = gBrowser.contentDocument;
+  // eslint-disable-next-line mozilla/no-cpows-in-tests
+  const dialogOverlay = content.gSubDialog._preloadDialog._overlay;
+
+  async function languagesSubdialogOpened() {
+    const promiseSubDialogLoaded = promiseLoadSubDialog("chrome://browser/content/preferences/languages.xul");
+    contentDocument.getElementById("chooseLanguage").click();
+    const win = await promiseSubDialogLoaded;
+    win.Preferences.forceEnableInstantApply();
+    is(dialogOverlay.style.visibility, "visible", "The dialog is visible.");
+    return win;
+  }
+
+  function closeLanguagesSubdialog() {
+    const closeBtn = dialogOverlay.querySelector(".dialogClose");
+    closeBtn.doCommand();
+  }
+
+  is(dialogOverlay.style.visibility, "", "The dialog is invisible.");
+  let win = await languagesSubdialogOpened();
+  ok(win.document.getElementById("spoofEnglish").hidden, "The 'Request English' checkbox is hidden.");
+  closeLanguagesSubdialog();
+  is(dialogOverlay.style.visibility, "", "The dialog is invisible.");
+
+  await SpecialPowers.pushPrefEnv({set: [
+    ["privacy.resistFingerprinting", true],
+    ["privacy.spoof_english", 0],
+  ]});
+
+  win = await languagesSubdialogOpened();
+  ok(!win.document.getElementById("spoofEnglish").hidden, "The 'Request English' checkbox isn't hidden.");
+  ok(!win.document.getElementById("spoofEnglish").checked, "The 'Request English' checkbox isn't checked.");
+  is(win.Preferences.get("privacy.spoof_english").value, 0, "The privacy.spoof_english pref is set to 0.");
+
+  win.document.getElementById("spoofEnglish").checked = true;
+  win.document.getElementById("spoofEnglish").doCommand();
+  ok(win.document.getElementById("spoofEnglish").checked, "The 'Request English' checkbox is checked.");
+  is(win.Preferences.get("privacy.spoof_english").value, 2, "The privacy.spoof_english pref is set to 2.");
+  closeLanguagesSubdialog();
+
+  win = await languagesSubdialogOpened();
+  ok(!win.document.getElementById("spoofEnglish").hidden, "The 'Request English' checkbox isn't hidden.");
+  ok(win.document.getElementById("spoofEnglish").checked, "The 'Request English' checkbox is checked.");
+  is(win.Preferences.get("privacy.spoof_english").value, 2, "The privacy.spoof_english pref is set to 2.");
+
+  win.document.getElementById("spoofEnglish").checked = false;
+  win.document.getElementById("spoofEnglish").doCommand();
+  ok(!win.document.getElementById("spoofEnglish").checked, "The 'Request English' checkbox isn't checked.");
+  is(win.Preferences.get("privacy.spoof_english").value, 1, "The privacy.spoof_english pref is set to 1.");
+  closeLanguagesSubdialog();
+
+  win = await languagesSubdialogOpened();
+  ok(!win.document.getElementById("spoofEnglish").hidden, "The 'Request English' checkbox isn't hidden.");
+  ok(!win.document.getElementById("spoofEnglish").checked, "The 'Request English' checkbox isn't checked.");
+  is(win.Preferences.get("privacy.spoof_english").value, 1, "The privacy.spoof_english pref is set to 1.");
+  closeLanguagesSubdialog();
+
+  gBrowser.removeCurrentTab();
+});
--- a/browser/components/preferences/languages.js
+++ b/browser/components/preferences/languages.js
@@ -314,34 +314,39 @@ var gLanguagesDialog = {
   readSpoofEnglish() {
     var checkbox = document.getElementById("spoofEnglish");
     var resistFingerprinting = Services.prefs.getBoolPref("privacy.resistFingerprinting");
     if (!resistFingerprinting) {
       checkbox.hidden = true;
       return false;
     }
 
-    var spoofEnglish = document.getElementById("privacy.spoof_english").value;
+    var spoofEnglish = Preferences.get("privacy.spoof_english").value;
     var activeLanguages = this._activeLanguages;
     var availableLanguages = this._availableLanguages;
     checkbox.hidden = false;
     switch (spoofEnglish) {
-    case 1: // don't spoof intl.accept_lanauges
+    case 1: // don't spoof intl.accept_languages
       activeLanguages.disabled = false;
       activeLanguages.selectItem(activeLanguages.firstChild);
       availableLanguages.disabled = false;
       this.onAvailableLanguageSelect();
       return false;
-    case 2: // spoof intl.accept_lanauges
+    case 2: // spoof intl.accept_languages
       activeLanguages.clearSelection();
       activeLanguages.disabled = true;
       availableLanguages.disabled = true;
       this.onAvailableLanguageSelect();
       return true;
-    default: // will prompt for spoofing intl.accept_lanauges if resisting fingerprinting
+    default: // will prompt for spoofing intl.accept_languages if resisting fingerprinting
       return false;
     }
   },
 
   writeSpoofEnglish() {
     return document.getElementById("spoofEnglish").checked ? 2 : 1;
   }
 };
+
+// These focus and resize handlers hack around XUL bug 1194844
+// by triggering extra reflow (see bug 1194346).
+window.addEventListener("focus", () => gLanguagesDialog.forceReflow());
+window.addEventListener("resize", () => gLanguagesDialog.forceReflow());
--- a/browser/components/preferences/languages.xul
+++ b/browser/components/preferences/languages.xul
@@ -21,22 +21,17 @@
         buttons="accept,cancel,help"
         persist="lastSelected screenX screenY"
         closebuttonlabel="&preferencesCloseButton.label;"
         closebuttonaccesskey="&preferencesCloseButton.accesskey;"
         role="dialog"
         onload="gLanguagesDialog.init();"
         helpTopic="prefs-languages"
         ondialoghelp="openPrefsHelp()"
-        style="width: &window.width;"
-        onfocus="gLanguagesDialog.forceReflow()"
-        onresize="gLanguagesDialog.forceReflow()">
-
-<!-- The onfocus and onresize handlers above hack around XUL bug 1194844
-   - by triggering extra reflow (see bug 1194346). -->
+        style="width: &window.width;">
 
   <script type="application/javascript" src="chrome://browser/content/utilityOverlay.js"/>
   <script type="application/javascript" src="chrome://global/content/preferencesBindings.js"/>
   <script type="application/javascript" src="chrome://browser/content/preferences/languages.js"/>
 
   <keyset>
     <key key="&windowClose.key;" modifiers="accel" oncommand="Preferences.close(event)"/>
   </keyset>