Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var getURL = chrome.extension.getURL; | 5 var getURL = chrome.extension.getURL; |
| 6 var deepEq = chrome.test.checkDeepEq; | 6 var deepEq = chrome.test.checkDeepEq; |
| 7 var expectedEventData; | 7 var expectedEventData; |
| 8 var capturedEventData; | 8 var capturedEventData; |
| 9 var capturedUnexpectedData; | 9 var capturedUnexpectedData; |
| 10 var expectedEventOrder; | 10 var expectedEventOrder; |
| 11 var tabId; | 11 var tabId; |
| 12 var tabIdMap; | 12 var tabIdMap; |
| 13 var frameIdMap; | 13 var frameIdMap; |
| 14 var testServerPort; | 14 var testServerPort; |
| 15 var testServer = "www.a.com"; | 15 var testServer = "www.a.com"; |
| 16 var defaultScheme = "http"; | 16 var defaultScheme = "http"; |
| 17 var eventsCaptured; | 17 var eventsCaptured; |
| 18 | 18 |
| 19 // If true, don't bark on events that were not registered via expect(). | 19 // If true, don't bark on events that were not registered via expect(). |
| 20 // These events are recorded in capturedUnexpectedData instead of | 20 // These events are recorded in capturedUnexpectedData instead of |
| 21 // capturedEventData. | 21 // capturedEventData. |
| 22 var ignoreUnexpected = false; | 22 var ignoreUnexpected = false; |
| 23 | 23 |
| 24 // This is a debugging aid to print all received events as well as the | 24 // This is a debugging aid to print all received events as well as the |
| 25 // information whether they were expected. | 25 // information whether they were expected. |
| 26 var logAllRequests = false; | 26 var logAllRequests = false; |
| 27 | 27 |
| 28 function runTests(tests) { | 28 function runTests(tests) { |
| 29 chrome.tabs.create({url: "about:blank"}, function(tab) { | 29 var waitForAboutBlank = function(_, info, tab) { |
| 30 tabId = tab.id; | 30 if (info.status == "complete" && tab.url == "about:blank") { |
| 31 tabIdMap = {}; | 31 tabId = tab.id; |
| 32 tabIdMap[tabId] = 0; | 32 tabIdMap = {}; |
| 33 chrome.test.getConfig(function(config) { | 33 tabIdMap[tabId] = 0; |
| 34 testServerPort = config.testServer.port; | 34 chrome.tabs.onUpdated.removeListener(waitForAboutBlank); |
| 35 chrome.test.runTests(tests); | 35 chrome.test.getConfig(function(config) { |
| 36 }); | 36 testServerPort = config.testServer.port; |
| 37 }); | 37 chrome.test.runTests(tests); |
| 38 }); | |
| 39 } | |
| 40 }; | |
| 41 chrome.tabs.onUpdated.addListener(waitForAboutBlank); | |
| 42 chrome.tabs.create({url: "about:blank"}); | |
|
Matt Perry
2013/01/03 23:39:30
wow this API sucks :)
| |
| 38 } | 43 } |
| 39 | 44 |
| 40 // Returns an URL from the test server, fixing up the port. Must be called | 45 // Returns an URL from the test server, fixing up the port. Must be called |
| 41 // from within a test case passed to runTests. | 46 // from within a test case passed to runTests. |
| 42 function getServerURL(path, opt_host, opt_scheme) { | 47 function getServerURL(path, opt_host, opt_scheme) { |
| 43 if (!testServerPort) | 48 if (!testServerPort) |
| 44 throw new Error("Called getServerURL outside of runTests."); | 49 throw new Error("Called getServerURL outside of runTests."); |
| 45 var host = opt_host || testServer; | 50 var host = opt_host || testServer; |
| 46 var scheme = opt_scheme || defaultScheme; | 51 var scheme = opt_scheme || defaultScheme; |
| 47 return scheme + "://" + host + ":" + testServerPort + "/" + path; | 52 return scheme + "://" + host + ":" + testServerPort + "/" + path; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 // since they are unpredictable. | 164 // since they are unpredictable. |
| 160 if (details.tabId == -1 || details.type == "other" || | 165 if (details.tabId == -1 || details.type == "other" || |
| 161 details.url.match(/\/favicon.ico$/) || | 166 details.url.match(/\/favicon.ico$/) || |
| 162 details.url.match(/https:\/\/dl.google.com/)) | 167 details.url.match(/https:\/\/dl.google.com/)) |
| 163 return; | 168 return; |
| 164 | 169 |
| 165 // Pull the extra per-event options out of the expected data. These let | 170 // Pull the extra per-event options out of the expected data. These let |
| 166 // us specify special return values per event. | 171 // us specify special return values per event. |
| 167 var currentIndex = capturedEventData.length; | 172 var currentIndex = capturedEventData.length; |
| 168 var extraOptions; | 173 var extraOptions; |
| 174 var retval; | |
|
battre
2012/12/19 17:57:57
we assign retval in 176 to a global variable witho
| |
| 169 if (expectedEventData.length > currentIndex) { | 175 if (expectedEventData.length > currentIndex) { |
| 170 retval = | 176 retval = |
| 171 expectedEventData[currentIndex].retval_function ? | 177 expectedEventData[currentIndex].retval_function ? |
| 172 expectedEventData[currentIndex].retval_function(name, details) : | 178 expectedEventData[currentIndex].retval_function(name, details) : |
| 173 expectedEventData[currentIndex].retval; | 179 expectedEventData[currentIndex].retval; |
| 174 } | 180 } |
| 175 | 181 |
| 176 // Check that the frameId can be used to reliably determine the URL of the | 182 // Check that the frameId can be used to reliably determine the URL of the |
| 177 // frame that caused requests. | 183 // frame that caused requests. |
| 178 if (name == "onBeforeRequest") { | 184 if (name == "onBeforeRequest") { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 helper(chrome.webRequest.onHeadersReceived); | 329 helper(chrome.webRequest.onHeadersReceived); |
| 324 helper(chrome.webRequest.onResponseStarted); | 330 helper(chrome.webRequest.onResponseStarted); |
| 325 helper(chrome.webRequest.onBeforeRedirect); | 331 helper(chrome.webRequest.onBeforeRedirect); |
| 326 helper(chrome.webRequest.onCompleted); | 332 helper(chrome.webRequest.onCompleted); |
| 327 helper(chrome.webRequest.onErrorOccurred); | 333 helper(chrome.webRequest.onErrorOccurred); |
| 328 } | 334 } |
| 329 | 335 |
| 330 function resetDeclarativeRules() { | 336 function resetDeclarativeRules() { |
| 331 chrome.declarativeWebRequest.onRequest.removeRules(); | 337 chrome.declarativeWebRequest.onRequest.removeRules(); |
| 332 } | 338 } |
| OLD | NEW |