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

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

Issue 2435743002: [ResourceScheduler] Throttle H2/QUIC requests just like we do for 1.1 (Closed)
Patch Set: Nits Created 4 years, 2 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/loader/resource_scheduler.h" 5 #include "content/browser/loader/resource_scheduler.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/test/scoped_feature_list.h"
14 #include "base/timer/mock_timer.h" 15 #include "base/timer/mock_timer.h"
15 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
16 #include "content/browser/browser_thread_impl.h" 17 #include "content/browser/browser_thread_impl.h"
17 #include "content/browser/loader/resource_dispatcher_host_impl.h" 18 #include "content/browser/loader/resource_dispatcher_host_impl.h"
18 #include "content/public/browser/resource_context.h" 19 #include "content/public/browser/resource_context.h"
19 #include "content/public/browser/resource_controller.h" 20 #include "content/public/browser/resource_controller.h"
20 #include "content/public/browser/resource_throttle.h" 21 #include "content/public/browser/resource_throttle.h"
21 #include "content/public/test/mock_render_process_host.h" 22 #include "content/public/test/mock_render_process_host.h"
22 #include "content/public/test/test_browser_context.h" 23 #include "content/public/test/test_browser_context.h"
23 #include "content/test/test_render_view_host_factory.h" 24 #include "content/test/test_render_view_host_factory.h"
(...skipping 15 matching lines...) Expand all
39 40
40 class TestRequestFactory; 41 class TestRequestFactory;
41 42
42 const int kChildId = 30; 43 const int kChildId = 30;
43 const int kRouteId = 75; 44 const int kRouteId = 75;
44 const int kChildId2 = 43; 45 const int kChildId2 = 43;
45 const int kRouteId2 = 67; 46 const int kRouteId2 = 67;
46 const int kBackgroundChildId = 35; 47 const int kBackgroundChildId = 35;
47 const int kBackgroundRouteId = 43; 48 const int kBackgroundRouteId = 43;
48 49
50 const char kPrioritySupportedRequestsDelayable[] =
51 "PrioritySupportedRequestsDelayable";
52
49 class TestRequest : public ResourceController { 53 class TestRequest : public ResourceController {
50 public: 54 public:
51 TestRequest(std::unique_ptr<net::URLRequest> url_request, 55 TestRequest(std::unique_ptr<net::URLRequest> url_request,
52 std::unique_ptr<ResourceThrottle> throttle, 56 std::unique_ptr<ResourceThrottle> throttle,
53 ResourceScheduler* scheduler) 57 ResourceScheduler* scheduler)
54 : started_(false), 58 : started_(false),
55 url_request_(std::move(url_request)), 59 url_request_(std::move(url_request)),
56 throttle_(std::move(throttle)), 60 throttle_(std::move(throttle)),
57 scheduler_(scheduler) { 61 scheduler_(scheduler) {
58 throttle_->set_controller_for_testing(this); 62 throttle_->set_controller_for_testing(this);
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 EXPECT_TRUE(medium->started()); 311 EXPECT_TRUE(medium->started());
308 EXPECT_TRUE(lowest->started()); 312 EXPECT_TRUE(lowest->started());
309 EXPECT_FALSE(lowest2->started()); 313 EXPECT_FALSE(lowest2->started());
310 314
311 scheduler()->OnWillInsertBody(kChildId, kRouteId); 315 scheduler()->OnWillInsertBody(kChildId, kRouteId);
312 base::RunLoop().RunUntilIdle(); 316 base::RunLoop().RunUntilIdle();
313 EXPECT_TRUE(lowest2->started()); 317 EXPECT_TRUE(lowest2->started());
314 } 318 }
315 319
316 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilBodyInsertedExceptSpdy) { 320 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilBodyInsertedExceptSpdy) {
321 base::test::ScopedFeatureList scoped_feature_list;
322 scoped_feature_list.InitFromCommandLine("",
323 kPrioritySupportedRequestsDelayable);
317 http_server_properties_.SetSupportsSpdy( 324 http_server_properties_.SetSupportsSpdy(
318 url::SchemeHostPort("https", "spdyhost", 443), true); 325 url::SchemeHostPort("https", "spdyhost", 443), true);
319 std::unique_ptr<TestRequest> high( 326 std::unique_ptr<TestRequest> high(
320 NewRequest("http://host/high", net::HIGHEST)); 327 NewRequest("http://host/high", net::HIGHEST));
321 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 328 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
322 std::unique_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); 329 std::unique_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
323 std::unique_ptr<TestRequest> low_spdy( 330 std::unique_ptr<TestRequest> low_spdy(
324 NewRequest("https://spdyhost/low", net::LOWEST)); 331 NewRequest("https://spdyhost/low", net::LOWEST));
325 EXPECT_TRUE(high->started()); 332 EXPECT_TRUE(high->started());
326 EXPECT_TRUE(low->started()); 333 EXPECT_TRUE(low->started());
327 EXPECT_FALSE(low2->started()); 334 EXPECT_FALSE(low2->started());
328 EXPECT_TRUE(low_spdy->started()); 335 EXPECT_TRUE(low_spdy->started());
329 336
330 scheduler()->OnWillInsertBody(kChildId, kRouteId); 337 scheduler()->OnWillInsertBody(kChildId, kRouteId);
331 high.reset(); 338 high.reset();
332 base::RunLoop().RunUntilIdle(); 339 base::RunLoop().RunUntilIdle();
333 EXPECT_TRUE(low2->started()); 340 EXPECT_TRUE(low2->started());
334 } 341 }
335 342
343 TEST_F(ResourceSchedulerTest,
344 OneLowLoadsUntilBodyInsertedEvenSpdyWhenDelayable) {
345 base::test::ScopedFeatureList scoped_feature_list;
346 scoped_feature_list.InitFromCommandLine(kPrioritySupportedRequestsDelayable,
347 "");
348 http_server_properties_.SetSupportsSpdy(
349 url::SchemeHostPort("https", "spdyhost", 443), true);
350 std::unique_ptr<TestRequest> high(
351 NewRequest("http://host/high", net::HIGHEST));
352 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
353 std::unique_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
354 std::unique_ptr<TestRequest> low_spdy(
355 NewRequest("https://spdyhost/low", net::LOWEST));
356 EXPECT_TRUE(high->started());
357 EXPECT_TRUE(low->started());
358 EXPECT_FALSE(low2->started());
359 EXPECT_FALSE(low_spdy->started());
360
361 scheduler()->OnWillInsertBody(kChildId, kRouteId);
362 high.reset();
363 base::RunLoop().RunUntilIdle();
364 EXPECT_TRUE(low2->started());
365 }
366
336 TEST_F(ResourceSchedulerTest, SpdyLowBlocksOtherLowUntilBodyInserted) { 367 TEST_F(ResourceSchedulerTest, SpdyLowBlocksOtherLowUntilBodyInserted) {
337 http_server_properties_.SetSupportsSpdy( 368 http_server_properties_.SetSupportsSpdy(
338 url::SchemeHostPort("https", "spdyhost", 443), true); 369 url::SchemeHostPort("https", "spdyhost", 443), true);
339 std::unique_ptr<TestRequest> high( 370 std::unique_ptr<TestRequest> high(
340 NewRequest("http://host/high", net::HIGHEST)); 371 NewRequest("http://host/high", net::HIGHEST));
341 std::unique_ptr<TestRequest> low_spdy( 372 std::unique_ptr<TestRequest> low_spdy(
342 NewRequest("https://spdyhost/low", net::LOWEST)); 373 NewRequest("https://spdyhost/low", net::LOWEST));
343 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 374 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
344 EXPECT_TRUE(high->started()); 375 EXPECT_TRUE(high->started());
345 EXPECT_TRUE(low_spdy->started()); 376 EXPECT_TRUE(low_spdy->started());
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 std::unique_ptr<TestRequest> high( 655 std::unique_ptr<TestRequest> high(
625 NewRequest("http://host/high", net::HIGHEST)); 656 NewRequest("http://host/high", net::HIGHEST));
626 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 657 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
627 658
628 std::unique_ptr<TestRequest> request( 659 std::unique_ptr<TestRequest> request(
629 NewRequest("chrome-extension://req", net::LOWEST)); 660 NewRequest("chrome-extension://req", net::LOWEST));
630 EXPECT_TRUE(request->started()); 661 EXPECT_TRUE(request->started());
631 } 662 }
632 663
633 TEST_F(ResourceSchedulerTest, SpdyProxySchedulesImmediately) { 664 TEST_F(ResourceSchedulerTest, SpdyProxySchedulesImmediately) {
665 base::test::ScopedFeatureList scoped_feature_list;
666 scoped_feature_list.InitFromCommandLine("",
667 kPrioritySupportedRequestsDelayable);
634 std::unique_ptr<TestRequest> high( 668 std::unique_ptr<TestRequest> high(
635 NewRequest("http://host/high", net::HIGHEST)); 669 NewRequest("http://host/high", net::HIGHEST));
636 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 670 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
637 671
638 std::unique_ptr<TestRequest> request( 672 std::unique_ptr<TestRequest> request(
639 NewRequest("http://host/req", net::IDLE)); 673 NewRequest("http://host/req", net::IDLE));
640 EXPECT_FALSE(request->started()); 674 EXPECT_FALSE(request->started());
641 675
642 scheduler()->OnReceivedSpdyProxiedHttpResponse(kChildId, kRouteId); 676 scheduler()->OnReceivedSpdyProxiedHttpResponse(kChildId, kRouteId);
643 base::RunLoop().RunUntilIdle(); 677 base::RunLoop().RunUntilIdle();
644 EXPECT_TRUE(request->started()); 678 EXPECT_TRUE(request->started());
645 679
646 std::unique_ptr<TestRequest> after( 680 std::unique_ptr<TestRequest> after(
647 NewRequest("http://host/after", net::IDLE)); 681 NewRequest("http://host/after", net::IDLE));
648 EXPECT_TRUE(after->started()); 682 EXPECT_TRUE(after->started());
649 } 683 }
650 684
685 TEST_F(ResourceSchedulerTest, SpdyProxyDelayable) {
686 base::test::ScopedFeatureList scoped_feature_list;
687 scoped_feature_list.InitFromCommandLine(kPrioritySupportedRequestsDelayable,
688 "");
689 std::unique_ptr<TestRequest> high(
690 NewRequest("http://host/high", net::HIGHEST));
691 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
692
693 std::unique_ptr<TestRequest> request(
694 NewRequest("http://host/req", net::IDLE));
695 EXPECT_FALSE(request->started());
696
697 scheduler()->OnReceivedSpdyProxiedHttpResponse(kChildId, kRouteId);
698 base::RunLoop().RunUntilIdle();
699 EXPECT_FALSE(request->started());
700
701 std::unique_ptr<TestRequest> after(
702 NewRequest("http://host/after", net::IDLE));
703 EXPECT_FALSE(after->started());
704 }
705
651 TEST_F(ResourceSchedulerTest, NewSpdyHostInDelayableRequests) { 706 TEST_F(ResourceSchedulerTest, NewSpdyHostInDelayableRequests) {
707 base::test::ScopedFeatureList scoped_feature_list;
708 scoped_feature_list.InitFromCommandLine("",
709 kPrioritySupportedRequestsDelayable);
710
652 scheduler()->OnWillInsertBody(kChildId, kRouteId); 711 scheduler()->OnWillInsertBody(kChildId, kRouteId);
653 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. 712 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc.
654 713
655 std::unique_ptr<TestRequest> low1_spdy( 714 std::unique_ptr<TestRequest> low1_spdy(
656 NewRequest("http://spdyhost1:8080/low", net::LOWEST)); 715 NewRequest("http://spdyhost1:8080/low", net::LOWEST));
657 // Cancel a request after we learn the server supports SPDY. 716 // Cancel a request after we learn the server supports SPDY.
658 ScopedVector<TestRequest> lows; 717 ScopedVector<TestRequest> lows;
659 for (int i = 0; i < kMaxNumDelayableRequestsPerClient - 1; ++i) { 718 for (int i = 0; i < kMaxNumDelayableRequestsPerClient - 1; ++i) {
660 string url = "http://host" + base::IntToString(i) + "/low"; 719 string url = "http://host" + base::IntToString(i) + "/low";
661 lows.push_back(NewRequest(url.c_str(), net::LOWEST)); 720 lows.push_back(NewRequest(url.c_str(), net::LOWEST));
(...skipping 13 matching lines...) Expand all
675 // Reprioritize a request after we learn the server supports SPDY. 734 // Reprioritize a request after we learn the server supports SPDY.
676 EXPECT_TRUE(low2_spdy->started()); 735 EXPECT_TRUE(low2_spdy->started());
677 http_server_properties_.SetSupportsSpdy( 736 http_server_properties_.SetSupportsSpdy(
678 url::SchemeHostPort("http", "spdyhost2", 8080), true); 737 url::SchemeHostPort("http", "spdyhost2", 8080), true);
679 ChangeRequestPriority(low2_spdy.get(), net::LOWEST); 738 ChangeRequestPriority(low2_spdy.get(), net::LOWEST);
680 base::RunLoop().RunUntilIdle(); 739 base::RunLoop().RunUntilIdle();
681 std::unique_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); 740 std::unique_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
682 EXPECT_TRUE(low2->started()); 741 EXPECT_TRUE(low2->started());
683 } 742 }
684 743
744 TEST_F(ResourceSchedulerTest, NewDelayableSpdyHostInDelayableRequests) {
745 base::test::ScopedFeatureList scoped_feature_list;
746 scoped_feature_list.InitFromCommandLine(kPrioritySupportedRequestsDelayable,
747 "");
748
749 scheduler()->OnWillInsertBody(kChildId, kRouteId);
750 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc.
751
752 std::unique_ptr<TestRequest> low1_spdy(
753 NewRequest("http://spdyhost1:8080/low", net::LOWEST));
754 // Cancel a request after we learn the server supports SPDY.
755 ScopedVector<TestRequest> lows;
756 for (int i = 0; i < kMaxNumDelayableRequestsPerClient - 1; ++i) {
757 string url = "http://host" + base::IntToString(i) + "/low";
758 lows.push_back(NewRequest(url.c_str(), net::LOWEST));
759 }
760 std::unique_ptr<TestRequest> low1(NewRequest("http://host/low", net::LOWEST));
761 EXPECT_FALSE(low1->started());
762 http_server_properties_.SetSupportsSpdy(
763 url::SchemeHostPort("http", "spdyhost1", 8080), true);
764 low1_spdy.reset();
765 base::RunLoop().RunUntilIdle();
766 EXPECT_TRUE(low1->started());
767
768 low1.reset();
769 base::RunLoop().RunUntilIdle();
770 std::unique_ptr<TestRequest> low2_spdy(
771 NewRequest("http://spdyhost2:8080/low", net::IDLE));
772 // Reprioritize a request after we learn the server supports SPDY.
773 EXPECT_TRUE(low2_spdy->started());
774 http_server_properties_.SetSupportsSpdy(
775 url::SchemeHostPort("http", "spdyhost2", 8080), true);
776 ChangeRequestPriority(low2_spdy.get(), net::LOWEST);
777 base::RunLoop().RunUntilIdle();
778 std::unique_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
779 EXPECT_FALSE(low2->started());
780 }
781
685 // Async revalidations which are not started when the tab is closed must be 782 // Async revalidations which are not started when the tab is closed must be
686 // started at some point, or they will hang around forever and prevent other 783 // started at some point, or they will hang around forever and prevent other
687 // async revalidations to the same URL from being issued. 784 // async revalidations to the same URL from being issued.
688 TEST_F(ResourceSchedulerTest, RequestStartedAfterClientDeleted) { 785 TEST_F(ResourceSchedulerTest, RequestStartedAfterClientDeleted) {
689 scheduler_->OnClientCreated(kChildId2, kRouteId2); 786 scheduler_->OnClientCreated(kChildId2, kRouteId2);
690 std::unique_ptr<TestRequest> high(NewRequestWithChildAndRoute( 787 std::unique_ptr<TestRequest> high(NewRequestWithChildAndRoute(
691 "http://host/high", net::HIGHEST, kChildId2, kRouteId2)); 788 "http://host/high", net::HIGHEST, kChildId2, kRouteId2));
692 std::unique_ptr<TestRequest> lowest1(NewRequestWithChildAndRoute( 789 std::unique_ptr<TestRequest> lowest1(NewRequestWithChildAndRoute(
693 "http://host/lowest", net::LOWEST, kChildId2, kRouteId2)); 790 "http://host/lowest", net::LOWEST, kChildId2, kRouteId2));
694 std::unique_ptr<TestRequest> lowest2(NewRequestWithChildAndRoute( 791 std::unique_ptr<TestRequest> lowest2(NewRequestWithChildAndRoute(
(...skipping 28 matching lines...) Expand all
723 scheduler_->OnClientDeleted(kChildId2, kRouteId2); 820 scheduler_->OnClientDeleted(kChildId2, kRouteId2);
724 high.reset(); 821 high.reset();
725 delayable_requests.clear(); 822 delayable_requests.clear();
726 base::RunLoop().RunUntilIdle(); 823 base::RunLoop().RunUntilIdle();
727 EXPECT_TRUE(lowest->started()); 824 EXPECT_TRUE(lowest->started());
728 } 825 }
729 826
730 } // unnamed namespace 827 } // unnamed namespace
731 828
732 } // namespace content 829 } // namespace content
OLDNEW
« content/browser/loader/resource_scheduler.cc ('K') | « content/browser/loader/resource_scheduler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698