Bug 1287007 - Fix timing issue in browser_ext_contextMenus.js r=billm
authorRob Wu <rob@robwu.nl>
Wed, 12 Oct 2016 01:10:33 +0200
changeset 428732 434598e8b200a661b6a4dafb667ad9299ed92396
parent 428731 424e3fa0b282b076767bbf13d61db59f1b03acae
child 428733 f10221d238ac3f5bb4e0f2a00591291d4ee4cee9
push id33405
push userbcampen@mozilla.com
push dateMon, 24 Oct 2016 15:32:53 +0000
reviewersbillm
bugs1287007
milestone52.0a1
Bug 1287007 - Fix timing issue in browser_ext_contextMenus.js r=billm MozReview-Commit-ID: D7No2zFUWjf
browser/components/extensions/test/browser/browser_ext_contextMenus.js
--- a/browser/components/extensions/test/browser/browser_ext_contextMenus.js
+++ b/browser/components/extensions/test/browser/browser_ext_contextMenus.js
@@ -269,33 +269,48 @@ add_task(function* testRemoveAllWithTwoE
   const manifest = {permissions: ["contextMenus"]};
 
   const first = ExtensionTestUtils.loadExtension({manifest, background() {
     browser.contextMenus.create({title: "alpha", contexts: ["all"]});
 
     browser.contextMenus.onClicked.addListener(() => {
       browser.contextMenus.removeAll();
     });
-    browser.test.onMessage.addListener(() => {
+    browser.test.onMessage.addListener(msg => {
+      if (msg == "ping") {
+        browser.test.sendMessage("pong-alpha");
+        return;
+      }
       browser.contextMenus.create({title: "gamma", contexts: ["all"]});
     });
   }});
 
   const second = ExtensionTestUtils.loadExtension({manifest, background() {
     browser.contextMenus.create({title: "beta", contexts: ["all"]});
 
     browser.contextMenus.onClicked.addListener(() => {
       browser.contextMenus.removeAll();
     });
+
+    browser.test.onMessage.addListener(() => {
+      browser.test.sendMessage("pong-beta");
+    });
   }});
 
   yield first.startup();
   yield second.startup();
 
   function* confirmMenuItems(...items) {
+    // Round-trip to extension to make sure that the context menu state has been
+    // updated by the async contextMenus.create / contextMenus.removeAll calls.
+    first.sendMessage("ping");
+    second.sendMessage("ping");
+    yield first.awaitMessage("pong-alpha");
+    yield second.awaitMessage("pong-beta");
+
     const menu = yield openContextMenu();
     for (const id of ["alpha", "beta", "gamma"]) {
       const expected = items.includes(id);
       const found = menu.getElementsByAttribute("label", id);
       is(found.length, expected, `menu item ${id} ${expected ? "" : "not "}found`);
     }
     // Return the first menu item, we need to click it.
     return menu.getElementsByAttribute("label", items[0])[0];