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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * mojo-helpers contains extensions to testharness.js useful for consuming 2 * mojo-helpers contains extensions to testharness.js useful for consuming
3 * and mocking Mojo services directly within test code. 3 * and mocking Mojo services directly within test code.
4 */ 4 */
5 'use strict'; 5 'use strict';
6 6
7 // Fix up the global window.define, since all baked-in Mojo modules expect to
8 // find it there. This define() also returns a promise to the module.
9 function define(name, deps, factory) {
10 return new Promise(resolve => {
11 mojo.define(name, deps, (...modules) => {
12 let result = factory(...modules);
13 resolve(result);
14 return result;
15 });
16 });
17 }
18
19 // Returns a promise to an object that exposes common Mojo module interfaces.
20 // Additional modules to load can be specified in the |modules| parameter. The
21 // result will contain them, in the same order, in the |modules| field.
22 function loadMojoModules(name, modules = []) {
23 return define('Mojo layout test module: ' + name, [
24 'mojo/public/js/core',
25 'mojo/public/js/router',
26 'mojo/public/js/support',
27 'content/public/renderer/service_provider',
28 ].concat(modules), (core, router, support, serviceProvider, ...rest) => {
29 return {
30 core: core,
31 router: router,
32 support: support,
33
34 // |serviceProvider| is a bit of a misnomer. It should probably be
35 // called |serviceRegistry|, so let's call it that here.
36 serviceRegistry: serviceProvider,
37
38 modules: rest,
39 };
40 });
41 }
42
7 // Runs a promise_test which depends on the Mojo system API modules available to 43 // Runs a promise_test which depends on the Mojo system API modules available to
8 // all layout tests. The test implementation function is called with an Object 44 // all layout tests. The test implementation function is called with an Object
9 // that exposes common Mojo module interfaces. 45 // that exposes common Mojo module interfaces.
10 function mojo_test(func, name, properties) { 46 function mojo_test(func, name, properties) {
11 // Fix up the global window.define, since all baked-in Mojo modules expect to 47 promise_test(() => loadMojoModules(name).then(func), name, properties);
12 // find it there.
13 window.define = mojo.define;
14
15 promise_test(() => {
16 return new Promise((resolve, reject) => {
17 define('Mojo layout test module: ' + name, [
18 'mojo/public/js/core',
19 'mojo/public/js/router',
20 'content/public/renderer/service_provider',
21 ], (core, router, serviceProvider) => {
22 try {
23 resolve(func({
24 core: core,
25 router: router,
26
27 // |serviceProvider| is a bit of a misnomer. It should probably be
28 // called |serviceRegistry|, so let's call it that here.
29 serviceRegistry: serviceProvider,
30 }));
31 } catch (e) {
32 reject(e);
33 }
34 });
35 });
36 }, name, properties);
37 } 48 }
38 49
39 // Polls aggressively for a message to become available on a pipe. 50 // Waits for a message to become available on a pipe.
40 function mojo_wait_for_incoming_message(mojo, pipe) { 51 function mojo_wait_for_incoming_message(mojo, pipe) {
41 return new Promise((resolve, reject) => { 52 return new Promise((resolve, reject) => {
42 let wait = () => { 53 mojo.support.asyncWait(pipe, mojo.core.HANDLE_SIGNAL_READABLE, result => {
43 let result = mojo.core.readMessage(pipe, 0); 54 if (result != mojo.core.RESULT_OK) {
44 if (result.result === mojo.core.RESULT_SHOULD_WAIT) { 55 reject(result);
45 setTimeout(wait);
46 return; 56 return;
47 } 57 }
48 58 let buffer, handles;
49 if (result.result !== mojo.core.RESULT_OK) { 59 ({ result, buffer, handles } = mojo.core.readMessage(pipe, 0));
50 reject(result.result); 60 if (result !== mojo.core.RESULT_OK) {
61 reject(result);
51 return; 62 return;
52 } 63 }
53 64 resolve({ buffer, handles });
54 resolve({ buffer: result.buffer, handles: result.handles }); 65 });
55 };
56
57 wait();
58 }); 66 });
59 }; 67 };
OLDNEW
« 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