Bug 1469951 - Update homepage policy to include startpage r=Felipe
authorMichael Kaply <mozilla@kaply.com>
Tue, 16 Oct 2018 15:09:58 +0000
changeset 499941 83aba42445aad36c01279a71fc4c73563991a3be
parent 499940 88f1a7ca5c3f31a5b5d53fc5231328965f9df4a0
child 499942 9d781037111bc5c77a643be0ae23188117a71cef
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe
bugs1469951
milestone64.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 1469951 - Update homepage policy to include startpage r=Felipe Differential Revision: https://phabricator.services.mozilla.com/D8562
browser/components/enterprisepolicies/Policies.jsm
browser/components/enterprisepolicies/schemas/policies-schema.json
browser/components/enterprisepolicies/tests/browser/browser_policy_set_homepage.js
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -543,33 +543,51 @@ var Policies = {
     },
   },
 
   "Homepage": {
     onBeforeUIStartup(manager, param) {
       // |homepages| will be a string containing a pipe-separated ('|') list of
       // URLs because that is what the "Home page" section of about:preferences
       // (and therefore what the pref |browser.startup.homepage|) accepts.
-      let homepages = param.URL.href;
-      if (param.Additional && param.Additional.length > 0) {
-        homepages += "|" + param.Additional.map(url => url.href).join("|");
+      if (param.URL) {
+        let homepages = param.URL.href;
+        if (param.Additional && param.Additional.length > 0) {
+          homepages += "|" + param.Additional.map(url => url.href).join("|");
+        }
+        if (param.Locked) {
+          setAndLockPref("browser.startup.homepage", homepages);
+          setAndLockPref("pref.browser.homepage.disable_button.current_page", true);
+          setAndLockPref("pref.browser.homepage.disable_button.bookmark_page", true);
+          setAndLockPref("pref.browser.homepage.disable_button.restore_default", true);
+        } else {
+          setDefaultPref("browser.startup.homepage", homepages);
+          runOncePerModification("setHomepage", homepages, () => {
+            Services.prefs.clearUserPref("browser.startup.homepage");
+          });
+        }
       }
-      if (param.Locked) {
-        setAndLockPref("browser.startup.homepage", homepages);
-        setAndLockPref("browser.startup.page", 1);
-        setAndLockPref("pref.browser.homepage.disable_button.current_page", true);
-        setAndLockPref("pref.browser.homepage.disable_button.bookmark_page", true);
-        setAndLockPref("pref.browser.homepage.disable_button.restore_default", true);
-      } else {
-        setDefaultPref("browser.startup.homepage", homepages);
-        setDefaultPref("browser.startup.page", 1);
-        runOncePerModification("setHomepage", homepages, () => {
-          Services.prefs.clearUserPref("browser.startup.homepage");
-          Services.prefs.clearUserPref("browser.startup.page");
-        });
+      if (param.StartPage) {
+        let prefValue;
+        switch (param.StartPage) {
+          case "none":
+            prefValue = 0;
+            break;
+          case "homepage":
+            prefValue = 1;
+            break;
+          case "previous-session":
+            prefValue = 3;
+            break;
+        }
+        if (param.Locked) {
+          setAndLockPref("browser.startup.page", prefValue);
+        } else {
+          setDefaultPref("browser.startup.page", prefValue);
+        }
       }
     },
   },
 
   "InstallAddonsPermission": {
     onBeforeUIStartup(manager, param) {
       if ("Allow" in param) {
         addAllowDenyPermissions("install", param.Allow, null);
--- a/browser/components/enterprisepolicies/schemas/policies-schema.json
+++ b/browser/components/enterprisepolicies/schemas/policies-schema.json
@@ -343,19 +343,22 @@
           "type": "boolean"
         },
         "Additional": {
           "type": "array",
           "strict": false,
           "items": {
             "type": "URL"
           }
+        },
+        "StartPage": {
+          "type": "string",
+          "enum": ["none", "homepage", "previous-session"]
         }
-      },
-      "required": ["URL"]
+      }
     },
 
     "InstallAddonsPermission": {
       "type": "object",
       "properties": {
         "Allow": {
           "type": "array",
           "strict": false,
--- a/browser/components/enterprisepolicies/tests/browser/browser_policy_set_homepage.js
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_set_homepage.js
@@ -5,41 +5,51 @@
 ChromeUtils.defineModuleGetter(this, "HomePage",
                                "resource:///modules/HomePage.jsm");
 
 registerCleanupFunction(function restore_pref_values() {
   // These two prefs are set as user prefs in case the "Locked"
   // option from this policy was not used. In this case, it won't
   // be tracked nor restored by the PoliciesPrefTracker.
   Services.prefs.clearUserPref("browser.startup.homepage");
-  Services.prefs.clearUserPref("browser.startup.page");
 });
 
-async function check_homepage({expectedURL, expectedPageVal = 1, locked = false}) {
-  is(HomePage.get(),
-     expectedURL, "Homepage URL should match expected");
-  is(Services.prefs.getIntPref("browser.startup.page", -1), expectedPageVal,
-     "Pref page value should match expected");
-  is(Services.prefs.prefIsLocked("browser.startup.homepage"), locked,
-     "Lock status of browser.startup.homepage should match expected");
-  is(Services.prefs.prefIsLocked("browser.startup.page"), locked,
-     "Lock status of browser.startup.page should match expected");
+async function check_homepage({expectedURL, expectedPageVal = -1, locked = false}) {
+  if (expectedURL) {
+    is(HomePage.get(),
+       expectedURL, "Homepage URL should match expected");
+    is(Services.prefs.prefIsLocked("browser.startup.homepage"), locked,
+       "Lock status of browser.startup.homepage should match expected");
+  }
+  if (expectedPageVal != -1) {
+    is(Services.prefs.getIntPref("browser.startup.page", -1), expectedPageVal,
+       "Pref page value should match expected");
+    is(Services.prefs.prefIsLocked("browser.startup.page"), locked,
+       "Lock status of browser.startup.page should match expected");
+  }
 
   // Test that UI is disabled when the Locked property is enabled
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:preferences");
   await ContentTask.spawn(tab.linkedBrowser, {expectedURL, expectedPageVal, locked},
                           // eslint-disable-next-line no-shadow
                           async function({expectedURL, expectedPageVal, locked}) {
-    let browserRestoreSessionCheckbox = content.document.getElementById("browserRestoreSession");
-    is(browserRestoreSessionCheckbox.disabled, locked,
-       "Disabled status of session restore status should match expected");
-    let shouldBeChecked = expectedPageVal === 3;
-    is(browserRestoreSessionCheckbox.checked, shouldBeChecked,
-       "Session restore status checkbox should be: " + (shouldBeChecked ? "checked" : "unchecked"));
+    if (expectedPageVal != -1) {
+      // Only check restore checkbox for StartPage
+      let browserRestoreSessionCheckbox = content.document.getElementById("browserRestoreSession");
+      is(browserRestoreSessionCheckbox.disabled, locked,
+         "Disabled status of session restore status should match expected");
+      let shouldBeChecked = expectedPageVal === 3;
+      is(browserRestoreSessionCheckbox.checked, shouldBeChecked,
+         "Session restore status checkbox should be: " + (shouldBeChecked ? "checked" : "unchecked"));
+    }
 
+    if (!expectedURL) {
+      // If only StartPage was changed, no need to check these
+      return;
+    }
     content.document.getElementById("category-home").click();
 
     let homepageTextbox = content.document.getElementById("homePageUrl");
     // Unfortunately this test does not work because the new UI does not fill
     // default values into the URL box at the moment.
     // is(homepageTextbox.value, expectedURL,
     //    "Homepage URL should match expected");
 
@@ -83,16 +93,17 @@ add_task(async function homepage_test_re
     "policies": {
       "Homepage": {
         "URL": "http://example1.com/",
       },
     },
   });
   await check_homepage({expectedURL: "http://example2.com/",
                        expectedPageVal: 3});
+  Services.prefs.clearUserPref("browser.startup.page");
 });
 
 add_task(async function homepage_test_different_policy_value() {
   // This policy is a change from the policy's previous value. This should
   // override the user's homepage
   await setupPolicyEngineWithJson({
     "policies": {
       "Homepage": {
@@ -160,8 +171,79 @@ add_task(async function homepage_test_an
     "policies": {
       "Homepage": {
         "URL": "http://example1.com/#test",
       },
     },
   });
   await check_homepage({expectedURL: "http://example1.com/#test"});
 });
+
+add_task(async function homepage_test_startpage_homepage() {
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "Homepage": {
+        "URL": "http://example1.com/#test",
+        "StartPage": "homepage",
+      },
+    },
+  });
+  await check_homepage({expectedURL: "http://example1.com/#test", expectedPageVal: 1});
+});
+
+add_task(async function homepage_test_startpage_homepage_locked() {
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "Homepage": {
+        "URL": "http://example1.com/#test",
+        "StartPage": "homepage",
+        "Locked": true,
+      },
+    },
+  });
+  await check_homepage({expectedURL: "http://example1.com/#test", expectedPageVal: 1, locked: true});
+});
+
+add_task(async function homepage_test_startpage_none() {
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "Homepage": {
+        "StartPage": "none",
+      },
+    },
+  });
+  await check_homepage({expectedPageVal: 0});
+});
+
+add_task(async function homepage_test_startpage_none_locked() {
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "Homepage": {
+        "StartPage": "none",
+        "Locked": true,
+      },
+    },
+  });
+  await check_homepage({expectedPageVal: 0, locked: true});
+});
+
+add_task(async function homepage_test_startpage_restore() {
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "Homepage": {
+        "StartPage": "previous-session",
+      },
+    },
+  });
+  await check_homepage({expectedPageVal: 3});
+});
+
+add_task(async function homepage_test_startpage_restore_locked() {
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "Homepage": {
+        "StartPage": "previous-session",
+        "Locked": true,
+      },
+    },
+  });
+  await check_homepage({expectedPageVal: 3, locked: true});
+});