| 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 <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
| 13 #include "base/metrics/field_trial_param_associator.h" | 13 #include "base/metrics/field_trial_param_associator.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/test/histogram_tester.h" |
| 16 #include "base/test/mock_entropy_provider.h" | 17 #include "base/test/mock_entropy_provider.h" |
| 17 #include "base/test/scoped_feature_list.h" | 18 #include "base/test/scoped_feature_list.h" |
| 18 #include "base/timer/mock_timer.h" | 19 #include "base/timer/mock_timer.h" |
| 19 #include "base/timer/timer.h" | 20 #include "base/timer/timer.h" |
| 20 #include "content/public/browser/resource_context.h" | 21 #include "content/public/browser/resource_context.h" |
| 21 #include "content/public/browser/resource_throttle.h" | 22 #include "content/public/browser/resource_throttle.h" |
| 22 #include "content/public/test/mock_render_process_host.h" | 23 #include "content/public/test/mock_render_process_host.h" |
| 23 #include "content/public/test/test_browser_context.h" | 24 #include "content/public/test/test_browser_context.h" |
| 24 #include "content/public/test/test_browser_thread_bundle.h" | 25 #include "content/public/test/test_browser_thread_bundle.h" |
| 25 #include "content/test/test_render_view_host_factory.h" | 26 #include "content/test/test_render_view_host_factory.h" |
| 26 #include "content/test/test_web_contents.h" | 27 #include "content/test/test_web_contents.h" |
| 27 #include "net/base/host_port_pair.h" | 28 #include "net/base/host_port_pair.h" |
| 28 #include "net/base/request_priority.h" | 29 #include "net/base/request_priority.h" |
| 29 #include "net/http/http_server_properties_impl.h" | 30 #include "net/http/http_server_properties_impl.h" |
| 30 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" | 31 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 31 #include "net/url_request/url_request.h" | 32 #include "net/url_request/url_request.h" |
| 32 #include "net/url_request/url_request_test_util.h" | 33 #include "net/url_request/url_request_test_util.h" |
| 34 #include "testing/gmock/include/gmock/gmock.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 34 #include "ui/latency/latency_info.h" | 36 #include "ui/latency/latency_info.h" |
| 35 #include "url/scheme_host_port.h" | 37 #include "url/scheme_host_port.h" |
| 36 | 38 |
| 37 using std::string; | 39 using std::string; |
| 38 | 40 |
| 39 namespace content { | 41 namespace content { |
| 40 | 42 |
| 41 namespace { | 43 namespace { |
| 42 | 44 |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 EXPECT_TRUE(low_spdy->started()); | 500 EXPECT_TRUE(low_spdy->started()); |
| 499 EXPECT_FALSE(low->started()); | 501 EXPECT_FALSE(low->started()); |
| 500 | 502 |
| 501 scheduler()->OnWillInsertBody(kChildId, kRouteId); | 503 scheduler()->OnWillInsertBody(kChildId, kRouteId); |
| 502 high.reset(); | 504 high.reset(); |
| 503 base::RunLoop().RunUntilIdle(); | 505 base::RunLoop().RunUntilIdle(); |
| 504 EXPECT_TRUE(low->started()); | 506 EXPECT_TRUE(low->started()); |
| 505 } | 507 } |
| 506 | 508 |
| 507 TEST_F(ResourceSchedulerTest, NavigationResetsState) { | 509 TEST_F(ResourceSchedulerTest, NavigationResetsState) { |
| 510 base::HistogramTester histogram_tester; |
| 508 scheduler()->OnWillInsertBody(kChildId, kRouteId); | 511 scheduler()->OnWillInsertBody(kChildId, kRouteId); |
| 509 scheduler()->OnNavigate(kChildId, kRouteId); | 512 scheduler()->OnNavigate(kChildId, kRouteId); |
| 510 std::unique_ptr<TestRequest> high( | 513 |
| 511 NewRequest("http://host/high", net::HIGHEST)); | 514 { |
| 512 std::unique_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); | 515 std::unique_ptr<TestRequest> high( |
| 513 std::unique_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); | 516 NewRequest("http://host/high", net::HIGHEST)); |
| 514 EXPECT_TRUE(high->started()); | 517 std::unique_ptr<TestRequest> low( |
| 515 EXPECT_TRUE(low->started()); | 518 NewRequest("http://host/low", net::LOWEST)); |
| 516 EXPECT_FALSE(low2->started()); | 519 std::unique_ptr<TestRequest> low2( |
| 520 NewRequest("http://host/low", net::LOWEST)); |
| 521 EXPECT_TRUE(high->started()); |
| 522 EXPECT_TRUE(low->started()); |
| 523 EXPECT_FALSE(low2->started()); |
| 524 } |
| 525 |
| 526 histogram_tester.ExpectTotalCount("ResourceScheduler.RequestsCount.All", 2); |
| 527 EXPECT_THAT( |
| 528 histogram_tester.GetAllSamples("ResourceScheduler.RequestsCount.All"), |
| 529 testing::ElementsAre(base::Bucket(1, 1), base::Bucket(2, 1))); |
| 530 |
| 531 histogram_tester.ExpectTotalCount("ResourceScheduler.RequestsCount.Delayable", |
| 532 2); |
| 533 histogram_tester.ExpectTotalCount( |
| 534 "ResourceScheduler.RequestsCount.NonDelayable", 2); |
| 535 histogram_tester.ExpectTotalCount( |
| 536 "ResourceScheduler.RequestsCount.TotalLayoutBlocking", 2); |
| 537 |
| 538 histogram_tester.ExpectUniqueSample( |
| 539 "ResourceScheduler.PeakDelayableRequestsInFlight.LayoutBlocking", 1, 1); |
| 540 histogram_tester.ExpectUniqueSample( |
| 541 "ResourceScheduler.PeakDelayableRequestsInFlight.NonDelayable", 1, 1); |
| 517 } | 542 } |
| 518 | 543 |
| 519 TEST_F(ResourceSchedulerTest, BackgroundRequestStartsImmediately) { | 544 TEST_F(ResourceSchedulerTest, BackgroundRequestStartsImmediately) { |
| 520 const int route_id = 0; // Indicates a background request. | 545 const int route_id = 0; // Indicates a background request. |
| 521 std::unique_ptr<TestRequest> request( | 546 std::unique_ptr<TestRequest> request( |
| 522 NewRequestWithRoute("http://host/1", net::LOWEST, route_id)); | 547 NewRequestWithRoute("http://host/1", net::LOWEST, route_id)); |
| 523 EXPECT_TRUE(request->started()); | 548 EXPECT_TRUE(request->started()); |
| 524 } | 549 } |
| 525 | 550 |
| 526 TEST_F(ResourceSchedulerTest, MoreThanOneHighRequestBlocksDelayableRequests) { | 551 TEST_F(ResourceSchedulerTest, MoreThanOneHighRequestBlocksDelayableRequests) { |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 scheduler_->OnClientDeleted(kChildId2, kRouteId2); | 978 scheduler_->OnClientDeleted(kChildId2, kRouteId2); |
| 954 high.reset(); | 979 high.reset(); |
| 955 delayable_requests.clear(); | 980 delayable_requests.clear(); |
| 956 base::RunLoop().RunUntilIdle(); | 981 base::RunLoop().RunUntilIdle(); |
| 957 EXPECT_TRUE(lowest->started()); | 982 EXPECT_TRUE(lowest->started()); |
| 958 } | 983 } |
| 959 | 984 |
| 960 } // unnamed namespace | 985 } // unnamed namespace |
| 961 | 986 |
| 962 } // namespace content | 987 } // namespace content |
| OLD | NEW |