OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 chrome.runtime.onConnect.addListener(function(port) { | 5 chrome.runtime.onConnect.addListener(function(port) { |
6 var is_ready_to_crash = false; | 6 var is_ready_to_crash = false; |
7 var succeed1 = chrome.test.callbackAdded(); | 7 var succeed1 = chrome.test.callbackAdded(); |
8 var succeed2 = chrome.test.callbackAdded(); | 8 var succeed2 = chrome.test.callbackAdded(); |
9 | 9 |
10 port.onMessage.addListener(function(msg) { | 10 port.onMessage.addListener(function(msg) { |
11 chrome.test.assertEq('is_ready_to_crash', msg); | 11 chrome.test.assertEq('is_ready_to_crash', msg); |
12 is_ready_to_crash = true; | 12 is_ready_to_crash = true; |
13 chrome.test.sendMessage('ready_to_crash'); | 13 chrome.test.sendMessage('ready_to_crash'); |
14 // Now the browser test should kill the tab, and the port should be closed. | 14 // Now the browser test should kill the tab, and the port should be closed. |
15 }); | 15 }); |
16 port.onDisconnect.addListener(function() { | 16 port.onDisconnect.addListener(function() { |
17 chrome.test.log('port.onDisconnect was triggered.'); | 17 chrome.test.log('port.onDisconnect was triggered.'); |
18 chrome.test.assertTrue(is_ready_to_crash); | 18 chrome.test.assertTrue(is_ready_to_crash); |
19 succeed1(); | 19 succeed1(); |
20 }); | 20 }); |
21 | 21 |
22 chrome.tabs.sendMessage(port.sender.tab.id, 'Rob says hi', function() { | 22 chrome.tabs.sendMessage(port.sender.tab.id, 'Rob says hi', function() { |
23 chrome.test.log('tab.sendMessage\'s response callback was invoked'); | 23 chrome.test.log('tab.sendMessage\'s response callback was invoked'); |
24 chrome.test.assertNoLastError(); | 24 chrome.test.assertLastError( |
| 25 'The message port closed before a reponse was received.'); |
25 succeed2(); | 26 succeed2(); |
26 }); | 27 }); |
27 }); | 28 }); |
OLD | NEW |