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

// Checks that pressing the down arrow key starts the proper searches, depending
// on the input value/state.

"use strict";

add_setup(async function () {
  await PlacesUtils.history.clear();
  // Enough vists to get this site into Top Sites.
  for (let i = 0; i < 5; i++) {
    await PlacesTestUtils.addVisits("http://example.com/");
  }

  await updateTopSites(
    sites => sites && sites[0] && sites[0].url == "http://example.com/"
  );
  registerCleanupFunction(async function () {
    await PlacesUtils.history.clear();
  });
});

add_task(async function url() {
  await BrowserTestUtils.withNewTab("http://example.com/", async () => {
    gURLBar.focus();
    gURLBar.selectionEnd = gURLBar.untrimmedValue.length;
    gURLBar.selectionStart = gURLBar.untrimmedValue.length;
    EventUtils.synthesizeKey("KEY_ArrowDown");
    await UrlbarTestUtils.promiseSearchComplete(window);
    Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), 0);
    let details = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
    Assert.ok(details.autofill);
    Assert.equal(details.url, "http://example.com/");
    Assert.equal(gURLBar.value, "example.com/");
    await UrlbarTestUtils.promisePopupClose(window);
  });
});

add_task(async function userTyping() {
  await UrlbarTestUtils.promiseAutocompleteResultPopup({
    window,
    value: "foo",
    fireInputEvent: true,
  });
  await UrlbarTestUtils.promisePopupClose(window);
  EventUtils.synthesizeKey("KEY_ArrowDown");
  await UrlbarTestUtils.promiseSearchComplete(window);
  Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), 0);
  let details = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
  Assert.equal(details.type, UrlbarUtils.RESULT_TYPE.SEARCH);
  Assert.ok(details.searchParams);
  Assert.equal(details.searchParams.query, "foo");
  Assert.equal(gURLBar.value, "foo");
  await UrlbarTestUtils.promisePopupClose(window);
});

add_task(async function empty() {
  await UrlbarTestUtils.promiseAutocompleteResultPopup({
    window,
    value: "",
    fireInputEvent: true,
  });
  await UrlbarTestUtils.promisePopupClose(window);
  EventUtils.synthesizeKey("KEY_ArrowDown");
  await UrlbarTestUtils.promiseSearchComplete(window);
  Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), -1);
  let details = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
  Assert.equal(details.url, "http://example.com/");
  Assert.equal(gURLBar.value, "");
});

add_task(async function new_window() {
  let win = await BrowserTestUtils.openNewBrowserWindow();
  win.gURLBar.focus();
  EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
  await UrlbarTestUtils.promiseSearchComplete(win);
  Assert.equal(UrlbarTestUtils.getSelectedRowIndex(win), -1);
  let details = await UrlbarTestUtils.getDetailsOfResultAt(win, 0);
  Assert.equal(details.url, "http://example.com/");
  Assert.equal(win.gURLBar.value, "");
  await BrowserTestUtils.closeWindow(win);
});