Bug 1446508 - Create test file that makes it easier to add tests for simple policies. r=MattN
authorFelipe Gomes <felipc@gmail.com>
Wed, 21 Mar 2018 13:11:42 -0300
changeset 1460151 4c929665312fc27063c99d519b68ebf13cae1000
parent 1460150 a92b420e1f7fd74cff86ea0e80ae714a469a1786
child 1460152 fa81899efb5e45b28e9fc78e5e3958094dd40008
child 1462990 8d0da6bd03e310c2da5605e7da58fbd58109e5e3
push id260095
push userecoal95@gmail.com
push dateWed, 21 Mar 2018 17:01:50 +0000
treeherdertry@0c24a9ae2a68 [default view] [failures only]
reviewersMattN
bugs1446508
milestone61.0a1
Bug 1446508 - Create test file that makes it easier to add tests for simple policies. r=MattN
browser/components/enterprisepolicies/tests/browser/browser.ini
browser/components/enterprisepolicies/tests/browser/browser_policies_basic_tests.js
browser/components/enterprisepolicies/tests/browser/browser_policies_simple_policies.js
browser/components/enterprisepolicies/tests/browser/browser_policies_simple_pref_policies.js
browser/components/enterprisepolicies/tests/browser/browser_policy_disable_formhistory.js
browser/components/enterprisepolicies/tests/browser/browser_policy_enable_tracking_protection.js
browser/components/enterprisepolicies/tests/browser/browser_policy_remember_passwords.js
--- a/browser/components/enterprisepolicies/tests/browser/browser.ini
+++ b/browser/components/enterprisepolicies/tests/browser/browser.ini
@@ -1,41 +1,39 @@
 [DEFAULT]
 prefs =
   browser.policies.enabled=true
 support-files =
   head.js
   config_popups_cookies_addons_flash.json
   config_broken_json.json
 
+[browser_policies_basic_tests.js]
 [browser_policies_broken_json.js]
 [browser_policies_enterprise_only.js]
 [browser_policies_notice_in_aboutpreferences.js]
 [browser_policies_popups_cookies_addons_flash.js]
 [browser_policies_runOnce_helper.js]
 [browser_policies_setAndLockPref_API.js]
-[browser_policies_simple_policies.js]
+[browser_policies_simple_pref_policies.js]
 [browser_policies_sorted_alphabetically.js]
 [browser_policies_validate_and_parse_API.js]
 [browser_policy_app_update.js]
 [browser_policy_block_about_addons.js]
 [browser_policy_block_about_config.js]
 [browser_policy_block_about_profiles.js]
 [browser_policy_block_about_support.js]
 [browser_policy_block_set_desktop_background.js]
 [browser_policy_bookmarks.js]
 [browser_policy_clear_blocked_cookies.js]
 [browser_policy_default_browser_check.js]
 [browser_policy_disable_feedback_commands.js]
-[browser_policy_disable_formhistory.js]
 [browser_policy_disable_fxaccounts.js]
 [browser_policy_disable_masterpassword.js]
 [browser_policy_disable_pdfjs.js]
 [browser_policy_disable_pocket.js]
 [browser_policy_disable_privatebrowsing.js]
 [browser_policy_disable_safemode.js]
 [browser_policy_disable_shield.js]
 [browser_policy_display_bookmarks.js]
 [browser_policy_display_menu.js]
-[browser_policy_enable_tracking_protection.js]
 [browser_policy_proxy.js]
-[browser_policy_remember_passwords.js]
 [browser_policy_set_homepage.js]
