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

Side by Side Diff: ios/web/test/data/mojo_test.js

Issue 2946383002: Support new-style Mojo JS core API on IOS. (Closed)
Patch Set: . Created 3 years, 5 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 | « ios/web/test/data/mojo_test.html ('k') | ios/web/webui/crw_web_ui_manager.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This module provides the test page for WebUIMojoTest. Once the page is 5 // This module provides the test page for WebUIMojoTest. Once the page is
6 // loaded it sends "syn" message to the native code. Once page receives "ack" 6 // loaded it sends "syn" message to the native code. Once page receives "ack"
7 // from the native code, the page then sends "fin". Test succeeds only when 7 // from the native code, the page then sends "fin". Test succeeds only when
8 // "fin" is received by the native page. Refer to 8 // "fin" is received by the native page. Refer to
9 // ios/web/webui/web_ui_mojo_inttest.mm for testing code. 9 // ios/web/webui/web_ui_mojo_inttest.mm for testing code.
10 10
11 /** @return {!Promise} */ 11 var pageImpl, browserProxy;
12 function getBrowserProxy() {
13 return new Promise(function(resolve, reject) {
14 define([
15 'mojo/public/js/bindings',
16 'ios/web/test/mojo_test.mojom',
17 'content/public/renderer/frame_interfaces',
18 ], function(bindings, mojom, frameInterfaces) {
19 var pageImpl, browserProxy;
20 12
21 /** @constructor */ 13 /** @constructor */
22 function TestPageImpl() { 14 function TestPageImpl() {
23 this.binding = new bindings.Binding(mojom.TestPage, this); 15 this.binding = new mojo.Binding(TestPage, this);
24 } 16 }
25 17
26 TestPageImpl.prototype = { 18 TestPageImpl.prototype = {
27 /** @override */ 19 /** @override */
28 handleNativeMessage: function(result) { 20 handleNativeMessage: function(result) {
29 if (result.message == 'ack') { 21 if (result.message == 'ack') {
30 // Native code has replied with "ack", send "fin" to complete the 22 // Native code has replied with "ack", send "fin" to complete the
31 // test. 23 // test.
32 browserProxy.handleJsMessage('fin'); 24 browserProxy.handleJsMessage('fin');
33 } 25 }
34 }, 26 },
35 }; 27 };
36
37 browserProxy = new mojom.TestUIHandlerMojoPtr(
38 frameInterfaces.getInterface(mojom.TestUIHandlerMojo.name));
39 pageImpl = new TestPageImpl();
40
41 browserProxy.setClientPage(pageImpl.binding.createInterfacePtrAndBind());
42 resolve(browserProxy);
43 });
44 });
45 }
46 28
47 /** 29 /**
48 * @return {!Promise} Fires when DOMContentLoaded event is received. 30 * @return {!Promise} Fires when DOMContentLoaded event is received.
49 */ 31 */
50 function whenDomContentLoaded() { 32 function whenDomContentLoaded() {
51 return new Promise(function(resolve, reject) { 33 return new Promise(function(resolve, reject) {
52 document.addEventListener('DOMContentLoaded', resolve); 34 document.addEventListener('DOMContentLoaded', resolve);
53 }); 35 });
54 } 36 }
55 37
56 function main() { 38 function main() {
57 Promise.all([ 39 whenDomContentLoaded().then(function() {
58 getBrowserProxy(), whenDomContentLoaded() 40 browserProxy = new TestUIHandlerMojoPtr();
59 ]).then(function([browserProxy]) { 41 Mojo.bindInterface(TestUIHandlerMojo.name,
42 mojo.makeRequest(browserProxy).handle);
43
44 pageImpl = new TestPageImpl();
45 var pagePtr = new TestPagePtr();
46 pageImpl.binding.bind(mojo.makeRequest(pagePtr));
47 browserProxy.setClientPage(pagePtr);
48
60 // Send "syn" so native code should reply with "ack". 49 // Send "syn" so native code should reply with "ack".
61 browserProxy.handleJsMessage('syn'); 50 browserProxy.handleJsMessage('syn');
62 }); 51 });
63 } 52 }
53
64 main(); 54 main();
OLDNEW
« no previous file with comments | « ios/web/test/data/mojo_test.html ('k') | ios/web/webui/crw_web_ui_manager.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698