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

/* This test ensures that pressing ctrl+enter bypasses the autoFilled
 * value, and only considers what the user typed (but not just enter).
 */

async function test_autocomplete(data) {
  let { desc, typed, autofilled, modified, waitForUrl, keys } = data;
  info(desc);

  await UrlbarTestUtils.promiseAutocompleteResultPopup({
    window,
    value: typed,
  });
  Assert.equal(gURLBar.value, autofilled, "autofilled value is as expected");

  let promiseLoad = BrowserTestUtils.waitForDocLoadAndStopIt(
    waitForUrl,
    gBrowser.selectedBrowser
  );

  keys.forEach(([key, mods]) => EventUtils.synthesizeKey(key, mods));

  Assert.equal(gURLBar.value, modified, "value is as expected");

  await promiseLoad;
  gURLBar.blur();
}

add_task(async function () {
  await SpecialPowers.pushPrefEnv({
    set: [["browser.urlbar.autoFill", true]],
  });
  registerCleanupFunction(async function () {
    gURLBar.handleRevert();
    await PlacesUtils.bookmarks.eraseEverything();
    await PlacesUtils.history.clear();
  });

  // Add a typed visit, so it will be autofilled.
  await PlacesTestUtils.addVisits({
    uri: "https://example.com/",
    transition: Ci.nsINavHistoryService.TRANSITION_TYPED,
  });
  await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies();

  await test_autocomplete({
    desc: "ENTER on the autofilled part should use autofill",
    typed: "exam",
    autofilled: "example.com/",
    modified: UrlbarTestUtils.trimURL("https://example.com"),
    waitForUrl: "https://example.com/",
    keys: [["KEY_Enter"]],
  });

  await test_autocomplete({
    desc: "CTRL+ENTER on the autofilled part should bypass autofill",
    typed: "exam",
    autofilled: "example.com/",
    modified: UrlbarTestUtils.trimURL("https://www.exam.com"),
    waitForUrl: "https://www.exam.com/",
    keys: [["KEY_Enter", { ctrlKey: true }]],
  });
});