Bug 1568855 - Setting a new default homepage should switch to Custom URL in prefs. r=jaws
authorMichael Kaply <mozilla@kaply.com>
Tue, 30 Jul 2019 23:34:49 +0000
changeset 485452 4d8cee124c4e668b6f2edce172f9297eb9457b06
parent 485451 56b1594759719d8d815f91a7017641a131dfa88f
child 485453 10fed3e6310ac8b40928e8bb37a9a975915c2124
push id91307
push usermozilla@kaply.com
push dateWed, 31 Jul 2019 00:49:41 +0000
treeherderautoland@4d8cee124c4e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1568855
milestone70.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 1568855 - Setting a new default homepage should switch to Custom URL in prefs. r=jaws Differential Revision: https://phabricator.services.mozilla.com/D39405
browser/components/preferences/in-content/home.js
browser/components/preferences/in-content/tests/browser.ini
browser/components/preferences/in-content/tests/browser_homepage_default.js
browser/modules/HomePage.jsm
--- a/browser/components/preferences/in-content/home.js
+++ b/browser/components/preferences/in-content/home.js
@@ -318,16 +318,17 @@ var gHomePane = {
         } else {
           this._renderCustomSettings({ shouldShow: false });
         }
         break;
       case this.HOME_MODE_CUSTOM:
         if (startupPref.value === gMainPane.STARTUP_PREF_BLANK) {
           Services.prefs.clearUserPref(startupPref.id);
         }
+        HomePage.clear();
         this._renderCustomSettings({ shouldShow: true });
         break;
     }
   },
 
   /**
    * Switches the "Use Current Page" button between its singular and plural
    * forms.
--- a/browser/components/preferences/in-content/tests/browser.ini
+++ b/browser/components/preferences/in-content/tests/browser.ini
@@ -52,16 +52,17 @@ skip-if = (verify && debug && (os == 'li
 [browser_contentblocking_categories.js]
 [browser_contentblocking.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_homepages_use_bookmark.js]
+[browser_homepage_default.js]
 [browser_extension_controlled.js]
 skip-if = ccov && os == 'win' # bug 1437051
 [browser_languages_subdialog.js]
 [browser_browser_languages_subdialog.js]
 skip-if = (!debug && os == 'win') # Bug 1518370
 [browser_layersacceleration.js]
 [browser_masterpassword.js]
 [browser_newtab_menu.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_homepage_default.js
@@ -0,0 +1,31 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function default_homepage_test() {
+  await SpecialPowers.pushPrefEnv({
+    set: [["browser.startup.page", 1]],
+  });
+  let defaults = Services.prefs.getDefaultBranch("");
+  // Simulate a homepage set via policy or a distribution.
+  defaults.setStringPref("browser.startup.homepage", "https://example.com");
+
+  await openPreferencesViaOpenPreferencesAPI("paneHome", { leaveOpen: true });
+
+  let doc = gBrowser.contentDocument;
+  let homeMode = doc.getElementById("homeMode");
+  Assert.equal(homeMode.value, 2, "homeMode should be 2 (Custom URL)");
+
+  let homePageUrl = doc.getElementById("homePageUrl");
+  Assert.equal(
+    homePageUrl.value,
+    "https://example.com",
+    "homePageUrl should be example.com"
+  );
+
+  registerCleanupFunction(async () => {
+    defaults.setStringPref("browser.startup.homepage", "about:home");
+    BrowserTestUtils.removeTab(gBrowser.selectedTab);
+  });
+});
--- a/browser/modules/HomePage.jsm
+++ b/browser/modules/HomePage.jsm
@@ -12,16 +12,17 @@ var EXPORTED_SYMBOLS = ["HomePage"];
 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.defineModuleGetter(
   this,
   "PrivateBrowsingUtils",
   "resource://gre/modules/PrivateBrowsingUtils.jsm"
 );
 
 const kPrefName = "browser.startup.homepage";
+const kDefaultHomePage = "about:home";
 
 function getHomepagePref(useDefault) {
   let homePage;
   let prefs = Services.prefs;
   if (useDefault) {
     prefs = prefs.getDefaultBranch(null);
   }
   try {
@@ -84,19 +85,23 @@ let HomePage = {
     return Services.prefs.prefHasUserValue(kPrefName);
   },
 
   get locked() {
     return Services.prefs.prefIsLocked(kPrefName);
   },
 
   get isDefault() {
-    return HomePage.get() === HomePage.getDefault();
+    return HomePage.get() === kDefaultHomePage;
   },
 
   set(value) {
     Services.prefs.setStringPref(kPrefName, value);
   },
 
-  reset() {
+  clear() {
     Services.prefs.clearUserPref(kPrefName);
   },
+
+  reset() {
+    Services.prefs.setStringPref(kPrefName, kDefaultHomePage);
+  },
 };