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

// Tests immediately entering search mode in a new window and then exiting it.
// No errors should be thrown and search mode should be exited successfully.

"use strict";

add_task(async function escape() {
  await doTest(win =>
    EventUtils.synthesizeKey("KEY_Escape", { repeat: 2 }, win)
  );
});

add_task(async function backspace() {
  await doTest(win => EventUtils.synthesizeKey("KEY_Backspace", {}, win));
});

async function doTest(exitSearchMode) {
  let win = await BrowserTestUtils.openNewBrowserWindow();

  // Press accel+K to enter search mode.
  await UrlbarTestUtils.promisePopupOpen(win, () =>
    EventUtils.synthesizeKey("k", { accelKey: true }, win)
  );
  await UrlbarTestUtils.assertSearchMode(win, {
    engineName: Services.search.defaultEngine.name,
    isGeneralPurposeEngine: true,
    source: UrlbarUtils.RESULT_SOURCE.SEARCH,
    isPreview: false,
    entry: "shortcut",
  });

  // Exit search mode.
  await exitSearchMode(win);
  await UrlbarTestUtils.assertSearchMode(win, null);

  await UrlbarTestUtils.promisePopupClose(win);
  await BrowserTestUtils.closeWindow(win);
}