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

Unified Diff: chrome/test/data/extensions/api_test/native_messaging/test.js

Issue 10818013: Native Messaging! (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: nit Created 8 years, 3 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/data/extensions/api_test/native_messaging/manifest.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/extensions/api_test/native_messaging/test.js
diff --git a/chrome/test/data/extensions/api_test/native_messaging/test.js b/chrome/test/data/extensions/api_test/native_messaging/test.js
new file mode 100644
index 0000000000000000000000000000000000000000..cb58585ff73cea79ccb99eb8adb7341e6a946b75
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/native_messaging/test.js
@@ -0,0 +1,47 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+chrome.test.getConfig(function(config) {
+ chrome.test.runTests([
+
+ function sendMessageWithCallback() {
+ var message = {"text": "Hi there!", "number": 3};
+ chrome.extension.sendNativeMessage(
+ 'echo.py', message,
+ chrome.test.callbackPass(function(nativeResponse) {
+ var expectedResponse = {"id": 1, "echo": message};
+ chrome.test.assertEq(expectedResponse, nativeResponse);
+ }));
+ },
+
+ // The goal of this test, is just not to crash.
+ function sendMessageWithoutCallback() {
+ var message = {"text": "Hi there!", "number": 3};
+ chrome.extension.sendNativeMessage('echo.py', message);
+ chrome.test.succeed(); // Mission Complete
+ },
+
+ function connect() {
+ var messagesToSend = [{"text": "foo"},
+ {"text": "bar", "funCount": 9001},
+ {}];
+ var expectedResponses = [{"id": 1, "echo": messagesToSend[0]},
+ {"id": 2, "echo": messagesToSend[1]},
+ {"id": 3, "echo": messagesToSend[2]}];
+ var currentMessage = 0;
+
+ port = chrome.extension.connectNative('echo.py',
+ messagesToSend[currentMessage]);
+ port.onMessage.addListener(function(message) {
+ chrome.test.assertEq(expectedResponses[currentMessage], message);
+ currentMessage++;
+
+ if (currentMessage == expectedResponses.length)
+ chrome.test.notifyPass();
+ else
+ port.postMessage(messagesToSend[currentMessage]);
+ });
+ }
+ ]);
+});
« no previous file with comments | « chrome/test/data/extensions/api_test/native_messaging/manifest.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698