| 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; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 // a request with the given details. If the method returns true, the event | 174 // a request with the given details. If the method returns true, the event |
| 175 // should be ignored. | 175 // should be ignored. |
| 176 function isUnexpectedDetachedRequest(name, details) { | 176 function isUnexpectedDetachedRequest(name, details) { |
| 177 // This function is responsible for marking detached requests as unexpected. | 177 // This function is responsible for marking detached requests as unexpected. |
| 178 // Non-detached requests are not this function's concern. | 178 // Non-detached requests are not this function's concern. |
| 179 if (details.tabId !== -1 || details.frameId >= 0) | 179 if (details.tabId !== -1 || details.frameId >= 0) |
| 180 return false; | 180 return false; |
| 181 | 181 |
| 182 // Only return true if there is no matching expectation for the given details. | 182 // Only return true if there is no matching expectation for the given details. |
| 183 return !expectedEventData.some(function(exp) { | 183 return !expectedEventData.some(function(exp) { |
| 184 var didMatchTabAndFrameId = |
| 185 exp.details.tabId === -1 && |
| 186 exp.details.frameId === -1; |
| 187 |
| 188 // Accept non-matching tabId/frameId for ping/beacon requests because these |
| 189 // requests can continue after a frame is removed. And due to a bug, such |
| 190 // requests have a tabId/frameId of -1. |
| 191 // The test will fail anyway, but then with a helpful error (expectation |
| 192 // differs from actual events) instead of an obscure test timeout. |
| 193 // TODO(robwu): Remove this once https://crbug.com/522129 gets fixed. |
| 194 didMatchTabAndFrameId = didMatchTabAndFrameId || details.type === 'ping'; |
| 195 |
| 184 return name === exp.event && | 196 return name === exp.event && |
| 185 exp.details.tabId === -1 && | 197 didMatchTabAndFrameId && |
| 186 exp.details.frameId === -1 && | |
| 187 exp.details.method === details.method && | 198 exp.details.method === details.method && |
| 188 exp.details.url === details.url && | 199 exp.details.url === details.url && |
| 189 exp.details.type === details.type; | 200 exp.details.type === details.type; |
| 190 }); | 201 }); |
| 191 } | 202 } |
| 192 | 203 |
| 193 function captureEvent(name, details, callback) { | 204 function captureEvent(name, details, callback) { |
| 194 // Ignore system-level requests like safebrowsing updates and favicon fetches | 205 // Ignore system-level requests like safebrowsing updates and favicon fetches |
| 195 // since they are unpredictable. | 206 // since they are unpredictable. |
| 196 if (details.type == "other" || | 207 if (details.type == "other" || |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 helper('onHeadersReceived'); | 413 helper('onHeadersReceived'); |
| 403 helper('onResponseStarted'); | 414 helper('onResponseStarted'); |
| 404 helper('onBeforeRedirect'); | 415 helper('onBeforeRedirect'); |
| 405 helper('onCompleted'); | 416 helper('onCompleted'); |
| 406 helper('onErrorOccurred'); | 417 helper('onErrorOccurred'); |
| 407 } | 418 } |
| 408 | 419 |
| 409 function resetDeclarativeRules() { | 420 function resetDeclarativeRules() { |
| 410 chrome.declarativeWebRequest.onRequest.removeRules(); | 421 chrome.declarativeWebRequest.onRequest.removeRules(); |
| 411 } | 422 } |
| OLD | NEW |