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/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
377 EXPECT_TRUE(lowest->started()); | 377 EXPECT_TRUE(lowest->started()); |
378 EXPECT_FALSE(lowest2->started()); | 378 EXPECT_FALSE(lowest2->started()); |
379 scheduler()->OnWillInsertBody(kChildId, kRouteId); | 379 scheduler()->OnWillInsertBody(kChildId, kRouteId); |
380 EXPECT_TRUE(lowest2->started()); | 380 EXPECT_TRUE(lowest2->started()); |
381 } | 381 } |
382 | 382 |
383 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilBodyInsertedExceptSpdy) { | 383 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilBodyInsertedExceptSpdy) { |
384 http_server_properties_.SetSupportsSpdy( | 384 http_server_properties_.SetSupportsSpdy( |
385 net::HostPortPair("spdyhost", 443), true); | 385 net::HostPortPair("spdyhost", 443), true); |
386 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); | 386 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); |
387 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); | |
388 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); | |
387 scoped_ptr<TestRequest> low_spdy( | 389 scoped_ptr<TestRequest> low_spdy( |
388 NewRequest("https://spdyhost/low", net::LOWEST)); | 390 NewRequest("https://spdyhost/low", net::LOWEST)); |
389 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); | |
390 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); | |
391 EXPECT_TRUE(high->started()); | 391 EXPECT_TRUE(high->started()); |
392 EXPECT_TRUE(low_spdy->started()); | 392 EXPECT_TRUE(low_spdy->started()); |
393 EXPECT_TRUE(low->started()); | 393 EXPECT_TRUE(low->started()); |
394 EXPECT_FALSE(low2->started()); | 394 EXPECT_FALSE(low2->started()); |
395 scheduler()->OnWillInsertBody(kChildId, kRouteId); | 395 scheduler()->OnWillInsertBody(kChildId, kRouteId); |
396 high.reset(); | 396 high.reset(); |
397 EXPECT_TRUE(low2->started()); | 397 EXPECT_TRUE(low2->started()); |
398 } | 398 } |
399 | 399 |
400 TEST_F(ResourceSchedulerTest, NavigationResetsState) { | 400 TEST_F(ResourceSchedulerTest, NavigationResetsState) { |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
700 EXPECT_TRUE(low1->started()); | 700 EXPECT_TRUE(low1->started()); |
701 | 701 |
702 low1.reset(); | 702 low1.reset(); |
703 scoped_ptr<TestRequest> low2_spdy( | 703 scoped_ptr<TestRequest> low2_spdy( |
704 NewRequest("http://spdyhost2:8080/low", net::IDLE)); | 704 NewRequest("http://spdyhost2:8080/low", net::IDLE)); |
705 // Reprioritize a request after we learn the server supports SPDY. | 705 // Reprioritize a request after we learn the server supports SPDY. |
706 EXPECT_TRUE(low2_spdy->started()); | 706 EXPECT_TRUE(low2_spdy->started()); |
707 http_server_properties_.SetSupportsSpdy( | 707 http_server_properties_.SetSupportsSpdy( |
708 net::HostPortPair("spdyhost2", 8080), true); | 708 net::HostPortPair("spdyhost2", 8080), true); |
709 ChangeRequestPriority(low2_spdy.get(), net::LOWEST); | 709 ChangeRequestPriority(low2_spdy.get(), net::LOWEST); |
710 // Low priority in-flight requests on the SPDY connection are still considered | |
711 // delayable as far as the accounting goes and should still hold back the | |
712 // request on the non-spdy host. | |
710 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); | 713 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); |
711 EXPECT_TRUE(low2->started()); | 714 EXPECT_FALSE(low2->started()); |
712 } | 715 } |
713 | 716 |
714 TEST_F(ResourceSchedulerTest, ThrottledClientCreation) { | 717 TEST_F(ResourceSchedulerTest, ThrottledClientCreation) { |
715 // TODO(aiolos): remove when throttling and coalescing have both landed | 718 // TODO(aiolos): remove when throttling and coalescing have both landed |
716 scheduler()->SetThrottleOptionsForTesting(true /* should_throttle */, | 719 scheduler()->SetThrottleOptionsForTesting(true /* should_throttle */, |
717 false /* should_coalesce */); | 720 false /* should_coalesce */); |
718 EXPECT_TRUE(scheduler()->should_throttle()); | 721 EXPECT_TRUE(scheduler()->should_throttle()); |
719 scheduler()->OnClientCreated( | 722 scheduler()->OnClientCreated( |
720 kBackgroundChildId2, kBackgroundRouteId2, false, false); | 723 kBackgroundChildId2, kBackgroundRouteId2, false, false); |
721 | 724 |
(...skipping 1631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2353 } | 2356 } |
2354 scoped_ptr<TestRequest> lowest(NewRequestWithChildAndRoute( | 2357 scoped_ptr<TestRequest> lowest(NewRequestWithChildAndRoute( |
2355 "http://host/lowest", net::LOWEST, kChildId2, kRouteId2)); | 2358 "http://host/lowest", net::LOWEST, kChildId2, kRouteId2)); |
2356 EXPECT_FALSE(lowest->started()); | 2359 EXPECT_FALSE(lowest->started()); |
2357 scheduler_->OnClientDeleted(kChildId2, kRouteId2); | 2360 scheduler_->OnClientDeleted(kChildId2, kRouteId2); |
2358 high.reset(); | 2361 high.reset(); |
2359 delayable_requests.clear(); | 2362 delayable_requests.clear(); |
2360 EXPECT_TRUE(lowest->started()); | 2363 EXPECT_TRUE(lowest->started()); |
2361 } | 2364 } |
2362 | 2365 |
2366 TEST_F(ResourceSchedulerTest, DefaultLayoutBlockingPriority) { | |
2367 const int kEnablePriorityIncrease = 0; | |
2368 ASSERT_TRUE(InitializeFieldTrials( | |
2369 base::StringPrintf("ResourcePriorities/LayoutBlocking_000%d0_0_1_10/", | |
mmenke
2015/08/11 19:27:28
Why the terminal slash on group names here? The t
Pat Meenan
2015/08/12 16:21:00
The other file didn't use the command-line parsing
| |
2370 kEnablePriorityIncrease))); | |
2371 InitializeScheduler(); | |
2372 scoped_ptr<TestRequest> high( | |
2373 NewRequest("http://hosthigh/high", net::HIGHEST)); | |
2374 scoped_ptr<TestRequest> high2( | |
2375 NewRequest("http://hosthigh/high", net::HIGHEST)); | |
2376 scoped_ptr<TestRequest> medium( | |
2377 NewRequest("http://hostmedium/medium", net::MEDIUM)); | |
2378 scoped_ptr<TestRequest> medium2( | |
2379 NewRequest("http://hostmedium/medium", net::MEDIUM)); | |
2380 scoped_ptr<TestRequest> low(NewRequest("http://hostlow/low", net::LOW)); | |
2381 scoped_ptr<TestRequest> low2(NewRequest("http://hostlow/low", net::LOW)); | |
2382 scoped_ptr<TestRequest> lowest(NewRequest("http://hostlowest/lowest", net::LOW EST)); | |
2383 scoped_ptr<TestRequest> lowest2( | |
2384 NewRequest("http://hostlowest/lowest", net::LOWEST)); | |
2385 EXPECT_TRUE(high->started()); | |
2386 EXPECT_TRUE(high2->started()); | |
2387 EXPECT_TRUE(medium->started()); | |
2388 EXPECT_TRUE(medium2->started()); | |
2389 EXPECT_TRUE(low->started()); | |
2390 EXPECT_TRUE(low2->started()); | |
2391 EXPECT_TRUE(lowest->started()); | |
2392 EXPECT_FALSE(lowest2->started()); | |
2393 lowest.reset(); | |
2394 EXPECT_TRUE(lowest2->started()); | |
2395 } | |
2396 | |
2397 TEST_F(ResourceSchedulerTest, IncreaseLayoutBlockingPriority) { | |
2398 // Changes the level of priorities that are allowed during layout-blocking | |
2399 // from net::LOWEST to net::LOW. | |
2400 const int kEnablePriorityIncrease = 1; | |
mmenke
2015/08/11 19:27:28
Suggest giving the value of all relevant variables
Pat Meenan
2015/08/12 16:21:00
Done.
| |
2401 ASSERT_TRUE(InitializeFieldTrials( | |
2402 base::StringPrintf("ResourcePriorities/LayoutBlocking_000%d0_0_1_10/", | |
2403 kEnablePriorityIncrease))); | |
2404 InitializeScheduler(); | |
2405 scoped_ptr<TestRequest> high( | |
2406 NewRequest("http://hosthigh/high", net::HIGHEST)); | |
2407 scoped_ptr<TestRequest> high2( | |
2408 NewRequest("http://hosthigh/high", net::HIGHEST)); | |
2409 scoped_ptr<TestRequest> medium( | |
2410 NewRequest("http://hostmedium/medium", net::MEDIUM)); | |
2411 scoped_ptr<TestRequest> medium2( | |
2412 NewRequest("http://hostmedium/medium", net::MEDIUM)); | |
2413 scoped_ptr<TestRequest> low(NewRequest("http://hostlow/low", net::LOW)); | |
2414 scoped_ptr<TestRequest> low2(NewRequest("http://hostlow/low", net::LOW)); | |
2415 scoped_ptr<TestRequest> lowest(NewRequest("http://hostlowest/lowest", net::LOW EST)); | |
2416 scoped_ptr<TestRequest> lowest2( | |
2417 NewRequest("http://hostlowest/lowest", net::LOWEST)); | |
2418 EXPECT_TRUE(high->started()); | |
2419 EXPECT_TRUE(high2->started()); | |
2420 EXPECT_TRUE(medium->started()); | |
2421 EXPECT_TRUE(medium2->started()); | |
2422 EXPECT_TRUE(low->started()); | |
2423 EXPECT_FALSE(low2->started()); | |
2424 EXPECT_FALSE(lowest->started()); | |
2425 EXPECT_FALSE(lowest2->started()); | |
2426 low.reset(); | |
2427 EXPECT_TRUE(low2->started()); | |
2428 EXPECT_FALSE(lowest->started()); | |
2429 EXPECT_FALSE(lowest2->started()); | |
2430 low2.reset(); | |
2431 EXPECT_TRUE(lowest->started()); | |
2432 EXPECT_FALSE(lowest2->started()); | |
2433 lowest.reset(); | |
2434 EXPECT_TRUE(lowest2->started()); | |
2435 } | |
2436 | |
2437 TEST_F(ResourceSchedulerTest, UseLayoutBlockingThresholdOne) { | |
2438 // Prevents anly low priority requests from starting while more than | |
mmenke
2015/08/11 19:27:28
anly -> any
Pat Meenan
2015/08/12 16:21:00
Done.
| |
2439 // N high priority requests are pending (before body). | |
2440 const int kLayoutBlockingThreshold = 1; | |
2441 ASSERT_TRUE(InitializeFieldTrials( | |
2442 base::StringPrintf("ResourcePriorities/LayoutBlocking_00001_%d_1_10/", | |
2443 kLayoutBlockingThreshold))); | |
2444 InitializeScheduler(); | |
2445 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); | |
2446 scoped_ptr<TestRequest> high2(NewRequest("http://host/high", net::HIGHEST)); | |
2447 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); | |
2448 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); | |
2449 EXPECT_TRUE(high->started()); | |
2450 EXPECT_TRUE(high2->started()); | |
2451 EXPECT_FALSE(low->started()); | |
2452 EXPECT_FALSE(low2->started()); | |
2453 high.reset(); | |
2454 EXPECT_TRUE(low->started()); | |
2455 EXPECT_FALSE(low2->started()); | |
2456 high2.reset(); | |
mmenke
2015/08/11 19:27:28
EXPECT_FALSE(low2->started()); .... At least I th
Pat Meenan
2015/08/12 16:21:00
Done.
| |
2457 scheduler()->OnWillInsertBody(kChildId, kRouteId); | |
2458 EXPECT_TRUE(low2->started()); | |
2459 } | |
2460 | |
2461 TEST_F(ResourceSchedulerTest, UseLayoutBlockingThresholdTwo) { | |
2462 // Prevents anly low priority requests from starting while more than | |
mmenke
2015/08/11 19:27:28
any
Pat Meenan
2015/08/12 16:21:00
Done.
| |
2463 // N high priority requests are pending (before body). | |
2464 const int kLayoutBlockingThreshold = 2; | |
2465 ASSERT_TRUE(InitializeFieldTrials( | |
2466 base::StringPrintf("ResourcePriorities/LayoutBlockingTwo_00001_%d_1_10/", | |
2467 kLayoutBlockingThreshold))); | |
2468 InitializeScheduler(); | |
2469 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); | |
2470 scoped_ptr<TestRequest> high2(NewRequest("http://host/high", net::HIGHEST)); | |
2471 scoped_ptr<TestRequest> high3(NewRequest("http://host/high", net::HIGHEST)); | |
2472 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); | |
2473 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); | |
2474 EXPECT_TRUE(high->started()); | |
2475 EXPECT_TRUE(high2->started()); | |
2476 EXPECT_TRUE(high3->started()); | |
2477 EXPECT_FALSE(low->started()); | |
2478 EXPECT_FALSE(low2->started()); | |
2479 high.reset(); | |
2480 EXPECT_TRUE(low->started()); | |
2481 EXPECT_FALSE(low2->started()); | |
2482 high2.reset(); | |
2483 high3.reset(); | |
mmenke
2015/08/11 19:27:28
Again, should have EXPECT here for low2.
Pat Meenan
2015/08/12 16:21:00
Done.
| |
2484 scheduler()->OnWillInsertBody(kChildId, kRouteId); | |
2485 EXPECT_TRUE(low2->started()); | |
2486 } | |
2487 | |
2488 TEST_F(ResourceSchedulerTest, IncreaseLowLoadsUntilBodyInserted) { | |
mmenke
2015/08/11 19:27:28
I think TwoDelayableLoadsUntilBodyInserted would b
Pat Meenan
2015/08/12 16:21:00
Done.
| |
2489 const int kMaxNumDelayableWhileLayoutBlocking = 2; | |
2490 ASSERT_TRUE(InitializeFieldTrials( | |
2491 base::StringPrintf("ResourcePriorities/IncreaseLow_00000_0_%d_10/", | |
2492 kMaxNumDelayableWhileLayoutBlocking))); | |
mmenke
2015/08/11 19:27:28
Any reason why the last 3 have no text describing
Pat Meenan
2015/08/12 16:21:00
No good reason - just added a comment explaining t
| |
2493 InitializeScheduler(); | |
2494 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); | |
2495 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); | |
2496 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); | |
2497 scoped_ptr<TestRequest> low3(NewRequest("http://host/low", net::LOWEST)); | |
2498 EXPECT_TRUE(high->started()); | |
2499 EXPECT_TRUE(low->started()); | |
2500 EXPECT_TRUE(low2->started()); | |
2501 EXPECT_FALSE(low3->started()); | |
2502 high.reset(); | |
2503 scheduler()->OnWillInsertBody(kChildId, kRouteId); | |
2504 EXPECT_TRUE(low3->started()); | |
2505 } | |
2506 | |
2507 TEST_F(ResourceSchedulerTest, IncreaseLowLoadsUntilBodyInsertedLayoutBlocking) { | |
mmenke
2015/08/11 19:27:28
UseLayoutBlockingThresholdOneAndTwoDelayableLoadsU
Pat Meenan
2015/08/12 16:21:00
Done.
| |
2508 const int kLayoutBlockingThreshold = 1; | |
2509 const int kMaxNumDelayableWhileLayoutBlocking = 2; | |
2510 ASSERT_TRUE(InitializeFieldTrials( | |
2511 base::StringPrintf("ResourcePriorities/IncreaseLow_00001_%d_%d_10/", | |
2512 kLayoutBlockingThreshold, | |
2513 kMaxNumDelayableWhileLayoutBlocking))); | |
2514 InitializeScheduler(); | |
2515 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); | |
2516 scoped_ptr<TestRequest> high2(NewRequest("http://host/high", net::HIGHEST)); | |
2517 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); | |
2518 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); | |
2519 scoped_ptr<TestRequest> low3(NewRequest("http://host/low", net::LOWEST)); | |
2520 EXPECT_TRUE(high->started()); | |
2521 EXPECT_TRUE(high2->started()); | |
2522 EXPECT_FALSE(low->started()); | |
2523 EXPECT_FALSE(low2->started()); | |
2524 EXPECT_FALSE(low3->started()); | |
2525 high.reset(); | |
2526 EXPECT_TRUE(low->started()); | |
2527 EXPECT_TRUE(low2->started()); | |
2528 EXPECT_FALSE(low3->started()); | |
2529 high2.reset(); | |
2530 scheduler()->OnWillInsertBody(kChildId, kRouteId); | |
2531 EXPECT_TRUE(low3->started()); | |
2532 } | |
2533 | |
2534 TEST_F(ResourceSchedulerTest, IncreaseMaxNumDelayableRequestsPerClient) { | |
2535 const int kMaxNumDelayableRequestsPerClient = 25; | |
2536 ASSERT_TRUE(InitializeFieldTrials( | |
2537 base::StringPrintf("ResourcePriorities/IncreaseDelayable_00000_0_1_%d/", | |
2538 kMaxNumDelayableRequestsPerClient))); | |
mmenke
2015/08/11 19:27:28
Should we have another simple test that checks the
Pat Meenan
2015/08/12 16:21:00
Done.
| |
2539 InitializeScheduler(); | |
2540 | |
2541 // We only load low priority resources if there's a body. | |
mmenke
2015/08/11 19:27:28
nit: Avoid using "we" in comments.
Pat Meenan
2015/08/12 16:21:00
Done.
| |
2542 scheduler()->OnWillInsertBody(kChildId, kRouteId); | |
2543 | |
2544 // Queue requests from different hosts until we reach the total limit. | |
2545 ScopedVector<TestRequest> lows_differenthosts; | |
2546 for (int i = 0; i < kMaxNumDelayableRequestsPerClient; ++i) { | |
2547 string url = "http://host" + base::IntToString(i) + "/low"; | |
2548 lows_differenthosts.push_back(NewRequest(url.c_str(), net::LOWEST)); | |
2549 EXPECT_TRUE(lows_differenthosts[i]->started()); | |
2550 } | |
2551 | |
2552 scoped_ptr<TestRequest> last_differenthost(NewRequest("http://host_new/last", | |
2553 net::LOWEST)); | |
2554 EXPECT_FALSE(last_differenthost->started()); | |
2555 } | |
2556 | |
2363 } // unnamed namespace | 2557 } // unnamed namespace |
2364 | 2558 |
2365 } // namespace content | 2559 } // namespace content |
OLD | NEW |