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

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

Issue 2405093003: [WIP] Mojo native bindings interface.
Patch Set: cleanup 2 Created 4 years, 2 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();
(...skipping 12 matching lines...) Expand all
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('Mojo Helpers', [
31 'mojo/public/js/core', 31 'mojo/public/js/core',
32 'mojo/public/js/router', 32 'mojo/public/js/router',
33 'mojo/public/js/support',
34 'content/public/renderer/frame_interfaces', 33 'content/public/renderer/frame_interfaces',
35 'content/public/renderer/interfaces', 34 'content/public/renderer/interfaces',
36 'content/shell/renderer/layout_test/frame_interface_registry', 35 'content/shell/renderer/layout_test/frame_interface_registry',
37 'content/shell/renderer/layout_test/interface_registry', 36 'content/shell/renderer/layout_test/interface_registry',
38 ], (core, router, support, frameInterfaces, interfaces, frameInterfaceRegistry, 37 ], (core, router, frameInterfaces, interfaces, frameInterfaceRegistry,
39 interfaceRegistry) => { 38 interfaceRegistry) => {
40 let tearDown = () => { 39 let tearDown = () => {
41 frameInterfaces.clearInterfaceOverridesForTesting(); 40 frameInterfaces.clearInterfaceOverridesForTesting();
42 interfaces.clearInterfaceOverridesForTesting(); 41 interfaces.clearInterfaceOverridesForTesting();
43 }; 42 };
44 addEventListener('unload', tearDown); 43 addEventListener('unload', tearDown);
45 if (window.add_completion_callback) 44 if (window.add_completion_callback)
46 add_completion_callback(tearDown); 45 add_completion_callback(tearDown);
47 46
48 return { 47 return {
49 core, 48 core,
50 router, 49 router,
51 support,
52 frameInterfaces, 50 frameInterfaces,
53 frameInterfaceRegistry, 51 frameInterfaceRegistry,
54 interfaces, 52 interfaces,
55 interfaceRegistry, 53 interfaceRegistry,
56 }; 54 };
57 }); 55 });
58 56
59 // Returns a promise to an object that exposes common Mojo module interfaces. 57 // 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 58 // 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. 59 // result will contain them, in the same order, in the |modules| field.
(...skipping 11 matching lines...) Expand all
73 // that exposes common Mojo module interfaces. 71 // that exposes common Mojo module interfaces.
74 function mojo_test(func, name, properties) { 72 function mojo_test(func, name, properties) {
75 promise_test(() => loadMojoModules(name).then(mojo => { 73 promise_test(() => loadMojoModules(name).then(mojo => {
76 return Promise.resolve(func(mojo)); 74 return Promise.resolve(func(mojo));
77 }), name, properties); 75 }), name, properties);
78 } 76 }
79 77
80 // Waits for a message to become available on a pipe. 78 // Waits for a message to become available on a pipe.
81 function mojo_wait_for_incoming_message(mojo, pipe) { 79 function mojo_wait_for_incoming_message(mojo, pipe) {
82 return new Promise((resolve, reject) => { 80 return new Promise((resolve, reject) => {
83 mojo.support.asyncWait(pipe, mojo.core.HANDLE_SIGNAL_READABLE, result => { 81 let watcher = mojo.core.watch(pipe, mojo.core.HANDLE_SIGNAL_READABLE, result => {
82 watcher.cancel();
84 if (result != mojo.core.RESULT_OK) { 83 if (result != mojo.core.RESULT_OK) {
85 reject(result); 84 reject(result);
86 return; 85 return;
87 } 86 }
88 let buffer, handles; 87 let buffer, handles;
89 ({ result, buffer, handles } = mojo.core.readMessage(pipe, 0)); 88 ({ result, buffer, handles } = mojo.core.readMessage(pipe, 0));
90 if (result !== mojo.core.RESULT_OK) { 89 if (result !== mojo.core.RESULT_OK) {
91 reject(result); 90 reject(result);
92 return; 91 return;
93 } 92 }
94 resolve({ buffer, handles }); 93 resolve({ buffer, handles });
95 }); 94 });
96 }); 95 });
97 }; 96 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698