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

"use strict";

const { SearchWidgetTracker } = ChromeUtils.importESModule(
  "resource:///modules/SearchWidgetTracker.sys.mjs"
);

const SEARCH_BAR_PREF_NAME = "browser.search.widget.inNavBar";
const SEARCH_BAR_LAST_USED_PREF_NAME = "browser.search.widget.lastUsed";

add_task(async function checkSearchBarPresent() {
  Services.prefs.setBoolPref(SEARCH_BAR_PREF_NAME, true);
  Services.prefs.setStringPref(
    SEARCH_BAR_LAST_USED_PREF_NAME,
    new Date("2022").toISOString()
  );

  Assert.ok(
    BrowserSearch.searchBar,
    "Search bar should be present in the Nav bar"
  );
  SearchWidgetTracker._updateSearchBarVisibilityBasedOnUsage();
  Assert.ok(
    !BrowserSearch.searchBar,
    "Search bar should not be present in the Nav bar"
  );
  Assert.equal(
    Services.prefs.getBoolPref(SEARCH_BAR_PREF_NAME),
    false,
    "Should remove the search bar"
  );
  Services.prefs.clearUserPref(SEARCH_BAR_LAST_USED_PREF_NAME);
  Services.prefs.clearUserPref(SEARCH_BAR_PREF_NAME);
});