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

/**
 * Tests that autofill is cleared if a remote search mode is entered but still
 * works for local search modes.
 */

"use strict";

add_setup(async function () {
  for (let i = 0; i < 5; i++) {
    await PlacesTestUtils.addVisits([{ uri: "http://example.com/" }]);
  }

  await SearchTestUtils.installSearchExtension({}, { setAsDefault: true });
  let defaultEngine = Services.search.getEngineByName("Example");
  await Services.search.moveEngine(defaultEngine, 0);

  await SpecialPowers.pushPrefEnv({
    set: [["browser.urlbar.suggest.quickactions", false]],
  });

  registerCleanupFunction(async () => {
    await PlacesUtils.history.clear();
  });
});

// Tests that autofill is cleared when entering a remote search mode and that
// autofill doesn't happen when in that mode.
add_task(async function remote() {
  info("Sanity check: we autofill in a normal search.");
  await UrlbarTestUtils.promiseAutocompleteResultPopup({
    window,
    value: "ex",
    fireInputEvent: true,
  });
  let details = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
  Assert.ok(details.autofill, "We're autofilling.");
  Assert.equal(
    gURLBar.value,
    "example.com/",
    "Urlbar contains the autofilled URL."
  );
  info("Enter remote search mode and check autofill is cleared.");
  await UrlbarTestUtils.enterSearchMode(window);
  Assert.equal(gURLBar.value, "ex", "Urlbar contains the typed string.");

  info("Continue typing and check that we're not autofilling.");
  await UrlbarTestUtils.promiseAutocompleteResultPopup({
    window,
    value: "exa",
    fireInputEvent: true,
  });

  details = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
  Assert.ok(!details.autofill, "We're not autofilling.");
  Assert.equal(gURLBar.value, "exa", "Urlbar contains the typed string.");

  info("Exit remote search mode and check that we now autofill.");
  await UrlbarTestUtils.exitSearchMode(window, { backspace: true });
  await UrlbarTestUtils.promiseAutocompleteResultPopup({
    window,
    value: "exam",
    fireInputEvent: true,
  });
  details = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
  Assert.ok(details.autofill, "We're autofilling.");
  Assert.equal(
    gURLBar.value,
    "example.com/",
    "Urlbar contains the typed string."
  );
  await UrlbarTestUtils.promisePopupClose(window, () => gURLBar.blur());
});

// Tests that autofill works as normal when entering and when in a local search
// mode.
add_task(async function local() {
  info("Sanity check: we autofill in a normal search.");
  await UrlbarTestUtils.promiseAutocompleteResultPopup({
    window,
    value: "ex",
    fireInputEvent: true,
  });
  let details = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
  Assert.ok(details.autofill, "We're autofilling.");
  Assert.equal(
    gURLBar.value,
    "example.com/",
    "Urlbar contains the autofilled URL."
  );
  info("Enter local search mode and check autofill is preserved.");
  await UrlbarTestUtils.enterSearchMode(window, {
    source: UrlbarUtils.RESULT_SOURCE.HISTORY,
  });
  Assert.equal(
    gURLBar.value,
    "example.com/",
    "Urlbar contains the autofilled URL."
  );

  info("Continue typing and check that we're autofilling.");
  await UrlbarTestUtils.promiseAutocompleteResultPopup({
    window,
    value: "exa",
    fireInputEvent: true,
  });

  details = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
  Assert.ok(details.autofill, "We're autofilling.");
  Assert.equal(
    gURLBar.value,
    "example.com/",
    "Urlbar contains the autofilled URL."
  );

  info("Exit local search mode and check that nothing has changed.");
  await UrlbarTestUtils.exitSearchMode(window, { backspace: true });
  await UrlbarTestUtils.promiseAutocompleteResultPopup({
    window,
    value: "exam",
    fireInputEvent: true,
  });
  details = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
  Assert.ok(details.autofill, "We're autofilling.");
  Assert.equal(
    gURLBar.value,
    "example.com/",
    "Urlbar contains the typed string."
  );
  await UrlbarTestUtils.promisePopupClose(window, () => gURLBar.blur());
});