1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
5 Tests the showSearchTerms option on the about:preferences#search page.
10 ChromeUtils.defineLazyGetter(this, "QuickSuggestTestUtils", () => {
11 const { QuickSuggestTestUtils: module } = ChromeUtils.importESModule(
12 "resource://testing-common/QuickSuggestTestUtils.sys.mjs"
18 const { CustomizableUITestUtils } = ChromeUtils.importESModule(
19 "resource://testing-common/CustomizableUITestUtils.sys.mjs"
21 let gCUITestUtils = new CustomizableUITestUtils(window);
23 const CHECKBOX_ID = "searchShowSearchTermCheckbox";
24 const PREF_SEARCHTERMS = "browser.urlbar.showSearchTerms.enabled";
25 const PREF_FEATUREGATE = "browser.urlbar.showSearchTerms.featureGate";
28 If Nimbus experiment is enabled, check option visibility.
30 add_task(async function showSearchTermsVisibility_experiment_beforeOpen() {
31 await SpecialPowers.pushPrefEnv({
32 set: [[PREF_FEATUREGATE, false]],
34 await QuickSuggestTestUtils.withExperiment({
36 showSearchTermsFeatureGate: true,
38 callback: async () => {
39 await openPreferencesViaOpenPreferencesAPI("search", {
42 let doc = gBrowser.selectedBrowser.contentDocument;
43 let container = doc.getElementById(CHECKBOX_ID);
45 BrowserTestUtils.isVisible(container),
46 "The option box is visible"
48 gBrowser.removeCurrentTab();
51 await SpecialPowers.popPrefEnv();
55 If Nimbus experiment is not enabled initially but eventually enabled,
56 check option visibility on Preferences page.
58 add_task(async function showSearchTermsVisibility_experiment_afterOpen() {
59 await SpecialPowers.pushPrefEnv({
60 set: [[PREF_FEATUREGATE, false]],
62 await openPreferencesViaOpenPreferencesAPI("search", { leaveOpen: true });
63 let doc = gBrowser.selectedBrowser.contentDocument;
64 let container = doc.getElementById(CHECKBOX_ID);
66 BrowserTestUtils.isHidden(container),
67 "The option box is initially hidden."
70 // Install experiment.
71 await QuickSuggestTestUtils.withExperiment({
73 showSearchTermsFeatureGate: true,
75 callback: async () => {
77 BrowserTestUtils.isVisible(container),
78 "The option box is visible"
84 BrowserTestUtils.isHidden(container),
85 "The option box is hidden again after the experiment is uninstalled."
88 gBrowser.removeCurrentTab();
89 await SpecialPowers.popPrefEnv();
93 Check using the checkbox modifies the preference.
95 add_task(async function showSearchTerms_checkbox() {
96 // Enable the feature.
97 await SpecialPowers.pushPrefEnv({
98 set: [[PREF_FEATUREGATE, true]],
100 await openPreferencesViaOpenPreferencesAPI("search", { leaveOpen: true });
101 let doc = gBrowser.selectedBrowser.contentDocument;
103 let option = doc.getElementById(CHECKBOX_ID);
105 // Evaluate checkbox pref is true.
106 Assert.ok(option.checked, "Option box should be checked.");
108 // Evaluate checkbox when pref is false.
109 await SpecialPowers.pushPrefEnv({
110 set: [[PREF_SEARCHTERMS, false]],
112 Assert.ok(!option.checked, "Option box should not be checked.");
113 await SpecialPowers.popPrefEnv();
115 // Evaluate pref when checkbox is un-checked.
116 await BrowserTestUtils.synthesizeMouseAtCenter(
119 gBrowser.selectedBrowser
122 Services.prefs.getBoolPref(PREF_SEARCHTERMS),
124 "Preference should be false if un-checked."
127 // Evaluate pref when checkbox is checked.
128 await BrowserTestUtils.synthesizeMouseAtCenter(
131 gBrowser.selectedBrowser
134 Services.prefs.getBoolPref(PREF_SEARCHTERMS),
136 "Preference should be true if checked."
140 Services.prefs.clearUserPref(PREF_SEARCHTERMS);
141 gBrowser.removeCurrentTab();
142 await SpecialPowers.popPrefEnv();
146 When loading the search preferences panel, the
147 showSearchTerms checkbox should be hidden if
148 the search bar is enabled.
150 add_task(async function showSearchTerms_and_searchBar_preference_load() {
151 // Enable the feature.
152 await SpecialPowers.pushPrefEnv({
153 set: [[PREF_FEATUREGATE, true]],
155 await gCUITestUtils.addSearchBar();
157 await openPreferencesViaOpenPreferencesAPI("search", { leaveOpen: true });
158 let doc = gBrowser.selectedBrowser.contentDocument;
160 let checkbox = doc.getElementById(CHECKBOX_ID);
163 "showSearchTerms checkbox should be hidden when search bar is enabled."
167 gBrowser.removeCurrentTab();
168 await SpecialPowers.popPrefEnv();
169 gCUITestUtils.removeSearchBar();
173 If the search bar is enabled while the search
174 preferences panel is open, the showSearchTerms
175 checkbox should not be clickable.
177 add_task(async function showSearchTerms_and_searchBar_preference_change() {
178 // Enable the feature.
179 await SpecialPowers.pushPrefEnv({
180 set: [[PREF_FEATUREGATE, true]],
183 await openPreferencesViaOpenPreferencesAPI("search", { leaveOpen: true });
184 let doc = gBrowser.selectedBrowser.contentDocument;
186 let checkbox = doc.getElementById(CHECKBOX_ID);
187 Assert.ok(!checkbox.hidden, "showSearchTerms checkbox should be shown.");
189 await gCUITestUtils.addSearchBar();
192 "showSearchTerms checkbox should be hidden when search bar is enabled."
196 gCUITestUtils.removeSearchBar();
197 Assert.ok(!checkbox.hidden, "showSearchTerms checkbox should be shown.");
199 gBrowser.removeCurrentTab();
200 await SpecialPowers.popPrefEnv();