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 testWebSocketPort; | |
| 14 var testServerPort; | 15 var testServerPort; |
| 15 var testServer = "www.a.com"; | 16 var testServer = "www.a.com"; |
| 16 var defaultScheme = "http"; | 17 var defaultScheme = "http"; |
| 17 var eventsCaptured; | 18 var eventsCaptured; |
| 18 var listeners = { | 19 var listeners = { |
| 19 'onBeforeRequest': [], | 20 'onBeforeRequest': [], |
| 20 'onBeforeSendHeaders': [], | 21 'onBeforeSendHeaders': [], |
| 21 'onAuthRequired': [], | 22 'onAuthRequired': [], |
| 22 'onSendHeaders': [], | 23 'onSendHeaders': [], |
| 23 'onHeadersReceived': [], | 24 'onHeadersReceived': [], |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 38 | 39 |
| 39 function runTests(tests) { | 40 function runTests(tests) { |
| 40 var waitForAboutBlank = function(_, info, tab) { | 41 var waitForAboutBlank = function(_, info, tab) { |
| 41 if (info.status == "complete" && tab.url == "about:blank") { | 42 if (info.status == "complete" && tab.url == "about:blank") { |
| 42 tabId = tab.id; | 43 tabId = tab.id; |
| 43 tabIdMap = {"-1": -1}; | 44 tabIdMap = {"-1": -1}; |
| 44 tabIdMap[tabId] = 0; | 45 tabIdMap[tabId] = 0; |
| 45 chrome.tabs.onUpdated.removeListener(waitForAboutBlank); | 46 chrome.tabs.onUpdated.removeListener(waitForAboutBlank); |
| 46 chrome.test.getConfig(function(config) { | 47 chrome.test.getConfig(function(config) { |
| 47 testServerPort = config.testServer.port; | 48 testServerPort = config.testServer.port; |
| 49 testWebSocketPort = config.testWebSocketPort; | |
| 48 chrome.test.runTests(tests); | 50 chrome.test.runTests(tests); |
| 49 }); | 51 }); |
| 50 } | 52 } |
| 51 }; | 53 }; |
| 52 chrome.tabs.onUpdated.addListener(waitForAboutBlank); | 54 chrome.tabs.onUpdated.addListener(waitForAboutBlank); |
| 53 chrome.tabs.create({url: "about:blank"}); | 55 chrome.tabs.create({url: "about:blank"}); |
| 54 } | 56 } |
| 55 | 57 |
| 56 // Returns an URL from the test server, fixing up the port. Must be called | 58 // Returns an URL from the test server, fixing up the port. Must be called |
| 57 // from within a test case passed to runTests. | 59 // from within a test case passed to runTests. |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 didMatchTabAndFrameId && | 199 didMatchTabAndFrameId && |
| 198 exp.details.method === details.method && | 200 exp.details.method === details.method && |
| 199 exp.details.url === details.url && | 201 exp.details.url === details.url && |
| 200 exp.details.type === details.type; | 202 exp.details.type === details.type; |
| 201 }); | 203 }); |
| 202 } | 204 } |
| 203 | 205 |
| 204 function captureEvent(name, details, callback) { | 206 function captureEvent(name, details, callback) { |
| 205 // Ignore system-level requests like safebrowsing updates and favicon fetches | 207 // Ignore system-level requests like safebrowsing updates and favicon fetches |
| 206 // since they are unpredictable. | 208 // since they are unpredictable. |
| 207 if ((details.type == "other" && !details.url.includes('dont-ignore-me')) || | 209 // TODO(pkalinnikov): Remove the startsWith('ws') check once a new type gets |
| 210 // intoduced for the WebSocket requests. | |
|
tyoshino (SeeGerritForStatus)
2016/12/06 08:05:06
introduced
pkalinnikov
2016/12/13 21:15:59
Done.
| |
| 211 if ((details.type == "other" && !details.url.includes('dont-ignore-me') && | |
| 212 !details.url.startsWith('ws')) || | |
| 208 isUnexpectedDetachedRequest(name, details) || | 213 isUnexpectedDetachedRequest(name, details) || |
| 209 details.url.match(/\/favicon.ico$/) || | 214 details.url.match(/\/favicon.ico$/) || |
| 210 details.url.match(/https:\/\/dl.google.com/)) | 215 details.url.match(/https:\/\/dl.google.com/)) { |
| 211 return; | 216 return; |
| 217 } | |
| 212 | 218 |
| 213 // Pull the extra per-event options out of the expected data. These let | 219 // Pull the extra per-event options out of the expected data. These let |
| 214 // us specify special return values per event. | 220 // us specify special return values per event. |
| 215 var currentIndex = capturedEventData.length; | 221 var currentIndex = capturedEventData.length; |
| 216 var extraOptions; | 222 var extraOptions; |
| 217 var retval; | 223 var retval; |
| 218 if (expectedEventData.length > currentIndex) { | 224 if (expectedEventData.length > currentIndex) { |
| 219 retval = | 225 retval = |
| 220 expectedEventData[currentIndex].retval_function ? | 226 expectedEventData[currentIndex].retval_function ? |
| 221 expectedEventData[currentIndex].retval_function(name, details) : | 227 expectedEventData[currentIndex].retval_function(name, details) : |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 helper('onHeadersReceived'); | 419 helper('onHeadersReceived'); |
| 414 helper('onResponseStarted'); | 420 helper('onResponseStarted'); |
| 415 helper('onBeforeRedirect'); | 421 helper('onBeforeRedirect'); |
| 416 helper('onCompleted'); | 422 helper('onCompleted'); |
| 417 helper('onErrorOccurred'); | 423 helper('onErrorOccurred'); |
| 418 } | 424 } |
| 419 | 425 |
| 420 function resetDeclarativeRules() { | 426 function resetDeclarativeRules() { |
| 421 chrome.declarativeWebRequest.onRequest.removeRules(); | 427 chrome.declarativeWebRequest.onRequest.removeRules(); |
| 422 } | 428 } |
| OLD | NEW |