Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Unified Diff: third_party/WebKit/LayoutTests/resources/mojo-helpers.js

Issue 1698933002: Change mojo-helpers.js to support other test harnesses. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@service-registry-js-wrapper
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/resources/mojo-helpers.js
diff --git a/third_party/WebKit/LayoutTests/resources/mojo-helpers.js b/third_party/WebKit/LayoutTests/resources/mojo-helpers.js
index 625d7fdfe46e06c320489bf8f8267644dfb9c658..bad8c7e590b39dbe9eb15604665b85d96baff64e 100644
--- a/third_party/WebKit/LayoutTests/resources/mojo-helpers.js
+++ b/third_party/WebKit/LayoutTests/resources/mojo-helpers.js
@@ -4,56 +4,64 @@
*/
'use strict';
+// Fix up the global window.define, since all baked-in Mojo modules expect to
+// find it there. This define() also returns a promise to the module.
+function define(name, deps, factory) {
+ return new Promise(resolve => {
+ mojo.define(name, deps, (...modules) => {
+ let result = factory(...modules);
+ resolve(result);
+ return result;
+ });
+ });
+}
+
+// Returns a promise to an object that exposes common Mojo module interfaces.
+// Additional modules to load can be specified in the |modules| parameter. The
+// result will contain them, in the same order, in the |modules| field.
+function loadMojoModules(name, modules = []) {
+ return define('Mojo layout test module: ' + name, [
+ 'mojo/public/js/core',
+ 'mojo/public/js/router',
+ 'mojo/public/js/support',
+ 'content/public/renderer/service_provider',
+ ].concat(modules), (core, router, support, serviceProvider, ...rest) => {
+ return {
+ core: core,
+ router: router,
+ support: support,
+
+ // |serviceProvider| is a bit of a misnomer. It should probably be
+ // called |serviceRegistry|, so let's call it that here.
+ serviceRegistry: serviceProvider,
+
+ modules: rest,
+ };
+ });
+}
+
// Runs a promise_test which depends on the Mojo system API modules available to
// all layout tests. The test implementation function is called with an Object
// that exposes common Mojo module interfaces.
function mojo_test(func, name, properties) {
- // Fix up the global window.define, since all baked-in Mojo modules expect to
- // find it there.
- window.define = mojo.define;
-
- promise_test(() => {
- return new Promise((resolve, reject) => {
- define('Mojo layout test module: ' + name, [
- 'mojo/public/js/core',
- 'mojo/public/js/router',
- 'content/public/renderer/service_provider',
- ], (core, router, serviceProvider) => {
- try {
- resolve(func({
- core: core,
- router: router,
-
- // |serviceProvider| is a bit of a misnomer. It should probably be
- // called |serviceRegistry|, so let's call it that here.
- serviceRegistry: serviceProvider,
- }));
- } catch (e) {
- reject(e);
- }
- });
- });
- }, name, properties);
+ promise_test(() => loadMojoModules(name).then(func), name, properties);
}
-// Polls aggressively for a message to become available on a pipe.
+// Waits for a message to become available on a pipe.
function mojo_wait_for_incoming_message(mojo, pipe) {
return new Promise((resolve, reject) => {
- let wait = () => {
- let result = mojo.core.readMessage(pipe, 0);
- if (result.result === mojo.core.RESULT_SHOULD_WAIT) {
- setTimeout(wait);
+ mojo.support.asyncWait(pipe, mojo.core.HANDLE_SIGNAL_READABLE, result => {
+ if (result != mojo.core.RESULT_OK) {
+ reject(result);
return;
}
-
- if (result.result !== mojo.core.RESULT_OK) {
- reject(result.result);
+ let buffer, handles;
+ ({ result, buffer, handles } = mojo.core.readMessage(pipe, 0));
+ if (result !== mojo.core.RESULT_OK) {
+ reject(result);
return;
}
-
- resolve({ buffer: result.buffer, handles: result.handles });
- };
-
- wait();
+ resolve({ buffer, handles });
+ });
});
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698