Bug 1224893: [webext] Queue unexpected messages for subsequent calls to awaitMessage, follow-up. r=me r=billm a=lizzard
authorKris Maglione <maglione.k@gmail.com>
Tue, 17 Nov 2015 14:04:53 -0800
changeset 305629 7d2f0faddb3f07b574471c45b2c13ec18e37bd22
parent 305628 837e564f36973f5bf2d93e2e5a2c1b1423bcbecd
child 305630 5c87a2e6268e68311274069a4a82af03ab011574
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme, billm, lizzard
bugs1224893
milestone44.0a2
Bug 1224893: [webext] Queue unexpected messages for subsequent calls to awaitMessage, follow-up. r=me r=billm a=lizzard
testing/mochitest/tests/SimpleTest/ExtensionTestUtils.js
--- a/testing/mochitest/tests/SimpleTest/ExtensionTestUtils.js
+++ b/testing/mochitest/tests/SimpleTest/ExtensionTestUtils.js
@@ -15,26 +15,28 @@ ExtensionTestUtils.loadExtension = funct
       SimpleTest.is(messageQueue.length, 0, "message queue is empty");
     }
     if (messageAwaiter.size) {
       SimpleTest.is(messageAwaiter.size, 0, "no tasks awaiting on messages");
     }
   });
 
   function checkMessages() {
-    if (messageQueue.length) {
+    while (messageQueue.length) {
       let [msg, ...args] = messageQueue[0];
 
       let listener = messageAwaiter.get(msg);
-      if (listener) {
-        messageQueue.shift();
-        messageAwaiter.delete(msg);
+      if (!listener) {
+        break;
+      }
 
-        listener.resolve(...args);
-      }
+      messageQueue.shift();
+      messageAwaiter.delete(msg);
+
+      listener.resolve(...args);
     }
   }
 
   function checkDuplicateListeners(msg) {
     if (messageHandler.has(msg) || messageAwaiter.has(msg)) {
       throw new Error("only one message handler allowed");
     }
   }