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

"use strict";

const tests = [
  async function (win) {
    info("Type something, click on search settings.");
    await BrowserTestUtils.withNewTab(
      { gBrowser: win.gBrowser, url: "about:blank" },
      async browser => {
        win.gURLBar.select();
        const promise = onSyncPaneLoaded();
        await UrlbarTestUtils.promiseAutocompleteResultPopup({
          window: win,
          value: "x",
          fireInputEvent: true,
        });
        UrlbarTestUtils.getOneOffSearchButtons(win).settingsButton.click();
        await promise;
      }
    );
    return null;
  },

  async function (win) {
    info("Type something, Up, Enter on search settings.");
    await BrowserTestUtils.withNewTab(
      { gBrowser: win.gBrowser, url: "about:blank" },
      async browser => {
        win.gURLBar.select();
        const promise = onSyncPaneLoaded();
        await UrlbarTestUtils.promiseAutocompleteResultPopup({
          window: win,
          value: "x",
          fireInputEvent: true,
        });
        EventUtils.synthesizeKey("KEY_ArrowUp", {}, win);
        Assert.ok(
          UrlbarTestUtils.getOneOffSearchButtons(
            win
          ).selectedButton.classList.contains("search-setting-button"),
          "Should have selected the settings button"
        );
        EventUtils.synthesizeKey("VK_RETURN", {}, win);
        await promise;
      }
    );
    return null;
  },
];

function onSyncPaneLoaded() {
  return new Promise(resolve => {
    Services.obs.addObserver(function panesLoadedObs() {
      Services.obs.removeObserver(panesLoadedObs, "sync-pane-loaded");
      resolve();
    }, "sync-pane-loaded");
  });
}

add_task(async function test() {
  await SpecialPowers.pushPrefEnv({
    set: [["browser.urlbar.eventTelemetry.enabled", true]],
  });

  const win = await BrowserTestUtils.openNewBrowserWindow();

  // This is not necessary after each loop, because assertEvents does it.
  Services.telemetry.clearEvents();

  for (let i = 0; i < tests.length; i++) {
    info(`Running no event test at index ${i}`);
    await tests[i](win);
    // Always blur to ensure it's not accounted as an additional abandonment.
    win.gURLBar.blur();
    TelemetryTestUtils.assertEvents([], { category: "urlbar" });
  }

  await BrowserTestUtils.closeWindow(win);
});