OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 chrome.test.getConfig(function(config) { |
| 6 chrome.test.runTests([ |
| 7 |
| 8 function sendMessageWithCallback() { |
| 9 var message = {"text": "Hi there!", "number": 3}; |
| 10 chrome.extension.sendNativeMessage( |
| 11 'echo.py', message, |
| 12 chrome.test.callbackPass(function(nativeResponse) { |
| 13 var expectedResponse = {"id": 1, "echo": message}; |
| 14 chrome.test.assertEq(expectedResponse, nativeResponse); |
| 15 })); |
| 16 }, |
| 17 |
| 18 // The goal of this test, is just not to crash. |
| 19 function sendMessageWithoutCallback() { |
| 20 var message = {"text": "Hi there!", "number": 3}; |
| 21 chrome.extension.sendNativeMessage('echo.py', message); |
| 22 chrome.test.succeed(); // Mission Complete |
| 23 }, |
| 24 |
| 25 function connect() { |
| 26 var messagesToSend = [{"text": "foo"}, |
| 27 {"text": "bar", "funCount": 9001}, |
| 28 {}]; |
| 29 var expectedResponses = [{"id": 1, "echo": messagesToSend[0]}, |
| 30 {"id": 2, "echo": messagesToSend[1]}, |
| 31 {"id": 3, "echo": messagesToSend[2]}]; |
| 32 var currentMessage = 0; |
| 33 |
| 34 port = chrome.extension.connectNative('echo.py', |
| 35 messagesToSend[currentMessage]); |
| 36 port.onMessage.addListener(function(message) { |
| 37 chrome.test.assertEq(expectedResponses[currentMessage], message); |
| 38 currentMessage++; |
| 39 |
| 40 if (currentMessage == expectedResponses.length) |
| 41 chrome.test.notifyPass(); |
| 42 else |
| 43 port.postMessage(messagesToSend[currentMessage]); |
| 44 }); |
| 45 } |
| 46 ]); |
| 47 }); |
OLD | NEW |