Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: chrome/test/data/extensions/api_test/native_messaging/test.js

Issue 10918255: The Windows portion of Native Messagaing (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 var appName = navigator.platform.match(/win/i) ? 'echo.bat' : 'echo.py';
6
5 chrome.test.getConfig(function(config) { 7 chrome.test.getConfig(function(config) {
6 chrome.test.runTests([ 8 chrome.test.runTests([
7 9
10 // The goal of this test is just not to crash.
11 function sendMessageWithoutCallback() {
12 var message = {"text": "Hi there!", "number": 3};
13 chrome.extension.sendNativeMessage(appName, message);
14 chrome.test.succeed(); // Mission Complete
15 },
16
8 function sendMessageWithCallback() { 17 function sendMessageWithCallback() {
9 var message = {"text": "Hi there!", "number": 3}; 18 var message = {"text": "Hi there!", "number": 3};
10 chrome.extension.sendNativeMessage( 19 chrome.extension.sendNativeMessage(
11 'echo.py', message, 20 appName, message,
12 chrome.test.callbackPass(function(nativeResponse) { 21 chrome.test.callbackPass(function(nativeResponse) {
13 var expectedResponse = {"id": 1, "echo": message}; 22 var expectedResponse = {"id": 1, "echo": message};
14 chrome.test.assertEq(expectedResponse, nativeResponse); 23 chrome.test.assertEq(expectedResponse, nativeResponse);
15 })); 24 }));
16 }, 25 },
17 26
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() { 27 function connect() {
26 var messagesToSend = [{"text": "foo"}, 28 var messagesToSend = [{"text": "foo"},
27 {"text": "bar", "funCount": 9001}, 29 {"text": "bar", "funCount": 9001},
28 {}]; 30 {}];
29 var expectedResponses = [{"id": 1, "echo": messagesToSend[0]}, 31 var expectedResponses = [{"id": 1, "echo": messagesToSend[0]},
30 {"id": 2, "echo": messagesToSend[1]}, 32 {"id": 2, "echo": messagesToSend[1]},
31 {"id": 3, "echo": messagesToSend[2]}]; 33 {"id": 3, "echo": messagesToSend[2]}];
32 var currentMessage = 0; 34 var currentMessage = 0;
33 35
34 port = chrome.extension.connectNative('echo.py', 36 port = chrome.extension.connectNative(appName,
35 messagesToSend[currentMessage]); 37 messagesToSend[currentMessage]);
36 port.onMessage.addListener(function(message) { 38 port.onMessage.addListener(function(message) {
37 chrome.test.assertEq(expectedResponses[currentMessage], message); 39 chrome.test.assertEq(expectedResponses[currentMessage], message);
38 currentMessage++; 40 currentMessage++;
39 41
40 if (currentMessage == expectedResponses.length) 42 if (currentMessage == expectedResponses.length)
41 chrome.test.notifyPass(); 43 chrome.test.notifyPass();
42 else 44 else
43 port.postMessage(messagesToSend[currentMessage]); 45 port.postMessage(messagesToSend[currentMessage]);
44 }); 46 });
45 } 47 }
46 ]); 48 ]);
47 }); 49 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698