Chromium Code Reviews| Index: chrome/test/data/extensions/api_test/webrequest/framework.js |
| diff --git a/chrome/test/data/extensions/api_test/webrequest/framework.js b/chrome/test/data/extensions/api_test/webrequest/framework.js |
| index 23b1303bd038b5bf3517662b914dad1cd9ec8695..31d720012d81f313cd5907b348811c14ed157108 100644 |
| --- a/chrome/test/data/extensions/api_test/webrequest/framework.js |
| +++ b/chrome/test/data/extensions/api_test/webrequest/framework.js |
| @@ -40,7 +40,7 @@ function runTests(tests) { |
| var waitForAboutBlank = function(_, info, tab) { |
| if (info.status == "complete" && tab.url == "about:blank") { |
| tabId = tab.id; |
| - tabIdMap = {}; |
| + tabIdMap = {"-1": -1}; |
| tabIdMap[tabId] = 0; |
| chrome.tabs.onUpdated.removeListener(waitForAboutBlank); |
| chrome.test.getConfig(function(config) { |
| @@ -170,10 +170,32 @@ function checkUserAgent(headers) { |
| return false; |
| } |
| +// Whether the request is missing a tabId and frameId and we're not expecting |
| +// a request with the given details. |
| +function isUnexpectedDetachedRequest(name, details) { |
|
battre
2015/12/15 12:53:09
Could you add some more comments that explain what
robwu
2015/12/15 13:17:25
Done.
|
| + if (details.tabId !== -1 || details.frameId >= 0) |
| + return false; |
| + |
| + return expectedEventData.every(function(exp) { |
| + return name !== exp.event || |
| + exp.details.tabId !== -1 || |
| + exp.details.frameId !== -1 || |
| + exp.details.method !== details.method || |
| + exp.details.url !== details.url || |
| + exp.details.type !== details.type; |
| + }); |
| +} |
| + |
| function captureEvent(name, details, callback) { |
| + // frameId should be -1 or positive, but is sometimes -2 (MSG_ROUTING_NONE). |
| + // TODO(robwu): This will be resolved once crbug.com/432875 is resolved. |
| + if (details.frameId === -2) |
| + details.frameId = -1; |
| + |
| // Ignore system-level requests like safebrowsing updates and favicon fetches |
| // since they are unpredictable. |
| - if (details.tabId == -1 || details.type == "other" || |
| + if (details.type == "other" || |
| + isUnexpectedDetachedRequest(name, details) || |
| details.url.match(/\/favicon.ico$/) || |
| details.url.match(/https:\/\/dl.google.com/)) |
| return; |
| @@ -218,7 +240,9 @@ function captureEvent(name, details, callback) { |
| // This assigns unique IDs to newly opened tabs. However, the new IDs are only |
| // deterministic, if the order in which the tabs are opened is deterministic. |
| if (!(details.tabId in tabIdMap)) { |
| - tabIdMap[details.tabId] = Object.keys(tabIdMap).length; |
| + // Subtract one because the map is initialized with {"-1": -1}, and the |
| + // first tab has ID 0. |
| + tabIdMap[details.tabId] = Object.keys(tabIdMap).length - 1; |
| } |
| details.tabId = tabIdMap[details.tabId]; |