Chromium Code Reviews| Index: chrome/test/data/extensions/api_test/webrequest/test_declarative.js |
| diff --git a/chrome/test/data/extensions/api_test/webrequest/test_declarative.js b/chrome/test/data/extensions/api_test/webrequest/test_declarative.js |
| index 91fb9aeafcb8f1ec5b54b4f52b136cd8c598f889..6097e0dcff1c1933d99b6521f7b4312eeaf91736 100644 |
| --- a/chrome/test/data/extensions/api_test/webrequest/test_declarative.js |
| +++ b/chrome/test/data/extensions/api_test/webrequest/test_declarative.js |
| @@ -56,6 +56,11 @@ function getURLHttpWithHeaders() { |
| "files/extensions/api_test/webrequest/declarative/headers.html"); |
| } |
| +function getURLParties() { |
|
battre
2012/10/05 12:57:33
Can you add a comment why this is called getURLPar
vabr (Chromium)
2012/10/05 16:13:27
Done. On a second thought, the "parties" name soun
|
| + return getServerURL( |
| + "files/extensions/api_test/webrequest/declarative/parties.html"); |
| +} |
| + |
| function getURLSetCookie() { |
| return getServerURL('set-cookie?Foo=Bar'); |
| } |
| @@ -79,6 +84,79 @@ function getURLHttpSimpleOnB() { |
| "b.com"); |
| } |
| +// Shared test sections. |
| +function cancelThirdPartyExpected() { |
| + return [ |
| + { label: "onBeforeRequest", |
| + event: "onBeforeRequest", |
| + details: { |
| + url: getURLParties(), |
| + frameUrl: getURLParties() |
| + } |
| + }, |
| + { label: "onBeforeSendHeaders", |
| + event: "onBeforeSendHeaders", |
| + details: {url: getURLParties()} |
| + }, |
| + { label: "onSendHeaders", |
| + event: "onSendHeaders", |
| + details: {url: getURLParties()} |
| + }, |
| + { label: "onHeadersReceived", |
| + event: "onHeadersReceived", |
| + details: { |
| + url: getURLParties(), |
| + statusLine: "HTTP/1.0 200 OK" |
| + } |
| + }, |
| + { label: "onResponseStarted", |
| + event: "onResponseStarted", |
| + details: { |
| + url: getURLParties(), |
| + fromCache: false, |
| + ip: "127.0.0.1", |
| + statusCode: 200, |
| + statusLine: "HTTP/1.0 200 OK" |
| + } |
| + }, |
| + { label: "onCompleted", |
| + event: "onCompleted", |
| + details: { |
| + fromCache: false, |
| + ip: "127.0.0.1", |
| + url: getURLParties(), |
| + statusCode: 200, |
| + statusLine: "HTTP/1.0 200 OK" |
| + } |
| + }, |
| + { label: "img-onBeforeRequest", |
| + event: "onBeforeRequest", |
| + details: { |
| + type: "image", |
| + url: "http://non_existing_third_party.com/image.png", |
| + frameUrl: getURLParties() |
| + } |
| + }, |
| + { label: "img-onErrorOccurred", |
| + event: "onErrorOccurred", |
| + details: { |
| + error: "net::ERR_BLOCKED_BY_CLIENT", |
| + fromCache: false, |
| + type: "image", |
| + url: "http://non_existing_third_party.com/image.png" |
| + } |
| + }, |
| + ]; |
| +} |
| + |
| +function cancelThirdPartyExpectedOrder() { |
| + return [ |
| + ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", |
| + "onHeadersReceived", "onResponseStarted", "onCompleted"], |
| + ["img-onBeforeRequest", "img-onErrorOccurred"] |
| + ]; |
| +} |
| + |
| runTests([ |
| function testCancelRequest() { |
| @@ -114,6 +192,42 @@ runTests([ |
| ); |
| }, |
| + // Tests that "thirdPartyForCookies: true" matches third party requests. |
| + function testThirdParty() { |
| + ignoreUnexpected = false; |
| + expect(cancelThirdPartyExpected(), cancelThirdPartyExpectedOrder()); |
| + onRequest.addRules( |
| + [ {'conditions': [new RequestMatcher({thirdPartyForCookies: true})], |
| + 'actions': [new chrome.declarativeWebRequest.CancelRequest()]},], |
| + function() {navigateAndWait(getURLParties());} |
| + ); |
| + }, |
| + |
| + // Tests that "thirdPartyForCookies: false" matches first party requests, |
| + // by cancelling all requests, and overriding the cancelling rule only for |
| + // requests matching "thirdPartyForCookies: false". |
| + function testFirstParty() { |
| + ignoreUnexpected = false; |
| + expect(cancelThirdPartyExpected(), cancelThirdPartyExpectedOrder()); |
| + onRequest.addRules( |
| + [ {'priority': 2, |
| + 'conditions': [ |
| + new RequestMatcher({thirdPartyForCookies: false}) |
| + ], |
| + 'actions': [ |
| + new chrome.declarativeWebRequest.IgnoreRules({ |
| + lowerPriorityThan: 2 }) |
| + ] |
| + }, |
| + {'priority': 1, |
| + 'conditions': [new RequestMatcher({})], |
| + 'actions': [new chrome.declarativeWebRequest.CancelRequest()] |
| + }, |
| + ], |
| + function() {navigateAndWait(getURLParties());} |
| + ); |
| + }, |
| + |
| function testRedirectRequest() { |
| ignoreUnexpected = true; |
| expect( |