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

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

Issue 1706903003: Delay resource scheduling decisions until network access. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed unit tests Created 4 years, 10 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 <utility> 7 #include <utility>
8 8
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 const int kChildId2 = 43; 45 const int kChildId2 = 43;
46 const int kRouteId2 = 67; 46 const int kRouteId2 = 67;
47 const int kBackgroundChildId = 35; 47 const int kBackgroundChildId = 35;
48 const int kBackgroundRouteId = 43; 48 const int kBackgroundRouteId = 43;
49 49
50 class TestRequest : public ResourceController { 50 class TestRequest : public ResourceController {
51 public: 51 public:
52 TestRequest(scoped_ptr<net::URLRequest> url_request, 52 TestRequest(scoped_ptr<net::URLRequest> url_request,
53 scoped_ptr<ResourceThrottle> throttle, 53 scoped_ptr<ResourceThrottle> throttle,
54 ResourceScheduler* scheduler) 54 ResourceScheduler* scheduler)
55 : started_(false), 55 : starting_(false),
56 started_(false),
57 sending_(false),
58 sent_(false),
56 url_request_(std::move(url_request)), 59 url_request_(std::move(url_request)),
57 throttle_(std::move(throttle)), 60 throttle_(std::move(throttle)),
58 scheduler_(scheduler) { 61 scheduler_(scheduler) {
59 throttle_->set_controller_for_testing(this); 62 throttle_->set_controller_for_testing(this);
60 } 63 }
61 ~TestRequest() override { 64 ~TestRequest() override {
62 // The URLRequest must still be valid when the ScheduledResourceRequest is 65 // The URLRequest must still be valid when the ScheduledResourceRequest is
63 // destroyed, so that it can unregister itself. 66 // destroyed, so that it can unregister itself.
64 throttle_.reset(); 67 throttle_.reset();
65 } 68 }
66 69
67 bool started() const { return started_; } 70 bool started() const { return started_; }
71 bool sent() const { return sent_; }
68 72
69 void Start() { 73 void Start() {
70 bool deferred = false; 74 bool deferred = false;
71 throttle_->WillStartRequest(&deferred); 75 throttle_->WillStartRequest(&deferred);
72 started_ = !deferred; 76 started_ = !deferred;
77 starting_ = !started_;
78 }
79
80 void Send() {
mmenke 2016/02/25 18:09:51 I want to spend some time mulling over this change
81 bool deferred = false;
82 throttle_->WillStartUsingNetwork(&deferred);
83 sent_ = !deferred;
84 sending_ = !sent_;
73 } 85 }
74 86
75 void ChangePriority(net::RequestPriority new_priority, int intra_priority) { 87 void ChangePriority(net::RequestPriority new_priority, int intra_priority) {
76 scheduler_->ReprioritizeRequest(url_request_.get(), new_priority, 88 scheduler_->ReprioritizeRequest(url_request_.get(), new_priority,
77 intra_priority); 89 intra_priority);
78 } 90 }
79 91
80 void Cancel() override { 92 void Cancel() override {
81 // Alert the scheduler that the request can be deleted. 93 // Alert the scheduler that the request can be deleted.
82 throttle_.reset(); 94 throttle_.reset();
83 } 95 }
84 96
85 const net::URLRequest* url_request() const { return url_request_.get(); } 97 const net::URLRequest* url_request() const { return url_request_.get(); }
86 98
87 protected: 99 protected:
88 // ResourceController interface: 100 // ResourceController interface:
89 void CancelAndIgnore() override {} 101 void CancelAndIgnore() override {}
90 void CancelWithError(int error_code) override {} 102 void CancelWithError(int error_code) override {}
91 void Resume() override { started_ = true; } 103 void Resume() override {
104 if (starting_) {
105 started_ = true;
106 } else if (sending_) {
107 sent_ = true;
108 }
109 }
92 110
93 private: 111 private:
112 bool starting_;
94 bool started_; 113 bool started_;
114 bool sending_;
115 bool sent_;
95 scoped_ptr<net::URLRequest> url_request_; 116 scoped_ptr<net::URLRequest> url_request_;
96 scoped_ptr<ResourceThrottle> throttle_; 117 scoped_ptr<ResourceThrottle> throttle_;
97 ResourceScheduler* scheduler_; 118 ResourceScheduler* scheduler_;
98 }; 119 };
99 120
100 class CancelingTestRequest : public TestRequest { 121 class CancelingTestRequest : public TestRequest {
101 public: 122 public:
102 CancelingTestRequest(scoped_ptr<net::URLRequest> url_request, 123 CancelingTestRequest(scoped_ptr<net::URLRequest> url_request,
103 scoped_ptr<ResourceThrottle> throttle, 124 scoped_ptr<ResourceThrottle> throttle,
104 ResourceScheduler* scheduler) 125 ResourceScheduler* scheduler)
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 int child_id, 248 int child_id,
228 int route_id, 249 int route_id,
229 bool is_async) { 250 bool is_async) {
230 scoped_ptr<net::URLRequest> url_request( 251 scoped_ptr<net::URLRequest> url_request(
231 NewURLRequestWithChildAndRoute(url, priority, child_id, route_id)); 252 NewURLRequestWithChildAndRoute(url, priority, child_id, route_id));
232 scoped_ptr<ResourceThrottle> throttle(scheduler_->ScheduleRequest( 253 scoped_ptr<ResourceThrottle> throttle(scheduler_->ScheduleRequest(
233 child_id, route_id, is_async, url_request.get())); 254 child_id, route_id, is_async, url_request.get()));
234 TestRequest* request = new TestRequest(std::move(url_request), 255 TestRequest* request = new TestRequest(std::move(url_request),
235 std::move(throttle), scheduler()); 256 std::move(throttle), scheduler());
236 request->Start(); 257 request->Start();
258 EXPECT_TRUE(request->started());
259 request->Send();
mmenke 2016/02/25 18:09:51 We have four types of requests now: 1) Those that
237 return request; 260 return request;
238 } 261 }
239 262
240 void ChangeRequestPriority(TestRequest* request, 263 void ChangeRequestPriority(TestRequest* request,
241 net::RequestPriority new_priority, 264 net::RequestPriority new_priority,
242 int intra_priority = 0) { 265 int intra_priority = 0) {
243 request->ChangePriority(new_priority, intra_priority); 266 request->ChangePriority(new_priority, intra_priority);
244 } 267 }
245 268
246 void FireCoalescingTimer() { 269 void FireCoalescingTimer() {
(...skipping 11 matching lines...) Expand all
258 ResourceDispatcherHostImpl rdh_; 281 ResourceDispatcherHostImpl rdh_;
259 scoped_ptr<ResourceScheduler> scheduler_; 282 scoped_ptr<ResourceScheduler> scheduler_;
260 base::FieldTrialList field_trial_list_; 283 base::FieldTrialList field_trial_list_;
261 base::MockTimer* mock_timer_; 284 base::MockTimer* mock_timer_;
262 net::HttpServerPropertiesImpl http_server_properties_; 285 net::HttpServerPropertiesImpl http_server_properties_;
263 net::TestURLRequestContext context_; 286 net::TestURLRequestContext context_;
264 }; 287 };
265 288
266 TEST_F(ResourceSchedulerTest, OneIsolatedLowRequest) { 289 TEST_F(ResourceSchedulerTest, OneIsolatedLowRequest) {
267 scoped_ptr<TestRequest> request(NewRequest("http://host/1", net::LOWEST)); 290 scoped_ptr<TestRequest> request(NewRequest("http://host/1", net::LOWEST));
268 EXPECT_TRUE(request->started()); 291 EXPECT_TRUE(request->sent());
269 } 292 }
270 293
271 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilIdle) { 294 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilIdle) {
272 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 295 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
273 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 296 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
274 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); 297 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
275 EXPECT_TRUE(high->started()); 298 EXPECT_TRUE(high->sent());
276 EXPECT_TRUE(low->started()); 299 EXPECT_TRUE(low->sent());
277 EXPECT_FALSE(low2->started()); 300 EXPECT_FALSE(low2->sent());
278 301
279 high.reset(); 302 high.reset();
280 base::RunLoop().RunUntilIdle(); 303 base::RunLoop().RunUntilIdle();
281 EXPECT_TRUE(low2->started()); 304 EXPECT_TRUE(low2->sent());
282 } 305 }
283 306
284 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilBodyInserted) { 307 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilBodyInserted) {
285 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 308 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
286 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 309 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
287 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); 310 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
288 EXPECT_TRUE(high->started()); 311 EXPECT_TRUE(high->sent());
289 EXPECT_TRUE(low->started()); 312 EXPECT_TRUE(low->sent());
290 EXPECT_FALSE(low2->started()); 313 EXPECT_FALSE(low2->sent());
291 314
292 high.reset(); 315 high.reset();
293 base::RunLoop().RunUntilIdle(); 316 base::RunLoop().RunUntilIdle();
294 // TODO(mmenke): The name of this test implies this should be false. 317 // TODO(mmenke): The name of this test implies this should be false.
295 // Investigate if this is now expected, remove or update this test if it is. 318 // Investigate if this is now expected, remove or update this test if it is.
296 EXPECT_TRUE(low2->started()); 319 EXPECT_TRUE(low2->sent());
297 320
298 scheduler()->OnWillInsertBody(kChildId, kRouteId); 321 scheduler()->OnWillInsertBody(kChildId, kRouteId);
299 base::RunLoop().RunUntilIdle(); 322 base::RunLoop().RunUntilIdle();
300 EXPECT_TRUE(low2->started()); 323 EXPECT_TRUE(low2->sent());
301 } 324 }
302 325
303 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilCriticalComplete) { 326 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilCriticalComplete) {
304 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 327 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
305 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 328 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
306 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); 329 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
307 EXPECT_TRUE(high->started()); 330 EXPECT_TRUE(high->sent());
308 EXPECT_TRUE(low->started()); 331 EXPECT_TRUE(low->sent());
309 EXPECT_FALSE(low2->started()); 332 EXPECT_FALSE(low2->sent());
310 333
311 scheduler()->OnWillInsertBody(kChildId, kRouteId); 334 scheduler()->OnWillInsertBody(kChildId, kRouteId);
312 base::RunLoop().RunUntilIdle(); 335 base::RunLoop().RunUntilIdle();
313 EXPECT_FALSE(low2->started()); 336 EXPECT_FALSE(low2->sent());
314 337
315 high.reset(); 338 high.reset();
316 base::RunLoop().RunUntilIdle(); 339 base::RunLoop().RunUntilIdle();
317 EXPECT_TRUE(low2->started()); 340 EXPECT_TRUE(low2->sent());
318 } 341 }
319 342
320 TEST_F(ResourceSchedulerTest, LowDoesNotBlockCriticalComplete) { 343 TEST_F(ResourceSchedulerTest, LowDoesNotBlockCriticalComplete) {
321 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOW)); 344 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOW));
322 scoped_ptr<TestRequest> lowest(NewRequest("http://host/lowest", net::LOWEST)); 345 scoped_ptr<TestRequest> lowest(NewRequest("http://host/lowest", net::LOWEST));
323 scoped_ptr<TestRequest> lowest2( 346 scoped_ptr<TestRequest> lowest2(
324 NewRequest("http://host/lowest", net::LOWEST)); 347 NewRequest("http://host/lowest", net::LOWEST));
325 EXPECT_TRUE(low->started()); 348 EXPECT_TRUE(low->sent());
326 EXPECT_TRUE(lowest->started()); 349 EXPECT_TRUE(lowest->sent());
327 EXPECT_FALSE(lowest2->started()); 350 EXPECT_FALSE(lowest2->sent());
328 351
329 scheduler()->OnWillInsertBody(kChildId, kRouteId); 352 scheduler()->OnWillInsertBody(kChildId, kRouteId);
330 base::RunLoop().RunUntilIdle(); 353 base::RunLoop().RunUntilIdle();
331 EXPECT_TRUE(lowest2->started()); 354 EXPECT_TRUE(lowest2->sent());
332 } 355 }
333 356
334 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilBodyInsertedExceptSpdy) { 357 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilBodyInsertedExceptSpdy) {
335 http_server_properties_.SetSupportsSpdy( 358 http_server_properties_.SetSupportsSpdy(
336 net::HostPortPair("spdyhost", 443), true); 359 net::HostPortPair("spdyhost", 443), true);
337 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 360 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
338 scoped_ptr<TestRequest> low_spdy( 361 scoped_ptr<TestRequest> low_spdy(
339 NewRequest("https://spdyhost/low", net::LOWEST)); 362 NewRequest("https://spdyhost/low", net::LOWEST));
340 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 363 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
341 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); 364 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
342 EXPECT_TRUE(high->started()); 365 EXPECT_TRUE(high->sent());
343 EXPECT_TRUE(low_spdy->started()); 366 EXPECT_TRUE(low_spdy->sent());
344 EXPECT_TRUE(low->started()); 367 EXPECT_TRUE(low->sent());
345 EXPECT_FALSE(low2->started()); 368 EXPECT_FALSE(low2->sent());
346 369
347 scheduler()->OnWillInsertBody(kChildId, kRouteId); 370 scheduler()->OnWillInsertBody(kChildId, kRouteId);
348 high.reset(); 371 high.reset();
349 base::RunLoop().RunUntilIdle(); 372 base::RunLoop().RunUntilIdle();
350 EXPECT_TRUE(low2->started()); 373 EXPECT_TRUE(low2->sent());
351 } 374 }
352 375
353 TEST_F(ResourceSchedulerTest, NavigationResetsState) { 376 TEST_F(ResourceSchedulerTest, NavigationResetsState) {
354 scheduler()->OnWillInsertBody(kChildId, kRouteId); 377 scheduler()->OnWillInsertBody(kChildId, kRouteId);
355 scheduler()->OnNavigate(kChildId, kRouteId); 378 scheduler()->OnNavigate(kChildId, kRouteId);
356 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 379 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
357 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 380 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
358 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); 381 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
359 EXPECT_TRUE(high->started()); 382 EXPECT_TRUE(high->sent());
360 EXPECT_TRUE(low->started()); 383 EXPECT_TRUE(low->sent());
361 EXPECT_FALSE(low2->started()); 384 EXPECT_FALSE(low2->sent());
362 } 385 }
363 386
364 TEST_F(ResourceSchedulerTest, BackgroundRequestStartsImmediately) { 387 TEST_F(ResourceSchedulerTest, BackgroundRequestStartsImmediately) {
365 const int route_id = 0; // Indicates a background request. 388 const int route_id = 0; // Indicates a background request.
366 scoped_ptr<TestRequest> request(NewRequestWithRoute("http://host/1", 389 scoped_ptr<TestRequest> request(NewRequestWithRoute("http://host/1",
367 net::LOWEST, route_id)); 390 net::LOWEST, route_id));
368 EXPECT_TRUE(request->started()); 391 EXPECT_TRUE(request->sent());
369 } 392 }
370 393
371 TEST_F(ResourceSchedulerTest, StartMultipleLowRequestsWhenIdle) { 394 TEST_F(ResourceSchedulerTest, StartMultipleLowRequestsWhenIdle) {
372 scoped_ptr<TestRequest> high1(NewRequest("http://host/high1", net::HIGHEST)); 395 scoped_ptr<TestRequest> high1(NewRequest("http://host/high1", net::HIGHEST));
373 scoped_ptr<TestRequest> high2(NewRequest("http://host/high2", net::HIGHEST)); 396 scoped_ptr<TestRequest> high2(NewRequest("http://host/high2", net::HIGHEST));
374 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 397 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
375 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); 398 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
376 EXPECT_TRUE(high1->started()); 399 EXPECT_TRUE(high1->sent());
377 EXPECT_TRUE(high2->started()); 400 EXPECT_TRUE(high2->sent());
378 EXPECT_TRUE(low->started()); 401 EXPECT_TRUE(low->sent());
379 EXPECT_FALSE(low2->started()); 402 EXPECT_FALSE(low2->sent());
380 403
381 high1.reset(); 404 high1.reset();
382 base::RunLoop().RunUntilIdle(); 405 base::RunLoop().RunUntilIdle();
383 EXPECT_FALSE(low2->started()); 406 EXPECT_FALSE(low2->sent());
384 407
385 high2.reset(); 408 high2.reset();
386 base::RunLoop().RunUntilIdle(); 409 base::RunLoop().RunUntilIdle();
387 EXPECT_TRUE(low2->started()); 410 EXPECT_TRUE(low2->sent());
388 } 411 }
389 412
390 TEST_F(ResourceSchedulerTest, CancelOtherRequestsWhileResuming) { 413 TEST_F(ResourceSchedulerTest, CancelOtherRequestsWhileResuming) {
391 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 414 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
392 scoped_ptr<TestRequest> low1(NewRequest("http://host/low1", net::LOWEST)); 415 scoped_ptr<TestRequest> low1(NewRequest("http://host/low1", net::LOWEST));
393 416
394 scoped_ptr<net::URLRequest> url_request( 417 scoped_ptr<net::URLRequest> url_request(
395 NewURLRequest("http://host/low2", net::LOWEST)); 418 NewURLRequest("http://host/low2", net::LOWEST));
396 scoped_ptr<ResourceThrottle> throttle(scheduler()->ScheduleRequest( 419 scoped_ptr<ResourceThrottle> throttle(scheduler()->ScheduleRequest(
397 kChildId, kRouteId, true, url_request.get())); 420 kChildId, kRouteId, true, url_request.get()));
398 scoped_ptr<CancelingTestRequest> low2(new CancelingTestRequest( 421 scoped_ptr<CancelingTestRequest> low2(new CancelingTestRequest(
399 std::move(url_request), std::move(throttle), scheduler())); 422 std::move(url_request), std::move(throttle), scheduler()));
400 low2->Start(); 423 low2->Start();
424 EXPECT_TRUE(low2->started());
425 low2->Send();
401 426
402 scoped_ptr<TestRequest> low3(NewRequest("http://host/low3", net::LOWEST)); 427 scoped_ptr<TestRequest> low3(NewRequest("http://host/low3", net::LOWEST));
403 low2->set_request_to_cancel(std::move(low3)); 428 low2->set_request_to_cancel(std::move(low3));
404 scoped_ptr<TestRequest> low4(NewRequest("http://host/low4", net::LOWEST)); 429 scoped_ptr<TestRequest> low4(NewRequest("http://host/low4", net::LOWEST));
405 430
406 EXPECT_TRUE(high->started()); 431 EXPECT_TRUE(high->sent());
407 EXPECT_FALSE(low2->started()); 432 EXPECT_FALSE(low2->sent());
408 433
409 high.reset(); 434 high.reset();
410 base::RunLoop().RunUntilIdle(); 435 base::RunLoop().RunUntilIdle();
411 EXPECT_TRUE(low1->started()); 436 EXPECT_TRUE(low1->sent());
412 EXPECT_TRUE(low2->started()); 437 EXPECT_TRUE(low2->sent());
413 EXPECT_TRUE(low4->started()); 438 EXPECT_TRUE(low4->sent());
414 } 439 }
415 440
416 TEST_F(ResourceSchedulerTest, LimitedNumberOfDelayableRequestsInFlight) { 441 TEST_F(ResourceSchedulerTest, LimitedNumberOfDelayableRequestsInFlight) {
417 // We only load low priority resources if there's a body. 442 // We only load low priority resources if there's a body.
418 scheduler()->OnWillInsertBody(kChildId, kRouteId); 443 scheduler()->OnWillInsertBody(kChildId, kRouteId);
419 444
420 // Throw in one high priority request to make sure that's not a factor. 445 // Throw in one high priority request to make sure that's not a factor.
421 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 446 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
422 EXPECT_TRUE(high->started()); 447 EXPECT_TRUE(high->sent());
423 448
424 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. 449 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc.
425 const int kMaxNumDelayableRequestsPerHost = 6; 450 const int kMaxNumDelayableRequestsPerHost = 6;
426 ScopedVector<TestRequest> lows_singlehost; 451 ScopedVector<TestRequest> lows_singlehost;
427 // Queue up to the per-host limit (we subtract the current high-pri request). 452 // Queue up to the per-host limit (we subtract the current high-pri request).
428 for (int i = 0; i < kMaxNumDelayableRequestsPerHost - 1; ++i) { 453 for (int i = 0; i < kMaxNumDelayableRequestsPerHost - 1; ++i) {
429 string url = "http://host/low" + base::IntToString(i); 454 string url = "http://host/low" + base::IntToString(i);
430 lows_singlehost.push_back(NewRequest(url.c_str(), net::LOWEST)); 455 lows_singlehost.push_back(NewRequest(url.c_str(), net::LOWEST));
431 EXPECT_TRUE(lows_singlehost[i]->started()); 456 EXPECT_TRUE(lows_singlehost[i]->started());
432 } 457 }
433 458
434 scoped_ptr<TestRequest> second_last_singlehost(NewRequest("http://host/last", 459 scoped_ptr<TestRequest> second_last_singlehost(NewRequest("http://host/last",
435 net::LOWEST)); 460 net::LOWEST));
436 scoped_ptr<TestRequest> last_singlehost(NewRequest("http://host/s_last", 461 scoped_ptr<TestRequest> last_singlehost(NewRequest("http://host/s_last",
437 net::LOWEST)); 462 net::LOWEST));
438 463
439 EXPECT_FALSE(second_last_singlehost->started()); 464 EXPECT_FALSE(second_last_singlehost->sent());
440 465
441 high.reset(); 466 high.reset();
442 base::RunLoop().RunUntilIdle(); 467 base::RunLoop().RunUntilIdle();
443 EXPECT_TRUE(second_last_singlehost->started()); 468 EXPECT_TRUE(second_last_singlehost->sent());
444 EXPECT_FALSE(last_singlehost->started()); 469 EXPECT_FALSE(last_singlehost->sent());
445 470
446 lows_singlehost.erase(lows_singlehost.begin()); 471 lows_singlehost.erase(lows_singlehost.begin());
447 base::RunLoop().RunUntilIdle(); 472 base::RunLoop().RunUntilIdle();
448 EXPECT_TRUE(last_singlehost->started()); 473 EXPECT_TRUE(last_singlehost->sent());
449 474
450 // Queue more requests from different hosts until we reach the total limit. 475 // Queue more requests from different hosts until we reach the total limit.
451 int expected_slots_left = 476 int expected_slots_left =
452 kMaxNumDelayableRequestsPerClient - kMaxNumDelayableRequestsPerHost; 477 kMaxNumDelayableRequestsPerClient - kMaxNumDelayableRequestsPerHost;
453 EXPECT_GT(expected_slots_left, 0); 478 EXPECT_GT(expected_slots_left, 0);
454 ScopedVector<TestRequest> lows_different_host; 479 ScopedVector<TestRequest> lows_different_host;
455 base::RunLoop().RunUntilIdle(); 480 base::RunLoop().RunUntilIdle();
456 for (int i = 0; i < expected_slots_left; ++i) { 481 for (int i = 0; i < expected_slots_left; ++i) {
457 string url = "http://host" + base::IntToString(i) + "/low"; 482 string url = "http://host" + base::IntToString(i) + "/low";
458 lows_different_host.push_back(NewRequest(url.c_str(), net::LOWEST)); 483 lows_different_host.push_back(NewRequest(url.c_str(), net::LOWEST));
459 EXPECT_TRUE(lows_different_host[i]->started()); 484 EXPECT_TRUE(lows_different_host[i]->sent());
460 } 485 }
461 486
462 scoped_ptr<TestRequest> last_different_host(NewRequest("http://host_new/last", 487 scoped_ptr<TestRequest> last_different_host(NewRequest("http://host_new/last",
463 net::LOWEST)); 488 net::LOWEST));
464 EXPECT_FALSE(last_different_host->started()); 489 EXPECT_FALSE(last_different_host->sent());
465 } 490 }
466 491
467 TEST_F(ResourceSchedulerTest, RaisePriorityAndStart) { 492 TEST_F(ResourceSchedulerTest, RaisePriorityAndStart) {
468 // Dummies to enforce scheduling. 493 // Dummies to enforce scheduling.
469 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 494 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
470 scoped_ptr<TestRequest> low(NewRequest("http://host/req", net::LOWEST)); 495 scoped_ptr<TestRequest> low(NewRequest("http://host/req", net::LOWEST));
471 496
472 scoped_ptr<TestRequest> request(NewRequest("http://host/req", net::LOWEST)); 497 scoped_ptr<TestRequest> request(NewRequest("http://host/req", net::LOWEST));
473 EXPECT_FALSE(request->started()); 498 EXPECT_FALSE(request->sent());
474 499
475 ChangeRequestPriority(request.get(), net::HIGHEST); 500 ChangeRequestPriority(request.get(), net::HIGHEST);
476 base::RunLoop().RunUntilIdle(); 501 base::RunLoop().RunUntilIdle();
477 EXPECT_TRUE(request->started()); 502 EXPECT_TRUE(request->sent());
478 } 503 }
479 504
480 TEST_F(ResourceSchedulerTest, RaisePriorityInQueue) { 505 TEST_F(ResourceSchedulerTest, RaisePriorityInQueue) {
481 // Dummies to enforce scheduling. 506 // Dummies to enforce scheduling.
482 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 507 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
483 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 508 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
484 509
485 scoped_ptr<TestRequest> request(NewRequest("http://host/req", net::IDLE)); 510 scoped_ptr<TestRequest> request(NewRequest("http://host/req", net::IDLE));
486 scoped_ptr<TestRequest> idle(NewRequest("http://host/idle", net::IDLE)); 511 scoped_ptr<TestRequest> idle(NewRequest("http://host/idle", net::IDLE));
487 EXPECT_FALSE(request->started()); 512 EXPECT_FALSE(request->sent());
488 EXPECT_FALSE(idle->started()); 513 EXPECT_FALSE(idle->sent());
489 514
490 ChangeRequestPriority(request.get(), net::LOWEST); 515 ChangeRequestPriority(request.get(), net::LOWEST);
491 base::RunLoop().RunUntilIdle(); 516 base::RunLoop().RunUntilIdle();
492 EXPECT_FALSE(request->started()); 517 EXPECT_FALSE(request->sent());
493 EXPECT_FALSE(idle->started()); 518 EXPECT_FALSE(idle->sent());
494 519
495 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. 520 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc.
496 ScopedVector<TestRequest> lows; 521 ScopedVector<TestRequest> lows;
497 for (int i = 0; i < kMaxNumDelayableRequestsPerClient - 1; ++i) { 522 for (int i = 0; i < kMaxNumDelayableRequestsPerClient - 1; ++i) {
498 string url = "http://host/low" + base::IntToString(i); 523 string url = "http://host/low" + base::IntToString(i);
499 lows.push_back(NewRequest(url.c_str(), net::LOWEST)); 524 lows.push_back(NewRequest(url.c_str(), net::LOWEST));
500 } 525 }
501 526
502 scheduler()->OnWillInsertBody(kChildId, kRouteId); 527 scheduler()->OnWillInsertBody(kChildId, kRouteId);
503 high.reset(); 528 high.reset();
504 base::RunLoop().RunUntilIdle(); 529 base::RunLoop().RunUntilIdle();
505 530
506 EXPECT_TRUE(request->started()); 531 EXPECT_TRUE(request->sent());
507 EXPECT_FALSE(idle->started()); 532 EXPECT_FALSE(idle->sent());
508 } 533 }
509 534
510 TEST_F(ResourceSchedulerTest, LowerPriority) { 535 TEST_F(ResourceSchedulerTest, LowerPriority) {
511 // Dummies to enforce scheduling. 536 // Dummies to enforce scheduling.
512 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 537 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
513 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 538 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
514 539
515 scoped_ptr<TestRequest> request(NewRequest("http://host/req", net::LOWEST)); 540 scoped_ptr<TestRequest> request(NewRequest("http://host/req", net::LOWEST));
516 scoped_ptr<TestRequest> idle(NewRequest("http://host/idle", net::IDLE)); 541 scoped_ptr<TestRequest> idle(NewRequest("http://host/idle", net::IDLE));
517 EXPECT_FALSE(request->started()); 542 EXPECT_FALSE(request->sent());
518 EXPECT_FALSE(idle->started()); 543 EXPECT_FALSE(idle->sent());
519 544
520 ChangeRequestPriority(request.get(), net::IDLE); 545 ChangeRequestPriority(request.get(), net::IDLE);
521 base::RunLoop().RunUntilIdle(); 546 base::RunLoop().RunUntilIdle();
522 EXPECT_FALSE(request->started()); 547 EXPECT_FALSE(request->sent());
523 EXPECT_FALSE(idle->started()); 548 EXPECT_FALSE(idle->sent());
524 549
525 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. 550 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc.
526 // 2 fewer filler requests: 1 for the "low" dummy at the start, and 1 for the 551 // 2 fewer filler requests: 1 for the "low" dummy at the start, and 1 for the
527 // one at the end, which will be tested. 552 // one at the end, which will be tested.
528 const int kNumFillerRequests = kMaxNumDelayableRequestsPerClient - 2; 553 const int kNumFillerRequests = kMaxNumDelayableRequestsPerClient - 2;
529 ScopedVector<TestRequest> lows; 554 ScopedVector<TestRequest> lows;
530 for (int i = 0; i < kNumFillerRequests; ++i) { 555 for (int i = 0; i < kNumFillerRequests; ++i) {
531 string url = "http://host" + base::IntToString(i) + "/low"; 556 string url = "http://host" + base::IntToString(i) + "/low";
532 lows.push_back(NewRequest(url.c_str(), net::LOWEST)); 557 lows.push_back(NewRequest(url.c_str(), net::LOWEST));
533 } 558 }
534 559
535 scheduler()->OnWillInsertBody(kChildId, kRouteId); 560 scheduler()->OnWillInsertBody(kChildId, kRouteId);
536 high.reset(); 561 high.reset();
537 base::RunLoop().RunUntilIdle(); 562 base::RunLoop().RunUntilIdle();
538 563
539 EXPECT_FALSE(request->started()); 564 EXPECT_FALSE(request->sent());
540 EXPECT_TRUE(idle->started()); 565 EXPECT_TRUE(idle->sent());
541 } 566 }
542 567
543 TEST_F(ResourceSchedulerTest, ReprioritizedRequestGoesToBackOfQueue) { 568 TEST_F(ResourceSchedulerTest, ReprioritizedRequestGoesToBackOfQueue) {
544 // Dummies to enforce scheduling. 569 // Dummies to enforce scheduling.
545 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 570 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
546 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 571 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
547 572
548 scoped_ptr<TestRequest> request(NewRequest("http://host/req", net::LOWEST)); 573 scoped_ptr<TestRequest> request(NewRequest("http://host/req", net::LOWEST));
549 scoped_ptr<TestRequest> idle(NewRequest("http://host/idle", net::IDLE)); 574 scoped_ptr<TestRequest> idle(NewRequest("http://host/idle", net::IDLE));
550 EXPECT_FALSE(request->started()); 575 EXPECT_FALSE(request->sent());
551 EXPECT_FALSE(idle->started()); 576 EXPECT_FALSE(idle->sent());
552 577
553 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. 578 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc.
554 ScopedVector<TestRequest> lows; 579 ScopedVector<TestRequest> lows;
555 for (int i = 0; i < kMaxNumDelayableRequestsPerClient; ++i) { 580 for (int i = 0; i < kMaxNumDelayableRequestsPerClient; ++i) {
556 string url = "http://host/low" + base::IntToString(i); 581 string url = "http://host/low" + base::IntToString(i);
557 lows.push_back(NewRequest(url.c_str(), net::LOWEST)); 582 lows.push_back(NewRequest(url.c_str(), net::LOWEST));
558 } 583 }
559 584
560 ChangeRequestPriority(request.get(), net::IDLE); 585 ChangeRequestPriority(request.get(), net::IDLE);
561 base::RunLoop().RunUntilIdle(); 586 base::RunLoop().RunUntilIdle();
562 EXPECT_FALSE(request->started()); 587 EXPECT_FALSE(request->sent());
563 EXPECT_FALSE(idle->started()); 588 EXPECT_FALSE(idle->sent());
564 589
565 ChangeRequestPriority(request.get(), net::LOWEST); 590 ChangeRequestPriority(request.get(), net::LOWEST);
566 base::RunLoop().RunUntilIdle(); 591 base::RunLoop().RunUntilIdle();
567 EXPECT_FALSE(request->started()); 592 EXPECT_FALSE(request->sent());
568 EXPECT_FALSE(idle->started()); 593 EXPECT_FALSE(idle->sent());
569 594
570 scheduler()->OnWillInsertBody(kChildId, kRouteId); 595 scheduler()->OnWillInsertBody(kChildId, kRouteId);
571 base::RunLoop().RunUntilIdle(); 596 base::RunLoop().RunUntilIdle();
572 EXPECT_FALSE(request->started()); 597 EXPECT_FALSE(request->sent());
573 EXPECT_FALSE(idle->started()); 598 EXPECT_FALSE(idle->sent());
574 } 599 }
575 600
576 TEST_F(ResourceSchedulerTest, HigherIntraPriorityGoesToFrontOfQueue) { 601 TEST_F(ResourceSchedulerTest, HigherIntraPriorityGoesToFrontOfQueue) {
577 // Dummies to enforce scheduling. 602 // Dummies to enforce scheduling.
578 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 603 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
579 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 604 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
580 605
581 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. 606 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc.
582 ScopedVector<TestRequest> lows; 607 ScopedVector<TestRequest> lows;
583 for (int i = 0; i < kMaxNumDelayableRequestsPerClient; ++i) { 608 for (int i = 0; i < kMaxNumDelayableRequestsPerClient; ++i) {
584 string url = "http://host/low" + base::IntToString(i); 609 string url = "http://host/low" + base::IntToString(i);
585 lows.push_back(NewRequest(url.c_str(), net::IDLE)); 610 lows.push_back(NewRequest(url.c_str(), net::IDLE));
586 } 611 }
587 612
588 scoped_ptr<TestRequest> request(NewRequest("http://host/req", net::IDLE)); 613 scoped_ptr<TestRequest> request(NewRequest("http://host/req", net::IDLE));
589 EXPECT_FALSE(request->started()); 614 EXPECT_FALSE(request->sent());
590 615
591 ChangeRequestPriority(request.get(), net::IDLE, 1); 616 ChangeRequestPriority(request.get(), net::IDLE, 1);
592 base::RunLoop().RunUntilIdle(); 617 base::RunLoop().RunUntilIdle();
593 EXPECT_FALSE(request->started()); 618 EXPECT_FALSE(request->sent());
594 619
595 scheduler()->OnWillInsertBody(kChildId, kRouteId); 620 scheduler()->OnWillInsertBody(kChildId, kRouteId);
596 high.reset(); 621 high.reset();
597 base::RunLoop().RunUntilIdle(); 622 base::RunLoop().RunUntilIdle();
598 EXPECT_TRUE(request->started()); 623 EXPECT_TRUE(request->sent());
599 } 624 }
600 625
601 TEST_F(ResourceSchedulerTest, NonHTTPSchedulesImmediately) { 626 TEST_F(ResourceSchedulerTest, NonHTTPSchedulesImmediately) {
602 // Dummies to enforce scheduling. 627 // Dummies to enforce scheduling.
603 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 628 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
604 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 629 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
605 630
606 scoped_ptr<TestRequest> request( 631 scoped_ptr<TestRequest> request(
607 NewRequest("chrome-extension://req", net::LOWEST)); 632 NewRequest("chrome-extension://req", net::LOWEST));
608 EXPECT_TRUE(request->started()); 633 EXPECT_TRUE(request->sent());
609 } 634 }
610 635
611 TEST_F(ResourceSchedulerTest, SpdyProxySchedulesImmediately) { 636 TEST_F(ResourceSchedulerTest, SpdyProxySchedulesImmediately) {
612 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 637 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
613 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 638 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
614 639
615 scoped_ptr<TestRequest> request(NewRequest("http://host/req", net::IDLE)); 640 scoped_ptr<TestRequest> request(NewRequest("http://host/req", net::IDLE));
616 EXPECT_FALSE(request->started()); 641 EXPECT_FALSE(request->sent());
617 642
618 scheduler()->OnReceivedSpdyProxiedHttpResponse(kChildId, kRouteId); 643 scheduler()->OnReceivedSpdyProxiedHttpResponse(kChildId, kRouteId);
619 base::RunLoop().RunUntilIdle(); 644 base::RunLoop().RunUntilIdle();
620 EXPECT_TRUE(request->started()); 645 EXPECT_TRUE(request->sent());
621 646
622 scoped_ptr<TestRequest> after(NewRequest("http://host/after", net::IDLE)); 647 scoped_ptr<TestRequest> after(NewRequest("http://host/after", net::IDLE));
623 EXPECT_TRUE(after->started()); 648 EXPECT_TRUE(after->sent());
624 } 649 }
625 650
626 TEST_F(ResourceSchedulerTest, NewSpdyHostInDelayableRequests) { 651 TEST_F(ResourceSchedulerTest, NewSpdyHostInDelayableRequests) {
627 scheduler()->OnWillInsertBody(kChildId, kRouteId); 652 scheduler()->OnWillInsertBody(kChildId, kRouteId);
628 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. 653 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc.
629 654
630 scoped_ptr<TestRequest> low1_spdy( 655 scoped_ptr<TestRequest> low1_spdy(
631 NewRequest("http://spdyhost1:8080/low", net::LOWEST)); 656 NewRequest("http://spdyhost1:8080/low", net::LOWEST));
632 // Cancel a request after we learn the server supports SPDY. 657 // Cancel a request after we learn the server supports SPDY.
633 ScopedVector<TestRequest> lows; 658 ScopedVector<TestRequest> lows;
634 for (int i = 0; i < kMaxNumDelayableRequestsPerClient - 1; ++i) { 659 for (int i = 0; i < kMaxNumDelayableRequestsPerClient - 1; ++i) {
635 string url = "http://host" + base::IntToString(i) + "/low"; 660 string url = "http://host" + base::IntToString(i) + "/low";
636 lows.push_back(NewRequest(url.c_str(), net::LOWEST)); 661 lows.push_back(NewRequest(url.c_str(), net::LOWEST));
637 } 662 }
638 scoped_ptr<TestRequest> low1(NewRequest("http://host/low", net::LOWEST)); 663 scoped_ptr<TestRequest> low1(NewRequest("http://host/low", net::LOWEST));
639 EXPECT_FALSE(low1->started()); 664 EXPECT_FALSE(low1->sent());
640 http_server_properties_.SetSupportsSpdy( 665 http_server_properties_.SetSupportsSpdy(
641 net::HostPortPair("spdyhost1", 8080), true); 666 net::HostPortPair("spdyhost1", 8080), true);
642 low1_spdy.reset(); 667 low1_spdy.reset();
643 base::RunLoop().RunUntilIdle(); 668 base::RunLoop().RunUntilIdle();
644 EXPECT_TRUE(low1->started()); 669 EXPECT_TRUE(low1->sent());
645 670
646 low1.reset(); 671 low1.reset();
647 base::RunLoop().RunUntilIdle(); 672 base::RunLoop().RunUntilIdle();
648 scoped_ptr<TestRequest> low2_spdy( 673 scoped_ptr<TestRequest> low2_spdy(
649 NewRequest("http://spdyhost2:8080/low", net::IDLE)); 674 NewRequest("http://spdyhost2:8080/low", net::IDLE));
650 // Reprioritize a request after we learn the server supports SPDY. 675 // Reprioritize a request after we learn the server supports SPDY.
651 EXPECT_TRUE(low2_spdy->started()); 676 EXPECT_TRUE(low2_spdy->sent());
652 http_server_properties_.SetSupportsSpdy( 677 http_server_properties_.SetSupportsSpdy(
653 net::HostPortPair("spdyhost2", 8080), true); 678 net::HostPortPair("spdyhost2", 8080), true);
654 ChangeRequestPriority(low2_spdy.get(), net::LOWEST); 679 ChangeRequestPriority(low2_spdy.get(), net::LOWEST);
655 base::RunLoop().RunUntilIdle(); 680 base::RunLoop().RunUntilIdle();
656 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); 681 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
657 EXPECT_TRUE(low2->started()); 682 EXPECT_TRUE(low2->sent());
658 } 683 }
659 684
660 TEST_F(ResourceSchedulerTest, OustandingRequestLimitEnforced) { 685 TEST_F(ResourceSchedulerTest, OustandingRequestLimitEnforced) {
661 const int kRequestLimit = 3; 686 const int kRequestLimit = 3;
662 ASSERT_TRUE(InitializeFieldTrials( 687 ASSERT_TRUE(InitializeFieldTrials(
663 base::StringPrintf("OutstandingRequestLimiting/Limit=%d/", 688 base::StringPrintf("OutstandingRequestLimiting/Limit=%d/",
664 kRequestLimit))); 689 kRequestLimit)));
665 InitializeScheduler(); 690 InitializeScheduler();
666 691
667 // Throw in requests up to the above limit; make sure they are started. 692 // Throw in requests up to the above limit; make sure they are started.
668 ScopedVector<TestRequest> requests; 693 ScopedVector<TestRequest> requests;
669 for (int i = 0; i < kRequestLimit; ++i) { 694 for (int i = 0; i < kRequestLimit; ++i) {
670 string url = "http://host/medium"; 695 string url = "http://host/medium";
671 requests.push_back(NewRequest(url.c_str(), net::MEDIUM)); 696 requests.push_back(NewRequest(url.c_str(), net::MEDIUM));
672 EXPECT_TRUE(requests[i]->started()); 697 EXPECT_TRUE(requests[i]->sent());
673 } 698 }
674 699
675 // Confirm that another request will indeed fail. 700 // Confirm that another request will indeed fail.
676 string url = "http://host/medium"; 701 string url = "http://host/medium";
677 requests.push_back(NewRequest(url.c_str(), net::MEDIUM)); 702 requests.push_back(NewRequest(url.c_str(), net::MEDIUM));
678 EXPECT_FALSE(requests[kRequestLimit]->started()); 703 EXPECT_FALSE(requests[kRequestLimit]->sent());
679 } 704 }
680 705
681 // Confirm that outstanding requests limits apply to requests to hosts 706 // Confirm that outstanding requests limits apply to requests to hosts
682 // that support request priority. 707 // that support request priority.
683 TEST_F(ResourceSchedulerTest, 708 TEST_F(ResourceSchedulerTest,
684 OutstandingRequestsLimitsEnforcedForRequestPriority) { 709 OutstandingRequestsLimitsEnforcedForRequestPriority) {
685 const int kRequestLimit = 3; 710 const int kRequestLimit = 3;
686 ASSERT_TRUE(InitializeFieldTrials( 711 ASSERT_TRUE(InitializeFieldTrials(
687 base::StringPrintf("OutstandingRequestLimiting/Limit=%d/", 712 base::StringPrintf("OutstandingRequestLimiting/Limit=%d/",
688 kRequestLimit))); 713 kRequestLimit)));
689 InitializeScheduler(); 714 InitializeScheduler();
690 715
691 http_server_properties_.SetSupportsSpdy( 716 http_server_properties_.SetSupportsSpdy(
692 net::HostPortPair("spdyhost", 443), true); 717 net::HostPortPair("spdyhost", 443), true);
693 718
694 // Throw in requests up to the above limit; make sure they are started. 719 // Throw in requests up to the above limit; make sure they are started.
695 ScopedVector<TestRequest> requests; 720 ScopedVector<TestRequest> requests;
696 for (int i = 0; i < kRequestLimit; ++i) { 721 for (int i = 0; i < kRequestLimit; ++i) {
697 string url = "http://spdyhost/medium"; 722 string url = "http://spdyhost/medium";
698 requests.push_back(NewRequest(url.c_str(), net::MEDIUM)); 723 requests.push_back(NewRequest(url.c_str(), net::MEDIUM));
699 EXPECT_TRUE(requests[i]->started()); 724 EXPECT_TRUE(requests[i]->sent());
700 } 725 }
701 726
702 // Confirm that another request will indeed fail. 727 // Confirm that another request will indeed fail.
703 string url = "http://spdyhost/medium"; 728 string url = "http://spdyhost/medium";
704 requests.push_back(NewRequest(url.c_str(), net::MEDIUM)); 729 requests.push_back(NewRequest(url.c_str(), net::MEDIUM));
705 EXPECT_FALSE(requests[kRequestLimit]->started()); 730 EXPECT_FALSE(requests[kRequestLimit]->sent());
706 } 731 }
707 732
708 TEST_F(ResourceSchedulerTest, OutstandingRequestLimitDelays) { 733 TEST_F(ResourceSchedulerTest, OutstandingRequestLimitDelays) {
709 const int kRequestLimit = 3; 734 const int kRequestLimit = 3;
710 ASSERT_TRUE(InitializeFieldTrials( 735 ASSERT_TRUE(InitializeFieldTrials(
711 base::StringPrintf("OutstandingRequestLimiting/Limit=%d/", 736 base::StringPrintf("OutstandingRequestLimiting/Limit=%d/",
712 kRequestLimit))); 737 kRequestLimit)));
713 738
714 InitializeScheduler(); 739 InitializeScheduler();
715 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 740 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
716 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 741 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
717 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); 742 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
718 EXPECT_TRUE(high->started()); 743 EXPECT_TRUE(high->sent());
719 EXPECT_FALSE(low->started()); 744 EXPECT_FALSE(low->sent());
720 EXPECT_FALSE(low2->started()); 745 EXPECT_FALSE(low2->sent());
721 746
722 high.reset(); 747 high.reset();
723 base::RunLoop().RunUntilIdle(); 748 base::RunLoop().RunUntilIdle();
724 EXPECT_TRUE(low->started()); 749 EXPECT_TRUE(low->sent());
725 EXPECT_TRUE(low2->started()); 750 EXPECT_TRUE(low2->sent());
726 } 751 }
727 752
728 // Async revalidations which are not started when the tab is closed must be 753 // Async revalidations which are not started when the tab is closed must be
729 // started at some point, or they will hang around forever and prevent other 754 // started at some point, or they will hang around forever and prevent other
730 // async revalidations to the same URL from being issued. 755 // async revalidations to the same URL from being issued.
731 TEST_F(ResourceSchedulerTest, RequestStartedAfterClientDeleted) { 756 TEST_F(ResourceSchedulerTest, RequestStartedAfterClientDeleted) {
732 scheduler_->OnClientCreated(kChildId2, kRouteId2); 757 scheduler_->OnClientCreated(kChildId2, kRouteId2);
733 scoped_ptr<TestRequest> high(NewRequestWithChildAndRoute( 758 scoped_ptr<TestRequest> high(NewRequestWithChildAndRoute(
734 "http://host/high", net::HIGHEST, kChildId2, kRouteId2)); 759 "http://host/high", net::HIGHEST, kChildId2, kRouteId2));
735 scoped_ptr<TestRequest> lowest1(NewRequestWithChildAndRoute( 760 scoped_ptr<TestRequest> lowest1(NewRequestWithChildAndRoute(
736 "http://host/lowest", net::LOWEST, kChildId2, kRouteId2)); 761 "http://host/lowest", net::LOWEST, kChildId2, kRouteId2));
737 scoped_ptr<TestRequest> lowest2(NewRequestWithChildAndRoute( 762 scoped_ptr<TestRequest> lowest2(NewRequestWithChildAndRoute(
738 "http://host/lowest", net::LOWEST, kChildId2, kRouteId2)); 763 "http://host/lowest", net::LOWEST, kChildId2, kRouteId2));
739 EXPECT_FALSE(lowest2->started()); 764 EXPECT_FALSE(lowest2->sent());
740 765
741 scheduler_->OnClientDeleted(kChildId2, kRouteId2); 766 scheduler_->OnClientDeleted(kChildId2, kRouteId2);
742 high.reset(); 767 high.reset();
743 lowest1.reset(); 768 lowest1.reset();
744 base::RunLoop().RunUntilIdle(); 769 base::RunLoop().RunUntilIdle();
745 EXPECT_TRUE(lowest2->started()); 770 EXPECT_TRUE(lowest2->sent());
746 } 771 }
747 772
748 // The ResourceScheduler::Client destructor calls 773 // The ResourceScheduler::Client destructor calls
749 // LoadAnyStartablePendingRequests(), which may start some pending requests. 774 // LoadAnyStartablePendingRequests(), which may start some pending requests.
750 // This test is to verify that requests will be started at some point 775 // This test is to verify that requests will be started at some point
751 // even if they were not started by the destructor. 776 // even if they were not started by the destructor.
752 TEST_F(ResourceSchedulerTest, RequestStartedAfterClientDeletedManyDelayable) { 777 TEST_F(ResourceSchedulerTest, RequestStartedAfterClientDeletedManyDelayable) {
753 scheduler_->OnClientCreated(kChildId2, kRouteId2); 778 scheduler_->OnClientCreated(kChildId2, kRouteId2);
754 scoped_ptr<TestRequest> high(NewRequestWithChildAndRoute( 779 scoped_ptr<TestRequest> high(NewRequestWithChildAndRoute(
755 "http://host/high", net::HIGHEST, kChildId2, kRouteId2)); 780 "http://host/high", net::HIGHEST, kChildId2, kRouteId2));
756 const int kMaxNumDelayableRequestsPerClient = 10; 781 const int kMaxNumDelayableRequestsPerClient = 10;
757 ScopedVector<TestRequest> delayable_requests; 782 ScopedVector<TestRequest> delayable_requests;
758 for (int i = 0; i < kMaxNumDelayableRequestsPerClient + 1; ++i) { 783 for (int i = 0; i < kMaxNumDelayableRequestsPerClient + 1; ++i) {
759 delayable_requests.push_back(NewRequestWithChildAndRoute( 784 delayable_requests.push_back(NewRequestWithChildAndRoute(
760 "http://host/lowest", net::LOWEST, kChildId2, kRouteId2)); 785 "http://host/lowest", net::LOWEST, kChildId2, kRouteId2));
761 } 786 }
762 scoped_ptr<TestRequest> lowest(NewRequestWithChildAndRoute( 787 scoped_ptr<TestRequest> lowest(NewRequestWithChildAndRoute(
763 "http://host/lowest", net::LOWEST, kChildId2, kRouteId2)); 788 "http://host/lowest", net::LOWEST, kChildId2, kRouteId2));
764 EXPECT_FALSE(lowest->started()); 789 EXPECT_FALSE(lowest->sent());
765 790
766 scheduler_->OnClientDeleted(kChildId2, kRouteId2); 791 scheduler_->OnClientDeleted(kChildId2, kRouteId2);
767 high.reset(); 792 high.reset();
768 delayable_requests.clear(); 793 delayable_requests.clear();
769 base::RunLoop().RunUntilIdle(); 794 base::RunLoop().RunUntilIdle();
770 EXPECT_TRUE(lowest->started()); 795 EXPECT_TRUE(lowest->sent());
771 } 796 }
772 797
773 TEST_F(ResourceSchedulerTest, DefaultLayoutBlockingPriority) { 798 TEST_F(ResourceSchedulerTest, DefaultLayoutBlockingPriority) {
774 const int kDeferLateScripts = 0; 799 const int kDeferLateScripts = 0;
775 const int kIncreaseFontPriority = 0; 800 const int kIncreaseFontPriority = 0;
776 const int kIncreaseAsyncScriptPriority = 0; 801 const int kIncreaseAsyncScriptPriority = 0;
777 const int kEnablePriorityIncrease = 0; 802 const int kEnablePriorityIncrease = 0;
778 const int kEnableLayoutBlockingThreshold = 0; 803 const int kEnableLayoutBlockingThreshold = 0;
779 const int kLayoutBlockingThreshold = 0; 804 const int kLayoutBlockingThreshold = 0;
780 const int kMaxNumDelayableWhileLayoutBlocking = 1; 805 const int kMaxNumDelayableWhileLayoutBlocking = 1;
(...skipping 15 matching lines...) Expand all
796 NewRequest("http://hosthigh/high", net::HIGHEST)); 821 NewRequest("http://hosthigh/high", net::HIGHEST));
797 scoped_ptr<TestRequest> medium( 822 scoped_ptr<TestRequest> medium(
798 NewRequest("http://hostmedium/medium", net::MEDIUM)); 823 NewRequest("http://hostmedium/medium", net::MEDIUM));
799 scoped_ptr<TestRequest> medium2( 824 scoped_ptr<TestRequest> medium2(
800 NewRequest("http://hostmedium/medium", net::MEDIUM)); 825 NewRequest("http://hostmedium/medium", net::MEDIUM));
801 scoped_ptr<TestRequest> low(NewRequest("http://hostlow/low", net::LOW)); 826 scoped_ptr<TestRequest> low(NewRequest("http://hostlow/low", net::LOW));
802 scoped_ptr<TestRequest> low2(NewRequest("http://hostlow/low", net::LOW)); 827 scoped_ptr<TestRequest> low2(NewRequest("http://hostlow/low", net::LOW));
803 scoped_ptr<TestRequest> lowest(NewRequest("http://hostlowest/lowest", net::LOW EST)); 828 scoped_ptr<TestRequest> lowest(NewRequest("http://hostlowest/lowest", net::LOW EST));
804 scoped_ptr<TestRequest> lowest2( 829 scoped_ptr<TestRequest> lowest2(
805 NewRequest("http://hostlowest/lowest", net::LOWEST)); 830 NewRequest("http://hostlowest/lowest", net::LOWEST));
806 EXPECT_TRUE(high->started()); 831 EXPECT_TRUE(high->sent());
807 EXPECT_TRUE(high2->started()); 832 EXPECT_TRUE(high2->sent());
808 EXPECT_TRUE(medium->started()); 833 EXPECT_TRUE(medium->sent());
809 EXPECT_TRUE(medium2->started()); 834 EXPECT_TRUE(medium2->sent());
810 EXPECT_TRUE(low->started()); 835 EXPECT_TRUE(low->sent());
811 EXPECT_TRUE(low2->started()); 836 EXPECT_TRUE(low2->sent());
812 EXPECT_TRUE(lowest->started()); 837 EXPECT_TRUE(lowest->sent());
813 EXPECT_FALSE(lowest2->started()); 838 EXPECT_FALSE(lowest2->sent());
814 839
815 lowest.reset(); 840 lowest.reset();
816 base::RunLoop().RunUntilIdle(); 841 base::RunLoop().RunUntilIdle();
817 EXPECT_TRUE(lowest2->started()); 842 EXPECT_TRUE(lowest2->sent());
818 } 843 }
819 844
820 TEST_F(ResourceSchedulerTest, IncreaseLayoutBlockingPriority) { 845 TEST_F(ResourceSchedulerTest, IncreaseLayoutBlockingPriority) {
821 // Changes the level of priorities that are allowed during layout-blocking 846 // Changes the level of priorities that are allowed during layout-blocking
822 // from net::LOWEST to net::LOW. 847 // from net::LOWEST to net::LOW.
823 const int kDeferLateScripts = 0; 848 const int kDeferLateScripts = 0;
824 const int kIncreaseFontPriority = 0; 849 const int kIncreaseFontPriority = 0;
825 const int kIncreaseAsyncScriptPriority = 0; 850 const int kIncreaseAsyncScriptPriority = 0;
826 const int kEnablePriorityIncrease = 1; 851 const int kEnablePriorityIncrease = 1;
827 const int kEnableLayoutBlockingThreshold = 0; 852 const int kEnableLayoutBlockingThreshold = 0;
(...skipping 17 matching lines...) Expand all
845 NewRequest("http://hosthigh/high", net::HIGHEST)); 870 NewRequest("http://hosthigh/high", net::HIGHEST));
846 scoped_ptr<TestRequest> medium( 871 scoped_ptr<TestRequest> medium(
847 NewRequest("http://hostmedium/medium", net::MEDIUM)); 872 NewRequest("http://hostmedium/medium", net::MEDIUM));
848 scoped_ptr<TestRequest> medium2( 873 scoped_ptr<TestRequest> medium2(
849 NewRequest("http://hostmedium/medium", net::MEDIUM)); 874 NewRequest("http://hostmedium/medium", net::MEDIUM));
850 scoped_ptr<TestRequest> low(NewRequest("http://hostlow/low", net::LOW)); 875 scoped_ptr<TestRequest> low(NewRequest("http://hostlow/low", net::LOW));
851 scoped_ptr<TestRequest> low2(NewRequest("http://hostlow/low", net::LOW)); 876 scoped_ptr<TestRequest> low2(NewRequest("http://hostlow/low", net::LOW));
852 scoped_ptr<TestRequest> lowest(NewRequest("http://hostlowest/lowest", net::LOW EST)); 877 scoped_ptr<TestRequest> lowest(NewRequest("http://hostlowest/lowest", net::LOW EST));
853 scoped_ptr<TestRequest> lowest2( 878 scoped_ptr<TestRequest> lowest2(
854 NewRequest("http://hostlowest/lowest", net::LOWEST)); 879 NewRequest("http://hostlowest/lowest", net::LOWEST));
855 EXPECT_TRUE(high->started()); 880 EXPECT_TRUE(high->sent());
856 EXPECT_TRUE(high2->started()); 881 EXPECT_TRUE(high2->sent());
857 EXPECT_TRUE(medium->started()); 882 EXPECT_TRUE(medium->sent());
858 EXPECT_TRUE(medium2->started()); 883 EXPECT_TRUE(medium2->sent());
859 EXPECT_TRUE(low->started()); 884 EXPECT_TRUE(low->sent());
860 EXPECT_FALSE(low2->started()); 885 EXPECT_FALSE(low2->sent());
861 EXPECT_FALSE(lowest->started()); 886 EXPECT_FALSE(lowest->sent());
862 EXPECT_FALSE(lowest2->started()); 887 EXPECT_FALSE(lowest2->sent());
863 888
864 low.reset(); 889 low.reset();
865 base::RunLoop().RunUntilIdle(); 890 base::RunLoop().RunUntilIdle();
866 EXPECT_TRUE(low2->started()); 891 EXPECT_TRUE(low2->sent());
867 EXPECT_FALSE(lowest->started()); 892 EXPECT_FALSE(lowest->sent());
868 EXPECT_FALSE(lowest2->started()); 893 EXPECT_FALSE(lowest2->sent());
869 894
870 low2.reset(); 895 low2.reset();
871 base::RunLoop().RunUntilIdle(); 896 base::RunLoop().RunUntilIdle();
872 EXPECT_TRUE(lowest->started()); 897 EXPECT_TRUE(lowest->sent());
873 EXPECT_FALSE(lowest2->started()); 898 EXPECT_FALSE(lowest2->sent());
874 899
875 lowest.reset(); 900 lowest.reset();
876 base::RunLoop().RunUntilIdle(); 901 base::RunLoop().RunUntilIdle();
877 EXPECT_TRUE(lowest2->started()); 902 EXPECT_TRUE(lowest2->sent());
878 } 903 }
879 904
880 TEST_F(ResourceSchedulerTest, UseLayoutBlockingThresholdOne) { 905 TEST_F(ResourceSchedulerTest, UseLayoutBlockingThresholdOne) {
881 // Prevents any low priority requests from starting while more than 906 // Prevents any low priority requests from starting while more than
882 // N high priority requests are pending (before body). 907 // N high priority requests are pending (before body).
883 const int kDeferLateScripts = 0; 908 const int kDeferLateScripts = 0;
884 const int kIncreaseFontPriority = 0; 909 const int kIncreaseFontPriority = 0;
885 const int kIncreaseAsyncScriptPriority = 0; 910 const int kIncreaseAsyncScriptPriority = 0;
886 const int kEnablePriorityIncrease = 0; 911 const int kEnablePriorityIncrease = 0;
887 const int kEnableLayoutBlockingThreshold = 1; 912 const int kEnableLayoutBlockingThreshold = 1;
888 const int kLayoutBlockingThreshold = 1; 913 const int kLayoutBlockingThreshold = 1;
889 const int kMaxNumDelayableWhileLayoutBlocking = 1; 914 const int kMaxNumDelayableWhileLayoutBlocking = 1;
890 const int kMaxNumDelayableRequestsPerClient = 10; 915 const int kMaxNumDelayableRequestsPerClient = 10;
891 ASSERT_TRUE(InitializeFieldTrials(base::StringPrintf( 916 ASSERT_TRUE(InitializeFieldTrials(base::StringPrintf(
892 "ResourcePriorities/LayoutBlocking_%d%d%d%d%d_%d_%d_%d/", 917 "ResourcePriorities/LayoutBlocking_%d%d%d%d%d_%d_%d_%d/",
893 kDeferLateScripts, 918 kDeferLateScripts,
894 kIncreaseFontPriority, 919 kIncreaseFontPriority,
895 kIncreaseAsyncScriptPriority, 920 kIncreaseAsyncScriptPriority,
896 kEnablePriorityIncrease, 921 kEnablePriorityIncrease,
897 kEnableLayoutBlockingThreshold, 922 kEnableLayoutBlockingThreshold,
898 kLayoutBlockingThreshold, 923 kLayoutBlockingThreshold,
899 kMaxNumDelayableWhileLayoutBlocking, 924 kMaxNumDelayableWhileLayoutBlocking,
900 kMaxNumDelayableRequestsPerClient))); 925 kMaxNumDelayableRequestsPerClient)));
901 InitializeScheduler(); 926 InitializeScheduler();
902 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 927 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
903 scoped_ptr<TestRequest> high2(NewRequest("http://host/high", net::HIGHEST)); 928 scoped_ptr<TestRequest> high2(NewRequest("http://host/high", net::HIGHEST));
904 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 929 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
905 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); 930 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
906 EXPECT_TRUE(high->started()); 931 EXPECT_TRUE(high->sent());
907 EXPECT_TRUE(high2->started()); 932 EXPECT_TRUE(high2->sent());
908 EXPECT_FALSE(low->started()); 933 EXPECT_FALSE(low->sent());
909 EXPECT_FALSE(low2->started()); 934 EXPECT_FALSE(low2->sent());
910 935
911 high.reset(); 936 high.reset();
912 base::RunLoop().RunUntilIdle(); 937 base::RunLoop().RunUntilIdle();
913 EXPECT_TRUE(low->started()); 938 EXPECT_TRUE(low->sent());
914 EXPECT_FALSE(low2->started()); 939 EXPECT_FALSE(low2->sent());
915 940
916 high2.reset(); 941 high2.reset();
917 base::RunLoop().RunUntilIdle(); 942 base::RunLoop().RunUntilIdle();
918 EXPECT_FALSE(low2->started()); 943 EXPECT_FALSE(low2->sent());
919 944
920 scheduler()->OnWillInsertBody(kChildId, kRouteId); 945 scheduler()->OnWillInsertBody(kChildId, kRouteId);
921 base::RunLoop().RunUntilIdle(); 946 base::RunLoop().RunUntilIdle();
922 EXPECT_TRUE(low2->started()); 947 EXPECT_TRUE(low2->sent());
923 } 948 }
924 949
925 TEST_F(ResourceSchedulerTest, UseLayoutBlockingThresholdTwo) { 950 TEST_F(ResourceSchedulerTest, UseLayoutBlockingThresholdTwo) {
926 // Prevents any low priority requests from starting while more than 951 // Prevents any low priority requests from starting while more than
927 // N high priority requests are pending (before body). 952 // N high priority requests are pending (before body).
928 const int kDeferLateScripts = 0; 953 const int kDeferLateScripts = 0;
929 const int kIncreaseFontPriority = 0; 954 const int kIncreaseFontPriority = 0;
930 const int kIncreaseAsyncScriptPriority = 0; 955 const int kIncreaseAsyncScriptPriority = 0;
931 const int kEnablePriorityIncrease = 0; 956 const int kEnablePriorityIncrease = 0;
932 const int kEnableLayoutBlockingThreshold = 1; 957 const int kEnableLayoutBlockingThreshold = 1;
933 const int kLayoutBlockingThreshold = 2; 958 const int kLayoutBlockingThreshold = 2;
934 const int kMaxNumDelayableWhileLayoutBlocking = 1; 959 const int kMaxNumDelayableWhileLayoutBlocking = 1;
935 const int kMaxNumDelayableRequestsPerClient = 10; 960 const int kMaxNumDelayableRequestsPerClient = 10;
936 ASSERT_TRUE(InitializeFieldTrials(base::StringPrintf( 961 ASSERT_TRUE(InitializeFieldTrials(base::StringPrintf(
937 "ResourcePriorities/LayoutBlocking_%d%d%d%d%d_%d_%d_%d/", 962 "ResourcePriorities/LayoutBlocking_%d%d%d%d%d_%d_%d_%d/",
938 kDeferLateScripts, 963 kDeferLateScripts,
939 kIncreaseFontPriority, 964 kIncreaseFontPriority,
940 kIncreaseAsyncScriptPriority, 965 kIncreaseAsyncScriptPriority,
941 kEnablePriorityIncrease, 966 kEnablePriorityIncrease,
942 kEnableLayoutBlockingThreshold, 967 kEnableLayoutBlockingThreshold,
943 kLayoutBlockingThreshold, 968 kLayoutBlockingThreshold,
944 kMaxNumDelayableWhileLayoutBlocking, 969 kMaxNumDelayableWhileLayoutBlocking,
945 kMaxNumDelayableRequestsPerClient))); 970 kMaxNumDelayableRequestsPerClient)));
946 InitializeScheduler(); 971 InitializeScheduler();
947 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 972 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
948 scoped_ptr<TestRequest> high2(NewRequest("http://host/high", net::HIGHEST)); 973 scoped_ptr<TestRequest> high2(NewRequest("http://host/high", net::HIGHEST));
949 scoped_ptr<TestRequest> high3(NewRequest("http://host/high", net::HIGHEST)); 974 scoped_ptr<TestRequest> high3(NewRequest("http://host/high", net::HIGHEST));
950 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 975 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
951 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); 976 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
952 EXPECT_TRUE(high->started()); 977 EXPECT_TRUE(high->sent());
953 EXPECT_TRUE(high2->started()); 978 EXPECT_TRUE(high2->sent());
954 EXPECT_TRUE(high3->started()); 979 EXPECT_TRUE(high3->sent());
955 EXPECT_FALSE(low->started()); 980 EXPECT_FALSE(low->sent());
956 EXPECT_FALSE(low2->started()); 981 EXPECT_FALSE(low2->sent());
957 982
958 high.reset(); 983 high.reset();
959 base::RunLoop().RunUntilIdle(); 984 base::RunLoop().RunUntilIdle();
960 EXPECT_TRUE(low->started()); 985 EXPECT_TRUE(low->sent());
961 EXPECT_FALSE(low2->started()); 986 EXPECT_FALSE(low2->sent());
962 987
963 high2.reset(); 988 high2.reset();
964 high3.reset(); 989 high3.reset();
965 base::RunLoop().RunUntilIdle(); 990 base::RunLoop().RunUntilIdle();
966 EXPECT_FALSE(low2->started()); 991 EXPECT_FALSE(low2->sent());
967 992
968 scheduler()->OnWillInsertBody(kChildId, kRouteId); 993 scheduler()->OnWillInsertBody(kChildId, kRouteId);
969 base::RunLoop().RunUntilIdle(); 994 base::RunLoop().RunUntilIdle();
970 EXPECT_TRUE(low2->started()); 995 EXPECT_TRUE(low2->sent());
971 } 996 }
972 997
973 TEST_F(ResourceSchedulerTest, TwoDelayableLoadsUntilBodyInserted) { 998 TEST_F(ResourceSchedulerTest, TwoDelayableLoadsUntilBodyInserted) {
974 // Allow for two low priority requests to be in flight at any point in time 999 // Allow for two low priority requests to be in flight at any point in time
975 // during the layout-blocking phase of loading. 1000 // during the layout-blocking phase of loading.
976 const int kDeferLateScripts = 0; 1001 const int kDeferLateScripts = 0;
977 const int kIncreaseFontPriority = 0; 1002 const int kIncreaseFontPriority = 0;
978 const int kIncreaseAsyncScriptPriority = 0; 1003 const int kIncreaseAsyncScriptPriority = 0;
979 const int kEnablePriorityIncrease = 0; 1004 const int kEnablePriorityIncrease = 0;
980 const int kEnableLayoutBlockingThreshold = 0; 1005 const int kEnableLayoutBlockingThreshold = 0;
981 const int kLayoutBlockingThreshold = 0; 1006 const int kLayoutBlockingThreshold = 0;
982 const int kMaxNumDelayableWhileLayoutBlocking = 2; 1007 const int kMaxNumDelayableWhileLayoutBlocking = 2;
983 const int kMaxNumDelayableRequestsPerClient = 10; 1008 const int kMaxNumDelayableRequestsPerClient = 10;
984 ASSERT_TRUE(InitializeFieldTrials(base::StringPrintf( 1009 ASSERT_TRUE(InitializeFieldTrials(base::StringPrintf(
985 "ResourcePriorities/LayoutBlocking_%d%d%d%d%d_%d_%d_%d/", 1010 "ResourcePriorities/LayoutBlocking_%d%d%d%d%d_%d_%d_%d/",
986 kDeferLateScripts, 1011 kDeferLateScripts,
987 kIncreaseFontPriority, 1012 kIncreaseFontPriority,
988 kIncreaseAsyncScriptPriority, 1013 kIncreaseAsyncScriptPriority,
989 kEnablePriorityIncrease, 1014 kEnablePriorityIncrease,
990 kEnableLayoutBlockingThreshold, 1015 kEnableLayoutBlockingThreshold,
991 kLayoutBlockingThreshold, 1016 kLayoutBlockingThreshold,
992 kMaxNumDelayableWhileLayoutBlocking, 1017 kMaxNumDelayableWhileLayoutBlocking,
993 kMaxNumDelayableRequestsPerClient))); 1018 kMaxNumDelayableRequestsPerClient)));
994 InitializeScheduler(); 1019 InitializeScheduler();
995 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 1020 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
996 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 1021 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
997 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); 1022 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
998 scoped_ptr<TestRequest> low3(NewRequest("http://host/low", net::LOWEST)); 1023 scoped_ptr<TestRequest> low3(NewRequest("http://host/low", net::LOWEST));
999 EXPECT_TRUE(high->started()); 1024 EXPECT_TRUE(high->sent());
1000 EXPECT_TRUE(low->started()); 1025 EXPECT_TRUE(low->sent());
1001 EXPECT_TRUE(low2->started()); 1026 EXPECT_TRUE(low2->sent());
1002 EXPECT_FALSE(low3->started()); 1027 EXPECT_FALSE(low3->sent());
1003 1028
1004 high.reset(); 1029 high.reset();
1005 scheduler()->OnWillInsertBody(kChildId, kRouteId); 1030 scheduler()->OnWillInsertBody(kChildId, kRouteId);
1006 base::RunLoop().RunUntilIdle(); 1031 base::RunLoop().RunUntilIdle();
1007 EXPECT_TRUE(low3->started()); 1032 EXPECT_TRUE(low3->sent());
1008 } 1033 }
1009 1034
1010 TEST_F(ResourceSchedulerTest, 1035 TEST_F(ResourceSchedulerTest,
1011 UseLayoutBlockingThresholdOneAndTwoDelayableLoadsUntilBodyInserted) { 1036 UseLayoutBlockingThresholdOneAndTwoDelayableLoadsUntilBodyInserted) {
1012 // Allow for two low priority requests to be in flight during the 1037 // Allow for two low priority requests to be in flight during the
1013 // layout-blocking phase of loading but only when there is not more than one 1038 // layout-blocking phase of loading but only when there is not more than one
1014 // in-flight high priority request. 1039 // in-flight high priority request.
1015 const int kDeferLateScripts = 0; 1040 const int kDeferLateScripts = 0;
1016 const int kIncreaseFontPriority = 0; 1041 const int kIncreaseFontPriority = 0;
1017 const int kIncreaseAsyncScriptPriority = 0; 1042 const int kIncreaseAsyncScriptPriority = 0;
(...skipping 11 matching lines...) Expand all
1029 kEnableLayoutBlockingThreshold, 1054 kEnableLayoutBlockingThreshold,
1030 kLayoutBlockingThreshold, 1055 kLayoutBlockingThreshold,
1031 kMaxNumDelayableWhileLayoutBlocking, 1056 kMaxNumDelayableWhileLayoutBlocking,
1032 kMaxNumDelayableRequestsPerClient))); 1057 kMaxNumDelayableRequestsPerClient)));
1033 InitializeScheduler(); 1058 InitializeScheduler();
1034 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 1059 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
1035 scoped_ptr<TestRequest> high2(NewRequest("http://host/high", net::HIGHEST)); 1060 scoped_ptr<TestRequest> high2(NewRequest("http://host/high", net::HIGHEST));
1036 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 1061 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
1037 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); 1062 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
1038 scoped_ptr<TestRequest> low3(NewRequest("http://host/low", net::LOWEST)); 1063 scoped_ptr<TestRequest> low3(NewRequest("http://host/low", net::LOWEST));
1039 EXPECT_TRUE(high->started()); 1064 EXPECT_TRUE(high->sent());
1040 EXPECT_TRUE(high2->started()); 1065 EXPECT_TRUE(high2->sent());
1041 EXPECT_FALSE(low->started()); 1066 EXPECT_FALSE(low->sent());
1042 EXPECT_FALSE(low2->started()); 1067 EXPECT_FALSE(low2->sent());
1043 EXPECT_FALSE(low3->started()); 1068 EXPECT_FALSE(low3->sent());
1044 1069
1045 high.reset(); 1070 high.reset();
1046 base::RunLoop().RunUntilIdle(); 1071 base::RunLoop().RunUntilIdle();
1047 EXPECT_TRUE(low->started()); 1072 EXPECT_TRUE(low->sent());
1048 EXPECT_TRUE(low2->started()); 1073 EXPECT_TRUE(low2->sent());
1049 EXPECT_FALSE(low3->started()); 1074 EXPECT_FALSE(low3->sent());
1050 1075
1051 high2.reset(); 1076 high2.reset();
1052 scheduler()->OnWillInsertBody(kChildId, kRouteId); 1077 scheduler()->OnWillInsertBody(kChildId, kRouteId);
1053 base::RunLoop().RunUntilIdle(); 1078 base::RunLoop().RunUntilIdle();
1054 EXPECT_TRUE(low3->started()); 1079 EXPECT_TRUE(low3->sent());
1055 } 1080 }
1056 1081
1057 TEST_F(ResourceSchedulerTest, TwentyMaxNumDelayableRequestsPerClient) { 1082 TEST_F(ResourceSchedulerTest, TwentyMaxNumDelayableRequestsPerClient) {
1058 // Do not exceed 20 low-priority requests to be in flight across all hosts 1083 // Do not exceed 20 low-priority requests to be in flight across all hosts
1059 // at any point in time. 1084 // at any point in time.
1060 const int kDeferLateScripts = 0; 1085 const int kDeferLateScripts = 0;
1061 const int kIncreaseFontPriority = 0; 1086 const int kIncreaseFontPriority = 0;
1062 const int kIncreaseAsyncScriptPriority = 0; 1087 const int kIncreaseAsyncScriptPriority = 0;
1063 const int kEnablePriorityIncrease = 0; 1088 const int kEnablePriorityIncrease = 0;
1064 const int kEnableLayoutBlockingThreshold = 0; 1089 const int kEnableLayoutBlockingThreshold = 0;
(...skipping 13 matching lines...) Expand all
1078 InitializeScheduler(); 1103 InitializeScheduler();
1079 1104
1080 // Only load low priority resources if there's a body. 1105 // Only load low priority resources if there's a body.
1081 scheduler()->OnWillInsertBody(kChildId, kRouteId); 1106 scheduler()->OnWillInsertBody(kChildId, kRouteId);
1082 1107
1083 // Queue requests from different hosts until the total limit is reached. 1108 // Queue requests from different hosts until the total limit is reached.
1084 ScopedVector<TestRequest> lows_different_host; 1109 ScopedVector<TestRequest> lows_different_host;
1085 for (int i = 0; i < kMaxNumDelayableRequestsPerClient; ++i) { 1110 for (int i = 0; i < kMaxNumDelayableRequestsPerClient; ++i) {
1086 string url = "http://host" + base::IntToString(i) + "/low"; 1111 string url = "http://host" + base::IntToString(i) + "/low";
1087 lows_different_host.push_back(NewRequest(url.c_str(), net::LOWEST)); 1112 lows_different_host.push_back(NewRequest(url.c_str(), net::LOWEST));
1088 EXPECT_TRUE(lows_different_host[i]->started()); 1113 EXPECT_TRUE(lows_different_host[i]->sent());
1089 } 1114 }
1090 1115
1091 scoped_ptr<TestRequest> last_different_host(NewRequest("http://host_new/last", 1116 scoped_ptr<TestRequest> last_different_host(NewRequest("http://host_new/last",
1092 net::LOWEST)); 1117 net::LOWEST));
1093 EXPECT_FALSE(last_different_host->started()); 1118 EXPECT_FALSE(last_different_host->sent());
1094 } 1119 }
1095 1120
1096 TEST_F(ResourceSchedulerTest, 1121 TEST_F(ResourceSchedulerTest,
1097 TwentyMaxNumDelayableRequestsPerClientWithEverythingEnabled) { 1122 TwentyMaxNumDelayableRequestsPerClientWithEverythingEnabled) {
1098 // Do not exceed 20 low-priority requests to be in flight across all hosts 1123 // Do not exceed 20 low-priority requests to be in flight across all hosts
1099 // at any point in time and make sure it still works correctly when the other 1124 // at any point in time and make sure it still works correctly when the other
1100 // options are toggled. 1125 // options are toggled.
1101 const int kDeferLateScripts = 1; 1126 const int kDeferLateScripts = 1;
1102 const int kIncreaseFontPriority = 1; 1127 const int kIncreaseFontPriority = 1;
1103 const int kIncreaseAsyncScriptPriority = 1; 1128 const int kIncreaseAsyncScriptPriority = 1;
(...skipping 15 matching lines...) Expand all
1119 InitializeScheduler(); 1144 InitializeScheduler();
1120 1145
1121 // Only load low priority resources if there's a body. 1146 // Only load low priority resources if there's a body.
1122 scheduler()->OnWillInsertBody(kChildId, kRouteId); 1147 scheduler()->OnWillInsertBody(kChildId, kRouteId);
1123 1148
1124 // Queue requests from different hosts until the total limit is reached. 1149 // Queue requests from different hosts until the total limit is reached.
1125 ScopedVector<TestRequest> lows_different_host; 1150 ScopedVector<TestRequest> lows_different_host;
1126 for (int i = 0; i < kMaxNumDelayableRequestsPerClient; ++i) { 1151 for (int i = 0; i < kMaxNumDelayableRequestsPerClient; ++i) {
1127 string url = "http://host" + base::IntToString(i) + "/low"; 1152 string url = "http://host" + base::IntToString(i) + "/low";
1128 lows_different_host.push_back(NewRequest(url.c_str(), net::LOWEST)); 1153 lows_different_host.push_back(NewRequest(url.c_str(), net::LOWEST));
1129 EXPECT_TRUE(lows_different_host[i]->started()); 1154 EXPECT_TRUE(lows_different_host[i]->sent());
1130 } 1155 }
1131 1156
1132 scoped_ptr<TestRequest> last_different_host(NewRequest("http://host_new/last", 1157 scoped_ptr<TestRequest> last_different_host(NewRequest("http://host_new/last",
1133 net::LOWEST)); 1158 net::LOWEST));
1134 EXPECT_FALSE(last_different_host->started()); 1159 EXPECT_FALSE(last_different_host->sent());
1135 } 1160 }
1136 1161
1137 } // unnamed namespace 1162 } // unnamed namespace
1138 1163
1139 } // namespace content 1164 } // 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