summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/browser/browser_searchMode_oneOffButton.js
diff options
context:
space:
mode:
Diffstat (limited to 'browser/components/urlbar/tests/browser/browser_searchMode_oneOffButton.js')
-rw-r--r--browser/components/urlbar/tests/browser/browser_searchMode_oneOffButton.js108
1 files changed, 108 insertions, 0 deletions
diff --git a/browser/components/urlbar/tests/browser/browser_searchMode_oneOffButton.js b/browser/components/urlbar/tests/browser/browser_searchMode_oneOffButton.js
new file mode 100644
index 0000000000..1ba0d3283b
--- /dev/null
+++ b/browser/components/urlbar/tests/browser/browser_searchMode_oneOffButton.js
@@ -0,0 +1,108 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Tests one-off search button behavior with search mode.
+ */
+
+const TEST_ENGINE_NAME = "test engine";
+
+add_setup(async function () {
+ await SearchTestUtils.installSearchExtension({
+ name: TEST_ENGINE_NAME,
+ keyword: "@test",
+ });
+});
+
+add_task(async function test() {
+ info("Test no one-off buttons are selected when entering search mode");
+
+ info("Open the result popup");
+ await UrlbarTestUtils.promiseAutocompleteResultPopup({
+ window,
+ value: "",
+ });
+
+ info("Select one of one-off button");
+ const oneOffs = UrlbarTestUtils.getOneOffSearchButtons(window);
+ await TestUtils.waitForCondition(
+ () => !oneOffs._rebuilding,
+ "Waiting for one-offs to finish rebuilding"
+ );
+ EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true });
+ ok(oneOffs.selectedButton, "There is a selected one-off button");
+
+ info("Enter search mode");
+ await UrlbarTestUtils.enterSearchMode(window, {
+ engineName: TEST_ENGINE_NAME,
+ });
+ await UrlbarTestUtils.assertSearchMode(window, {
+ engineName: TEST_ENGINE_NAME,
+ entry: "oneoff",
+ });
+ ok(!oneOffs.selectedButton, "There is no selected one-off button");
+});
+
+add_task(async function () {
+ info(
+ "Test the status of the selected one-off button when exiting search mode with backspace"
+ );
+
+ info("Open the result popup");
+ await UrlbarTestUtils.promiseAutocompleteResultPopup({
+ window,
+ value: "",
+ });
+
+ info("Select one of one-off button");
+ const oneOffs = UrlbarTestUtils.getOneOffSearchButtons(window);
+ await TestUtils.waitForCondition(
+ () => !oneOffs._rebuilding,
+ "Waiting for one-offs to finish rebuilding"
+ );
+ EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true });
+ ok(oneOffs.selectedButton, "There is a selected one-off button");
+ await UrlbarTestUtils.assertSearchMode(window, {
+ engineName: oneOffs.selectedButton.engine.name,
+ source: UrlbarUtils.RESULT_SOURCE.SEARCH,
+ entry: "oneoff",
+ isPreview: true,
+ });
+
+ info("Exit from search mode");
+ await UrlbarTestUtils.exitSearchMode(window);
+ ok(!oneOffs.selectedButton, "There is no any selected one-off button");
+});
+
+add_task(async function () {
+ info(
+ "Test the status of the selected one-off button when exiting search mode with clicking close button"
+ );
+
+ info("Open the result popup");
+ await UrlbarTestUtils.promiseAutocompleteResultPopup({
+ window,
+ value: "",
+ });
+
+ info("Select one of one-off button");
+ const oneOffs = UrlbarTestUtils.getOneOffSearchButtons(window);
+ await TestUtils.waitForCondition(
+ () => !oneOffs._rebuilding,
+ "Waiting for one-offs to finish rebuilding"
+ );
+ EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true });
+ ok(oneOffs.selectedButton, "There is a selected one-off button");
+ await UrlbarTestUtils.assertSearchMode(window, {
+ engineName: oneOffs.selectedButton.engine.name,
+ source: UrlbarUtils.RESULT_SOURCE.SEARCH,
+ entry: "oneoff",
+ isPreview: true,
+ });
+
+ info("Exit from search mode");
+ await UrlbarTestUtils.exitSearchMode(window, { clickClose: true });
+ ok(!oneOffs.selectedButton, "There is no any selected one-off button");
+});