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

Side by Side Diff: chrome/test/data/extensions/api_test/messaging/background_only/test.js

Issue 1588533002: Never connect a port to the same frame (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 unified diff | Download patch
OLDNEW
(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 ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698