Bug 1324192 - split system addon update tests into expected pass / expected fail to avoid timeouts r?aswan draft
authorRobert Helmer <rhelmer@mozilla.com>
Thu, 02 Mar 2017 11:35:59 -0800
changeset 492074 5db372353d01a187e9b812bf40bc5208a775e4bd
parent 492073 298dc4d4337890468adfaac607a805696c1da5c2
child 547640 5bf4285ecc7f6376cad2702d31f5ca7ca07e178c
push id47519
push userrhelmer@mozilla.com
push dateThu, 02 Mar 2017 19:37:30 +0000
reviewersaswan
bugs1324192
milestone54.0a1
Bug 1324192 - split system addon update tests into expected pass / expected fail to avoid timeouts r?aswan MozReview-Commit-ID: 4zRCUGqFwcx
toolkit/mozapps/extensions/test/xpcshell/test_system_update.js
toolkit/mozapps/extensions/test/xpcshell/test_system_update_fail.js
toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
--- a/toolkit/mozapps/extensions/test/xpcshell/test_system_update.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_system_update.js
@@ -1,10 +1,10 @@
-// Tests that we reset to the default system add-ons correctly when switching
-// application versions
+// Tests that system add-on upgrades work.
+
 const PREF_SYSTEM_ADDON_SET           = "extensions.systemAddonSet";
 const PREF_SYSTEM_ADDON_UPDATE_URL    = "extensions.systemAddon.update.url";
 const PREF_APP_UPDATE_ENABLED         = "app.update.enabled";
 
 Components.utils.import("resource://testing-common/httpd.js");
 
 BootstrapMonitor.init();
 
@@ -251,43 +251,16 @@ const TESTS = {
         { isUpgrade: true, version: "2.0"},
         { isUpgrade: true, version: "3.0"},
         { isUpgrade: true, version: "1.0"},
         { isUpgrade: false, version: null}
       ]
     }
   },
 
