| OLD | NEW |
| 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/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "content/public/test/test_browser_context.h" | 24 #include "content/public/test/test_browser_context.h" |
| 25 #include "content/test/test_render_view_host_factory.h" | 25 #include "content/test/test_render_view_host_factory.h" |
| 26 #include "content/test/test_web_contents.h" | 26 #include "content/test/test_web_contents.h" |
| 27 #include "net/base/host_port_pair.h" | 27 #include "net/base/host_port_pair.h" |
| 28 #include "net/base/request_priority.h" | 28 #include "net/base/request_priority.h" |
| 29 #include "net/http/http_server_properties_impl.h" | 29 #include "net/http/http_server_properties_impl.h" |
| 30 #include "net/url_request/url_request.h" | 30 #include "net/url_request/url_request.h" |
| 31 #include "net/url_request/url_request_test_util.h" | 31 #include "net/url_request/url_request_test_util.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 33 #include "ui/events/latency_info.h" | 33 #include "ui/events/latency_info.h" |
| 34 #include "url/scheme_host_port.h" |
| 34 | 35 |
| 35 using std::string; | 36 using std::string; |
| 36 | 37 |
| 37 namespace content { | 38 namespace content { |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 class TestRequestFactory; | 42 class TestRequestFactory; |
| 42 | 43 |
| 43 const int kChildId = 30; | 44 const int kChildId = 30; |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 EXPECT_TRUE(lowest->started()); | 331 EXPECT_TRUE(lowest->started()); |
| 331 EXPECT_FALSE(lowest2->started()); | 332 EXPECT_FALSE(lowest2->started()); |
| 332 | 333 |
| 333 scheduler()->OnWillInsertBody(kChildId, kRouteId); | 334 scheduler()->OnWillInsertBody(kChildId, kRouteId); |
| 334 base::RunLoop().RunUntilIdle(); | 335 base::RunLoop().RunUntilIdle(); |
| 335 EXPECT_TRUE(lowest2->started()); | 336 EXPECT_TRUE(lowest2->started()); |
| 336 } | 337 } |
| 337 | 338 |
| 338 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilBodyInsertedExceptSpdy) { | 339 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilBodyInsertedExceptSpdy) { |
| 339 http_server_properties_.SetSupportsSpdy( | 340 http_server_properties_.SetSupportsSpdy( |
| 340 net::HostPortPair("spdyhost", 443), true); | 341 url::SchemeHostPort("https", "spdyhost", 443), true); |
| 341 std::unique_ptr<TestRequest> high( | 342 std::unique_ptr<TestRequest> high( |
| 342 NewRequest("http://host/high", net::HIGHEST)); | 343 NewRequest("http://host/high", net::HIGHEST)); |
| 343 std::unique_ptr<TestRequest> low_spdy( | 344 std::unique_ptr<TestRequest> low_spdy( |
| 344 NewRequest("https://spdyhost/low", net::LOWEST)); | 345 NewRequest("https://spdyhost/low", net::LOWEST)); |
| 345 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); | 346 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); |
| 346 std::unique_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); | 347 std::unique_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); |
| 347 EXPECT_TRUE(high->started()); | 348 EXPECT_TRUE(high->started()); |
| 348 EXPECT_TRUE(low_spdy->started()); | 349 EXPECT_TRUE(low_spdy->started()); |
| 349 EXPECT_TRUE(low->started()); | 350 EXPECT_TRUE(low->started()); |
| 350 EXPECT_FALSE(low2->started()); | 351 EXPECT_FALSE(low2->started()); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 NewRequest("http://spdyhost1:8080/low", net::LOWEST)); | 659 NewRequest("http://spdyhost1:8080/low", net::LOWEST)); |
| 659 // Cancel a request after we learn the server supports SPDY. | 660 // Cancel a request after we learn the server supports SPDY. |
| 660 ScopedVector<TestRequest> lows; | 661 ScopedVector<TestRequest> lows; |
| 661 for (int i = 0; i < kMaxNumDelayableRequestsPerClient - 1; ++i) { | 662 for (int i = 0; i < kMaxNumDelayableRequestsPerClient - 1; ++i) { |
| 662 string url = "http://host" + base::IntToString(i) + "/low"; | 663 string url = "http://host" + base::IntToString(i) + "/low"; |
| 663 lows.push_back(NewRequest(url.c_str(), net::LOWEST)); | 664 lows.push_back(NewRequest(url.c_str(), net::LOWEST)); |
| 664 } | 665 } |
| 665 std::unique_ptr<TestRequest> low1(NewRequest("http://host/low", net::LOWEST)); | 666 std::unique_ptr<TestRequest> low1(NewRequest("http://host/low", net::LOWEST)); |
| 666 EXPECT_FALSE(low1->started()); | 667 EXPECT_FALSE(low1->started()); |
| 667 http_server_properties_.SetSupportsSpdy( | 668 http_server_properties_.SetSupportsSpdy( |
| 668 net::HostPortPair("spdyhost1", 8080), true); | 669 url::SchemeHostPort("http", "spdyhost1", 8080), true); |
| 669 low1_spdy.reset(); | 670 low1_spdy.reset(); |
| 670 base::RunLoop().RunUntilIdle(); | 671 base::RunLoop().RunUntilIdle(); |
| 671 EXPECT_TRUE(low1->started()); | 672 EXPECT_TRUE(low1->started()); |
| 672 | 673 |
| 673 low1.reset(); | 674 low1.reset(); |
| 674 base::RunLoop().RunUntilIdle(); | 675 base::RunLoop().RunUntilIdle(); |
| 675 std::unique_ptr<TestRequest> low2_spdy( | 676 std::unique_ptr<TestRequest> low2_spdy( |
| 676 NewRequest("http://spdyhost2:8080/low", net::IDLE)); | 677 NewRequest("http://spdyhost2:8080/low", net::IDLE)); |
| 677 // Reprioritize a request after we learn the server supports SPDY. | 678 // Reprioritize a request after we learn the server supports SPDY. |
| 678 EXPECT_TRUE(low2_spdy->started()); | 679 EXPECT_TRUE(low2_spdy->started()); |
| 679 http_server_properties_.SetSupportsSpdy( | 680 http_server_properties_.SetSupportsSpdy( |
| 680 net::HostPortPair("spdyhost2", 8080), true); | 681 url::SchemeHostPort("http", "spdyhost2", 8080), true); |
| 681 ChangeRequestPriority(low2_spdy.get(), net::LOWEST); | 682 ChangeRequestPriority(low2_spdy.get(), net::LOWEST); |
| 682 base::RunLoop().RunUntilIdle(); | 683 base::RunLoop().RunUntilIdle(); |
| 683 std::unique_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); | 684 std::unique_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); |
| 684 EXPECT_TRUE(low2->started()); | 685 EXPECT_TRUE(low2->started()); |
| 685 } | 686 } |
| 686 | 687 |
| 687 TEST_F(ResourceSchedulerTest, OustandingRequestLimitEnforced) { | 688 TEST_F(ResourceSchedulerTest, OustandingRequestLimitEnforced) { |
| 688 const int kRequestLimit = 3; | 689 const int kRequestLimit = 3; |
| 689 ASSERT_TRUE(InitializeFieldTrials( | 690 ASSERT_TRUE(InitializeFieldTrials( |
| 690 base::StringPrintf("OutstandingRequestLimiting/Limit=%d/", | 691 base::StringPrintf("OutstandingRequestLimiting/Limit=%d/", |
| (...skipping 18 matching lines...) Expand all Loading... |
| 709 // that support request priority. | 710 // that support request priority. |
| 710 TEST_F(ResourceSchedulerTest, | 711 TEST_F(ResourceSchedulerTest, |
| 711 OutstandingRequestsLimitsEnforcedForRequestPriority) { | 712 OutstandingRequestsLimitsEnforcedForRequestPriority) { |
| 712 const int kRequestLimit = 3; | 713 const int kRequestLimit = 3; |
| 713 ASSERT_TRUE(InitializeFieldTrials( | 714 ASSERT_TRUE(InitializeFieldTrials( |
| 714 base::StringPrintf("OutstandingRequestLimiting/Limit=%d/", | 715 base::StringPrintf("OutstandingRequestLimiting/Limit=%d/", |
| 715 kRequestLimit))); | 716 kRequestLimit))); |
| 716 InitializeScheduler(); | 717 InitializeScheduler(); |
| 717 | 718 |
| 718 http_server_properties_.SetSupportsSpdy( | 719 http_server_properties_.SetSupportsSpdy( |
| 719 net::HostPortPair("spdyhost", 443), true); | 720 url::SchemeHostPort("https", "spdyhost", 443), true); |
| 720 | 721 |
| 721 // Throw in requests up to the above limit; make sure they are started. | 722 // Throw in requests up to the above limit; make sure they are started. |
| 722 ScopedVector<TestRequest> requests; | 723 ScopedVector<TestRequest> requests; |
| 723 for (int i = 0; i < kRequestLimit; ++i) { | 724 for (int i = 0; i < kRequestLimit; ++i) { |
| 724 string url = "http://spdyhost/medium"; | 725 string url = "http://spdyhost/medium"; |
| 725 requests.push_back(NewRequest(url.c_str(), net::MEDIUM)); | 726 requests.push_back(NewRequest(url.c_str(), net::MEDIUM)); |
| 726 EXPECT_TRUE(requests[i]->started()); | 727 EXPECT_TRUE(requests[i]->started()); |
| 727 } | 728 } |
| 728 | 729 |
| 729 // Confirm that another request will indeed fail. | 730 // Confirm that another request will indeed fail. |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 } | 1169 } |
| 1169 | 1170 |
| 1170 std::unique_ptr<TestRequest> last_different_host( | 1171 std::unique_ptr<TestRequest> last_different_host( |
| 1171 NewRequest("http://host_new/last", net::LOWEST)); | 1172 NewRequest("http://host_new/last", net::LOWEST)); |
| 1172 EXPECT_FALSE(last_different_host->started()); | 1173 EXPECT_FALSE(last_different_host->started()); |
| 1173 } | 1174 } |
| 1174 | 1175 |
| 1175 } // unnamed namespace | 1176 } // unnamed namespace |
| 1176 | 1177 |
| 1177 } // namespace content | 1178 } // namespace content |
| OLD | NEW |