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

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

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

Powered by Google App Engine
This is Rietveld 408576698