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 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 new RequestMatcher({url: {pathSuffix: "image.png"}})], | 398 new RequestMatcher({url: {pathSuffix: "image.png"}})], |
399 actions: [new RedirectToTransparentImage()]}, | 399 actions: [new RedirectToTransparentImage()]}, |
400 {conditions: [ | 400 {conditions: [ |
401 new RequestMatcher({url: {pathSuffix: "frame.html"}})], | 401 new RequestMatcher({url: {pathSuffix: "frame.html"}})], |
402 actions: [new RedirectToEmptyDocument()]}, | 402 actions: [new RedirectToEmptyDocument()]}, |
403 ], | 403 ], |
404 function() {navigateAndWait(getURLHttpRedirectTest());} | 404 function() {navigateAndWait(getURLHttpRedirectTest());} |
405 ); | 405 ); |
406 }, | 406 }, |
407 | 407 |
| 408 // Tests that a request is redirected during the onHeadersReceived stage |
| 409 // when the conditions include a RequestMatcher with a contentType. |
| 410 function testRedirectRequestByContentType() { |
| 411 ignoreUnexpected = true; |
| 412 expect( |
| 413 [ |
| 414 { label: "onBeforeRequest-a", |
| 415 event: "onBeforeRequest", |
| 416 details: { |
| 417 type: "main_frame", |
| 418 url: getURLHttpWithHeaders(), |
| 419 frameUrl: getURLHttpWithHeaders() |
| 420 }, |
| 421 }, |
| 422 { label: "onBeforeRedirect", |
| 423 event: "onBeforeRedirect", |
| 424 details: { |
| 425 url: getURLHttpWithHeaders(), |
| 426 redirectUrl: getURLHttpSimple(), |
| 427 statusLine: "", |
| 428 statusCode: -1, |
| 429 fromCache: false, |
| 430 } |
| 431 }, |
| 432 { label: "onBeforeRequest-b", |
| 433 event: "onBeforeRequest", |
| 434 details: { |
| 435 type: "main_frame", |
| 436 url: getURLHttpSimple(), |
| 437 frameUrl: getURLHttpSimple(), |
| 438 }, |
| 439 }, |
| 440 { label: "onCompleted", |
| 441 event: "onCompleted", |
| 442 details: { |
| 443 ip: "127.0.0.1", |
| 444 url: getURLHttpSimple(), |
| 445 fromCache: false, |
| 446 statusCode: 200, |
| 447 statusLine: "HTTP/1.1 200 OK", |
| 448 } |
| 449 }, |
| 450 ], |
| 451 [ ["onBeforeRequest-a", "onBeforeRedirect", "onBeforeRequest-b", |
| 452 "onCompleted"] ]); |
| 453 |
| 454 onRequest.addRules( |
| 455 [ {'conditions': [new RequestMatcher({'contentType': ["text/plain"]})], |
| 456 'actions': [ |
| 457 new RedirectRequest({'redirectUrl': getURLHttpSimple()})]} |
| 458 ], |
| 459 function() {navigateAndWait(getURLHttpWithHeaders());} |
| 460 ); |
| 461 }, |
| 462 |
408 function testRedirectByRegEx() { | 463 function testRedirectByRegEx() { |
409 ignoreUnexpected = true; | 464 ignoreUnexpected = true; |
410 expect( | 465 expect( |
411 [ | 466 [ |
412 { label: "onCompleted", | 467 { label: "onCompleted", |
413 event: "onCompleted", | 468 event: "onCompleted", |
414 details: { | 469 details: { |
415 ip: "127.0.0.1", | 470 ip: "127.0.0.1", |
416 url: getURLHttpSimpleB(), | 471 url: getURLHttpSimpleB(), |
417 fromCache: false, | 472 fromCache: false, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 'urlMatches': 'simple[A-Z].*a\.html$', | 507 'urlMatches': 'simple[A-Z].*a\.html$', |
453 'schemes': ["http"] | 508 'schemes': ["http"] |
454 }, | 509 }, |
455 })], | 510 })], |
456 'actions': [new CancelRequest()]} | 511 'actions': [new CancelRequest()]} |
457 ], | 512 ], |
458 function() {navigateAndWait(getURLHttpSimple());} | 513 function() {navigateAndWait(getURLHttpSimple());} |
459 ); | 514 ); |
460 }, | 515 }, |
461 ]); | 516 ]); |
OLD | NEW |