OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 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" |
| 7 // from the native code, the page then sends "fin". Test succeeds only when |
| 8 // "fin" is received by the native page. Refer to |
| 9 // ios/web/webui/web_ui_mojo_inttest.mm for testing code. |
| 10 |
| 11 define('main', [ |
| 12 'mojo/public/js/bindings', |
| 13 'mojo/public/js/core', |
| 14 'mojo/public/js/connection', |
| 15 'ios/web/test/mojo_test.mojom', |
| 16 'content/public/renderer/service_provider', |
| 17 ], function(bindings, core, connection, browser, serviceProvider) { |
| 18 |
| 19 var page; |
| 20 |
| 21 function TestPageImpl(browser) { |
| 22 this.browser_ = browser; |
| 23 }; |
| 24 |
| 25 TestPageImpl.prototype = Object.create(browser.TestPage.stubClass.prototype); |
| 26 |
| 27 /** |
| 28 * Sends message as a string to the native code. |
| 29 * |
| 30 * @param {string} message Message to send. |
| 31 */ |
| 32 TestPageImpl.prototype.sendMessage = function(message) { |
| 33 var pipe = core.createMessagePipe(); |
| 34 var stub = connection.bindHandleToStub(pipe.handle0, browser.TestPage); |
| 35 bindings.StubBindings(stub).delegate = page; |
| 36 page.stub_ = stub; |
| 37 this.browser_.handleJsMessage(message, pipe.handle1); |
| 38 }; |
| 39 |
| 40 /** |
| 41 * Called by native code with "ack" message. |
| 42 * |
| 43 * @param {!NativeMessageResultMojo} result Object received from the native |
| 44 code. |
| 45 */ |
| 46 TestPageImpl.prototype.handleNativeMessage = function(result) { |
| 47 if (result.message == 'ack') { |
| 48 // Native code has replied with "ack", send "fin" to complete the test. |
| 49 this.sendMessage('fin'); |
| 50 } |
| 51 }; |
| 52 |
| 53 return function() { |
| 54 var browserProxy = connection.bindHandleToProxy( |
| 55 serviceProvider.connectToService(browser.TestUIHandlerMojo.name), |
| 56 browser.TestUIHandlerMojo); |
| 57 |
| 58 page = new TestPageImpl(browserProxy); |
| 59 |
| 60 // Send "syn" so native code should reply with "ack". |
| 61 page.sendMessage('syn'); |
| 62 }; |
| 63 }); |
OLD | NEW |