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

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

Issue 393163003: Add coalescing timer to ResourceScheduler. CL 2 from BUG=128035. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@rsblank
Patch Set: Nits and reviewer suggestions. Created 6 years, 4 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 "base/memory/scoped_vector.h" 7 #include "base/memory/scoped_vector.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/timer/mock_timer.h"
11 #include "base/timer/timer.h"
10 #include "content/browser/browser_thread_impl.h" 12 #include "content/browser/browser_thread_impl.h"
11 #include "content/browser/loader/resource_dispatcher_host_impl.h" 13 #include "content/browser/loader/resource_dispatcher_host_impl.h"
12 #include "content/browser/loader/resource_message_filter.h" 14 #include "content/browser/loader/resource_message_filter.h"
13 #include "content/browser/loader/resource_request_info_impl.h" 15 #include "content/browser/loader/resource_request_info_impl.h"
14 #include "content/common/resource_messages.h" 16 #include "content/common/resource_messages.h"
15 #include "content/public/browser/resource_context.h" 17 #include "content/public/browser/resource_context.h"
16 #include "content/public/browser/resource_controller.h" 18 #include "content/public/browser/resource_controller.h"
17 #include "content/public/browser/resource_throttle.h" 19 #include "content/public/browser/resource_throttle.h"
18 #include "content/public/common/process_type.h" 20 #include "content/public/common/process_type.h"
19 #include "content/public/common/resource_type.h" 21 #include "content/public/common/resource_type.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 131 }
130 132
131 FakeResourceContext context_; 133 FakeResourceContext context_;
132 }; 134 };
133 135
134 class ResourceSchedulerTest : public testing::Test { 136 class ResourceSchedulerTest : public testing::Test {
135 protected: 137 protected:
136 ResourceSchedulerTest() 138 ResourceSchedulerTest()
137 : next_request_id_(0), 139 : next_request_id_(0),
138 ui_thread_(BrowserThread::UI, &message_loop_), 140 ui_thread_(BrowserThread::UI, &message_loop_),
139 io_thread_(BrowserThread::IO, &message_loop_) { 141 io_thread_(BrowserThread::IO, &message_loop_),
142 mock_timer_(new base::MockTimer(true, true)) {
143 scheduler_.set_timer_for_testing(scoped_ptr<base::Timer>(mock_timer_));
144
145 // TODO(aiolos): Remove when throttling and coalescing have both landed.
146 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
147 false /* should_coalesce */);
140 148
141 scheduler_.OnClientCreated(kChildId, kRouteId); 149 scheduler_.OnClientCreated(kChildId, kRouteId);
142 scheduler_.OnVisibilityChanged(kChildId, kRouteId, true); 150 scheduler_.OnVisibilityChanged(kChildId, kRouteId, true);
143 scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId); 151 scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId);
144 context_.set_http_server_properties(http_server_properties_.GetWeakPtr()); 152 context_.set_http_server_properties(http_server_properties_.GetWeakPtr());
145 } 153 }
146 154
147 virtual ~ResourceSchedulerTest() { 155 virtual ~ResourceSchedulerTest() {
148 scheduler_.OnClientDeleted(kChildId, kRouteId); 156 scheduler_.OnClientDeleted(kChildId, kRouteId);
149 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId); 157 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 scoped_refptr<FakeResourceMessageFilter> filter( 258 scoped_refptr<FakeResourceMessageFilter> filter(
251 new FakeResourceMessageFilter(kChildId)); 259 new FakeResourceMessageFilter(kChildId));
252 const ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( 260 const ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(
253 request->url_request()); 261 request->url_request());
254 const GlobalRequestID& id = info->GetGlobalRequestID(); 262 const GlobalRequestID& id = info->GetGlobalRequestID();
255 ResourceHostMsg_DidChangePriority msg(id.request_id, new_priority, 263 ResourceHostMsg_DidChangePriority msg(id.request_id, new_priority,
256 intra_priority); 264 intra_priority);
257 rdh_.OnMessageReceived(msg, filter.get()); 265 rdh_.OnMessageReceived(msg, filter.get());
258 } 266 }
259 267
268 void FireCoalescingTimer() {
269 EXPECT_TRUE(mock_timer_->IsRunning());
270 mock_timer_->Fire();
271 }
272
260 int next_request_id_; 273 int next_request_id_;
261 base::MessageLoopForIO message_loop_; 274 base::MessageLoopForIO message_loop_;
262 BrowserThreadImpl ui_thread_; 275 BrowserThreadImpl ui_thread_;
263 BrowserThreadImpl io_thread_; 276 BrowserThreadImpl io_thread_;
264 ResourceDispatcherHostImpl rdh_; 277 ResourceDispatcherHostImpl rdh_;
265 ResourceScheduler scheduler_; 278 ResourceScheduler scheduler_;
279 base::MockTimer* mock_timer_;
266 net::HttpServerPropertiesImpl http_server_properties_; 280 net::HttpServerPropertiesImpl http_server_properties_;
267 net::TestURLRequestContext context_; 281 net::TestURLRequestContext context_;
268 }; 282 };
269 283
270 TEST_F(ResourceSchedulerTest, OneIsolatedLowRequest) { 284 TEST_F(ResourceSchedulerTest, OneIsolatedLowRequest) {
271 scoped_ptr<TestRequest> request(NewRequest("http://host/1", net::LOWEST)); 285 scoped_ptr<TestRequest> request(NewRequest("http://host/1", net::LOWEST));
272 EXPECT_TRUE(request->started()); 286 EXPECT_TRUE(request->started());
273 } 287 }
274 288
275 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilIdle) { 289 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilIdle) {
(...skipping 1468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 kBackgroundRouteId)); 1758 kBackgroundRouteId));
1745 EXPECT_EQ(ResourceScheduler::THROTTLED, 1759 EXPECT_EQ(ResourceScheduler::THROTTLED,
1746 scheduler_.GetClientStateForTesting(kBackgroundChildId2, 1760 scheduler_.GetClientStateForTesting(kBackgroundChildId2,
1747 kBackgroundRouteId2)); 1761 kBackgroundRouteId2));
1748 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, 1762 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING,
1749 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); 1763 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1750 1764
1751 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1765 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1752 } 1766 }
1753 1767
1768 TEST_F(ResourceSchedulerTest, CoalescedClientCreationStartsTimer) {
1769 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1770 true /* should_coalesce */);
1771 EXPECT_FALSE(mock_timer_->IsRunning());
1772 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1773 EXPECT_FALSE(mock_timer_->IsRunning());
1774 scheduler_.OnLoadingStateChanged(
1775 kBackgroundChildId, kBackgroundRouteId, true);
1776 EXPECT_EQ(ResourceScheduler::COALESCED,
1777 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1778 kBackgroundRouteId));
1779 EXPECT_TRUE(mock_timer_->IsRunning());
1780 }
1781
1782 TEST_F(ResourceSchedulerTest, ActiveLoadingClientLoadedAndHiddenStartsTimer) {
1783 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1784 true /* should_coalesce */);
1785 EXPECT_FALSE(mock_timer_->IsRunning());
1786 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING,
1787 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1788 EXPECT_EQ(ResourceScheduler::THROTTLED,
1789 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1790 kBackgroundRouteId));
1791 EXPECT_FALSE(mock_timer_->IsRunning());
1792
1793 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1794 EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
1795 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1796 EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
1797 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1798 kBackgroundRouteId));
1799 EXPECT_FALSE(mock_timer_->IsRunning());
1800
1801 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
1802 EXPECT_EQ(ResourceScheduler::COALESCED,
1803 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1804 EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
1805 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1806 kBackgroundRouteId));
1807 EXPECT_TRUE(mock_timer_->IsRunning());
1808 }
1809
1810 TEST_F(ResourceSchedulerTest, ActiveLoadingClientHiddenAndLoadedStartsTimer) {
1811 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1812 true /* should_coalesce */);
1813 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING,
1814 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1815 EXPECT_EQ(ResourceScheduler::THROTTLED,
1816 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1817 kBackgroundRouteId));
1818 EXPECT_FALSE(mock_timer_->IsRunning());
1819
1820 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
1821 EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
1822 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1823 EXPECT_FALSE(mock_timer_->IsRunning());
1824
1825 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1826 EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
1827 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1828 kBackgroundRouteId));
1829 EXPECT_EQ(ResourceScheduler::COALESCED,
1830 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1831 EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
1832 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1833 kBackgroundRouteId));
1834 EXPECT_TRUE(mock_timer_->IsRunning());
1835 }
1836
1837 TEST_F(ResourceSchedulerTest, LastCoalescedClientDeletionStopsTimer) {
1838 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1839 true /* should_coalesce */);
1840 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
1841 EXPECT_FALSE(mock_timer_->IsRunning());
1842 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1843 EXPECT_FALSE(mock_timer_->IsRunning());
1844 scheduler_.OnLoadingStateChanged(
1845 kBackgroundChildId, kBackgroundRouteId, true);
1846 EXPECT_EQ(ResourceScheduler::COALESCED,
1847 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1848 kBackgroundRouteId));
1849 scheduler_.OnLoadingStateChanged(
1850 kBackgroundChildId2, kBackgroundRouteId2, true);
1851 EXPECT_EQ(ResourceScheduler::COALESCED,
1852 scheduler_.GetClientStateForTesting(kBackgroundChildId2,
1853 kBackgroundRouteId2));
1854 EXPECT_TRUE(mock_timer_->IsRunning());
1855
1856 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId);
1857 EXPECT_TRUE(mock_timer_->IsRunning());
1858
1859 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1860 EXPECT_FALSE(mock_timer_->IsRunning());
1861
1862 // To avoid errors on test tear down.
1863 scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId);
1864 }
1865
1866 TEST_F(ResourceSchedulerTest, LastCoalescedClientStartsLoadingStopsTimer) {
1867 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1868 true /* should_coalesce */);
1869 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
1870 EXPECT_FALSE(mock_timer_->IsRunning());
1871 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1872 EXPECT_FALSE(mock_timer_->IsRunning());
1873 scheduler_.OnLoadingStateChanged(
1874 kBackgroundChildId, kBackgroundRouteId, true);
1875 EXPECT_EQ(ResourceScheduler::COALESCED,
1876 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1877 kBackgroundRouteId));
1878 scheduler_.OnLoadingStateChanged(
1879 kBackgroundChildId2, kBackgroundRouteId2, true);
1880 EXPECT_EQ(ResourceScheduler::COALESCED,
1881 scheduler_.GetClientStateForTesting(kBackgroundChildId2,
1882 kBackgroundRouteId2));
1883 EXPECT_TRUE(mock_timer_->IsRunning());
1884
1885 scheduler_.OnLoadingStateChanged(
1886 kBackgroundChildId, kBackgroundRouteId, false);
1887 EXPECT_TRUE(mock_timer_->IsRunning());
1888
1889 scheduler_.OnLoadingStateChanged(
1890 kBackgroundChildId2, kBackgroundRouteId2, false);
1891 EXPECT_FALSE(mock_timer_->IsRunning());
1892
1893 // This is needed to avoid errors on test tear down.
1894 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1895 }
1896
1897 TEST_F(ResourceSchedulerTest, LastCoalescedClientBecomesVisibleStopsTimer) {
1898 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1899 true /* should_coalesce */);
1900 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
1901 EXPECT_FALSE(mock_timer_->IsRunning());
1902 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1903 EXPECT_FALSE(mock_timer_->IsRunning());
1904 scheduler_.OnLoadingStateChanged(
1905 kBackgroundChildId, kBackgroundRouteId, true);
1906 EXPECT_EQ(ResourceScheduler::COALESCED,
1907 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1908 kBackgroundRouteId));
1909 scheduler_.OnLoadingStateChanged(
1910 kBackgroundChildId2, kBackgroundRouteId2, true);
1911 EXPECT_EQ(ResourceScheduler::COALESCED,
1912 scheduler_.GetClientStateForTesting(kBackgroundChildId2,
1913 kBackgroundRouteId2));
1914 EXPECT_TRUE(mock_timer_->IsRunning());
1915
1916 scheduler_.OnVisibilityChanged(kBackgroundChildId, kBackgroundRouteId, true);
1917 EXPECT_TRUE(mock_timer_->IsRunning());
1918
1919 scheduler_.OnVisibilityChanged(
1920 kBackgroundChildId2, kBackgroundRouteId2, true);
1921 EXPECT_FALSE(mock_timer_->IsRunning());
1922
1923 // To avoid errors on test tear down.
1924 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1925 }
1926
1927 TEST_F(ResourceSchedulerTest,
1928 CoalescedClientBecomesVisibleAndLoadingStopsTimer) {
1929 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1930 true /* should_coalesce */);
1931 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1932 EXPECT_FALSE(mock_timer_->IsRunning());
1933 scheduler_.OnLoadingStateChanged(
1934 kBackgroundChildId, kBackgroundRouteId, true);
1935 EXPECT_EQ(ResourceScheduler::COALESCED,
1936 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1937 kBackgroundRouteId));
1938 EXPECT_TRUE(mock_timer_->IsRunning());
1939
1940 scheduler_.OnAudibilityChanged(kBackgroundChildId, kBackgroundRouteId, true);
1941 EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
1942 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1943 kBackgroundRouteId));
1944 EXPECT_FALSE(mock_timer_->IsRunning());
1945
1946 scheduler_.OnLoadingStateChanged(
1947 kBackgroundChildId, kBackgroundRouteId, false);
1948 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING,
1949 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1950 kBackgroundRouteId));
1951 EXPECT_FALSE(mock_timer_->IsRunning());
1952 }
1953
1954 TEST_F(ResourceSchedulerTest,
1955 CoalescedClientBecomesLoadingAndVisibleStopsTimer) {
1956 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1957 true /* should_coalesce */);
1958 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1959 EXPECT_FALSE(mock_timer_->IsRunning());
1960 scheduler_.OnLoadingStateChanged(
1961 kBackgroundChildId, kBackgroundRouteId, true);
1962 EXPECT_EQ(ResourceScheduler::COALESCED,
1963 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1964 kBackgroundRouteId));
1965 EXPECT_TRUE(mock_timer_->IsRunning());
1966
1967 scheduler_.OnLoadingStateChanged(
1968 kBackgroundChildId, kBackgroundRouteId, false);
1969 EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
1970 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1971 kBackgroundRouteId));
1972 EXPECT_FALSE(mock_timer_->IsRunning());
1973
1974 scheduler_.OnVisibilityChanged(kBackgroundChildId, kBackgroundRouteId, true);
1975 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING,
1976 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1977 kBackgroundRouteId));
1978 EXPECT_FALSE(mock_timer_->IsRunning());
1979 }
1980
1981 TEST_F(ResourceSchedulerTest, CoalescedRequestsIssueOnTimer) {
1982 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1983 true /* should_coalesce */);
1984 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1985 scheduler_.OnLoadingStateChanged(
1986 kBackgroundChildId, kBackgroundRouteId, true);
1987 EXPECT_EQ(ResourceScheduler::COALESCED,
1988 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1989 kBackgroundRouteId));
1990 EXPECT_TRUE(scheduler_.active_clients_loaded());
1991
1992 scoped_ptr<TestRequest> high(
1993 NewBackgroundRequest("http://host/high", net::HIGHEST));
1994 scoped_ptr<TestRequest> low(
1995 NewBackgroundRequest("http://host/low", net::LOWEST));
1996 EXPECT_FALSE(high->started());
1997 EXPECT_FALSE(low->started());
1998
1999 FireCoalescingTimer();
2000
2001 EXPECT_TRUE(high->started());
2002 EXPECT_TRUE(low->started());
2003 }
2004
2005 TEST_F(ResourceSchedulerTest, CoalescedRequestsUnthrottleCorrectlyOnTimer) {
2006 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
2007 true /* should_coalesce */);
2008 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
2009 scheduler_.OnLoadingStateChanged(
2010 kBackgroundChildId, kBackgroundRouteId, true);
2011 EXPECT_EQ(ResourceScheduler::COALESCED,
2012 scheduler_.GetClientStateForTesting(kBackgroundChildId,
2013 kBackgroundRouteId));
2014 EXPECT_TRUE(scheduler_.active_clients_loaded());
2015
2016 scoped_ptr<TestRequest> high(
2017 NewBackgroundRequest("http://host/high", net::HIGHEST));
2018 scoped_ptr<TestRequest> high2(
2019 NewBackgroundRequest("http://host/high", net::HIGHEST));
2020 scoped_ptr<TestRequest> high3(
2021 NewBackgroundRequest("http://host/high", net::HIGHEST));
2022 scoped_ptr<TestRequest> high4(
2023 NewBackgroundRequest("http://host/high", net::HIGHEST));
2024 scoped_ptr<TestRequest> low(
2025 NewBackgroundRequest("http://host/low", net::LOWEST));
2026 scoped_ptr<TestRequest> low2(
2027 NewBackgroundRequest("http://host/low", net::LOWEST));
2028 scoped_ptr<TestRequest> low3(
2029 NewBackgroundRequest("http://host/low", net::LOWEST));
2030 scoped_ptr<TestRequest> low4(
2031 NewBackgroundRequest("http://host/low", net::LOWEST));
2032
2033 http_server_properties_.SetSupportsSpdy(net::HostPortPair("spdyhost", 443),
2034 true);
2035 scoped_ptr<TestRequest> low_spdy(
2036 NewBackgroundRequest("https://spdyhost/low", net::LOW));
2037 scoped_ptr<TestRequest> sync_request(
2038 NewBackgroundSyncRequest("http://host/req", net::LOW));
2039 scoped_ptr<TestRequest> non_http_request(
2040 NewBackgroundRequest("chrome-extension://req", net::LOW));
2041
2042 // Sync requests should issue immediately.
2043 EXPECT_TRUE(sync_request->started());
2044 // Non-http(s) requests should issue immediately.
2045 EXPECT_TRUE(non_http_request->started());
2046 // Nothing else should issue without a timer fire.
2047 EXPECT_FALSE(high->started());
2048 EXPECT_FALSE(high2->started());
2049 EXPECT_FALSE(high3->started());
2050 EXPECT_FALSE(high4->started());
2051 EXPECT_FALSE(low->started());
2052 EXPECT_FALSE(low2->started());
2053 EXPECT_FALSE(low3->started());
2054 EXPECT_FALSE(low4->started());
2055 EXPECT_FALSE(low_spdy->started());
2056
2057 FireCoalescingTimer();
2058
2059 // All high priority requests should issue.
2060 EXPECT_TRUE(high->started());
2061 EXPECT_TRUE(high2->started());
2062 EXPECT_TRUE(high3->started());
2063 EXPECT_TRUE(high4->started());
2064 // There should only be one net::LOWEST priority request issued with
2065 // non-delayable requests in flight.
2066 EXPECT_TRUE(low->started());
2067 EXPECT_FALSE(low2->started());
2068 EXPECT_FALSE(low3->started());
2069 EXPECT_FALSE(low4->started());
2070 // Spdy-Enable requests should issue regardless of priority.
2071 EXPECT_TRUE(low_spdy->started());
2072 }
2073
2074 TEST_F(ResourceSchedulerTest, CoalescedRequestsWaitForNextTimer) {
2075 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
2076 true /* should_coalesce */);
2077 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
2078 scheduler_.OnLoadingStateChanged(
2079 kBackgroundChildId, kBackgroundRouteId, true);
2080
2081 EXPECT_EQ(ResourceScheduler::COALESCED,
2082 scheduler_.GetClientStateForTesting(kBackgroundChildId,
2083 kBackgroundRouteId));
2084 EXPECT_TRUE(scheduler_.active_clients_loaded());
2085
2086 scoped_ptr<TestRequest> high(
2087 NewBackgroundRequest("http://host/high", net::HIGHEST));
2088 EXPECT_FALSE(high->started());
2089
2090 FireCoalescingTimer();
2091
2092 scoped_ptr<TestRequest> high2(
2093 NewBackgroundRequest("http://host/high2", net::HIGHEST));
2094 scoped_ptr<TestRequest> low(
2095 NewBackgroundRequest("http://host/low", net::LOWEST));
2096
2097 EXPECT_TRUE(high->started());
2098 EXPECT_FALSE(high2->started());
2099 EXPECT_FALSE(low->started());
2100
2101 FireCoalescingTimer();
2102
2103 EXPECT_TRUE(high->started());
2104 EXPECT_TRUE(high2->started());
2105 EXPECT_TRUE(low->started());
2106 }
2107
1754 } // unnamed namespace 2108 } // unnamed namespace
1755 2109
1756 } // namespace content 2110 } // 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