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

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

Issue 2643063002: Refactor Blink's ServiceConnector and add ability to mock in layout tests (Closed)
Patch Set: fix compile Created 3 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
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 let define = (function(){
10 let moduleCache = new Map(); 10 let moduleCache = new Map();
11 11
12 return function(name, deps, factory) { 12 return function(name, deps, factory) {
13 let promise = moduleCache.get(name); 13 let promise = moduleCache.get(name);
14 if (promise === undefined) { 14 if (promise === undefined) {
15 // This promise must be cached as gin.define will only call the factory 15 // This promise must be cached as gin.define will only call the factory
16 // function the first time the module is defined. 16 // function the first time the module is defined.
17 promise = new Promise(resolve => { 17 promise = new Promise(resolve => {
18 gin.define(name, deps, (...modules) => { 18 gin.define(name, deps, (...modules) => {
19 let result = factory(...modules); 19 let result = factory(...modules);
20 resolve(result); 20 resolve(result);
21 return result; 21 return result;
22 }); 22 });
23 }); 23 });
24 moduleCache.set(name, promise); 24 moduleCache.set(name, promise);
25 } 25 }
26 return promise; 26 return promise;
27 } 27 }
28 })(); 28 })();
29 29
30 define('Mojo Helpers', [ 30 define(
31 'mojo/public/js/core', 31 'Mojo Helpers',
32 'mojo/public/js/router', 32 [
33 'mojo/public/js/support', 33 'mojo/public/js/core',
34 'content/public/renderer/frame_interfaces', 34 'mojo/public/js/router',
35 'content/public/renderer/interfaces', 35 'mojo/public/js/support',
36 'content/shell/renderer/layout_test/frame_interface_registry', 36 'content/public/renderer/connector',
37 'content/shell/renderer/layout_test/interface_registry', 37 'content/public/renderer/frame_interfaces',
38 ], (core, router, support, frameInterfaces, interfaces, frameInterfaceRegistry, 38 'content/public/renderer/interfaces',
39 interfaceRegistry) => { 39 'content/shell/renderer/layout_test/frame_interface_registry',
40 let tearDown = () => { 40 'content/shell/renderer/layout_test/interface_registry',
41 frameInterfaces.clearInterfaceOverridesForTesting(); 41 ],
42 interfaces.clearInterfaceOverridesForTesting(); 42 (core, router, support, connector, frameInterfaces, interfaces,
43 }; 43 frameInterfaceRegistry, interfaceRegistry) => {
44 addEventListener('unload', tearDown); 44 let tearDown = () => {
45 if (window.add_completion_callback) 45 connector.clearInterfaceOverridesForTesting();
dcheng 2017/03/21 18:56:18 Do we have any documentation about the differences
Ken Rockot(use gerrit already) 2017/03/23 04:56:04 No, they're all different ways for the client (bli
46 add_completion_callback(tearDown); 46 frameInterfaces.clearInterfaceOverridesForTesting();
47 interfaces.clearInterfaceOverridesForTesting();
48 };
49 addEventListener('unload', tearDown);
50 if (window.add_completion_callback)
51 add_completion_callback(tearDown);
47 52
48 return { 53 return {
49 core, 54 core,
50 router, 55 router,
51 support, 56 support,
52 frameInterfaces, 57 connector,
53 frameInterfaceRegistry, 58 frameInterfaces,
54 interfaces, 59 frameInterfaceRegistry,
55 interfaceRegistry, 60 interfaces,
56 }; 61 interfaceRegistry,
57 }); 62 };
63 });
58 64
59 // Returns a promise to an object that exposes common Mojo module interfaces. 65 // Returns a promise to an object that exposes common Mojo module interfaces.
60 // Additional modules to load can be specified in the |modules| parameter. The 66 // Additional modules to load can be specified in the |modules| parameter. The
61 // result will contain them, in the same order, in the |modules| field. 67 // result will contain them, in the same order, in the |modules| field.
62 function loadMojoModules(name, modules = []) { 68 function loadMojoModules(name, modules = []) {
63 return define('Mojo modules: ' + name, 69 return define('Mojo modules: ' + name,
64 [ 'Mojo Helpers' ].concat(modules), 70 [ 'Mojo Helpers' ].concat(modules),
65 (mojo, ...rest) => { 71 (mojo, ...rest) => {
66 mojo.modules = rest 72 mojo.modules = rest
67 return mojo; 73 return mojo;
(...skipping 20 matching lines...) Expand all
88 let buffer, handles; 94 let buffer, handles;
89 ({ result, buffer, handles } = mojo.core.readMessage(pipe, 0)); 95 ({ result, buffer, handles } = mojo.core.readMessage(pipe, 0));
90 if (result !== mojo.core.RESULT_OK) { 96 if (result !== mojo.core.RESULT_OK) {
91 reject(result); 97 reject(result);
92 return; 98 return;
93 } 99 }
94 resolve({ buffer, handles }); 100 resolve({ buffer, handles });
95 }); 101 });
96 }); 102 });
97 }; 103 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698