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",
106 retval: {cancel: true}
108 // Cancelling is considered an error.
109 { label: "onErrorOccurred",
110 event: "onErrorOccurred",
112 url: getURLHttpSimpleLoad(),
114 error: "net::ERR_BLOCKED_BY_CLIENT"
115 // Request to chrome-extension:// url has no IP.
120 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
121 "onHeadersReceived", "onErrorOccurred"]
123 {urls: ["<all_urls>"]}, // filter
125 navigateAndWait(getURLHttpSimpleLoad());
128 // Navigates to a page and provides invalid header information. The request
129 // should continue as if the headers were not changed.
130 function simpleLoadIgnoreOnBeforeSendHeadersInvalidHeaders() {
133 { label: "onBeforeRequest",
134 event: "onBeforeRequest",
138 url: getURLHttpSimpleLoad(),
139 frameUrl: getURLHttpSimpleLoad()
142 { label: "onBeforeSendHeaders",
143 event: "onBeforeSendHeaders",
145 url: getURLHttpSimpleLoad(),
146 requestHeadersValid: true
148 retval: {requestHeaders: [{name: "User-Agent"}]}
150 // The headers were invalid, so they should not be modified.
151 // TODO(robwu): Test whether an error is logged to the console.
152 { label: "onSendHeaders",
153 event: "onSendHeaders",
155 url: getURLHttpSimpleLoad(),
156 requestHeadersValid: true
159 { label: "onHeadersReceived",
160 event: "onHeadersReceived",
162 url: getURLHttpSimpleLoad(),
163 statusLine: "HTTP/1.1 200 OK",
167 { label: "onResponseStarted",
168 event: "onResponseStarted",
170 url: getURLHttpSimpleLoad(),
174 statusLine: "HTTP/1.1 200 OK",
177 { label: "onCompleted",
178 event: "onCompleted",
180 url: getURLHttpSimpleLoad(),
184 statusLine: "HTTP/1.1 200 OK",
189 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
190 "onHeadersReceived", "onResponseStarted", "onCompleted"]
192 {urls: ["<all_urls>"]}, // filter
193 ["blocking", "requestHeaders"]);
194 navigateAndWait(getURLHttpSimpleLoad());
197 // Navigates to a page and provides invalid header information. The request
198 // should continue as if the headers were not changed.
199 function simpleLoadIgnoreOnBeforeSendHeadersInvalidResponse() {
200 // Exception handling seems to break this test, so disable it.
201 // See http://crbug.com/370897. TODO(robwu): Fix me.
202 chrome.test.setExceptionHandler(function(){});
205 { label: "onBeforeRequest",
206 event: "onBeforeRequest",
210 url: getURLHttpSimpleLoad(),
211 frameUrl: getURLHttpSimpleLoad()
214 { label: "onBeforeSendHeaders",
215 event: "onBeforeSendHeaders",
217 url: getURLHttpSimpleLoad(),
218 requestHeadersValid: true
222 // TODO(robwu): Test whether an error is logged to the console.
223 { label: "onSendHeaders",
224 event: "onSendHeaders",
226 url: getURLHttpSimpleLoad(),
227 requestHeadersValid: true
230 { label: "onHeadersReceived",
231 event: "onHeadersReceived",
233 url: getURLHttpSimpleLoad(),
234 statusLine: "HTTP/1.1 200 OK",
238 { label: "onResponseStarted",
239 event: "onResponseStarted",
241 url: getURLHttpSimpleLoad(),
245 statusLine: "HTTP/1.1 200 OK",
248 { label: "onCompleted",
249 event: "onCompleted",
251 url: getURLHttpSimpleLoad(),
255 statusLine: "HTTP/1.1 200 OK",
260 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
261 "onHeadersReceived", "onResponseStarted", "onCompleted"]
263 {urls: ["<all_urls>"]}, // filter
264 ["blocking", "requestHeaders"]);
265 navigateAndWait(getURLHttpSimpleLoad());
268 // Navigates to a page with a blocking handler that redirects to a different
270 function complexLoadRedirected() {
273 { label: "onBeforeRequest-1",
274 event: "onBeforeRequest",
276 url: getURL("complexLoad/a.html"),
277 frameUrl: getURL("complexLoad/a.html")
279 retval: {redirectUrl: getURL("simpleLoad/a.html")}
281 { label: "onBeforeRedirect",
282 event: "onBeforeRedirect",
284 url: getURL("complexLoad/a.html"),
285 redirectUrl: getURL("simpleLoad/a.html"),
287 statusLine: "HTTP/1.1 307 Internal Redirect",
291 { label: "onBeforeRequest-2",
292 event: "onBeforeRequest",
294 url: getURL("simpleLoad/a.html"),
295 frameUrl: getURL("simpleLoad/a.html"),
298 { label: "onResponseStarted",
299 event: "onResponseStarted",
301 url: getURL("simpleLoad/a.html"),
304 statusLine: "HTTP/1.1 200 OK",
305 // Request to chrome-extension:// url has no IP.
308 { label: "onCompleted",
309 event: "onCompleted",
311 url: getURL("simpleLoad/a.html"),
314 statusLine: "HTTP/1.1 200 OK",
315 // Request to chrome-extension:// url has no IP.
320 ["onBeforeRequest-1", "onBeforeRedirect", "onBeforeRequest-2",
321 "onResponseStarted", "onCompleted"],
323 {urls: ["<all_urls>"]}, // filter
325 navigateAndWait(getURL("complexLoad/a.html"));
328 // Tests redirect of <img crossorigin="anonymous" src="...">
329 function crossOriginAnonymousRedirect() {
330 testLoadCORSImage("anonymous");
333 // Tests redirect of <img crossorigin="use-credentials" src="...">
334 function crossOriginCredentialedRedirect() {
335 testLoadCORSImage("use-credentials");
338 // Loads a testserver page that echoes the User-Agent header that was
339 // sent to fetch it. We modify the outgoing User-Agent in
340 // onBeforeSendHeaders, so we should see that modified version.
341 function modifyRequestHeaders() {
344 { label: "onBeforeRequest",
345 event: "onBeforeRequest",
347 url: getURLEchoUserAgent(),
348 frameUrl: getURLEchoUserAgent()
351 { label: "onBeforeSendHeaders",
352 event: "onBeforeSendHeaders",
354 url: getURLEchoUserAgent(),
355 // Note: no requestHeaders because we don't ask for them.
357 retval: {requestHeaders: [{name: "User-Agent", value: "FoobarUA"}]}
359 { label: "onSendHeaders",
360 event: "onSendHeaders",
362 url: getURLEchoUserAgent()
365 { label: "onHeadersReceived",
366 event: "onHeadersReceived",
368 url: getURLEchoUserAgent(),
369 statusLine: "HTTP/1.1 200 OK",
373 { label: "onResponseStarted",
374 event: "onResponseStarted",
376 url: getURLEchoUserAgent(),
380 statusLine: "HTTP/1.1 200 OK",
383 { label: "onCompleted",
384 event: "onCompleted",
386 url: getURLEchoUserAgent(),
390 statusLine: "HTTP/1.1 200 OK",
395 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
396 "onHeadersReceived", "onResponseStarted", "onCompleted"]
398 {urls: ["<all_urls>"]}, ["blocking"]);
399 // Check the page content for our modified User-Agent string.
400 navigateAndWait(getURLEchoUserAgent(), function() {
401 chrome.test.listenOnce(chrome.extension.onRequest, function(request) {
402 chrome.test.assertTrue(request.pass, "Request header was not set.");
404 chrome.tabs.executeScript(tabId,
406 code: "chrome.extension.sendRequest(" +
407 "{pass: document.body.innerText.indexOf('FoobarUA') >= 0});"
412 // Loads a testserver page that echoes the User-Agent header that was
413 // sent to fetch it. We modify the outgoing User-Agent in
414 // onBeforeSendHeaders, so we should see that modified version.
415 // In this version we check whether we can set binary header values.
416 function modifyBinaryRequestHeaders() {
419 { label: "onBeforeRequest",
420 event: "onBeforeRequest",
422 url: getURLEchoUserAgent(),
423 frameUrl: getURLEchoUserAgent()
426 { label: "onBeforeSendHeaders",
427 event: "onBeforeSendHeaders",
429 url: getURLEchoUserAgent(),
430 // Note: no requestHeaders because we don't ask for them.
432 retval: {requestHeaders: [{name: "User-Agent",
433 binaryValue: toCharCodes("FoobarUA")}]}
435 { label: "onSendHeaders",
436 event: "onSendHeaders",
438 url: getURLEchoUserAgent()
441 { label: "onHeadersReceived",
442 event: "onHeadersReceived",
444 url: getURLEchoUserAgent(),
445 statusLine: "HTTP/1.1 200 OK",
449 { label: "onResponseStarted",
450 event: "onResponseStarted",
452 url: getURLEchoUserAgent(),
456 statusLine: "HTTP/1.1 200 OK",
459 { label: "onCompleted",
460 event: "onCompleted",
462 url: getURLEchoUserAgent(),
466 statusLine: "HTTP/1.1 200 OK",
471 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
472 "onHeadersReceived", "onResponseStarted", "onCompleted"]
474 {urls: ["<all_urls>"]}, ["blocking"]);
475 // Check the page content for our modified User-Agent string.
476 navigateAndWait(getURLEchoUserAgent(), function() {
477 chrome.test.listenOnce(chrome.extension.onRequest, function(request) {
478 chrome.test.assertTrue(request.pass, "Request header was not set.");
480 chrome.tabs.executeScript(tabId,
482 code: "chrome.extension.sendRequest(" +
483 "{pass: document.body.innerText.indexOf('FoobarUA') >= 0});"
488 // Loads a testserver page that sets a cookie "Foo=Bar" but removes
489 // the cookies from the response headers so that they are not set.
490 function modifyResponseHeaders() {
493 { label: "onBeforeRequest",
494 event: "onBeforeRequest",
498 url: getURLSetCookie(),
499 frameUrl: getURLSetCookie()
502 { label: "onBeforeSendHeaders",
503 event: "onBeforeSendHeaders",
505 url: getURLSetCookie(),
506 // Note: no requestHeaders because we don't ask for them.
509 { label: "onSendHeaders",
510 event: "onSendHeaders",
512 url: getURLSetCookie(),
515 { label: "onHeadersReceived",
516 event: "onHeadersReceived",
518 url: getURLSetCookie(),
519 statusLine: "HTTP/1.1 200 OK",
521 responseHeadersExist: true,
523 retval_function: function(name, details) {
524 responseHeaders = details.responseHeaders;
526 for (var i = 0; i < responseHeaders.length; ++i) {
527 if (responseHeaders[i].name === "Set-Cookie" &&
528 responseHeaders[i].value.indexOf("Foo") != -1) {
530 responseHeaders.splice(i);
534 chrome.test.assertTrue(found);
535 return {responseHeaders: responseHeaders};
538 { label: "onResponseStarted",
539 event: "onResponseStarted",
541 url: getURLSetCookie(),
544 statusLine: "HTTP/1.1 200 OK",
546 responseHeadersExist: true,
549 { label: "onCompleted",
550 event: "onCompleted",
552 url: getURLSetCookie(),
555 statusLine: "HTTP/1.1 200 OK",
557 responseHeadersExist: true,
562 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
563 "onHeadersReceived", "onResponseStarted", "onCompleted"]
565 {urls: ["<all_urls>"]}, ["blocking", "responseHeaders"]);
566 // Check that the cookie was really removed.
567 navigateAndWait(getURLSetCookie(), function() {
568 chrome.test.listenOnce(chrome.extension.onRequest, function(request) {
569 chrome.test.assertTrue(request.pass, "Cookie was not removed.");
571 chrome.tabs.executeScript(tabId,
572 { code: "chrome.extension.sendRequest(" +
573 "{pass: document.cookie.indexOf('Foo') == -1});"
578 // Loads a testserver page that sets a cookie "Foo=U+FDD1" which is not a
579 // valid UTF-8 code point. Therefore, it cannot be passed to JavaScript
580 // as a normal string.
581 function handleNonUTF8InModifyResponseHeaders() {
584 { label: "onBeforeRequest",
585 event: "onBeforeRequest",
589 url: getURLNonUTF8SetCookie(),
590 frameUrl: getURLNonUTF8SetCookie()
593 { label: "onBeforeSendHeaders",
594 event: "onBeforeSendHeaders",
596 url: getURLNonUTF8SetCookie(),
597 // Note: no requestHeaders because we don't ask for them.
600 { label: "onSendHeaders",
601 event: "onSendHeaders",
603 url: getURLNonUTF8SetCookie(),
606 { label: "onHeadersReceived",
607 event: "onHeadersReceived",
609 url: getURLNonUTF8SetCookie(),
610 statusLine: "HTTP/1.1 200 OK",
612 responseHeadersExist: true,
614 retval_function: function(name, details) {
615 responseHeaders = details.responseHeaders;
617 var expectedValue = [
624 for (var i = 0; i < responseHeaders.length; ++i) {
625 if (responseHeaders[i].name === "Set-Cookie" &&
626 deepEq(responseHeaders[i].binaryValue, expectedValue)) {
628 responseHeaders.splice(i);
632 chrome.test.assertTrue(found);
633 return {responseHeaders: responseHeaders};
636 { label: "onResponseStarted",
637 event: "onResponseStarted",
639 url: getURLNonUTF8SetCookie(),
642 statusLine: "HTTP/1.1 200 OK",
644 responseHeadersExist: true,
647 { label: "onCompleted",
648 event: "onCompleted",
650 url: getURLNonUTF8SetCookie(),
653 statusLine: "HTTP/1.1 200 OK",
655 responseHeadersExist: true,
660 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
661 "onHeadersReceived", "onResponseStarted", "onCompleted"]
663 {urls: ["<all_urls>"]}, ["blocking", "responseHeaders"]);
664 // Check that the cookie was really removed.
665 navigateAndWait(getURLNonUTF8SetCookie(), function() {
666 chrome.test.listenOnce(chrome.extension.onRequest, function(request) {
667 chrome.test.assertTrue(request.pass, "Cookie was not removed.");
669 chrome.tabs.executeScript(tabId,
670 { code: "chrome.extension.sendRequest(" +
671 "{pass: document.cookie.indexOf('Foo') == -1});"
676 // Navigates to a page with a blocking handler that redirects to a different
677 // non-http page during onHeadersReceived. The requested page should not be
678 // loaded, and the redirect should succeed.
679 function simpleLoadRedirectOnReceiveHeaders() {
682 { label: "onBeforeRequest-1",
683 event: "onBeforeRequest",
687 url: getURLHttpSimpleLoad(),
688 frameUrl: getURLHttpSimpleLoad()
691 { label: "onBeforeSendHeaders",
692 event: "onBeforeSendHeaders",
694 url: getURLHttpSimpleLoad(),
695 // Note: no requestHeaders because we don't ask for them.
698 { label: "onSendHeaders",
699 event: "onSendHeaders",
701 url: getURLHttpSimpleLoad()
704 { label: "onHeadersReceived",
705 event: "onHeadersReceived",
707 url: getURLHttpSimpleLoad(),
708 statusLine: "HTTP/1.1 200 OK",
711 retval: {redirectUrl: getURL("simpleLoad/a.html")}
713 { label: "onBeforeRedirect",
714 event: "onBeforeRedirect",
716 url: getURLHttpSimpleLoad(),
717 redirectUrl: getURL("simpleLoad/a.html"),
718 statusLine: "HTTP/1.1 302 Found",
724 { label: "onBeforeRequest-2",
725 event: "onBeforeRequest",
727 url: getURL("simpleLoad/a.html"),
728 frameUrl: getURL("simpleLoad/a.html"),
731 { label: "onResponseStarted",
732 event: "onResponseStarted",
734 url: getURL("simpleLoad/a.html"),
737 statusLine: "HTTP/1.1 200 OK",
738 // Request to chrome-extension:// url has no IP.
741 { label: "onCompleted",
742 event: "onCompleted",
744 url: getURL("simpleLoad/a.html"),
747 statusLine: "HTTP/1.1 200 OK",
748 // Request to chrome-extension:// url has no IP.
753 ["onBeforeRequest-1", "onBeforeSendHeaders", "onSendHeaders",
754 "onHeadersReceived", "onBeforeRedirect", "onBeforeRequest-2",
755 "onResponseStarted", "onCompleted"]
757 {urls: ["<all_urls>"]}, // filter
759 navigateAndWait(getURLHttpSimpleLoad());
762 // Checks that synchronous XHR requests from ourself are invisible to blocking
764 function syncXhrsFromOurselfAreInvisible() {
767 { label: "a-onBeforeRequest",
768 event: "onBeforeRequest",
770 url: getURL("simpleLoad/a.html"),
771 frameUrl: getURL("simpleLoad/a.html")
774 { label: "a-onResponseStarted",
775 event: "onResponseStarted",
777 url: getURL("simpleLoad/a.html"),
780 statusLine: "HTTP/1.1 200 OK",
781 // Request to chrome-extension:// url has no IP.
784 { label: "a-onCompleted",
785 event: "onCompleted",
787 url: getURL("simpleLoad/a.html"),
790 statusLine: "HTTP/1.1 200 OK",
791 // Request to chrome-extension:// url has no IP.
794 // We do not see onBeforeRequest for the XHR request here because it is
795 // handled by a blocking handler.
796 { label: "x-onSendHeaders",
797 event: "onSendHeaders",
799 url: getURLHttpXHRData(),
801 type: "xmlhttprequest",
804 { label: "x-onResponseStarted",
805 event: "onResponseStarted",
807 url: getURLHttpXHRData(),
810 statusLine: "HTTP/1.1 200 OK",
812 type: "xmlhttprequest",
814 // Request to chrome-extension:// url has no IP.
817 { label: "x-onCompleted",
818 event: "onCompleted",
820 url: getURLHttpXHRData(),
823 statusLine: "HTTP/1.1 200 OK",
825 type: "xmlhttprequest",
827 // Request to chrome-extension:// url has no IP.
830 { label: "b-onBeforeRequest",
831 event: "onBeforeRequest",
833 url: getURL("complexLoad/b.jpg"),
834 frameUrl: getURL("complexLoad/b.jpg")
837 { label: "b-onResponseStarted",
838 event: "onResponseStarted",
840 url: getURL("complexLoad/b.jpg"),
843 statusLine: "HTTP/1.1 200 OK",
844 // Request to chrome-extension:// url has no IP.
847 { label: "b-onCompleted",
848 event: "onCompleted",
850 url: getURL("complexLoad/b.jpg"),
853 statusLine: "HTTP/1.1 200 OK",
854 // Request to chrome-extension:// url has no IP.
859 ["a-onBeforeRequest", "a-onResponseStarted", "a-onCompleted",
860 "x-onSendHeaders", "x-onResponseStarted", "x-onCompleted",
861 "b-onBeforeRequest", "b-onResponseStarted", "b-onCompleted"]
863 {urls: ["<all_urls>"]}, ["blocking"]);
864 // Check the page content for our modified User-Agent string.
865 navigateAndWait(getURL("simpleLoad/a.html"), function() {
866 var req = new XMLHttpRequest();
867 var asynchronous = false;
868 req.open("GET", getURLHttpXHRData(), asynchronous);
870 navigateAndWait(getURL("complexLoad/b.jpg"));
874 // Checks that asynchronous XHR requests from ourself are visible to blocking
876 function asyncXhrsFromOurselfAreVisible() {
879 { label: "a-onBeforeRequest",
880 event: "onBeforeRequest",
882 url: getURL("simpleLoad/a.html"),
883 frameUrl: getURL("simpleLoad/a.html")
886 { label: "a-onResponseStarted",
887 event: "onResponseStarted",
889 url: getURL("simpleLoad/a.html"),
892 statusLine: "HTTP/1.1 200 OK",
893 // Request to chrome-extension:// url has no IP.
896 { label: "a-onCompleted",
897 event: "onCompleted",
899 url: getURL("simpleLoad/a.html"),
902 statusLine: "HTTP/1.1 200 OK",
903 // Request to chrome-extension:// url has no IP.
907 label: "x-onBeforeRequest",
908 event: "onBeforeRequest",
910 url: getURLHttpXHRData(),
912 type: "xmlhttprequest",
913 frameUrl: "unknown frame URL",
917 label: "x-onBeforeSendHeaders",
918 event: "onBeforeSendHeaders",
920 url: getURLHttpXHRData(),
922 type: "xmlhttprequest",
925 { label: "x-onSendHeaders",
926 event: "onSendHeaders",
928 url: getURLHttpXHRData(),
930 type: "xmlhttprequest",
933 { label: "x-onResponseStarted",
934 event: "onResponseStarted",
936 url: getURLHttpXHRData(),
939 statusLine: "HTTP/1.1 200 OK",
941 type: "xmlhttprequest",
943 // Request to chrome-extension:// url has no IP.
947 label: "x-onHeadersReceived",
948 event: "onHeadersReceived",
950 url: getURLHttpXHRData(),
952 type: "xmlhttprequest",
953 statusLine: "HTTP/1.1 200 OK",
957 { label: "x-onCompleted",
958 event: "onCompleted",
960 url: getURLHttpXHRData(),
963 statusLine: "HTTP/1.1 200 OK",
965 type: "xmlhttprequest",
967 // Request to chrome-extension:// url has no IP.
970 { label: "b-onBeforeRequest",
971 event: "onBeforeRequest",
973 url: getURL("complexLoad/b.jpg"),
974 frameUrl: getURL("complexLoad/b.jpg")
977 { label: "b-onResponseStarted",
978 event: "onResponseStarted",
980 url: getURL("complexLoad/b.jpg"),
983 statusLine: "HTTP/1.1 200 OK",
984 // Request to chrome-extension:// url has no IP.
987 { label: "b-onCompleted",
988 event: "onCompleted",
990 url: getURL("complexLoad/b.jpg"),
993 statusLine: "HTTP/1.1 200 OK",
994 // Request to chrome-extension:// url has no IP.
999 ["a-onBeforeRequest", "a-onResponseStarted", "a-onCompleted",
1000 "x-onBeforeRequest", "x-onBeforeSendHeaders", "x-onSendHeaders",
1001 "x-onHeadersReceived", "x-onResponseStarted", "x-onCompleted"],
1002 ["a-onCompleted", "x-onBeforeRequest",
1003 "b-onBeforeRequest", "b-onResponseStarted", "b-onCompleted"]
1005 {urls: ["<all_urls>"]}, ["blocking"]);
1006 // Check the page content for our modified User-Agent string.
1007 navigateAndWait(getURL("simpleLoad/a.html"), function() {
1008 var req = new XMLHttpRequest();
1009 var asynchronous = true;
1010 req.open("GET", getURLHttpXHRData(), asynchronous);
1012 navigateAndWait(getURL("complexLoad/b.jpg"));
1018 // This helper verifies that extensions can successfully redirect resources even
1019 // if cross-origin access control is in effect via the crossorigin attribute.
1020 // Used by crossOriginAnonymousRedirect and crossOriginCredentialedRedirect.
1021 function testLoadCORSImage(crossOriginAttributeValue) {
1022 // (Non-existent) image URL, with random query string to bust the cache.
1023 var requestedUrl = getServerURL("cors/intercepted_by_extension.gif?" +
1024 Math.random(), "original.tld");
1025 var frameUrl = getServerURL(
1026 "extensions/api_test/webrequest/cors/load_image.html?" +
1027 "crossOrigin=" + crossOriginAttributeValue +
1028 "&src=" + encodeURIComponent(requestedUrl));
1029 var redirectTarget = getServerURL(
1030 "extensions/api_test/webrequest/cors/redirect_target.gif", "domain.tld");
1033 { label: "onBeforeRequest-1",
1034 event: "onBeforeRequest",
1038 // Frame URL unavailable because requests are filtered by type=image.
1039 frameUrl: "unknown frame URL",
1041 retval: {redirectUrl: redirectTarget}
1043 { label: "onBeforeRedirect",
1044 event: "onBeforeRedirect",
1048 redirectUrl: redirectTarget,
1049 statusLine: "HTTP/1.1 307 Internal Redirect",
1054 { label: "onBeforeRequest-2",
1055 event: "onBeforeRequest",
1058 url: redirectTarget,
1059 // Frame URL unavailable because requests are filtered by type=image.
1060 frameUrl: "unknown frame URL",
1064 label: "onBeforeSendHeaders",
1065 event: "onBeforeSendHeaders",
1068 url: redirectTarget,
1072 label: "onSendHeaders",
1073 event: "onSendHeaders",
1076 url: redirectTarget,
1080 label: "onHeadersReceived",
1081 event: "onHeadersReceived",
1084 url: redirectTarget,
1085 statusLine: "HTTP/1.1 200 OK",
1089 { label: "onResponseStarted",
1090 event: "onResponseStarted",
1093 url: redirectTarget,
1097 statusLine: "HTTP/1.1 200 OK",
1100 { label: "onCompleted",
1101 event: "onCompleted",
1104 url: redirectTarget,
1108 statusLine: "HTTP/1.1 200 OK",
1111 // After the image loads, the test will load the following URL
1112 // to signal that the test succeeded.
1114 label: "onBeforeRequest-3",
1115 event: "onBeforeRequest",
1118 url: getServerURL("signal_that_image_loaded_successfully"),
1119 // Frame URL unavailable because requests are filtered by type=image.
1120 frameUrl: "unknown frame URL",
1122 retval: {cancel: true}
1124 { label: "onErrorOccurred",
1125 event: "onErrorOccurred",
1128 url: getServerURL("signal_that_image_loaded_successfully"),
1130 error: "net::ERR_BLOCKED_BY_CLIENT",
1135 ["onBeforeRequest-1", "onBeforeRedirect", "onBeforeRequest-2",
1136 "onBeforeSendHeaders", "onSendHeaders", "onHeadersReceived",
1137 "onResponseStarted", "onCompleted",
1138 "onBeforeRequest-3", "onErrorOccurred"],
1140 {urls: ["<all_urls>"], types: ['image']}, // filter
1142 navigateAndWait(frameUrl);