summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/urlbar/browser_search_favicon.js
blob: a8e6dbbcd957431af6c886ce3af95a52bc36683d (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
var gOriginalEngine;
var gEngine;
var gRestyleSearchesPref = "browser.urlbar.restyleSearches";

registerCleanupFunction(() => {
  Services.prefs.clearUserPref(gRestyleSearchesPref);
  Services.search.currentEngine = gOriginalEngine;
  Services.search.removeEngine(gEngine);
  return PlacesTestUtils.clearHistory();
});

add_task(function*() {
  Services.prefs.setBoolPref(gRestyleSearchesPref, true);
});

add_task(function*() {

  Services.search.addEngineWithDetails("SearchEngine", "", "", "",
                                       "GET", "http://s.example.com/search");
  gEngine = Services.search.getEngineByName("SearchEngine");
  gEngine.addParam("q", "{searchTerms}", null);
  gOriginalEngine = Services.search.currentEngine;
  Services.search.currentEngine = gEngine;

  let uri = NetUtil.newURI("http://s.example.com/search?q=foo&client=1");
  yield PlacesTestUtils.addVisits({ uri: uri, title: "Foo - SearchEngine Search" });

  yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");

  // The first autocomplete result has the action searchengine, while
  // the second result is the "search favicon" element.
  yield promiseAutocompleteResultPopup("foo");
  let result = gURLBar.popup.richlistbox.children[1];

  isnot(result, null, "Expect a search result");
  is(result.getAttribute("type"), "searchengine", "Expect correct `type` attribute");

  let titleHbox = result._titleText.parentNode.parentNode;
  ok(titleHbox.classList.contains("ac-title"), "Title hbox sanity check");
  is_element_visible(titleHbox, "Title element should be visible");

  let urlHbox = result._urlText.parentNode.parentNode;
  ok(urlHbox.classList.contains("ac-url"), "URL hbox sanity check");
  is_element_hidden(urlHbox, "URL element should be hidden");

  let actionHbox = result._actionText.parentNode.parentNode;
  ok(actionHbox.classList.contains("ac-action"), "Action hbox sanity check");
  is_element_hidden(actionHbox, "Action element should be hidden because it is not selected");
  is(result._actionText.textContent, "Search with SearchEngine", "Action text should be as expected");

  gBrowser.removeCurrentTab();
});