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

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

Issue 709933002: Add frameId to MessageSender (extension messaging API) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments put message in assertTrue Created 6 years, 1 month 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 d76997fd34bccc78feb735d7c6a85a1ca5f24eed..33a302f4ef4ca52f5dd91236ea307960d5e11908 100644
--- a/chrome/test/data/extensions/api_test/messaging/connect/test.js
+++ b/chrome/test/data/extensions/api_test/messaging/connect/test.js
@@ -70,6 +70,7 @@ chrome.test.getConfig(function(config) {
listenOnce(chrome.runtime.onConnect, function(port) {
chrome.test.assertEq({
tab: testTab,
+ frameId: 0, // Main frame
url: testTab.url,
id: chrome.runtime.id
}, port.sender);
@@ -95,6 +96,7 @@ chrome.test.getConfig(function(config) {
function(request, sender, sendResponse) {
chrome.test.assertEq({
tab: testTab,
+ frameId: 0, // Main frame
url: testTab.url,
id: chrome.runtime.id
}, sender);
@@ -116,6 +118,55 @@ chrome.test.getConfig(function(config) {
chrome.test.log("sendMessageFromTab: sent first message to tab");
},
+ // Tests that a message from a child frame has a correct frameId.
+ function sendMessageFromFrameInTab() {
+ // This test will run twice.
+ // At the first run, the frameId will be saved. At the second run we check
+ // whether the frameId is different from the previously saved frameId.
+ var runCount = 0;
+ var frameId;
+ listenForever(
+ chrome.runtime.onMessage,
+ function(request, sender, sendResponse) {
+ // Child frames have a positive frameId.
+ chrome.test.assertTrue(sender.frameId >= 1,
+ 'frameId must be positive, but it is ' + sender.frameId);
+ if (runCount === 0)
+ frameId = sender.frameId;
+ else // The second (different) frame must have a different frameId.
+ chrome.test.assertTrue(sender.frameId != frameId);
+ delete sender.frameId;
+ chrome.test.assertEq({
+ tab: testTab,
+ url: request.frameUrl,
+ id: chrome.runtime.id
+ }, sender);
+
+ // Now test whether the frameId that we got back makes sense...
+ chrome.webNavigation.getAllFrames({
+ tabId: testTab.id
+ }, function(details) {
+ var frames = details.filter(function(frame) {
+ return frame.frameId === frameId;
+ });
+ // If |frames.length| is zero, then the frameId was bogus.
+ // If it is higher than one, then the webNavigation API is broken.
+ chrome.test.assertEq(frames.length, 1);
+ chrome.test.assertEq(frames[0].url, request.frameUrl);
+ if (++runCount == 2) {
+ // This is the second run, the test has completed.
+ doneListening();
+ }
+ });
+ }
+ );
not at google - send to devlin 2014/11/11 01:00:56 Sorry - why does it need to be as complicated as t
robwu 2014/11/11 21:32:47 and 3) frameId is positive and 4) frameId is uniqu
not at google - send to devlin 2014/11/11 22:01:58 3 and 4 seem implicitly tested by 1 and 2? So long
robwu 2014/11/11 22:20:49 Yes. We're commenting on an old version of the fil
+
+ var port = chrome.tabs.connect(testTab.id);
+ port.postMessage({testSendMessageFromFrame: true});
+ port.disconnect();
+ chrome.test.log("sendMessageFromFrameInTab: send 1st message to tab");
+ },
+
// Tests error handling when sending a request from a content script to an
// invalid extension.
function sendMessageFromTabError() {

Powered by Google App Engine
This is Rietveld 408576698