--- 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();