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

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

Issue 8879011: Make URL filter for web request API mandatory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 pass = chrome.test.callbackPass; 5 var pass = chrome.test.callbackPass;
6 6
7 // Constants as functions, not to be called until after runTests. 7 // Constants as functions, not to be called until after runTests.
8 function getURLEchoUserAgent() { 8 function getURLEchoUserAgent() {
9 return getServerURL('echoheader?User-Agent'); 9 return getServerURL('echoheader?User-Agent');
10 } 10 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 url: getURL("complexLoad/b.html"), 55 url: getURL("complexLoad/b.html"),
56 fromCache: false, 56 fromCache: false,
57 error: "net::ERR_BLOCKED_BY_CLIENT" 57 error: "net::ERR_BLOCKED_BY_CLIENT"
58 // Request to chrome-extension:// url has no IP. 58 // Request to chrome-extension:// url has no IP.
59 } 59 }
60 }, 60 },
61 ], 61 ],
62 [ // event order 62 [ // event order
63 ["onBeforeRequest", "onErrorOccurred"] 63 ["onBeforeRequest", "onErrorOccurred"]
64 ], 64 ],
65 {}, // filter 65 {urls: ["<all_urls>"]}, // filter
66 ["blocking"]); 66 ["blocking"]);
67 navigateAndWait(getURL("complexLoad/b.html")); 67 navigateAndWait(getURL("complexLoad/b.html"));
68 }, 68 },
69 69
70 // Navigates to a page with subresources, with a blocking handler that 70 // Navigates to a page with subresources, with a blocking handler that
71 // cancels the page request. The page will not load, and we should not 71 // cancels the page request. The page will not load, and we should not
72 // see the subresources. 72 // see the subresources.
73 function simpleLoadCancelledOnReceiveHeaders() { 73 function simpleLoadCancelledOnReceiveHeaders() {
74 expect( 74 expect(
75 [ // events 75 [ // events
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 fromCache: false, 112 fromCache: false,
113 error: "net::ERR_BLOCKED_BY_CLIENT" 113 error: "net::ERR_BLOCKED_BY_CLIENT"
114 // Request to chrome-extension:// url has no IP. 114 // Request to chrome-extension:// url has no IP.
115 } 115 }
116 }, 116 },
117 ], 117 ],
118 [ // event order 118 [ // event order
119 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", 119 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
120 "onHeadersReceived", "onErrorOccurred"] 120 "onHeadersReceived", "onErrorOccurred"]
121 ], 121 ],
122 {}, // filter 122 {urls: ["<all_urls>"]}, // filter
123 ["blocking"]); 123 ["blocking"]);
124 navigateAndWait(getURLHttpSimpleLoad()); 124 navigateAndWait(getURLHttpSimpleLoad());
125 }, 125 },
126 126
127 // Navigates to a page with a blocking handler that redirects to a different 127 // Navigates to a page with a blocking handler that redirects to a different
128 // page. 128 // page.
129 // TODO(mpcomplete): We should see an onBeforeRedirect as well, but our 129 // TODO(mpcomplete): We should see an onBeforeRedirect as well, but our
130 // process switching logic cancels the original redirect request and 130 // process switching logic cancels the original redirect request and
131 // starts a new one instead. See http://crbug.com/79520. 131 // starts a new one instead. See http://crbug.com/79520.
132 function complexLoadRedirected() { 132 function complexLoadRedirected() {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 statusCode: 200, 174 statusCode: 200,
175 statusLine: "HTTP/1.1 200 OK", 175 statusLine: "HTTP/1.1 200 OK",
176 // Request to chrome-extension:// url has no IP. 176 // Request to chrome-extension:// url has no IP.
177 } 177 }
178 }, 178 },
179 ], 179 ],
180 [ // event order 180 [ // event order
181 ["onBeforeRequest-1", "onErrorOccurred-1", "onBeforeRequest-2", 181 ["onBeforeRequest-1", "onErrorOccurred-1", "onBeforeRequest-2",
182 "onResponseStarted", "onCompleted"], 182 "onResponseStarted", "onCompleted"],
183 ], 183 ],
184 {}, // filter 184 {urls: ["<all_urls>"]}, // filter
185 ["blocking"]); 185 ["blocking"]);
186 navigateAndWait(getURL("complexLoad/a.html")); 186 navigateAndWait(getURL("complexLoad/a.html"));
187 }, 187 },
188 188
189 // Loads a testserver page that echoes the User-Agent header that was 189 // Loads a testserver page that echoes the User-Agent header that was
190 // sent to fetch it. We modify the outgoing User-Agent in 190 // sent to fetch it. We modify the outgoing User-Agent in
191 // onBeforeSendHeaders, so we should see that modified version. 191 // onBeforeSendHeaders, so we should see that modified version.
192 function modifyRequestHeaders() { 192 function modifyRequestHeaders() {
193 expect( 193 expect(
194 [ // events 194 [ // events
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 statusCode: 200, 238 statusCode: 200,
239 ip: "127.0.0.1", 239 ip: "127.0.0.1",
240 statusLine: "HTTP/1.0 200 OK", 240 statusLine: "HTTP/1.0 200 OK",
241 } 241 }
242 }, 242 },
243 ], 243 ],
244 [ // event order 244 [ // event order
245 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", 245 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
246 "onHeadersReceived", "onResponseStarted", "onCompleted"] 246 "onHeadersReceived", "onResponseStarted", "onCompleted"]
247 ], 247 ],
248 {}, ["blocking"]); 248 {urls: ["<all_urls>"]}, ["blocking"]);
249 // Check the page content for our modified User-Agent string. 249 // Check the page content for our modified User-Agent string.
250 navigateAndWait(getURLEchoUserAgent(), function() { 250 navigateAndWait(getURLEchoUserAgent(), function() {
251 chrome.test.listenOnce(chrome.extension.onRequest, function(request) { 251 chrome.test.listenOnce(chrome.extension.onRequest, function(request) {
252 chrome.test.assertTrue(request.pass, "Request header was not set."); 252 chrome.test.assertTrue(request.pass, "Request header was not set.");
253 }); 253 });
254 chrome.tabs.executeScript(tabId, 254 chrome.tabs.executeScript(tabId,
255 { 255 {
256 code: "chrome.extension.sendRequest(" + 256 code: "chrome.extension.sendRequest(" +
257 "{pass: document.body.innerText.indexOf('FoobarUA') >= 0});" 257 "{pass: document.body.innerText.indexOf('FoobarUA') >= 0});"
258 }); 258 });
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 statusCode: 200, 313 statusCode: 200,
314 ip: "127.0.0.1", 314 ip: "127.0.0.1",
315 statusLine: "HTTP/1.0 200 OK", 315 statusLine: "HTTP/1.0 200 OK",
316 } 316 }
317 }, 317 },
318 ], 318 ],
319 [ // event order 319 [ // event order
320 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", 320 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
321 "onHeadersReceived", "onResponseStarted", "onCompleted"] 321 "onHeadersReceived", "onResponseStarted", "onCompleted"]
322 ], 322 ],
323 {}, ["blocking"]); 323 {urls: ["<all_urls>"]}, ["blocking"]);
324 // Check the page content for our modified User-Agent string. 324 // Check the page content for our modified User-Agent string.
325 navigateAndWait(getURLEchoUserAgent(), function() { 325 navigateAndWait(getURLEchoUserAgent(), function() {
326 chrome.test.listenOnce(chrome.extension.onRequest, function(request) { 326 chrome.test.listenOnce(chrome.extension.onRequest, function(request) {
327 chrome.test.assertTrue(request.pass, "Request header was not set."); 327 chrome.test.assertTrue(request.pass, "Request header was not set.");
328 }); 328 });
329 chrome.tabs.executeScript(tabId, 329 chrome.tabs.executeScript(tabId,
330 { 330 {
331 code: "chrome.extension.sendRequest(" + 331 code: "chrome.extension.sendRequest(" +
332 "{pass: document.body.innerText.indexOf('FoobarUA') >= 0});" 332 "{pass: document.body.innerText.indexOf('FoobarUA') >= 0});"
333 }); 333 });
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 statusLine: "HTTP/1.0 200 OK", 403 statusLine: "HTTP/1.0 200 OK",
404 ip: "127.0.0.1", 404 ip: "127.0.0.1",
405 responseHeadersExist: true, 405 responseHeadersExist: true,
406 } 406 }
407 }, 407 },
408 ], 408 ],
409 [ // event order 409 [ // event order
410 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", 410 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
411 "onHeadersReceived", "onResponseStarted", "onCompleted"] 411 "onHeadersReceived", "onResponseStarted", "onCompleted"]
412 ], 412 ],
413 {}, ["blocking", "responseHeaders"]); 413 {urls: ["<all_urls>"]}, ["blocking", "responseHeaders"]);
414 // Check that the cookie was really removed. 414 // Check that the cookie was really removed.
415 navigateAndWait(getURLSetCookie(), function() { 415 navigateAndWait(getURLSetCookie(), function() {
416 chrome.test.listenOnce(chrome.extension.onRequest, function(request) { 416 chrome.test.listenOnce(chrome.extension.onRequest, function(request) {
417 chrome.test.assertTrue(request.pass, "Cookie was not removed."); 417 chrome.test.assertTrue(request.pass, "Cookie was not removed.");
418 }); 418 });
419 chrome.tabs.executeScript(tabId, 419 chrome.tabs.executeScript(tabId,
420 { code: "chrome.extension.sendRequest(" + 420 { code: "chrome.extension.sendRequest(" +
421 "{pass: document.cookie.indexOf('Foo') == -1});" 421 "{pass: document.cookie.indexOf('Foo') == -1});"
422 }); 422 });
423 }); 423 });
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 statusLine: "HTTP/1.0 200 OK", 501 statusLine: "HTTP/1.0 200 OK",
502 ip: "127.0.0.1", 502 ip: "127.0.0.1",
503 responseHeadersExist: true, 503 responseHeadersExist: true,
504 } 504 }
505 }, 505 },
506 ], 506 ],
507 [ // event order 507 [ // event order
508 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", 508 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
509 "onHeadersReceived", "onResponseStarted", "onCompleted"] 509 "onHeadersReceived", "onResponseStarted", "onCompleted"]
510 ], 510 ],
511 {}, ["blocking", "responseHeaders"]); 511 {urls: ["<all_urls>"]}, ["blocking", "responseHeaders"]);
512 // Check that the cookie was really removed. 512 // Check that the cookie was really removed.
513 navigateAndWait(getURLNonUTF8SetCookie(), function() { 513 navigateAndWait(getURLNonUTF8SetCookie(), function() {
514 chrome.test.listenOnce(chrome.extension.onRequest, function(request) { 514 chrome.test.listenOnce(chrome.extension.onRequest, function(request) {
515 chrome.test.assertTrue(request.pass, "Cookie was not removed."); 515 chrome.test.assertTrue(request.pass, "Cookie was not removed.");
516 }); 516 });
517 chrome.tabs.executeScript(tabId, 517 chrome.tabs.executeScript(tabId,
518 { code: "chrome.extension.sendRequest(" + 518 { code: "chrome.extension.sendRequest(" +
519 "{pass: document.cookie.indexOf('Foo') == -1});" 519 "{pass: document.cookie.indexOf('Foo') == -1});"
520 }); 520 });
521 }); 521 });
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 statusLine: "HTTP/1.1 200 OK", 614 statusLine: "HTTP/1.1 200 OK",
615 // Request to chrome-extension:// url has no IP. 615 // Request to chrome-extension:// url has no IP.
616 } 616 }
617 }, 617 },
618 ], 618 ],
619 [ // event order 619 [ // event order
620 ["a-onBeforeRequest", "a-onResponseStarted", "a-onCompleted", 620 ["a-onBeforeRequest", "a-onResponseStarted", "a-onCompleted",
621 "x-onSendHeaders", "x-onResponseStarted", "x-onCompleted", 621 "x-onSendHeaders", "x-onResponseStarted", "x-onCompleted",
622 "b-onBeforeRequest", "b-onResponseStarted", "b-onCompleted"] 622 "b-onBeforeRequest", "b-onResponseStarted", "b-onCompleted"]
623 ], 623 ],
624 {}, ["blocking"]); 624 {urls: ["<all_urls>"]}, ["blocking"]);
625 // Check the page content for our modified User-Agent string. 625 // Check the page content for our modified User-Agent string.
626 navigateAndWait(getURL("simpleLoad/a.html"), function() { 626 navigateAndWait(getURL("simpleLoad/a.html"), function() {
627 var req = new XMLHttpRequest(); 627 var req = new XMLHttpRequest();
628 var asynchronous = false; 628 var asynchronous = false;
629 req.open("GET", getURLHttpXHRData(), asynchronous); 629 req.open("GET", getURLHttpXHRData(), asynchronous);
630 req.send(null); 630 req.send(null);
631 navigateAndWait(getURL("complexLoad/b.jpg")); 631 navigateAndWait(getURL("complexLoad/b.jpg"));
632 }); 632 });
633 }, 633 },
634 ]); 634 ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698