Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5244)

Unified Diff: chrome/test/data/extensions/api_test/webrequest/framework.js

Issue 1515703005: WebRequest API: add more resource types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments (creis, mattm, battre) Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..d540e8dbf6e5c9589f6545a574a0b5fa7344b927 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,34 @@ 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) {
+ if (details.tabId !== -1 || details.frameId >= 0)
battre 2015/12/15 13:32:55 // The event is considered expected if it happens
robwu 2015/12/15 14:13:30 Done, with a slightly different wording. It's not
+ return false;
+
+ // This only returns false if there is at least one expected event where the
+ // details match the given details.
battre 2015/12/15 13:32:55 I am struggling with the negations. Unexpected, a
robwu 2015/12/15 14:13:30 I've uploaded a new patchset that moves the negati
+ 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 +242,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];

Powered by Google App Engine
This is Rietveld 408576698