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

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: Nit 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
« no previous file with comments | « content/browser/loader/resource_scheduler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
324 InitializeScheduler();
325
317 http_server_properties_.SetSupportsSpdy( 326 http_server_properties_.SetSupportsSpdy(
318 url::SchemeHostPort("https", "spdyhost", 443), true); 327 url::SchemeHostPort("https", "spdyhost", 443), true);
319 std::unique_ptr<TestRequest> high( 328 std::unique_ptr<TestRequest> high(
320 NewRequest("http://host/high", net::HIGHEST)); 329 NewRequest("http://host/high", net::HIGHEST));
321 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 330 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
322 std::unique_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); 331 std::unique_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
323 std::unique_ptr<TestRequest> low_spdy( 332 std::unique_ptr<TestRequest> low_spdy(
324 NewRequest("https://spdyhost/low", net::LOWEST)); 333 NewRequest("https://spdyhost/low", net::LOWEST));
325 EXPECT_TRUE(high->started()); 334 EXPECT_TRUE(high->started());
326 EXPECT_TRUE(low->started()); 335 EXPECT_TRUE(low->started());
327 EXPECT_FALSE(low2->started()); 336 EXPECT_FALSE(low2->started());
328 EXPECT_TRUE(low_spdy->started()); 337 EXPECT_TRUE(low_spdy->started());
329 338
330 scheduler()->OnWillInsertBody(kChildId, kRouteId); 339 scheduler()->OnWillInsertBody(kChildId, kRouteId);
331 high.reset(); 340 high.reset();
332 base::RunLoop().RunUntilIdle(); 341 base::RunLoop().RunUntilIdle();
333 EXPECT_TRUE(low2->started()); 342 EXPECT_TRUE(low2->started());
334 } 343 }
335 344
345 TEST_F(ResourceSchedulerTest,
346 OneLowLoadsUntilBodyInsertedEvenSpdyWhenDelayable) {
347 http_server_properties_.SetSupportsSpdy(
348 url::SchemeHostPort("https", "spdyhost", 443), true);
349 std::unique_ptr<TestRequest> high(
350 NewRequest("http://host/high", net::HIGHEST));
351 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
352 std::unique_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
353 std::unique_ptr<TestRequest> low_spdy(
354 NewRequest("https://spdyhost/low", net::LOWEST));
355 EXPECT_TRUE(high->started());
356 EXPECT_TRUE(low->started());
357 EXPECT_FALSE(low2->started());
358 EXPECT_FALSE(low_spdy->started());
359
360 scheduler()->OnWillInsertBody(kChildId, kRouteId);
361 high.reset();
362 base::RunLoop().RunUntilIdle();
363 EXPECT_TRUE(low2->started());
364 }
365
336 TEST_F(ResourceSchedulerTest, SpdyLowBlocksOtherLowUntilBodyInserted) { 366 TEST_F(ResourceSchedulerTest, SpdyLowBlocksOtherLowUntilBodyInserted) {
337 http_server_properties_.SetSupportsSpdy( 367 http_server_properties_.SetSupportsSpdy(
338 url::SchemeHostPort("https", "spdyhost", 443), true); 368 url::SchemeHostPort("https", "spdyhost", 443), true);
339 std::unique_ptr<TestRequest> high( 369 std::unique_ptr<TestRequest> high(
340 NewRequest("http://host/high", net::HIGHEST)); 370 NewRequest("http://host/high", net::HIGHEST));
341 std::unique_ptr<TestRequest> low_spdy( 371 std::unique_ptr<TestRequest> low_spdy(
342 NewRequest("https://spdyhost/low", net::LOWEST)); 372 NewRequest("https://spdyhost/low", net::LOWEST));
343 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 373 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
344 EXPECT_TRUE(high->started()); 374 EXPECT_TRUE(high->started());
345 EXPECT_TRUE(low_spdy->started()); 375 EXPECT_TRUE(low_spdy->started());
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 std::unique_ptr<TestRequest> high( 654 std::unique_ptr<TestRequest> high(
625 NewRequest("http://host/high", net::HIGHEST)); 655 NewRequest("http://host/high", net::HIGHEST));
626 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 656 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
627 657
628 std::unique_ptr<TestRequest> request( 658 std::unique_ptr<TestRequest> request(
629 NewRequest("chrome-extension://req", net::LOWEST)); 659 NewRequest("chrome-extension://req", net::LOWEST));
630 EXPECT_TRUE(request->started()); 660 EXPECT_TRUE(request->started());
631 } 661 }
632 662
633 TEST_F(ResourceSchedulerTest, SpdyProxySchedulesImmediately) { 663 TEST_F(ResourceSchedulerTest, SpdyProxySchedulesImmediately) {
664 base::test::ScopedFeatureList scoped_feature_list;
665 scoped_feature_list.InitFromCommandLine("",
666 kPrioritySupportedRequestsDelayable);
667 InitializeScheduler();
668
634 std::unique_ptr<TestRequest> high( 669 std::unique_ptr<TestRequest> high(
635 NewRequest("http://host/high", net::HIGHEST)); 670 NewRequest("http://host/high", net::HIGHEST));
636 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 671 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
637 672
638 std::unique_ptr<TestRequest> request( 673 std::unique_ptr<TestRequest> request(
639 NewRequest("http://host/req", net::IDLE)); 674 NewRequest("http://host/req", net::IDLE));
640 EXPECT_FALSE(request->started()); 675 EXPECT_FALSE(request->started());
641 676
642 scheduler()->OnReceivedSpdyProxiedHttpResponse(kChildId, kRouteId); 677 scheduler()->OnReceivedSpdyProxiedHttpResponse(kChildId, kRouteId);
643 base::RunLoop().RunUntilIdle(); 678 base::RunLoop().RunUntilIdle();
644 EXPECT_TRUE(request->started()); 679 EXPECT_TRUE(request->started());
645 680
646 std::unique_ptr<TestRequest> after( 681 std::unique_ptr<TestRequest> after(
647 NewRequest("http://host/after", net::IDLE)); 682 NewRequest("http://host/after", net::IDLE));
648 EXPECT_TRUE(after->started()); 683 EXPECT_TRUE(after->started());
649 } 684 }
650 685
686 TEST_F(ResourceSchedulerTest, SpdyProxyDelayable) {
687 std::unique_ptr<TestRequest> high(
688 NewRequest("http://host/high", net::HIGHEST));
689 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
690
691 std::unique_ptr<TestRequest> request(
692 NewRequest("http://host/req", net::IDLE));
693 EXPECT_FALSE(request->started());
694
695 scheduler()->OnReceivedSpdyProxiedHttpResponse(kChildId, kRouteId);
696 base::RunLoop().RunUntilIdle();
697 EXPECT_FALSE(request->started());
698
699 std::unique_ptr<TestRequest> after(
700 NewRequest("http://host/after", net::IDLE));
701 EXPECT_FALSE(after->started());
702 }
703
651 TEST_F(ResourceSchedulerTest, NewSpdyHostInDelayableRequests) { 704 TEST_F(ResourceSchedulerTest, NewSpdyHostInDelayableRequests) {
705 base::test::ScopedFeatureList scoped_feature_list;
706 scoped_feature_list.InitFromCommandLine("",
707 kPrioritySupportedRequestsDelayable);
708 InitializeScheduler();
709
652 scheduler()->OnWillInsertBody(kChildId, kRouteId); 710 scheduler()->OnWillInsertBody(kChildId, kRouteId);
653 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. 711 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc.
654 712
655 std::unique_ptr<TestRequest> low1_spdy( 713 std::unique_ptr<TestRequest> low1_spdy(
656 NewRequest("http://spdyhost1:8080/low", net::LOWEST)); 714 NewRequest("http://spdyhost1:8080/low", net::LOWEST));
657 // Cancel a request after we learn the server supports SPDY. 715 // Cancel a request after we learn the server supports SPDY.
658 ScopedVector<TestRequest> lows; 716 ScopedVector<TestRequest> lows;
659 for (int i = 0; i < kMaxNumDelayableRequestsPerClient - 1; ++i) { 717 for (int i = 0; i < kMaxNumDelayableRequestsPerClient - 1; ++i) {
660 string url = "http://host" + base::IntToString(i) + "/low"; 718 string url = "http://host" + base::IntToString(i) + "/low";
661 lows.push_back(NewRequest(url.c_str(), net::LOWEST)); 719 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. 733 // Reprioritize a request after we learn the server supports SPDY.
676 EXPECT_TRUE(low2_spdy->started()); 734 EXPECT_TRUE(low2_spdy->started());
677 http_server_properties_.SetSupportsSpdy( 735 http_server_properties_.SetSupportsSpdy(
678 url::SchemeHostPort("http", "spdyhost2", 8080), true); 736 url::SchemeHostPort("http", "spdyhost2", 8080), true);
679 ChangeRequestPriority(low2_spdy.get(), net::LOWEST); 737 ChangeRequestPriority(low2_spdy.get(), net::LOWEST);
680 base::RunLoop().RunUntilIdle(); 738 base::RunLoop().RunUntilIdle();
681 std::unique_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); 739 std::unique_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
682 EXPECT_TRUE(low2->started()); 740 EXPECT_TRUE(low2->started());
683 } 741 }
684 742
743 TEST_F(ResourceSchedulerTest, NewDelayableSpdyHostInDelayableRequests) {
744 scheduler()->OnWillInsertBody(kChildId, kRouteId);
745 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc.
746
747 std::unique_ptr<TestRequest> low1_spdy(
748 NewRequest("http://spdyhost1:8080/low", net::LOWEST));
749 // Cancel a request after we learn the server supports SPDY.
750 ScopedVector<TestRequest> lows;
751 for (int i = 0; i < kMaxNumDelayableRequestsPerClient - 1; ++i) {
752 string url = "http://host" + base::IntToString(i) + "/low";
753 lows.push_back(NewRequest(url.c_str(), net::LOWEST));
754 }
755 std::unique_ptr<TestRequest> low1(NewRequest("http://host/low", net::LOWEST));
756 EXPECT_FALSE(low1->started());
757 http_server_properties_.SetSupportsSpdy(
758 url::SchemeHostPort("http", "spdyhost1", 8080), true);
759 low1_spdy.reset();
760 base::RunLoop().RunUntilIdle();
761 EXPECT_TRUE(low1->started());
762
763 low1.reset();
764 base::RunLoop().RunUntilIdle();
765 std::unique_ptr<TestRequest> low2_spdy(
766 NewRequest("http://spdyhost2:8080/low", net::IDLE));
767 // Reprioritize a request after we learn the server supports SPDY.
768 EXPECT_TRUE(low2_spdy->started());
769 http_server_properties_.SetSupportsSpdy(
770 url::SchemeHostPort("http", "spdyhost2", 8080), true);
771 ChangeRequestPriority(low2_spdy.get(), net::LOWEST);
772 base::RunLoop().RunUntilIdle();
773 std::unique_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
774 EXPECT_FALSE(low2->started());
775 }
776
685 // Async revalidations which are not started when the tab is closed must be 777 // 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 778 // started at some point, or they will hang around forever and prevent other
687 // async revalidations to the same URL from being issued. 779 // async revalidations to the same URL from being issued.
688 TEST_F(ResourceSchedulerTest, RequestStartedAfterClientDeleted) { 780 TEST_F(ResourceSchedulerTest, RequestStartedAfterClientDeleted) {
689 scheduler_->OnClientCreated(kChildId2, kRouteId2); 781 scheduler_->OnClientCreated(kChildId2, kRouteId2);
690 std::unique_ptr<TestRequest> high(NewRequestWithChildAndRoute( 782 std::unique_ptr<TestRequest> high(NewRequestWithChildAndRoute(
691 "http://host/high", net::HIGHEST, kChildId2, kRouteId2)); 783 "http://host/high", net::HIGHEST, kChildId2, kRouteId2));
692 std::unique_ptr<TestRequest> lowest1(NewRequestWithChildAndRoute( 784 std::unique_ptr<TestRequest> lowest1(NewRequestWithChildAndRoute(
693 "http://host/lowest", net::LOWEST, kChildId2, kRouteId2)); 785 "http://host/lowest", net::LOWEST, kChildId2, kRouteId2));
694 std::unique_ptr<TestRequest> lowest2(NewRequestWithChildAndRoute( 786 std::unique_ptr<TestRequest> lowest2(NewRequestWithChildAndRoute(
(...skipping 28 matching lines...) Expand all
723 scheduler_->OnClientDeleted(kChildId2, kRouteId2); 815 scheduler_->OnClientDeleted(kChildId2, kRouteId2);
724 high.reset(); 816 high.reset();
725 delayable_requests.clear(); 817 delayable_requests.clear();
726 base::RunLoop().RunUntilIdle(); 818 base::RunLoop().RunUntilIdle();
727 EXPECT_TRUE(lowest->started()); 819 EXPECT_TRUE(lowest->started());
728 } 820 }
729 821
730 } // unnamed namespace 822 } // unnamed namespace
731 823
732 } // namespace content 824 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_scheduler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698