summaryrefslogtreecommitdiffstats
path: root/browser/components/firefoxview/tests/browser/browser_feature_callout_theme.js
blob: f56414145e1872b1ed399a70eddab4dbc825fad7 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const { FeatureCallout } = ChromeUtils.importESModule(
  "resource:///modules/FeatureCallout.sys.mjs"
);

async function testCallout(config) {
  const featureCallout = new FeatureCallout(config);
  const testMessage = getCalloutMessageById(
    "FIREFOX_VIEW_FEATURE_TOUR_2_NO_CWS"
  );
  const screen = testMessage.message.content.screens.find(s => s.id);
  screen.parent_selector = "body";
  const sandbox = createSandboxWithCalloutTriggerStub(testMessage, config.page);
  featureCallout.showFeatureCallout();
  await waitForCalloutScreen(config.win.document, screen.id);
  testStyles(config.win);
  return { featureCallout, sandbox };
}

function testStyles(win) {
  const calloutEl = win.document.querySelector(calloutSelector);
  const calloutStyle = win.getComputedStyle(calloutEl);
  for (const type of ["light", "dark", "hcm"]) {
    for (const name of FeatureCallout.themePropNames) {
      ok(
        calloutStyle.getPropertyValue(`--fc-${name}-${type}`),
        `Theme property --fc-${name}-${type} is set`
      );
    }
  }
}

add_task(async function feature_callout_chrome_theme() {
  const win = await BrowserTestUtils.openNewBrowserWindow();
  const { sandbox } = await testCallout({
    win,
    browser: win.gBrowser.selectedBrowser,
    prefName: "fakepref",
    page: "chrome",
    theme: { preset: "chrome" },
  });
  await BrowserTestUtils.closeWindow(win);
  sandbox.restore();
});

add_task(async function feature_callout_pdfjs_theme() {
  const win = await BrowserTestUtils.openNewBrowserWindow();
  const { sandbox } = await testCallout({
    win,
    browser: win.gBrowser.selectedBrowser,
    prefName: "fakepref",
    page: "chrome",
    theme: { preset: "pdfjs", simulateContent: true },
  });
  await BrowserTestUtils.closeWindow(win);
  sandbox.restore();
});

add_task(async function feature_callout_content_theme() {
  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: "about:firefoxview",
    },
    async browser => {
      const { sandbox } = await testCallout({
        win: browser.contentWindow,
        prefName: "fakepref",
        page: "about:firefoxview",
        theme: { preset: "themed-content" },
      });
      sandbox.restore();
    }
  );
});