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

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

Issue 348253002: Add CORS headers to URLRequestRedirectJob. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: EXPECT GURL -> std::string Created 6 years, 3 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
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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 ], 315 ],
316 [ // event order 316 [ // event order
317 ["onBeforeRequest-1", "onBeforeRedirect", "onBeforeRequest-2", 317 ["onBeforeRequest-1", "onBeforeRedirect", "onBeforeRequest-2",
318 "onResponseStarted", "onCompleted"], 318 "onResponseStarted", "onCompleted"],
319 ], 319 ],
320 {urls: ["<all_urls>"]}, // filter 320 {urls: ["<all_urls>"]}, // filter
321 ["blocking"]); 321 ["blocking"]);
322 navigateAndWait(getURL("complexLoad/a.html")); 322 navigateAndWait(getURL("complexLoad/a.html"));
323 }, 323 },
324 324
325 // Tests redirect of <img crossorigin="anonymous" src="...">
326 function crossOriginAnonymousRedirect() {
327 testLoadCORSImage("anonymous");
328 },
329
330 // Tests redirect of <img crossorigin="use-credentials" src="...">
331 function crossOriginCredentialedRedirect() {
332 testLoadCORSImage("use-credentials");
333 },
334
325 // Loads a testserver page that echoes the User-Agent header that was 335 // Loads a testserver page that echoes the User-Agent header that was
326 // sent to fetch it. We modify the outgoing User-Agent in 336 // sent to fetch it. We modify the outgoing User-Agent in
327 // onBeforeSendHeaders, so we should see that modified version. 337 // onBeforeSendHeaders, so we should see that modified version.
328 function modifyRequestHeaders() { 338 function modifyRequestHeaders() {
329 expect( 339 expect(
330 [ // events 340 [ // events
331 { label: "onBeforeRequest", 341 { label: "onBeforeRequest",
332 event: "onBeforeRequest", 342 event: "onBeforeRequest",
333 details: { 343 details: {
334 url: getURLEchoUserAgent(), 344 url: getURLEchoUserAgent(),
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 // Check the page content for our modified User-Agent string. 997 // Check the page content for our modified User-Agent string.
988 navigateAndWait(getURL("simpleLoad/a.html"), function() { 998 navigateAndWait(getURL("simpleLoad/a.html"), function() {
989 var req = new XMLHttpRequest(); 999 var req = new XMLHttpRequest();
990 var asynchronous = true; 1000 var asynchronous = true;
991 req.open("GET", getURLHttpXHRData(), asynchronous); 1001 req.open("GET", getURLHttpXHRData(), asynchronous);
992 req.send(null); 1002 req.send(null);
993 navigateAndWait(getURL("complexLoad/b.jpg")); 1003 navigateAndWait(getURL("complexLoad/b.jpg"));
994 }); 1004 });
995 }, 1005 },
996 ]); 1006 ]);
1007
1008
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");
1022 expect(
1023 [ // events
1024 { label: "onBeforeRequest-1",
1025 event: "onBeforeRequest",
1026 details: {
1027 type: "image",
1028 url: requestedUrl,
1029 // Frame URL unavailable because requests are filtered by type=image.
1030 frameUrl: "unknown frame URL",
1031 },
1032 retval: {redirectUrl: redirectTarget}
1033 },
1034 { label: "onBeforeRedirect",
1035 event: "onBeforeRedirect",
1036 details: {
1037 type: "image",
1038 url: requestedUrl,
1039 redirectUrl: redirectTarget,
1040 statusLine: "HTTP/1.1 307 Internal Redirect",
1041 statusCode: 307,
1042 fromCache: false,
1043 }
1044 },
1045 { label: "onBeforeRequest-2",
1046 event: "onBeforeRequest",
1047 details: {
1048 type: "image",
1049 url: redirectTarget,
1050 // Frame URL unavailable because requests are filtered by type=image.
1051 frameUrl: "unknown frame URL",
1052 },
1053 },
1054 {
1055 label: "onBeforeSendHeaders",
1056 event: "onBeforeSendHeaders",
1057 details: {
1058 type: "image",
1059 url: redirectTarget,
1060 }
1061 },
1062 {
1063 label: "onSendHeaders",
1064 event: "onSendHeaders",
1065 details: {
1066 type: "image",
1067 url: redirectTarget,
1068 }
1069 },
1070 {
1071 label: "onHeadersReceived",
1072 event: "onHeadersReceived",
1073 details: {
1074 type: "image",
1075 url: redirectTarget,
1076 statusLine: "HTTP/1.1 200 OK",
1077 }
1078 },
1079 { label: "onResponseStarted",
1080 event: "onResponseStarted",
1081 details: {
1082 type: "image",
1083 url: redirectTarget,
1084 fromCache: false,
1085 statusCode: 200,
1086 ip: "127.0.0.1",
1087 statusLine: "HTTP/1.1 200 OK",
1088 }
1089 },
1090 { label: "onCompleted",
1091 event: "onCompleted",
1092 details: {
1093 type: "image",
1094 url: redirectTarget,
1095 fromCache: false,
1096 statusCode: 200,
1097 ip: "127.0.0.1",
1098 statusLine: "HTTP/1.1 200 OK",
1099 }
1100 },
1101 // After the image loads, the test will load the following URL
1102 // to signal that the test succeeded.
1103 {
1104 label: "onBeforeRequest-3",
1105 event: "onBeforeRequest",
1106 details: {
1107 type: "image",
1108 url: getServerURL("signal_that_image_loaded_successfully"),
1109 // Frame URL unavailable because requests are filtered by type=image.
1110 frameUrl: "unknown frame URL",
1111 },
1112 retval: {cancel: true}
1113 },
1114 { label: "onErrorOccurred",
1115 event: "onErrorOccurred",
1116 details: {
1117 type: "image",
1118 url: getServerURL("signal_that_image_loaded_successfully"),
1119 fromCache: false,
1120 error: "net::ERR_BLOCKED_BY_CLIENT",
1121 }
1122 },
1123 ],
1124 [ // event order
1125 ["onBeforeRequest-1", "onBeforeRedirect", "onBeforeRequest-2",
1126 "onBeforeSendHeaders", "onSendHeaders", "onHeadersReceived",
1127 "onResponseStarted", "onCompleted",
1128 "onBeforeRequest-3", "onErrorOccurred"],
1129 ],
1130 {urls: ["<all_urls>"], types: ['image']}, // filter
1131 ["blocking"]);
1132 navigateAndWait(frameUrl);
1133 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698