Index: content/browser/loader/resource_scheduler_unittest.cc |
diff --git a/content/browser/loader/resource_scheduler_unittest.cc b/content/browser/loader/resource_scheduler_unittest.cc |
index 3ac956667bfdafb138962616a723766662ad8c10..38af6b86d8579aa6dba3ae3c2757c7693383ef0d 100644 |
--- a/content/browser/loader/resource_scheduler_unittest.cc |
+++ b/content/browser/loader/resource_scheduler_unittest.cc |
@@ -384,10 +384,10 @@ TEST_F(ResourceSchedulerTest, OneLowLoadsUntilBodyInsertedExceptSpdy) { |
http_server_properties_.SetSupportsSpdy( |
net::HostPortPair("spdyhost", 443), true); |
scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); |
- scoped_ptr<TestRequest> low_spdy( |
- NewRequest("https://spdyhost/low", net::LOWEST)); |
scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); |
scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); |
+ scoped_ptr<TestRequest> low_spdy( |
+ NewRequest("https://spdyhost/low", net::LOWEST)); |
EXPECT_TRUE(high->started()); |
EXPECT_TRUE(low_spdy->started()); |
EXPECT_TRUE(low->started()); |
@@ -707,8 +707,11 @@ TEST_F(ResourceSchedulerTest, NewSpdyHostInDelayableRequests) { |
http_server_properties_.SetSupportsSpdy( |
net::HostPortPair("spdyhost2", 8080), true); |
ChangeRequestPriority(low2_spdy.get(), net::LOWEST); |
+ // Low priority in-flight requests on the SPDY connection are still considered |
+ // delayable as far as the accounting goes and should still hold back the |
+ // request on the non-spdy host. |
scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); |
- EXPECT_TRUE(low2->started()); |
+ EXPECT_FALSE(low2->started()); |
} |
TEST_F(ResourceSchedulerTest, ThrottledClientCreation) { |
@@ -2360,6 +2363,197 @@ TEST_F(ResourceSchedulerTest, RequestStartedAfterClientDeletedManyDelayable) { |
EXPECT_TRUE(lowest->started()); |
} |
+TEST_F(ResourceSchedulerTest, DefaultLayoutBlockingPriority) { |
+ const int kEnablePriorityIncrease = 0; |
+ ASSERT_TRUE(InitializeFieldTrials( |
+ base::StringPrintf("ResourcePriorities/LayoutBlocking_000%d0_0_1_10/", |
+ kEnablePriorityIncrease))); |
+ InitializeScheduler(); |
+ scoped_ptr<TestRequest> high( |
+ NewRequest("http://hosthigh/high", net::HIGHEST)); |
+ scoped_ptr<TestRequest> high2( |
+ NewRequest("http://hosthigh/high", net::HIGHEST)); |
+ scoped_ptr<TestRequest> medium( |
+ NewRequest("http://hostmedium/medium", net::MEDIUM)); |
+ scoped_ptr<TestRequest> medium2( |
+ NewRequest("http://hostmedium/medium", net::MEDIUM)); |
+ scoped_ptr<TestRequest> low(NewRequest("http://hostlow/low", net::LOW)); |
+ scoped_ptr<TestRequest> low2(NewRequest("http://hostlow/low", net::LOW)); |
+ scoped_ptr<TestRequest> lowest(NewRequest("http://hostlowest/lowest", net::LOWEST)); |
+ scoped_ptr<TestRequest> lowest2( |
+ NewRequest("http://hostlowest/lowest", net::LOWEST)); |
+ EXPECT_TRUE(high->started()); |
+ EXPECT_TRUE(high2->started()); |
+ EXPECT_TRUE(medium->started()); |
+ EXPECT_TRUE(medium2->started()); |
+ EXPECT_TRUE(low->started()); |
+ EXPECT_TRUE(low2->started()); |
+ EXPECT_TRUE(lowest->started()); |
+ EXPECT_FALSE(lowest2->started()); |
+ lowest.reset(); |
+ EXPECT_TRUE(lowest2->started()); |
+} |
+ |
+TEST_F(ResourceSchedulerTest, IncreaseLayoutBlockingPriority) { |
+ // Changes the level of priorities that are allowed during layout-blocking |
+ // from net::LOWEST to net::LOW. |
+ const int kEnablePriorityIncrease = 1; |
+ ASSERT_TRUE(InitializeFieldTrials( |
+ base::StringPrintf("ResourcePriorities/LayoutBlocking_000%d0_0_1_10/", |
+ kEnablePriorityIncrease))); |
+ InitializeScheduler(); |
+ scoped_ptr<TestRequest> high( |
+ NewRequest("http://hosthigh/high", net::HIGHEST)); |
+ scoped_ptr<TestRequest> high2( |
+ NewRequest("http://hosthigh/high", net::HIGHEST)); |
+ scoped_ptr<TestRequest> medium( |
+ NewRequest("http://hostmedium/medium", net::MEDIUM)); |
+ scoped_ptr<TestRequest> medium2( |
+ NewRequest("http://hostmedium/medium", net::MEDIUM)); |
+ scoped_ptr<TestRequest> low(NewRequest("http://hostlow/low", net::LOW)); |
+ scoped_ptr<TestRequest> low2(NewRequest("http://hostlow/low", net::LOW)); |
+ scoped_ptr<TestRequest> lowest(NewRequest("http://hostlowest/lowest", net::LOWEST)); |
+ scoped_ptr<TestRequest> lowest2( |
+ NewRequest("http://hostlowest/lowest", net::LOWEST)); |
+ EXPECT_TRUE(high->started()); |
+ EXPECT_TRUE(high2->started()); |
+ EXPECT_TRUE(medium->started()); |
+ EXPECT_TRUE(medium2->started()); |
+ EXPECT_TRUE(low->started()); |
+ EXPECT_FALSE(low2->started()); |
+ EXPECT_FALSE(lowest->started()); |
+ EXPECT_FALSE(lowest2->started()); |
+ low.reset(); |
+ EXPECT_TRUE(low2->started()); |
+ EXPECT_FALSE(lowest->started()); |
+ EXPECT_FALSE(lowest2->started()); |
+ low2.reset(); |
+ EXPECT_TRUE(lowest->started()); |
+ EXPECT_FALSE(lowest2->started()); |
+ lowest.reset(); |
+ EXPECT_TRUE(lowest2->started()); |
+} |
+ |
+TEST_F(ResourceSchedulerTest, UseLayoutBlockingThresholdOne) { |
+ // Prevents anly low priority requests from starting while more than |
+ // N high priority requests are pending (before body). |
+ const int kLayoutBlockingThreshold = 1; |
+ ASSERT_TRUE(InitializeFieldTrials( |
+ base::StringPrintf("ResourcePriorities/LayoutBlocking_00001_%d_1_10/", |
+ kLayoutBlockingThreshold))); |
+ InitializeScheduler(); |
+ scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); |
+ scoped_ptr<TestRequest> high2(NewRequest("http://host/high", net::HIGHEST)); |
+ scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); |
+ scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); |
+ EXPECT_TRUE(high->started()); |
+ EXPECT_TRUE(high2->started()); |
+ EXPECT_FALSE(low->started()); |
+ EXPECT_FALSE(low2->started()); |
+ high.reset(); |
+ EXPECT_TRUE(low->started()); |
+ EXPECT_FALSE(low2->started()); |
+ high2.reset(); |
+ scheduler()->OnWillInsertBody(kChildId, kRouteId); |
+ EXPECT_TRUE(low2->started()); |
+} |
+ |
+TEST_F(ResourceSchedulerTest, UseLayoutBlockingThresholdTwo) { |
+ // Prevents anly low priority requests from starting while more than |
+ // N high priority requests are pending (before body). |
+ const int kLayoutBlockingThreshold = 2; |
+ ASSERT_TRUE(InitializeFieldTrials( |
+ base::StringPrintf("ResourcePriorities/LayoutBlockingTwo_00001_%d_1_10/", |
+ kLayoutBlockingThreshold))); |
+ InitializeScheduler(); |
+ scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); |
+ scoped_ptr<TestRequest> high2(NewRequest("http://host/high", net::HIGHEST)); |
+ scoped_ptr<TestRequest> high3(NewRequest("http://host/high", net::HIGHEST)); |
+ scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); |
+ scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); |
+ EXPECT_TRUE(high->started()); |
+ EXPECT_TRUE(high2->started()); |
+ EXPECT_TRUE(high3->started()); |
+ EXPECT_FALSE(low->started()); |
+ EXPECT_FALSE(low2->started()); |
+ high.reset(); |
+ EXPECT_TRUE(low->started()); |
+ EXPECT_FALSE(low2->started()); |
+ high2.reset(); |
+ high3.reset(); |
+ scheduler()->OnWillInsertBody(kChildId, kRouteId); |
+ EXPECT_TRUE(low2->started()); |
+} |
+ |
+TEST_F(ResourceSchedulerTest, IncreaseLowLoadsUntilBodyInserted) { |
+ const int kMaxNumDelayableWhileLayoutBlocking = 2; |
+ ASSERT_TRUE(InitializeFieldTrials( |
+ base::StringPrintf("ResourcePriorities/IncreaseLow_00000_0_%d_10/", |
+ kMaxNumDelayableWhileLayoutBlocking))); |
+ InitializeScheduler(); |
+ scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); |
+ scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); |
+ scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); |
+ scoped_ptr<TestRequest> low3(NewRequest("http://host/low", net::LOWEST)); |
+ EXPECT_TRUE(high->started()); |
+ EXPECT_TRUE(low->started()); |
+ EXPECT_TRUE(low2->started()); |
+ EXPECT_FALSE(low3->started()); |
+ high.reset(); |
+ scheduler()->OnWillInsertBody(kChildId, kRouteId); |
+ EXPECT_TRUE(low3->started()); |
+} |
+ |
+TEST_F(ResourceSchedulerTest, IncreaseLowLoadsUntilBodyInsertedLayoutBlocking) { |
+ const int kLayoutBlockingThreshold = 1; |
+ const int kMaxNumDelayableWhileLayoutBlocking = 2; |
+ ASSERT_TRUE(InitializeFieldTrials( |
+ base::StringPrintf("ResourcePriorities/IncreaseLow_00001_%d_%d_10/", |
+ kLayoutBlockingThreshold, |
+ kMaxNumDelayableWhileLayoutBlocking))); |
+ InitializeScheduler(); |
+ scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); |
+ scoped_ptr<TestRequest> high2(NewRequest("http://host/high", net::HIGHEST)); |
+ scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); |
+ scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); |
+ scoped_ptr<TestRequest> low3(NewRequest("http://host/low", net::LOWEST)); |
+ EXPECT_TRUE(high->started()); |
+ EXPECT_TRUE(high2->started()); |
+ EXPECT_FALSE(low->started()); |
+ EXPECT_FALSE(low2->started()); |
+ EXPECT_FALSE(low3->started()); |
+ high.reset(); |
+ EXPECT_TRUE(low->started()); |
+ EXPECT_TRUE(low2->started()); |
+ EXPECT_FALSE(low3->started()); |
+ high2.reset(); |
+ scheduler()->OnWillInsertBody(kChildId, kRouteId); |
+ EXPECT_TRUE(low3->started()); |
+} |
+ |
+TEST_F(ResourceSchedulerTest, IncreaseMaxNumDelayableRequestsPerClient) { |
+ const int kMaxNumDelayableRequestsPerClient = 25; |
+ ASSERT_TRUE(InitializeFieldTrials( |
+ base::StringPrintf("ResourcePriorities/IncreaseDelayable_00000_0_1_%d/", |
+ kMaxNumDelayableRequestsPerClient))); |
+ InitializeScheduler(); |
+ |
+ // We only load low priority resources if there's a body. |
+ scheduler()->OnWillInsertBody(kChildId, kRouteId); |
+ |
+ // Queue requests from different hosts until we reach the total limit. |
+ ScopedVector<TestRequest> lows_differenthosts; |
+ for (int i = 0; i < kMaxNumDelayableRequestsPerClient; ++i) { |
+ string url = "http://host" + base::IntToString(i) + "/low"; |
+ lows_differenthosts.push_back(NewRequest(url.c_str(), net::LOWEST)); |
+ EXPECT_TRUE(lows_differenthosts[i]->started()); |
+ } |
+ |
+ scoped_ptr<TestRequest> last_differenthost(NewRequest("http://host_new/last", |
+ net::LOWEST)); |
+ EXPECT_FALSE(last_differenthost->started()); |
+} |
+ |
} // unnamed namespace |
} // namespace content |