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 otherId = 'dceacbkfkmllgmjmbhgkpjegnodmildf';
7 function testConversation(port) {
8 var sawResponses = false;
9 port.onMessage.addListener(function(msg) {
10 if (msg == 'message_1_reply') {
11 port.postMessage('message_2');
12 } else if (msg == 'message_2_reply') {
14 port.postMessage('ok_to_disconnect');
16 console.log('saw unexpected message: "' + msg + '"');
20 port.onDisconnect.addListener(function(){
22 chrome.test.succeed();
26 port.postMessage('message_1');
29 chrome.test.sendMessage('Launched');
31 chrome.test.runTests([
34 var port = chrome.runtime.connect(otherId);
35 testConversation(port);
38 function connectUsingNamedPort() {
39 var port = chrome.runtime.connect(otherId, {'name': 'SomeChannelName'});
40 testConversation(port);
43 function sendMessage() {
44 chrome.runtime.sendMessage(otherId, 'hello', function(response) {
45 if (response == 'hello_response')
46 chrome.test.succeed();