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

Side by Side Diff: content/browser/service_worker/service_worker_browsertest.cc

Issue 1859313002: Save-Data should not be added to CORS Access-Control-Request-Headers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <map> 7 #include <map>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
17 #include "base/thread_task_runner_handle.h" 18 #include "base/thread_task_runner_handle.h"
18 #include "base/time/time.h" 19 #include "base/time/time.h"
19 #include "build/build_config.h" 20 #include "build/build_config.h"
20 #include "content/browser/fileapi/chrome_blob_storage_context.h" 21 #include "content/browser/fileapi/chrome_blob_storage_context.h"
21 #include "content/browser/service_worker/embedded_worker_instance.h" 22 #include "content/browser/service_worker/embedded_worker_instance.h"
22 #include "content/browser/service_worker/embedded_worker_registry.h" 23 #include "content/browser/service_worker/embedded_worker_registry.h"
23 #include "content/browser/service_worker/service_worker_context_core.h" 24 #include "content/browser/service_worker/service_worker_context_core.h"
24 #include "content/browser/service_worker/service_worker_context_observer.h" 25 #include "content/browser/service_worker/service_worker_context_observer.h"
25 #include "content/browser/service_worker/service_worker_context_wrapper.h" 26 #include "content/browser/service_worker/service_worker_context_wrapper.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 return std::move(http_response); 211 return std::move(http_response);
211 } 212 }
212 213
213 scoped_ptr<net::test_server::HttpResponse> VerifySaveDataHeaderNotInRequest( 214 scoped_ptr<net::test_server::HttpResponse> VerifySaveDataHeaderNotInRequest(
214 const net::test_server::HttpRequest& request) { 215 const net::test_server::HttpRequest& request) {
215 auto it = request.headers.find("Save-Data"); 216 auto it = request.headers.find("Save-Data");
216 EXPECT_EQ(request.headers.end(), it); 217 EXPECT_EQ(request.headers.end(), it);
217 return make_scoped_ptr(new net::test_server::BasicHttpResponse()); 218 return make_scoped_ptr(new net::test_server::BasicHttpResponse());
218 } 219 }
219 220
221 scoped_ptr<net::test_server::HttpResponse>
222 VerifySaveDataNotInAccessControlRequestHeader(
223 const net::test_server::HttpRequest& request) {
224 // Save-Data should be present.
225 auto it = request.headers.find("Save-Data");
226 EXPECT_NE(request.headers.end(), it);
227 EXPECT_EQ("on", it->second);
228
229 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
230 new net::test_server::BasicHttpResponse());
231 if (request.method == net::test_server::METHOD_OPTIONS) {
232 // Access-Control-Request-Headers should contain 'X-Custom-Header' and not
233 // contain 'Save-Data'.
234 auto it_acrh = request.headers.find("Access-Control-Request-Headers");
falken 2016/04/06 04:41:36 nit: "acrh_iter" is a more common Chromium naming
Raj 2016/04/06 05:08:41 Done.
235 EXPECT_NE(request.headers.end(), it_acrh);
236 EXPECT_NE(std::string::npos, it_acrh->second.find("x-custom-header"));
237 EXPECT_EQ(std::string::npos, it_acrh->second.find("save-data"));
238 http_response->AddCustomHeader("Access-Control-Allow-Headers",
239 it_acrh->second);
240 http_response->AddCustomHeader("Access-Control-Allow-Methods", "GET");
241 http_response->AddCustomHeader("Access-Control-Allow-Origin", "*");
242 } else {
243 http_response->AddCustomHeader("Access-Control-Allow-Origin", "*");
244 http_response->set_content("PASS");
245 }
246 return std::move(http_response);
247 }
248
220 // The ImportsBustMemcache test requires that the imported script 249 // The ImportsBustMemcache test requires that the imported script
221 // would naturally be cached in blink's memcache, but the embedded 250 // would naturally be cached in blink's memcache, but the embedded
222 // test server doesn't produce headers that allow the blink's memcache 251 // test server doesn't produce headers that allow the blink's memcache
223 // to do that. This interceptor injects headers that give the import 252 // to do that. This interceptor injects headers that give the import
224 // an experiration far in the future. 253 // an experiration far in the future.
225 class LongLivedResourceInterceptor : public net::URLRequestInterceptor { 254 class LongLivedResourceInterceptor : public net::URLRequestInterceptor {
226 public: 255 public:
227 explicit LongLivedResourceInterceptor(const std::string& body) 256 explicit LongLivedResourceInterceptor(const std::string& body)
228 : body_(body) {} 257 : body_(body) {}
229 ~LongLivedResourceInterceptor() override {} 258 ~LongLivedResourceInterceptor() override {}
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 SetBrowserClientForTesting(old_client); 1138 SetBrowserClientForTesting(old_client);
1110 shell()->Close(); 1139 shell()->Close();
1111 1140
1112 base::RunLoop run_loop; 1141 base::RunLoop run_loop;
1113 public_context()->UnregisterServiceWorker( 1142 public_context()->UnregisterServiceWorker(
1114 embedded_test_server()->GetURL(kPageUrl), 1143 embedded_test_server()->GetURL(kPageUrl),
1115 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); 1144 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure()));
1116 run_loop.Run(); 1145 run_loop.Run();
1117 } 1146 }
1118 1147
1148 IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest, CrossOriginFetchWithSaveData) {
1149 const char kPageUrl[] = "/service_worker/fetch_cross_origin.html";
1150 const char kWorkerUrl[] = "/service_worker/fetch_event_pass_through.js";
1151 net::EmbeddedTestServer cross_origin_server;
1152 cross_origin_server.ServeFilesFromSourceDirectory("content/test/data");
1153 cross_origin_server.RegisterRequestHandler(
1154 base::Bind(&VerifySaveDataNotInAccessControlRequestHeader));
1155 cross_origin_server.Start();
1156
1157 MockContentBrowserClient content_browser_client;
1158 content_browser_client.set_data_saver_enabled(true);
1159 ContentBrowserClient* old_client =
1160 SetBrowserClientForTesting(&content_browser_client);
1161 shell()->web_contents()->GetRenderViewHost()->OnWebkitPreferencesChanged();
1162 scoped_refptr<WorkerActivatedObserver> observer =
1163 new WorkerActivatedObserver(wrapper());
1164 observer->Init();
1165 public_context()->RegisterServiceWorker(
1166 embedded_test_server()->GetURL(kPageUrl),
1167 embedded_test_server()->GetURL(kWorkerUrl),
1168 base::Bind(&ExpectResultAndRun, true, base::Bind(&base::DoNothing)));
1169 observer->Wait();
1170
1171 NavigateToURL(shell(),
1172 embedded_test_server()->GetURL(base::StringPrintf(
1173 "%s?%s", kPageUrl,
1174 cross_origin_server.GetURL("/cross_origin_request.html")
1175 .spec()
1176 .c_str())));
1177 const base::string16 title1 = base::ASCIIToUTF16("PASS");
1178 TitleWatcher title_watcher1(shell()->web_contents(), title1);
1179 EXPECT_EQ(title1, title_watcher1.WaitAndGetTitle());
falken 2016/04/06 04:41:36 Remove the 1 from these names?
Raj 2016/04/06 05:08:41 Done.
1180
1181 SetBrowserClientForTesting(old_client);
1182 shell()->Close();
1183
1184 base::RunLoop run_loop;
1185 public_context()->UnregisterServiceWorker(
1186 embedded_test_server()->GetURL(kPageUrl),
1187 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure()));
1188 run_loop.Run();
1189 }
1190
1119 IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest, 1191 IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest,
1120 FetchPageWithSaveDataPassThroughOnFetch) { 1192 FetchPageWithSaveDataPassThroughOnFetch) {
1121 const char kPageUrl[] = "/service_worker/pass_through_fetch.html"; 1193 const char kPageUrl[] = "/service_worker/pass_through_fetch.html";
1122 const char kWorkerUrl[] = "/service_worker/fetch_event_pass_through.js"; 1194 const char kWorkerUrl[] = "/service_worker/fetch_event_pass_through.js";
1123 MockContentBrowserClient content_browser_client; 1195 MockContentBrowserClient content_browser_client;
1124 content_browser_client.set_data_saver_enabled(true); 1196 content_browser_client.set_data_saver_enabled(true);
1125 ContentBrowserClient* old_client = 1197 ContentBrowserClient* old_client =
1126 SetBrowserClientForTesting(&content_browser_client); 1198 SetBrowserClientForTesting(&content_browser_client);
1127 shell()->web_contents()->GetRenderViewHost()->OnWebkitPreferencesChanged(); 1199 shell()->web_contents()->GetRenderViewHost()->OnWebkitPreferencesChanged();
1128 scoped_refptr<WorkerActivatedObserver> observer = 1200 scoped_refptr<WorkerActivatedObserver> observer =
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 ASSERT_EQ(SERVICE_WORKER_OK, status); 1557 ASSERT_EQ(SERVICE_WORKER_OK, status);
1486 // Stop the worker. 1558 // Stop the worker.
1487 StopWorker(SERVICE_WORKER_OK); 1559 StopWorker(SERVICE_WORKER_OK);
1488 // Restart the worker. 1560 // Restart the worker.
1489 StartWorker(SERVICE_WORKER_OK); 1561 StartWorker(SERVICE_WORKER_OK);
1490 // Stop the worker. 1562 // Stop the worker.
1491 StopWorker(SERVICE_WORKER_OK); 1563 StopWorker(SERVICE_WORKER_OK);
1492 } 1564 }
1493 1565
1494 } // namespace content 1566 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698