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

Unified Diff: chrome/test/data/extensions/api_test/webrequest/events/test.html

Issue 6698009: Add request_id to HttpRequestInfo and pass it to the NetworkDelegate for events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: delegate callbcak Created 9 years, 9 months 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/events/test.html
diff --git a/chrome/test/data/extensions/api_test/webrequest/events/test.html b/chrome/test/data/extensions/api_test/webrequest/events/test.html
index 83c1dba8301354d1ae98d6f839b490b325e9532d..90f3ad6ff6b94198f1564e626bea38f750c06c7e 100644
--- a/chrome/test/data/extensions/api_test/webrequest/events/test.html
+++ b/chrome/test/data/extensions/api_test/webrequest/events/test.html
@@ -2,6 +2,25 @@
var getURL = chrome.extension.getURL;
var expectedEventData;
var capturedEventData;
+var tabId;
+
+// PORT will be changed to the port of the test server.
+var URL_HTTP_SIMPLE_LOAD =
+ 'http://www.a.com:PORT/files/extensions/api_test/webrequest/events/simpleLoad/a.html';
+
+function runTests(tests) {
+ chrome.tabs.getSelected(null, function(tab) {
+ tabId = tab.id;
+ chrome.test.getConfig(function(config) {
+ var fixPort = function(url) {
+ return url.replace(/PORT/, config.testServer.port);
+ };
+ URL_HTTP_SIMPLE_LOAD = fixPort(URL_HTTP_SIMPLE_LOAD);
+
+ chrome.test.runTests(tests);
+ });
+ });
+}
function expect(data, filter, extraInfoSpec) {
expectedEventData = data;
@@ -36,6 +55,11 @@ function initListeners(filter, extraInfoSpec) {
captureEvent("onBeforeRequest", details);
return {cancel: true}; // no effect unless event is blocking.
}, filter, extraInfoSpec);
+ chrome.experimental.webRequest.onBeforeSendHeaders.addListener(
+ function(details) {
+ captureEvent("onBeforeSendHeaders", details);
+ return {cancel: true}; // no effect unless event is blocking.
+ }, filter, extraInfoSpec);
chrome.experimental.webRequest.onRequestSent.addListener(
function(details) {
captureEvent("onRequestSent", details);
@@ -74,6 +98,7 @@ function removeListeners() {
chrome.test.assertEq(0, event.subEvents_.length);
}
helper(chrome.experimental.webRequest.onBeforeRequest);
+ helper(chrome.experimental.webRequest.onBeforeSendHeaders);
helper(chrome.experimental.webRequest.onRequestSent);
helper(chrome.experimental.webRequest.onHeadersReceived);
helper(chrome.experimental.webRequest.onBeforeRedirect);
@@ -81,79 +106,121 @@ function removeListeners() {
helper(chrome.experimental.webRequest.onErrorOccurred);
}
-chrome.tabs.getSelected(null, function(tab) {
- var tabId = tab.id;
+runTests([
+ // Navigates to a blank page.
+ function simpleLoad() {
+ expect([
+ [ "onBeforeRequest",
+ {
+ method: "GET",
+ tabId: tabId,
+ type: "main_frame",
+ url: getURL("simpleLoad/a.html")
+ }
+ ],
+ ]);
+ chrome.tabs.update(tabId, { url: getURL("simpleLoad/a.html") });
+ },
- chrome.test.runTests([
- // Navigates to a blank page.
- function simpleLoad() {
- expect([
- [ "onBeforeRequest",
- {
- method: "GET",
- url: getURL("simpleLoad/a.html")
- }
- ],
- ]);
- chrome.tabs.update(tabId, { url: getURL("simpleLoad/a.html") });
- },
+ // Navigates to a blank page via HTTP. Only HTTP requests get the
+ // onBeforeSendHeaders event.
+ function simpleLoadHttp() {
+ expect([
+ [ "onBeforeRequest",
+ {
+ method: "GET",
+ tabId: tabId,
+ type: "main_frame",
+ url: URL_HTTP_SIMPLE_LOAD
+ }
+ ],
+ [ "onBeforeSendHeaders",
+ {
+ url: URL_HTTP_SIMPLE_LOAD
+ }
+ ],
+ ], {types: ["main_frame"]}, []);
+ chrome.tabs.update(tabId, { url: URL_HTTP_SIMPLE_LOAD });
+ },
- // Navigates to a page with subresources.
- // TODO(mpcomplete): add multiple subresources; requires support for
- // recognizing partial ordering.
- function complexLoad() {
- expect([
- [ "onBeforeRequest",
- {
- method: "GET",
- url: getURL("complexLoad/a.html")
- }
- ],
- [ "onBeforeRequest",
- {
- method: "GET",
- url: getURL("complexLoad/b.html")
- }
- ],
- [ "onBeforeRequest",
- {
- method: "GET",
- url: getURL("complexLoad/b.jpg")
- }
- ],
- ]);
- chrome.tabs.update(tabId, { url: getURL("complexLoad/a.html") });
- },
+ // Navigates to a page with subresources.
+ // TODO(mpcomplete): add multiple subresources; requires support for
+ // recognizing partial ordering.
+ function complexLoad() {
+ expect([
+ [ "onBeforeRequest",
+ {
+ method: "GET",
+ tabId: tabId,
+ type: "main_frame",
+ url: getURL("complexLoad/a.html")
+ }
+ ],
+ [ "onBeforeRequest",
+ {
+ method: "GET",
+ tabId: tabId,
+ type: "sub_frame",
+ url: getURL("complexLoad/b.html")
+ }
+ ],
+ [ "onBeforeRequest",
+ {
+ method: "GET",
+ tabId: tabId,
+ type: "image",
+ url: getURL("complexLoad/b.jpg")
+ }
+ ],
+ ]);
+ chrome.tabs.update(tabId, { url: getURL("complexLoad/a.html") });
+ },
- // Navigates to a page with subresources, with a blocking handler that
- // cancels the page request. The page will not load, and we should not
- // see the subresources.
- function complexLoadBlocking() {
- expect([
- [ "onBeforeRequest",
- {
- method: "GET",
- url: getURL("complexLoad/a.html")
- }
- ]
- ], {}, ["blocking"]);
- chrome.tabs.update(tabId, { url: getURL("complexLoad/a.html") });
- },
+ // Navigates to a page with subresources, with a blocking handler that
+ // cancels the page request. The page will not load, and we should not
+ // see the subresources.
+ function complexLoadBlocking() {
+ expect([
+ [ "onBeforeRequest",
+ {
+ method: "GET",
+ tabId: tabId,
+ type: "main_frame",
+ url: getURL("complexLoad/a.html")
+ }
+ ]
+ ], {}, ["blocking"]);
+ chrome.tabs.update(tabId, { url: getURL("complexLoad/a.html") });
+ },
- // Loads several resources, but should only see the simpleLoad
- // due to the filter.
- function simpleLoadFiltered() {
- expect([
- [ "onBeforeRequest",
- {
- method: "GET",
- url: getURL("simpleLoad/a.html")
- }
- ],
- ], {urls: [getURL("simpleLoad/*")]}, []);
+ // Loads several resources, but should only see the complexLoad main_frame
+ // and image due to the filter.
+ function complexLoadFiltered() {
+ expect([
+ [ "onBeforeRequest",
+ {
+ method: "GET",
+ tabId: tabId,
+ type: "main_frame",
+ url: getURL("complexLoad/a.html")
+ }
+ ],
+ [ "onBeforeRequest",
+ {
+ method: "GET",
+ tabId: tabId,
+ type: "image",
+ url: getURL("complexLoad/b.jpg")
+ }
+ ]
+ ], {urls: [getURL("complexLoad/*")],
+ types: ["main_frame", "image"],
+ tabId: tabId}, []);
+ chrome.tabs.create({ url: getURL("simpleLoad/a.html") },
+ function(newTab) {
+ chrome.tabs.remove(newTab.id);
chrome.tabs.update(tabId, { url: getURL("complexLoad/a.html") });
- chrome.tabs.create({ url: getURL("simpleLoad/a.html") });
- },
- ]);
-});
+ });
+ },
+]);
</script>

Powered by Google App Engine
This is Rietveld 408576698