1 const { CustomizableUITestUtils } = ChromeUtils.importESModule(
2 "resource://testing-common/CustomizableUITestUtils.sys.mjs"
4 let gCUITestUtils = new CustomizableUITestUtils(window);
6 add_task(async function test_setup() {
7 await gCUITestUtils.addSearchBar();
8 registerCleanupFunction(() => {
9 gCUITestUtils.removeSearchBar();
13 add_task(async function () {
14 const promiseFocusInSearchBar = BrowserTestUtils.waitForEvent(
15 BrowserSearch.searchBar.textbox,
18 BrowserSearch.searchBar.focus();
19 await promiseFocusInSearchBar;
21 let DOMWindowUtils = EventUtils._getDOMWindowUtils();
23 DOMWindowUtils.IMEStatus,
24 DOMWindowUtils.IME_STATUS_ENABLED,
25 "IME should be available when searchbar has focus"
28 let searchPopup = document.getElementById("PopupSearchAutoComplete");
30 // Open popup of the searchbar
31 // Oddly, F4 key press is sometimes not handled by the search bar.
32 // It's out of scope of this test, so, let's retry to open it if failed.
34 async function tryToOpen() {
36 BrowserSearch.searchBar.focus();
37 EventUtils.synthesizeKey("KEY_F4");
38 await TestUtils.waitForCondition(
39 () => searchPopup.state == "open",
40 "The popup isn't opened",
45 // timed out, let's just return false without asserting the failure.
50 for (let i = 0; i < 5; i++) {
51 if (await tryToOpen()) {
55 ok(false, "Failed to open the popup of searchbar");
59 DOMWindowUtils.IMEStatus,
60 DOMWindowUtils.IME_STATUS_ENABLED,
61 "IME should be available even when the popup of searchbar is open"
64 // Activate the menubar, then, the popup should be closed
65 is(searchPopup.state, "open", "The popup of searchbar shouldn't be closed");
66 let hiddenPromise = BrowserTestUtils.waitForEvent(searchPopup, "popuphidden");
67 EventUtils.synthesizeKey("KEY_Alt");
69 await new Promise(r => setTimeout(r, 0));
72 DOMWindowUtils.IMEStatus,
73 DOMWindowUtils.IME_STATUS_DISABLED,
74 "IME should not be available when menubar is active"
76 // Inactivate the menubar (and restore the focus to the searchbar
77 EventUtils.synthesizeKey("KEY_Escape");
79 DOMWindowUtils.IMEStatus,
80 DOMWindowUtils.IME_STATUS_ENABLED,
81 "IME should be available after focus is back to the searchbar"