summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_urlbarSearchMode.js
blob: 052fcf355c8ea809439545a9ce60cbbe3cd97752 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * This test makes sure that the urlbar's search mode is correctly preserved.
 */

ChromeUtils.defineESModuleGetters(this, {
  UrlbarUtils: "resource:///modules/UrlbarUtils.sys.mjs",
});

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() {
  // Open the urlbar view and enter search mode.
  await UrlbarTestUtils.promiseAutocompleteResultPopup({
    window,
    value: "test",
  });
  await UrlbarTestUtils.enterSearchMode(window, {
    source: UrlbarUtils.RESULT_SOURCE.HISTORY,
  });

  // The search mode should be in the tab state.
  let state = JSON.parse(ss.getTabState(gBrowser.selectedTab));
  Assert.ok(
    "searchMode" in state,
    "state.searchMode is present after entering search mode"
  );
  Assert.deepEqual(
    state.searchMode,
    {
      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
      entry: "oneoff",
      isPreview: false,
    },
    "state.searchMode is correct"
  );

  // Exit search mode.
  await UrlbarTestUtils.exitSearchMode(window);

  // The search mode should not be in the tab state.
  let newState = JSON.parse(ss.getTabState(gBrowser.selectedTab));
  Assert.ok(
    !newState.searchMode,
    "state.searchMode is not present after exiting search mode"
  );

  await UrlbarTestUtils.promisePopupClose(window);
});