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