summaryrefslogtreecommitdiffstats
path: root/browser/components/search/test/browser/browser_tooManyEnginesOffered.js
blob: 89647f98545eb4e2812d3dd4dcab86ddb0fd2a57 (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
"use strict";

// This test makes sure that when a page offers many search engines,
// a limited number of add-engine items will be shown in the searchbar.

const searchPopup = document.getElementById("PopupSearchAutoComplete");

add_task(async function test_setup() {
  await gCUITestUtils.addSearchBar();

  await Services.search.init();
  registerCleanupFunction(() => {
    gCUITestUtils.removeSearchBar();
  });
});

add_task(async function test() {
  let searchbar = BrowserSearch.searchBar;

  let rootDir = getRootDirectory(gTestPath);
  let url = rootDir + "tooManyEnginesOffered.html";
  await BrowserTestUtils.openNewForegroundTab(gBrowser, url);

  // Open the search popup.
  let promise = promiseEvent(searchPopup, "popupshown");
  info("Opening search panel");
  searchbar.focus();
  // In TV we may try opening too early, when the searchbar is not ready yet.
  await TestUtils.waitForCondition(
    () => BrowserSearch.searchBar.textbox.controller.input,
    "Wait for the searchbar controller to connect"
  );
  EventUtils.synthesizeKey("KEY_ArrowDown");
  await promise;

  const addEngineList = searchPopup.oneOffButtons._getAddEngines();
  Assert.equal(
    addEngineList.length,
    6,
    "Expected number of engines retrieved from web page"
  );

  const displayedAddEngineList =
    searchPopup.oneOffButtons.buttons.querySelectorAll(
      ".searchbar-engine-one-off-add-engine"
    );
  Assert.equal(
    displayedAddEngineList.length,
    searchPopup.oneOffButtons._maxInlineAddEngines,
    "Expected number of engines displayed on popup"
  );

  for (let i = 0; i < displayedAddEngineList.length; i++) {
    const engine = addEngineList[i];
    const item = displayedAddEngineList[i];
    Assert.equal(
      item.getAttribute("engine-name"),
      engine.title,
      "Expected engine is displaying"
    );
  }

  promise = promiseEvent(searchPopup, "popuphidden");
  EventUtils.synthesizeKey("KEY_Escape", {}, searchPopup.ownerGlobal);
  await promise;

  gBrowser.removeCurrentTab();
});