Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / native_messaging / test.js
blobab747a1f9f0b5370b48f2a47aaf60dc755456333
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.
5 var appName = 'com.google.chrome.test.echo';
7 chrome.test.getConfig(function(config) {
8 chrome.test.runTests([
9 function invalidHostName() {
10 var message = {"text": "Hello!"};
11 chrome.runtime.sendNativeMessage(
12 'not.installed.app', message,
13 chrome.test.callbackFail(
14 "Specified native messaging host not found.",
15 function(response) {
16 chrome.test.assertEq(undefined, response);
17 }));
20 function nonexistentHost() {
21 var message = {"text": "Hello!"};
22 chrome.runtime.sendNativeMessage(
23 'com.google.chrome.test.host_binary_missing', message,
24 chrome.test.callbackFail(
25 "Specified native messaging host not found.",
26 function(response) {
27 chrome.test.assertEq(undefined, response);
28 }));
31 function sendMessageWithCallback() {
32 var message = {"text": "Hi there!", "number": 3};
33 chrome.runtime.sendNativeMessage(
34 appName, message,
35 chrome.test.callbackPass(function(response) {
36 chrome.test.assertEq(1, response.id);
37 chrome.test.assertEq(message, response.echo);
38 chrome.test.assertEq(
39 response.caller_url, window.location.origin + "/");
40 }));
43 // The goal of this test is just not to crash.
44 function sendMessageWithoutCallback() {
45 var message = {"text": "Hi there!", "number": 3};
46 chrome.extension.sendNativeMessage(appName, message);
47 chrome.test.succeed(); // Mission Complete
50 function bigMessage() {
51 // Create a special message for which the test host must try sending a
52 // message that is bigger than the limit.
53 var message = { "bigMessageTest": true };
54 chrome.runtime.sendNativeMessage(
55 appName, message,
56 chrome.test.callbackFail(
57 "Error when communicating with the native messaging host.",
58 function(response) {
59 chrome.test.assertEq(undefined, response);
60 }));
63 function connect() {
64 var messagesToSend = [{"text": "foo"},
65 {"text": "bar", "funCount": 9001},
66 {}];
67 var currentMessage = 0;
69 port = chrome.extension.connectNative(appName);
70 port.postMessage(messagesToSend[currentMessage]);
72 port.onMessage.addListener(function(message) {
73 chrome.test.assertEq(currentMessage + 1, message.id);
74 chrome.test.assertEq(messagesToSend[currentMessage], message.echo);
75 chrome.test.assertEq(
76 message.caller_url, window.location.origin + "/");
77 currentMessage++;
79 if (currentMessage == messagesToSend.length)
80 chrome.test.succeed();
81 else
82 port.postMessage(messagesToSend[currentMessage]);
83 });
86 // Verify that the case when host stops itself is handled properly.
87 function stopHost() {
88 port = chrome.extension.connectNative(appName);
90 port.onDisconnect.addListener(
91 chrome.test.callback(function() {}, "Native host has exited."));
93 // Send first message that should stop the host.
94 port.postMessage({ "stopHostTest": true });
96 ]);
97 });