| 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 "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  Loading... | 
| 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  Loading... | 
| 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  Loading... | 
| 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, CoalescedClientBecomesAudibleStopsTimer) { | 
|  | 1838   scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 
|  | 1839                                           true /* should_coalesce */); | 
|  | 1840   scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 
|  | 1841   EXPECT_FALSE(mock_timer_->IsRunning()); | 
|  | 1842   scheduler_.OnLoadingStateChanged( | 
|  | 1843       kBackgroundChildId, kBackgroundRouteId, true); | 
|  | 1844   EXPECT_EQ(ResourceScheduler::COALESCED, | 
|  | 1845             scheduler_.GetClientStateForTesting(kBackgroundChildId, | 
|  | 1846                                                 kBackgroundRouteId)); | 
|  | 1847   EXPECT_TRUE(mock_timer_->IsRunning()); | 
|  | 1848 | 
|  | 1849   scheduler_.OnAudibilityChanged(kBackgroundChildId, kBackgroundRouteId, true); | 
|  | 1850   EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 
|  | 1851             scheduler_.GetClientStateForTesting(kBackgroundChildId, | 
|  | 1852                                                 kBackgroundRouteId)); | 
|  | 1853   EXPECT_FALSE(mock_timer_->IsRunning()); | 
|  | 1854 } | 
|  | 1855 | 
|  | 1856 TEST_F(ResourceSchedulerTest, LastCoalescedClientDeletionStopsTimer) { | 
|  | 1857   scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 
|  | 1858                                           true /* should_coalesce */); | 
|  | 1859   scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 
|  | 1860   EXPECT_FALSE(mock_timer_->IsRunning()); | 
|  | 1861   scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 
|  | 1862   EXPECT_FALSE(mock_timer_->IsRunning()); | 
|  | 1863   scheduler_.OnLoadingStateChanged( | 
|  | 1864       kBackgroundChildId, kBackgroundRouteId, true); | 
|  | 1865   EXPECT_EQ(ResourceScheduler::COALESCED, | 
|  | 1866             scheduler_.GetClientStateForTesting(kBackgroundChildId, | 
|  | 1867                                                 kBackgroundRouteId)); | 
|  | 1868   scheduler_.OnLoadingStateChanged( | 
|  | 1869       kBackgroundChildId2, kBackgroundRouteId2, true); | 
|  | 1870   EXPECT_EQ(ResourceScheduler::COALESCED, | 
|  | 1871             scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 
|  | 1872                                                 kBackgroundRouteId2)); | 
|  | 1873   EXPECT_TRUE(mock_timer_->IsRunning()); | 
|  | 1874 | 
|  | 1875   scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId); | 
|  | 1876   EXPECT_TRUE(mock_timer_->IsRunning()); | 
|  | 1877 | 
|  | 1878   scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 
|  | 1879   EXPECT_FALSE(mock_timer_->IsRunning()); | 
|  | 1880 | 
|  | 1881   // To avoid errors on test tear down. | 
|  | 1882   scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId); | 
|  | 1883 } | 
|  | 1884 | 
|  | 1885 TEST_F(ResourceSchedulerTest, LastCoalescedClientStartsLoadingStopsTimer) { | 
|  | 1886   scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 
|  | 1887                                           true /* should_coalesce */); | 
|  | 1888   scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 
|  | 1889   EXPECT_FALSE(mock_timer_->IsRunning()); | 
|  | 1890   scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 
|  | 1891   EXPECT_FALSE(mock_timer_->IsRunning()); | 
|  | 1892   scheduler_.OnLoadingStateChanged( | 
|  | 1893       kBackgroundChildId, kBackgroundRouteId, true); | 
|  | 1894   EXPECT_EQ(ResourceScheduler::COALESCED, | 
|  | 1895             scheduler_.GetClientStateForTesting(kBackgroundChildId, | 
|  | 1896                                                 kBackgroundRouteId)); | 
|  | 1897   scheduler_.OnLoadingStateChanged( | 
|  | 1898       kBackgroundChildId2, kBackgroundRouteId2, true); | 
|  | 1899   EXPECT_EQ(ResourceScheduler::COALESCED, | 
|  | 1900             scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 
|  | 1901                                                 kBackgroundRouteId2)); | 
|  | 1902   EXPECT_TRUE(mock_timer_->IsRunning()); | 
|  | 1903 | 
|  | 1904   scheduler_.OnLoadingStateChanged( | 
|  | 1905       kBackgroundChildId, kBackgroundRouteId, false); | 
|  | 1906   EXPECT_TRUE(mock_timer_->IsRunning()); | 
|  | 1907 | 
|  | 1908   scheduler_.OnLoadingStateChanged( | 
|  | 1909       kBackgroundChildId2, kBackgroundRouteId2, false); | 
|  | 1910   EXPECT_FALSE(mock_timer_->IsRunning()); | 
|  | 1911 | 
|  | 1912   // This is needed to avoid errors on test tear down. | 
|  | 1913   scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 
|  | 1914 } | 
|  | 1915 | 
|  | 1916 TEST_F(ResourceSchedulerTest, LastCoalescedClientBecomesVisibleStopsTimer) { | 
|  | 1917   scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 
|  | 1918                                           true /* should_coalesce */); | 
|  | 1919   scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 
|  | 1920   EXPECT_FALSE(mock_timer_->IsRunning()); | 
|  | 1921   scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 
|  | 1922   EXPECT_FALSE(mock_timer_->IsRunning()); | 
|  | 1923   scheduler_.OnLoadingStateChanged( | 
|  | 1924       kBackgroundChildId, kBackgroundRouteId, true); | 
|  | 1925   EXPECT_EQ(ResourceScheduler::COALESCED, | 
|  | 1926             scheduler_.GetClientStateForTesting(kBackgroundChildId, | 
|  | 1927                                                 kBackgroundRouteId)); | 
|  | 1928   scheduler_.OnLoadingStateChanged( | 
|  | 1929       kBackgroundChildId2, kBackgroundRouteId2, true); | 
|  | 1930   EXPECT_EQ(ResourceScheduler::COALESCED, | 
|  | 1931             scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 
|  | 1932                                                 kBackgroundRouteId2)); | 
|  | 1933   EXPECT_TRUE(mock_timer_->IsRunning()); | 
|  | 1934 | 
|  | 1935   scheduler_.OnVisibilityChanged(kBackgroundChildId, kBackgroundRouteId, true); | 
|  | 1936   EXPECT_TRUE(mock_timer_->IsRunning()); | 
|  | 1937 | 
|  | 1938   scheduler_.OnVisibilityChanged( | 
|  | 1939       kBackgroundChildId2, kBackgroundRouteId2, true); | 
|  | 1940   EXPECT_FALSE(mock_timer_->IsRunning()); | 
|  | 1941 | 
|  | 1942   // To avoid errors on test tear down. | 
|  | 1943   scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 
|  | 1944 } | 
|  | 1945 | 
|  | 1946 TEST_F(ResourceSchedulerTest, | 
|  | 1947        CoalescedClientBecomesLoadingAndVisibleStopsTimer) { | 
|  | 1948   scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 
|  | 1949                                           true /* should_coalesce */); | 
|  | 1950   scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 
|  | 1951   EXPECT_FALSE(mock_timer_->IsRunning()); | 
|  | 1952   scheduler_.OnLoadingStateChanged( | 
|  | 1953       kBackgroundChildId, kBackgroundRouteId, true); | 
|  | 1954   EXPECT_EQ(ResourceScheduler::COALESCED, | 
|  | 1955             scheduler_.GetClientStateForTesting(kBackgroundChildId, | 
|  | 1956                                                 kBackgroundRouteId)); | 
|  | 1957   EXPECT_TRUE(mock_timer_->IsRunning()); | 
|  | 1958 | 
|  | 1959   scheduler_.OnLoadingStateChanged( | 
|  | 1960       kBackgroundChildId, kBackgroundRouteId, false); | 
|  | 1961   EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 
|  | 1962             scheduler_.GetClientStateForTesting(kBackgroundChildId, | 
|  | 1963                                                 kBackgroundRouteId)); | 
|  | 1964   EXPECT_FALSE(mock_timer_->IsRunning()); | 
|  | 1965 | 
|  | 1966   scheduler_.OnVisibilityChanged(kBackgroundChildId, kBackgroundRouteId, true); | 
|  | 1967   EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 
|  | 1968             scheduler_.GetClientStateForTesting(kBackgroundChildId, | 
|  | 1969                                                 kBackgroundRouteId)); | 
|  | 1970   EXPECT_FALSE(mock_timer_->IsRunning()); | 
|  | 1971 } | 
|  | 1972 | 
|  | 1973 TEST_F(ResourceSchedulerTest, CoalescedRequestsIssueOnTimer) { | 
|  | 1974   scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 
|  | 1975                                           true /* should_coalesce */); | 
|  | 1976   scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 
|  | 1977   scheduler_.OnLoadingStateChanged( | 
|  | 1978       kBackgroundChildId, kBackgroundRouteId, true); | 
|  | 1979   EXPECT_EQ(ResourceScheduler::COALESCED, | 
|  | 1980             scheduler_.GetClientStateForTesting(kBackgroundChildId, | 
|  | 1981                                                 kBackgroundRouteId)); | 
|  | 1982   EXPECT_TRUE(scheduler_.active_clients_loaded()); | 
|  | 1983 | 
|  | 1984   scoped_ptr<TestRequest> high( | 
|  | 1985       NewBackgroundRequest("http://host/high", net::HIGHEST)); | 
|  | 1986   scoped_ptr<TestRequest> low( | 
|  | 1987       NewBackgroundRequest("http://host/low", net::LOWEST)); | 
|  | 1988   EXPECT_FALSE(high->started()); | 
|  | 1989   EXPECT_FALSE(low->started()); | 
|  | 1990 | 
|  | 1991   FireCoalescingTimer(); | 
|  | 1992 | 
|  | 1993   EXPECT_TRUE(high->started()); | 
|  | 1994   EXPECT_TRUE(low->started()); | 
|  | 1995 } | 
|  | 1996 | 
|  | 1997 TEST_F(ResourceSchedulerTest, CoalescedRequestsUnthrottleCorrectlyOnTimer) { | 
|  | 1998   scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 
|  | 1999                                           true /* should_coalesce */); | 
|  | 2000   scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 
|  | 2001   scheduler_.OnLoadingStateChanged( | 
|  | 2002       kBackgroundChildId, kBackgroundRouteId, true); | 
|  | 2003   EXPECT_EQ(ResourceScheduler::COALESCED, | 
|  | 2004             scheduler_.GetClientStateForTesting(kBackgroundChildId, | 
|  | 2005                                                 kBackgroundRouteId)); | 
|  | 2006   EXPECT_TRUE(scheduler_.active_clients_loaded()); | 
|  | 2007 | 
|  | 2008   scoped_ptr<TestRequest> high( | 
|  | 2009       NewBackgroundRequest("http://host/high", net::HIGHEST)); | 
|  | 2010   scoped_ptr<TestRequest> high2( | 
|  | 2011       NewBackgroundRequest("http://host/high", net::HIGHEST)); | 
|  | 2012   scoped_ptr<TestRequest> high3( | 
|  | 2013       NewBackgroundRequest("http://host/high", net::HIGHEST)); | 
|  | 2014   scoped_ptr<TestRequest> high4( | 
|  | 2015       NewBackgroundRequest("http://host/high", net::HIGHEST)); | 
|  | 2016   scoped_ptr<TestRequest> low( | 
|  | 2017       NewBackgroundRequest("http://host/low", net::LOWEST)); | 
|  | 2018   scoped_ptr<TestRequest> low2( | 
|  | 2019       NewBackgroundRequest("http://host/low", net::LOWEST)); | 
|  | 2020   scoped_ptr<TestRequest> low3( | 
|  | 2021       NewBackgroundRequest("http://host/low", net::LOWEST)); | 
|  | 2022   scoped_ptr<TestRequest> low4( | 
|  | 2023       NewBackgroundRequest("http://host/low", net::LOWEST)); | 
|  | 2024 | 
|  | 2025   http_server_properties_.SetSupportsSpdy(net::HostPortPair("spdyhost", 443), | 
|  | 2026                                           true); | 
|  | 2027   scoped_ptr<TestRequest> low_spdy( | 
|  | 2028       NewBackgroundRequest("https://spdyhost/low", net::LOW)); | 
|  | 2029   scoped_ptr<TestRequest> sync_request( | 
|  | 2030       NewBackgroundSyncRequest("http://host/req", net::LOW)); | 
|  | 2031   scoped_ptr<TestRequest> non_http_request( | 
|  | 2032       NewBackgroundRequest("chrome-extension://req", net::LOW)); | 
|  | 2033 | 
|  | 2034   // Sync requests should issue immediately. | 
|  | 2035   EXPECT_TRUE(sync_request->started()); | 
|  | 2036   // Non-http(s) requests should issue immediately. | 
|  | 2037   EXPECT_TRUE(non_http_request->started()); | 
|  | 2038   // Nothing else should issue without a timer fire. | 
|  | 2039   EXPECT_FALSE(high->started()); | 
|  | 2040   EXPECT_FALSE(high2->started()); | 
|  | 2041   EXPECT_FALSE(high3->started()); | 
|  | 2042   EXPECT_FALSE(high4->started()); | 
|  | 2043   EXPECT_FALSE(low->started()); | 
|  | 2044   EXPECT_FALSE(low2->started()); | 
|  | 2045   EXPECT_FALSE(low3->started()); | 
|  | 2046   EXPECT_FALSE(low4->started()); | 
|  | 2047   EXPECT_FALSE(low_spdy->started()); | 
|  | 2048 | 
|  | 2049   FireCoalescingTimer(); | 
|  | 2050 | 
|  | 2051   // All high priority requests should issue. | 
|  | 2052   EXPECT_TRUE(high->started()); | 
|  | 2053   EXPECT_TRUE(high2->started()); | 
|  | 2054   EXPECT_TRUE(high3->started()); | 
|  | 2055   EXPECT_TRUE(high4->started()); | 
|  | 2056   // There should only be one net::LOWEST priority request issued with | 
|  | 2057   // non-delayable requests in flight. | 
|  | 2058   EXPECT_TRUE(low->started()); | 
|  | 2059   EXPECT_FALSE(low2->started()); | 
|  | 2060   EXPECT_FALSE(low3->started()); | 
|  | 2061   EXPECT_FALSE(low4->started()); | 
|  | 2062   // Spdy-Enable requests should issue regardless of priority. | 
|  | 2063   EXPECT_TRUE(low_spdy->started()); | 
|  | 2064 } | 
|  | 2065 | 
|  | 2066 TEST_F(ResourceSchedulerTest, CoalescedRequestsWaitForNextTimer) { | 
|  | 2067   scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 
|  | 2068                                           true /* should_coalesce */); | 
|  | 2069   scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 
|  | 2070   scheduler_.OnLoadingStateChanged( | 
|  | 2071       kBackgroundChildId, kBackgroundRouteId, true); | 
|  | 2072 | 
|  | 2073   EXPECT_EQ(ResourceScheduler::COALESCED, | 
|  | 2074             scheduler_.GetClientStateForTesting(kBackgroundChildId, | 
|  | 2075                                                 kBackgroundRouteId)); | 
|  | 2076   EXPECT_TRUE(scheduler_.active_clients_loaded()); | 
|  | 2077 | 
|  | 2078   scoped_ptr<TestRequest> high( | 
|  | 2079       NewBackgroundRequest("http://host/high", net::HIGHEST)); | 
|  | 2080   EXPECT_FALSE(high->started()); | 
|  | 2081 | 
|  | 2082   FireCoalescingTimer(); | 
|  | 2083 | 
|  | 2084   scoped_ptr<TestRequest> high2( | 
|  | 2085       NewBackgroundRequest("http://host/high2", net::HIGHEST)); | 
|  | 2086   scoped_ptr<TestRequest> low( | 
|  | 2087       NewBackgroundRequest("http://host/low", net::LOWEST)); | 
|  | 2088 | 
|  | 2089   EXPECT_TRUE(high->started()); | 
|  | 2090   EXPECT_FALSE(high2->started()); | 
|  | 2091   EXPECT_FALSE(low->started()); | 
|  | 2092 | 
|  | 2093   FireCoalescingTimer(); | 
|  | 2094 | 
|  | 2095   EXPECT_TRUE(high->started()); | 
|  | 2096   EXPECT_TRUE(high2->started()); | 
|  | 2097   EXPECT_TRUE(low->started()); | 
|  | 2098 } | 
|  | 2099 | 
| 1754 }  // unnamed namespace | 2100 }  // unnamed namespace | 
| 1755 | 2101 | 
| 1756 }  // namespace content | 2102 }  // namespace content | 
| OLD | NEW | 
|---|