summaryrefslogtreecommitdiffstats
path: root/browser/components/newtab/test/browser/browser_asrouter_toolbarbadge.js
blob: f0089a2364dc80d2213bdbf6d8b60d692533fd5a (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const { OnboardingMessageProvider } = ChromeUtils.import(
  "resource://activity-stream/lib/OnboardingMessageProvider.jsm"
);
const { ToolbarBadgeHub } = ChromeUtils.import(
  "resource://activity-stream/lib/ToolbarBadgeHub.jsm"
);

add_task(async function test_setup() {
  // Cleanup pref value because we click the fxa accounts button.
  // This is not required during tests because we "force show" the message
  // by sending it directly to the Hub bypassing targeting.
  registerCleanupFunction(() => {
    // Clicking on the Firefox Accounts button while in the signed out
    // state opens a new tab for signing in.
    // We'll clean those up here for now.
    gBrowser.removeAllTabsBut(gBrowser.tabs[0]);
    // Stop the load in the last tab that remains.
    gBrowser.stop();
    Services.prefs.clearUserPref("identity.fxaccounts.toolbar.accessed");
  });
});

add_task(async function test_fxa_badge_shown_nodelay() {
  const [msg] = (await OnboardingMessageProvider.getMessages()).filter(
    ({ id }) => id === "FXA_ACCOUNTS_BADGE"
  );

  Assert.ok(msg, "FxA test message exists");

  // Ensure we badge immediately
  msg.content.delay = undefined;

  let browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
  // Click the button and clear the badge that occurs normally at startup
  let fxaButton = browserWindow.document.getElementById(msg.content.target);
  fxaButton.click();

  await BrowserTestUtils.waitForCondition(
    () =>
      !browserWindow.document
        .getElementById(msg.content.target)
        .querySelector(".toolbarbutton-badge")
        .classList.contains("feature-callout"),
    "Initially element is not badged"
  );

  ToolbarBadgeHub.registerBadgeNotificationListener(msg);

  await BrowserTestUtils.waitForCondition(
    () =>
      browserWindow.document
        .getElementById(msg.content.target)
        .querySelector(".toolbarbutton-badge")
        .classList.contains("feature-callout"),
    "Wait for element to be badged"
  );

  let newWin = await BrowserTestUtils.openNewBrowserWindow();
  browserWindow = Services.wm.getMostRecentWindow("navigator:browser");

  await BrowserTestUtils.waitForCondition(
    () =>
      browserWindow.document
        .getElementById(msg.content.target)
        .querySelector(".toolbarbutton-badge")
        .classList.contains("feature-callout"),
    "Wait for element to be badged"
  );

  await BrowserTestUtils.closeWindow(newWin);
  browserWindow = Services.wm.getMostRecentWindow("navigator:browser");

  // Click the button and clear the badge
  fxaButton = document.getElementById(msg.content.target);
  fxaButton.click();

  await BrowserTestUtils.waitForCondition(
    () =>
      !browserWindow.document
        .getElementById(msg.content.target)
        .querySelector(".toolbarbutton-badge")
        .classList.contains("feature-callout"),
    "Button should no longer be badged"
  );
});

add_task(async function test_fxa_badge_shown_withdelay() {
  const [msg] = (await OnboardingMessageProvider.getMessages()).filter(
    ({ id }) => id === "FXA_ACCOUNTS_BADGE"
  );

  Assert.ok(msg, "FxA test message exists");

  // Enough to trigger the setTimeout badging
  msg.content.delay = 1;

  let browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
  // Click the button and clear the badge that occurs normally at startup
  let fxaButton = browserWindow.document.getElementById(msg.content.target);
  fxaButton.click();

  await BrowserTestUtils.waitForCondition(
    () =>
      !browserWindow.document
        .getElementById(msg.content.target)
        .querySelector(".toolbarbutton-badge")
        .classList.contains("feature-callout"),
    "Initially element is not badged"
  );

  ToolbarBadgeHub.registerBadgeNotificationListener(msg);

  await BrowserTestUtils.waitForCondition(
    () =>
      browserWindow.document
        .getElementById(msg.content.target)
        .querySelector(".toolbarbutton-badge")
        .classList.contains("feature-callout"),
    "Wait for element to be badged"
  );

  let newWin = await BrowserTestUtils.openNewBrowserWindow();
  browserWindow = Services.wm.getMostRecentWindow("navigator:browser");

  await BrowserTestUtils.waitForCondition(
    () =>
      browserWindow.document
        .getElementById(msg.content.target)
        .querySelector(".toolbarbutton-badge")
        .classList.contains("feature-callout"),
    "Wait for element to be badged"
  );

  await BrowserTestUtils.closeWindow(newWin);
  browserWindow = Services.wm.getMostRecentWindow("navigator:browser");

  // Click the button and clear the badge
  fxaButton = document.getElementById(msg.content.target);
  fxaButton.click();

  await BrowserTestUtils.waitForCondition(
    () =>
      !browserWindow.document
        .getElementById(msg.content.target)
        .querySelector(".toolbarbutton-badge")
        .classList.contains("feature-callout"),
    "Button should no longer be badged"
  );
});