Bug 1151082 - RequestSyncAPI - avoid infinite loop when processing pending messages, r=ehsan
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 09 Apr 2015 19:59:39 +0100
changeset 238503 0097fbcadabc9b0ce5a2f167a2e7cca633013681
parent 238502 38291788a6f41b06a75d681af2b11ad2814223ef
child 238504 89f9815da675849f839d27227dbde669e249e1ba
push id58233
push useramarchesini@mozilla.com
push dateFri, 10 Apr 2015 08:43:55 +0000
treeherdermozilla-inbound@0097fbcadabc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1151082
milestone40.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 1151082 - RequestSyncAPI - avoid infinite loop when processing pending messages, r=ehsan
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]
 skip-if = buildapp == 'b2g'
 [test_wakeUp.html]
 skip-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>