summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/urlbar/browser_bug1070778.js
blob: ab88d04d84b430fab729cafc8a525c7a9ca53763 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

function is_selected(index) {
  is(gURLBar.popup.richlistbox.selectedIndex, index, `Item ${index + 1} should be selected`);
}

add_task(function*() {
  let bookmarks = [];
  bookmarks.push((yield PlacesUtils.bookmarks
                                   .insert({ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
                                             url: "http://example.com/?q=%s",
                                             title: "test" })));
  yield PlacesUtils.keywords.insert({ keyword: "keyword",
                                      url: "http://example.com/?q=%s" });

  // This item only needed so we can select the keyword item, select something
  // else, then select the keyword item again.
  bookmarks.push((yield PlacesUtils.bookmarks
                                   .insert({ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
                                             url: "http://example.com/keyword",
                                             title: "keyword abc" })));

  registerCleanupFunction(function* () {
    for (let bm of bookmarks) {
      yield PlacesUtils.bookmarks.remove(bm);
    }
  });

  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
  yield promiseAutocompleteResultPopup("keyword a");

  // First item should already be selected
  is_selected(0);
  // Select next one (important!)
  EventUtils.synthesizeKey("VK_DOWN", {});
  is_selected(1);
  // Re-select keyword item
  EventUtils.synthesizeKey("VK_UP", {});
  is_selected(0);

  EventUtils.synthesizeKey("b", {});
  yield promiseSearchComplete();

  is(gURLBar.textValue, "keyword ab", "urlbar should have expected input");

  let result = gURLBar.popup.richlistbox.firstChild;
  isnot(result, null, "Should have first item");
  let uri = NetUtil.newURI(result.getAttribute("url"));
  is(uri.spec, PlacesUtils.mozActionURI("keyword", {url: "http://example.com/?q=ab", input: "keyword ab"}), "Expect correct url");

  EventUtils.synthesizeKey("VK_ESCAPE", {});
  yield promisePopupHidden(gURLBar.popup);
  gBrowser.removeTab(tab);
});