no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / layout / xul / test / browser_bug1163304.js
blobcebc857c9aa53f9997d51e3b15127a1004030b37
1 const { CustomizableUITestUtils } = ChromeUtils.importESModule(
2   "resource://testing-common/CustomizableUITestUtils.sys.mjs"
3 );
4 let gCUITestUtils = new CustomizableUITestUtils(window);
6 add_task(async function test_setup() {
7   await gCUITestUtils.addSearchBar();
8   registerCleanupFunction(() => {
9     gCUITestUtils.removeSearchBar();
10   });
11 });
13 add_task(async function () {
14   const promiseFocusInSearchBar = BrowserTestUtils.waitForEvent(
15     BrowserSearch.searchBar.textbox,
16     "focus"
17   );
18   BrowserSearch.searchBar.focus();
19   await promiseFocusInSearchBar;
21   let DOMWindowUtils = EventUtils._getDOMWindowUtils();
22   is(
23     DOMWindowUtils.IMEStatus,
24     DOMWindowUtils.IME_STATUS_ENABLED,
25     "IME should be available when searchbar has focus"
26   );
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.
33   await (async () => {
34     async function tryToOpen() {
35       try {
36         BrowserSearch.searchBar.focus();
37         EventUtils.synthesizeKey("KEY_F4");
38         await TestUtils.waitForCondition(
39           () => searchPopup.state == "open",
40           "The popup isn't opened",
41           5,
42           100
43         );
44       } catch (e) {
45         // timed out, let's just return false without asserting the failure.
46         return false;
47       }
48       return true;
49     }
50     for (let i = 0; i < 5; i++) {
51       if (await tryToOpen()) {
52         return;
53       }
54     }
55     ok(false, "Failed to open the popup of searchbar");
56   })();
58   is(
59     DOMWindowUtils.IMEStatus,
60     DOMWindowUtils.IME_STATUS_ENABLED,
61     "IME should be available even when the popup of searchbar is open"
62   );
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");
68   await hiddenPromise;
69   await new Promise(r => setTimeout(r, 0));
71   is(
72     DOMWindowUtils.IMEStatus,
73     DOMWindowUtils.IME_STATUS_DISABLED,
74     "IME should not be available when menubar is active"
75   );
76   // Inactivate the menubar (and restore the focus to the searchbar
77   EventUtils.synthesizeKey("KEY_Escape");
78   is(
79     DOMWindowUtils.IMEStatus,
80     DOMWindowUtils.IME_STATUS_ENABLED,
81     "IME should be available after focus is back to the searchbar"
82   );
83 });