OLD | NEW |
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 /** @return {!Promise} */ |
12 function getBrowserProxy() { | 12 function getBrowserProxy() { |
13 return new Promise(function(resolve, reject) { | 13 return new Promise(function(resolve, reject) { |
14 define([ | 14 define([ |
15 'mojo/public/js/bindings', | 15 'mojo/public/js/bindings', |
| 16 'mojo/public/js/connection', |
16 'ios/web/test/mojo_test.mojom', | 17 'ios/web/test/mojo_test.mojom', |
17 'content/public/renderer/frame_interfaces', | 18 'content/public/renderer/frame_interfaces', |
18 ], function(bindings, mojom, frameInterfaces) { | 19 ], function(bindings, connection, mojom, frameInterfaces) { |
19 var pageImpl, browserProxy; | 20 var pageImpl, browserProxy; |
20 | 21 |
21 /** @constructor */ | 22 /** @constructor */ |
22 function TestPageImpl() { | 23 function TestPageImpl() { |
23 this.binding = new bindings.Binding(mojom.TestPage, this); | 24 this.binding = new bindings.Binding(mojom.TestPage, this); |
24 } | 25 } |
25 | 26 |
26 TestPageImpl.prototype = { | 27 TestPageImpl.prototype = { |
27 /** @override */ | 28 /** @override */ |
28 handleNativeMessage: function(result) { | 29 handleNativeMessage: function(result) { |
29 if (result.message == 'ack') { | 30 if (result.message == 'ack') { |
30 // Native code has replied with "ack", send "fin" to complete the | 31 // Native code has replied with "ack", send "fin" to complete the |
31 // test. | 32 // test. |
32 browserProxy.handleJsMessage('fin'); | 33 browserProxy.handleJsMessage('fin'); |
33 } | 34 } |
34 }, | 35 }, |
35 }; | 36 }; |
36 | 37 |
37 browserProxy = new mojom.TestUIHandlerMojoPtr( | 38 browserProxy = connection.bindHandleToProxy( |
38 frameInterfaces.getInterface(mojom.TestUIHandlerMojo.name)); | 39 frameInterfaces.getInterface(mojom.TestUIHandlerMojo.name), |
| 40 mojom.TestUIHandlerMojo); |
39 pageImpl = new TestPageImpl(); | 41 pageImpl = new TestPageImpl(); |
40 | 42 |
41 browserProxy.setClientPage(pageImpl.binding.createInterfacePtrAndBind()); | 43 browserProxy.setClientPage(pageImpl.binding.createInterfacePtrAndBind()); |
42 resolve(browserProxy); | 44 resolve(browserProxy); |
43 }); | 45 }); |
44 }); | 46 }); |
45 } | 47 } |
46 | 48 |
47 /** | 49 /** |
48 * @return {!Promise} Fires when DOMContentLoaded event is received. | 50 * @return {!Promise} Fires when DOMContentLoaded event is received. |
49 */ | 51 */ |
50 function whenDomContentLoaded() { | 52 function whenDomContentLoaded() { |
51 return new Promise(function(resolve, reject) { | 53 return new Promise(function(resolve, reject) { |
52 document.addEventListener('DOMContentLoaded', resolve); | 54 document.addEventListener('DOMContentLoaded', resolve); |
53 }); | 55 }); |
54 } | 56 } |
55 | 57 |
56 function main() { | 58 function main() { |
57 Promise.all([ | 59 Promise.all([ |
58 getBrowserProxy(), whenDomContentLoaded() | 60 getBrowserProxy(), whenDomContentLoaded() |
59 ]).then(function([browserProxy]) { | 61 ]).then(function([browserProxy]) { |
60 // Send "syn" so native code should reply with "ack". | 62 // Send "syn" so native code should reply with "ack". |
61 browserProxy.handleJsMessage('syn'); | 63 browserProxy.handleJsMessage('syn'); |
62 }); | 64 }); |
63 } | 65 } |
64 main(); | 66 main(); |
OLD | NEW |