summaryrefslogtreecommitdiffstats
path: root/chrome/test/data/extensions/api_test/connect/test.html
blob: b108a8d3330f91ebb4cb8a51ee87cf10f088d7bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<script>
chrome.test.runTests([
  // Tests receiving a request from a content script and responding.
  function onRequest() {
    chrome.extension.onRequest.addListener(
      function(request, sender, sendResponse) {
        chrome.test.assertTrue("url" in sender.tab, "no tab available.");
        chrome.test.assertEq(sender.id, location.host);
        if (request.step == 1) {
          // Step 1: Page should send another request for step 2.
          sendResponse({nextStep: true});
        } else {
          // Step 2.
          chrome.test.assertEq(request.step, 2);
          sendResponse({});
          chrome.test.succeed();
        } 
      });
  },
  // Tests sending a request to a tab and receiving a response.
  function sendRequest() {
    chrome.tabs.getSelected(null, function(tab) {
      chrome.test.log("Selected tab: " + tab.url);
      chrome.tabs.sendRequest(tab.id, {step2: 1}, function(response) {
        chrome.test.assertTrue(response.success);
        chrome.test.succeed();
      });
    });
  }
]);

chrome.test.log("Creating tab...");
chrome.tabs.create({
  url: "http://localhost:1337/files/extensions/test_file.html"
});
</script>