Commit ec290cb1 authored by Masayuki Nakano's avatar Masayuki Nakano
Browse files

Bug 1707789 - Make browser_bug1163304.js retry to open the popup of search bar...

Bug 1707789 - Make browser_bug1163304.js retry to open the popup of search bar if failed r=NeilDeakin

In my investigation, `F4` key in the search bar may not be handled as expected
because if it happens, the popup's state stays "closed" and "popupshowing",
"popuphiding" nor "popuphidden" event is fired.

The scope of the test is checking IME enabled state in searchbar in some
situations.  Therefore, failing to open the popup with `F4` key is out of
scope of the test.  So, let's make it retry to open the popup in the case.

Differential Revision: https://phabricator.services.mozilla.com/D114571
parent 8f730193
Loading
Loading
Loading
Loading
+27 −4
Original line number Diff line number Diff line
@@ -27,11 +27,33 @@ add_task(async function() {

  let searchPopup = document.getElementById("PopupSearchAutoComplete");

  let shownPromise = BrowserTestUtils.waitForEvent(searchPopup, "popupshown");
  // Open popup of the searchbar
  // Oddly, F4 key press is sometimes not handled by the search bar.
  // It's out of scope of this test, so, let's retry to open it if failed.
  await (async () => {
    async function tryToOpen() {
      try {
        BrowserSearch.searchBar.focus();
        EventUtils.synthesizeKey("KEY_F4");
  await shownPromise;
  await new Promise(r => setTimeout(r, 0));
        await TestUtils.waitForCondition(
          () => searchPopup.state == "open",
          "The popup isn't opened",
          5,
          100
        );
      } catch (e) {
        // timed out, let's just return false without asserting the failure.
        return false;
      }
      return true;
    }
    for (let i = 0; i < 5; i++) {
      if (await tryToOpen()) {
        return;
      }
    }
    ok(false, "Failed to open the popup of searchbar");
  })();

  is(
    DOMWindowUtils.IMEStatus,
@@ -40,6 +62,7 @@ add_task(async function() {
  );

  // Activate the menubar, then, the popup should be closed
  is(searchPopup.state, "open", "The popup of searchbar shouldn't be closed");
  let hiddenPromise = BrowserTestUtils.waitForEvent(searchPopup, "popuphidden");
  EventUtils.synthesizeKey("KEY_Alt");
  await hiddenPromise;