| 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 92709cfb1a15ad0e6f9f5d3ae24488591d4807bd..eb695d7febc00088f7939773fa7c29f8e3cbadb1 100644
|
| --- a/chrome/test/data/extensions/api_test/webrequest/test_declarative.js
|
| +++ b/chrome/test/data/extensions/api_test/webrequest/test_declarative.js
|
| @@ -56,7 +56,7 @@ function getURLHttpWithHeaders() {
|
| "files/extensions/api_test/webrequest/declarative/headers.html");
|
| }
|
|
|
| -function getURLThirdParty() {
|
| +function getURLOfHTMLWithThirdParty() {
|
| // Returns the URL of a HTML document with a third-party resource.
|
| return getServerURL(
|
| "files/extensions/api_test/webrequest/declarative/third-party.html");
|
| @@ -86,29 +86,29 @@ function cancelThirdPartyExpected() {
|
| { label: "onBeforeRequest",
|
| event: "onBeforeRequest",
|
| details: {
|
| - url: getURLThirdParty(),
|
| - frameUrl: getURLThirdParty()
|
| + url: getURLOfHTMLWithThirdParty(),
|
| + frameUrl: getURLOfHTMLWithThirdParty()
|
| }
|
| },
|
| { label: "onBeforeSendHeaders",
|
| event: "onBeforeSendHeaders",
|
| - details: {url: getURLThirdParty()}
|
| + details: {url: getURLOfHTMLWithThirdParty()}
|
| },
|
| { label: "onSendHeaders",
|
| event: "onSendHeaders",
|
| - details: {url: getURLThirdParty()}
|
| + details: {url: getURLOfHTMLWithThirdParty()}
|
| },
|
| { label: "onHeadersReceived",
|
| event: "onHeadersReceived",
|
| details: {
|
| - url: getURLThirdParty(),
|
| + url: getURLOfHTMLWithThirdParty(),
|
| statusLine: "HTTP/1.0 200 OK"
|
| }
|
| },
|
| { label: "onResponseStarted",
|
| event: "onResponseStarted",
|
| details: {
|
| - url: getURLThirdParty(),
|
| + url: getURLOfHTMLWithThirdParty(),
|
| fromCache: false,
|
| ip: "127.0.0.1",
|
| statusCode: 200,
|
| @@ -120,7 +120,7 @@ function cancelThirdPartyExpected() {
|
| details: {
|
| fromCache: false,
|
| ip: "127.0.0.1",
|
| - url: getURLThirdParty(),
|
| + url: getURLOfHTMLWithThirdParty(),
|
| statusCode: 200,
|
| statusLine: "HTTP/1.0 200 OK"
|
| }
|
| @@ -130,7 +130,7 @@ function cancelThirdPartyExpected() {
|
| details: {
|
| type: "image",
|
| url: "http://non_existing_third_party.com/image.png",
|
| - frameUrl: getURLThirdParty()
|
| + frameUrl: getURLOfHTMLWithThirdParty()
|
| }
|
| },
|
| { label: "img-onErrorOccurred",
|
| @@ -248,7 +248,7 @@ runTests([
|
| onRequest.addRules(
|
| [ {'conditions': [new RequestMatcher({thirdPartyForCookies: true})],
|
| 'actions': [new chrome.declarativeWebRequest.CancelRequest()]},],
|
| - function() {navigateAndWait(getURLThirdParty());}
|
| + function() {navigateAndWait(getURLOfHTMLWithThirdParty());}
|
| );
|
| },
|
|
|
| @@ -273,7 +273,136 @@ runTests([
|
| 'actions': [new chrome.declarativeWebRequest.CancelRequest()]
|
| },
|
| ],
|
| - function() {navigateAndWait(getURLThirdParty());}
|
| + function() {navigateAndWait(getURLOfHTMLWithThirdParty());}
|
| + );
|
| + },
|
| +
|
| + // Tests "firstPartyForCookiesUrl" by using it to override a cancelling rule.
|
| + function testFirstPartyForCookiesUrl() {
|
| + // This test sets up three rules:
|
| + // Rule 1 is a priority 1 cancel-all rule to fire onBeforeRequest.
|
| + // Rule 2 is a priority 2 rule to ignore rule 1 for requests satisfying the
|
| + // first-party filter. This rule is the core of this test.
|
| + // Rule 3 is a priority 3 canceling rule for non-existing URLs. It will
|
| + // fire later, in stage onBeforeSendHeaders. This is necessary to avoid
|
| + // platform-dependent HTTP 404 responses.
|
| + ignoreUnexpected = false;
|
| + expect(
|
| + [
|
| + // This block of events is a successfull fetch of the main frame doc.
|
| + { label: "onBeforeRequest",
|
| + event: "onBeforeRequest",
|
| + details: {
|
| + url: getURLOfHTMLWithThirdParty(),
|
| + frameUrl: getURLOfHTMLWithThirdParty()
|
| + }
|
| + },
|
| + // Once we are here, rule 1 has been ignored.
|
| + { label: "onBeforeSendHeaders",
|
| + event: "onBeforeSendHeaders",
|
| + details: {url: getURLOfHTMLWithThirdParty()}
|
| + },
|
| + // Rule 3 does not apply, because the requested resource exists.
|
| + { label: "onSendHeaders",
|
| + event: "onSendHeaders",
|
| + details: {url: getURLOfHTMLWithThirdParty()}
|
| + },
|
| + { label: "onHeadersReceived",
|
| + event: "onHeadersReceived",
|
| + details: {
|
| + url: getURLOfHTMLWithThirdParty(),
|
| + statusLine: "HTTP/1.0 200 OK"
|
| + }
|
| + },
|
| + { label: "onResponseStarted",
|
| + event: "onResponseStarted",
|
| + details: {
|
| + url: getURLOfHTMLWithThirdParty(),
|
| + 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: getURLOfHTMLWithThirdParty(),
|
| + statusCode: 200,
|
| + statusLine: "HTTP/1.0 200 OK"
|
| + }
|
| + },
|
| +
|
| + // This block of events is a fetch of a non-existing sub-resource.
|
| + { label: "img-onBeforeRequest",
|
| + event: "onBeforeRequest",
|
| + details: {
|
| + type: "image",
|
| + url: "http://non_existing_third_party.com/image.png",
|
| + frameUrl: getURLOfHTMLWithThirdParty()
|
| + }
|
| + },
|
| + // Once we are here, rule 1 has been ignored.
|
| + { label: "img-onBeforeSendHeaders",
|
| + event: "onBeforeSendHeaders",
|
| + details: {
|
| + type: "image",
|
| + url: "http://non_existing_third_party.com/image.png",
|
| + }
|
| + },
|
| + // Rule 3 has fired, and saved us the trouble of getting a 404.
|
| + { label: "img-onErrorOccurred",
|
| + event: "onErrorOccurred",
|
| + details: {
|
| + url: "http://non_existing_third_party.com/image.png",
|
| + type: "image",
|
| + fromCache: false,
|
| + error: "net::ERR_BLOCKED_BY_CLIENT"
|
| + }
|
| + },
|
| + ],
|
| + [ ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
|
| + "onHeadersReceived", "onResponseStarted", "onCompleted"],
|
| + ["img-onBeforeRequest", "img-onBeforeSendHeaders",
|
| + "img-onErrorOccurred"] ]);
|
| + onRequest.addRules(
|
| + [ // This rule cancels everyhting, and sooner than the very last rule
|
| + // would. The test is reduced to making sure this (1st) rule was ignored
|
| + // as a consequence of the 2nd rule.
|
| + {'priority': 1,
|
| + 'conditions': [new RequestMatcher({
|
| + 'stages': ["onBeforeRequest"]
|
| + })],
|
| + 'actions': [new chrome.declarativeWebRequest.CancelRequest()]
|
| + },
|
| + {'priority': 2,
|
| + 'conditions': [
|
| + new RequestMatcher({
|
| + firstPartyForCookiesUrl: {
|
| + hostEquals: testServer
|
| + }
|
| + })
|
| + ],
|
| + 'actions': [
|
| + new chrome.declarativeWebRequest.IgnoreRules({
|
| + lowerPriorityThan: 2 })
|
| + ]
|
| + },
|
| + // This rule cancels the request with a 3rd party URL just before it is
|
| + // sent. This is necessary, because sending it would generate different
|
| + // HTTP 4xx codes on different platforms, making it impossible to
|
| + // present a single list of expected events.
|
| + {'priority': 3,
|
| + 'conditions': [new RequestMatcher({
|
| + 'url': { 'hostEquals': 'non_existing_third_party.com' },
|
| + 'stages': ["onBeforeSendHeaders"]
|
| + })],
|
| + 'actions': [new chrome.declarativeWebRequest.CancelRequest()]
|
| + },
|
| + ],
|
| + function() {navigateAndWait(getURLOfHTMLWithThirdParty());}
|
| );
|
| },
|
|
|
|
|