Bug 1416142 - Intermittent timeout in browser_ext_omnibox.js. r=standard8, a=test-only
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 23 Nov 2017 13:47:34 +0100
changeset 445031 939de878cd753f107bf4fbc25bb9fd6e5e46e488
parent 445030 9cf204dbec09f98bb684c4109e579ce4c7e9f2c7
child 445032 3f9baaa05d42528e6d8afaf681bbe5782709706b
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstandard8, test-only
bugs1416142
milestone58.0
Bug 1416142 - Intermittent timeout in browser_ext_omnibox.js. r=standard8, a=test-only MozReview-Commit-ID: DAZumEpI1xB
browser/components/extensions/test/browser/browser_ext_omnibox.js
--- a/browser/components/extensions/test/browser/browser_ext_omnibox.js
+++ b/browser/components/extensions/test/browser/browser_ext_omnibox.js
@@ -90,16 +90,28 @@ add_task(async function() {
       () => gURLBar.popup.richlistbox.children.length > index &&
             gURLBar.popup.richlistbox.children[index].getAttribute("ac-text") == searchString,
       `Waiting for the autocomplete result for "${searchString}" at [${index}] to appear`);
     // Ensure the addition is complete, for proper mouse events on the entries.
     await new Promise(resolve => window.requestIdleCallback(resolve, {timeout: 1000}));
     return gURLBar.popup.richlistbox.children[index];
   }
 
+  async function promiseClickOnItem(item, details) {
+    // The Address Bar panel is animated and updated on a timer, thus it may not
+    // yet be listening to events when we try to click on it.  This uses a
+    // polling strategy to repeat the click, if it doesn't go through.
+    let clicked = false;
+    item.addEventListener("mousedown", () => { clicked = true; }, {once: true});
+    while (!clicked) {
+      EventUtils.synthesizeMouseAtCenter(item, details);
+      await new Promise(r => window.requestIdleCallback(r, {timeout: 1000}));
+    }
+  }
+
   let inputSessionSerial = 0;
   async function startInputSession(indexToWaitFor) {
     gURLBar.focus();
     gURLBar.value = keyword;
     EventUtils.synthesizeKey(" ", {});
     await expectEvent("on-input-started-fired");
     // Always use a different input at every invokation, so that
     // waitForAutocompleteResultAt can distinguish different cases.
@@ -193,45 +205,46 @@ add_task(async function() {
     let item = gURLBar.popup.richlistbox.children[0];
 
     is(item.getAttribute("title"), expectedText,
       `Expected heuristic result to have title: "${expectedText}".`);
 
     is(item.getAttribute("displayurl"), `${keyword} ${text}`,
       `Expected heuristic result to have displayurl: "${keyword} ${text}".`);
 
-    EventUtils.synthesizeMouseAtCenter(item, {});
-
-    await expectEvent("on-input-entered-fired", {
+    let promiseEvent = expectEvent("on-input-entered-fired", {
       text,
       disposition: "currentTab",
     });
+    await promiseClickOnItem(item, {});
+    await promiseEvent;
   }
 
   async function testDisposition(suggestionIndex, expectedDisposition, expectedText) {
     await startInputSession(suggestionIndex);
 
     // Select the suggestion.
     for (let i = 0; i < suggestionIndex; i++) {
       EventUtils.synthesizeKey("VK_DOWN", {});
     }
 
-    let item = gURLBar.popup.richlistbox.children[suggestionIndex];
-    if (expectedDisposition == "currentTab") {
-      EventUtils.synthesizeMouseAtCenter(item, {});
-    } else if (expectedDisposition == "newForegroundTab") {
-      EventUtils.synthesizeMouseAtCenter(item, {accelKey: true});
-    } else if (expectedDisposition == "newBackgroundTab") {
-      EventUtils.synthesizeMouseAtCenter(item, {shiftKey: true, accelKey: true});
-    }
-
-    await expectEvent("on-input-entered-fired", {
+    let promiseEvent = expectEvent("on-input-entered-fired", {
       text: expectedText,
       disposition: expectedDisposition,
     });
+
+    let item = gURLBar.popup.richlistbox.children[suggestionIndex];
+    if (expectedDisposition == "currentTab") {
+      await promiseClickOnItem(item, {});
+    } else if (expectedDisposition == "newForegroundTab") {
+      await promiseClickOnItem(item, {accelKey: true});
+    } else if (expectedDisposition == "newBackgroundTab") {
+      await promiseClickOnItem(item, {shiftKey: true, accelKey: true});
+    }
+    await promiseEvent;
   }
 
   async function testSuggestions(info) {
     extension.sendMessage("set-synchronous", {synchronous: false});
 
     function expectSuggestion({content, description}, index) {
       let item = gURLBar.popup.richlistbox.children[index + 1]; // Skip the heuristic result.
 
@@ -245,21 +258,22 @@ add_task(async function() {
 
     let text = await startInputSession(info.suggestions.length - 1);
 
     extension.sendMessage(info.test);
     await extension.awaitMessage("test-ready");
 
     info.suggestions.forEach(expectSuggestion);
 
-    EventUtils.synthesizeMouseAtCenter(gURLBar.popup.richlistbox.children[0], {});
-    await expectEvent("on-input-entered-fired", {
+    let promiseEvent = expectEvent("on-input-entered-fired", {
       text,
       disposition: "currentTab",
     });
+    await promiseClickOnItem(gURLBar.popup.richlistbox.children[0], {});
+    await promiseEvent;
   }
 
   await extension.startup();
 
   await SimpleTest.promiseFocus(window);
 
   await testInputEvents();