Bug 1347207 - Add and fix tests for theme loading warnings. r=mixedpuppy
authorTim Nguyen <ntim.bugs@gmail.com>
Thu, 09 Aug 2018 19:00:39 +0100
changeset 485951 56a97a3eee824d1b5174d4ca075c080e8fbbc054
parent 485950 98010ec675282db53e3e48491c5efeb1496bfc4c
child 485952 b72122eacaeeda7a39dd1cefca3096f46903b184
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1347207
milestone63.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 1347207 - Add and fix tests for theme loading warnings. r=mixedpuppy MozReview-Commit-ID: 6C3H7wPK2v6
toolkit/components/extensions/test/browser/browser.ini
toolkit/components/extensions/test/browser/browser_ext_themes_warnings.js
toolkit/components/extensions/test/xpcshell/test_ext_manifest_themes.js
--- a/toolkit/components/extensions/test/browser/browser.ini
+++ b/toolkit/components/extensions/test/browser/browser.ini
@@ -28,8 +28,9 @@ skip-if = verify
 [browser_ext_themes_toolbarbutton_icons.js]
 [browser_ext_themes_toolbarbutton_colors.js]
 [browser_ext_themes_theme_transition.js]
 [browser_ext_themes_arrowpanels.js]
 [browser_ext_themes_tab_selected.js]
 [browser_ext_themes_autocomplete_popup.js]
 [browser_ext_themes_sanitization.js]
 [browser_ext_themes_findbar.js]
+[browser_ext_themes_warnings.js]
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/browser/browser_ext_themes_warnings.js
@@ -0,0 +1,131 @@
+"use strict";
+
+// This test checks that theme warnings are properly emitted.
+
+function waitForConsole(task, message) {
+  return new Promise(async resolve => {
+    SimpleTest.monitorConsole(resolve, [{
+      message: new RegExp(message),
+    }]);
+    await task();
+    SimpleTest.endMonitorConsole();
+  });
+}
+
+add_task(async function setup() {
+  SimpleTest.waitForExplicitFinish();
+});
+
+add_task(async function test_static_theme() {
+  for (const property of ["colors", "images", "properties"]) {
+    const extension = ExtensionTestUtils.loadExtension({
+      manifest: {
+        theme: {
+          [property]: {
+            such_property: "much_wow",
+          },
+        },
+      },
+    });
+    await waitForConsole(
+      extension.startup,
+      `Unrecognized theme property found: ${property}.such_property`,
+    );
+    await extension.unload();
+  }
+});
+
+add_task(async function test_dynamic_theme() {
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      permissions: ["theme"],
+    },
+    background() {
+      browser.test.onMessage.addListener((msg, details) => {
+        if (msg === "update-theme") {
+          browser.theme.update(details).then(() => {
+            browser.test.sendMessage("theme-updated");
+          });
+        } else {
+          browser.theme.reset().then(() => {
+            browser.test.sendMessage("theme-reset");
+          });
+        }
+      });
+    },
+  });
+
+  await extension.startup();
+
+  for (const property of ["colors", "images", "properties"]) {
+    extension.sendMessage("update-theme", {
+      [property]: {
+        such_property: "much_wow",
+      },
+    });
+    await waitForConsole(
+      () => extension.awaitMessage("theme-updated"),
+      `Unrecognized theme property found: ${property}.such_property`
+    );
+  }
+
+  await extension.unload();
+});
+
+add_task(async function test_experiment() {
+  Services.prefs.setBoolPref("extensions.legacy.enabled", true);
+
+  info("Testing that experiments are handled correctly when legacy pref is enabled");
+
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      theme: {
+        properties: {
+          such_property: "much_wow",
+          unknown_property: "very_unknown",
+        },
+      },
+      theme_experiment: {
+        properties: {
+          such_property: "--such-property",
+        },
+      },
+    },
+  });
+  if (!AppConstants.MOZ_ALLOW_LEGACY_EXTENSIONS) {
+    await waitForConsole(
+      extension.startup,
+      "This extension is not allowed to run theme experiments"
+    );
+  } else {
+    await waitForConsole(
+      extension.startup,
+      "Unrecognized theme property found: properties.unknown_property"
+    );
+  }
+  await extension.unload();
+
+  info("Testing that experiments are handled correctly when legacy pref is disabled");
+
+  Services.prefs.setBoolPref("extensions.legacy.enabled", false);
+
+  extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      theme: {
+        properties: {
+          such_property: "much_wow",
+        },
+      },
+      theme_experiment: {
+        properties: {
+          such_property: "--such-property",
+        },
+      },
+    },
+  });
+  await waitForConsole(
+    extension.startup,
+    "This extension is not allowed to run theme experiments"
+  );
+  await extension.unload();
+});
--- a/toolkit/components/extensions/test/xpcshell/test_ext_manifest_themes.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_manifest_themes.js
@@ -1,31 +1,28 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
 async function test_theme_property(property) {
   let normalized = await ExtensionTestUtils.normalizeManifest({
     "theme": {
       [property]: {
-        "unrecognized_key": "unrecognized_value",
       },
     },
   }, "manifest.ThemeManifest");
 
-  let expectedWarning;
   if (property === "unrecognized_key") {
-    expectedWarning = `Error processing theme.${property}`;
+    const expectedWarning = `Error processing theme.${property}`;
+    ok(normalized.errors[0].includes(expectedWarning),
+       `The manifest warning ${JSON.stringify(normalized.errors[0])} must contain ${JSON.stringify(expectedWarning)}`);
   } else {
-    expectedWarning = `Error processing theme.${property}.unrecognized_key`;
+    equal(normalized.errors.length, 0, "Should have a warning");
   }
   equal(normalized.error, undefined, "Should not have an error");
-  equal(normalized.errors.length, 1, "Should have a warning");
-  ok(normalized.errors[0].includes(expectedWarning),
-     `The manifest warning ${JSON.stringify(normalized.errors[0])} must contain ${JSON.stringify(expectedWarning)}`);
 }
 
 add_task(async function test_manifest_themes() {
   await test_theme_property("images");
   await test_theme_property("colors");
   await test_theme_property("icons");
   await test_theme_property("unrecognized_key");
 });