| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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. |
| 4 |
| 5 var kPortErrorMessage = |
| 6 'Could not establish connection. Receiving end does not exist.'; |
| 7 |
| 8 // onMessage / onConnect in the same frame cannot be triggered by sendMessage or |
| 9 // connect, so both attempts to send a message should fail with an error. |
| 10 |
| 11 chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) { |
| 12 chrome.test.fail('onMessage should not be triggered. Received: ' + msg); |
| 13 }); |
| 14 |
| 15 chrome.runtime.onConnect.addListener(function(port) { |
| 16 chrome.test.fail('onConnect should not be triggered. Port: ' + port.name); |
| 17 }); |
| 18 |
| 19 chrome.test.runTests([ |
| 20 function sendMessageExpectingNoAnswer() { |
| 21 chrome.runtime.sendMessage('hello without callback'); |
| 22 // The timer is here to try and get the test failure in the correct test |
| 23 // case (namely "sendMessageExpectingNoAnswer"). If the timer is too short, |
| 24 // but the test fails, then onMessage will still print an error that shows |
| 25 // which test fails, but the test runner will think that it is running in |
| 26 // the next test, and attribute the failure incorrectly. |
| 27 setTimeout(chrome.test.callbackPass(), 100); |
| 28 }, |
| 29 |
| 30 function sendMessageExpectingNoAnswerWithCallback() { |
| 31 chrome.runtime.sendMessage('hello with callback', |
| 32 chrome.test.callbackFail(kPortErrorMessage)); |
| 33 }, |
| 34 |
| 35 function connectAndDisconnect() { |
| 36 chrome.runtime.connect({ name: 'The First Port'}).disconnect(); |
| 37 // Like sendMessageExpectingNoAnswer; onConnect should not be triggered. |
| 38 setTimeout(chrome.test.callbackPass(), 100); |
| 39 }, |
| 40 |
| 41 function connectExpectDisconnect() { |
| 42 chrome.runtime.connect({ name: 'The Last Port'}).onDisconnect.addListener( |
| 43 chrome.test.callbackFail(kPortErrorMessage)); |
| 44 }, |
| 45 ]); |
| OLD | NEW |