rename from browser/components/enterprisepolicies/tests/browser/browser_policies_simple_policies.js
rename to browser/components/enterprisepolicies/tests/browser/browser_policies_basic_tests.js
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policies_simple_pref_policies.js
@@ -0,0 +1,90 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/*
+ * Use this file to add tests to policies that are
+ * simple pref flips.
+ *
+ * It's best to make a test to actually test the feature
+ * instead of the pref flip, but if that feature is well
+ * covered by tests, including that its pref actually works,
+ * it's OK to have the policy test here just to ensure
+ * that the right pref values are set.
+ */
+
+const POLICIES_TESTS = [
+  /*
+   * Example:
+   * {
+   *   // Policies to be set at once through the engine
+   *   policies: { "DisableFoo": true, "ConfigureBar": 42 },
+   *
+   *   // Locked prefs to check
+   *   lockedPrefs: { "feature.foo": false },
+   *
+   *   // Unlocked prefs to check
+   *   unlockedPrefs: { "bar.baz": 42 }
+   * },
+   */
+
+   // POLICY: RememberPasswords
+  {
+    policies: { "RememberPasswords": false },
+    lockedPrefs: { "signon.rememberSignons": false },
+  },
+  {
+    policies: { "RememberPasswords": true },
+    lockedPrefs: { "signon.rememberSignons": true },
+  },
+
+  // POLICY: DisableFormHistory
+  {
+    policies: { "DisableFormHistory": true },
+    lockedPrefs: { "browser.formfill.enable": false },
+  },
+
+  // POLICY: EnableTrackingProtection
+  {
+    policies: {
+      "EnableTrackingProtection": {
+        "Value": true
+      }
+    },
+    unlockedPrefs: {
+      "privacy.trackingprotection.enabled": true,
+      "privacy.trackingprotection.pbmode.enabled": true,
+    }
+  },
+  {
+    policies: {
+      "EnableTrackingProtection": {
+        "Value": false,
+        "Locked": true
+      }
+    },
+    lockedPrefs: {
+      "privacy.trackingprotection.enabled": false,
+      "privacy.trackingprotection.pbmode.enabled": false,
+    }
+  },
+];
+
+add_task(async function test_policy_remember_passwords() {
+  for (let test of POLICIES_TESTS) {
+    await setupPolicyEngineWithJson({
+      "policies": test.policies
+    });
+
+    info("Checking policy: " + Object.keys(test.policies)[0]);
+
+    for (let [prefName, prefValue] of Object.entries(test.lockedPrefs || {})) {
+      checkLockedPref(prefName, prefValue);
+    }
+
+    for (let [prefName, prefValue] of Object.entries(test.unlockedPrefs || {})) {
+      checkUnlockedPref(prefName, prefValue);
+    }
+  }
+ });
deleted file mode 100644
--- a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_formhistory.js
+++ /dev/null
@@ -1,15 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
-
-"use strict";
-
-add_task(async function test_policy_disable_formhistory() {
-  await setupPolicyEngineWithJson({
-    "policies": {
-      "DisableFormHistory": true
-    }
-  });
-
-  is(Services.prefs.getBoolPref("browser.formfill.enable"), false, "FormHistory has been disabled");
-  is(Services.prefs.prefIsLocked("browser.formfill.enable"), true, "FormHistory pref has been locked");
-});
deleted file mode 100644
--- a/browser/components/enterprisepolicies/tests/browser/browser_policy_enable_tracking_protection.js
+++ /dev/null
@@ -1,33 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
-
-"use strict";
-
-add_task(async function test_policy_enable_tracking_protection1() {
-  await setupPolicyEngineWithJson({
-    "policies": {
-      "EnableTrackingProtection": {
-        "Value": true
-      }
-    }
-  });
-
-  is(Services.prefs.getBoolPref("privacy.trackingprotection.enabled"), true, "Tracking protection has been enabled by default.");
-  is(Services.prefs.getBoolPref("privacy.trackingprotection.pbmode.enabled"), true, "Tracking protection has been enabled by default in private browsing mode.");
-  is(Services.prefs.prefIsLocked("privacy.trackingprotection.enabled"), false, "Tracking protection pref is not locked.");
-});
-
-add_task(async function test_policy_enable_tracking_protection_locked() {
-  await setupPolicyEngineWithJson({
-    "policies": {
-      "EnableTrackingProtection": {
-        "Value": false,
-        "Locked": true
-      }
-    }
-  });
-
-  is(Services.prefs.getBoolPref("privacy.trackingprotection.enabled"), false, "Tracking protection has been disabled by default.");
-  is(Services.prefs.getBoolPref("privacy.trackingprotection.pbmode.enabled"), false, "Tracking protection has been disabled by default in private browsing mode.");
-  is(Services.prefs.prefIsLocked("privacy.trackingprotection.enabled"), true, "Tracking protection pref is locked.");
-});
deleted file mode 100644
--- a/browser/components/enterprisepolicies/tests/browser/browser_policy_remember_passwords.js
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
-
-"use strict";
-
-add_task(async function test_policy_remember_passwords() {
-  await setupPolicyEngineWithJson({
-    "policies": {
-      "RememberPasswords": false
-    }
-  });
-
-  is(Services.prefs.getBoolPref("signon.rememberSignons"), false, "Logins & Passwords have been disabled");
-  is(Services.prefs.prefIsLocked("signon.rememberSignons"), true, "Logins & Passwords pref has been locked");
-
-
-  await setupPolicyEngineWithJson({
-    "policies": {
-      "RememberPasswords": true
-    }
-  });
-
-  is(Services.prefs.getBoolPref("signon.rememberSignons"), true, "Logins & Passwords have been enabled");
-  is(Services.prefs.prefIsLocked("signon.rememberSignons"), true, "Logins & Passwords pref has been locked");
-});