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

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

Issue 12600018: ResourceScheduler should use renderer notifications instead of MRUCache to track renderers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reverse destruction order Created 7 years, 9 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 | Annotate | Revision Log
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 "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "content/browser/browser_thread_impl.h" 8 #include "content/browser/browser_thread_impl.h"
9 #include "content/browser/loader/resource_dispatcher_host_impl.h" 9 #include "content/browser/loader/resource_dispatcher_host_impl.h"
10 #include "content/browser/loader/resource_request_info_impl.h" 10 #include "content/browser/loader/resource_request_info_impl.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } 73 }
74 74
75 scoped_ptr<TestRequest> request_to_cancel_; 75 scoped_ptr<TestRequest> request_to_cancel_;
76 }; 76 };
77 77
78 class ResourceSchedulerTest : public testing::Test { 78 class ResourceSchedulerTest : public testing::Test {
79 protected: 79 protected:
80 ResourceSchedulerTest() 80 ResourceSchedulerTest()
81 : message_loop_(MessageLoop::TYPE_IO), 81 : message_loop_(MessageLoop::TYPE_IO),
82 ui_thread_(BrowserThread::UI, &message_loop_) { 82 ui_thread_(BrowserThread::UI, &message_loop_) {
83 scheduler_.OnNavigate(kChildId, kRouteId); 83 scheduler_.OnClientCreated(kChildId, kRouteId);
84 } 84 }
85 85
86 virtual ~ResourceSchedulerTest() { 86 virtual ~ResourceSchedulerTest() {
87 scheduler_.OnClientDeleted(kChildId, kRouteId);
87 } 88 }
88 89
89 scoped_ptr<net::URLRequest> NewURLRequest(const char* url, 90 scoped_ptr<net::URLRequest> NewURLRequest(const char* url,
90 net::RequestPriority priority, 91 net::RequestPriority priority,
91 int route_id = kRouteId) { 92 int route_id = kRouteId) {
92 scoped_ptr<net::URLRequest> url_request( 93 scoped_ptr<net::URLRequest> url_request(
93 context_.CreateRequest(GURL(url), NULL)); 94 context_.CreateRequest(GURL(url), NULL));
94 url_request->set_priority(priority); 95 url_request->set_priority(priority);
95 ResourceRequestInfo::AllocateForTesting( 96 ResourceRequestInfo::AllocateForTesting(
96 url_request.get(), ResourceType::SUB_RESOURCE, NULL, kChildId, 97 url_request.get(), ResourceType::SUB_RESOURCE, NULL, kChildId,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 162 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
162 EXPECT_TRUE(high1->started()); 163 EXPECT_TRUE(high1->started());
163 EXPECT_TRUE(high2->started()); 164 EXPECT_TRUE(high2->started());
164 EXPECT_FALSE(low->started()); 165 EXPECT_FALSE(low->started());
165 high1.reset(); 166 high1.reset();
166 EXPECT_FALSE(low->started()); 167 EXPECT_FALSE(low->started());
167 high2.reset(); 168 high2.reset();
168 EXPECT_TRUE(low->started()); 169 EXPECT_TRUE(low->started());
169 } 170 }
170 171
171 TEST_F(ResourceSchedulerTest, EvictedClientsIssuePendingRequests) {
172 ScopedVector<TestRequest> low_requests;
173 ScopedVector<TestRequest> high_requests;
174 for (int i = 0; i < 6; i++) {
175 scheduler_.OnNavigate(kChildId, kRouteId + i);
176 high_requests.push_back(
177 NewRequest("http://host/i", net::HIGHEST, kRouteId + i));
178 low_requests.push_back(
179 NewRequest("http://host/i", net::LOWEST, kRouteId + i));
180 EXPECT_FALSE(low_requests[i]->started());
181 }
182 EXPECT_TRUE(low_requests[0]->started());
183 }
184
185 TEST_F(ResourceSchedulerTest, CancelOtherRequestsWhileResuming) { 172 TEST_F(ResourceSchedulerTest, CancelOtherRequestsWhileResuming) {
186 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 173 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
187 scoped_ptr<TestRequest> low1(NewRequest("http://host/low1", net::LOWEST)); 174 scoped_ptr<TestRequest> low1(NewRequest("http://host/low1", net::LOWEST));
188 175
189 scoped_ptr<net::URLRequest> url_request( 176 scoped_ptr<net::URLRequest> url_request(
190 NewURLRequest("http://host/low2", net::LOWEST)); 177 NewURLRequest("http://host/low2", net::LOWEST));
191 scoped_ptr<ResourceThrottle> throttle(scheduler_.ScheduleRequest( 178 scoped_ptr<ResourceThrottle> throttle(scheduler_.ScheduleRequest(
192 kChildId, kRouteId, url_request.get())); 179 kChildId, kRouteId, url_request.get()));
193 scoped_ptr<CancelingTestRequest> low2(new CancelingTestRequest( 180 scoped_ptr<CancelingTestRequest> low2(new CancelingTestRequest(
194 throttle.Pass(), url_request.Pass())); 181 throttle.Pass(), url_request.Pass()));
195 low2->Start(); 182 low2->Start();
196 183
197 scoped_ptr<TestRequest> low3(NewRequest("http://host/low3", net::LOWEST)); 184 scoped_ptr<TestRequest> low3(NewRequest("http://host/low3", net::LOWEST));
198 low2->set_request_to_cancel(low3.Pass()); 185 low2->set_request_to_cancel(low3.Pass());
199 scoped_ptr<TestRequest> low4(NewRequest("http://host/low4", net::LOWEST)); 186 scoped_ptr<TestRequest> low4(NewRequest("http://host/low4", net::LOWEST));
200 187
201 EXPECT_TRUE(high->started()); 188 EXPECT_TRUE(high->started());
202 EXPECT_FALSE(low2->started()); 189 EXPECT_FALSE(low2->started());
203 high.reset(); 190 high.reset();
204 EXPECT_TRUE(low1->started()); 191 EXPECT_TRUE(low1->started());
205 EXPECT_TRUE(low2->started()); 192 EXPECT_TRUE(low2->started());
206 EXPECT_TRUE(low4->started()); 193 EXPECT_TRUE(low4->started());
207 } 194 }
208 195
209 } // unnamed namespace 196 } // unnamed namespace
210 197
211 } // namespace content 198 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_scheduler.cc ('k') | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698