Bug 1330349 - Part 4 - make sure theme type WebExtension support is covered by the existing test suite. r?Mossop draft
authorMike de Boer <mdeboer@mozilla.com>
Thu, 02 Mar 2017 14:22:23 +0100
changeset 491926 87370044cee487a820e097fc9fc82b2b97522cb0
parent 491925 9d7554d6ea4faadfb42ae2dc140613d253a9bbc6
child 491927 bcdff925907b31c94d6b35036393cdd972b5a256
push id47458
push usermdeboer@mozilla.com
push dateThu, 02 Mar 2017 13:47:01 +0000
reviewersMossop
bugs1330349
milestone54.0a1
Bug 1330349 - Part 4 - make sure theme type WebExtension support is covered by the existing test suite. r?Mossop MozReview-Commit-ID: 4oN89cCY4k
toolkit/mozapps/extensions/test/xpcshell/test_dss.js
toolkit/mozapps/extensions/test/xpcshell/test_temporary.js
toolkit/mozapps/extensions/test/xpcshell/test_webextension.js
toolkit/mozapps/extensions/test/xpcshell/test_webextension_icons.js
--- a/toolkit/mozapps/extensions/test/xpcshell/test_dss.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_dss.js
@@ -379,32 +379,30 @@ function run_test_5() {
 
     ensure_test_completed();
 
     prepare_test({
       "2@personas.mozilla.org": [
         "onEnabling"
       ],
       "theme2@tests.mozilla.org": [
-        ["onDisabling", false],
-        "onDisabled"
+        "onDisabling"
       ]
     });
 
     p2.userDisabled = false;
 
     ensure_test_completed();
 
     prepare_test({
       "2@personas.mozilla.org": [
-        ["onOperationCancelled", true]
+        "onOperationCancelled"
       ],
       "theme2@tests.mozilla.org": [
-        ["onEnabling", false],
-        "onEnabled"
+        "onOperationCancelled"
       ]
     });
 
     t2.userDisabled = false;
 
     ensure_test_completed();
 
     do_check_true(t2.isActive);
@@ -441,61 +439,58 @@ function check_test_5() {
 
 // Switching from a custom theme to a lightweight theme should require a restart
 function run_test_6() {
   prepare_test({
     "2@personas.mozilla.org": [
       "onEnabling",
     ],
     "theme2@tests.mozilla.org": [
-      ["onDisabling", false],
-      "onDisabled"
+      "onDisabling"
     ]
   });
 
   AddonManager.getAddonsByIDs(["2@personas.mozilla.org",
                                "theme2@tests.mozilla.org"], function([p2, t2]) {
     p2.userDisabled = false;
 
     ensure_test_completed();
 
     prepare_test({
       "2@personas.mozilla.org": [
         "onOperationCancelled",
       ],
       "theme2@tests.mozilla.org": [
-        ["onEnabling", false],
-        "onEnabled"
+        "onOperationCancelled"
       ]
     });
 
     t2.userDisabled = false;
 
     ensure_test_completed();
 
     prepare_test({
       "2@personas.mozilla.org": [
         "onEnabling",
       ],
       "theme2@tests.mozilla.org": [
-        ["onDisabling", false],
-        "onDisabled"
+        "onDisabling"
       ]
     });
 
     p2.userDisabled = false;
 
     ensure_test_completed();
 
     do_check_false(p2.isActive);
     do_check_false(p2.userDisabled);
     do_check_true(hasFlag(AddonManager.PENDING_ENABLE, p2.pendingOperations));
-    do_check_false(t2.isActive);
+    do_check_true(t2.isActive);
     do_check_true(t2.userDisabled);
-    do_check_false(hasFlag(AddonManager.PENDING_DISABLE, t2.pendingOperations));
+    do_check_true(hasFlag(AddonManager.PENDING_DISABLE, t2.pendingOperations));
     do_check_false(gLWThemeChanged);
 
     do_execute_soon(check_test_6);
   });
 }
 
 function check_test_6() {
   restartManager();
--- a/toolkit/mozapps/extensions/test/xpcshell/test_temporary.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_temporary.js
@@ -302,18 +302,50 @@ add_task(function*() {
     // temporary add-on is installed and started
     do_check_neq(addon, null);
     do_check_eq(addon.version, "5.0");
     do_check_eq(addon.name, "Test WebExtension 1 (temporary)");
     do_check_true(addon.isCompatible);
     do_check_false(addon.appDisabled);
     do_check_true(addon.isActive);
     do_check_eq(addon.type, "extension");
+    do_check_true(addon.isWebExtension);
     do_check_eq(addon.signedState, mozinfo.addon_signing ? AddonManager.SIGNEDSTATE_SIGNED : AddonManager.SIGNEDSTATE_NOT_REQUIRED);
 
+    // test reloading a webextension with the same name, but a different type.
+    webext.remove(false);
+    webext = createTempWebExtensionFile({
+      manifest: {
+        version: "6.0",
+        name: "Test WebExtension 1 (temporary)",
+        applications: {
+          gecko: {
+            id: ID
+          }
+        },
+        theme: { images: { headerURL: "https://example.com/example.png" } }
+      }
+    });
+
+    yield Promise.all([
+      AddonManager.installTemporaryAddon(webext),
+      promiseAddonStartup(),
+    ]);
+    addon = yield promiseAddonByID(ID);
+
+    do_check_neq(addon, null);
+    do_check_eq(addon.version, "6.0");
+    do_check_eq(addon.name, "Test WebExtension 1 (temporary)");
+    do_check_true(addon.isCompatible);
+    do_check_false(addon.appDisabled);
+    do_check_true(addon.isActive);
+    // This is what we're really interested in:
+    do_check_eq(addon.type, "theme");
+    do_check_true(addon.isWebExtension);
+
     restartManager();
 
     BootstrapMonitor.checkAddonInstalled(ID, "1.0");
     BootstrapMonitor.checkAddonStarted(ID, "1.0");
 
     addon = yield promiseAddonByID(ID);
 
     // existing add-on is back
--- a/toolkit/mozapps/extensions/test/xpcshell/test_webextension.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_webextension.js
@@ -25,18 +25,21 @@ function promiseAddonStartup() {
 
     Management.on("ready", listener);
   });
 }
 
 function promiseInstallWebExtension(aData) {
   let addonFile = createTempWebExtensionFile(aData);
 
-  return promiseInstallAllFiles([addonFile]).then(() => {
+  return promiseInstallAllFiles([addonFile]).then(installs => {
     Services.obs.notifyObservers(addonFile, "flush-cache-entry", null);
+    // Since themes are disabled by default, it won't start up.
+    if ("theme" in aData.manifest)
+      return installs[0].addon;
     return promiseAddonStartup();
   });
 }
 
 add_task(function*() {
   equal(GlobalManager.extensionMap.size, 0);
 
   yield Promise.all([
@@ -413,8 +416,53 @@ add_task(function* authorNotString() {
       }
     });
 
     addon = yield promiseAddonByID(addon.id);
     equal(addon.creator, null);
     addon.uninstall();
   }
 });
+
+add_task(function* testThemeExtension() {
+  let addon = yield promiseInstallWebExtension({
+    manifest: {
+      "author": "Some author",
+      manifest_version: 2,
+      name: "Web Extension Name",
+      version: "1.0",
+      theme: { images: { headerURL: "https://example.com/example.png" } },
+    }
+  });
+
+  addon = yield promiseAddonByID(addon.id);
+  do_check_neq(addon, null);
+  do_check_eq(addon.creator, "Some author");
+  do_check_eq(addon.version, "1.0");
+  do_check_eq(addon.name, "Web Extension Name");
+  do_check_true(addon.isCompatible);
+  do_check_false(addon.appDisabled);
+  do_check_false(addon.isActive);
+  do_check_true(addon.userDisabled);
+  do_check_false(addon.isSystem);
+  do_check_eq(addon.type, "theme");
+  do_check_true(addon.isWebExtension);
+  do_check_eq(addon.signedState, mozinfo.addon_signing ? AddonManager.SIGNEDSTATE_SIGNED : AddonManager.SIGNEDSTATE_NOT_REQUIRED);
+
+  addon.uninstall();
+
+  // Also test one without a proper 'theme' section.
+  addon = yield promiseInstallWebExtension({
+    manifest: {
+      "author": "Some author",
+      manifest_version: 2,
+      name: "Web Extension Name",
+      version: "1.0",
+      theme: null,
+    }
+  });
+
+  addon = yield promiseAddonByID(addon.id);
+  do_check_eq(addon.type, "extension");
+  do_check_true(addon.isWebExtension);
+
+  addon.uninstall();
+});
--- a/toolkit/mozapps/extensions/test/xpcshell/test_webextension_icons.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_webextension_icons.js
@@ -19,37 +19,22 @@ function promiseAddonStartup() {
       Management.off("startup", listener);
       resolve(extension);
     };
 
     Management.on("startup", listener);
   });
 }
 
-// Test simple icon set parsing
-add_task(function*() {
-  yield promiseWriteWebManifestForExtension({
-    name: "Web Extension Name",
-    version: "1.0",
-    manifest_version: 2,
-    applications: {
-      gecko: {
-        id: ID
-      }
-    },
-    icons: {
-      16: "icon16.png",
-      32: "icon32.png",
-      48: "icon48.png",
-      64: "icon64.png"
-    }
-  }, profileDir);
+function* testSimpleIconsetParsing(manifest) {
+  yield promiseWriteWebManifestForExtension(manifest, profileDir);
 
   yield promiseRestartManager();
-  yield promiseAddonStartup();
+  if (!manifest.theme)
+    yield promiseAddonStartup();
 
   let uri = do_get_addon_root_uri(profileDir, ID);
 
   let addon = yield promiseAddonByID(ID);
   do_check_neq(addon, null);
 
   function check_icons(addon_copy) {
     deepEqual(addon_copy.icons, {
@@ -71,50 +56,35 @@ add_task(function*() {
     equal(AddonManager.getPreferredIconURL(addon, 64), uri + "icon64.png");
     equal(AddonManager.getPreferredIconURL(addon, 128), uri + "icon64.png");
   }
 
   check_icons(addon);
 
   // check if icons are persisted through a restart
   yield promiseRestartManager();
-  yield promiseAddonStartup();
+  if (!manifest.theme)
+    yield promiseAddonStartup();
 
   addon = yield promiseAddonByID(ID);
   do_check_neq(addon, null);
 
   check_icons(addon);
 
   addon.uninstall();
 
   yield promiseRestartManager();
-});
+}
 
-// Test AddonManager.getPreferredIconURL for retina screen sizes
-add_task(function*() {
-  yield promiseWriteWebManifestForExtension({
-    name: "Web Extension Name",
-    version: "1.0",
-    manifest_version: 2,
-    applications: {
-      gecko: {
-        id: ID
-      }
-    },
-    icons: {
-      32: "icon32.png",
-      48: "icon48.png",
-      64: "icon64.png",
-      128: "icon128.png",
-      256: "icon256.png"
-    }
-  }, profileDir);
+function* testRetinaIconsetParsing(manifest) {
+  yield promiseWriteWebManifestForExtension(manifest, profileDir);
 
   yield promiseRestartManager();
-  yield promiseAddonStartup();
+  if (!manifest.theme)
+    yield promiseAddonStartup();
 
   let addon = yield promiseAddonByID(ID);
   do_check_neq(addon, null);
 
   let uri = do_get_addon_root_uri(profileDir, ID);
 
   // AddonManager displays larger icons for higher pixel density
   equal(AddonManager.getPreferredIconURL(addon, 32, {
@@ -127,40 +97,136 @@ add_task(function*() {
 
   equal(AddonManager.getPreferredIconURL(addon, 64, {
     devicePixelRatio: 2
   }), uri + "icon128.png");
 
   addon.uninstall();
 
   yield promiseRestartManager();
-});
+}
 
-// Handles no icons gracefully
-add_task(function*() {
-  yield promiseWriteWebManifestForExtension({
-    name: "Web Extension Name",
-    version: "1.0",
-    manifest_version: 2,
-    applications: {
-      gecko: {
-        id: ID
-      }
-    }
-  }, profileDir);
+function* testNoIconsParsing(manifest) {
+  yield promiseWriteWebManifestForExtension(manifest, profileDir);
 
   yield promiseRestartManager();
-  yield promiseAddonStartup();
+  if (!manifest.theme)
+    yield promiseAddonStartup();
 
   let addon = yield promiseAddonByID(ID);
   do_check_neq(addon, null);
 
   deepEqual(addon.icons, {});
 
   equal(addon.iconURL, null);
   equal(addon.icon64URL, null);
 
   equal(AddonManager.getPreferredIconURL(addon, 128), null);
 
   addon.uninstall();
 
   yield promiseRestartManager();
+}
+
+// Test simple icon set parsing
+add_task(function*() {
+  yield* testSimpleIconsetParsing({
+    name: "Web Extension Name",
+    version: "1.0",
+    manifest_version: 2,
+    applications: {
+      gecko: {
+        id: ID
+      }
+    },
+    icons: {
+      16: "icon16.png",
+      32: "icon32.png",
+      48: "icon48.png",
+      64: "icon64.png"
+    }
+  });
+
+  // Now for theme-type extensions too.
+  yield* testSimpleIconsetParsing({
+    name: "Web Extension Name",
+    version: "1.0",
+    manifest_version: 2,
+    applications: {
+      gecko: {
+        id: ID
+      }
+    },
+    icons: {
+      16: "icon16.png",
+      32: "icon32.png",
+      48: "icon48.png",
+      64: "icon64.png"
+    },
+    theme: { images: { headerURL: "https://example.com/example.png" } }
+  });
 });
+
+// Test AddonManager.getPreferredIconURL for retina screen sizes
+add_task(function*() {
+  yield* testRetinaIconsetParsing({
+    name: "Web Extension Name",
+    version: "1.0",
+    manifest_version: 2,
+    applications: {
+      gecko: {
+        id: ID
+      }
+    },
+    icons: {
+      32: "icon32.png",
+      48: "icon48.png",
+      64: "icon64.png",
+      128: "icon128.png",
+      256: "icon256.png"
+    }
+  });
+
+  yield* testRetinaIconsetParsing({
+    name: "Web Extension Name",
+    version: "1.0",
+    manifest_version: 2,
+    applications: {
+      gecko: {
+        id: ID
+      }
+    },
+    icons: {
+      32: "icon32.png",
+      48: "icon48.png",
+      64: "icon64.png",
+      128: "icon128.png",
+      256: "icon256.png"
+    },
+    theme: { images: { headerURL: "https://example.com/example.png" } }
+  });
+});
+
+// Handles no icons gracefully
+add_task(function*() {
+  yield* testNoIconsParsing({
+    name: "Web Extension Name",
+    version: "1.0",
+    manifest_version: 2,
+    applications: {
+      gecko: {
+        id: ID
+      }
+    }
+  });
+
+  yield* testNoIconsParsing({
+    name: "Web Extension Name",
+    version: "1.0",
+    manifest_version: 2,
+    applications: {
+      gecko: {
+        id: ID
+      }
+    },
+    theme: { images: { headerURL: "https://example.com/example.png" } }
+  });
+});