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

Unified Diff: components/data_reduction_proxy/browser/data_reduction_proxy_protocol_unittest.cc

Issue 603323002: Maybe add CORS headers to data reduction proxy redirect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/data_reduction_proxy/browser/data_reduction_proxy_protocol.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/data_reduction_proxy/browser/data_reduction_proxy_protocol_unittest.cc
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_protocol_unittest.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_protocol_unittest.cc
index ac5dab5166b7acbbdab200a25cf72e28ad9fe5bd..409e4a8cdc5577046b75d8641a1f60324d400ccd 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_protocol_unittest.cc
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_protocol_unittest.cc
@@ -353,6 +353,50 @@ TEST_F(DataReductionProxyProtocolTest, OverrideResponseAsRedirect) {
}
}
+// Tests that the response is correctly overwritten as a redirect with CORS
+// headers when an Origin header is provided in the initial request.
+TEST_F(DataReductionProxyProtocolTest, OverrideResponseAsRedirectCORS) {
+ net::TestURLRequestContext context;
+ const struct {
+ const char* headers;
+ const char* expected_headers;
+ } tests[] = {
+ { "HTTP/1.1 200 0K\n"
+ "Chrome-Proxy: block=1\n"
+ "Via: 1.1 Chrome-Compression-Proxy\n",
+
+ "HTTP/1.1 302 Found\n"
+ "Chrome-Proxy: block=1\n"
+ "Via: 1.1 Chrome-Compression-Proxy\n"
+ "Location: http://www.google.com/\n"
+ "Access-Control-Allow-Origin: http://www.else.com\n"
+ "Access-Control-Allow-Credentials: true\n"
+ },
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
+ std::string headers(tests[i].headers);
+ HeadersToRaw(&headers);
+ scoped_refptr<HttpResponseHeaders> original_response_headers(
+ new HttpResponseHeaders(headers));
+ scoped_refptr<HttpResponseHeaders> override_response_headers;
+ TestDelegate test_delegate;
+ scoped_ptr<net::URLRequest> request(
+ context.CreateRequest(GURL("http://www.google.com/"),
+ net::DEFAULT_PRIORITY,
+ NULL,
+ NULL));
+ request->SetExtraRequestHeaderByName("Origin", "http://www.else.com", true);
+ OverrideResponseAsRedirect(request.get(), original_response_headers.get(),
+ &override_response_headers);
+ int expected_flags = net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY;
+ EXPECT_EQ(expected_flags, request->load_flags());
+ std::string override_headers;
+ override_response_headers->GetNormalizedHeaders(&override_headers);
+ EXPECT_EQ(std::string(tests[i].expected_headers), override_headers);
+ }
+}
+
// After each test, the proxy retry info will contain zero, one, or two of the
// data reduction proxies depending on whether no bypass was indicated by the
« no previous file with comments | « components/data_reduction_proxy/browser/data_reduction_proxy_protocol.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698