Bug 1151082 - RequestSyncAPI - avoid infinite loop when processing pending messages, r=ehsan

This commit is contained in:
Andrea Marchesini 2015-04-09 19:59:39 +01:00
parent ad75daea37
commit 7fc63c73d6
3 changed files with 81 additions and 1 deletions

View File

@ -814,7 +814,7 @@ this.RequestSyncService = {
this._pendingOperation = false; this._pendingOperation = false;
// managing the pending messages now that the initialization is completed. // 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.receiveMessage(this._pendingMessages.shift());
} }
}, },

View File

@ -17,3 +17,4 @@ skip-if = !(buildapp == 'b2g' && toolkit == 'gonk')
[test_runNow.html] [test_runNow.html]
run-if = buildapp == 'b2g' && toolkit == 'gonk' run-if = buildapp == 'b2g' && toolkit == 'gonk'
[test_promise.html] [test_promise.html]
[test_bug1151082.html]

View File

@ -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>