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