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

Side by Side Diff: chrome/browser/prerender/prerender_manager_unittest.cc

Issue 7210020: Added prerendering to omnibox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 9 years, 6 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/memory/scoped_vector.h" 5 #include "base/memory/scoped_vector.h"
6 #include "base/time.h" 6 #include "base/time.h"
7 #include "chrome/browser/prerender/prerender_contents.h" 7 #include "chrome/browser/prerender/prerender_contents.h"
8 #include "chrome/browser/prerender/prerender_manager.h" 8 #include "chrome/browser/prerender/prerender_manager.h"
9 #include "chrome/browser/prerender/prerender_origin.h"
9 #include "chrome/test/testing_browser_process.h" 10 #include "chrome/test/testing_browser_process.h"
10 #include "content/browser/browser_thread.h" 11 #include "content/browser/browser_thread.h"
11 #include "content/browser/renderer_host/render_view_host.h" 12 #include "content/browser/renderer_host/render_view_host.h"
12 #include "content/browser/renderer_host/render_process_host.h" 13 #include "content/browser/renderer_host/render_process_host.h"
13 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 namespace prerender { 17 namespace prerender {
17 18
18 namespace { 19 namespace {
19 20
20 class DummyPrerenderContents : public PrerenderContents { 21 class DummyPrerenderContents : public PrerenderContents {
21 public: 22 public:
22 DummyPrerenderContents(PrerenderManager* prerender_manager, 23 DummyPrerenderContents(PrerenderManager* prerender_manager,
23 PrerenderTracker* prerender_tracker, 24 PrerenderTracker* prerender_tracker,
24 const GURL& url, 25 const GURL& url,
25 FinalStatus expected_final_status) 26 FinalStatus expected_final_status)
26 : PrerenderContents(prerender_manager, prerender_tracker, NULL, url, 27 : PrerenderContents(prerender_manager, prerender_tracker, NULL, url,
27 GURL()), 28 GURL(), ORIGIN_LINK_REL_PRERENDER),
28 has_started_(false), 29 has_started_(false),
29 expected_final_status_(expected_final_status) { 30 expected_final_status_(expected_final_status) {
30 } 31 }
31 32
32 virtual ~DummyPrerenderContents() { 33 virtual ~DummyPrerenderContents() {
33 EXPECT_EQ(expected_final_status_, final_status()); 34 EXPECT_EQ(expected_final_status_, final_status());
34 } 35 }
35 36
36 virtual void StartPrerendering( 37 virtual void StartPrerendering(
37 const RenderViewHost* source_render_view_host) OVERRIDE { 38 const RenderViewHost* source_render_view_host) OVERRIDE {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 expected_final_status); 112 expected_final_status);
112 for (std::vector<GURL>::const_iterator it = alias_urls.begin(); 113 for (std::vector<GURL>::const_iterator it = alias_urls.begin();
113 it != alias_urls.end(); 114 it != alias_urls.end();
114 ++it) { 115 ++it) {
115 EXPECT_TRUE(prerender_contents->AddAliasURL(*it)); 116 EXPECT_TRUE(prerender_contents->AddAliasURL(*it));
116 } 117 }
117 SetNextPrerenderContents(prerender_contents); 118 SetNextPrerenderContents(prerender_contents);
118 return prerender_contents; 119 return prerender_contents;
119 } 120 }
120 121
121 // Shorthand to add a simple preload with no aliases. 122 // Shorthand to add a simple preload with a reasonable source.
122 bool AddSimplePreload(const GURL& url) { 123 bool AddSimplePrerender(const GURL& url) {
123 return AddPreload(std::pair<int, int>(-1, -1), url, GURL()); 124 return AddPrerender(ORIGIN_LINK_REL_PRERENDER, url);
124 } 125 }
125 126
126 bool IsPendingEntry(const GURL& url) { 127 bool IsPendingEntry(const GURL& url) {
127 return (PrerenderManager::FindPendingEntry(url) != NULL); 128 return (PrerenderManager::FindPendingEntry(url) != NULL);
128 } 129 }
129 130
130 void set_rate_limit_enabled(bool enabled) { rate_limit_enabled_ = true; } 131 void set_rate_limit_enabled(bool enabled) { rate_limit_enabled_ = true; }
131 132
132 PrerenderContents* next_prerender_contents() { 133 PrerenderContents* next_prerender_contents() {
133 return next_prerender_contents_.get(); 134 return next_prerender_contents_.get();
(...skipping 10 matching lines...) Expand all
144 virtual base::Time GetCurrentTime() const OVERRIDE { 145 virtual base::Time GetCurrentTime() const OVERRIDE {
145 return time_; 146 return time_;
146 } 147 }
147 148
148 virtual base::TimeTicks GetCurrentTimeTicks() const OVERRIDE { 149 virtual base::TimeTicks GetCurrentTimeTicks() const OVERRIDE {
149 return time_ticks_; 150 return time_ticks_;
150 } 151 }
151 152
152 virtual PrerenderContents* CreatePrerenderContents( 153 virtual PrerenderContents* CreatePrerenderContents(
153 const GURL& url, 154 const GURL& url,
154 const GURL& referrer) OVERRIDE { 155 const GURL& referrer,
156 Origin origin) OVERRIDE {
155 DCHECK(next_prerender_contents_.get()); 157 DCHECK(next_prerender_contents_.get());
156 return next_prerender_contents_.release(); 158 return next_prerender_contents_.release();
157 } 159 }
158 160
159 base::Time time_; 161 base::Time time_;
160 base::TimeTicks time_ticks_; 162 base::TimeTicks time_ticks_;
161 scoped_ptr<PrerenderContents> next_prerender_contents_; 163 scoped_ptr<PrerenderContents> next_prerender_contents_;
162 // PrerenderContents with an |expected_final_status| of FINAL_STATUS_USED, 164 // PrerenderContents with an |expected_final_status| of FINAL_STATUS_USED,
163 // tracked so they will be automatically deleted. 165 // tracked so they will be automatically deleted.
164 ScopedVector<PrerenderContents> used_prerender_contents_; 166 ScopedVector<PrerenderContents> used_prerender_contents_;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 198
197 // Needed to pass PrerenderManager's DCHECKs. 199 // Needed to pass PrerenderManager's DCHECKs.
198 ScopedTestingBrowserProcess browser_process_; 200 ScopedTestingBrowserProcess browser_process_;
199 MessageLoop message_loop_; 201 MessageLoop message_loop_;
200 BrowserThread ui_thread_; 202 BrowserThread ui_thread_;
201 scoped_ptr<TestPrerenderManager> prerender_manager_; 203 scoped_ptr<TestPrerenderManager> prerender_manager_;
202 }; 204 };
203 205
204 TEST_F(PrerenderManagerTest, EmptyTest) { 206 TEST_F(PrerenderManagerTest, EmptyTest) {
205 GURL url("http://www.google.com/"); 207 GURL url("http://www.google.com/");
206 EXPECT_FALSE(prerender_manager()->MaybeUsePreloadedPage(NULL, url, false)); 208 EXPECT_FALSE(prerender_manager()->MaybeUsePrerenderedPage(NULL, url, false));
207 } 209 }
208 210
209 TEST_F(PrerenderManagerTest, FoundTest) { 211 TEST_F(PrerenderManagerTest, FoundTest) {
210 GURL url("http://www.google.com/"); 212 GURL url("http://www.google.com/");
211 DummyPrerenderContents* prerender_contents = 213 DummyPrerenderContents* prerender_contents =
212 prerender_manager()->CreateNextPrerenderContents( 214 prerender_manager()->CreateNextPrerenderContents(
213 url, 215 url,
214 FINAL_STATUS_USED); 216 FINAL_STATUS_USED);
215 EXPECT_TRUE(prerender_manager()->AddSimplePreload(url)); 217 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url));
216 EXPECT_TRUE(prerender_contents->has_started()); 218 EXPECT_TRUE(prerender_contents->has_started());
217 ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(url)); 219 ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(url));
218 } 220 }
219 221
220 // Make sure that if queue a request, and a second prerender request for the 222 // Make sure that if queue a request, and a second prerender request for the
221 // same URL comes in, that we drop the second request and keep the first one. 223 // same URL comes in, that we drop the second request and keep the first one.
222 TEST_F(PrerenderManagerTest, DropSecondRequestTest) { 224 TEST_F(PrerenderManagerTest, DropSecondRequestTest) {
223 GURL url("http://www.google.com/"); 225 GURL url("http://www.google.com/");
224 DummyPrerenderContents* prerender_contents = 226 DummyPrerenderContents* prerender_contents =
225 prerender_manager()->CreateNextPrerenderContents( 227 prerender_manager()->CreateNextPrerenderContents(
226 url, 228 url,
227 FINAL_STATUS_USED); 229 FINAL_STATUS_USED);
228 DummyPrerenderContents* null = NULL; 230 DummyPrerenderContents* null = NULL;
229 EXPECT_TRUE(prerender_manager()->AddSimplePreload(url)); 231 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url));
230 EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); 232 EXPECT_EQ(null, prerender_manager()->next_prerender_contents());
231 EXPECT_TRUE(prerender_contents->has_started()); 233 EXPECT_TRUE(prerender_contents->has_started());
232 234
233 DummyPrerenderContents* prerender_contents1 = 235 DummyPrerenderContents* prerender_contents1 =
234 prerender_manager()->CreateNextPrerenderContents( 236 prerender_manager()->CreateNextPrerenderContents(
235 url, 237 url,
236 FINAL_STATUS_MANAGER_SHUTDOWN); 238 FINAL_STATUS_MANAGER_SHUTDOWN);
237 EXPECT_FALSE(prerender_manager()->AddSimplePreload(url)); 239 EXPECT_FALSE(prerender_manager()->AddSimplePrerender(url));
238 EXPECT_EQ(prerender_contents1, 240 EXPECT_EQ(prerender_contents1,
239 prerender_manager()->next_prerender_contents()); 241 prerender_manager()->next_prerender_contents());
240 EXPECT_FALSE(prerender_contents1->has_started()); 242 EXPECT_FALSE(prerender_contents1->has_started());
241 243
242 ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(url)); 244 ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(url));
243 } 245 }
244 246
245 // Ensure that we expire a prerendered page after the max. permitted time. 247 // Ensure that we expire a prerendered page after the max. permitted time.
246 TEST_F(PrerenderManagerTest, ExpireTest) { 248 TEST_F(PrerenderManagerTest, ExpireTest) {
247 GURL url("http://www.google.com/"); 249 GURL url("http://www.google.com/");
248 DummyPrerenderContents* prerender_contents = 250 DummyPrerenderContents* prerender_contents =
249 prerender_manager()->CreateNextPrerenderContents( 251 prerender_manager()->CreateNextPrerenderContents(
250 url, 252 url,
251 FINAL_STATUS_TIMED_OUT); 253 FINAL_STATUS_TIMED_OUT);
252 DummyPrerenderContents* null = NULL; 254 DummyPrerenderContents* null = NULL;
253 EXPECT_TRUE(prerender_manager()->AddSimplePreload(url)); 255 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url));
254 EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); 256 EXPECT_EQ(null, prerender_manager()->next_prerender_contents());
255 EXPECT_TRUE(prerender_contents->has_started()); 257 EXPECT_TRUE(prerender_contents->has_started());
256 prerender_manager()->AdvanceTime(prerender_manager()->max_prerender_age() 258 prerender_manager()->AdvanceTime(prerender_manager()->max_prerender_age()
257 + base::TimeDelta::FromSeconds(1)); 259 + base::TimeDelta::FromSeconds(1));
258 ASSERT_EQ(null, prerender_manager()->GetEntry(url)); 260 ASSERT_EQ(null, prerender_manager()->GetEntry(url));
259 } 261 }
260 262
261 // LRU Test. Make sure that if we prerender more than one request, that 263 // LRU Test. Make sure that if we prerender more than one request, that
262 // the oldest one will be dropped. 264 // the oldest one will be dropped.
263 TEST_F(PrerenderManagerTest, DropOldestRequestTest) { 265 TEST_F(PrerenderManagerTest, DropOldestRequestTest) {
264 GURL url("http://www.google.com/"); 266 GURL url("http://www.google.com/");
265 DummyPrerenderContents* prerender_contents = 267 DummyPrerenderContents* prerender_contents =
266 prerender_manager()->CreateNextPrerenderContents( 268 prerender_manager()->CreateNextPrerenderContents(
267 url, 269 url,
268 FINAL_STATUS_EVICTED); 270 FINAL_STATUS_EVICTED);
269 DummyPrerenderContents* null = NULL; 271 DummyPrerenderContents* null = NULL;
270 EXPECT_TRUE(prerender_manager()->AddSimplePreload(url)); 272 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url));
271 EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); 273 EXPECT_EQ(null, prerender_manager()->next_prerender_contents());
272 EXPECT_TRUE(prerender_contents->has_started()); 274 EXPECT_TRUE(prerender_contents->has_started());
273 275
274 GURL url1("http://news.google.com/"); 276 GURL url1("http://news.google.com/");
275 DummyPrerenderContents* prerender_contents1 = 277 DummyPrerenderContents* prerender_contents1 =
276 prerender_manager()->CreateNextPrerenderContents( 278 prerender_manager()->CreateNextPrerenderContents(
277 url1, 279 url1,
278 FINAL_STATUS_USED); 280 FINAL_STATUS_USED);
279 EXPECT_TRUE(prerender_manager()->AddSimplePreload(url1)); 281 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url1));
280 EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); 282 EXPECT_EQ(null, prerender_manager()->next_prerender_contents());
281 EXPECT_TRUE(prerender_contents1->has_started()); 283 EXPECT_TRUE(prerender_contents1->has_started());
282 284
283 ASSERT_EQ(null, prerender_manager()->GetEntry(url)); 285 ASSERT_EQ(null, prerender_manager()->GetEntry(url));
284 ASSERT_EQ(prerender_contents1, prerender_manager()->GetEntry(url1)); 286 ASSERT_EQ(prerender_contents1, prerender_manager()->GetEntry(url1));
285 } 287 }
286 288
287 // Two element prerender test. Ensure that the LRU operates correctly if we 289 // Two element prerender test. Ensure that the LRU operates correctly if we
288 // permit 2 elements to be kept prerendered. 290 // permit 2 elements to be kept prerendered.
289 TEST_F(PrerenderManagerTest, TwoElementPrerenderTest) { 291 TEST_F(PrerenderManagerTest, TwoElementPrerenderTest) {
290 prerender_manager()->set_max_elements(2); 292 prerender_manager()->set_max_elements(2);
291 GURL url("http://www.google.com/"); 293 GURL url("http://www.google.com/");
292 DummyPrerenderContents* prerender_contents = 294 DummyPrerenderContents* prerender_contents =
293 prerender_manager()->CreateNextPrerenderContents( 295 prerender_manager()->CreateNextPrerenderContents(
294 url, 296 url,
295 FINAL_STATUS_EVICTED); 297 FINAL_STATUS_EVICTED);
296 DummyPrerenderContents* null = NULL; 298 DummyPrerenderContents* null = NULL;
297 EXPECT_TRUE(prerender_manager()->AddSimplePreload(url)); 299 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url));
298 EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); 300 EXPECT_EQ(null, prerender_manager()->next_prerender_contents());
299 EXPECT_TRUE(prerender_contents->has_started()); 301 EXPECT_TRUE(prerender_contents->has_started());
300 302
301 GURL url1("http://news.google.com/"); 303 GURL url1("http://news.google.com/");
302 DummyPrerenderContents* prerender_contents1 = 304 DummyPrerenderContents* prerender_contents1 =
303 prerender_manager()->CreateNextPrerenderContents( 305 prerender_manager()->CreateNextPrerenderContents(
304 url1, 306 url1,
305 FINAL_STATUS_USED); 307 FINAL_STATUS_USED);
306 EXPECT_TRUE(prerender_manager()->AddSimplePreload(url1)); 308 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url1));
307 EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); 309 EXPECT_EQ(null, prerender_manager()->next_prerender_contents());
308 EXPECT_TRUE(prerender_contents1->has_started()); 310 EXPECT_TRUE(prerender_contents1->has_started());
309 311
310 GURL url2("http://images.google.com/"); 312 GURL url2("http://images.google.com/");
311 DummyPrerenderContents* prerender_contents2 = 313 DummyPrerenderContents* prerender_contents2 =
312 prerender_manager()->CreateNextPrerenderContents( 314 prerender_manager()->CreateNextPrerenderContents(
313 url2, 315 url2,
314 FINAL_STATUS_USED); 316 FINAL_STATUS_USED);
315 EXPECT_TRUE(prerender_manager()->AddSimplePreload(url2)); 317 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url2));
316 EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); 318 EXPECT_EQ(null, prerender_manager()->next_prerender_contents());
317 EXPECT_TRUE(prerender_contents2->has_started()); 319 EXPECT_TRUE(prerender_contents2->has_started());
318 320
319 ASSERT_EQ(null, prerender_manager()->GetEntry(url)); 321 ASSERT_EQ(null, prerender_manager()->GetEntry(url));
320 ASSERT_EQ(prerender_contents1, prerender_manager()->GetEntry(url1)); 322 ASSERT_EQ(prerender_contents1, prerender_manager()->GetEntry(url1));
321 ASSERT_EQ(prerender_contents2, prerender_manager()->GetEntry(url2)); 323 ASSERT_EQ(prerender_contents2, prerender_manager()->GetEntry(url2));
322 } 324 }
323 325
324 TEST_F(PrerenderManagerTest, AliasURLTest) { 326 TEST_F(PrerenderManagerTest, AliasURLTest) {
325 GURL url("http://www.google.com/"); 327 GURL url("http://www.google.com/");
326 GURL alias_url1("http://www.google.com/index.html"); 328 GURL alias_url1("http://www.google.com/index.html");
327 GURL alias_url2("http://google.com/"); 329 GURL alias_url2("http://google.com/");
328 GURL not_an_alias_url("http://google.com/index.html"); 330 GURL not_an_alias_url("http://google.com/index.html");
329 std::vector<GURL> alias_urls; 331 std::vector<GURL> alias_urls;
330 alias_urls.push_back(alias_url1); 332 alias_urls.push_back(alias_url1);
331 alias_urls.push_back(alias_url2); 333 alias_urls.push_back(alias_url2);
332 334
333 // Test that all of the aliases work, but not_an_alias_url does not. 335 // Test that all of the aliases work, but not_an_alias_url does not.
334 DummyPrerenderContents* prerender_contents = 336 DummyPrerenderContents* prerender_contents =
335 prerender_manager()->CreateNextPrerenderContents( 337 prerender_manager()->CreateNextPrerenderContents(
336 url, alias_urls, FINAL_STATUS_USED); 338 url, alias_urls, FINAL_STATUS_USED);
337 EXPECT_TRUE(prerender_manager()->AddSimplePreload(url)); 339 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url));
338 ASSERT_EQ(NULL, prerender_manager()->GetEntry(not_an_alias_url)); 340 ASSERT_EQ(NULL, prerender_manager()->GetEntry(not_an_alias_url));
339 ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(alias_url1)); 341 ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(alias_url1));
340 prerender_contents = prerender_manager()->CreateNextPrerenderContents( 342 prerender_contents = prerender_manager()->CreateNextPrerenderContents(
341 url, alias_urls, FINAL_STATUS_USED); 343 url, alias_urls, FINAL_STATUS_USED);
342 EXPECT_TRUE(prerender_manager()->AddSimplePreload(url)); 344 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url));
343 ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(alias_url2)); 345 ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(alias_url2));
344 prerender_contents = prerender_manager()->CreateNextPrerenderContents( 346 prerender_contents = prerender_manager()->CreateNextPrerenderContents(
345 url, alias_urls, FINAL_STATUS_USED); 347 url, alias_urls, FINAL_STATUS_USED);
346 EXPECT_TRUE(prerender_manager()->AddSimplePreload(url)); 348 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url));
347 ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(url)); 349 ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(url));
348 350
349 // Test that alias URLs can not be added. 351 // Test that alias URLs can not be added.
350 prerender_contents = prerender_manager()->CreateNextPrerenderContents( 352 prerender_contents = prerender_manager()->CreateNextPrerenderContents(
351 url, alias_urls, FINAL_STATUS_USED); 353 url, alias_urls, FINAL_STATUS_USED);
352 EXPECT_TRUE(prerender_manager()->AddSimplePreload(url)); 354 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url));
353 EXPECT_FALSE(prerender_manager()->AddSimplePreload(url)); 355 EXPECT_FALSE(prerender_manager()->AddSimplePrerender(url));
354 EXPECT_FALSE(prerender_manager()->AddSimplePreload(alias_url1)); 356 EXPECT_FALSE(prerender_manager()->AddSimplePrerender(alias_url1));
355 EXPECT_FALSE(prerender_manager()->AddSimplePreload(alias_url2)); 357 EXPECT_FALSE(prerender_manager()->AddSimplePrerender(alias_url2));
356 ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(url)); 358 ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(url));
357 } 359 }
358 360
359 // Ensure that we ignore prerender requests within the rate limit. 361 // Ensure that we ignore prerender requests within the rate limit.
360 TEST_F(PrerenderManagerTest, RateLimitInWindowTest) { 362 TEST_F(PrerenderManagerTest, RateLimitInWindowTest) {
361 GURL url("http://www.google.com/"); 363 GURL url("http://www.google.com/");
362 DummyPrerenderContents* prerender_contents = 364 DummyPrerenderContents* prerender_contents =
363 prerender_manager()->CreateNextPrerenderContents( 365 prerender_manager()->CreateNextPrerenderContents(
364 url, 366 url,
365 FINAL_STATUS_MANAGER_SHUTDOWN); 367 FINAL_STATUS_MANAGER_SHUTDOWN);
366 DummyPrerenderContents* null = NULL; 368 DummyPrerenderContents* null = NULL;
367 EXPECT_TRUE(prerender_manager()->AddSimplePreload(url)); 369 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url));
368 EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); 370 EXPECT_EQ(null, prerender_manager()->next_prerender_contents());
369 EXPECT_TRUE(prerender_contents->has_started()); 371 EXPECT_TRUE(prerender_contents->has_started());
370 372
371 prerender_manager()->set_rate_limit_enabled(true); 373 prerender_manager()->set_rate_limit_enabled(true);
372 prerender_manager()->AdvanceTimeTicks(base::TimeDelta::FromMilliseconds(1)); 374 prerender_manager()->AdvanceTimeTicks(base::TimeDelta::FromMilliseconds(1));
373 375
374 GURL url1("http://news.google.com/"); 376 GURL url1("http://news.google.com/");
375 prerender_manager()->CreateNextPrerenderContents( 377 prerender_manager()->CreateNextPrerenderContents(
376 url, 378 url,
377 FINAL_STATUS_MANAGER_SHUTDOWN); 379 FINAL_STATUS_MANAGER_SHUTDOWN);
378 EXPECT_FALSE(prerender_manager()->AddSimplePreload(url1)); 380 EXPECT_FALSE(prerender_manager()->AddSimplePrerender(url1));
379 prerender_manager()->set_rate_limit_enabled(false); 381 prerender_manager()->set_rate_limit_enabled(false);
380 } 382 }
381 383
382 // Ensure that we don't ignore prerender requests outside the rate limit. 384 // Ensure that we don't ignore prerender requests outside the rate limit.
383 TEST_F(PrerenderManagerTest, RateLimitOutsideWindowTest) { 385 TEST_F(PrerenderManagerTest, RateLimitOutsideWindowTest) {
384 GURL url("http://www.google.com/"); 386 GURL url("http://www.google.com/");
385 DummyPrerenderContents* prerender_contents = 387 DummyPrerenderContents* prerender_contents =
386 prerender_manager()->CreateNextPrerenderContents( 388 prerender_manager()->CreateNextPrerenderContents(
387 url, 389 url,
388 FINAL_STATUS_EVICTED); 390 FINAL_STATUS_EVICTED);
389 DummyPrerenderContents* null = NULL; 391 DummyPrerenderContents* null = NULL;
390 EXPECT_TRUE(prerender_manager()->AddSimplePreload(url)); 392 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url));
391 EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); 393 EXPECT_EQ(null, prerender_manager()->next_prerender_contents());
392 EXPECT_TRUE(prerender_contents->has_started()); 394 EXPECT_TRUE(prerender_contents->has_started());
393 395
394 prerender_manager()->set_rate_limit_enabled(true); 396 prerender_manager()->set_rate_limit_enabled(true);
395 prerender_manager()->AdvanceTimeTicks( 397 prerender_manager()->AdvanceTimeTicks(
396 base::TimeDelta::FromMilliseconds(2000)); 398 base::TimeDelta::FromMilliseconds(2000));
397 399
398 GURL url1("http://news.google.com/"); 400 GURL url1("http://news.google.com/");
399 DummyPrerenderContents* rate_limit_prerender_contents = 401 DummyPrerenderContents* rate_limit_prerender_contents =
400 prerender_manager()->CreateNextPrerenderContents( 402 prerender_manager()->CreateNextPrerenderContents(
401 url1, 403 url1,
402 FINAL_STATUS_MANAGER_SHUTDOWN); 404 FINAL_STATUS_MANAGER_SHUTDOWN);
403 EXPECT_TRUE(prerender_manager()->AddSimplePreload(url1)); 405 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url1));
404 EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); 406 EXPECT_EQ(null, prerender_manager()->next_prerender_contents());
405 EXPECT_TRUE(rate_limit_prerender_contents->has_started()); 407 EXPECT_TRUE(rate_limit_prerender_contents->has_started());
406 prerender_manager()->set_rate_limit_enabled(false); 408 prerender_manager()->set_rate_limit_enabled(false);
407 } 409 }
408 410
409 TEST_F(PrerenderManagerTest, PendingPreloadTest) { 411 TEST_F(PrerenderManagerTest, PendingPrerenderTest) {
410 GURL url("http://www.google.com/"); 412 GURL url("http://www.google.com/");
411 DummyPrerenderContents* prerender_contents = 413 DummyPrerenderContents* prerender_contents =
412 prerender_manager()->CreateNextPrerenderContents( 414 prerender_manager()->CreateNextPrerenderContents(
413 url, 415 url,
414 FINAL_STATUS_USED); 416 FINAL_STATUS_USED);
415 EXPECT_TRUE(prerender_manager()->AddSimplePreload(url)); 417 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url));
416 418
417 int child_id; 419 int child_id;
418 int route_id; 420 int route_id;
419 ASSERT_TRUE(prerender_contents->GetChildId(&child_id)); 421 ASSERT_TRUE(prerender_contents->GetChildId(&child_id));
420 ASSERT_TRUE(prerender_contents->GetRouteId(&route_id)); 422 ASSERT_TRUE(prerender_contents->GetRouteId(&route_id));
421 423
422 GURL pending_url("http://news.google.com/"); 424 GURL pending_url("http://news.google.com/");
423 425
424 EXPECT_TRUE( 426 EXPECT_TRUE(prerender_manager()->AddPrerenderFromPage(
425 prerender_manager()->AddPreload(std::make_pair(child_id, route_id), 427 ORIGIN_LINK_REL_PRERENDER, std::make_pair(child_id, route_id),
426 pending_url, 428 pending_url, url));
427 url));
428 429
429 EXPECT_TRUE(prerender_manager()->IsPendingEntry(pending_url)); 430 EXPECT_TRUE(prerender_manager()->IsPendingEntry(pending_url));
430 EXPECT_TRUE(prerender_contents->has_started()); 431 EXPECT_TRUE(prerender_contents->has_started());
431 ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(url)); 432 ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(url));
432 } 433 }
433 434
434 // Ensure that extracting a urlencoded URL in the url= query string component 435 // Ensure that extracting a urlencoded URL in the url= query string component
435 // works. 436 // works.
436 TEST_F(PrerenderManagerTest, ExtractURLInQueryStringTest) { 437 TEST_F(PrerenderManagerTest, ExtractURLInQueryStringTest) {
437 GURL result; 438 GURL result;
(...skipping 15 matching lines...) Expand all
453 // group will not be able to override FINAL_STATUS_CONTROL_GROUP. 454 // group will not be able to override FINAL_STATUS_CONTROL_GROUP.
454 TEST_F(PrerenderManagerTest, ControlGroup) { 455 TEST_F(PrerenderManagerTest, ControlGroup) {
455 RestorePrerenderMode restore_prerender_mode; 456 RestorePrerenderMode restore_prerender_mode;
456 PrerenderManager::SetMode( 457 PrerenderManager::SetMode(
457 PrerenderManager::PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP); 458 PrerenderManager::PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP);
458 GURL url("http://www.google.com/"); 459 GURL url("http://www.google.com/");
459 DummyPrerenderContents* prerender_contents = 460 DummyPrerenderContents* prerender_contents =
460 prerender_manager()->CreateNextPrerenderContents( 461 prerender_manager()->CreateNextPrerenderContents(
461 url, 462 url,
462 FINAL_STATUS_CONTROL_GROUP); 463 FINAL_STATUS_CONTROL_GROUP);
463 EXPECT_TRUE(prerender_manager()->AddSimplePreload(url)); 464 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url));
464 EXPECT_FALSE(prerender_contents->has_started()); 465 EXPECT_FALSE(prerender_contents->has_started());
465 } 466 }
466 467
467 // Tests that prerendering is cancelled when the source render view does not 468 // Tests that prerendering is cancelled when the source render view does not
468 // exist. On failure, the DCHECK in CreatePrerenderContents() above should be 469 // exist. On failure, the DCHECK in CreatePrerenderContents() above should be
469 // triggered. 470 // triggered.
470 TEST_F(PrerenderManagerTest, SourceRenderViewClosed) { 471 TEST_F(PrerenderManagerTest, SourceRenderViewClosed) {
471 GURL url("http://www.google.com/"); 472 GURL url("http://www.google.com/");
472 prerender_manager()->CreateNextPrerenderContents( 473 prerender_manager()->CreateNextPrerenderContents(
473 url, 474 url,
474 FINAL_STATUS_MANAGER_SHUTDOWN); 475 FINAL_STATUS_MANAGER_SHUTDOWN);
475 EXPECT_FALSE(prerender_manager()->AddPreload( 476 EXPECT_FALSE(prerender_manager()->AddPrerenderFromPage(
476 std::pair<int, int>(100, 100), url, GURL())); 477 ORIGIN_LINK_REL_PRERENDER, std::pair<int, int>(100, 100), url, GURL()));
477 } 478 }
478 479
479 // Tests that the prerender manager ignores fragment references when matching 480 // Tests that the prerender manager ignores fragment references when matching
480 // prerender URLs in the case the fragment is not in the prerender URL. 481 // prerender URLs in the case the fragment is not in the prerender URL.
481 TEST_F(PrerenderManagerTest, PageMatchesFragmentTest) { 482 TEST_F(PrerenderManagerTest, PageMatchesFragmentTest) {
482 GURL url("http://www.google.com/"); 483 GURL url("http://www.google.com/");
483 GURL fragment_url("http://www.google.com/#test"); 484 GURL fragment_url("http://www.google.com/#test");
484 485
485 DummyPrerenderContents* prerender_contents = 486 DummyPrerenderContents* prerender_contents =
486 prerender_manager()->CreateNextPrerenderContents(url, 487 prerender_manager()->CreateNextPrerenderContents(url,
487 FINAL_STATUS_USED); 488 FINAL_STATUS_USED);
488 EXPECT_TRUE(prerender_manager()->AddSimplePreload(url)); 489 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url));
489 EXPECT_TRUE(prerender_contents->has_started()); 490 EXPECT_TRUE(prerender_contents->has_started());
490 ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(fragment_url)); 491 ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(fragment_url));
491 } 492 }
492 493
493 // Tests that the prerender manager ignores fragment references when matching 494 // Tests that the prerender manager ignores fragment references when matching
494 // prerender URLs in the case the fragment is in the prerender URL. 495 // prerender URLs in the case the fragment is in the prerender URL.
495 TEST_F(PrerenderManagerTest, FragmentMatchesPageTest) { 496 TEST_F(PrerenderManagerTest, FragmentMatchesPageTest) {
496 GURL url("http://www.google.com/"); 497 GURL url("http://www.google.com/");
497 GURL fragment_url("http://www.google.com/#test"); 498 GURL fragment_url("http://www.google.com/#test");
498 499
499 DummyPrerenderContents* prerender_contents = 500 DummyPrerenderContents* prerender_contents =
500 prerender_manager()->CreateNextPrerenderContents(fragment_url, 501 prerender_manager()->CreateNextPrerenderContents(fragment_url,
501 FINAL_STATUS_USED); 502 FINAL_STATUS_USED);
502 EXPECT_TRUE(prerender_manager()->AddSimplePreload(fragment_url)); 503 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(fragment_url));
503 EXPECT_TRUE(prerender_contents->has_started()); 504 EXPECT_TRUE(prerender_contents->has_started());
504 ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(url)); 505 ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(url));
505 } 506 }
506 507
507 // Tests that the prerender manager ignores fragment references when matching 508 // Tests that the prerender manager ignores fragment references when matching
508 // prerender URLs in the case the fragment is in both URLs. 509 // prerender URLs in the case the fragment is in both URLs.
509 TEST_F(PrerenderManagerTest, FragmentMatchesFragmentTest) { 510 TEST_F(PrerenderManagerTest, FragmentMatchesFragmentTest) {
510 GURL fragment_url("http://www.google.com/#test"); 511 GURL fragment_url("http://www.google.com/#test");
511 GURL other_fragment_url("http://www.google.com/#other_test"); 512 GURL other_fragment_url("http://www.google.com/#other_test");
512 513
513 DummyPrerenderContents* prerender_contents = 514 DummyPrerenderContents* prerender_contents =
514 prerender_manager()->CreateNextPrerenderContents(fragment_url, 515 prerender_manager()->CreateNextPrerenderContents(fragment_url,
515 FINAL_STATUS_USED); 516 FINAL_STATUS_USED);
516 EXPECT_TRUE(prerender_manager()->AddSimplePreload(fragment_url)); 517 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(fragment_url));
517 EXPECT_TRUE(prerender_contents->has_started()); 518 EXPECT_TRUE(prerender_contents->has_started());
518 ASSERT_EQ(prerender_contents, 519 ASSERT_EQ(prerender_contents,
519 prerender_manager()->GetEntry(other_fragment_url)); 520 prerender_manager()->GetEntry(other_fragment_url));
520 } 521 }
521 522
522 // Make sure that clearing works as expected. 523 // Make sure that clearing works as expected.
523 TEST_F(PrerenderManagerTest, ClearTest) { 524 TEST_F(PrerenderManagerTest, ClearTest) {
524 GURL url("http://www.google.com/"); 525 GURL url("http://www.google.com/");
525 DummyPrerenderContents* prerender_contents = 526 DummyPrerenderContents* prerender_contents =
526 prerender_manager()->CreateNextPrerenderContents( 527 prerender_manager()->CreateNextPrerenderContents(
527 url, 528 url,
528 FINAL_STATUS_CACHE_OR_HISTORY_CLEARED); 529 FINAL_STATUS_CACHE_OR_HISTORY_CLEARED);
529 EXPECT_TRUE(prerender_manager()->AddSimplePreload(url)); 530 EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url));
530 EXPECT_TRUE(prerender_contents->has_started()); 531 EXPECT_TRUE(prerender_contents->has_started());
531 prerender_manager()->ClearData(PrerenderManager::CLEAR_PRERENDER_CONTENTS); 532 prerender_manager()->ClearData(PrerenderManager::CLEAR_PRERENDER_CONTENTS);
532 DummyPrerenderContents* null = NULL; 533 DummyPrerenderContents* null = NULL;
533 EXPECT_EQ(null, prerender_manager()->GetEntry(url)); 534 EXPECT_EQ(null, prerender_manager()->GetEntry(url));
534 } 535 }
535 536
536 } // namespace prerender 537 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_manager.cc ('k') | chrome/browser/prerender/prerender_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698