summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/contentTheme/browser_contentTheme_in_process_tab.js
blob: c53e178bc519b59cf5abf4e349bff6ab8d11ea96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Tests that tabs running in the parent process can hear about updates
 * to lightweight themes via contentTheme.js.
 *
 * The test loads the History Sidebar document in a tab to avoid having
 * to create a special parent-process page for the LightweightTheme
 * JSWindow actors.
 */
add_task(async function test_in_process_tab() {
  let win = await BrowserTestUtils.openNewBrowserWindow();
  const IN_PROCESS_URI = "chrome://browser/content/places/historySidebar.xhtml";
  const SIDEBAR_BGCOLOR = "rgb(255, 0, 0)";
  // contentTheme.js will always convert the sidebar text color to rgba, so
  // we need to compare against that.
  const SIDEBAR_TEXT_COLOR = "rgba(0, 255, 0, 1)";

  await BrowserTestUtils.withNewTab(
    {
      gBrowser: win.gBrowser,
      url: IN_PROCESS_URI,
    },
    async browser => {
      await SpecialPowers.spawn(
        browser,
        [SIDEBAR_BGCOLOR, SIDEBAR_TEXT_COLOR],
        async (bgColor, textColor) => {
          let style = content.document.documentElement.style;
          Assert.notEqual(
            style.getPropertyValue("--lwt-sidebar-background-color"),
            bgColor
          );
          Assert.notEqual(
            style.getPropertyValue("--lwt-sidebar-text-color"),
            textColor
          );
        }
      );

      // Now cobble together a very simple theme that sets the sidebar background
      // and text color.
      let lwtData = {
        theme: {
          sidebar: SIDEBAR_BGCOLOR,
          sidebar_text: SIDEBAR_TEXT_COLOR,
        },
        darkTheme: null,
        window: win.docShell.outerWindowID,
      };

      Services.obs.notifyObservers(lwtData, "lightweight-theme-styling-update");

      await SpecialPowers.spawn(
        browser,
        [SIDEBAR_BGCOLOR, SIDEBAR_TEXT_COLOR],
        async (bgColor, textColor) => {
          let style = content.document.documentElement.style;
          Assert.equal(
            style.getPropertyValue("--lwt-sidebar-background-color"),
            bgColor,
            "The sidebar background text color should have been set by " +
              "contentTheme.js"
          );
          Assert.equal(
            style.getPropertyValue("--lwt-sidebar-text-color"),
            textColor,
            "The sidebar background text color should have been set by " +
              "contentTheme.js"
          );
        }
      );
    }
  );

  await BrowserTestUtils.closeWindow(win);
});