-  // Specifying an incorrect version should stop us updating anything
-  badVersion: {
-    fails: true,
-    updateList: [
-      { id: "system2@tests.mozilla.org", version: "4.0", path: "system2_3.xpi" },
-      { id: "system3@tests.mozilla.org", version: "3.0", path: "system3_3.xpi" }
-    ],
-  },
-
-  // Specifying an invalid size should stop us updating anything
-  badSize: {
-    fails: true,
-    updateList: [
-      { id: "system2@tests.mozilla.org", version: "3.0", path: "system2_3.xpi", size: 2 },
-      { id: "system3@tests.mozilla.org", version: "3.0", path: "system3_3.xpi" }
-    ],
-  },
-
-  // Specifying an incorrect hash should stop us updating anything
-  badHash: {
-    fails: true,
-    updateList: [
-      { id: "system2@tests.mozilla.org", version: "3.0", path: "system2_3.xpi" },
-      { id: "system3@tests.mozilla.org", version: "3.0", path: "system3_3.xpi", hashFunction: "sha1", hashValue: "205a4c49bd513ebd30594e380c19e86bba1f83e2" }
-    ],
-  },
-
   // Correct sizes and hashes should work
   checkSizeHash: {
     updateList: [
       { id: "system2@tests.mozilla.org", version: "3.0", path: "system2_3.xpi", size: 4697 },
       { id: "system3@tests.mozilla.org", version: "3.0", path: "system3_3.xpi", hashFunction: "sha1", hashValue: "a4c7198d56deb315511c02937fd96c696de6cb84" },
       { id: "system5@tests.mozilla.org", version: "1.0", path: "system5_1.xpi", size: 4691, hashFunction: "sha1", hashValue: "6887b916a1a9a5338b0df4181f6187f5396861eb" }
     ],
     finalState: {
@@ -315,52 +288,16 @@ const TESTS = {
       withBothSets: [
         { isUpgrade: false, version: "1.0"},
         { isUpgrade: true, version: "3.0"},
         { isUpgrade: true, version: "3.0"},
         { isUpgrade: false, version: null},
         { isUpgrade: true, version: "1.0"}
       ]
     }
-  },
-
-  // A bad certificate should stop updates
-  badCert: {
-    fails: true,
-    updateList: [
-      { id: "system1@tests.mozilla.org", version: "1.0", path: "system1_1_badcert.xpi" },
-      { id: "system3@tests.mozilla.org", version: "1.0", path: "system3_1.xpi" }
-    ],
-  },
-
-  // An unpacked add-on should stop updates.
-  notPacked: {
-    fails: true,
-    updateList: [
-      { id: "system6@tests.mozilla.org", version: "1.0", path: "system6_1_unpack.xpi" },
-      { id: "system3@tests.mozilla.org", version: "1.0", path: "system3_1.xpi" }
-    ],
-  },
-
-  // A non-bootstrap add-on should stop updates.
-  notBootstrap: {
-    fails: true,
-    updateList: [
-      { id: "system6@tests.mozilla.org", version: "1.0", path: "system6_2_notBootstrap.xpi" },
-      { id: "system3@tests.mozilla.org", version: "1.0", path: "system3_1.xpi" }
-    ],
-  },
-
-  // A non-multiprocess add-on should stop updates.
-  notMultiprocess: {
-    fails: true,
-    updateList: [
-      { id: "system6@tests.mozilla.org", version: "1.0", path: "system6_3_notMultiprocess.xpi" },
-      { id: "system3@tests.mozilla.org", version: "1.0", path: "system3_1.xpi" }
-    ],
   }
 }
 
 add_task(function* setup() {
   // Initialise the profile
   startupManager();
   yield promiseShutdownManager();
 });
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_system_update_fail.js
@@ -0,0 +1,184 @@
+// Tests that system add-on upgrades fail to upgrade in expected cases.
+
+const PREF_SYSTEM_ADDON_SET           = "extensions.systemAddonSet";
+const PREF_SYSTEM_ADDON_UPDATE_URL    = "extensions.systemAddon.update.url";
+const PREF_APP_UPDATE_ENABLED         = "app.update.enabled";
+
+Components.utils.import("resource://testing-common/httpd.js");
+
+BootstrapMonitor.init();
+
+createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2");
+
+var testserver = new HttpServer();
+testserver.registerDirectory("/data/", do_get_file("data/system_addons"));
+testserver.start();
+var root = testserver.identity.primaryScheme + "://" +
+           testserver.identity.primaryHost + ":" +
+           testserver.identity.primaryPort + "/data/"
+Services.prefs.setCharPref(PREF_SYSTEM_ADDON_UPDATE_URL, root + "update.xml");
+
+/**
+ * Defines the set of initial conditions to run each test against. Each should
+ * define the following properties:
+ *
+ * setup:        A task to setup the profile into the initial state.
+ * initialState: The initial expected system add-on state after setup has run.
+ */
+const TEST_CONDITIONS = {
+  // Runs tests with no updated or default system add-ons initially installed
+  blank: {
+    *setup() {
+      clearSystemAddonUpdatesDir();
+      distroDir.leafName = "empty";
+    },
+    initialState: [
+      { isUpgrade: false, version: null},
+      { isUpgrade: false, version: null},
+      { isUpgrade: false, version: null},
+      { isUpgrade: false, version: null},
+      { isUpgrade: false, version: null}
+    ],
+  },
+  // Runs tests with default system add-ons installed
+  withAppSet: {
+    *setup() {
+      clearSystemAddonUpdatesDir();
+      distroDir.leafName = "prefilled";
+    },
+    initialState: [
+      { isUpgrade: false, version: null},
+      { isUpgrade: false, version: "2.0"},
+      { isUpgrade: false, version: "2.0"},
+      { isUpgrade: false, version: null},
+      { isUpgrade: false, version: null}
+    ]
+  },
+
+  // Runs tests with updated system add-ons installed
+  withProfileSet: {
+    *setup() {
+      buildPrefilledUpdatesDir();
+      distroDir.leafName = "empty";
+    },
+    initialState: [
+      { isUpgrade: false, version: null},
+      { isUpgrade: true, version: "2.0"},
+      { isUpgrade: true, version: "2.0"},
+      { isUpgrade: false, version: null},
+      { isUpgrade: false, version: null}
+    ]
+  },
+
+  // Runs tests with both default and updated system add-ons installed
+  withBothSets: {
+    *setup() {
+      buildPrefilledUpdatesDir();
+      distroDir.leafName = "hidden";
+    },
+    initialState: [
+      { isUpgrade: false, version: "1.0"},
+      { isUpgrade: true, version: "2.0"},
+      { isUpgrade: true, version: "2.0"},
+      { isUpgrade: false, version: null},
+      { isUpgrade: false, version: null}
+    ]
+  },
+};
+
+
+/**
+ * The tests to run. Each test must define an updateList or test. The following
+ * properties are used:
+ *
+ * updateList: The set of add-ons the server should respond with.
+ * test:       A function to run to perform the update check (replaces
+ *             updateList)
+ * fails:      An optional property, if true the update check is expected to
+ *             fail.
+ * finalState: An optional property, the expected final state of system add-ons,
+ *             if missing the test condition's initialState is used.
+ */
+const TESTS = {
+  // Specifying an incorrect version should stop us updating anything
+  badVersion: {
+    fails: true,
+    updateList: [
+      { id: "system2@tests.mozilla.org", version: "4.0", path: "system2_3.xpi" },
+      { id: "system3@tests.mozilla.org", version: "3.0", path: "system3_3.xpi" }
+    ],
+  },
+
+  // Specifying an invalid size should stop us updating anything
+  badSize: {
+    fails: true,
+    updateList: [
+      { id: "system2@tests.mozilla.org", version: "3.0", path: "system2_3.xpi", size: 2 },
+      { id: "system3@tests.mozilla.org", version: "3.0", path: "system3_3.xpi" }
+    ],
+  },
+
+  // Specifying an incorrect hash should stop us updating anything
+  badHash: {
+    fails: true,
+    updateList: [
+      { id: "system2@tests.mozilla.org", version: "3.0", path: "system2_3.xpi" },
+      { id: "system3@tests.mozilla.org", version: "3.0", path: "system3_3.xpi", hashFunction: "sha1", hashValue: "205a4c49bd513ebd30594e380c19e86bba1f83e2" }
+    ],
+  },
+
+  // A bad certificate should stop updates
+  badCert: {
+    fails: true,
+    updateList: [
+      { id: "system1@tests.mozilla.org", version: "1.0", path: "system1_1_badcert.xpi" },
+      { id: "system3@tests.mozilla.org", version: "1.0", path: "system3_1.xpi" }
+    ],
+  },
+
+  // An unpacked add-on should stop updates.
+  notPacked: {
+    fails: true,
+    updateList: [
+      { id: "system6@tests.mozilla.org", version: "1.0", path: "system6_1_unpack.xpi" },
+      { id: "system3@tests.mozilla.org", version: "1.0", path: "system3_1.xpi" }
+    ],
+  },
+
+  // A non-bootstrap add-on should stop updates.
+  notBootstrap: {
+    fails: true,
+    updateList: [
+      { id: "system6@tests.mozilla.org", version: "1.0", path: "system6_2_notBootstrap.xpi" },
+      { id: "system3@tests.mozilla.org", version: "1.0", path: "system3_1.xpi" }
+    ],
+  },
+
+  // A non-multiprocess add-on should stop updates.
+  notMultiprocess: {
+    fails: true,
+    updateList: [
+      { id: "system6@tests.mozilla.org", version: "1.0", path: "system6_3_notMultiprocess.xpi" },
+      { id: "system3@tests.mozilla.org", version: "1.0", path: "system3_1.xpi" }
+    ],
+  }
+}
+
+add_task(function* setup() {
+  // Initialise the profile
+  startupManager();
+  yield promiseShutdownManager();
+});
+
+add_task(function*() {
+  for (let setupName of Object.keys(TEST_CONDITIONS)) {
+    for (let testName of Object.keys(TESTS)) {
+        do_print("Running test " + setupName + " " + testName);
+
+        let setup = TEST_CONDITIONS[setupName];
+        let test = TESTS[testName];
+
+        yield execSystemAddonTest(setupName, setup, test);
+    }
+  }
+});
--- a/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
+++ b/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
@@ -23,16 +23,17 @@ skip-if = appname != "firefox"
 [test_pluginInfoURL.js]
 [test_provider_markSafe.js]
 [test_provider_shutdown.js]
 [test_provider_unsafe_access_shutdown.js]
 [test_provider_unsafe_access_startup.js]
 [test_ProductAddonChecker.js]
 [test_shutdown.js]
 [test_system_update.js]
+[test_system_update_fail.js]
 [test_system_reset.js]
 [test_XPIcancel.js]
 [test_XPIStates.js]
 [test_temporary.js]
 tags = webextensions
 [test_install_from_sources.js]
 [test_proxies.js]
 [test_proxy.js]