зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1504756 - [marionette] Add executeSoon() to run tasks on the main thread. r=ato
To be closer to other test harnesses which are using executeSoon() to run a task on the main thread, this patch adds the same method to Marionette's sync module. Differential Revision: https://phabricator.services.mozilla.com/D13659 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
679f0aa4c4
Коммит
be3136d0ab
|
@ -3,6 +3,8 @@ sync module
|
|||
|
||||
Provides an assortment of synchronisation primitives.
|
||||
|
||||
.. js:autofunction:: executeSoon
|
||||
|
||||
.. js:autoclass:: MessageManagerDestroyedPromise
|
||||
:members:
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ const {Log} = ChromeUtils.import("chrome://marionette/content/log.js", {});
|
|||
XPCOMUtils.defineLazyGetter(this, "log", Log.get);
|
||||
|
||||
this.EXPORTED_SYMBOLS = [
|
||||
"executeSoon",
|
||||
"DebounceCallback",
|
||||
"IdlePromise",
|
||||
"MessageManagerDestroyedPromise",
|
||||
|
@ -30,6 +31,21 @@ const {TYPE_ONE_SHOT, TYPE_REPEATING_SLACK} = Ci.nsITimer;
|
|||
|
||||
const PROMISE_TIMEOUT = AppConstants.DEBUG ? 4500 : 1500;
|
||||
|
||||
|
||||
/**
|
||||
* Dispatch a function to be executed on the main thread.
|
||||
*
|
||||
* @param {function} func
|
||||
* Function to be executed.
|
||||
*/
|
||||
function executeSoon(func) {
|
||||
if (typeof func != "function") {
|
||||
throw new TypeError();
|
||||
}
|
||||
|
||||
Services.tm.dispatchToMainThread(func);
|
||||
}
|
||||
|
||||
/**
|
||||
* @callback Condition
|
||||
*
|
||||
|
|
|
@ -35,6 +35,23 @@ class MockTimer {
|
|||
}
|
||||
}
|
||||
|
||||
add_test(function test_executeSoon_callback() {
|
||||
// executeSoon() is already defined for xpcshell in head.js. As such import
|
||||
// our implementation into a custom namespace.
|
||||
let sync = {};
|
||||
ChromeUtils.import("chrome://marionette/content/sync.js", sync);
|
||||
|
||||
for (let func of ["foo", null, true, [], {}]) {
|
||||
Assert.throws(() => sync.executeSoon(func), /TypeError/);
|
||||
}
|
||||
|
||||
let a;
|
||||
sync.executeSoon(() => { a = 1; });
|
||||
executeSoon(() => equal(1, a));
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_PollPromise_funcTypes() {
|
||||
for (let type of ["foo", 42, null, undefined, true, [], {}]) {
|
||||
Assert.throws(() => new PollPromise(type), /TypeError/);
|
||||
|
|
|
@ -10,14 +10,17 @@ const CC = Components.Constructor;
|
|||
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/EventEmitter.jsm");
|
||||
const {StreamUtils} =
|
||||
ChromeUtils.import("chrome://marionette/content/stream-utils.js", {});
|
||||
const {Packet, JSONPacket, BulkPacket} =
|
||||
ChromeUtils.import("chrome://marionette/content/packets.js", {});
|
||||
|
||||
const executeSoon = function(func) {
|
||||
Services.tm.dispatchToMainThread(func);
|
||||
};
|
||||
const {
|
||||
StreamUtils,
|
||||
} = ChromeUtils.import("chrome://marionette/content/stream-utils.js", {});
|
||||
const {
|
||||
BulkPacket,
|
||||
JSONPacket,
|
||||
Packet,
|
||||
} = ChromeUtils.import("chrome://marionette/content/packets.js", {});
|
||||
const {
|
||||
executeSoon,
|
||||
} = ChromeUtils.import("chrome://marionette/content/sync.js", {});
|
||||
|
||||
const flags = {wantVerbose: false, wantLogging: false};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче