| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // See ../test_declarative_permissions.js for the tests that use these rules. | |
| 6 | |
| 7 var onRequest = chrome.declarativeWebRequest.onRequest; | |
| 8 var RequestMatcher = chrome.declarativeWebRequest.RequestMatcher; | |
| 9 | |
| 10 chrome.test.getConfig(function(config) { | |
| 11 addRules(config.testServer.port); | |
| 12 }); | |
| 13 | |
| 14 function addRules(testServerPort) { | |
| 15 onRequest.addRules( | |
| 16 [{conditions: [new RequestMatcher({ | |
| 17 url: {hostSuffix: '.a.com', | |
| 18 schemes: ['https']}})], | |
| 19 actions: [new chrome.declarativeWebRequest.RedirectRequest({ | |
| 20 redirectUrl: 'http://www.a.com:' + testServerPort + | |
| 21 '/files/nonexistent/redirected' })] | |
| 22 }, | |
| 23 {conditions: [new RequestMatcher({ | |
| 24 url: {hostSuffix: '.a.com', | |
| 25 pathSuffix: '/b.html'}})], | |
| 26 actions: [new chrome.declarativeWebRequest.RedirectRequest({ | |
| 27 redirectUrl: 'http://www.c.com:' + testServerPort + | |
| 28 '/files/nonexistent/redirected' })] | |
| 29 }, | |
| 30 {conditions: [new RequestMatcher({ | |
| 31 url: {hostSuffix: '.a.com', | |
| 32 pathSuffix: '/fake.html'}})], | |
| 33 actions: [new chrome.declarativeWebRequest.RedirectByRegEx({ | |
| 34 from: '(.*)fake(.*)', to: '$1b$2' | |
| 35 })] | |
| 36 }, | |
| 37 | |
| 38 {conditions: [new RequestMatcher({url: {pathContains: 'blank'}})], | |
| 39 actions: [new chrome.declarativeWebRequest.RedirectToEmptyDocument()] | |
| 40 }, | |
| 41 {conditions: [new RequestMatcher({url: {pathContains: 'cancel'}})], | |
| 42 actions: [new chrome.declarativeWebRequest.CancelRequest()] | |
| 43 }], | |
| 44 function(rules) { | |
| 45 if (chrome.runtime.lastError) | |
| 46 chrome.test.fail(chrome.runtime.lastError); | |
| 47 chrome.test.sendMessage("rules all registered"); | |
| 48 } | |
| 49 ); | |
| 50 } | |
| OLD | NEW |