tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_bug1163304.js (2585B)


      1 const { CustomizableUITestUtils } = ChromeUtils.importESModule(
      2  "resource://testing-common/CustomizableUITestUtils.sys.mjs"
      3 );
      4 let gCUITestUtils = new CustomizableUITestUtils(window);
      5 let searchBar;
      6 
      7 add_task(async function test_setup() {
      8  await SpecialPowers.pushPrefEnv({
      9    set: [["browser.search.widget.new", false]],
     10  });
     11  searchBar = await gCUITestUtils.addSearchBar();
     12  registerCleanupFunction(() => {
     13    gCUITestUtils.removeSearchBar();
     14  });
     15 });
     16 
     17 add_task(async function () {
     18  const promiseFocusInSearchBar = BrowserTestUtils.waitForEvent(
     19    searchBar.textbox,
     20    "focus"
     21  );
     22  searchBar.focus();
     23  await promiseFocusInSearchBar;
     24 
     25  let DOMWindowUtils = EventUtils._getDOMWindowUtils();
     26  is(
     27    DOMWindowUtils.IMEStatus,
     28    DOMWindowUtils.IME_STATUS_ENABLED,
     29    "IME should be available when searchbar has focus"
     30  );
     31 
     32  let searchPopup = document.getElementById("PopupSearchAutoComplete");
     33 
     34  // Open popup of the searchbar
     35  // Oddly, F4 key press is sometimes not handled by the search bar.
     36  // It's out of scope of this test, so, let's retry to open it if failed.
     37  await (async () => {
     38    async function tryToOpen() {
     39      try {
     40        searchBar.focus();
     41        EventUtils.synthesizeKey("KEY_F4");
     42        await TestUtils.waitForCondition(
     43          () => searchPopup.state == "open",
     44          "The popup isn't opened",
     45          5,
     46          100
     47        );
     48      } catch (e) {
     49        // timed out, let's just return false without asserting the failure.
     50        return false;
     51      }
     52      return true;
     53    }
     54    for (let i = 0; i < 5; i++) {
     55      if (await tryToOpen()) {
     56        return;
     57      }
     58    }
     59    ok(false, "Failed to open the popup of searchbar");
     60  })();
     61 
     62  is(
     63    DOMWindowUtils.IMEStatus,
     64    DOMWindowUtils.IME_STATUS_ENABLED,
     65    "IME should be available even when the popup of searchbar is open"
     66  );
     67 
     68  // Activate the menubar, then, the popup should be closed
     69  is(searchPopup.state, "open", "The popup of searchbar shouldn't be closed");
     70  let hiddenPromise = BrowserTestUtils.waitForEvent(searchPopup, "popuphidden");
     71  EventUtils.synthesizeKey("KEY_Alt");
     72  await hiddenPromise;
     73  await new Promise(r => setTimeout(r, 0));
     74 
     75  is(
     76    DOMWindowUtils.IMEStatus,
     77    DOMWindowUtils.IME_STATUS_DISABLED,
     78    "IME should not be available when menubar is active"
     79  );
     80  // Inactivate the menubar (and restore the focus to the searchbar
     81  EventUtils.synthesizeKey("KEY_Escape");
     82  is(
     83    DOMWindowUtils.IMEStatus,
     84    DOMWindowUtils.IME_STATUS_ENABLED,
     85    "IME should be available after focus is back to the searchbar"
     86  );
     87 });