mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 20:35:50 +00:00
Bug 934066 - Add a simple parent/child synchronization mechanism for xpcshell tests. r=ted
This commit is contained in:
parent
26c0110ca6
commit
2de3a805b5
@ -32,6 +32,7 @@ var provider = {
|
||||
this._isHigh = enable;
|
||||
if (enable) {
|
||||
this._seenHigh = true;
|
||||
do_execute_soon(stop_high_accuracy_watch);
|
||||
}
|
||||
},
|
||||
_isHigh: false,
|
||||
@ -58,6 +59,9 @@ function errorCallback()
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
var geolocation;
|
||||
var watchID2;
|
||||
|
||||
function run_test()
|
||||
{
|
||||
if (runningInParent) {
|
||||
@ -78,18 +82,21 @@ function run_test()
|
||||
prefs.setBoolPref("geo.wifi.scan", false);
|
||||
}
|
||||
|
||||
let geolocation = Cc["@mozilla.org/geolocation;1"].createInstance(Ci.nsISupports);
|
||||
|
||||
do_test_pending();
|
||||
|
||||
geolocation = Cc["@mozilla.org/geolocation;1"].createInstance(Ci.nsISupports);
|
||||
let watchID1 = geolocation.watchPosition(successCallback, errorCallback);
|
||||
let watchID2 = geolocation.watchPosition(successCallback, errorCallback,
|
||||
{enableHighAccuracy: true});
|
||||
watchID2 = geolocation.watchPosition(successCallback, errorCallback,
|
||||
{enableHighAccuracy: true});
|
||||
|
||||
do_timeout(5000, function() {
|
||||
if (!runningInParent) {
|
||||
do_await_remote_message('high_acc_enabled', stop_high_accuracy_watch);
|
||||
}
|
||||
}
|
||||
|
||||
function stop_high_accuracy_watch() {
|
||||
geolocation.clearWatch(watchID2);
|
||||
do_timeout(1000, check_results);
|
||||
});
|
||||
check_results();
|
||||
}
|
||||
|
||||
function check_results()
|
||||
|
@ -32,6 +32,7 @@ var provider = {
|
||||
this._isHigh = enable;
|
||||
if (enable) {
|
||||
this._seenHigh = true;
|
||||
do_send_remote_message('high_acc_enabled');
|
||||
}
|
||||
},
|
||||
_isHigh: false,
|
||||
|
@ -1237,6 +1237,48 @@ function run_test_in_child(testFile, optionalCallback)
|
||||
callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a given function as soon as a particular cross-process message is received.
|
||||
* Must be paired with do_send_remote_message or equivalent ProcessMessageManager calls.
|
||||
*/
|
||||
function do_await_remote_message(name, callback)
|
||||
{
|
||||
var listener = {
|
||||
receiveMessage: function(message) {
|
||||
if (message.name == name) {
|
||||
mm.removeMessageListener(name, listener);
|
||||
callback();
|
||||
do_test_finished();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var mm;
|
||||
if (runningInParent) {
|
||||
mm = Cc["@mozilla.org/parentprocessmessagemanager;1"].getService(Ci.nsIMessageBroadcaster);
|
||||
} else {
|
||||
mm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsISyncMessageSender);
|
||||
}
|
||||
do_test_pending();
|
||||
mm.addMessageListener(name, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously send a message to all remote processes. Pairs with do_await_remote_message
|
||||
* or equivalent ProcessMessageManager listeners.
|
||||
*/
|
||||
function do_send_remote_message(name) {
|
||||
var mm;
|
||||
var sender;
|
||||
if (runningInParent) {
|
||||
mm = Cc["@mozilla.org/parentprocessmessagemanager;1"].getService(Ci.nsIMessageBroadcaster);
|
||||
sender = 'broadcastAsyncMessage';
|
||||
} else {
|
||||
mm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsISyncMessageSender);
|
||||
sender = 'sendAsyncMessage';
|
||||
}
|
||||
mm[sender](name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a test function to the list of tests that are to be run asynchronously.
|
||||
|
Loading…
Reference in New Issue
Block a user