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
3 // found in the LICENSE file.
8 #include "base/command_line.h"
9 #include "base/format_macros.h"
10 #include "base/memory/scoped_vector.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/metrics/field_trial.h"
13 #include "base/prefs/pref_service.h"
14 #include "base/strings/stringprintf.h"
15 #include "base/time/time.h"
16 #include "chrome/browser/net/prediction_options.h"
17 #include "chrome/browser/prerender/prerender_contents.h"
18 #include "chrome/browser/prerender/prerender_handle.h"
19 #include "chrome/browser/prerender/prerender_link_manager.h"
20 #include "chrome/browser/prerender/prerender_manager.h"
21 #include "chrome/browser/prerender/prerender_origin.h"
22 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/pref_names.h"
24 #include "chrome/common/prerender_types.h"
25 #include "chrome/test/base/testing_browser_process.h"
26 #include "chrome/test/base/testing_profile.h"
27 #include "content/public/browser/render_view_host.h"
28 #include "content/public/test/test_browser_thread.h"
29 #include "testing/gtest/include/gtest/gtest.h"
30 #include "ui/gfx/size.h"
34 using base::TimeDelta
;
35 using base::TimeTicks
;
36 using content::BrowserThread
;
37 using content::Referrer
;
41 class UnitTestPrerenderManager
;
45 class DummyPrerenderContents
: public PrerenderContents
{
47 DummyPrerenderContents(UnitTestPrerenderManager
* test_prerender_manager
,
48 PrerenderTracker
* prerender_tracker
,
51 FinalStatus expected_final_status
);
53 virtual ~DummyPrerenderContents();
55 virtual void StartPrerendering(
57 const gfx::Size
& size
,
58 content::SessionStorageNamespace
* session_storage_namespace
,
59 net::URLRequestContextGetter
* request_context
) override
;
61 virtual bool GetChildId(int* child_id
) const override
{
62 // Having a default child_id of -1 forces pending prerenders not to fail
63 // on session storage and cross domain checking.
68 virtual bool GetRouteId(int* route_id
) const override
{
69 *route_id
= route_id_
;
73 FinalStatus
expected_final_status() const { return expected_final_status_
; }
75 bool prerendering_has_been_cancelled() const {
76 return PrerenderContents::prerendering_has_been_cancelled();
80 static int g_next_route_id_
;
83 UnitTestPrerenderManager
* test_prerender_manager_
;
84 FinalStatus expected_final_status_
;
87 int DummyPrerenderContents::g_next_route_id_
= 0;
89 const gfx::Size
kSize(640, 480);
91 const uint32 kDefaultRelTypes
= PrerenderRelTypePrerender
;
95 class UnitTestPrerenderManager
: public PrerenderManager
{
97 using PrerenderManager::kMinTimeBetweenPrerendersMs
;
98 using PrerenderManager::kNavigationRecordWindowMs
;
100 explicit UnitTestPrerenderManager(Profile
* profile
,
101 PrerenderTracker
* prerender_tracker
)
102 : PrerenderManager(profile
, prerender_tracker
),
104 time_ticks_(TimeTicks::Now()),
105 prerender_tracker_(prerender_tracker
) {
106 set_rate_limit_enabled(false);
107 OnCookieStoreLoaded();
110 virtual ~UnitTestPrerenderManager() {
113 // From KeyedService, via PrererenderManager:
114 virtual void Shutdown() override
{
115 if (next_prerender_contents())
116 next_prerender_contents_
->Destroy(FINAL_STATUS_MANAGER_SHUTDOWN
);
117 PrerenderManager::Shutdown();
120 // From PrerenderManager:
121 virtual void MoveEntryToPendingDelete(PrerenderContents
* entry
,
122 FinalStatus final_status
) override
{
123 if (entry
== next_prerender_contents_
.get())
125 PrerenderManager::MoveEntryToPendingDelete(entry
, final_status
);
128 PrerenderContents
* FindEntry(const GURL
& url
) {
130 to_delete_prerenders_
.clear();
131 if (PrerenderData
* data
= FindPrerenderData(url
, NULL
))
132 return data
->contents();
136 PrerenderContents
* FindAndUseEntry(const GURL
& url
) {
137 PrerenderData
* prerender_data
= FindPrerenderData(url
, NULL
);
140 ScopedVector
<PrerenderData
>::iterator to_erase
=
141 FindIteratorForPrerenderContents(prerender_data
->contents());
142 CHECK(to_erase
!= active_prerenders_
.end());
143 PrerenderContents
* prerender_contents
= prerender_data
->ReleaseContents();
144 active_prerenders_
.erase(to_erase
);
146 prerender_contents
->PrepareForUse();
147 return prerender_contents
;
150 void AdvanceTime(TimeDelta delta
) {
154 void AdvanceTimeTicks(TimeDelta delta
) {
155 time_ticks_
+= delta
;
158 DummyPrerenderContents
* CreateNextPrerenderContents(
160 FinalStatus expected_final_status
) {
161 DummyPrerenderContents
* prerender_contents
=
162 new DummyPrerenderContents(this, prerender_tracker_
, url
,
163 ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN
,
164 expected_final_status
);
165 SetNextPrerenderContents(prerender_contents
);
166 return prerender_contents
;
169 DummyPrerenderContents
* CreateNextPrerenderContents(
172 FinalStatus expected_final_status
) {
173 DummyPrerenderContents
* prerender_contents
=
174 new DummyPrerenderContents(this, prerender_tracker_
, url
,
175 origin
, expected_final_status
);
176 SetNextPrerenderContents(prerender_contents
);
177 return prerender_contents
;
180 DummyPrerenderContents
* CreateNextPrerenderContents(
182 const std::vector
<GURL
>& alias_urls
,
183 FinalStatus expected_final_status
) {
184 DummyPrerenderContents
* prerender_contents
=
185 new DummyPrerenderContents(this, prerender_tracker_
, url
,
186 ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN
,
187 expected_final_status
);
188 for (std::vector
<GURL
>::const_iterator it
= alias_urls
.begin();
189 it
!= alias_urls
.end();
191 EXPECT_TRUE(prerender_contents
->AddAliasURL(*it
));
193 SetNextPrerenderContents(prerender_contents
);
194 return prerender_contents
;
197 void set_rate_limit_enabled(bool enabled
) {
198 mutable_config().rate_limit_enabled
= enabled
;
201 PrerenderContents
* next_prerender_contents() {
202 return next_prerender_contents_
.get();
205 // from PrerenderManager
206 virtual Time
GetCurrentTime() const override
{
210 virtual TimeTicks
GetCurrentTimeTicks() const override
{
214 virtual PrerenderContents
* GetPrerenderContentsForRoute(
215 int child_id
, int route_id
) const override
{
216 // Overridden for the PrerenderLinkManager's pending prerender logic.
217 PrerenderContentsMap::const_iterator iter
= prerender_contents_map_
.find(
218 std::make_pair(child_id
, route_id
));
219 if (iter
== prerender_contents_map_
.end())
224 void DummyPrerenderContentsStarted(int child_id
,
226 PrerenderContents
* prerender_contents
) {
227 prerender_contents_map_
[std::make_pair(child_id
, route_id
)] =
231 void DummyPrerenderContentsDestroyed(int child_id
,
233 prerender_contents_map_
.erase(std::make_pair(child_id
, route_id
));
237 virtual net::URLRequestContextGetter
* GetURLRequestContext() override
{
242 void SetNextPrerenderContents(DummyPrerenderContents
* prerender_contents
) {
243 CHECK(!next_prerender_contents_
.get());
244 next_prerender_contents_
.reset(prerender_contents
);
245 if (prerender_contents
->expected_final_status() == FINAL_STATUS_USED
)
246 used_prerender_contents_
.push_back(prerender_contents
);
250 virtual PrerenderContents
* CreatePrerenderContents(
252 const Referrer
& referrer
,
254 uint8 experiment_id
) override
{
255 CHECK(next_prerender_contents_
.get());
256 EXPECT_EQ(url
, next_prerender_contents_
->prerender_url());
257 EXPECT_EQ(origin
, next_prerender_contents_
->origin());
258 return next_prerender_contents_
.release();
261 // Maintain a map from route pairs to PrerenderContents for
262 // GetPrerenderContentsForRoute.
263 typedef std::map
<std::pair
<int,int>, PrerenderContents
*> PrerenderContentsMap
;
264 PrerenderContentsMap prerender_contents_map_
;
267 TimeTicks time_ticks_
;
268 scoped_ptr
<PrerenderContents
> next_prerender_contents_
;
269 // PrerenderContents with an |expected_final_status| of FINAL_STATUS_USED,
270 // tracked so they will be automatically deleted.
271 ScopedVector
<PrerenderContents
> used_prerender_contents_
;
273 PrerenderTracker
* prerender_tracker_
;
276 class RestorePrerenderMode
{
278 RestorePrerenderMode() : prev_mode_(PrerenderManager::GetMode()) {
281 ~RestorePrerenderMode() { PrerenderManager::SetMode(prev_mode_
); }
283 PrerenderManager::PrerenderManagerMode prev_mode_
;
286 DummyPrerenderContents::DummyPrerenderContents(
287 UnitTestPrerenderManager
* test_prerender_manager
,
288 PrerenderTracker
* prerender_tracker
,
291 FinalStatus expected_final_status
)
292 : PrerenderContents(test_prerender_manager
,
293 NULL
, url
, Referrer(), origin
,
294 PrerenderManager::kNoExperiment
),
295 route_id_(g_next_route_id_
++),
296 test_prerender_manager_(test_prerender_manager
),
297 expected_final_status_(expected_final_status
) {
300 DummyPrerenderContents::~DummyPrerenderContents() {
301 EXPECT_EQ(expected_final_status_
, final_status());
302 test_prerender_manager_
->DummyPrerenderContentsDestroyed(-1, route_id_
);
305 void DummyPrerenderContents::StartPrerendering(
306 int creator_child_id
,
307 const gfx::Size
& size
,
308 content::SessionStorageNamespace
* session_storage_namespace
,
309 net::URLRequestContextGetter
* request_context
) {
310 // In the base PrerenderContents implementation, StartPrerendering will
311 // be called even when the PrerenderManager is part of the control group,
312 // but it will early exit before actually creating a new RenderView if
313 // |is_control_group| is true;
314 load_start_time_
= test_prerender_manager_
->GetCurrentTimeTicks();
315 if (!test_prerender_manager_
->IsControlGroup(experiment_id())) {
316 prerendering_has_started_
= true;
317 test_prerender_manager_
->DummyPrerenderContentsStarted(-1, route_id_
, this);
318 NotifyPrerenderStart();
322 class PrerenderTest
: public testing::Test
{
324 static const int kDefaultChildId
= -1;
325 static const int kDefaultRenderViewRouteId
= -1;
327 PrerenderTest() : ui_thread_(BrowserThread::UI
, &message_loop_
),
328 prerender_manager_(new UnitTestPrerenderManager(
329 &profile_
, prerender_tracker())),
330 prerender_link_manager_(
331 new PrerenderLinkManager(prerender_manager_
.get())),
332 last_prerender_id_(0),
333 field_trial_list_(NULL
) {
334 // Enable omnibox prerendering.
335 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
336 switches::kPrerenderFromOmnibox
,
337 switches::kPrerenderFromOmniboxSwitchValueEnabled
);
340 virtual ~PrerenderTest() {
341 prerender_link_manager_
->OnChannelClosing(kDefaultChildId
);
342 prerender_link_manager_
->Shutdown();
343 prerender_manager_
->Shutdown();
346 UnitTestPrerenderManager
* prerender_manager() {
347 return prerender_manager_
.get();
350 PrerenderLinkManager
* prerender_link_manager() {
351 return prerender_link_manager_
.get();
354 void SetConcurrency(size_t concurrency
) {
355 prerender_manager()->mutable_config().max_link_concurrency_per_launcher
=
357 prerender_manager()->mutable_config().max_link_concurrency
=
358 std::max(prerender_manager()->mutable_config().max_link_concurrency
,
362 bool IsEmptyPrerenderLinkManager() const {
363 return prerender_link_manager_
->IsEmpty();
366 int last_prerender_id() const {
367 return last_prerender_id_
;
370 int GetNextPrerenderID() {
371 return ++last_prerender_id_
;
374 bool LauncherHasRunningPrerender(int child_id
, int prerender_id
) {
375 PrerenderLinkManager::LinkPrerender
* prerender
=
376 prerender_link_manager()->FindByLauncherChildIdAndPrerenderId(
377 child_id
, prerender_id
);
378 return prerender
&& prerender
->handle
;
381 bool LauncherHasScheduledPrerender(int child_id
, int prerender_id
) {
382 PrerenderLinkManager::LinkPrerender
* prerender
=
383 prerender_link_manager()->FindByLauncherChildIdAndPrerenderId(
384 child_id
, prerender_id
);
385 return prerender
!= NULL
;
388 // Shorthand to add a simple prerender with a reasonable source. Returns
389 // true iff the prerender has been added to the PrerenderManager by the
390 // PrerenderLinkManager and the PrerenderManager returned a handle.
391 bool AddSimplePrerender(const GURL
& url
) {
392 prerender_link_manager()->OnAddPrerender(
393 kDefaultChildId
, GetNextPrerenderID(), url
, kDefaultRelTypes
,
394 content::Referrer(), kSize
, kDefaultRenderViewRouteId
);
395 return LauncherHasRunningPrerender(kDefaultChildId
, last_prerender_id());
398 void DisablePrerender() {
399 profile_
.GetPrefs()->SetInteger(
400 prefs::kNetworkPredictionOptions
,
401 chrome_browser_net::NETWORK_PREDICTION_NEVER
);
405 PrerenderTracker
* prerender_tracker() {
406 return g_browser_process
->prerender_tracker();
409 // Needed to pass PrerenderManager's DCHECKs.
410 TestingProfile profile_
;
411 base::MessageLoop message_loop_
;
412 content::TestBrowserThread ui_thread_
;
413 scoped_ptr
<UnitTestPrerenderManager
> prerender_manager_
;
414 scoped_ptr
<PrerenderLinkManager
> prerender_link_manager_
;
415 int last_prerender_id_
;
416 base::FieldTrialList field_trial_list_
;
419 TEST_F(PrerenderTest
, FoundTest
) {
420 GURL
url("http://www.google.com/");
421 DummyPrerenderContents
* prerender_contents
=
422 prerender_manager()->CreateNextPrerenderContents(
425 EXPECT_TRUE(AddSimplePrerender(url
));
426 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
427 ASSERT_EQ(prerender_contents
, prerender_manager()->FindAndUseEntry(url
));
430 // Make sure that if queue a request, and a second prerender request for the
431 // same URL comes in, that the second request attaches to the first prerender,
432 // and we don't use the second prerender contents.
433 TEST_F(PrerenderTest
, DuplicateTest
) {
435 GURL
url("http://www.google.com/");
436 DummyPrerenderContents
* prerender_contents
=
437 prerender_manager()->CreateNextPrerenderContents(
440 DummyPrerenderContents
* null
= NULL
;
441 EXPECT_TRUE(AddSimplePrerender(url
));
442 EXPECT_EQ(null
, prerender_manager()->next_prerender_contents());
443 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
445 DummyPrerenderContents
* prerender_contents1
=
446 prerender_manager()->CreateNextPrerenderContents(
448 FINAL_STATUS_MANAGER_SHUTDOWN
);
449 EXPECT_TRUE(AddSimplePrerender(url
));
450 EXPECT_EQ(prerender_contents1
,
451 prerender_manager()->next_prerender_contents());
452 EXPECT_FALSE(prerender_contents1
->prerendering_has_started());
454 ASSERT_EQ(prerender_contents
, prerender_manager()->FindAndUseEntry(url
));
457 // Ensure that we expire a prerendered page after the max. permitted time.
458 TEST_F(PrerenderTest
, ExpireTest
) {
459 GURL
url("http://www.google.com/");
460 DummyPrerenderContents
* prerender_contents
=
461 prerender_manager()->CreateNextPrerenderContents(
463 FINAL_STATUS_TIMED_OUT
);
464 DummyPrerenderContents
* null
= NULL
;
465 EXPECT_TRUE(AddSimplePrerender(url
));
466 EXPECT_EQ(null
, prerender_manager()->next_prerender_contents());
467 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
468 prerender_manager()->AdvanceTimeTicks(
469 prerender_manager()->config().time_to_live
+ TimeDelta::FromSeconds(1));
470 ASSERT_EQ(null
, prerender_manager()->FindEntry(url
));
473 // Ensure that we don't launch prerenders of bad urls (in this case, a mailto:
475 TEST_F(PrerenderTest
, BadURLTest
) {
476 GURL
url("mailto:test@gmail.com");
477 DummyPrerenderContents
* prerender_contents
=
478 prerender_manager()->CreateNextPrerenderContents(
480 FINAL_STATUS_UNSUPPORTED_SCHEME
);
481 EXPECT_FALSE(AddSimplePrerender(url
));
482 EXPECT_FALSE(prerender_contents
->prerendering_has_started());
483 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
484 DummyPrerenderContents
* null
= NULL
;
485 EXPECT_EQ(null
, prerender_manager()->FindEntry(url
));
488 // When the user navigates away from a page, the prerenders it launched should
489 // have their time to expiry shortened from the default time to live.
490 TEST_F(PrerenderTest
, LinkManagerNavigateAwayExpire
) {
491 const TimeDelta time_to_live
= TimeDelta::FromSeconds(300);
492 const TimeDelta abandon_time_to_live
= TimeDelta::FromSeconds(20);
493 const TimeDelta test_advance
= TimeDelta::FromSeconds(22);
494 ASSERT_LT(test_advance
, time_to_live
);
495 ASSERT_LT(abandon_time_to_live
, test_advance
);
497 prerender_manager()->mutable_config().time_to_live
= time_to_live
;
498 prerender_manager()->mutable_config().abandon_time_to_live
=
499 abandon_time_to_live
;
501 GURL
url("http://example.com");
502 DummyPrerenderContents
* prerender_contents
=
503 prerender_manager()->CreateNextPrerenderContents(url
,
504 FINAL_STATUS_TIMED_OUT
);
505 EXPECT_TRUE(AddSimplePrerender(url
));
506 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
507 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
508 ASSERT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
509 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId
,
510 last_prerender_id());
511 EXPECT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
512 DummyPrerenderContents
* null
= NULL
;
513 EXPECT_EQ(null
, prerender_manager()->next_prerender_contents());
514 prerender_manager()->AdvanceTimeTicks(test_advance
);
516 EXPECT_EQ(null
, prerender_manager()->FindEntry(url
));
519 // But when we navigate away very close to the original expiry of a prerender,
520 // we shouldn't expect it to be extended.
521 TEST_F(PrerenderTest
, LinkManagerNavigateAwayNearExpiry
) {
522 const TimeDelta time_to_live
= TimeDelta::FromSeconds(300);
523 const TimeDelta abandon_time_to_live
= TimeDelta::FromSeconds(20);
525 // We will expect the prerender to still be alive after advancing the clock
526 // by first_advance. But, after second_advance, we expect it to have timed
527 // out, demonstrating that you can't extend a prerender by navigating away
528 // from its launcher.
529 const TimeDelta first_advance
= TimeDelta::FromSeconds(298);
530 const TimeDelta second_advance
= TimeDelta::FromSeconds(4);
531 ASSERT_LT(first_advance
, time_to_live
);
532 ASSERT_LT(time_to_live
- first_advance
, abandon_time_to_live
);
533 ASSERT_LT(time_to_live
, first_advance
+ second_advance
);
535 prerender_manager()->mutable_config().time_to_live
= time_to_live
;
536 prerender_manager()->mutable_config().abandon_time_to_live
=
537 abandon_time_to_live
;
539 GURL
url("http://example2.com");
540 DummyPrerenderContents
* prerender_contents
=
541 prerender_manager()->CreateNextPrerenderContents(url
,
542 FINAL_STATUS_TIMED_OUT
);
543 EXPECT_TRUE(AddSimplePrerender(url
));
544 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
545 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
546 ASSERT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
548 prerender_manager()->AdvanceTimeTicks(first_advance
);
549 EXPECT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
551 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId
,
552 last_prerender_id());
553 EXPECT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
555 DummyPrerenderContents
* null
= NULL
;
556 EXPECT_EQ(null
, prerender_manager()->next_prerender_contents());
558 prerender_manager()->AdvanceTimeTicks(second_advance
);
559 EXPECT_EQ(null
, prerender_manager()->FindEntry(url
));
562 // When the user navigates away from a page, and then launches a new prerender,
563 // the new prerender should preempt the abandoned prerender even if the
564 // abandoned prerender hasn't expired.
565 TEST_F(PrerenderTest
, LinkManagerNavigateAwayLaunchAnother
) {
566 const TimeDelta time_to_live
= TimeDelta::FromSeconds(300);
567 const TimeDelta abandon_time_to_live
= TimeDelta::FromSeconds(20);
568 const TimeDelta test_advance
= TimeDelta::FromSeconds(5);
569 ASSERT_LT(test_advance
, time_to_live
);
570 ASSERT_GT(abandon_time_to_live
, test_advance
);
572 prerender_manager()->mutable_config().time_to_live
= time_to_live
;
573 prerender_manager()->mutable_config().abandon_time_to_live
=
574 abandon_time_to_live
;
576 GURL
url("http://example.com");
577 prerender_manager()->CreateNextPrerenderContents(url
, FINAL_STATUS_CANCELLED
);
578 EXPECT_TRUE(AddSimplePrerender(url
));
579 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId
,
580 last_prerender_id());
582 prerender_manager()->AdvanceTimeTicks(test_advance
);
584 GURL
second_url("http://example2.com");
585 DummyPrerenderContents
* second_prerender_contents
=
586 prerender_manager()->CreateNextPrerenderContents(
587 second_url
, FINAL_STATUS_MANAGER_SHUTDOWN
);
588 EXPECT_TRUE(AddSimplePrerender(second_url
));
589 EXPECT_EQ(second_prerender_contents
,
590 prerender_manager()->FindEntry(second_url
));
594 // Make sure that if we prerender more requests than we support, that we launch
595 // them in the order given up until we reach MaxConcurrency, at which point we
596 // queue them and launch them in the order given. As well, insure that limits
597 // are enforced for the system as a whole and on a per launcher basis.
598 TEST_F(PrerenderTest
, MaxConcurrencyTest
) {
599 struct TestConcurrency
{
600 size_t max_link_concurrency
;
601 size_t max_link_concurrency_per_launcher
;
604 TestConcurrency concurrencies_to_test
[] = {
605 { prerender_manager()->config().max_link_concurrency
,
606 prerender_manager()->config().max_link_concurrency_per_launcher
},
608 // With the system limit higher than the per launcher limit, the per
609 // launcher limit should be in effect.
612 // With the per launcher limit higher than system limit, the system limit
613 // should be in effect.
617 DummyPrerenderContents
* null
= NULL
;
618 GURL
url_to_delay("http://www.google.com/delayme");
620 for (size_t i
= 0; i
< arraysize(concurrencies_to_test
); ++i
) {
621 prerender_manager()->mutable_config().max_link_concurrency
=
622 concurrencies_to_test
[i
].max_link_concurrency
;
623 prerender_manager()->mutable_config().max_link_concurrency_per_launcher
=
624 concurrencies_to_test
[i
].max_link_concurrency_per_launcher
;
626 const size_t effective_max_link_concurrency
=
627 std::min(concurrencies_to_test
[i
].max_link_concurrency
,
628 concurrencies_to_test
[i
].max_link_concurrency_per_launcher
);
630 std::vector
<GURL
> urls
;
631 std::vector
<PrerenderContents
*> prerender_contentses
;
633 // Launch prerenders up to the maximum this launcher can support.
634 for (size_t j
= 0; j
< effective_max_link_concurrency
; ++j
) {
636 GURL(base::StringPrintf("http://google.com/use#%" PRIuS
, j
)));
637 prerender_contentses
.push_back(
638 prerender_manager()->CreateNextPrerenderContents(urls
.back(),
640 EXPECT_TRUE(AddSimplePrerender(urls
.back()));
641 EXPECT_EQ(null
, prerender_manager()->next_prerender_contents());
642 EXPECT_TRUE(prerender_contentses
.back()->prerendering_has_started());
645 if (concurrencies_to_test
[i
].max_link_concurrency
>
646 effective_max_link_concurrency
) {
647 // We should be able to launch more prerenders on this system, but not for
648 // the default launcher.
649 GURL
extra_url("http://google.com/extraurl");
650 EXPECT_FALSE(AddSimplePrerender(extra_url
));
651 const int prerender_id
= last_prerender_id();
652 EXPECT_TRUE(LauncherHasScheduledPrerender(kDefaultChildId
,
654 prerender_link_manager()->OnCancelPrerender(kDefaultChildId
,
656 EXPECT_FALSE(LauncherHasScheduledPrerender(kDefaultChildId
,
660 DummyPrerenderContents
* prerender_contents_to_delay
=
661 prerender_manager()->CreateNextPrerenderContents(url_to_delay
,
663 EXPECT_FALSE(AddSimplePrerender(url_to_delay
));
664 EXPECT_FALSE(prerender_contents_to_delay
->prerendering_has_started());
665 EXPECT_NE(null
, prerender_manager()->next_prerender_contents());
666 EXPECT_EQ(null
, prerender_manager()->FindEntry(url_to_delay
));
667 for (size_t j
= 0; j
< effective_max_link_concurrency
; ++j
) {
668 EXPECT_EQ(prerender_contentses
[j
],
669 prerender_manager()->FindAndUseEntry(urls
[j
]));
670 EXPECT_TRUE(prerender_contents_to_delay
->prerendering_has_started());
673 EXPECT_EQ(prerender_contents_to_delay
,
674 prerender_manager()->FindAndUseEntry(url_to_delay
));
675 EXPECT_EQ(null
, prerender_manager()->next_prerender_contents());
679 TEST_F(PrerenderTest
, AliasURLTest
) {
682 GURL
url("http://www.google.com/");
683 GURL
alias_url1("http://www.google.com/index.html");
684 GURL
alias_url2("http://google.com/");
685 GURL
not_an_alias_url("http://google.com/index.html");
686 std::vector
<GURL
> alias_urls
;
687 alias_urls
.push_back(alias_url1
);
688 alias_urls
.push_back(alias_url2
);
690 // Test that all of the aliases work, but not_an_alias_url does not.
691 DummyPrerenderContents
* prerender_contents
=
692 prerender_manager()->CreateNextPrerenderContents(
693 url
, alias_urls
, FINAL_STATUS_USED
);
694 EXPECT_TRUE(AddSimplePrerender(url
));
695 ASSERT_EQ(NULL
, prerender_manager()->FindEntry(not_an_alias_url
));
696 ASSERT_EQ(prerender_contents
,
697 prerender_manager()->FindAndUseEntry(alias_url1
));
698 prerender_contents
= prerender_manager()->CreateNextPrerenderContents(
699 url
, alias_urls
, FINAL_STATUS_USED
);
700 EXPECT_TRUE(AddSimplePrerender(url
));
701 ASSERT_EQ(prerender_contents
,
702 prerender_manager()->FindAndUseEntry(alias_url2
));
703 prerender_contents
= prerender_manager()->CreateNextPrerenderContents(
704 url
, alias_urls
, FINAL_STATUS_USED
);
705 EXPECT_TRUE(AddSimplePrerender(url
));
706 ASSERT_EQ(prerender_contents
, prerender_manager()->FindAndUseEntry(url
));
708 // Test that alias URLs can not be added.
709 prerender_contents
= prerender_manager()->CreateNextPrerenderContents(
710 url
, alias_urls
, FINAL_STATUS_USED
);
711 EXPECT_TRUE(AddSimplePrerender(url
));
712 EXPECT_TRUE(AddSimplePrerender(url
));
713 EXPECT_TRUE(AddSimplePrerender(alias_url1
));
714 EXPECT_TRUE(AddSimplePrerender(alias_url2
));
715 ASSERT_EQ(prerender_contents
, prerender_manager()->FindAndUseEntry(url
));
718 TEST_F(PrerenderTest
, PendingPrerenderTest
) {
719 GURL
url("http://www.google.com/");
720 DummyPrerenderContents
* prerender_contents
=
721 prerender_manager()->CreateNextPrerenderContents(
724 EXPECT_TRUE(AddSimplePrerender(url
));
728 ASSERT_TRUE(prerender_contents
->GetChildId(&child_id
));
729 ASSERT_TRUE(prerender_contents
->GetRouteId(&route_id
));
731 GURL
pending_url("http://news.google.com/");
733 // Schedule a pending prerender launched from the prerender.
734 DummyPrerenderContents
* pending_prerender_contents
=
735 prerender_manager()->CreateNextPrerenderContents(
737 ORIGIN_GWS_PRERENDER
,
739 prerender_link_manager()->OnAddPrerender(
740 child_id
, GetNextPrerenderID(), pending_url
, kDefaultRelTypes
,
741 Referrer(url
, blink::WebReferrerPolicyDefault
),
743 EXPECT_FALSE(LauncherHasRunningPrerender(child_id
, last_prerender_id()));
744 EXPECT_FALSE(pending_prerender_contents
->prerendering_has_started());
746 // Use the referring prerender.
747 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
748 ASSERT_EQ(prerender_contents
, prerender_manager()->FindAndUseEntry(url
));
750 // The pending prerender should start now.
751 EXPECT_TRUE(LauncherHasRunningPrerender(child_id
, last_prerender_id()));
752 EXPECT_TRUE(pending_prerender_contents
->prerendering_has_started());
753 ASSERT_EQ(pending_prerender_contents
,
754 prerender_manager()->FindAndUseEntry(pending_url
));
757 TEST_F(PrerenderTest
, InvalidPendingPrerenderTest
) {
758 GURL
url("http://www.google.com/");
759 DummyPrerenderContents
* prerender_contents
=
760 prerender_manager()->CreateNextPrerenderContents(
763 EXPECT_TRUE(AddSimplePrerender(url
));
767 ASSERT_TRUE(prerender_contents
->GetChildId(&child_id
));
768 ASSERT_TRUE(prerender_contents
->GetRouteId(&route_id
));
770 // This pending URL has an unsupported scheme, and won't be able
772 GURL
pending_url("ftp://news.google.com/");
774 // Schedule a pending prerender launched from the prerender.
775 DummyPrerenderContents
* pending_prerender_contents
=
776 prerender_manager()->CreateNextPrerenderContents(
778 ORIGIN_GWS_PRERENDER
,
779 FINAL_STATUS_UNSUPPORTED_SCHEME
);
780 prerender_link_manager()->OnAddPrerender(
781 child_id
, GetNextPrerenderID(), pending_url
, kDefaultRelTypes
,
782 Referrer(url
, blink::WebReferrerPolicyDefault
),
784 EXPECT_FALSE(LauncherHasRunningPrerender(child_id
, last_prerender_id()));
785 EXPECT_FALSE(pending_prerender_contents
->prerendering_has_started());
787 // Use the referring prerender.
788 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
789 ASSERT_EQ(prerender_contents
, prerender_manager()->FindAndUseEntry(url
));
791 // The pending prerender still doesn't start.
792 EXPECT_FALSE(LauncherHasRunningPrerender(child_id
, last_prerender_id()));
793 EXPECT_FALSE(pending_prerender_contents
->prerendering_has_started());
796 TEST_F(PrerenderTest
, CancelPendingPrerenderTest
) {
797 GURL
url("http://www.google.com/");
798 DummyPrerenderContents
* prerender_contents
=
799 prerender_manager()->CreateNextPrerenderContents(
802 EXPECT_TRUE(AddSimplePrerender(url
));
806 ASSERT_TRUE(prerender_contents
->GetChildId(&child_id
));
807 ASSERT_TRUE(prerender_contents
->GetRouteId(&route_id
));
809 GURL
pending_url("http://news.google.com/");
811 // Schedule a pending prerender launched from the prerender.
812 prerender_link_manager()->OnAddPrerender(
813 child_id
, GetNextPrerenderID(), pending_url
, kDefaultRelTypes
,
814 Referrer(url
, blink::WebReferrerPolicyDefault
),
816 EXPECT_FALSE(LauncherHasRunningPrerender(child_id
, last_prerender_id()));
818 // Cancel the pending prerender.
819 prerender_link_manager()->OnCancelPrerender(child_id
, last_prerender_id());
821 // Use the referring prerender.
822 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
823 ASSERT_EQ(prerender_contents
, prerender_manager()->FindAndUseEntry(url
));
825 // The pending prerender doesn't start.
826 EXPECT_FALSE(LauncherHasRunningPrerender(child_id
, last_prerender_id()));
829 // Tests that a PrerenderManager created for a browser session in the control
830 // group works as expected.
831 TEST_F(PrerenderTest
, ControlGroup
) {
832 RestorePrerenderMode restore_prerender_mode
;
833 PrerenderManager::SetMode(
834 PrerenderManager::PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP
);
835 GURL
url("http://www.google.com/");
836 DummyPrerenderContents
* prerender_contents
=
837 prerender_manager()->CreateNextPrerenderContents(
839 FINAL_STATUS_MANAGER_SHUTDOWN
);
840 EXPECT_TRUE(AddSimplePrerender(url
));
841 EXPECT_FALSE(prerender_contents
->prerendering_has_started());
844 // Tests that prerendering is cancelled when the source render view does not
845 // exist. On failure, the DCHECK in CreatePrerenderContents() above should be
847 TEST_F(PrerenderTest
, SourceRenderViewClosed
) {
848 GURL
url("http://www.google.com/");
849 prerender_manager()->CreateNextPrerenderContents(
851 FINAL_STATUS_MANAGER_SHUTDOWN
);
852 prerender_link_manager()->OnAddPrerender(
853 100, GetNextPrerenderID(), url
, kDefaultRelTypes
, Referrer(), kSize
, 200);
854 EXPECT_FALSE(LauncherHasRunningPrerender(100, last_prerender_id()));
857 // Tests that prerendering doesn't launch rel=next prerenders without the field
859 TEST_F(PrerenderTest
, NoRelNextByDefault
) {
860 GURL
url("http://www.google.com/");
861 prerender_manager()->CreateNextPrerenderContents(
862 url
, FINAL_STATUS_MANAGER_SHUTDOWN
);
863 DummyPrerenderContents
* null
= NULL
;
865 prerender_link_manager()->OnAddPrerender(
866 kDefaultChildId
, GetNextPrerenderID(), url
, PrerenderRelTypeNext
,
867 Referrer(), kSize
, kDefaultRenderViewRouteId
);
868 EXPECT_EQ(null
, prerender_manager()->FindEntry(url
));
871 // Tests that prerendering does launch rel=next prerenders with the field trial.
872 TEST_F(PrerenderTest
, RelNextByFieldTrial
) {
873 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("PrerenderRelNextTrial",
875 GURL
url("http://www.google.com/");
876 DummyPrerenderContents
* prerender_contents
=
877 prerender_manager()->CreateNextPrerenderContents(
878 url
, ORIGIN_LINK_REL_NEXT
, FINAL_STATUS_USED
);
880 prerender_link_manager()->OnAddPrerender(
881 kDefaultChildId
, GetNextPrerenderID(), url
, PrerenderRelTypeNext
,
882 Referrer(), kSize
, kDefaultRenderViewRouteId
);
883 EXPECT_EQ(prerender_contents
, prerender_manager()->FindAndUseEntry(url
));
886 // Tests that prerendering is cancelled when we launch a second prerender of
887 // the same target within a short time interval.
888 TEST_F(PrerenderTest
, RecentlyVisited
) {
889 GURL
url("http://www.google.com/");
891 prerender_manager()->RecordNavigation(url
);
893 DummyPrerenderContents
* prerender_contents
=
894 prerender_manager()->CreateNextPrerenderContents(
895 url
, FINAL_STATUS_RECENTLY_VISITED
);
896 EXPECT_FALSE(AddSimplePrerender(url
));
897 EXPECT_FALSE(prerender_contents
->prerendering_has_started());
900 TEST_F(PrerenderTest
, NotSoRecentlyVisited
) {
901 GURL
url("http://www.google.com/");
903 prerender_manager()->RecordNavigation(url
);
904 prerender_manager()->AdvanceTimeTicks(
905 TimeDelta::FromMilliseconds(
906 UnitTestPrerenderManager::kNavigationRecordWindowMs
+ 500));
908 DummyPrerenderContents
* prerender_contents
=
909 prerender_manager()->CreateNextPrerenderContents(
910 url
, FINAL_STATUS_USED
);
911 EXPECT_TRUE(AddSimplePrerender(url
));
912 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
913 ASSERT_EQ(prerender_contents
, prerender_manager()->FindAndUseEntry(url
));
916 // Tests that our PPLT dummy prerender gets created properly.
917 TEST_F(PrerenderTest
, PPLTDummy
) {
918 RestorePrerenderMode restore_prerender_mode
;
919 PrerenderManager::SetMode(
920 PrerenderManager::PRERENDER_MODE_EXPERIMENT_MATCH_COMPLETE_GROUP
);
922 GURL
url("http://www.google.com/");
923 DummyPrerenderContents
* prerender_contents
=
924 prerender_manager()->CreateNextPrerenderContents(
925 url
, FINAL_STATUS_UNSUPPORTED_SCHEME
);
926 EXPECT_TRUE(AddSimplePrerender(url
));
927 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
928 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
930 DummyPrerenderContents
* pplt_dummy_contents
=
931 prerender_manager()->CreateNextPrerenderContents(url
,
933 GURL
ftp_url("ftp://ftp.google.com/");
934 // Adding this ftp URL will force the expected unsupported scheme error.
935 prerender_contents
->AddAliasURL(ftp_url
);
936 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
938 ASSERT_EQ(pplt_dummy_contents
, prerender_manager()->FindAndUseEntry(url
));
939 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
942 // Tests that our PPLT dummy prerender gets created properly, even
943 // when navigating to a page that has been recently navigated to.
944 TEST_F(PrerenderTest
, RecentlyVisitedPPLTDummy
) {
945 RestorePrerenderMode restore_prerender_mode
;
946 PrerenderManager::SetMode(
947 PrerenderManager::PRERENDER_MODE_EXPERIMENT_MATCH_COMPLETE_GROUP
);
949 GURL
url("http://www.google.com/");
950 DummyPrerenderContents
* prerender_contents
=
951 prerender_manager()->CreateNextPrerenderContents(
952 url
, FINAL_STATUS_UNSUPPORTED_SCHEME
);
953 EXPECT_TRUE(AddSimplePrerender(url
));
954 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
956 DummyPrerenderContents
* pplt_dummy_contents
=
957 prerender_manager()->CreateNextPrerenderContents(url
,
959 prerender_manager()->RecordNavigation(url
);
960 GURL
ftp_url("ftp://ftp.google.com/");
961 prerender_contents
->AddAliasURL(ftp_url
);
963 ASSERT_EQ(pplt_dummy_contents
, prerender_manager()->FindAndUseEntry(url
));
966 TEST_F(PrerenderTest
, PPLTLateCancel
) {
967 RestorePrerenderMode restore_prerender_mode
;
968 PrerenderManager::SetMode(
969 PrerenderManager::PRERENDER_MODE_EXPERIMENT_MATCH_COMPLETE_GROUP
);
971 GURL
url("http://www.google.com");
972 DummyPrerenderContents
* prerender_contents
=
973 prerender_manager()->CreateNextPrerenderContents(
974 url
, FINAL_STATUS_JAVASCRIPT_ALERT
);
975 EXPECT_TRUE(AddSimplePrerender(url
));
976 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
977 // Force the creation of a match complete dummy.
978 DummyPrerenderContents
* duplicate_prerender_contents
=
979 prerender_manager()->CreateNextPrerenderContents(url
,
980 FINAL_STATUS_CANCELLED
);
981 ASSERT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
982 prerender_contents
->Destroy(FINAL_STATUS_JAVASCRIPT_ALERT
);
983 ASSERT_EQ(duplicate_prerender_contents
, prerender_manager()->FindEntry(url
));
985 // Make sure that events on prerender handles propogate to the match
986 // complete replacement.
987 DummyPrerenderContents
* null
= NULL
;
988 prerender_link_manager()->OnCancelPrerender(kDefaultChildId
,
989 last_prerender_id());
990 ASSERT_EQ(null
, prerender_manager()->FindEntry(url
));
993 // Tests that the prerender manager matches include the fragment.
994 TEST_F(PrerenderTest
, FragmentMatchesTest
) {
995 GURL
fragment_url("http://www.google.com/#test");
997 DummyPrerenderContents
* prerender_contents
=
998 prerender_manager()->CreateNextPrerenderContents(fragment_url
,
1000 EXPECT_TRUE(AddSimplePrerender(fragment_url
));
1001 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
1002 ASSERT_EQ(prerender_contents
,
1003 prerender_manager()->FindAndUseEntry(fragment_url
));
1006 // Tests that the prerender manager uses fragment references when matching
1007 // prerender URLs in the case a different fragment is in both URLs.
1008 TEST_F(PrerenderTest
, FragmentsDifferTest
) {
1009 GURL
fragment_url("http://www.google.com/#test");
1010 GURL
other_fragment_url("http://www.google.com/#other_test");
1012 DummyPrerenderContents
* prerender_contents
=
1013 prerender_manager()->CreateNextPrerenderContents(fragment_url
,
1015 EXPECT_TRUE(AddSimplePrerender(fragment_url
));
1016 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
1018 DummyPrerenderContents
* null
= NULL
;
1019 ASSERT_EQ(null
, prerender_manager()->FindEntry(other_fragment_url
));
1021 ASSERT_EQ(prerender_contents
,
1022 prerender_manager()->FindAndUseEntry(fragment_url
));
1025 // Make sure that clearing works as expected.
1026 TEST_F(PrerenderTest
, ClearTest
) {
1027 GURL
url("http://www.google.com/");
1028 DummyPrerenderContents
* prerender_contents
=
1029 prerender_manager()->CreateNextPrerenderContents(
1031 FINAL_STATUS_CACHE_OR_HISTORY_CLEARED
);
1032 EXPECT_TRUE(AddSimplePrerender(url
));
1033 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
1034 prerender_manager()->ClearData(PrerenderManager::CLEAR_PRERENDER_CONTENTS
);
1035 DummyPrerenderContents
* null
= NULL
;
1036 EXPECT_EQ(null
, prerender_manager()->FindEntry(url
));
1039 // Make sure canceling works as expected.
1040 TEST_F(PrerenderTest
, CancelAllTest
) {
1041 GURL
url("http://www.google.com/");
1042 DummyPrerenderContents
* prerender_contents
=
1043 prerender_manager()->CreateNextPrerenderContents(
1044 url
, FINAL_STATUS_CANCELLED
);
1045 EXPECT_TRUE(AddSimplePrerender(url
));
1046 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
1047 prerender_manager()->CancelAllPrerenders();
1048 const DummyPrerenderContents
* null
= NULL
;
1049 EXPECT_EQ(null
, prerender_manager()->FindEntry(url
));
1052 TEST_F(PrerenderTest
, OmniboxNotAllowedWhenDisabled
) {
1054 EXPECT_FALSE(prerender_manager()->AddPrerenderFromOmnibox(
1055 GURL("http://www.example.com"), NULL
, gfx::Size()));
1058 TEST_F(PrerenderTest
, LinkRelNotAllowedWhenDisabled
) {
1060 EXPECT_FALSE(AddSimplePrerender(
1061 GURL("http://www.example.com")));
1064 TEST_F(PrerenderTest
, LinkManagerCancel
) {
1065 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1066 GURL
url("http://www.myexample.com");
1067 DummyPrerenderContents
* prerender_contents
=
1068 prerender_manager()->CreateNextPrerenderContents(
1069 url
, FINAL_STATUS_CANCELLED
);
1071 EXPECT_TRUE(AddSimplePrerender(url
));
1073 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
1074 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
1075 ASSERT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
1076 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
1077 prerender_link_manager()->OnCancelPrerender(kDefaultChildId
,
1078 last_prerender_id());
1080 EXPECT_TRUE(prerender_contents
->prerendering_has_been_cancelled());
1081 DummyPrerenderContents
* null
= NULL
;
1082 ASSERT_EQ(null
, prerender_manager()->FindEntry(url
));
1083 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1086 TEST_F(PrerenderTest
, LinkManagerCancelThenAbandon
) {
1087 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1088 GURL
url("http://www.myexample.com");
1089 DummyPrerenderContents
* prerender_contents
=
1090 prerender_manager()->CreateNextPrerenderContents(
1091 url
, FINAL_STATUS_CANCELLED
);
1093 EXPECT_TRUE(AddSimplePrerender(url
));
1095 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
1096 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
1097 ASSERT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
1098 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
1099 prerender_link_manager()->OnCancelPrerender(kDefaultChildId
,
1100 last_prerender_id());
1102 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1103 EXPECT_TRUE(prerender_contents
->prerendering_has_been_cancelled());
1104 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId
,
1105 last_prerender_id());
1107 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1108 EXPECT_TRUE(prerender_contents
->prerendering_has_been_cancelled());
1109 DummyPrerenderContents
* null
= NULL
;
1110 ASSERT_EQ(null
, prerender_manager()->FindEntry(url
));
1113 TEST_F(PrerenderTest
, LinkManagerAbandon
) {
1114 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1115 GURL
url("http://www.myexample.com");
1116 DummyPrerenderContents
* prerender_contents
=
1117 prerender_manager()->CreateNextPrerenderContents(
1118 url
, FINAL_STATUS_USED
);
1120 EXPECT_TRUE(AddSimplePrerender(url
));
1122 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
1123 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
1124 ASSERT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
1125 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
1126 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId
,
1127 last_prerender_id());
1129 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
1130 ASSERT_EQ(prerender_contents
, prerender_manager()->FindAndUseEntry(url
));
1133 TEST_F(PrerenderTest
, LinkManagerAbandonThenCancel
) {
1134 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1135 GURL
url("http://www.myexample.com");
1136 DummyPrerenderContents
* prerender_contents
=
1137 prerender_manager()->CreateNextPrerenderContents(
1138 url
, FINAL_STATUS_CANCELLED
);
1140 EXPECT_TRUE(AddSimplePrerender(url
));
1142 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
1143 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
1144 ASSERT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
1145 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
1146 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId
,
1147 last_prerender_id());
1149 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
1150 ASSERT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
1152 prerender_link_manager()->OnCancelPrerender(kDefaultChildId
,
1153 last_prerender_id());
1154 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1155 EXPECT_TRUE(prerender_contents
->prerendering_has_been_cancelled());
1156 DummyPrerenderContents
* null
= NULL
;
1157 ASSERT_EQ(null
, prerender_manager()->FindEntry(url
));
1160 TEST_F(PrerenderTest
, LinkManagerCancelTwice
) {
1161 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1162 GURL
url("http://www.myexample.com");
1163 DummyPrerenderContents
* prerender_contents
=
1164 prerender_manager()->CreateNextPrerenderContents(
1165 url
, FINAL_STATUS_CANCELLED
);
1167 EXPECT_TRUE(AddSimplePrerender(url
));
1168 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
1169 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
1170 EXPECT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
1171 prerender_link_manager()->OnCancelPrerender(kDefaultChildId
,
1172 last_prerender_id());
1174 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1175 EXPECT_TRUE(prerender_contents
->prerendering_has_been_cancelled());
1176 DummyPrerenderContents
* null
= NULL
;
1177 ASSERT_EQ(null
, prerender_manager()->FindEntry(url
));
1178 prerender_link_manager()->OnCancelPrerender(kDefaultChildId
,
1179 last_prerender_id());
1182 TEST_F(PrerenderTest
, LinkManagerAddTwiceCancelTwice
) {
1184 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1185 GURL
url("http://www.myexample.com");
1186 DummyPrerenderContents
* prerender_contents
=
1187 prerender_manager()->CreateNextPrerenderContents(
1188 url
, FINAL_STATUS_CANCELLED
);
1190 EXPECT_TRUE(AddSimplePrerender(url
));
1192 const int first_prerender_id
= last_prerender_id();
1193 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
1194 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
1195 EXPECT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
1196 EXPECT_TRUE(AddSimplePrerender(url
));
1198 const int second_prerender_id
= last_prerender_id();
1199 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
1200 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
1201 EXPECT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
1202 prerender_link_manager()->OnCancelPrerender(kDefaultChildId
,
1203 first_prerender_id
);
1205 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
1206 EXPECT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
1207 prerender_link_manager()->OnCancelPrerender(kDefaultChildId
,
1208 second_prerender_id
);
1210 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1211 EXPECT_TRUE(prerender_contents
->prerendering_has_been_cancelled());
1212 DummyPrerenderContents
* null
= NULL
;
1213 ASSERT_EQ(null
, prerender_manager()->FindEntry(url
));
1216 TEST_F(PrerenderTest
, LinkManagerAddTwiceCancelTwiceThenAbandonTwice
) {
1218 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1219 GURL
url("http://www.myexample.com");
1220 DummyPrerenderContents
* prerender_contents
=
1221 prerender_manager()->CreateNextPrerenderContents(
1222 url
, FINAL_STATUS_CANCELLED
);
1224 EXPECT_TRUE(AddSimplePrerender(url
));
1226 const int first_prerender_id
= last_prerender_id();
1227 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
1228 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
1229 ASSERT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
1230 EXPECT_TRUE(AddSimplePrerender(url
));
1232 const int second_prerender_id
= last_prerender_id();
1233 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
1234 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
1235 ASSERT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
1236 prerender_link_manager()->OnCancelPrerender(kDefaultChildId
,
1237 first_prerender_id
);
1239 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
1240 ASSERT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
1241 prerender_link_manager()->OnCancelPrerender(kDefaultChildId
,
1242 second_prerender_id
);
1244 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1245 EXPECT_TRUE(prerender_contents
->prerendering_has_been_cancelled());
1246 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId
,
1247 first_prerender_id
);
1249 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1250 EXPECT_TRUE(prerender_contents
->prerendering_has_been_cancelled());
1251 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId
,
1252 second_prerender_id
);
1254 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1255 EXPECT_TRUE(prerender_contents
->prerendering_has_been_cancelled());
1256 DummyPrerenderContents
* null
= NULL
;
1257 ASSERT_EQ(null
, prerender_manager()->FindEntry(url
));
1260 // TODO(gavinp): Update this test after abandon has an effect on Prerenders,
1261 // like shortening the timeouts.
1262 TEST_F(PrerenderTest
, LinkManagerAddTwiceAbandonTwiceUseTwice
) {
1264 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1265 GURL
url("http://www.myexample.com");
1266 DummyPrerenderContents
* prerender_contents
=
1267 prerender_manager()->CreateNextPrerenderContents(
1268 url
, FINAL_STATUS_USED
);
1270 EXPECT_TRUE(AddSimplePrerender(url
));
1272 const int first_prerender_id
= last_prerender_id();
1273 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
1274 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
1275 ASSERT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
1276 EXPECT_TRUE(AddSimplePrerender(url
));
1278 const int second_prerender_id
= last_prerender_id();
1279 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
1280 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
1281 ASSERT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
1282 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId
,
1283 first_prerender_id
);
1285 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
1286 ASSERT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
1287 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId
,
1288 second_prerender_id
);
1290 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
1291 ASSERT_EQ(prerender_contents
, prerender_manager()->FindAndUseEntry(url
));
1292 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1295 // TODO(gavinp): After abandon shortens the expire time on a Prerender,
1296 // add a series of tests testing advancing the time by either the abandon
1297 // or normal expire, and verifying the expected behaviour with groups
1299 TEST_F(PrerenderTest
, LinkManagerExpireThenCancel
) {
1300 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1301 GURL
url("http://www.myexample.com");
1302 DummyPrerenderContents
* prerender_contents
=
1303 prerender_manager()->CreateNextPrerenderContents(
1304 url
, FINAL_STATUS_TIMED_OUT
);
1306 EXPECT_TRUE(AddSimplePrerender(url
));
1308 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
1309 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
1310 ASSERT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
1311 prerender_manager()->AdvanceTimeTicks(
1312 prerender_manager()->config().time_to_live
+ TimeDelta::FromSeconds(1));
1314 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
1315 DummyPrerenderContents
* null
= NULL
;
1316 ASSERT_EQ(null
, prerender_manager()->FindEntry(url
));
1317 prerender_link_manager()->OnCancelPrerender(kDefaultChildId
,
1318 last_prerender_id());
1320 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1321 ASSERT_EQ(null
, prerender_manager()->FindEntry(url
));
1324 TEST_F(PrerenderTest
, LinkManagerExpireThenAddAgain
) {
1325 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1326 GURL
url("http://www.myexample.com");
1327 DummyPrerenderContents
* first_prerender_contents
=
1328 prerender_manager()->CreateNextPrerenderContents(
1329 url
, FINAL_STATUS_TIMED_OUT
);
1330 EXPECT_TRUE(AddSimplePrerender(url
));
1331 EXPECT_TRUE(first_prerender_contents
->prerendering_has_started());
1332 EXPECT_FALSE(first_prerender_contents
->prerendering_has_been_cancelled());
1333 ASSERT_EQ(first_prerender_contents
,
1334 prerender_manager()->FindEntry(url
));
1335 prerender_manager()->AdvanceTimeTicks(
1336 prerender_manager()->config().time_to_live
+ TimeDelta::FromSeconds(1));
1337 DummyPrerenderContents
* null
= NULL
;
1338 ASSERT_EQ(null
, prerender_manager()->FindEntry(url
));
1339 DummyPrerenderContents
* second_prerender_contents
=
1340 prerender_manager()->CreateNextPrerenderContents(
1341 url
, FINAL_STATUS_USED
);
1342 EXPECT_TRUE(AddSimplePrerender(url
));
1343 EXPECT_TRUE(second_prerender_contents
->prerendering_has_started());
1344 ASSERT_EQ(second_prerender_contents
,
1345 prerender_manager()->FindAndUseEntry(url
));
1348 TEST_F(PrerenderTest
, LinkManagerCancelThenAddAgain
) {
1349 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1350 GURL
url("http://www.myexample.com");
1351 DummyPrerenderContents
* first_prerender_contents
=
1352 prerender_manager()->CreateNextPrerenderContents(
1353 url
, FINAL_STATUS_CANCELLED
);
1354 EXPECT_TRUE(AddSimplePrerender(url
));
1355 EXPECT_TRUE(first_prerender_contents
->prerendering_has_started());
1356 EXPECT_FALSE(first_prerender_contents
->prerendering_has_been_cancelled());
1357 ASSERT_EQ(first_prerender_contents
, prerender_manager()->FindEntry(url
));
1358 prerender_link_manager()->OnCancelPrerender(kDefaultChildId
,
1359 last_prerender_id());
1360 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1361 EXPECT_TRUE(first_prerender_contents
->prerendering_has_been_cancelled());
1362 DummyPrerenderContents
* null
= NULL
;
1363 ASSERT_EQ(null
, prerender_manager()->FindEntry(url
));
1364 DummyPrerenderContents
* second_prerender_contents
=
1365 prerender_manager()->CreateNextPrerenderContents(
1366 url
, FINAL_STATUS_USED
);
1367 EXPECT_TRUE(AddSimplePrerender(url
));
1368 EXPECT_TRUE(second_prerender_contents
->prerendering_has_started());
1369 ASSERT_EQ(second_prerender_contents
,
1370 prerender_manager()->FindAndUseEntry(url
));
1373 TEST_F(PrerenderTest
, LinkManagerChannelClosing
) {
1374 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1375 GURL
url("http://www.myexample.com");
1376 DummyPrerenderContents
* prerender_contents
=
1377 prerender_manager()->CreateNextPrerenderContents(
1378 url
, FINAL_STATUS_TIMED_OUT
);
1380 EXPECT_TRUE(AddSimplePrerender(url
));
1381 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
1382 EXPECT_FALSE(prerender_contents
->prerendering_has_been_cancelled());
1383 ASSERT_EQ(prerender_contents
, prerender_manager()->FindEntry(url
));
1385 prerender_link_manager()->OnChannelClosing(kDefaultChildId
);
1387 prerender_manager()->AdvanceTimeTicks(
1388 prerender_manager()->config().abandon_time_to_live
+
1389 TimeDelta::FromSeconds(1));
1391 DummyPrerenderContents
* null
= NULL
;
1392 EXPECT_EQ(null
, prerender_manager()->FindEntry(url
));
1393 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1396 // Creates two prerenders, one of which should be blocked by the
1397 // max_link_concurrency; abandons both of them and waits to make sure both
1398 // are cleared from the PrerenderLinkManager.
1399 TEST_F(PrerenderTest
, LinkManagerAbandonInactivePrerender
) {
1401 ASSERT_LT(prerender_manager()->config().abandon_time_to_live
,
1402 prerender_manager()->config().time_to_live
);
1403 GURL
first_url("http://www.myexample.com");
1404 DummyPrerenderContents
* prerender_contents
=
1405 prerender_manager()->CreateNextPrerenderContents(
1406 first_url
, FINAL_STATUS_TIMED_OUT
);
1407 EXPECT_TRUE(AddSimplePrerender(first_url
));
1408 const int first_prerender_id
= last_prerender_id();
1410 GURL
second_url("http://www.neverlaunched.com");
1411 EXPECT_FALSE(AddSimplePrerender(second_url
));
1412 const int second_prerender_id
= last_prerender_id();
1414 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
1416 DummyPrerenderContents
* null
= NULL
;
1417 EXPECT_EQ(prerender_contents
, prerender_manager()->FindEntry(first_url
));
1418 EXPECT_EQ(null
, prerender_manager()->FindEntry(second_url
));
1420 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId
,
1421 first_prerender_id
);
1422 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId
,
1423 second_prerender_id
);
1425 prerender_manager()->AdvanceTimeTicks(
1426 prerender_manager()->config().abandon_time_to_live
+
1427 TimeDelta::FromSeconds(1));
1428 EXPECT_EQ(null
, prerender_manager()->FindEntry(first_url
));
1429 EXPECT_EQ(null
, prerender_manager()->FindEntry(second_url
));
1430 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1433 // Creates two prerenders, the second one started by the first, both of which
1434 // should be blocked by max_concurrency; abandons both of them and waits to make
1435 // sure both are cleared from the PrerenderLinkManager.
1436 TEST_F(PrerenderTest
, LinkManagerClearOnPendingAbandon
) {
1438 ASSERT_LT(prerender_manager()->config().abandon_time_to_live
,
1439 prerender_manager()->config().time_to_live
);
1440 GURL
first_url("http://www.myexample.com");
1441 DummyPrerenderContents
* prerender_contents
=
1442 prerender_manager()->CreateNextPrerenderContents(
1443 first_url
, FINAL_STATUS_TIMED_OUT
);
1444 EXPECT_TRUE(AddSimplePrerender(first_url
));
1445 const int first_prerender_id
= last_prerender_id();
1449 ASSERT_TRUE(prerender_contents
->GetChildId(&child_id
));
1450 ASSERT_TRUE(prerender_contents
->GetRouteId(&route_id
));
1452 GURL
pending_url("http://www.neverlaunched.com");
1453 prerender_link_manager()->OnAddPrerender(
1454 child_id
, GetNextPrerenderID(), pending_url
, kDefaultRelTypes
,
1455 content::Referrer(), kSize
, route_id
);
1456 const int second_prerender_id
= last_prerender_id();
1458 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
1460 DummyPrerenderContents
* null
= NULL
;
1461 EXPECT_EQ(prerender_contents
, prerender_manager()->FindEntry(first_url
));
1462 EXPECT_EQ(null
, prerender_manager()->FindEntry(pending_url
));
1464 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId
,
1465 first_prerender_id
);
1466 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId
,
1467 second_prerender_id
);
1469 prerender_manager()->AdvanceTimeTicks(
1470 prerender_manager()->config().abandon_time_to_live
+
1471 TimeDelta::FromSeconds(1));
1472 EXPECT_EQ(null
, prerender_manager()->FindEntry(first_url
));
1473 EXPECT_EQ(null
, prerender_manager()->FindEntry(pending_url
));
1474 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1477 // Creates two prerenders, one of which should be blocked by the
1478 // max_link_concurrency; uses one after the max wait to launch, and
1479 // ensures the second prerender does not start.
1480 TEST_F(PrerenderTest
, LinkManagerWaitToLaunchNotLaunched
) {
1482 ASSERT_LT(prerender_manager()->config().max_wait_to_launch
,
1483 prerender_manager()->config().time_to_live
);
1484 GURL
first_url("http://www.myexample.com");
1485 DummyPrerenderContents
* prerender_contents
=
1486 prerender_manager()->CreateNextPrerenderContents(
1487 first_url
, FINAL_STATUS_USED
);
1488 EXPECT_TRUE(AddSimplePrerender(first_url
));
1490 GURL
second_url("http://www.neverlaunched.com");
1491 EXPECT_FALSE(AddSimplePrerender(second_url
));
1493 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
1495 DummyPrerenderContents
* null
= NULL
;
1496 EXPECT_EQ(prerender_contents
, prerender_manager()->FindEntry(first_url
));
1497 EXPECT_EQ(null
, prerender_manager()->FindEntry(second_url
));
1499 prerender_manager()->AdvanceTimeTicks(
1500 prerender_manager()->config().max_wait_to_launch
+
1501 TimeDelta::FromSeconds(1));
1502 EXPECT_EQ(prerender_contents
, prerender_manager()->FindEntry(first_url
));
1503 EXPECT_EQ(null
, prerender_manager()->FindEntry(second_url
));
1505 EXPECT_EQ(prerender_contents
,
1506 prerender_manager()->FindAndUseEntry(first_url
));
1508 EXPECT_EQ(null
, prerender_manager()->FindEntry(first_url
));
1509 EXPECT_EQ(null
, prerender_manager()->FindEntry(second_url
));
1510 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1513 // Creates two prerenders, one of which should start when the first one expires.
1514 TEST_F(PrerenderTest
, LinkManagerExpireRevealingLaunch
) {
1516 ASSERT_LT(prerender_manager()->config().max_wait_to_launch
,
1517 prerender_manager()->config().time_to_live
);
1519 GURL
first_url("http://www.willexpire.com");
1520 DummyPrerenderContents
* first_prerender_contents
=
1521 prerender_manager()->CreateNextPrerenderContents(
1522 first_url
, FINAL_STATUS_TIMED_OUT
);
1523 EXPECT_TRUE(AddSimplePrerender(first_url
));
1524 EXPECT_EQ(first_prerender_contents
,
1525 prerender_manager()->FindEntry(first_url
));
1527 // Insert the second prerender so it will be still be launchable when the
1529 const TimeDelta wait_to_launch_second_prerender
=
1530 prerender_manager()->config().time_to_live
-
1531 prerender_manager()->config().max_wait_to_launch
+
1532 TimeDelta::FromSeconds(2);
1533 const TimeDelta wait_for_first_prerender_to_expire
=
1534 prerender_manager()->config().time_to_live
-
1535 wait_to_launch_second_prerender
+
1536 TimeDelta::FromSeconds(1);
1537 ASSERT_LT(prerender_manager()->config().time_to_live
,
1538 wait_to_launch_second_prerender
+
1539 wait_for_first_prerender_to_expire
);
1540 ASSERT_GT(prerender_manager()->config().max_wait_to_launch
.InSeconds(),
1541 wait_for_first_prerender_to_expire
.InSeconds());
1543 prerender_manager()->AdvanceTimeTicks(wait_to_launch_second_prerender
);
1544 GURL
second_url("http://www.willlaunch.com");
1545 DummyPrerenderContents
* second_prerender_contents
=
1546 prerender_manager()->CreateNextPrerenderContents(
1547 second_url
, FINAL_STATUS_USED
);
1548 EXPECT_FALSE(AddSimplePrerender(second_url
));
1550 // The first prerender is still running, but the second has not yet launched.
1551 EXPECT_EQ(first_prerender_contents
,
1552 prerender_manager()->FindEntry(first_url
));
1553 PrerenderContents
* null
= NULL
;
1554 EXPECT_EQ(null
, prerender_manager()->FindEntry(second_url
));
1556 // The first prerender should have died, giving life to the second one.
1557 prerender_manager()->AdvanceTimeTicks(wait_for_first_prerender_to_expire
);
1558 EXPECT_EQ(null
, prerender_manager()->FindEntry(first_url
));
1559 EXPECT_EQ(second_prerender_contents
,
1560 prerender_manager()->FindAndUseEntry(second_url
));
1563 TEST_F(PrerenderTest
, InstantSearchNotAllowedWhenDisabled
) {
1564 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
1566 "Group82 espv:8 use_cacheable_ntp:1 prefetch_results:1"));
1568 EXPECT_FALSE(prerender_manager()->AddPrerenderForInstant(
1569 GURL("http://www.example.com/instant_search"), NULL
, gfx::Size()));
1572 TEST_F(PrerenderTest
, PrerenderContentsForInstantSearch
) {
1573 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
1575 "Group82 espv:8 use_cacheable_ntp:1 prefetch_results:1"));
1576 GURL
url("http://www.example.com/instant_search");
1577 DummyPrerenderContents
* prerender_contents
=
1578 prerender_manager()->CreateNextPrerenderContents(url
, ORIGIN_INSTANT
,
1580 scoped_ptr
<PrerenderHandle
> prerender_handle(
1581 prerender_manager()->AddPrerenderForInstant(url
, NULL
, kSize
));
1582 CHECK(prerender_handle
.get());
1583 EXPECT_TRUE(prerender_handle
->IsPrerendering());
1584 EXPECT_TRUE(prerender_contents
->prerendering_has_started());
1585 EXPECT_EQ(prerender_contents
, prerender_handle
->contents());
1586 EXPECT_EQ(ORIGIN_INSTANT
, prerender_handle
->contents()->origin());
1587 ASSERT_EQ(prerender_contents
, prerender_manager()->FindAndUseEntry(url
));
1588 EXPECT_FALSE(prerender_handle
->IsPrerendering());
1591 } // namespace prerender