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>
Tue, 28 Feb 2017 17:31:27 +0100
changeset 490485 4cb54d3de92182b6563f97f6395630c04a845195
parent 490484 3969daeb4135351653ef284c609e160890e0f915
child 490486 2273e8a41ef942a877abe5cfddd27754efc2cd42
push id47114
push usermdeboer@mozilla.com
push dateTue, 28 Feb 2017 16:35:40 +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: K9nZiUzElxv
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_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,52 @@ 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_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,34 +19,18 @@ 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();
 
   let uri = do_get_addon_root_uri(profileDir, ID);
 
   let addon = yield promiseAddonByID(ID);
   do_check_neq(addon, null);
@@ -81,37 +65,20 @@ add_task(function*() {
   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();
 
   let addon = yield promiseAddonByID(ID);
   do_check_neq(addon, null);
 
   let uri = do_get_addon_root_uri(profileDir, ID);
@@ -127,30 +94,20 @@ 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();
 
   let addon = yield promiseAddonByID(ID);
   do_check_neq(addon, null);
 
   deepEqual(addon.icons, {});
@@ -158,9 +115,114 @@ add_task(function*() {
   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" } }
+  });
+});