| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var onRequest = chrome.declarativeWebRequest.onRequest; | 5 var onRequest = chrome.declarativeWebRequest.onRequest; |
| 6 var AddResponseHeader = | 6 var AddResponseHeader = |
| 7 chrome.declarativeWebRequest.AddResponseHeader; | 7 chrome.declarativeWebRequest.AddResponseHeader; |
| 8 var RequestMatcher = chrome.declarativeWebRequest.RequestMatcher; | 8 var RequestMatcher = chrome.declarativeWebRequest.RequestMatcher; |
| 9 var CancelRequest = chrome.declarativeWebRequest.CancelRequest; | 9 var CancelRequest = chrome.declarativeWebRequest.CancelRequest; |
| 10 var RedirectByRegEx = chrome.declarativeWebRequest.RedirectByRegEx; | 10 var RedirectByRegEx = chrome.declarativeWebRequest.RedirectByRegEx; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 function getURLHttpRedirectTest() { | 49 function getURLHttpRedirectTest() { |
| 50 return getServerURL( | 50 return getServerURL( |
| 51 "files/extensions/api_test/webrequest/declarative/a.html"); | 51 "files/extensions/api_test/webrequest/declarative/a.html"); |
| 52 } | 52 } |
| 53 | 53 |
| 54 function getURLHttpWithHeaders() { | 54 function getURLHttpWithHeaders() { |
| 55 return getServerURL( | 55 return getServerURL( |
| 56 "files/extensions/api_test/webrequest/declarative/headers.html"); | 56 "files/extensions/api_test/webrequest/declarative/headers.html"); |
| 57 } | 57 } |
| 58 | 58 |
| 59 function getURLThirdParty() { | 59 function getURLOfHTMLWithThirdParty() { |
| 60 // Returns the URL of a HTML document with a third-party resource. | 60 // Returns the URL of a HTML document with a third-party resource. |
| 61 return getServerURL( | 61 return getServerURL( |
| 62 "files/extensions/api_test/webrequest/declarative/third-party.html"); | 62 "files/extensions/api_test/webrequest/declarative/third-party.html"); |
| 63 } | 63 } |
| 64 | 64 |
| 65 function getURLSetCookie() { | 65 function getURLSetCookie() { |
| 66 return getServerURL('set-cookie?Foo=Bar'); | 66 return getServerURL('set-cookie?Foo=Bar'); |
| 67 } | 67 } |
| 68 | 68 |
| 69 function getURLSetCookie2() { | 69 function getURLSetCookie2() { |
| 70 return getServerURL('set-cookie?passedCookie=Foo&editedCookie=Foo&' + | 70 return getServerURL('set-cookie?passedCookie=Foo&editedCookie=Foo&' + |
| 71 'deletedCookie=Foo'); | 71 'deletedCookie=Foo'); |
| 72 } | 72 } |
| 73 | 73 |
| 74 function getURLEchoCookie() { | 74 function getURLEchoCookie() { |
| 75 return getServerURL('echoheader?Cookie'); | 75 return getServerURL('echoheader?Cookie'); |
| 76 } | 76 } |
| 77 | 77 |
| 78 function getURLHttpXHRData() { | 78 function getURLHttpXHRData() { |
| 79 return getServerURL("files/extensions/api_test/webrequest/xhr/data.json", | 79 return getServerURL("files/extensions/api_test/webrequest/xhr/data.json", |
| 80 "b.com"); | 80 "b.com"); |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Shared test sections. | 83 // Shared test sections. |
| 84 function cancelThirdPartyExpected() { | 84 function cancelThirdPartyExpected() { |
| 85 return [ | 85 return [ |
| 86 { label: "onBeforeRequest", | 86 { label: "onBeforeRequest", |
| 87 event: "onBeforeRequest", | 87 event: "onBeforeRequest", |
| 88 details: { | 88 details: { |
| 89 url: getURLThirdParty(), | 89 url: getURLOfHTMLWithThirdParty(), |
| 90 frameUrl: getURLThirdParty() | 90 frameUrl: getURLOfHTMLWithThirdParty() |
| 91 } | 91 } |
| 92 }, | 92 }, |
| 93 { label: "onBeforeSendHeaders", | 93 { label: "onBeforeSendHeaders", |
| 94 event: "onBeforeSendHeaders", | 94 event: "onBeforeSendHeaders", |
| 95 details: {url: getURLThirdParty()} | 95 details: {url: getURLOfHTMLWithThirdParty()} |
| 96 }, | 96 }, |
| 97 { label: "onSendHeaders", | 97 { label: "onSendHeaders", |
| 98 event: "onSendHeaders", | 98 event: "onSendHeaders", |
| 99 details: {url: getURLThirdParty()} | 99 details: {url: getURLOfHTMLWithThirdParty()} |
| 100 }, | 100 }, |
| 101 { label: "onHeadersReceived", | 101 { label: "onHeadersReceived", |
| 102 event: "onHeadersReceived", | 102 event: "onHeadersReceived", |
| 103 details: { | 103 details: { |
| 104 url: getURLThirdParty(), | 104 url: getURLOfHTMLWithThirdParty(), |
| 105 statusLine: "HTTP/1.0 200 OK" | 105 statusLine: "HTTP/1.0 200 OK" |
| 106 } | 106 } |
| 107 }, | 107 }, |
| 108 { label: "onResponseStarted", | 108 { label: "onResponseStarted", |
| 109 event: "onResponseStarted", | 109 event: "onResponseStarted", |
| 110 details: { | 110 details: { |
| 111 url: getURLThirdParty(), | 111 url: getURLOfHTMLWithThirdParty(), |
| 112 fromCache: false, | 112 fromCache: false, |
| 113 ip: "127.0.0.1", | 113 ip: "127.0.0.1", |
| 114 statusCode: 200, | 114 statusCode: 200, |
| 115 statusLine: "HTTP/1.0 200 OK" | 115 statusLine: "HTTP/1.0 200 OK" |
| 116 } | 116 } |
| 117 }, | 117 }, |
| 118 { label: "onCompleted", | 118 { label: "onCompleted", |
| 119 event: "onCompleted", | 119 event: "onCompleted", |
| 120 details: { | 120 details: { |
| 121 fromCache: false, | 121 fromCache: false, |
| 122 ip: "127.0.0.1", | 122 ip: "127.0.0.1", |
| 123 url: getURLThirdParty(), | 123 url: getURLOfHTMLWithThirdParty(), |
| 124 statusCode: 200, | 124 statusCode: 200, |
| 125 statusLine: "HTTP/1.0 200 OK" | 125 statusLine: "HTTP/1.0 200 OK" |
| 126 } | 126 } |
| 127 }, | 127 }, |
| 128 { label: "img-onBeforeRequest", | 128 { label: "img-onBeforeRequest", |
| 129 event: "onBeforeRequest", | 129 event: "onBeforeRequest", |
| 130 details: { | 130 details: { |
| 131 type: "image", | 131 type: "image", |
| 132 url: "http://non_existing_third_party.com/image.png", | 132 url: "http://non_existing_third_party.com/image.png", |
| 133 frameUrl: getURLThirdParty() | 133 frameUrl: getURLOfHTMLWithThirdParty() |
| 134 } | 134 } |
| 135 }, | 135 }, |
| 136 { label: "img-onErrorOccurred", | 136 { label: "img-onErrorOccurred", |
| 137 event: "onErrorOccurred", | 137 event: "onErrorOccurred", |
| 138 details: { | 138 details: { |
| 139 error: "net::ERR_BLOCKED_BY_CLIENT", | 139 error: "net::ERR_BLOCKED_BY_CLIENT", |
| 140 fromCache: false, | 140 fromCache: false, |
| 141 type: "image", | 141 type: "image", |
| 142 url: "http://non_existing_third_party.com/image.png" | 142 url: "http://non_existing_third_party.com/image.png" |
| 143 } | 143 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 function() {navigateAndWait(getURLHttpWithHeaders());} | 241 function() {navigateAndWait(getURLHttpWithHeaders());} |
| 242 ); | 242 ); |
| 243 }, | 243 }, |
| 244 // Tests that "thirdPartyForCookies: true" matches third party requests. | 244 // Tests that "thirdPartyForCookies: true" matches third party requests. |
| 245 function testThirdParty() { | 245 function testThirdParty() { |
| 246 ignoreUnexpected = false; | 246 ignoreUnexpected = false; |
| 247 expect(cancelThirdPartyExpected(), cancelThirdPartyExpectedOrder()); | 247 expect(cancelThirdPartyExpected(), cancelThirdPartyExpectedOrder()); |
| 248 onRequest.addRules( | 248 onRequest.addRules( |
| 249 [ {'conditions': [new RequestMatcher({thirdPartyForCookies: true})], | 249 [ {'conditions': [new RequestMatcher({thirdPartyForCookies: true})], |
| 250 'actions': [new chrome.declarativeWebRequest.CancelRequest()]},], | 250 'actions': [new chrome.declarativeWebRequest.CancelRequest()]},], |
| 251 function() {navigateAndWait(getURLThirdParty());} | 251 function() {navigateAndWait(getURLOfHTMLWithThirdParty());} |
| 252 ); | 252 ); |
| 253 }, | 253 }, |
| 254 | 254 |
| 255 // Tests that "thirdPartyForCookies: false" matches first party requests, | 255 // Tests that "thirdPartyForCookies: false" matches first party requests, |
| 256 // by cancelling all requests, and overriding the cancelling rule only for | 256 // by cancelling all requests, and overriding the cancelling rule only for |
| 257 // requests matching "thirdPartyForCookies: false". | 257 // requests matching "thirdPartyForCookies: false". |
| 258 function testFirstParty() { | 258 function testFirstParty() { |
| 259 ignoreUnexpected = false; | 259 ignoreUnexpected = false; |
| 260 expect(cancelThirdPartyExpected(), cancelThirdPartyExpectedOrder()); | 260 expect(cancelThirdPartyExpected(), cancelThirdPartyExpectedOrder()); |
| 261 onRequest.addRules( | 261 onRequest.addRules( |
| 262 [ {'priority': 2, | 262 [ {'priority': 2, |
| 263 'conditions': [ | 263 'conditions': [ |
| 264 new RequestMatcher({thirdPartyForCookies: false}) | 264 new RequestMatcher({thirdPartyForCookies: false}) |
| 265 ], | 265 ], |
| 266 'actions': [ | 266 'actions': [ |
| 267 new chrome.declarativeWebRequest.IgnoreRules({ | 267 new chrome.declarativeWebRequest.IgnoreRules({ |
| 268 lowerPriorityThan: 2 }) | 268 lowerPriorityThan: 2 }) |
| 269 ] | 269 ] |
| 270 }, | 270 }, |
| 271 {'priority': 1, | 271 {'priority': 1, |
| 272 'conditions': [new RequestMatcher({})], | 272 'conditions': [new RequestMatcher({})], |
| 273 'actions': [new chrome.declarativeWebRequest.CancelRequest()] | 273 'actions': [new chrome.declarativeWebRequest.CancelRequest()] |
| 274 }, | 274 }, |
| 275 ], | 275 ], |
| 276 function() {navigateAndWait(getURLThirdParty());} | 276 function() {navigateAndWait(getURLOfHTMLWithThirdParty());} |
| 277 ); | 277 ); |
| 278 }, | 278 }, |
| 279 | 279 |
| 280 function testFirstPartyForCookiesUrl() { |
| 281 // This is an end-to-end test for firstPartyForCookies. The choice of URL to |
| 282 // navigate to is purely arbitrary. |
| 283 ignoreUnexpected = false; |
| 284 expect( |
| 285 [ |
| 286 { label: "onBeforeRequest", |
| 287 event: "onBeforeRequest", |
| 288 details: { |
| 289 url: getURLOfHTMLWithThirdParty(), |
| 290 frameUrl: getURLOfHTMLWithThirdParty() |
| 291 } |
| 292 }, |
| 293 { label: "onErrorOccurred", |
| 294 event: "onErrorOccurred", |
| 295 details: { |
| 296 url: getURLOfHTMLWithThirdParty(), |
| 297 fromCache: false, |
| 298 error: "net::ERR_BLOCKED_BY_CLIENT" |
| 299 } |
| 300 }, |
| 301 ], |
| 302 [ ["onBeforeRequest", "onErrorOccurred"] ]); |
| 303 onRequest.addRules( |
| 304 [ {'conditions': [ |
| 305 new RequestMatcher({ |
| 306 firstPartyForCookiesUrl: { |
| 307 hostEquals: testServer |
| 308 } |
| 309 }) |
| 310 ], |
| 311 'actions': [new chrome.declarativeWebRequest.CancelRequest()] |
| 312 }, |
| 313 ], |
| 314 function() {navigateAndWait(getURLOfHTMLWithThirdParty());} |
| 315 ); |
| 316 }, |
| 317 |
| 280 function testRedirectRequest() { | 318 function testRedirectRequest() { |
| 281 ignoreUnexpected = true; | 319 ignoreUnexpected = true; |
| 282 expect( | 320 expect( |
| 283 [ | 321 [ |
| 284 { label: "onBeforeRequest-a", | 322 { label: "onBeforeRequest-a", |
| 285 event: "onBeforeRequest", | 323 event: "onBeforeRequest", |
| 286 details: { | 324 details: { |
| 287 type: "main_frame", | 325 type: "main_frame", |
| 288 url: getURLHttpComplex(), | 326 url: getURLHttpComplex(), |
| 289 frameUrl: getURLHttpComplex() | 327 frameUrl: getURLHttpComplex() |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 }, | 732 }, |
| 695 'requestHeaders': [{ nameContains: "" }], | 733 'requestHeaders': [{ nameContains: "" }], |
| 696 'excludeRequestHeaders': [{ valueContains: ["", "value123"] }] | 734 'excludeRequestHeaders': [{ valueContains: ["", "value123"] }] |
| 697 })], | 735 })], |
| 698 'actions': [new CancelRequest()]} | 736 'actions': [new CancelRequest()]} |
| 699 ], | 737 ], |
| 700 function() {navigateAndWait(getURLHttpSimple());} | 738 function() {navigateAndWait(getURLHttpSimple());} |
| 701 ); | 739 ); |
| 702 }, | 740 }, |
| 703 ]); | 741 ]); |
| OLD | NEW |