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
3 // found in the LICENSE file.
5 var pass = chrome.test.callbackPass;
7 // Constants as functions, not to be called until after runTests.
8 function getURLEchoUserAgent() {
9 return getServerURL('echoheader?User-Agent');
12 function getURLSetCookie() {
13 return getServerURL('set-cookie?Foo=Bar');
16 function getURLNonUTF8SetCookie() {
17 return getServerURL('set-header?Set-Cookie%3A%20Foo%3D%FE%D1');
20 function getURLHttpSimpleLoad() {
21 return getServerURL('extensions/api_test/webrequest/simpleLoad/a.html');
23 function getURLHttpXHRData() {
24 return getServerURL('extensions/api_test/webrequest/xhr/data.json');
27 function toCharCodes(str) {
29 for (var i = 0; i < str.length; ++i) {
30 result[i] = str.charCodeAt(i);
36 // Navigates to a page with subresources, with a blocking handler that
37 // cancels the page request. The page will not load, and we should not
38 // see the subresources.
39 function complexLoadCancelled() {
42 { label: "onBeforeRequest",
43 event: "onBeforeRequest",
46 url: getURL("complexLoad/b.html"),
47 frameUrl: getURL("complexLoad/b.html")
49 retval: {cancel: true}
51 // Cancelling is considered an error.
52 { label: "onErrorOccurred",
53 event: "onErrorOccurred",
55 url: getURL("complexLoad/b.html"),
57 error: "net::ERR_BLOCKED_BY_CLIENT"
58 // Request to chrome-extension:// url has no IP.
63 ["onBeforeRequest", "onErrorOccurred"]
65 {urls: ["<all_urls>"]}, // filter
67 navigateAndWait(getURL("complexLoad/b.html"));
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
72 // see the subresources.
73 function simpleLoadCancelledOnReceiveHeaders() {
76 { label: "onBeforeRequest",
77 event: "onBeforeRequest",
81 url: getURLHttpSimpleLoad(),
82 frameUrl: getURLHttpSimpleLoad()
84 retval: {cancel: false}
86 { label: "onBeforeSendHeaders",
87 event: "onBeforeSendHeaders",
89 url: getURLHttpSimpleLoad(),
90 // Note: no requestHeaders because we don't ask for them.
93 { label: "onSendHeaders",
94 event: "onSendHeaders",
96 url: getURLHttpSimpleLoad()
99 { label: "onHeadersReceived",
100 event: "onHeadersReceived",
102 url: getURLHttpSimpleLoad(),
103 statusLine: "HTTP/1.1 200 OK",
105 retval: {cancel: true}
107 // Cancelling is considered an error.
108 { label: "onErrorOccurred",
109 event: "onErrorOccurred",
111 url: getURLHttpSimpleLoad(),
113 error: "net::ERR_BLOCKED_BY_CLIENT"
114 // Request to chrome-extension:// url has no IP.
119 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
120 "onHeadersReceived", "onErrorOccurred"]
122 {urls: ["<all_urls>"]}, // filter
124 navigateAndWait(getURLHttpSimpleLoad());
127 // Navigates to a page and provides invalid header information. The request
128 // should continue as if the headers were not changed.
129 function simpleLoadIgnoreOnBeforeSendHeadersInvalidHeaders() {
132 { label: "onBeforeRequest",
133 event: "onBeforeRequest",
137 url: getURLHttpSimpleLoad(),
138 frameUrl: getURLHttpSimpleLoad()
141 { label: "onBeforeSendHeaders",
142 event: "onBeforeSendHeaders",
144 url: getURLHttpSimpleLoad(),
145 requestHeadersValid: true
147 retval: {requestHeaders: [{name: "User-Agent"}]}
149 // The headers were invalid, so they should not be modified.
150 // TODO(robwu): Test whether an error is logged to the console.
151 { label: "onSendHeaders",
152 event: "onSendHeaders",
154 url: getURLHttpSimpleLoad(),
155 requestHeadersValid: true
158 { label: "onHeadersReceived",
159 event: "onHeadersReceived",
161 url: getURLHttpSimpleLoad(),
162 statusLine: "HTTP/1.1 200 OK",
165 { label: "onResponseStarted",
166 event: "onResponseStarted",
168 url: getURLHttpSimpleLoad(),
172 statusLine: "HTTP/1.1 200 OK",
175 { label: "onCompleted",
176 event: "onCompleted",
178 url: getURLHttpSimpleLoad(),
182 statusLine: "HTTP/1.1 200 OK",
187 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
188 "onHeadersReceived", "onResponseStarted", "onCompleted"]
190 {urls: ["<all_urls>"]}, // filter
191 ["blocking", "requestHeaders"]);
192 navigateAndWait(getURLHttpSimpleLoad());
195 // Navigates to a page and provides invalid header information. The request
196 // should continue as if the headers were not changed.
197 function simpleLoadIgnoreOnBeforeSendHeadersInvalidResponse() {
198 // Exception handling seems to break this test, so disable it.
199 // See http://crbug.com/370897. TODO(robwu): Fix me.
200 chrome.test.setExceptionHandler(function(){});
203 { label: "onBeforeRequest",
204 event: "onBeforeRequest",
208 url: getURLHttpSimpleLoad(),
209 frameUrl: getURLHttpSimpleLoad()
212 { label: "onBeforeSendHeaders",
213 event: "onBeforeSendHeaders",
215 url: getURLHttpSimpleLoad(),
216 requestHeadersValid: true
220 // TODO(robwu): Test whether an error is logged to the console.
221 { label: "onSendHeaders",
222 event: "onSendHeaders",
224 url: getURLHttpSimpleLoad(),
225 requestHeadersValid: true
228 { label: "onHeadersReceived",
229 event: "onHeadersReceived",
231 url: getURLHttpSimpleLoad(),
232 statusLine: "HTTP/1.1 200 OK",
235 { label: "onResponseStarted",
236 event: "onResponseStarted",
238 url: getURLHttpSimpleLoad(),
242 statusLine: "HTTP/1.1 200 OK",
245 { label: "onCompleted",
246 event: "onCompleted",
248 url: getURLHttpSimpleLoad(),
252 statusLine: "HTTP/1.1 200 OK",
257 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
258 "onHeadersReceived", "onResponseStarted", "onCompleted"]
260 {urls: ["<all_urls>"]}, // filter
261 ["blocking", "requestHeaders"]);
262 navigateAndWait(getURLHttpSimpleLoad());
265 // Navigates to a page with a blocking handler that redirects to a different
267 function complexLoadRedirected() {
270 { label: "onBeforeRequest-1",
271 event: "onBeforeRequest",
273 url: getURL("complexLoad/a.html"),
274 frameUrl: getURL("complexLoad/a.html")
276 retval: {redirectUrl: getURL("simpleLoad/a.html")}
278 { label: "onBeforeRedirect",
279 event: "onBeforeRedirect",
281 url: getURL("complexLoad/a.html"),
282 redirectUrl: getURL("simpleLoad/a.html"),
284 statusLine: "HTTP/1.1 307 Internal Redirect",
288 { label: "onBeforeRequest-2",
289 event: "onBeforeRequest",
291 url: getURL("simpleLoad/a.html"),
292 frameUrl: getURL("simpleLoad/a.html"),
295 { label: "onResponseStarted",
296 event: "onResponseStarted",
298 url: getURL("simpleLoad/a.html"),
301 statusLine: "HTTP/1.1 200 OK",
302 // Request to chrome-extension:// url has no IP.
305 { label: "onCompleted",
306 event: "onCompleted",
308 url: getURL("simpleLoad/a.html"),
311 statusLine: "HTTP/1.1 200 OK",
312 // Request to chrome-extension:// url has no IP.
317 ["onBeforeRequest-1", "onBeforeRedirect", "onBeforeRequest-2",
318 "onResponseStarted", "onCompleted"],
320 {urls: ["<all_urls>"]}, // filter
322 navigateAndWait(getURL("complexLoad/a.html"));
325 // Tests redirect of <img crossorigin="anonymous" src="...">
326 function crossOriginAnonymousRedirect() {
327 testLoadCORSImage("anonymous");
330 // Tests redirect of <img crossorigin="use-credentials" src="...">
331 function crossOriginCredentialedRedirect() {
332 testLoadCORSImage("use-credentials");
335 // Loads a testserver page that echoes the User-Agent header that was
336 // sent to fetch it. We modify the outgoing User-Agent in
337 // onBeforeSendHeaders, so we should see that modified version.
338 function modifyRequestHeaders() {
341 { label: "onBeforeRequest",
342 event: "onBeforeRequest",
344 url: getURLEchoUserAgent(),
345 frameUrl: getURLEchoUserAgent()
348 { label: "onBeforeSendHeaders",
349 event: "onBeforeSendHeaders",
351 url: getURLEchoUserAgent(),
352 // Note: no requestHeaders because we don't ask for them.
354 retval: {requestHeaders: [{name: "User-Agent", value: "FoobarUA"}]}
356 { label: "onSendHeaders",
357 event: "onSendHeaders",
359 url: getURLEchoUserAgent()
362 { label: "onHeadersReceived",
363 event: "onHeadersReceived",
365 url: getURLEchoUserAgent(),
366 statusLine: "HTTP/1.1 200 OK",
369 { label: "onResponseStarted",
370 event: "onResponseStarted",
372 url: getURLEchoUserAgent(),
376 statusLine: "HTTP/1.1 200 OK",
379 { label: "onCompleted",
380 event: "onCompleted",
382 url: getURLEchoUserAgent(),
386 statusLine: "HTTP/1.1 200 OK",
391 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
392 "onHeadersReceived", "onResponseStarted", "onCompleted"]
394 {urls: ["<all_urls>"]}, ["blocking"]);
395 // Check the page content for our modified User-Agent string.
396 navigateAndWait(getURLEchoUserAgent(), function() {
397 chrome.test.listenOnce(chrome.extension.onRequest, function(request) {
398 chrome.test.assertTrue(request.pass, "Request header was not set.");
400 chrome.tabs.executeScript(tabId,
402 code: "chrome.extension.sendRequest(" +
403 "{pass: document.body.innerText.indexOf('FoobarUA') >= 0});"
408 // Loads a testserver page that echoes the User-Agent header that was
409 // sent to fetch it. We modify the outgoing User-Agent in
410 // onBeforeSendHeaders, so we should see that modified version.
411 // In this version we check whether we can set binary header values.
412 function modifyBinaryRequestHeaders() {
415 { label: "onBeforeRequest",
416 event: "onBeforeRequest",
418 url: getURLEchoUserAgent(),
419 frameUrl: getURLEchoUserAgent()
422 { label: "onBeforeSendHeaders",
423 event: "onBeforeSendHeaders",
425 url: getURLEchoUserAgent(),
426 // Note: no requestHeaders because we don't ask for them.
428 retval: {requestHeaders: [{name: "User-Agent",
429 binaryValue: toCharCodes("FoobarUA")}]}
431 { label: "onSendHeaders",
432 event: "onSendHeaders",
434 url: getURLEchoUserAgent()
437 { label: "onHeadersReceived",
438 event: "onHeadersReceived",
440 url: getURLEchoUserAgent(),
441 statusLine: "HTTP/1.1 200 OK",
444 { label: "onResponseStarted",
445 event: "onResponseStarted",
447 url: getURLEchoUserAgent(),
451 statusLine: "HTTP/1.1 200 OK",
454 { label: "onCompleted",
455 event: "onCompleted",
457 url: getURLEchoUserAgent(),
461 statusLine: "HTTP/1.1 200 OK",
466 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
467 "onHeadersReceived", "onResponseStarted", "onCompleted"]
469 {urls: ["<all_urls>"]}, ["blocking"]);
470 // Check the page content for our modified User-Agent string.
471 navigateAndWait(getURLEchoUserAgent(), function() {
472 chrome.test.listenOnce(chrome.extension.onRequest, function(request) {
473 chrome.test.assertTrue(request.pass, "Request header was not set.");
475 chrome.tabs.executeScript(tabId,
477 code: "chrome.extension.sendRequest(" +
478 "{pass: document.body.innerText.indexOf('FoobarUA') >= 0});"
483 // Loads a testserver page that sets a cookie "Foo=Bar" but removes
484 // the cookies from the response headers so that they are not set.
485 function modifyResponseHeaders() {
488 { label: "onBeforeRequest",
489 event: "onBeforeRequest",
493 url: getURLSetCookie(),
494 frameUrl: getURLSetCookie()
497 { label: "onBeforeSendHeaders",
498 event: "onBeforeSendHeaders",
500 url: getURLSetCookie(),
501 // Note: no requestHeaders because we don't ask for them.
504 { label: "onSendHeaders",
505 event: "onSendHeaders",
507 url: getURLSetCookie(),
510 { label: "onHeadersReceived",
511 event: "onHeadersReceived",
513 url: getURLSetCookie(),
514 statusLine: "HTTP/1.1 200 OK",
515 responseHeadersExist: true,
517 retval_function: function(name, details) {
518 responseHeaders = details.responseHeaders;
520 for (var i = 0; i < responseHeaders.length; ++i) {
521 if (responseHeaders[i].name === "Set-Cookie" &&
522 responseHeaders[i].value.indexOf("Foo") != -1) {
524 responseHeaders.splice(i);
528 chrome.test.assertTrue(found);
529 return {responseHeaders: responseHeaders};
532 { label: "onResponseStarted",
533 event: "onResponseStarted",
535 url: getURLSetCookie(),
538 statusLine: "HTTP/1.1 200 OK",
540 responseHeadersExist: true,
543 { label: "onCompleted",
544 event: "onCompleted",
546 url: getURLSetCookie(),
549 statusLine: "HTTP/1.1 200 OK",
551 responseHeadersExist: true,
556 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
557 "onHeadersReceived", "onResponseStarted", "onCompleted"]
559 {urls: ["<all_urls>"]}, ["blocking", "responseHeaders"]);
560 // Check that the cookie was really removed.
561 navigateAndWait(getURLSetCookie(), function() {
562 chrome.test.listenOnce(chrome.extension.onRequest, function(request) {
563 chrome.test.assertTrue(request.pass, "Cookie was not removed.");
565 chrome.tabs.executeScript(tabId,
566 { code: "chrome.extension.sendRequest(" +
567 "{pass: document.cookie.indexOf('Foo') == -1});"
572 // Loads a testserver page that sets a cookie "Foo=U+FDD1" which is not a
573 // valid UTF-8 code point. Therefore, it cannot be passed to JavaScript
574 // as a normal string.
575 function handleNonUTF8InModifyResponseHeaders() {
578 { label: "onBeforeRequest",
579 event: "onBeforeRequest",
583 url: getURLNonUTF8SetCookie(),
584 frameUrl: getURLNonUTF8SetCookie()
587 { label: "onBeforeSendHeaders",
588 event: "onBeforeSendHeaders",
590 url: getURLNonUTF8SetCookie(),
591 // Note: no requestHeaders because we don't ask for them.
594 { label: "onSendHeaders",
595 event: "onSendHeaders",
597 url: getURLNonUTF8SetCookie(),
600 { label: "onHeadersReceived",
601 event: "onHeadersReceived",
603 url: getURLNonUTF8SetCookie(),
604 statusLine: "HTTP/1.1 200 OK",
605 responseHeadersExist: true,
607 retval_function: function(name, details) {
608 responseHeaders = details.responseHeaders;
610 var expectedValue = [
617 for (var i = 0; i < responseHeaders.length; ++i) {
618 if (responseHeaders[i].name === "Set-Cookie" &&
619 deepEq(responseHeaders[i].binaryValue, expectedValue)) {
621 responseHeaders.splice(i);
625 chrome.test.assertTrue(found);
626 return {responseHeaders: responseHeaders};
629 { label: "onResponseStarted",
630 event: "onResponseStarted",
632 url: getURLNonUTF8SetCookie(),
635 statusLine: "HTTP/1.1 200 OK",
637 responseHeadersExist: true,
640 { label: "onCompleted",
641 event: "onCompleted",
643 url: getURLNonUTF8SetCookie(),
646 statusLine: "HTTP/1.1 200 OK",
648 responseHeadersExist: true,
653 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
654 "onHeadersReceived", "onResponseStarted", "onCompleted"]
656 {urls: ["<all_urls>"]}, ["blocking", "responseHeaders"]);
657 // Check that the cookie was really removed.
658 navigateAndWait(getURLNonUTF8SetCookie(), function() {
659 chrome.test.listenOnce(chrome.extension.onRequest, function(request) {
660 chrome.test.assertTrue(request.pass, "Cookie was not removed.");
662 chrome.tabs.executeScript(tabId,
663 { code: "chrome.extension.sendRequest(" +
664 "{pass: document.cookie.indexOf('Foo') == -1});"
669 // Navigates to a page with a blocking handler that redirects to a different
670 // non-http page during onHeadersReceived. The requested page should not be
671 // loaded, and the redirect should succeed.
672 function simpleLoadRedirectOnReceiveHeaders() {
675 { label: "onBeforeRequest-1",
676 event: "onBeforeRequest",
680 url: getURLHttpSimpleLoad(),
681 frameUrl: getURLHttpSimpleLoad()
684 { label: "onBeforeSendHeaders",
685 event: "onBeforeSendHeaders",
687 url: getURLHttpSimpleLoad(),
688 // Note: no requestHeaders because we don't ask for them.
691 { label: "onSendHeaders",
692 event: "onSendHeaders",
694 url: getURLHttpSimpleLoad()
697 { label: "onHeadersReceived",
698 event: "onHeadersReceived",
700 url: getURLHttpSimpleLoad(),
701 statusLine: "HTTP/1.1 200 OK",
703 retval: {redirectUrl: getURL("simpleLoad/a.html")}
705 { label: "onBeforeRedirect",
706 event: "onBeforeRedirect",
708 url: getURLHttpSimpleLoad(),
709 redirectUrl: getURL("simpleLoad/a.html"),
710 statusLine: "HTTP/1.1 302 Found",
716 { label: "onBeforeRequest-2",
717 event: "onBeforeRequest",
719 url: getURL("simpleLoad/a.html"),
720 frameUrl: getURL("simpleLoad/a.html"),
723 { label: "onResponseStarted",
724 event: "onResponseStarted",
726 url: getURL("simpleLoad/a.html"),
729 statusLine: "HTTP/1.1 200 OK",
730 // Request to chrome-extension:// url has no IP.
733 { label: "onCompleted",
734 event: "onCompleted",
736 url: getURL("simpleLoad/a.html"),
739 statusLine: "HTTP/1.1 200 OK",
740 // Request to chrome-extension:// url has no IP.
745 ["onBeforeRequest-1", "onBeforeSendHeaders", "onSendHeaders",
746 "onHeadersReceived", "onBeforeRedirect", "onBeforeRequest-2",
747 "onResponseStarted", "onCompleted"]
749 {urls: ["<all_urls>"]}, // filter
751 navigateAndWait(getURLHttpSimpleLoad());
754 // Checks that synchronous XHR requests from ourself are invisible to blocking
756 function syncXhrsFromOurselfAreInvisible() {
759 { label: "a-onBeforeRequest",
760 event: "onBeforeRequest",
762 url: getURL("simpleLoad/a.html"),
763 frameUrl: getURL("simpleLoad/a.html")
766 { label: "a-onResponseStarted",
767 event: "onResponseStarted",
769 url: getURL("simpleLoad/a.html"),
772 statusLine: "HTTP/1.1 200 OK",
773 // Request to chrome-extension:// url has no IP.
776 { label: "a-onCompleted",
777 event: "onCompleted",
779 url: getURL("simpleLoad/a.html"),
782 statusLine: "HTTP/1.1 200 OK",
783 // Request to chrome-extension:// url has no IP.
786 // We do not see onBeforeRequest for the XHR request here because it is
787 // handled by a blocking handler.
788 { label: "x-onSendHeaders",
789 event: "onSendHeaders",
791 url: getURLHttpXHRData(),
793 type: "xmlhttprequest",
796 { label: "x-onResponseStarted",
797 event: "onResponseStarted",
799 url: getURLHttpXHRData(),
802 statusLine: "HTTP/1.1 200 OK",
804 type: "xmlhttprequest",
806 // Request to chrome-extension:// url has no IP.
809 { label: "x-onCompleted",
810 event: "onCompleted",
812 url: getURLHttpXHRData(),
815 statusLine: "HTTP/1.1 200 OK",
817 type: "xmlhttprequest",
819 // Request to chrome-extension:// url has no IP.
822 { label: "b-onBeforeRequest",
823 event: "onBeforeRequest",
825 url: getURL("complexLoad/b.jpg"),
826 frameUrl: getURL("complexLoad/b.jpg")
829 { label: "b-onResponseStarted",
830 event: "onResponseStarted",
832 url: getURL("complexLoad/b.jpg"),
835 statusLine: "HTTP/1.1 200 OK",
836 // Request to chrome-extension:// url has no IP.
839 { label: "b-onCompleted",
840 event: "onCompleted",
842 url: getURL("complexLoad/b.jpg"),
845 statusLine: "HTTP/1.1 200 OK",
846 // Request to chrome-extension:// url has no IP.
851 ["a-onBeforeRequest", "a-onResponseStarted", "a-onCompleted",
852 "x-onSendHeaders", "x-onResponseStarted", "x-onCompleted",
853 "b-onBeforeRequest", "b-onResponseStarted", "b-onCompleted"]
855 {urls: ["<all_urls>"]}, ["blocking"]);
856 // Check the page content for our modified User-Agent string.
857 navigateAndWait(getURL("simpleLoad/a.html"), function() {
858 var req = new XMLHttpRequest();
859 var asynchronous = false;
860 req.open("GET", getURLHttpXHRData(), asynchronous);
862 navigateAndWait(getURL("complexLoad/b.jpg"));
866 // Checks that asynchronous XHR requests from ourself are visible to blocking
868 function asyncXhrsFromOurselfAreVisible() {
871 { label: "a-onBeforeRequest",
872 event: "onBeforeRequest",
874 url: getURL("simpleLoad/a.html"),
875 frameUrl: getURL("simpleLoad/a.html")
878 { label: "a-onResponseStarted",
879 event: "onResponseStarted",
881 url: getURL("simpleLoad/a.html"),
884 statusLine: "HTTP/1.1 200 OK",
885 // Request to chrome-extension:// url has no IP.
888 { label: "a-onCompleted",
889 event: "onCompleted",
891 url: getURL("simpleLoad/a.html"),
894 statusLine: "HTTP/1.1 200 OK",
895 // Request to chrome-extension:// url has no IP.
899 label: "x-onBeforeRequest",
900 event: "onBeforeRequest",
902 url: getURLHttpXHRData(),
904 type: "xmlhttprequest",
905 frameUrl: "unknown frame URL",
909 label: "x-onBeforeSendHeaders",
910 event: "onBeforeSendHeaders",
912 url: getURLHttpXHRData(),
914 type: "xmlhttprequest",
917 { label: "x-onSendHeaders",
918 event: "onSendHeaders",
920 url: getURLHttpXHRData(),
922 type: "xmlhttprequest",
925 { label: "x-onResponseStarted",
926 event: "onResponseStarted",
928 url: getURLHttpXHRData(),
931 statusLine: "HTTP/1.1 200 OK",
933 type: "xmlhttprequest",
935 // Request to chrome-extension:// url has no IP.
939 label: "x-onHeadersReceived",
940 event: "onHeadersReceived",
942 url: getURLHttpXHRData(),
944 type: "xmlhttprequest",
945 statusLine: "HTTP/1.1 200 OK",
948 { label: "x-onCompleted",
949 event: "onCompleted",
951 url: getURLHttpXHRData(),
954 statusLine: "HTTP/1.1 200 OK",
956 type: "xmlhttprequest",
958 // Request to chrome-extension:// url has no IP.
961 { label: "b-onBeforeRequest",
962 event: "onBeforeRequest",
964 url: getURL("complexLoad/b.jpg"),
965 frameUrl: getURL("complexLoad/b.jpg")
968 { label: "b-onResponseStarted",
969 event: "onResponseStarted",
971 url: getURL("complexLoad/b.jpg"),
974 statusLine: "HTTP/1.1 200 OK",
975 // Request to chrome-extension:// url has no IP.
978 { label: "b-onCompleted",
979 event: "onCompleted",
981 url: getURL("complexLoad/b.jpg"),
984 statusLine: "HTTP/1.1 200 OK",
985 // Request to chrome-extension:// url has no IP.
990 ["a-onBeforeRequest", "a-onResponseStarted", "a-onCompleted",
991 "x-onBeforeRequest", "x-onBeforeSendHeaders", "x-onSendHeaders",
992 "x-onHeadersReceived", "x-onResponseStarted", "x-onCompleted"],
993 ["a-onCompleted", "x-onBeforeRequest",
994 "b-onBeforeRequest", "b-onResponseStarted", "b-onCompleted"]
996 {urls: ["<all_urls>"]}, ["blocking"]);
997 // Check the page content for our modified User-Agent string.
998 navigateAndWait(getURL("simpleLoad/a.html"), function() {
999 var req = new XMLHttpRequest();
1000 var asynchronous = true;
1001 req.open("GET", getURLHttpXHRData(), asynchronous);
1003 navigateAndWait(getURL("complexLoad/b.jpg"));
1009 // This helper verifies that extensions can successfully redirect resources even
1010 // if cross-origin access control is in effect via the crossorigin attribute.
1011 // Used by crossOriginAnonymousRedirect and crossOriginCredentialedRedirect.
1012 function testLoadCORSImage(crossOriginAttributeValue) {
1013 // (Non-existent) image URL, with random query string to bust the cache.
1014 var requestedUrl = getServerURL("cors/intercepted_by_extension.gif?" +
1015 Math.random(), "original.tld");
1016 var frameUrl = getServerURL(
1017 "extensions/api_test/webrequest/cors/load_image.html?" +
1018 "crossOrigin=" + crossOriginAttributeValue +
1019 "&src=" + encodeURIComponent(requestedUrl));
1020 var redirectTarget = getServerURL(
1021 "extensions/api_test/webrequest/cors/redirect_target.gif", "domain.tld");
1024 { label: "onBeforeRequest-1",
1025 event: "onBeforeRequest",
1029 // Frame URL unavailable because requests are filtered by type=image.
1030 frameUrl: "unknown frame URL",
1032 retval: {redirectUrl: redirectTarget}
1034 { label: "onBeforeRedirect",
1035 event: "onBeforeRedirect",
1039 redirectUrl: redirectTarget,
1040 statusLine: "HTTP/1.1 307 Internal Redirect",
1045 { label: "onBeforeRequest-2",
1046 event: "onBeforeRequest",
1049 url: redirectTarget,
1050 // Frame URL unavailable because requests are filtered by type=image.
1051 frameUrl: "unknown frame URL",
1055 label: "onBeforeSendHeaders",
1056 event: "onBeforeSendHeaders",
1059 url: redirectTarget,
1063 label: "onSendHeaders",
1064 event: "onSendHeaders",
1067 url: redirectTarget,
1071 label: "onHeadersReceived",
1072 event: "onHeadersReceived",
1075 url: redirectTarget,
1076 statusLine: "HTTP/1.1 200 OK",
1079 { label: "onResponseStarted",
1080 event: "onResponseStarted",
1083 url: redirectTarget,
1087 statusLine: "HTTP/1.1 200 OK",
1090 { label: "onCompleted",
1091 event: "onCompleted",
1094 url: redirectTarget,
1098 statusLine: "HTTP/1.1 200 OK",
1101 // After the image loads, the test will load the following URL
1102 // to signal that the test succeeded.
1104 label: "onBeforeRequest-3",
1105 event: "onBeforeRequest",
1108 url: getServerURL("signal_that_image_loaded_successfully"),
1109 // Frame URL unavailable because requests are filtered by type=image.
1110 frameUrl: "unknown frame URL",
1112 retval: {cancel: true}
1114 { label: "onErrorOccurred",
1115 event: "onErrorOccurred",
1118 url: getServerURL("signal_that_image_loaded_successfully"),
1120 error: "net::ERR_BLOCKED_BY_CLIENT",
1125 ["onBeforeRequest-1", "onBeforeRedirect", "onBeforeRequest-2",
1126 "onBeforeSendHeaders", "onSendHeaders", "onHeadersReceived",
1127 "onResponseStarted", "onCompleted",
1128 "onBeforeRequest-3", "onErrorOccurred"],
1130 {urls: ["<all_urls>"], types: ['image']}, // filter
1132 navigateAndWait(frameUrl);