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

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: More tests and nits. 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
mmenke 2014/07/29 15:43:26 nit: Could put this in the initializer list.
aiolos (Not reviewing) 2014/07/29 17:58:51 Done.
143 scheduler_.set_timer_for_testing(scoped_ptr<base::Timer>(mock_timer_));
144
145 // TODO(aiolos): remove when throttling and coalescing have both landed
mmenke 2014/07/29 15:43:26 nit: Capitalize + add period.
aiolos (Not reviewing) 2014/07/29 17:58:51 Done.
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 CoalescedClientBecomesLoadingAndVisibleStopsTimer) {
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_.OnLoadingStateChanged(
1941 kBackgroundChildId, kBackgroundRouteId, false);
1942 EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
1943 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1944 kBackgroundRouteId));
1945 EXPECT_FALSE(mock_timer_->IsRunning());
1946
1947 scheduler_.OnVisibilityChanged(kBackgroundChildId, kBackgroundRouteId, true);
1948 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING,
1949 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1950 kBackgroundRouteId));
1951 EXPECT_FALSE(mock_timer_->IsRunning());
1952 }
1953 TEST_F(ResourceSchedulerTest,
1954 CoalescedClientBecomesVisibleAndLoadingStopsTimer) {
mmenke 2014/07/29 15:43:26 optional: Not sure this test gets us anything the
aiolos (Not reviewing) 2014/07/29 17:58:51 There are two ways to go from being COALESCED (bac
mmenke 2014/07/29 18:07:22 The request becomes uncoalesced on either of those
aiolos (Not reviewing) 2014/07/29 18:58:25 True. I kept the test, but changed it so that it's
1955 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1956 true /* should_coalesce */);
1957 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1958 EXPECT_FALSE(mock_timer_->IsRunning());
1959 scheduler_.OnLoadingStateChanged(
1960 kBackgroundChildId, kBackgroundRouteId, true);
1961 EXPECT_EQ(ResourceScheduler::COALESCED,
1962 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1963 kBackgroundRouteId));
1964 EXPECT_TRUE(mock_timer_->IsRunning());
1965
1966 scheduler_.OnVisibilityChanged(kBackgroundChildId, kBackgroundRouteId, true);
1967 EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
1968 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1969 kBackgroundRouteId));
1970 EXPECT_FALSE(mock_timer_->IsRunning());
1971
1972 scheduler_.OnLoadingStateChanged(
1973 kBackgroundChildId, kBackgroundRouteId, false);
1974 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING,
1975 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1976 kBackgroundRouteId));
1977 EXPECT_FALSE(mock_timer_->IsRunning());
1978 }
1979
1980 TEST_F(ResourceSchedulerTest, CoalescedRequestsIssueOnTimer) {
1981 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1982 true /* should_coalesce */);
1983 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1984 scheduler_.OnLoadingStateChanged(
1985 kBackgroundChildId, kBackgroundRouteId, true);
1986 EXPECT_EQ(ResourceScheduler::COALESCED,
1987 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1988 kBackgroundRouteId));
1989 EXPECT_TRUE(scheduler_.active_clients_loaded());
1990
1991 scoped_ptr<TestRequest> high(
1992 NewBackgroundRequest("http://host/high", net::HIGHEST));
1993 scoped_ptr<TestRequest> low(
1994 NewBackgroundRequest("http://host/low", net::LOWEST));
1995 EXPECT_FALSE(high->started());
1996 EXPECT_FALSE(low->started());
1997
1998 FireCoalescingTimer();
1999
2000 EXPECT_TRUE(high->started());
2001 EXPECT_TRUE(low->started());
2002 }
2003
2004 TEST_F(ResourceSchedulerTest, CoalescedRequestsUnthrottleCorrectlyOnTimer) {
2005 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
2006 true /* should_coalesce */);
2007 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
2008 scheduler_.OnLoadingStateChanged(
2009 kBackgroundChildId, kBackgroundRouteId, true);
2010 EXPECT_EQ(ResourceScheduler::COALESCED,
2011 scheduler_.GetClientStateForTesting(kBackgroundChildId,
2012 kBackgroundRouteId));
2013 EXPECT_TRUE(scheduler_.active_clients_loaded());
2014
2015 scoped_ptr<TestRequest> high(
2016 NewBackgroundRequest("http://host/high", net::HIGHEST));
2017 scoped_ptr<TestRequest> high2(
2018 NewBackgroundRequest("http://host/high", net::HIGHEST));
2019 scoped_ptr<TestRequest> high3(
2020 NewBackgroundRequest("http://host/high", net::HIGHEST));
2021 scoped_ptr<TestRequest> high4(
2022 NewBackgroundRequest("http://host/high", net::HIGHEST));
2023 scoped_ptr<TestRequest> low(
2024 NewBackgroundRequest("http://host/low", net::LOWEST));
2025 scoped_ptr<TestRequest> low2(
2026 NewBackgroundRequest("http://host/low", net::LOWEST));
2027 scoped_ptr<TestRequest> low3(
2028 NewBackgroundRequest("http://host/low", net::LOWEST));
2029 scoped_ptr<TestRequest> low4(
2030 NewBackgroundRequest("http://host/low", net::LOWEST));
2031
2032 http_server_properties_.SetSupportsSpdy(net::HostPortPair("spdyhost", 443),
2033 true);
2034 scoped_ptr<TestRequest> low_spdy(
2035 NewBackgroundRequest("https://spdyhost/low", net::LOW));
2036 scoped_ptr<TestRequest> sync_request(
2037 NewBackgroundSyncRequest("http://host/req", net::LOW));
2038 scoped_ptr<TestRequest> non_http_request(
2039 NewBackgroundRequest("chrome-extension://req", net::LOW));
2040
2041 // Sync requests should issue immediately.
2042 EXPECT_TRUE(sync_request->started());
2043 // Non-http(s) requests should issue immediately.
2044 EXPECT_TRUE(non_http_request->started());
2045 // Nothing else should issue without a timer fire.
2046 EXPECT_FALSE(high->started());
2047 EXPECT_FALSE(high2->started());
2048 EXPECT_FALSE(high3->started());
2049 EXPECT_FALSE(high4->started());
2050 EXPECT_FALSE(low->started());
2051 EXPECT_FALSE(low2->started());
2052 EXPECT_FALSE(low3->started());
2053 EXPECT_FALSE(low4->started());
2054 EXPECT_FALSE(low_spdy->started());
2055
2056 FireCoalescingTimer();
2057
2058 // All high priority requests should issue.
2059 EXPECT_TRUE(high->started());
2060 EXPECT_TRUE(high2->started());
2061 EXPECT_TRUE(high3->started());
2062 EXPECT_TRUE(high4->started());
2063 // There should only be one net::LOWEST priority request issued with
2064 // non-delayable requests in flight.
2065 EXPECT_TRUE(low->started());
2066 EXPECT_FALSE(low2->started());
2067 EXPECT_FALSE(low3->started());
2068 EXPECT_FALSE(low4->started());
2069 // Spdy-Enable requests should issue regardless of priority.
2070 EXPECT_TRUE(low_spdy->started());
2071 }
2072
2073 TEST_F(ResourceSchedulerTest, CoalescedRequestsWaitForNextTimer) {
2074 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
2075 true /* should_coalesce */);
2076 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
2077 scheduler_.OnLoadingStateChanged(
2078 kBackgroundChildId, kBackgroundRouteId, true);
2079
2080 EXPECT_EQ(ResourceScheduler::COALESCED,
2081 scheduler_.GetClientStateForTesting(kBackgroundChildId,
2082 kBackgroundRouteId));
2083 EXPECT_TRUE(scheduler_.active_clients_loaded());
2084
2085 scoped_ptr<TestRequest> high(
2086 NewBackgroundRequest("http://host/high", net::HIGHEST));
2087 EXPECT_FALSE(high->started());
2088
2089 FireCoalescingTimer();
2090
2091 scoped_ptr<TestRequest> high2(
2092 NewBackgroundRequest("http://host/high2", net::HIGHEST));
2093 scoped_ptr<TestRequest> low(
2094 NewBackgroundRequest("http://host/low", net::LOWEST));
2095
2096 EXPECT_TRUE(high->started());
2097 EXPECT_FALSE(high2->started());
2098 EXPECT_FALSE(low->started());
2099
2100 FireCoalescingTimer();
2101
2102 EXPECT_TRUE(high->started());
2103 EXPECT_TRUE(high2->started());
2104 EXPECT_TRUE(low->started());
2105 }
2106
1754 } // unnamed namespace 2107 } // unnamed namespace
1755 2108
1756 } // namespace content 2109 } // 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