Bug 1454627 - Fix timing issue in browser_ext_user_events.js r=mixedpuppy
authorRob Wu <rob@robwu.nl>
Tue, 31 Jul 2018 16:58:41 +0200
changeset 429567 3a4b606f79aea7836467edec5f83227163c781e3
parent 429566 50114fce0886ee55f0c83a79bc2518df6e1150b2
child 429568 b5399f9627bcd09799199a043561d5aef15717a9
push id34368
push userdvarga@mozilla.com
push dateWed, 01 Aug 2018 22:08:36 +0000
treeherdermozilla-central@210796a7e6b4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1454627
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1454627 - Fix timing issue in browser_ext_user_events.js r=mixedpuppy The hard-coded wait exists to avoid a test failure caused by a non-functional click event in an options browser. However, that still does not get rid of the intermittent failure. To really avoid the timing issue, check whether onclick was fired after supposedly triggering a click, and if not, wait and retry. MozReview-Commit-ID: 9eg6sz1s1e3
browser/components/extensions/test/browser/browser_ext_user_events.js
--- a/browser/components/extensions/test/browser/browser_ext_user_events.js
+++ b/browser/components/extensions/test/browser/browser_ext_user_events.js
@@ -85,39 +85,42 @@ add_task(async function testSources() {
           <a id="link" href="#">Link</a>
         </body>
         </html>`,
 
       "options.js"() {
         addEventListener("load", async () => {
           let link = document.getElementById("link");
           link.onclick = async event => {
+            link.onclick = null;
             event.preventDefault();
 
+            browser.test.log("Calling permission.request from options page.");
+
             try {
               let result = await browser.permissions.request({
                 permissions: ["webRequest"],
               });
               browser.test.sendMessage("request", {success: true, result});
             } catch (err) {
               browser.test.sendMessage("request", {success: false, errmsg: err.message});
             }
           };
 
           // Make a few trips through the event loop to make sure the
           // options browser is fully visible. This is a bit dodgy, but
           // we don't really have a reliable way to detect this from the
           // options page side, and synthetic click events won't work
           // until it is.
-          for (let i = 0; i < 10; i++) {
+          do {
+            browser.test.log("Waiting for the options browser to be visible...");
             await new Promise(resolve => setTimeout(resolve, 0));
-          }
-
-          synthesizeMouseAtCenter(link, {});
-        }, {once: true});
+            synthesizeMouseAtCenter(link, {});
+          } while (link.onclick !== null);
+        });
       },
     },
 
     manifest: {
       browser_action: {default_title: "test"},
       page_action: {default_title: "test"},
       permissions: ["contextMenus"],
       optional_permissions: ["bookmarks", "tabs", "webNavigation", "webRequest", "cookies"],
@@ -170,20 +173,20 @@ add_task(async function testSources() {
   extension.sendMessage("contextMenus.update");
   await extension.awaitMessage("contextMenus.update-done");
   menu = await openContextMenu("body");
   items = menu.getElementsByAttribute("label", "test user events in onClicked");
   is(items.length, 1, "Found context menu item again");
   EventUtils.synthesizeMouseAtCenter(items[0], {});
   await check("context menu in onClicked");
 
-  extension.sendMessage("openOptionsPage");
   promisePopupNotificationShown("addon-webext-permissions").then(panel => {
     panel.button.click();
   });
+  extension.sendMessage("openOptionsPage");
   await check("options page link click");
 
   await BrowserTestUtils.removeTab(gBrowser.selectedTab);
   await BrowserTestUtils.removeTab(tab);
 
   await extension.unload();
 
   registerCleanupFunction(() => CustomizableUI.reset());