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

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

Issue 10982044: Adding thirdParty property to RequestMatcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Jochen's comments Created 8 years, 2 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
« no previous file with comments | « chrome/test/data/extensions/api_test/webrequest/manifest.json ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 RedirectByRegEx = chrome.declarativeWebRequest.RedirectByRegEx;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 getURLParties() {
battre 2012/10/05 12:57:33 Can you add a comment why this is called getURLPar
vabr (Chromium) 2012/10/05 16:13:27 Done. On a second thought, the "parties" name soun
60 return getServerURL(
61 "files/extensions/api_test/webrequest/declarative/parties.html");
62 }
63
59 function getURLSetCookie() { 64 function getURLSetCookie() {
60 return getServerURL('set-cookie?Foo=Bar'); 65 return getServerURL('set-cookie?Foo=Bar');
61 } 66 }
62 67
63 function getURLSetCookie2() { 68 function getURLSetCookie2() {
64 return getServerURL('set-cookie?passedCookie=Foo&editedCookie=Foo&' + 69 return getServerURL('set-cookie?passedCookie=Foo&editedCookie=Foo&' +
65 'deletedCookie=Foo'); 70 'deletedCookie=Foo');
66 } 71 }
67 72
68 function getURLEchoCookie() { 73 function getURLEchoCookie() {
69 return getServerURL('echoheader?Cookie'); 74 return getServerURL('echoheader?Cookie');
70 } 75 }
71 76
72 function getURLHttpXHRData() { 77 function getURLHttpXHRData() {
73 return getServerURL("files/extensions/api_test/webrequest/xhr/data.json", 78 return getServerURL("files/extensions/api_test/webrequest/xhr/data.json",
74 "b.com"); 79 "b.com");
75 } 80 }
76 81
77 function getURLHttpSimpleOnB() { 82 function getURLHttpSimpleOnB() {
78 return getServerURL("files/extensions/api_test/webrequest/simpleLoad/a.html", 83 return getServerURL("files/extensions/api_test/webrequest/simpleLoad/a.html",
79 "b.com"); 84 "b.com");
80 } 85 }
81 86
87 // Shared test sections.
88 function cancelThirdPartyExpected() {
89 return [
90 { label: "onBeforeRequest",
91 event: "onBeforeRequest",
92 details: {
93 url: getURLParties(),
94 frameUrl: getURLParties()
95 }
96 },
97 { label: "onBeforeSendHeaders",
98 event: "onBeforeSendHeaders",
99 details: {url: getURLParties()}
100 },
101 { label: "onSendHeaders",
102 event: "onSendHeaders",
103 details: {url: getURLParties()}
104 },
105 { label: "onHeadersReceived",
106 event: "onHeadersReceived",
107 details: {
108 url: getURLParties(),
109 statusLine: "HTTP/1.0 200 OK"
110 }
111 },
112 { label: "onResponseStarted",
113 event: "onResponseStarted",
114 details: {
115 url: getURLParties(),
116 fromCache: false,
117 ip: "127.0.0.1",
118 statusCode: 200,
119 statusLine: "HTTP/1.0 200 OK"
120 }
121 },
122 { label: "onCompleted",
123 event: "onCompleted",
124 details: {
125 fromCache: false,
126 ip: "127.0.0.1",
127 url: getURLParties(),
128 statusCode: 200,
129 statusLine: "HTTP/1.0 200 OK"
130 }
131 },
132 { label: "img-onBeforeRequest",
133 event: "onBeforeRequest",
134 details: {
135 type: "image",
136 url: "http://non_existing_third_party.com/image.png",
137 frameUrl: getURLParties()
138 }
139 },
140 { label: "img-onErrorOccurred",
141 event: "onErrorOccurred",
142 details: {
143 error: "net::ERR_BLOCKED_BY_CLIENT",
144 fromCache: false,
145 type: "image",
146 url: "http://non_existing_third_party.com/image.png"
147 }
148 },
149 ];
150 }
151
152 function cancelThirdPartyExpectedOrder() {
153 return [
154 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
155 "onHeadersReceived", "onResponseStarted", "onCompleted"],
156 ["img-onBeforeRequest", "img-onErrorOccurred"]
157 ];
158 }
159
82 runTests([ 160 runTests([
83 161
84 function testCancelRequest() { 162 function testCancelRequest() {
85 ignoreUnexpected = true; 163 ignoreUnexpected = true;
86 expect( 164 expect(
87 [ 165 [
88 { label: "onErrorOccurred", 166 { label: "onErrorOccurred",
89 event: "onErrorOccurred", 167 event: "onErrorOccurred",
90 details: { 168 details: {
91 url: getURLHttpWithHeaders(), 169 url: getURLHttpWithHeaders(),
(...skipping 15 matching lines...) Expand all
107 'contentType': ["text/plain"], 185 'contentType': ["text/plain"],
108 'excludeContentType': ["image/png"], 186 'excludeContentType': ["image/png"],
109 'responseHeaders': [{ nameContains: ["content", "type"] } ], 187 'responseHeaders': [{ nameContains: ["content", "type"] } ],
110 'excludeResponseHeaders': [{ valueContains: "nonsense" }] })], 188 'excludeResponseHeaders': [{ valueContains: "nonsense" }] })],
111 'actions': [new CancelRequest()]} 189 'actions': [new CancelRequest()]}
112 ], 190 ],
113 function() {navigateAndWait(getURLHttpWithHeaders());} 191 function() {navigateAndWait(getURLHttpWithHeaders());}
114 ); 192 );
115 }, 193 },
116 194
195 // Tests that "thirdPartyForCookies: true" matches third party requests.
196 function testThirdParty() {
197 ignoreUnexpected = false;
198 expect(cancelThirdPartyExpected(), cancelThirdPartyExpectedOrder());
199 onRequest.addRules(
200 [ {'conditions': [new RequestMatcher({thirdPartyForCookies: true})],
201 'actions': [new chrome.declarativeWebRequest.CancelRequest()]},],
202 function() {navigateAndWait(getURLParties());}
203 );
204 },
205
206 // Tests that "thirdPartyForCookies: false" matches first party requests,
207 // by cancelling all requests, and overriding the cancelling rule only for
208 // requests matching "thirdPartyForCookies: false".
209 function testFirstParty() {
210 ignoreUnexpected = false;
211 expect(cancelThirdPartyExpected(), cancelThirdPartyExpectedOrder());
212 onRequest.addRules(
213 [ {'priority': 2,
214 'conditions': [
215 new RequestMatcher({thirdPartyForCookies: false})
216 ],
217 'actions': [
218 new chrome.declarativeWebRequest.IgnoreRules({
219 lowerPriorityThan: 2 })
220 ]
221 },
222 {'priority': 1,
223 'conditions': [new RequestMatcher({})],
224 'actions': [new chrome.declarativeWebRequest.CancelRequest()]
225 },
226 ],
227 function() {navigateAndWait(getURLParties());}
228 );
229 },
230
117 function testRedirectRequest() { 231 function testRedirectRequest() {
118 ignoreUnexpected = true; 232 ignoreUnexpected = true;
119 expect( 233 expect(
120 [ 234 [
121 { label: "onBeforeRequest-a", 235 { label: "onBeforeRequest-a",
122 event: "onBeforeRequest", 236 event: "onBeforeRequest",
123 details: { 237 details: {
124 type: "main_frame", 238 type: "main_frame",
125 url: getURLHttpComplex(), 239 url: getURLHttpComplex(),
126 frameUrl: getURLHttpComplex() 240 frameUrl: getURLHttpComplex()
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 this.status + ", responseText: " + this.responseText); 612 this.status + ", responseText: " + this.responseText);
499 } 613 }
500 } 614 }
501 req.open("GET", getURLHttpXHRData(), asynchronous); 615 req.open("GET", getURLHttpXHRData(), asynchronous);
502 req.send(null); 616 req.send(null);
503 }); 617 });
504 } 618 }
505 ); 619 );
506 }, 620 },
507 ]); 621 ]);
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/webrequest/manifest.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698