Bug 1151082 - RequestSyncAPI - avoid infinite loop when processing pending messages. r=ehsan, a=bajaj
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 09 Apr 2015 19:59:39 +0100
changeset 238147 db82a837c490d2698cd4400eaf38e1c00fa960ad
parent 238146 dd394cdc49762f7e2c754fc8ba060befb647f63c
child 238148 0697e47968a2e2ec94c7732c6769bb8947879585
push id491
push userryanvm@gmail.com
push dateWed, 15 Apr 2015 02:40:07 +0000
treeherdermozilla-b2g37_v2_2@7fa668810d43 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, bajaj
bugs1151082
milestone37.0
Bug 1151082 - RequestSyncAPI - avoid infinite loop when processing pending messages. r=ehsan, a=bajaj
dom/requestsync/RequestSyncService.jsm
dom/requestsync/tests/mochitest.ini
dom/requestsync/tests/test_bug1151082.html
--- a/dom/requestsync/RequestSyncService.jsm
+++ b/dom/requestsync/RequestSyncService.jsm
@@ -809,17 +809,17 @@ this.RequestSyncService = {
   },
 
   pendingOperationDone: function() {
     debug('pendingOperationDone');
 
     this._pendingOperation = false;
 
     // managing the pending messages now that the initialization is completed.
-    while (this._pendingMessages.length) {
+    while (this._pendingMessages.length && !this._pendingOperation) {
       this.receiveMessage(this._pendingMessages.shift());
     }
   },
 
   // This method creates a transaction and runs callbacks. Plus it manages the
   // pending operations system.
   dbTxn: function(aType, aCb, aSuccessCb, aErrorCb) {
     debug('dbTxn');
--- a/dom/requestsync/tests/mochitest.ini
+++ b/dom/requestsync/tests/mochitest.ini
@@ -12,8 +12,9 @@ support-files =
 [test_basic.html]
 [test_basic_app.html]
 run-if = buildapp != 'b2g'
 [test_wakeUp.html]
 run-if = buildapp == 'b2g' && toolkit == 'gonk'
 [test_runNow.html]
 run-if = buildapp == 'b2g' && toolkit == 'gonk'
 [test_promise.html]
+[test_bug1151082.html]
new file mode 100644
--- /dev/null
+++ b/dom/requestsync/tests/test_bug1151082.html
@@ -0,0 +1,79 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Test for RequestSync bug 1151082</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="common_basic.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+  <script type="application/javascript;version=1.7">
+
+
+  var tests = [
+    function() {
+      SpecialPowers.pushPrefEnv({"set": [["dom.requestSync.enabled", true],
+                                         ["dom.requestSync.minInterval", 1],
+                                         ["dom.ignore_webidl_scope_checks", true]]}, runTests);
+    },
+
+    function() {
+      SpecialPowers.pushPermissions(
+        [{ "type": "requestsync-manager", "allow": 1, "context": document } ], runTests);
+    },
+
+    function() {
+      if (SpecialPowers.isMainProcess()) {
+        SpecialPowers.Cu.import("resource://gre/modules/RequestSyncService.jsm");
+      }
+      runTests();
+    },
+
+    function() {
+      counter = 2;
+      function registerCb() {
+        if (!--counter) {
+          ok(true, "All the registrations are done.");
+          runTests();
+        }
+      }
+
+      navigator.sync.register('foobar', { minInterval: 5, wakeUpPage:'/' }).then(registerCb, genericError);
+      navigator.sync.register('barfoo', { minInterval: 5, wakeUpPage:'/' }).then(registerCb, genericError);
+    },
+
+    function() {
+      counter = 2;
+      function unregisterCb() {
+        if (!--counter) {
+          ok(true, "All the unregistrations are done.");
+          runTests();
+        }
+      }
+
+      navigator.sync.unregister('foobar').then(unregisterCb, genericError);
+      navigator.sync.unregister('barfoo').then(unregisterCb, genericError);
+    }
+  ];
+
+  function runTests() {
+    if (!tests.length) {
+      finish();
+      return;
+    }
+
+    var test = tests.shift();
+    test();
+  }
+
+  function finish() {
+    SimpleTest.finish();
+  }
+
+  SimpleTest.waitForExplicitFinish();
+  runTests();
+
+  </script>
+</body>
+</html>