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

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

Issue 1734753003: Revert of First set of WebUSB layout tests with Mojo service mocks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 | third_party/WebKit/LayoutTests/usb/mock-services.html » ('j') | 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 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. 8 // find it there. This define() also returns a promise to the module.
9 let define = (function(){ 9 function define(name, deps, factory) {
10 let moduleCache = new Map(); 10 return new Promise(resolve => {
11 11 mojo.define(name, deps, (...modules) => {
12 return function(name, deps, factory) { 12 let result = factory(...modules);
13 let promise = moduleCache.get(name); 13 resolve(result);
14 if (promise === undefined) { 14 return result;
15 // This promise must be cached as mojo.define will only call the factory 15 });
16 // function the first time the module is defined. 16 });
17 promise = new Promise(resolve => { 17 }
18 mojo.define(name, deps, (...modules) => {
19 let result = factory(...modules);
20 resolve(result);
21 return result;
22 });
23 });
24 moduleCache.set(name, promise);
25 }
26 return promise;
27 }
28 })();
29 18
30 // Returns a promise to an object that exposes common Mojo module interfaces. 19 // Returns a promise to an object that exposes common Mojo module interfaces.
31 // Additional modules to load can be specified in the |modules| parameter. The 20 // Additional modules to load can be specified in the |modules| parameter. The
32 // result will contain them, in the same order, in the |modules| field. 21 // result will contain them, in the same order, in the |modules| field.
33 function loadMojoModules(name, modules = []) { 22 function loadMojoModules(name, modules = []) {
34 return define('Mojo layout test module: ' + name, [ 23 return define('Mojo layout test module: ' + name, [
35 'mojo/public/js/core', 24 'mojo/public/js/core',
36 'mojo/public/js/router', 25 'mojo/public/js/router',
37 'mojo/public/js/support', 26 'mojo/public/js/support',
38 'content/public/renderer/service_provider', 27 'content/public/renderer/service_provider',
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 let buffer, handles; 67 let buffer, handles;
79 ({ result, buffer, handles } = mojo.core.readMessage(pipe, 0)); 68 ({ result, buffer, handles } = mojo.core.readMessage(pipe, 0));
80 if (result !== mojo.core.RESULT_OK) { 69 if (result !== mojo.core.RESULT_OK) {
81 reject(result); 70 reject(result);
82 return; 71 return;
83 } 72 }
84 resolve({ buffer, handles }); 73 resolve({ buffer, handles });
85 }); 74 });
86 }); 75 });
87 }; 76 };
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/usb/mock-services.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698