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 2301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2312 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); | 2312 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); |
2313 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); | 2313 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); |
2314 EXPECT_TRUE(high->started()); | 2314 EXPECT_TRUE(high->started()); |
2315 EXPECT_FALSE(low->started()); | 2315 EXPECT_FALSE(low->started()); |
2316 EXPECT_FALSE(low2->started()); | 2316 EXPECT_FALSE(low2->started()); |
2317 high.reset(); | 2317 high.reset(); |
2318 EXPECT_TRUE(low->started()); | 2318 EXPECT_TRUE(low->started()); |
2319 EXPECT_TRUE(low2->started()); | 2319 EXPECT_TRUE(low2->started()); |
2320 } | 2320 } |
2321 | 2321 |
| 2322 // Async revalidations which are not started when the tab is closed must be |
| 2323 // started at some point, or they will hang around forever and prevent other |
| 2324 // async revalidations to the same URL from being issued. |
| 2325 TEST_F(ResourceSchedulerTest, RequestStartedAfterClientDeleted) { |
| 2326 scheduler_->OnClientCreated(kChildId2, kRouteId2, false, false); |
| 2327 scoped_ptr<TestRequest> high(NewRequestWithChildAndRoute( |
| 2328 "http://host/high", net::HIGHEST, kChildId2, kRouteId2)); |
| 2329 scoped_ptr<TestRequest> lowest1(NewRequestWithChildAndRoute( |
| 2330 "http://host/lowest", net::LOWEST, kChildId2, kRouteId2)); |
| 2331 scoped_ptr<TestRequest> lowest2(NewRequestWithChildAndRoute( |
| 2332 "http://host/lowest", net::LOWEST, kChildId2, kRouteId2)); |
| 2333 EXPECT_FALSE(lowest2->started()); |
| 2334 scheduler_->OnClientDeleted(kChildId2, kRouteId2); |
| 2335 high.reset(); |
| 2336 lowest1.reset(); |
| 2337 EXPECT_TRUE(lowest2->started()); |
| 2338 } |
| 2339 |
| 2340 // The ResourceScheduler::Client destructor calls |
| 2341 // LoadAnyStartablePendingRequests(), which may start some pending requests. |
| 2342 // This test is to verify that requests will be started at some point |
| 2343 // even if they were not started by the destructor. |
| 2344 TEST_F(ResourceSchedulerTest, RequestStartedAfterClientDeletedManyDelayable) { |
| 2345 scheduler_->OnClientCreated(kChildId2, kRouteId2, false, false); |
| 2346 scoped_ptr<TestRequest> high(NewRequestWithChildAndRoute( |
| 2347 "http://host/high", net::HIGHEST, kChildId2, kRouteId2)); |
| 2348 const int kMaxNumDelayableRequestsPerClient = 10; |
| 2349 ScopedVector<TestRequest> delayable_requests; |
| 2350 for (int i = 0; i < kMaxNumDelayableRequestsPerClient + 1; ++i) { |
| 2351 delayable_requests.push_back(NewRequestWithChildAndRoute( |
| 2352 "http://host/lowest", net::LOWEST, kChildId2, kRouteId2)); |
| 2353 } |
| 2354 scoped_ptr<TestRequest> lowest(NewRequestWithChildAndRoute( |
| 2355 "http://host/lowest", net::LOWEST, kChildId2, kRouteId2)); |
| 2356 EXPECT_FALSE(lowest->started()); |
| 2357 scheduler_->OnClientDeleted(kChildId2, kRouteId2); |
| 2358 high.reset(); |
| 2359 delayable_requests.clear(); |
| 2360 EXPECT_TRUE(lowest->started()); |
| 2361 } |
| 2362 |
2322 } // unnamed namespace | 2363 } // unnamed namespace |
2323 | 2364 |
2324 } // namespace content | 2365 } // namespace content |
OLD | NEW |