function sendMessageFromFrameInTab() {
      var actualSenders = [];
      var doneListening = listenForever(
        chrome.runtime.onMessage,
        function(request, sender, sendResponse) {
          actualSenders.push(sender);

          // testSendMessageFromFrame() in page.js adds 2 frames. Wait for
          // messages from each.
          if (actualSenders.length < 2)
            return;

          chrome.webNavigation.getAllFrames({
            tabId: testTab.id
          }, function(details) {
            function sortByFrameId(a, b) {
              return a.frameId < b.frameId ? 1 : -1;
            }
            var expectedSenders = details.filter(function(frame) {
              return frame.frameId > 0; // Exclude main frame.
            }).map(function(frame) {
              return {
                tab: testTab,
                frameId: frame.frameId,
                url: frame.url,
                id: chrome.runtime.id
              };
            }).sort(sortByFrameId);

            actualSenders.sort(sortByFrameId);

            compareSenders(expectedSenders[0], actualSenders[0]);
            compareSenders(expectedSenders[1], actualSenders[1]);
            doneListening();
          });
        }
      );

      var port = chrome.tabs.connect(testTab.id);
      port.postMessage({testSendMessageFromFrame: true});
      port.disconnect();
      chrome.test.log("sendMessageFromFrameInTab: send 1st message to tab");
    }
// Tests that a message from a child frame has a correct frameId.
Tests that a message from a child frame has a correct frameId.
Tests that a message from a child frame has a correct frameId .
function sendMessageFromFrameInTab() {
      var actualSenders = [];
      var doneListening = listenForever(
        chrome.runtime.onMessage,
        function(request, sender, sendResponse) {
          actualSenders.push(sender);
          if (actualSenders.length < 2)
            return;
          chrome.webNavigation.getAllFrames({
            tabId: testTab.id
          }, function(details) {
            function sortByFrameId(a, b) {
              return a.frameId < b.frameId ? 1 : -1;
            }
            var expectedSenders = details.filter(function(frame) {
              return frame.frameId > 0; 
            }).map(function(frame) {
              return {
                tab: testTab,
                frameId: frame.frameId,
                url: frame.url,
                id: chrome.runtime.id
              };
            }).sort(sortByFrameId);
            actualSenders.sort(sortByFrameId);
            compareSenders(expectedSenders[0], actualSenders[0]);
            compareSenders(expectedSenders[1], actualSenders[1]);
            doneListening();
          });
        }
      );
      var port = chrome.tabs.connect(testTab.id);
      port.postMessage({testSendMessageFromFrame: true});
      port.disconnect();
      chrome.test.log("sendMessageFromFrameInTab: send 1st message to tab");
    }
function sendMessageFromFrameInTab ( ) { var actualSenders = [ ] ; var doneListening = listenForever ( chrome . runtime . onMessage , function ( request , sender , sendResponse ) { actualSenders . push ( sender ) ; if ( actualSenders . length < 2 ) return ; chrome . webNavigation . getAllFrames ( { tabId : testTab . id } , function ( details ) { function sortByFrameId ( a , b ) { return a . frameId < b . frameId ? 1 : - 1 ; } var expectedSenders = details . filter ( function ( frame ) { return frame . frameId > 0 ; } ) . map ( function ( frame ) { return { tab : testTab , frameId : frame . frameId , url : frame . url , id : chrome . runtime . id } ; } ) . sort ( sortByFrameId ) ; actualSenders . sort ( sortByFrameId ) ; compareSenders ( expectedSenders [ 0 ] , actualSenders [ 0 ] ) ; compareSenders ( expectedSenders [ 1 ] , actualSenders [ 1 ] ) ; doneListening ( ) ; } ) ; } ) ; var port = chrome . tabs . connect ( testTab . id ) ; port . postMessage ( { testSendMessageFromFrame : true } ) ; port . disconnect ( ) ; chrome . test . log ( "sendMessageFromFrameInTab: send 1st message to tab" ) ; }
Tests that a message from a child frame has a correct frameId.
Tests that a message from a child frame has a correct frameId .
// testSendMessageFromFrame() in page.js adds 2 frames. Wait for // messages from each. // Exclude main frame.