Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(600)

Side by Side Diff: chrome/test/data/extensions/api_test/webrequest/test_declarative.js

Issue 10449069: Support redirects by regular expression in declarative WebRequest API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 RedirectRequest = chrome.declarativeWebRequest.RedirectRequest; 11 var RedirectRequest = chrome.declarativeWebRequest.RedirectRequest;
11 var RedirectToTransparentImage = 12 var RedirectToTransparentImage =
12 chrome.declarativeWebRequest.RedirectToTransparentImage; 13 chrome.declarativeWebRequest.RedirectToTransparentImage;
13 var RedirectToEmptyDocument = 14 var RedirectToEmptyDocument =
14 chrome.declarativeWebRequest.RedirectToEmptyDocument; 15 chrome.declarativeWebRequest.RedirectToEmptyDocument;
15 var SetRequestHeader = 16 var SetRequestHeader =
16 chrome.declarativeWebRequest.SetRequestHeader; 17 chrome.declarativeWebRequest.SetRequestHeader;
17 var RemoveRequestHeader = 18 var RemoveRequestHeader =
18 chrome.declarativeWebRequest.RemoveRequestHeader; 19 chrome.declarativeWebRequest.RemoveRequestHeader;
19 var RemoveResponseHeader = 20 var RemoveResponseHeader =
20 chrome.declarativeWebRequest.RemoveResponseHeader; 21 chrome.declarativeWebRequest.RemoveResponseHeader;
21 var IgnoreRules = 22 var IgnoreRules =
22 chrome.declarativeWebRequest.IgnoreRules; 23 chrome.declarativeWebRequest.IgnoreRules;
23 24
24 // Constants as functions, not to be called until after runTests. 25 // Constants as functions, not to be called until after runTests.
25 function getURLEchoUserAgent() { 26 function getURLEchoUserAgent() {
26 return getServerURL('echoheader?User-Agent'); 27 return getServerURL('echoheader?User-Agent');
27 } 28 }
28 29
29 function getURLHttpSimple() { 30 function getURLHttpSimple() {
30 return getServerURL("files/extensions/api_test/webrequest/simpleLoad/a.html"); 31 return getServerURL("files/extensions/api_test/webrequest/simpleLoad/a.html");
31 } 32 }
32 33
34 function getURLHttpSimpleB() {
35 return getServerURL("files/extensions/api_test/webrequest/simpleLoad/b.html");
36 }
37
33 function getURLHttpComplex() { 38 function getURLHttpComplex() {
34 return getServerURL( 39 return getServerURL(
35 "files/extensions/api_test/webrequest/complexLoad/a.html"); 40 "files/extensions/api_test/webrequest/complexLoad/a.html");
36 } 41 }
37 42
38 function getURLHttpRedirectTest() { 43 function getURLHttpRedirectTest() {
39 return getServerURL( 44 return getServerURL(
40 "files/extensions/api_test/webrequest/declarative/a.html"); 45 "files/extensions/api_test/webrequest/declarative/a.html");
41 } 46 }
42 47
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 new RequestMatcher({url: {pathSuffix: "image.png"}})], 184 new RequestMatcher({url: {pathSuffix: "image.png"}})],
180 actions: [new RedirectToTransparentImage()]}, 185 actions: [new RedirectToTransparentImage()]},
181 {conditions: [ 186 {conditions: [
182 new RequestMatcher({url: {pathSuffix: "frame.html"}})], 187 new RequestMatcher({url: {pathSuffix: "frame.html"}})],
183 actions: [new RedirectToEmptyDocument()]}, 188 actions: [new RedirectToEmptyDocument()]},
184 ], 189 ],
185 function() {navigateAndWait(getURLHttpRedirectTest());} 190 function() {navigateAndWait(getURLHttpRedirectTest());}
186 ); 191 );
187 }, 192 },
188 193
194 function testRedirectByRegEx() {
195 ignoreUnexpected = true;
196 expect(
197 [
198 { label: "onCompleted",
199 event: "onCompleted",
200 details: {
201 ip: "127.0.0.1",
202 url: getURLHttpSimpleB(),
203 fromCache: false,
204 statusCode: 200,
205 statusLine: "HTTP/1.0 200 OK",
206 }
207 },
208 ],
209 [ ["onCompleted"] ]);
210
211 onRequest.addRules(
212 [ {conditions: [new RequestMatcher({url: {pathSuffix: ".html"}})],
213 actions: [
214 new RedirectByRegEx({from: "^(.*)/a.html$", to: "$1/b.html"})]}
215 ],
216 function() {navigateAndWait(getURLHttpSimple());}
217 );
218 },
219
189 function testSetRequestHeader() { 220 function testSetRequestHeader() {
190 ignoreUnexpected = true; 221 ignoreUnexpected = true;
191 expect(); // Used for initialization. 222 expect(); // Used for initialization.
192 onRequest.addRules( 223 onRequest.addRules(
193 [{conditions: [new RequestMatcher()], 224 [{conditions: [new RequestMatcher()],
194 actions: [new SetRequestHeader({name: "User-Agent", value: "FoobarUA"})] 225 actions: [new SetRequestHeader({name: "User-Agent", value: "FoobarUA"})]
195 }], 226 }],
196 function() { 227 function() {
197 // Check the page content for our modified User-Agent string. 228 // Check the page content for our modified User-Agent string.
198 navigateAndWait(getURLEchoUserAgent(), function() { 229 navigateAndWait(getURLEchoUserAgent(), function() {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 actions: [new CancelRequest()]}, 326 actions: [new CancelRequest()]},
296 {conditions: [new RequestMatcher({url: {pathContains: "a.html"}})], 327 {conditions: [new RequestMatcher({url: {pathContains: "a.html"}})],
297 actions: [new IgnoreRules({lowerPriorityThan: 200})], 328 actions: [new IgnoreRules({lowerPriorityThan: 200})],
298 priority: 200} 329 priority: 200}
299 ], 330 ],
300 function() {navigateAndWait(getURLHttpSimple());} 331 function() {navigateAndWait(getURLHttpSimple());}
301 ); 332 );
302 }, 333 },
303 334
304 ]); 335 ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698