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

"use strict";

/**
 * Check clicking on the search mode indicator when the urlbar is not focused puts
 * focus in the urlbar.
 */

add_task(async function test() {
  // Avoid remote connections.
  await SpecialPowers.pushPrefEnv({
    set: [["browser.search.suggest.enabled", false]],
  });

  await BrowserTestUtils.withNewTab("about:robots", async browser => {
    // View open, with string.
    await UrlbarTestUtils.promiseAutocompleteResultPopup({
      window,
      value: "test",
    });
    const indicator = document.getElementById("urlbar-search-mode-indicator");
    Assert.ok(!BrowserTestUtils.is_visible(indicator));
    const indicatorCloseButton = document.getElementById(
      "urlbar-search-mode-indicator-close"
    );
    Assert.ok(!BrowserTestUtils.is_visible(indicatorCloseButton));
    const labelBox = document.getElementById("urlbar-label-box");
    Assert.ok(!BrowserTestUtils.is_visible(labelBox));

    await UrlbarTestUtils.enterSearchMode(window);
    Assert.ok(BrowserTestUtils.is_visible(indicator));
    Assert.ok(BrowserTestUtils.is_visible(indicatorCloseButton));
    Assert.ok(!BrowserTestUtils.is_visible(labelBox));

    info("Blur the urlbar");
    gURLBar.blur();
    Assert.ok(BrowserTestUtils.is_visible(indicator));
    Assert.ok(BrowserTestUtils.is_visible(indicatorCloseButton));
    Assert.ok(!BrowserTestUtils.is_visible(labelBox));
    Assert.notEqual(
      document.activeElement,
      gURLBar.inputField,
      "URL Bar should not be focused"
    );

    info("Focus the urlbar clicking on the indicator");
    EventUtils.synthesizeMouseAtCenter(indicator, {});
    Assert.ok(BrowserTestUtils.is_visible(indicator));
    Assert.ok(BrowserTestUtils.is_visible(indicatorCloseButton));
    Assert.ok(!BrowserTestUtils.is_visible(labelBox));
    Assert.equal(
      document.activeElement,
      gURLBar.inputField,
      "URL Bar should be focused"
    );

    info("Leave search mode clicking on the close button");
    await UrlbarTestUtils.exitSearchMode(window, { clickClose: true });
    Assert.ok(!BrowserTestUtils.is_visible(indicator));
    Assert.ok(!BrowserTestUtils.is_visible(indicatorCloseButton));
    Assert.ok(!BrowserTestUtils.is_visible(labelBox));
  });

  await BrowserTestUtils.withNewTab("about:robots", async browser => {
    await UrlbarTestUtils.promiseAutocompleteResultPopup({
      window,
      value: "test",
    });
    const indicator = document.getElementById("urlbar-search-mode-indicator");
    Assert.ok(!BrowserTestUtils.is_visible(indicator));
    const indicatorCloseButton = document.getElementById(
      "urlbar-search-mode-indicator-close"
    );
    Assert.ok(!BrowserTestUtils.is_visible(indicatorCloseButton));

    await UrlbarTestUtils.enterSearchMode(window);
    Assert.ok(BrowserTestUtils.is_visible(indicator));
    Assert.ok(BrowserTestUtils.is_visible(indicatorCloseButton));

    info("Blur the urlbar");
    gURLBar.blur();
    Assert.ok(BrowserTestUtils.is_visible(indicator));
    Assert.ok(BrowserTestUtils.is_visible(indicatorCloseButton));
    Assert.notEqual(
      document.activeElement,
      gURLBar.inputField,
      "URL Bar should not be focused"
    );

    info("Leave search mode clicking on the close button while unfocussing");
    await UrlbarTestUtils.exitSearchMode(window, {
      clickClose: true,
      waitForSearch: false,
    });
    Assert.ok(!BrowserTestUtils.is_visible(indicator));
    Assert.ok(!BrowserTestUtils.is_visible(indicatorCloseButton));
  });
});