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

Unified Diff: chrome/test/data/extensions/api_test/messaging/connect/test.js

Issue 1108203004: Test that chrome.runtime.onMessage isn't fired for chrome.runtime.sendMessage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
Index: chrome/test/data/extensions/api_test/messaging/connect/test.js
diff --git a/chrome/test/data/extensions/api_test/messaging/connect/test.js b/chrome/test/data/extensions/api_test/messaging/connect/test.js
index 3e00629ed8a3606c9b4c0412acb3cfda6db20dff..0723021c724a61d3df31b315a255dc6f9249e4d8 100644
--- a/chrome/test/data/extensions/api_test/messaging/connect/test.js
+++ b/chrome/test/data/extensions/api_test/messaging/connect/test.js
@@ -290,6 +290,48 @@ chrome.test.getConfig(function(config) {
chrome.test.succeed();
},
+ // Tests that chrome.runtime.sendMessage is *not* delivered to the current
+ // context, consistent behavior with chrome.runtime.connect() and web APIs
+ // like localStorage changed listeners.
+ // Regression test for http://crbug.com/479951.
+ function sendMessageToCurrentContextFails() {
+ var stopFailing = failWhileListening(chrome.runtime.onMessage);
Devlin 2015/04/28 22:24:40 nit: stopFailing is kinda a funny name...but I got
not at google - send to devlin 2015/04/28 22:46:31 I think of it like a function. function stopFaili
+ chrome.runtime.sendMessage('ping', chrome.test.callbackFail(
+ 'Could not establish connection. Receiving end does not exist.',
+ function() {
+ stopFailing();
+ chrome.test.succeed();
+ }
+ ));
+ },
+
+ // Like sendMessageToCurrentContextFails, but with the sendMessage call not
+ // given a callback. This requires a more creative test setup because there
+ // is no callback to signal when it's supposed to have been done.
+ // Regression test for http://crbug.com/479951.
+ function sendMessageToCurrentTextWithoutCallbackFails() {
+ // Make the iframe - in a different context - watch for the message
+ // event. It *should* get it, while the current context's one doesn't.
+ var iframe = document.createElement('iframe');
+ iframe.src = chrome.runtime.getURL('blank_iframe.html');
+ document.body.appendChild(iframe);
+
+ var stopFailing = failWhileListening(chrome.runtime.onMessage);
+ chrome.test.listenOnce(
+ iframe.contentWindow.chrome.runtime.onMessage,
+ function(msg, sender) {
+ chrome.test.assertEq('ping', msg);
+ chrome.test.assertEq(chrome.runtime.id, sender.id);
+ chrome.test.assertEq(location.href, sender.url);
+ setTimeout(function() {
+ stopFailing();
+ chrome.test.succeed();
+ }, 0);
+ }
+ );
+
+ chrome.runtime.sendMessage('ping');
+ },
]);
});
@@ -318,3 +360,19 @@ function connectToTabWithFrameId(frameId, expectedMessages) {
port.postMessage({testSendMessageToFrame: true});
chrome.test.log('connectToTabWithFrameId: port to frame ' + frameId);
}
+
+// Listens to |event| and returns a callback to run to stop listening. While
+// listening, if |event| is fired, calls chrome.test.fail().
+function failWhileListening(event, doneListening) {
+ var failListener = function() {
+ chrome.test.fail('Event listener ran, but it shouldn\'t have. ' +
+ 'It\'s possible that may be triggered flakily, but this ' +
+ 'really is a real failure, not flaky sadness. Promise!');
+ };
+ var release = chrome.test.callbackAdded();
+ event.addListener(failListener);
+ return function() {
+ event.removeListener(failListener);
+ release();
+ };
+}

Powered by Google App Engine
This is Rietveld 408576698