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

/**
 * Tests the Search History option from the menubar starts Address Bar search
 * mode for history.
 */
ChromeUtils.defineLazyGetter(this, "UrlbarTestUtils", () => {
  const { UrlbarTestUtils: module } = ChromeUtils.importESModule(
    "resource://testing-common/UrlbarTestUtils.sys.mjs"
  );
  module.init(this);
  return module;
});

add_task(async function test_menu_search_history_with_window_open() {
  info("Opening history menu");
  let searchHistoryMenuEntry = document.getElementById("menu_searchHistory");

  searchHistoryMenuEntry.doCommand();

  await isUrlbarInHistorySearchMode(window);
});

add_task(async function test_menu_search_history_opens_new_window() {
  let newWindowPromise = TestUtils.topicObserved(
    "browser-delayed-startup-finished"
  );

  info(
    "Executing command in untracked browser window (simulating non-browser window)."
  );
  BrowserWindowTracker.untrackForTestsOnly(window);
  let searchHistoryMenuEntry = document.getElementById("menu_searchHistory");
  searchHistoryMenuEntry.doCommand();
  BrowserWindowTracker.track(window);

  info("Waiting for new window to open.");
  let [newWindow] = await newWindowPromise;
  await isUrlbarInHistorySearchMode(newWindow);
  await BrowserTestUtils.closeWindow(newWindow);
});

async function isUrlbarInHistorySearchMode(targetWin) {
  is(
    targetWin,
    BrowserWindowTracker.getTopWindow(),
    "Target window is top window."
  );
  await UrlbarTestUtils.promisePopupOpen(targetWin, () => {});

  // Verify URLBar is in search mode with correct restriction
  let searchMode = UrlbarUtils.searchModeForToken("^");
  searchMode.entry = "historymenu";
  await UrlbarTestUtils.assertSearchMode(targetWin, searchMode);
}