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

Side by Side Diff: content/browser/loader/navigation_url_loader_unittest.cc

Issue 1416953007: Add a function to add extra headers from NavigationThrottle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@data-reduction-proxy-resource-throttle
Patch Set: Fixed compilation issue Created 5 years, 1 month 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "content/browser/frame_host/navigation_request_info.h" 10 #include "content/browser/frame_host/navigation_request_info.h"
(...skipping 19 matching lines...) Expand all
30 #include "net/url_request/redirect_info.h" 30 #include "net/url_request/redirect_info.h"
31 #include "net/url_request/url_request.h" 31 #include "net/url_request/url_request.h"
32 #include "net/url_request/url_request_context.h" 32 #include "net/url_request/url_request_context.h"
33 #include "net/url_request/url_request_job_factory_impl.h" 33 #include "net/url_request/url_request_job_factory_impl.h"
34 #include "net/url_request/url_request_test_job.h" 34 #include "net/url_request/url_request_test_job.h"
35 #include "net/url_request/url_request_test_util.h" 35 #include "net/url_request/url_request_test_util.h"
36 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
37 37
38 namespace content { 38 namespace content {
39 39
40 using ExtraHeadersList = std::vector<std::pair<std::string, std::string> >;
41
40 namespace { 42 namespace {
41 43
42 class StreamProtocolHandler 44 class StreamProtocolHandler
43 : public net::URLRequestJobFactory::ProtocolHandler { 45 : public net::URLRequestJobFactory::ProtocolHandler {
44 public: 46 public:
45 StreamProtocolHandler(StreamRegistry* registry) : registry_(registry) {} 47 StreamProtocolHandler(StreamRegistry* registry) : registry_(registry) {}
46 48
47 // net::URLRequestJobFactory::ProtocolHandler implementation. 49 // net::URLRequestJobFactory::ProtocolHandler implementation.
48 net::URLRequestJob* MaybeCreateJob( 50 net::URLRequestJob* MaybeCreateJob(
49 net::URLRequest* request, 51 net::URLRequest* request,
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 delegate.WaitForRequestRedirected(); 260 delegate.WaitForRequestRedirected();
259 EXPECT_EQ(net::URLRequestTestJob::test_url_2(), 261 EXPECT_EQ(net::URLRequestTestJob::test_url_2(),
260 delegate.redirect_info().new_url); 262 delegate.redirect_info().new_url);
261 EXPECT_EQ("GET", delegate.redirect_info().new_method); 263 EXPECT_EQ("GET", delegate.redirect_info().new_method);
262 EXPECT_EQ(net::URLRequestTestJob::test_url_2(), 264 EXPECT_EQ(net::URLRequestTestJob::test_url_2(),
263 delegate.redirect_info().new_first_party_for_cookies); 265 delegate.redirect_info().new_first_party_for_cookies);
264 EXPECT_EQ(302, delegate.redirect_response()->head.headers->response_code()); 266 EXPECT_EQ(302, delegate.redirect_response()->head.headers->response_code());
265 EXPECT_EQ(1, delegate.on_request_handled_counter()); 267 EXPECT_EQ(1, delegate.on_request_handled_counter());
266 268
267 // Wait for the response to complete. 269 // Wait for the response to complete.
268 loader->FollowRedirect(); 270 loader->FollowRedirect(ExtraHeadersList());
269 delegate.WaitForResponseStarted(); 271 delegate.WaitForResponseStarted();
270 272
271 // Check the response is correct. 273 // Check the response is correct.
272 EXPECT_EQ("text/html", delegate.response()->head.mime_type); 274 EXPECT_EQ("text/html", delegate.response()->head.mime_type);
273 EXPECT_EQ(200, delegate.response()->head.headers->response_code()); 275 EXPECT_EQ(200, delegate.response()->head.headers->response_code());
274 276
275 // Release the body and check it is correct. 277 // Release the body and check it is correct.
276 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 278 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
277 EXPECT_EQ(net::URLRequestTestJob::test_data_2(), 279 EXPECT_EQ(net::URLRequestTestJob::test_data_2(),
278 FetchURL(delegate.body()->GetURL())); 280 FetchURL(delegate.body()->GetURL()));
(...skipping 26 matching lines...) Expand all
305 TestNavigationURLLoaderDelegate delegate; 307 TestNavigationURLLoaderDelegate delegate;
306 scoped_ptr<NavigationURLLoader> loader = 308 scoped_ptr<NavigationURLLoader> loader =
307 MakeTestLoader(net::URLRequestTestJob::test_url_redirect_to_url_2(), 309 MakeTestLoader(net::URLRequestTestJob::test_url_redirect_to_url_2(),
308 &delegate); 310 &delegate);
309 311
310 // Wait for the request to redirect. 312 // Wait for the request to redirect.
311 delegate.WaitForRequestRedirected(); 313 delegate.WaitForRequestRedirected();
312 314
313 // In the same event loop iteration, follow the redirect (allowing the 315 // In the same event loop iteration, follow the redirect (allowing the
314 // response to go through) and destroy the loader. 316 // response to go through) and destroy the loader.
315 loader->FollowRedirect(); 317 loader->FollowRedirect(ExtraHeadersList());
316 loader.reset(); 318 loader.reset();
317 319
318 // Verify the URLRequestTestJob no longer has anything paused and that no 320 // Verify the URLRequestTestJob no longer has anything paused and that no
319 // response body was received. 321 // response body was received.
320 base::RunLoop().RunUntilIdle(); 322 base::RunLoop().RunUntilIdle();
321 EXPECT_FALSE(net::URLRequestTestJob::ProcessOnePendingMessage()); 323 EXPECT_FALSE(net::URLRequestTestJob::ProcessOnePendingMessage());
322 EXPECT_FALSE(delegate.body()); 324 EXPECT_FALSE(delegate.body());
323 } 325 }
324 326
325 // Tests that the loader may be canceled by context. 327 // Tests that the loader may be canceled by context.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 397
396 // Release the body. 398 // Release the body.
397 delegate.ReleaseBody(); 399 delegate.ReleaseBody();
398 base::RunLoop().RunUntilIdle(); 400 base::RunLoop().RunUntilIdle();
399 401
400 // Verify that URLRequestTestJob no longer has anything paused. 402 // Verify that URLRequestTestJob no longer has anything paused.
401 EXPECT_FALSE(net::URLRequestTestJob::ProcessOnePendingMessage()); 403 EXPECT_FALSE(net::URLRequestTestJob::ProcessOnePendingMessage());
402 } 404 }
403 405
404 } // namespace content 406 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698