Chromium Code Reviews| 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..fe8239412230b1b56819a3fbfcc4faf733909c34 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,46 @@ 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() { |
| + var senders = []; |
| + listenForever( |
| + chrome.runtime.onMessage, |
| + function(request, sender, sendResponse) { |
| + // Child frames have a positive frameId. |
| + senders.push(sender); |
| + |
|
not at google - send to devlin
2014/11/12 01:02:46
Add comment:
// testSendMessageFromFrame() in pag
robwu
2014/11/12 10:00:21
Done.
|
| + if (senders.length == 2) { |
| + chrome.webNavigation.getAllFrames({ |
| + tabId: testTab.id |
| + }, function(details) { |
| + var expectedSenders = details.filter(function() { |
| + return frame.frameId > 0; // Exlude main frame. |
|
not at google - send to devlin
2014/11/12 01:02:46
Exlude -> Exclude.
robwu
2014/11/12 10:00:21
Done.
|
| + }).map(function(frame) { |
| + return { |
| + tab: testTab, |
| + frameId: frame.frameId, |
| + url: frame.url, |
| + id: chrome.runtime.id |
| + }; |
| + }).sort(sortByFrameId); |
| + senders.sort(sortByFrameId); |
| + chrome.test.assertEq(expectedSenders, senders); |
| + doneListening(); |
| + }); |
| + } |
| + } |
| + ); |
| + function sortByFrameId(a, b) { |
|
not at google - send to devlin
2014/11/12 01:02:46
nit: put this before it's used, not after. You cou
robwu
2014/11/12 10:00:21
Done.
|
| + return a.frameId < b.frameId ? 1 : -1; |
| + } |
| + |
| + 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() { |