function sendMessageFromTab() {
      var doneListening = listenForever(
        chrome.runtime.onMessage,
        function(request, sender, sendResponse) {
          let expectedSender = {
            tab: testTab,
            frameId: 0, // Main frame
            url: testTab.url,
            id: chrome.runtime.id
          };
          compareSenders(expectedSender, sender);
          if (request.step == 1) {
            // Step 1: Page should send another request for step 2.
            chrome.test.log("sendMessageFromTab: got step 1");
            sendResponse({nextStep: true});
          } else {
            // Step 2.
            chrome.test.assertEq(request.step, 2);
            sendResponse();
            doneListening();
          }
      });

      var port = chrome.tabs.connect(testTab.id);
      port.postMessage({testSendMessageFromTab: true});
      port.disconnect();
      chrome.test.log("sendMessageFromTab: sent first message to tab");
    }
// Tests receiving a request from a content script and responding.
Tests receiving a request from a content script and responding.
Tests receiving a request from a content script and responding .
function sendMessageFromTab() {
      var doneListening = listenForever(
        chrome.runtime.onMessage,
        function(request, sender, sendResponse) {
          let expectedSender = {
            tab: testTab,
            frameId: 0, 
            url: testTab.url,
            id: chrome.runtime.id
          };
          compareSenders(expectedSender, sender);
          if (request.step == 1) {
            chrome.test.log("sendMessageFromTab: got step 1");
            sendResponse({nextStep: true});
          } else {
            chrome.test.assertEq(request.step, 2);
            sendResponse();
            doneListening();
          }
      });
      var port = chrome.tabs.connect(testTab.id);
      port.postMessage({testSendMessageFromTab: true});
      port.disconnect();
      chrome.test.log("sendMessageFromTab: sent first message to tab");
    }
function sendMessageFromTab ( ) { var doneListening = listenForever ( chrome . runtime . onMessage , function ( request , sender , sendResponse ) { let expectedSender = { tab : testTab , frameId : 0 , url : testTab . url , id : chrome . runtime . id } ; compareSenders ( expectedSender , sender ) ; if ( request . step == 1 ) { chrome . test . log ( "sendMessageFromTab: got step 1" ) ; sendResponse ( { nextStep : true } ) ; } else { chrome . test . assertEq ( request . step , 2 ) ; sendResponse ( ) ; doneListening ( ) ; } } ) ; var port = chrome . tabs . connect ( testTab . id ) ; port . postMessage ( { testSendMessageFromTab : true } ) ; port . disconnect ( ) ; chrome . test . log ( "sendMessageFromTab: sent first message to tab" ) ; }
Tests receiving a request from a content script and responding.
Tests receiving a request from a content script and responding .
// Main frame // Step 1: Page should send another request for step 2. // Step 2.