| OLD | NEW |
| 1 <script> | 1 <!-- |
| 2 var assertEq = chrome.test.assertEq; | 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this |
| 3 var assertTrue = chrome.test.assertTrue; | 3 * source code is governed by a BSD-style license that can be found in the |
| 4 var numReceivedRequests = 0; | 4 * LICENSE file. |
| 5 var relativePath = 'files/extensions/api_test/executescript/permissions/'; | 5 --> |
| 6 var testFile = relativePath + 'empty.html'; | 6 <script src="test.js"></script> |
| 7 var testFileFrames = relativePath + 'frames.html'; | |
| 8 var onTabLoaded; | |
| 9 | |
| 10 chrome.extension.onRequest.addListener(function(req) { | |
| 11 numReceivedRequests++; | |
| 12 }); | |
| 13 | |
| 14 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { | |
| 15 if (tab.status == 'complete' && onTabLoaded) | |
| 16 onTabLoaded(tab); | |
| 17 }); | |
| 18 | |
| 19 chrome.test.getConfig(function(config) { | |
| 20 | |
| 21 function fixPort(url) { | |
| 22 return url.replace(/PORT/, config.testServer.port); | |
| 23 } | |
| 24 | |
| 25 chrome.test.runTests([ | |
| 26 // Test a race that used to occur here (see bug 30937). | |
| 27 // Open a tab that we're not allowed to execute in (c.com), then | |
| 28 // navigate it to a tab we *are* allowed to execute in (a.com), | |
| 29 // then quickly run script in the tab before it navigates. It | |
| 30 // should appear to work (no error -- it could have been a developer | |
| 31 // mistake), but not actually do anything. | |
| 32 function() { | |
| 33 chrome.tabs.create({url: fixPort('http://c.com:PORT/') + testFile}); | |
| 34 onTabLoaded = function(tab) { | |
| 35 onTabLoaded = null; | |
| 36 numReceivedRequests = 0; | |
| 37 chrome.tabs.update( | |
| 38 tab.id, {url: fixPort('http://a.com:PORT/') + testFile}); | |
| 39 chrome.tabs.executeScript(tab.id, {file: 'script.js'}); | |
| 40 window.setTimeout(function() { | |
| 41 assertEq(0, numReceivedRequests); | |
| 42 chrome.test.runNextTest(); | |
| 43 }, 4000); | |
| 44 }; | |
| 45 }, | |
| 46 | |
| 47 // Inject into all frames. This should only affect frames we have | |
| 48 // access to. This page has three subframes, one each from a.com, | |
| 49 // b.com, and c.com. We have access to two of those, plus the root | |
| 50 // frame, so we should get three responses. | |
| 51 function() { | |
| 52 chrome.tabs.create( | |
| 53 {url: fixPort('http://a.com:PORT/') + testFileFrames}); | |
| 54 onTabLoaded = function(tab) { | |
| 55 numReceivedRequests = 0; | |
| 56 chrome.tabs.executeScript(tab.id, | |
| 57 {file: 'script.js', allFrames: true}); | |
| 58 window.setTimeout(function() { | |
| 59 chrome.test.assertEq(3, numReceivedRequests); | |
| 60 chrome.test.runNextTest(); | |
| 61 }, 4000); | |
| 62 }; | |
| 63 } | |
| 64 ]); | |
| 65 | |
| 66 }); | |
| 67 | |
| 68 </script> | |
| OLD | NEW |