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

Unified 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: Also rename invocation of WillConnectToPort 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/data/extensions/api_test/messaging/background_only/manifest.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/extensions/api_test/messaging/background_only/test.js
diff --git a/chrome/test/data/extensions/api_test/messaging/background_only/test.js b/chrome/test/data/extensions/api_test/messaging/background_only/test.js
new file mode 100644
index 0000000000000000000000000000000000000000..de7cd9e3491737d626953f01d67c1911a9e7614c
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/messaging/background_only/test.js
@@ -0,0 +1,45 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var kPortErrorMessage =
+ 'Could not establish connection. Receiving end does not exist.';
+
+// onMessage / onConnect in the same frame cannot be triggered by sendMessage or
+// connect, so both attempts to send a message should fail with an error.
+
+chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
+ chrome.test.fail('onMessage should not be triggered. Received: ' + msg);
+});
+
+chrome.runtime.onConnect.addListener(function(port) {
+ chrome.test.fail('onConnect should not be triggered. Port: ' + port.name);
+});
+
+chrome.test.runTests([
+ function sendMessageExpectingNoAnswer() {
+ chrome.runtime.sendMessage('hello without callback');
+ // The timer is here to try and get the test failure in the correct test
+ // case (namely "sendMessageExpectingNoAnswer"). If the timer is too short,
+ // but the test fails, then onMessage will still print an error that shows
+ // which test fails, but the test runner will think that it is running in
+ // the next test, and attribute the failure incorrectly.
+ setTimeout(chrome.test.callbackPass(), 100);
+ },
+
+ function sendMessageExpectingNoAnswerWithCallback() {
+ chrome.runtime.sendMessage('hello with callback',
+ chrome.test.callbackFail(kPortErrorMessage));
+ },
+
+ function connectAndDisconnect() {
+ chrome.runtime.connect({ name: 'The First Port'}).disconnect();
+ // Like sendMessageExpectingNoAnswer; onConnect should not be triggered.
+ setTimeout(chrome.test.callbackPass(), 100);
+ },
+
+ function connectExpectDisconnect() {
+ chrome.runtime.connect({ name: 'The Last Port'}).onDisconnect.addListener(
+ chrome.test.callbackFail(kPortErrorMessage));
+ },
+]);
« no previous file with comments | « chrome/test/data/extensions/api_test/messaging/background_only/manifest.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698