Bug 1330369 - Part 3 - Add unit tests for sidebar.browser_style r=mixedpuppy
authorMatthew Wein <mwein@mozilla.com>
Tue, 16 May 2017 22:48:38 -0400
changeset 409113 8092c26b85d4273e0797638df567601e250808e0
parent 409112 a766850786e747f8e1495992b07c8212c1ab3306
child 409114 261836433b949898383936ffbf1876834fa25649
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1330369
milestone55.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 1330369 - Part 3 - Add unit tests for sidebar.browser_style r=mixedpuppy MozReview-Commit-ID: 9ILOY3s5pci
browser/components/extensions/test/browser/browser-common.ini
browser/components/extensions/test/browser/browser_ext_sidebarAction_browser_style.js
--- a/browser/components/extensions/test/browser/browser-common.ini
+++ b/browser/components/extensions/test/browser/browser-common.ini
@@ -90,16 +90,17 @@ skip-if = debug || asan # Bug 1354681
 [browser_ext_runtime_setUninstallURL.js]
 [browser_ext_sessions_forgetClosedTab.js]
 [browser_ext_sessions_forgetClosedWindow.js]
 [browser_ext_sessions_getRecentlyClosed.js]
 [browser_ext_sessions_getRecentlyClosed_private.js]
 [browser_ext_sessions_getRecentlyClosed_tabs.js]
 [browser_ext_sessions_restore.js]
 [browser_ext_sidebarAction.js]
+[browser_ext_sidebarAction_browser_style.js]
 [browser_ext_sidebarAction_context.js]
 [browser_ext_sidebarAction_contextMenu.js]
 [browser_ext_sidebarAction_tabs.js]
 [browser_ext_sidebarAction_windows.js]
 [browser_ext_simple.js]
 [browser_ext_tab_runtimeConnect.js]
 [browser_ext_tabs_audio.js]
 [browser_ext_tabs_captureVisibleTab.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/extensions/test/browser/browser_ext_sidebarAction_browser_style.js
@@ -0,0 +1,74 @@
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
+"use strict";
+
+function* testSidebarBrowserStyle(sidebarAction, assertMessage) {
+  function sidebarScript() {
+    browser.test.onMessage.addListener((msgName, info, assertMessage) => {
+      if (msgName !== "check-style") {
+        browser.test.notifyFail("options-ui-browser_style");
+      }
+
+      let style = window.getComputedStyle(document.getElementById("button"));
+      let buttonBackgroundColor = style.backgroundColor;
+      let browserStyleBackgroundColor = "rgb(9, 150, 248)";
+      if (!("browser_style" in info) || info.browser_style) {
+        browser.test.assertEq(browserStyleBackgroundColor, buttonBackgroundColor, assertMessage);
+      } else {
+        browser.test.assertTrue(browserStyleBackgroundColor !== buttonBackgroundColor, assertMessage);
+      }
+
+      browser.test.notifyPass("sidebar-browser-style");
+    });
+    browser.test.sendMessage("sidebar-ready");
+  }
+
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      "sidebar_action": sidebarAction,
+    },
+    useAddonManager: "temporary",
+
+    files: {
+      "panel.html": `
+        <!DOCTYPE html>
+        <html>
+          <button id="button" name="button" class="default">Default</button>
+          <script src="panel.js" type="text/javascript"></script>
+        </html>`,
+      "panel.js": sidebarScript,
+    },
+  });
+
+  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser);
+
+  yield extension.startup();
+  yield extension.awaitMessage("sidebar-ready");
+
+  extension.sendMessage("check-style", sidebarAction, assertMessage);
+  yield extension.awaitFinish("sidebar-browser-style");
+
+  yield extension.unload();
+
+  yield BrowserTestUtils.removeTab(tab);
+}
+
+add_task(function* test_sidebar_without_setting_browser_style() {
+  yield testSidebarBrowserStyle({
+    "default_panel": "panel.html",
+  }, "Expected correct style when browser_style is excluded");
+});
+
+add_task(function* test_sidebar_with_browser_style_set_to_true() {
+  yield testSidebarBrowserStyle({
+    "default_panel": "panel.html",
+    "browser_style": true,
+  }, "Expected correct style when browser_style is set to `true`");
+});
+
+add_task(function* test_sidebar_with_browser_style_set_to_false() {
+  yield testSidebarBrowserStyle({
+    "default_panel": "panel.html",
+    "browser_style": false,
+  }, "Expected no style when browser_style is set to `false`");
+});