Bug 1500379 - Split homepage test into two tests. r=mconley
authorMichael Kaply <mozilla@kaply.com>
Fri, 22 Nov 2019 16:34:42 +0000
changeset 503396 ee7bdadd80bc03b8174aaf29f6916c48cc8cf89c
parent 503395 3bd8841fab31690f88f9e1475a3a42e5f9780202
child 503397 46c23b186d73c481cd309ac8a3a75f3d53835139
push id36833
push userbtara@mozilla.com
push dateFri, 22 Nov 2019 21:40:53 +0000
treeherdermozilla-central@2c912e46295e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1500379
milestone72.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 1500379 - Split homepage test into two tests. r=mconley Differential Revision: https://phabricator.services.mozilla.com/D54306
browser/components/enterprisepolicies/tests/browser/browser.ini
browser/components/enterprisepolicies/tests/browser/browser_policy_set_homepage.js
browser/components/enterprisepolicies/tests/browser/browser_policy_set_startpage.js
browser/components/enterprisepolicies/tests/browser/head.js
--- a/browser/components/enterprisepolicies/tests/browser/browser.ini
+++ b/browser/components/enterprisepolicies/tests/browser/browser.ini
@@ -42,10 +42,11 @@ skip-if = (verify && debug && (os == 'ma
 [browser_policy_downloads.js]
 [browser_policy_extensionsettings.js]
 [browser_policy_firefoxhome.js]
 [browser_policy_override_postupdatepage.js]
 [browser_policy_passwordmanager.js]
 [browser_policy_search_engine.js]
 [browser_policy_searchbar.js]
 [browser_policy_set_homepage.js]
+[browser_policy_set_startpage.js]
 [browser_policy_support_menu.js]
 [browser_policy_websitefilter.js]
--- a/browser/components/enterprisepolicies/tests/browser/browser_policy_set_homepage.js
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_set_homepage.js
@@ -1,128 +1,19 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 "use strict";
 
-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");
 });
 
-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 }) {
-      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;
-      }
-      await content.gotoPref("paneHome");
-
-      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");
-
-      // Wait for rendering to be finished
-      await ContentTaskUtils.waitForCondition(
-        () =>
-          content.document.getElementById("useCurrentBtn").disabled === locked
-      );
-
-      is(
-        homepageTextbox.disabled,
-        locked,
-        "Homepage URL text box disabled status should match expected"
-      );
-      is(
-        content.document.getElementById("homeMode").disabled,
-        locked,
-        "Home mode drop down disabled status should match expected"
-      );
-      is(
-        content.document.getElementById("useCurrentBtn").disabled,
-        locked,
-        '"Use current page" button disabled status should match expected'
-      );
-      is(
-        content.document.getElementById("useBookmarkBtn").disabled,
-        locked,
-        '"Use bookmark" button disabled status should match expected'
-      );
-      is(
-        content.document.getElementById("restoreDefaultHomePageBtn").disabled,
-        locked,
-        '"Restore defaults" button disabled status should match expected'
-      );
-    }
-  );
-  await BrowserTestUtils.removeTab(tab);
-}
-
 add_task(async function homepage_test_simple() {
   await setupPolicyEngineWithJson({
     policies: {
       Homepage: {
         URL: "http://example1.com/",
       },
     },
   });
@@ -217,86 +108,8 @@ 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 });
-});
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_set_startpage.js
@@ -0,0 +1,89 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+add_task(async function setup() {
+  // browser.startup.page is set by unittest-required/user.js,
+  // but we need the default value
+  await SpecialPowers.pushPrefEnv({
+    clear: [["browser.startup.page"]],
+  });
+});
+
+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 });
+});
--- a/browser/components/enterprisepolicies/tests/browser/head.js
+++ b/browser/components/enterprisepolicies/tests/browser/head.js
@@ -8,16 +8,22 @@ const { EnterprisePolicyTesting, Policie
   "resource://testing-common/EnterprisePolicyTesting.jsm",
   null
 );
 const { TestUtils } = ChromeUtils.import(
   "resource://testing-common/TestUtils.jsm",
   null
 );
 
+ChromeUtils.defineModuleGetter(
+  this,
+  "HomePage",
+  "resource:///modules/HomePage.jsm"
+);
+
 PoliciesPrefTracker.start();
 
 async function setupPolicyEngineWithJson(json, customSchema) {
   PoliciesPrefTracker.restoreDefaultValues();
   if (typeof json != "object") {
     let filePath = getTestFilePath(json ? json : "non-existing-file.json");
     return EnterprisePolicyTesting.setupPolicyEngineWithJson(
       filePath,
@@ -54,16 +60,119 @@ async function checkBlockedPage(url, exp
           }
         );
         return blocked == expectedBlocked;
       }, `Page ${url} block was correct (expected=${expectedBlocked}).`);
     }
   );
 }
 
+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 }) {
+      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;
+      }
+      await content.gotoPref("paneHome");
+
+      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");
+
+      // Wait for rendering to be finished
+      await ContentTaskUtils.waitForCondition(
+        () =>
+          content.document.getElementById("useCurrentBtn").disabled === locked
+      );
+
+      is(
+        homepageTextbox.disabled,
+        locked,
+        "Homepage URL text box disabled status should match expected"
+      );
+      is(
+        content.document.getElementById("homeMode").disabled,
+        locked,
+        "Home mode drop down disabled status should match expected"
+      );
+      is(
+        content.document.getElementById("useCurrentBtn").disabled,
+        locked,
+        '"Use current page" button disabled status should match expected'
+      );
+      is(
+        content.document.getElementById("useBookmarkBtn").disabled,
+        locked,
+        '"Use bookmark" button disabled status should match expected'
+      );
+      is(
+        content.document.getElementById("restoreDefaultHomePageBtn").disabled,
+        locked,
+        '"Restore defaults" button disabled status should match expected'
+      );
+    }
+  );
+  await BrowserTestUtils.removeTab(tab);
+}
+
 add_task(async function policies_headjs_startWithCleanSlate() {
   if (Services.policies.status != Ci.nsIEnterprisePolicies.INACTIVE) {
     await setupPolicyEngineWithJson("");
   }
   is(
     Services.policies.status,
     Ci.nsIEnterprisePolicies.INACTIVE,
     "Engine is inactive at the start of the test"