| 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/connection', | 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(connection, 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() { |
| 24 this.binding = new bindings.Binding(mojom.TestPage, this); |
| 25 } |
| 23 | 26 |
| 24 TestPageImpl.prototype = { | 27 TestPageImpl.prototype = { |
| 25 __proto__: mojom.TestPage.stubClass.prototype, | |
| 26 | |
| 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 = connection.bindHandleToProxy( | 38 browserProxy = connection.bindHandleToProxy( |
| 38 frameInterfaces.getInterface(mojom.TestUIHandlerMojo.name), | 39 frameInterfaces.getInterface(mojom.TestUIHandlerMojo.name), |
| 39 mojom.TestUIHandlerMojo); | 40 mojom.TestUIHandlerMojo); |
| 40 pageImpl = new TestPageImpl(); | 41 pageImpl = new TestPageImpl(); |
| 41 | 42 |
| 42 browserProxy.setClientPage(connection.bindStubDerivedImpl(pageImpl)); | 43 browserProxy.setClientPage(pageImpl.binding.createInterfacePtrAndBind()); |
| 43 resolve(browserProxy); | 44 resolve(browserProxy); |
| 44 }); | 45 }); |
| 45 }); | 46 }); |
| 46 } | 47 } |
| 47 | 48 |
| 48 /** | 49 /** |
| 49 * @return {!Promise} Fires when DOMContentLoaded event is received. | 50 * @return {!Promise} Fires when DOMContentLoaded event is received. |
| 50 */ | 51 */ |
| 51 function whenDomContentLoaded() { | 52 function whenDomContentLoaded() { |
| 52 return new Promise(function(resolve, reject) { | 53 return new Promise(function(resolve, reject) { |
| 53 document.addEventListener('DOMContentLoaded', resolve); | 54 document.addEventListener('DOMContentLoaded', resolve); |
| 54 }); | 55 }); |
| 55 } | 56 } |
| 56 | 57 |
| 57 function main() { | 58 function main() { |
| 58 Promise.all([ | 59 Promise.all([ |
| 59 getBrowserProxy(), whenDomContentLoaded() | 60 getBrowserProxy(), whenDomContentLoaded() |
| 60 ]).then(function([browserProxy]) { | 61 ]).then(function([browserProxy]) { |
| 61 // Send "syn" so native code should reply with "ack". | 62 // Send "syn" so native code should reply with "ack". |
| 62 browserProxy.handleJsMessage('syn'); | 63 browserProxy.handleJsMessage('syn'); |
| 63 }); | 64 }); |
| 64 } | 65 } |
| 65 main(); | 66 main(); |
| OLD | NEW |