Give names to all utility processes.
[chromium-blink-merge.git] / chrome / browser / prerender / prerender_unittest.cc
blob9d226155dc4916d1f3694d436125690ee2382f7e
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.
5 #include <map>
6 #include <utility>
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_field_trial.h"
19 #include "chrome/browser/prerender/prerender_handle.h"
20 #include "chrome/browser/prerender/prerender_link_manager.h"
21 #include "chrome/browser/prerender/prerender_manager.h"
22 #include "chrome/browser/prerender/prerender_origin.h"
23 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/pref_names.h"
25 #include "chrome/common/prerender_types.h"
26 #include "chrome/test/base/testing_browser_process.h"
27 #include "chrome/test/base/testing_profile.h"
28 #include "content/public/browser/render_view_host.h"
29 #include "content/public/test/test_browser_thread.h"
30 #include "testing/gtest/include/gtest/gtest.h"
31 #include "ui/gfx/geometry/size.h"
32 #include "url/gurl.h"
34 using base::Time;
35 using base::TimeDelta;
36 using base::TimeTicks;
37 using content::BrowserThread;
38 using content::Referrer;
40 namespace prerender {
42 class UnitTestPrerenderManager;
44 namespace {
46 class DummyPrerenderContents : public PrerenderContents {
47 public:
48 DummyPrerenderContents(UnitTestPrerenderManager* test_prerender_manager,
49 const GURL& url,
50 Origin origin,
51 FinalStatus expected_final_status);
53 ~DummyPrerenderContents() override;
55 void StartPrerendering(
56 const gfx::Size& size,
57 content::SessionStorageNamespace* session_storage_namespace) override;
59 bool GetChildId(int* child_id) const override {
60 // Having a default child_id of -1 forces pending prerenders not to fail
61 // on session storage and cross domain checking.
62 *child_id = -1;
63 return true;
66 bool GetRouteId(int* route_id) const override {
67 *route_id = route_id_;
68 return true;
71 FinalStatus expected_final_status() const { return expected_final_status_; }
73 bool prerendering_has_been_cancelled() const {
74 return PrerenderContents::prerendering_has_been_cancelled();
77 private:
78 static int g_next_route_id_;
79 int route_id_;
81 UnitTestPrerenderManager* test_prerender_manager_;
82 FinalStatus expected_final_status_;
85 int DummyPrerenderContents::g_next_route_id_ = 0;
87 const gfx::Size kSize(640, 480);
89 const uint32 kDefaultRelTypes = PrerenderRelTypePrerender;
91 } // namespace
93 class UnitTestPrerenderManager : public PrerenderManager {
94 public:
95 using PrerenderManager::kMinTimeBetweenPrerendersMs;
96 using PrerenderManager::kNavigationRecordWindowMs;
98 explicit UnitTestPrerenderManager(Profile* profile)
99 : PrerenderManager(profile),
100 time_(Time::Now()),
101 time_ticks_(TimeTicks::Now()) {
102 set_rate_limit_enabled(false);
105 ~UnitTestPrerenderManager() override {}
107 // From KeyedService, via PrererenderManager:
108 void Shutdown() override {
109 if (next_prerender_contents())
110 next_prerender_contents_->Destroy(FINAL_STATUS_MANAGER_SHUTDOWN);
111 PrerenderManager::Shutdown();
114 // From PrerenderManager:
115 void MoveEntryToPendingDelete(PrerenderContents* entry,
116 FinalStatus final_status) override {
117 if (entry == next_prerender_contents_.get())
118 return;
119 PrerenderManager::MoveEntryToPendingDelete(entry, final_status);
122 PrerenderContents* FindEntry(const GURL& url) {
123 DeleteOldEntries();
124 to_delete_prerenders_.clear();
125 if (PrerenderData* data = FindPrerenderData(url, NULL))
126 return data->contents();
127 return NULL;
130 PrerenderContents* FindAndUseEntry(const GURL& url) {
131 PrerenderData* prerender_data = FindPrerenderData(url, NULL);
132 if (!prerender_data)
133 return NULL;
134 ScopedVector<PrerenderData>::iterator to_erase =
135 FindIteratorForPrerenderContents(prerender_data->contents());
136 CHECK(to_erase != active_prerenders_.end());
137 PrerenderContents* prerender_contents = prerender_data->ReleaseContents();
138 active_prerenders_.erase(to_erase);
140 prerender_contents->PrepareForUse();
141 return prerender_contents;
144 void AdvanceTime(TimeDelta delta) {
145 time_ += delta;
148 void AdvanceTimeTicks(TimeDelta delta) {
149 time_ticks_ += delta;
152 DummyPrerenderContents* CreateNextPrerenderContents(
153 const GURL& url,
154 FinalStatus expected_final_status) {
155 DummyPrerenderContents* prerender_contents =
156 new DummyPrerenderContents(this, url,
157 ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN,
158 expected_final_status);
159 SetNextPrerenderContents(prerender_contents);
160 return prerender_contents;
163 DummyPrerenderContents* CreateNextPrerenderContents(
164 const GURL& url,
165 Origin origin,
166 FinalStatus expected_final_status) {
167 DummyPrerenderContents* prerender_contents =
168 new DummyPrerenderContents(this, url, origin, expected_final_status);
169 SetNextPrerenderContents(prerender_contents);
170 return prerender_contents;
173 DummyPrerenderContents* CreateNextPrerenderContents(
174 const GURL& url,
175 const std::vector<GURL>& alias_urls,
176 FinalStatus expected_final_status) {
177 DummyPrerenderContents* prerender_contents =
178 new DummyPrerenderContents(this, url,
179 ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN,
180 expected_final_status);
181 for (std::vector<GURL>::const_iterator it = alias_urls.begin();
182 it != alias_urls.end();
183 ++it) {
184 EXPECT_TRUE(prerender_contents->AddAliasURL(*it));
186 SetNextPrerenderContents(prerender_contents);
187 return prerender_contents;
190 void set_rate_limit_enabled(bool enabled) {
191 mutable_config().rate_limit_enabled = enabled;
194 PrerenderContents* next_prerender_contents() {
195 return next_prerender_contents_.get();
198 // from PrerenderManager
199 Time GetCurrentTime() const override { return time_; }
201 TimeTicks GetCurrentTimeTicks() const override { return time_ticks_; }
203 PrerenderContents* GetPrerenderContentsForRoute(int child_id,
204 int route_id) const override {
205 // Overridden for the PrerenderLinkManager's pending prerender logic.
206 PrerenderContentsMap::const_iterator iter = prerender_contents_map_.find(
207 std::make_pair(child_id, route_id));
208 if (iter == prerender_contents_map_.end())
209 return NULL;
210 return iter->second;
213 void DummyPrerenderContentsStarted(int child_id,
214 int route_id,
215 PrerenderContents* prerender_contents) {
216 prerender_contents_map_[std::make_pair(child_id, route_id)] =
217 prerender_contents;
220 void DummyPrerenderContentsDestroyed(int child_id,
221 int route_id) {
222 prerender_contents_map_.erase(std::make_pair(child_id, route_id));
225 private:
226 void SetNextPrerenderContents(DummyPrerenderContents* prerender_contents) {
227 CHECK(!next_prerender_contents_.get());
228 next_prerender_contents_.reset(prerender_contents);
229 if (prerender_contents->expected_final_status() == FINAL_STATUS_USED)
230 used_prerender_contents_.push_back(prerender_contents);
233 PrerenderContents* CreatePrerenderContents(const GURL& url,
234 const Referrer& referrer,
235 Origin origin,
236 uint8 experiment_id) override {
237 CHECK(next_prerender_contents_.get());
238 EXPECT_EQ(url, next_prerender_contents_->prerender_url());
239 EXPECT_EQ(origin, next_prerender_contents_->origin());
240 return next_prerender_contents_.release();
243 // Maintain a map from route pairs to PrerenderContents for
244 // GetPrerenderContentsForRoute.
245 typedef std::map<std::pair<int,int>, PrerenderContents*> PrerenderContentsMap;
246 PrerenderContentsMap prerender_contents_map_;
248 Time time_;
249 TimeTicks time_ticks_;
250 scoped_ptr<PrerenderContents> next_prerender_contents_;
251 // PrerenderContents with an |expected_final_status| of FINAL_STATUS_USED,
252 // tracked so they will be automatically deleted.
253 ScopedVector<PrerenderContents> used_prerender_contents_;
256 class RestorePrerenderMode {
257 public:
258 RestorePrerenderMode() : prev_mode_(PrerenderManager::GetMode()) {
261 ~RestorePrerenderMode() { PrerenderManager::SetMode(prev_mode_); }
262 private:
263 PrerenderManager::PrerenderManagerMode prev_mode_;
266 DummyPrerenderContents::DummyPrerenderContents(
267 UnitTestPrerenderManager* test_prerender_manager,
268 const GURL& url,
269 Origin origin,
270 FinalStatus expected_final_status)
271 : PrerenderContents(test_prerender_manager,
272 NULL, url, Referrer(), origin,
273 PrerenderManager::kNoExperiment),
274 route_id_(g_next_route_id_++),
275 test_prerender_manager_(test_prerender_manager),
276 expected_final_status_(expected_final_status) {
279 DummyPrerenderContents::~DummyPrerenderContents() {
280 EXPECT_EQ(expected_final_status_, final_status());
281 test_prerender_manager_->DummyPrerenderContentsDestroyed(-1, route_id_);
284 void DummyPrerenderContents::StartPrerendering(
285 const gfx::Size& size,
286 content::SessionStorageNamespace* session_storage_namespace) {
287 // In the base PrerenderContents implementation, StartPrerendering will
288 // be called even when the PrerenderManager is part of the control group,
289 // but it will early exit before actually creating a new RenderView if
290 // |is_control_group| is true;
291 load_start_time_ = test_prerender_manager_->GetCurrentTimeTicks();
292 if (!test_prerender_manager_->IsControlGroup(experiment_id())) {
293 prerendering_has_started_ = true;
294 test_prerender_manager_->DummyPrerenderContentsStarted(-1, route_id_, this);
295 NotifyPrerenderStart();
299 class PrerenderTest : public testing::Test {
300 public:
301 static const int kDefaultChildId = -1;
302 static const int kDefaultRenderViewRouteId = -1;
304 PrerenderTest() : ui_thread_(BrowserThread::UI, &message_loop_),
305 prerender_manager_(new UnitTestPrerenderManager(&profile_)),
306 prerender_link_manager_(
307 new PrerenderLinkManager(prerender_manager_.get())),
308 last_prerender_id_(0),
309 field_trial_list_(NULL) {
310 // Enable omnibox prerendering.
311 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
312 switches::kPrerenderFromOmnibox,
313 switches::kPrerenderFromOmniboxSwitchValueEnabled);
316 ~PrerenderTest() override {
317 prerender_link_manager_->OnChannelClosing(kDefaultChildId);
318 prerender_link_manager_->Shutdown();
319 prerender_manager_->Shutdown();
322 UnitTestPrerenderManager* prerender_manager() {
323 return prerender_manager_.get();
326 PrerenderLinkManager* prerender_link_manager() {
327 return prerender_link_manager_.get();
330 void SetConcurrency(size_t concurrency) {
331 prerender_manager()->mutable_config().max_link_concurrency_per_launcher =
332 concurrency;
333 prerender_manager()->mutable_config().max_link_concurrency =
334 std::max(prerender_manager()->mutable_config().max_link_concurrency,
335 concurrency);
338 bool IsEmptyPrerenderLinkManager() const {
339 return prerender_link_manager_->IsEmpty();
342 int last_prerender_id() const {
343 return last_prerender_id_;
346 int GetNextPrerenderID() {
347 return ++last_prerender_id_;
350 bool LauncherHasRunningPrerender(int child_id, int prerender_id) {
351 PrerenderLinkManager::LinkPrerender* prerender =
352 prerender_link_manager()->FindByLauncherChildIdAndPrerenderId(
353 child_id, prerender_id);
354 return prerender && prerender->handle;
357 bool LauncherHasScheduledPrerender(int child_id, int prerender_id) {
358 PrerenderLinkManager::LinkPrerender* prerender =
359 prerender_link_manager()->FindByLauncherChildIdAndPrerenderId(
360 child_id, prerender_id);
361 return prerender != NULL;
364 // Shorthand to add a simple prerender with a reasonable source. Returns
365 // true iff the prerender has been added to the PrerenderManager by the
366 // PrerenderLinkManager and the PrerenderManager returned a handle.
367 bool AddSimplePrerender(const GURL& url) {
368 prerender_link_manager()->OnAddPrerender(
369 kDefaultChildId, GetNextPrerenderID(), url, kDefaultRelTypes,
370 content::Referrer(), kSize, kDefaultRenderViewRouteId);
371 return LauncherHasRunningPrerender(kDefaultChildId, last_prerender_id());
374 void DisablePrerender() {
375 profile_.GetPrefs()->SetInteger(
376 prefs::kNetworkPredictionOptions,
377 chrome_browser_net::NETWORK_PREDICTION_NEVER);
380 private:
381 // Needed to pass PrerenderManager's DCHECKs.
382 TestingProfile profile_;
383 base::MessageLoop message_loop_;
384 content::TestBrowserThread ui_thread_;
385 scoped_ptr<UnitTestPrerenderManager> prerender_manager_;
386 scoped_ptr<PrerenderLinkManager> prerender_link_manager_;
387 int last_prerender_id_;
388 base::FieldTrialList field_trial_list_;
391 TEST_F(PrerenderTest, PrerenderRespectsDisableFlag) {
392 RestorePrerenderMode restore_prerender_mode;
393 ASSERT_TRUE(PrerenderManager::IsPrerenderingPossible());
394 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
395 command_line->AppendSwitchASCII(
396 switches::kPrerenderMode,
397 switches::kPrerenderModeSwitchValueDisabled);
398 prerender::ConfigurePrerender(*command_line);
399 ASSERT_FALSE(PrerenderManager::IsPrerenderingPossible());
402 TEST_F(PrerenderTest, FoundTest) {
403 GURL url("http://www.google.com/");
404 DummyPrerenderContents* prerender_contents =
405 prerender_manager()->CreateNextPrerenderContents(
406 url,
407 FINAL_STATUS_USED);
408 EXPECT_TRUE(AddSimplePrerender(url));
409 EXPECT_TRUE(prerender_contents->prerendering_has_started());
410 ASSERT_EQ(prerender_contents, prerender_manager()->FindAndUseEntry(url));
413 // Make sure that if queue a request, and a second prerender request for the
414 // same URL comes in, that the second request attaches to the first prerender,
415 // and we don't use the second prerender contents.
416 TEST_F(PrerenderTest, DuplicateTest) {
417 SetConcurrency(2);
418 GURL url("http://www.google.com/");
419 DummyPrerenderContents* prerender_contents =
420 prerender_manager()->CreateNextPrerenderContents(
421 url,
422 FINAL_STATUS_USED);
423 DummyPrerenderContents* null = NULL;
424 EXPECT_TRUE(AddSimplePrerender(url));
425 EXPECT_EQ(null, prerender_manager()->next_prerender_contents());
426 EXPECT_TRUE(prerender_contents->prerendering_has_started());
428 DummyPrerenderContents* prerender_contents1 =
429 prerender_manager()->CreateNextPrerenderContents(
430 url,
431 FINAL_STATUS_MANAGER_SHUTDOWN);
432 EXPECT_TRUE(AddSimplePrerender(url));
433 EXPECT_EQ(prerender_contents1,
434 prerender_manager()->next_prerender_contents());
435 EXPECT_FALSE(prerender_contents1->prerendering_has_started());
437 ASSERT_EQ(prerender_contents, prerender_manager()->FindAndUseEntry(url));
440 // Ensure that we expire a prerendered page after the max. permitted time.
441 TEST_F(PrerenderTest, ExpireTest) {
442 GURL url("http://www.google.com/");
443 DummyPrerenderContents* prerender_contents =
444 prerender_manager()->CreateNextPrerenderContents(
445 url,
446 FINAL_STATUS_TIMED_OUT);
447 DummyPrerenderContents* null = NULL;
448 EXPECT_TRUE(AddSimplePrerender(url));
449 EXPECT_EQ(null, prerender_manager()->next_prerender_contents());
450 EXPECT_TRUE(prerender_contents->prerendering_has_started());
451 prerender_manager()->AdvanceTimeTicks(
452 prerender_manager()->config().time_to_live + TimeDelta::FromSeconds(1));
453 ASSERT_EQ(null, prerender_manager()->FindEntry(url));
456 // Ensure that we don't launch prerenders of bad urls (in this case, a mailto:
457 // url)
458 TEST_F(PrerenderTest, BadURLTest) {
459 GURL url("mailto:test@gmail.com");
460 DummyPrerenderContents* prerender_contents =
461 prerender_manager()->CreateNextPrerenderContents(
462 url,
463 FINAL_STATUS_UNSUPPORTED_SCHEME);
464 EXPECT_FALSE(AddSimplePrerender(url));
465 EXPECT_FALSE(prerender_contents->prerendering_has_started());
466 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
467 DummyPrerenderContents* null = NULL;
468 EXPECT_EQ(null, prerender_manager()->FindEntry(url));
471 // When the user navigates away from a page, the prerenders it launched should
472 // have their time to expiry shortened from the default time to live.
473 TEST_F(PrerenderTest, LinkManagerNavigateAwayExpire) {
474 const TimeDelta time_to_live = TimeDelta::FromSeconds(300);
475 const TimeDelta abandon_time_to_live = TimeDelta::FromSeconds(20);
476 const TimeDelta test_advance = TimeDelta::FromSeconds(22);
477 ASSERT_LT(test_advance, time_to_live);
478 ASSERT_LT(abandon_time_to_live, test_advance);
480 prerender_manager()->mutable_config().time_to_live = time_to_live;
481 prerender_manager()->mutable_config().abandon_time_to_live =
482 abandon_time_to_live;
484 GURL url("http://example.com");
485 DummyPrerenderContents* prerender_contents =
486 prerender_manager()->CreateNextPrerenderContents(url,
487 FINAL_STATUS_TIMED_OUT);
488 EXPECT_TRUE(AddSimplePrerender(url));
489 EXPECT_TRUE(prerender_contents->prerendering_has_started());
490 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
491 ASSERT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
492 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId,
493 last_prerender_id());
494 EXPECT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
495 DummyPrerenderContents* null = NULL;
496 EXPECT_EQ(null, prerender_manager()->next_prerender_contents());
497 prerender_manager()->AdvanceTimeTicks(test_advance);
499 EXPECT_EQ(null, prerender_manager()->FindEntry(url));
502 // But when we navigate away very close to the original expiry of a prerender,
503 // we shouldn't expect it to be extended.
504 TEST_F(PrerenderTest, LinkManagerNavigateAwayNearExpiry) {
505 const TimeDelta time_to_live = TimeDelta::FromSeconds(300);
506 const TimeDelta abandon_time_to_live = TimeDelta::FromSeconds(20);
508 // We will expect the prerender to still be alive after advancing the clock
509 // by first_advance. But, after second_advance, we expect it to have timed
510 // out, demonstrating that you can't extend a prerender by navigating away
511 // from its launcher.
512 const TimeDelta first_advance = TimeDelta::FromSeconds(298);
513 const TimeDelta second_advance = TimeDelta::FromSeconds(4);
514 ASSERT_LT(first_advance, time_to_live);
515 ASSERT_LT(time_to_live - first_advance, abandon_time_to_live);
516 ASSERT_LT(time_to_live, first_advance + second_advance);
518 prerender_manager()->mutable_config().time_to_live = time_to_live;
519 prerender_manager()->mutable_config().abandon_time_to_live =
520 abandon_time_to_live;
522 GURL url("http://example2.com");
523 DummyPrerenderContents* prerender_contents =
524 prerender_manager()->CreateNextPrerenderContents(url,
525 FINAL_STATUS_TIMED_OUT);
526 EXPECT_TRUE(AddSimplePrerender(url));
527 EXPECT_TRUE(prerender_contents->prerendering_has_started());
528 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
529 ASSERT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
531 prerender_manager()->AdvanceTimeTicks(first_advance);
532 EXPECT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
534 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId,
535 last_prerender_id());
536 EXPECT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
538 DummyPrerenderContents* null = NULL;
539 EXPECT_EQ(null, prerender_manager()->next_prerender_contents());
541 prerender_manager()->AdvanceTimeTicks(second_advance);
542 EXPECT_EQ(null, prerender_manager()->FindEntry(url));
545 // When the user navigates away from a page, and then launches a new prerender,
546 // the new prerender should preempt the abandoned prerender even if the
547 // abandoned prerender hasn't expired.
548 TEST_F(PrerenderTest, LinkManagerNavigateAwayLaunchAnother) {
549 const TimeDelta time_to_live = TimeDelta::FromSeconds(300);
550 const TimeDelta abandon_time_to_live = TimeDelta::FromSeconds(20);
551 const TimeDelta test_advance = TimeDelta::FromSeconds(5);
552 ASSERT_LT(test_advance, time_to_live);
553 ASSERT_GT(abandon_time_to_live, test_advance);
555 prerender_manager()->mutable_config().time_to_live = time_to_live;
556 prerender_manager()->mutable_config().abandon_time_to_live =
557 abandon_time_to_live;
559 GURL url("http://example.com");
560 prerender_manager()->CreateNextPrerenderContents(url, FINAL_STATUS_CANCELLED);
561 EXPECT_TRUE(AddSimplePrerender(url));
562 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId,
563 last_prerender_id());
565 prerender_manager()->AdvanceTimeTicks(test_advance);
567 GURL second_url("http://example2.com");
568 DummyPrerenderContents* second_prerender_contents =
569 prerender_manager()->CreateNextPrerenderContents(
570 second_url, FINAL_STATUS_MANAGER_SHUTDOWN);
571 EXPECT_TRUE(AddSimplePrerender(second_url));
572 EXPECT_EQ(second_prerender_contents,
573 prerender_manager()->FindEntry(second_url));
577 // Make sure that if we prerender more requests than we support, that we launch
578 // them in the order given up until we reach MaxConcurrency, at which point we
579 // queue them and launch them in the order given. As well, insure that limits
580 // are enforced for the system as a whole and on a per launcher basis.
581 TEST_F(PrerenderTest, MaxConcurrencyTest) {
582 struct TestConcurrency {
583 size_t max_link_concurrency;
584 size_t max_link_concurrency_per_launcher;
587 TestConcurrency concurrencies_to_test[] = {
588 { prerender_manager()->config().max_link_concurrency,
589 prerender_manager()->config().max_link_concurrency_per_launcher},
591 // With the system limit higher than the per launcher limit, the per
592 // launcher limit should be in effect.
593 { 2, 1 },
595 // With the per launcher limit higher than system limit, the system limit
596 // should be in effect.
597 { 2, 4 },
600 DummyPrerenderContents* null = NULL;
601 GURL url_to_delay("http://www.google.com/delayme");
603 for (size_t i = 0; i < arraysize(concurrencies_to_test); ++i) {
604 prerender_manager()->mutable_config().max_link_concurrency =
605 concurrencies_to_test[i].max_link_concurrency;
606 prerender_manager()->mutable_config().max_link_concurrency_per_launcher =
607 concurrencies_to_test[i].max_link_concurrency_per_launcher;
609 const size_t effective_max_link_concurrency =
610 std::min(concurrencies_to_test[i].max_link_concurrency,
611 concurrencies_to_test[i].max_link_concurrency_per_launcher);
613 std::vector<GURL> urls;
614 std::vector<PrerenderContents*> prerender_contentses;
616 // Launch prerenders up to the maximum this launcher can support.
617 for (size_t j = 0; j < effective_max_link_concurrency; ++j) {
618 urls.push_back(
619 GURL(base::StringPrintf("http://google.com/use#%" PRIuS, j)));
620 prerender_contentses.push_back(
621 prerender_manager()->CreateNextPrerenderContents(urls.back(),
622 FINAL_STATUS_USED));
623 EXPECT_TRUE(AddSimplePrerender(urls.back()));
624 EXPECT_EQ(null, prerender_manager()->next_prerender_contents());
625 EXPECT_TRUE(prerender_contentses.back()->prerendering_has_started());
628 if (concurrencies_to_test[i].max_link_concurrency >
629 effective_max_link_concurrency) {
630 // We should be able to launch more prerenders on this system, but not for
631 // the default launcher.
632 GURL extra_url("http://google.com/extraurl");
633 EXPECT_FALSE(AddSimplePrerender(extra_url));
634 const int prerender_id = last_prerender_id();
635 EXPECT_TRUE(LauncherHasScheduledPrerender(kDefaultChildId,
636 prerender_id));
637 prerender_link_manager()->OnCancelPrerender(kDefaultChildId,
638 prerender_id);
639 EXPECT_FALSE(LauncherHasScheduledPrerender(kDefaultChildId,
640 prerender_id));
643 DummyPrerenderContents* prerender_contents_to_delay =
644 prerender_manager()->CreateNextPrerenderContents(url_to_delay,
645 FINAL_STATUS_USED);
646 EXPECT_FALSE(AddSimplePrerender(url_to_delay));
647 EXPECT_FALSE(prerender_contents_to_delay->prerendering_has_started());
648 EXPECT_NE(null, prerender_manager()->next_prerender_contents());
649 EXPECT_EQ(null, prerender_manager()->FindEntry(url_to_delay));
650 for (size_t j = 0; j < effective_max_link_concurrency; ++j) {
651 EXPECT_EQ(prerender_contentses[j],
652 prerender_manager()->FindAndUseEntry(urls[j]));
653 EXPECT_TRUE(prerender_contents_to_delay->prerendering_has_started());
656 EXPECT_EQ(prerender_contents_to_delay,
657 prerender_manager()->FindAndUseEntry(url_to_delay));
658 EXPECT_EQ(null, prerender_manager()->next_prerender_contents());
662 TEST_F(PrerenderTest, AliasURLTest) {
663 SetConcurrency(7);
665 GURL url("http://www.google.com/");
666 GURL alias_url1("http://www.google.com/index.html");
667 GURL alias_url2("http://google.com/");
668 GURL not_an_alias_url("http://google.com/index.html");
669 std::vector<GURL> alias_urls;
670 alias_urls.push_back(alias_url1);
671 alias_urls.push_back(alias_url2);
673 // Test that all of the aliases work, but not_an_alias_url does not.
674 DummyPrerenderContents* prerender_contents =
675 prerender_manager()->CreateNextPrerenderContents(
676 url, alias_urls, FINAL_STATUS_USED);
677 EXPECT_TRUE(AddSimplePrerender(url));
678 ASSERT_EQ(NULL, prerender_manager()->FindEntry(not_an_alias_url));
679 ASSERT_EQ(prerender_contents,
680 prerender_manager()->FindAndUseEntry(alias_url1));
681 prerender_contents = prerender_manager()->CreateNextPrerenderContents(
682 url, alias_urls, FINAL_STATUS_USED);
683 EXPECT_TRUE(AddSimplePrerender(url));
684 ASSERT_EQ(prerender_contents,
685 prerender_manager()->FindAndUseEntry(alias_url2));
686 prerender_contents = prerender_manager()->CreateNextPrerenderContents(
687 url, alias_urls, FINAL_STATUS_USED);
688 EXPECT_TRUE(AddSimplePrerender(url));
689 ASSERT_EQ(prerender_contents, prerender_manager()->FindAndUseEntry(url));
691 // Test that alias URLs can not be added.
692 prerender_contents = prerender_manager()->CreateNextPrerenderContents(
693 url, alias_urls, FINAL_STATUS_USED);
694 EXPECT_TRUE(AddSimplePrerender(url));
695 EXPECT_TRUE(AddSimplePrerender(url));
696 EXPECT_TRUE(AddSimplePrerender(alias_url1));
697 EXPECT_TRUE(AddSimplePrerender(alias_url2));
698 ASSERT_EQ(prerender_contents, prerender_manager()->FindAndUseEntry(url));
701 TEST_F(PrerenderTest, PendingPrerenderTest) {
702 GURL url("http://www.google.com/");
703 DummyPrerenderContents* prerender_contents =
704 prerender_manager()->CreateNextPrerenderContents(
705 url,
706 FINAL_STATUS_USED);
707 EXPECT_TRUE(AddSimplePrerender(url));
709 int child_id;
710 int route_id;
711 ASSERT_TRUE(prerender_contents->GetChildId(&child_id));
712 ASSERT_TRUE(prerender_contents->GetRouteId(&route_id));
714 GURL pending_url("http://news.google.com/");
716 // Schedule a pending prerender launched from the prerender.
717 DummyPrerenderContents* pending_prerender_contents =
718 prerender_manager()->CreateNextPrerenderContents(
719 pending_url,
720 ORIGIN_GWS_PRERENDER,
721 FINAL_STATUS_USED);
722 prerender_link_manager()->OnAddPrerender(
723 child_id, GetNextPrerenderID(), pending_url, kDefaultRelTypes,
724 Referrer(url, blink::WebReferrerPolicyDefault),
725 kSize, route_id);
726 EXPECT_FALSE(LauncherHasRunningPrerender(child_id, last_prerender_id()));
727 EXPECT_FALSE(pending_prerender_contents->prerendering_has_started());
729 // Use the referring prerender.
730 EXPECT_TRUE(prerender_contents->prerendering_has_started());
731 ASSERT_EQ(prerender_contents, prerender_manager()->FindAndUseEntry(url));
733 // The pending prerender should start now.
734 EXPECT_TRUE(LauncherHasRunningPrerender(child_id, last_prerender_id()));
735 EXPECT_TRUE(pending_prerender_contents->prerendering_has_started());
736 ASSERT_EQ(pending_prerender_contents,
737 prerender_manager()->FindAndUseEntry(pending_url));
740 TEST_F(PrerenderTest, InvalidPendingPrerenderTest) {
741 GURL url("http://www.google.com/");
742 DummyPrerenderContents* prerender_contents =
743 prerender_manager()->CreateNextPrerenderContents(
744 url,
745 FINAL_STATUS_USED);
746 EXPECT_TRUE(AddSimplePrerender(url));
748 int child_id;
749 int route_id;
750 ASSERT_TRUE(prerender_contents->GetChildId(&child_id));
751 ASSERT_TRUE(prerender_contents->GetRouteId(&route_id));
753 // This pending URL has an unsupported scheme, and won't be able
754 // to start.
755 GURL pending_url("ftp://news.google.com/");
757 // Schedule a pending prerender launched from the prerender.
758 DummyPrerenderContents* pending_prerender_contents =
759 prerender_manager()->CreateNextPrerenderContents(
760 pending_url,
761 ORIGIN_GWS_PRERENDER,
762 FINAL_STATUS_UNSUPPORTED_SCHEME);
763 prerender_link_manager()->OnAddPrerender(
764 child_id, GetNextPrerenderID(), pending_url, kDefaultRelTypes,
765 Referrer(url, blink::WebReferrerPolicyDefault),
766 kSize, route_id);
767 EXPECT_FALSE(LauncherHasRunningPrerender(child_id, last_prerender_id()));
768 EXPECT_FALSE(pending_prerender_contents->prerendering_has_started());
770 // Use the referring prerender.
771 EXPECT_TRUE(prerender_contents->prerendering_has_started());
772 ASSERT_EQ(prerender_contents, prerender_manager()->FindAndUseEntry(url));
774 // The pending prerender still doesn't start.
775 EXPECT_FALSE(LauncherHasRunningPrerender(child_id, last_prerender_id()));
776 EXPECT_FALSE(pending_prerender_contents->prerendering_has_started());
779 TEST_F(PrerenderTest, CancelPendingPrerenderTest) {
780 GURL url("http://www.google.com/");
781 DummyPrerenderContents* prerender_contents =
782 prerender_manager()->CreateNextPrerenderContents(
783 url,
784 FINAL_STATUS_USED);
785 EXPECT_TRUE(AddSimplePrerender(url));
787 int child_id;
788 int route_id;
789 ASSERT_TRUE(prerender_contents->GetChildId(&child_id));
790 ASSERT_TRUE(prerender_contents->GetRouteId(&route_id));
792 GURL pending_url("http://news.google.com/");
794 // Schedule a pending prerender launched from the prerender.
795 prerender_link_manager()->OnAddPrerender(
796 child_id, GetNextPrerenderID(), pending_url, kDefaultRelTypes,
797 Referrer(url, blink::WebReferrerPolicyDefault),
798 kSize, route_id);
799 EXPECT_FALSE(LauncherHasRunningPrerender(child_id, last_prerender_id()));
801 // Cancel the pending prerender.
802 prerender_link_manager()->OnCancelPrerender(child_id, last_prerender_id());
804 // Use the referring prerender.
805 EXPECT_TRUE(prerender_contents->prerendering_has_started());
806 ASSERT_EQ(prerender_contents, prerender_manager()->FindAndUseEntry(url));
808 // The pending prerender doesn't start.
809 EXPECT_FALSE(LauncherHasRunningPrerender(child_id, last_prerender_id()));
812 // Tests that a PrerenderManager created for a browser session in the control
813 // group works as expected.
814 TEST_F(PrerenderTest, ControlGroup) {
815 RestorePrerenderMode restore_prerender_mode;
816 PrerenderManager::SetMode(
817 PrerenderManager::PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP);
818 GURL url("http://www.google.com/");
819 DummyPrerenderContents* prerender_contents =
820 prerender_manager()->CreateNextPrerenderContents(
821 url,
822 FINAL_STATUS_MANAGER_SHUTDOWN);
823 EXPECT_TRUE(AddSimplePrerender(url));
824 EXPECT_FALSE(prerender_contents->prerendering_has_started());
827 // Tests that prerendering is cancelled when the source render view does not
828 // exist. On failure, the DCHECK in CreatePrerenderContents() above should be
829 // triggered.
830 TEST_F(PrerenderTest, SourceRenderViewClosed) {
831 GURL url("http://www.google.com/");
832 prerender_manager()->CreateNextPrerenderContents(
833 url,
834 FINAL_STATUS_MANAGER_SHUTDOWN);
835 prerender_link_manager()->OnAddPrerender(
836 100, GetNextPrerenderID(), url, kDefaultRelTypes, Referrer(), kSize, 200);
837 EXPECT_FALSE(LauncherHasRunningPrerender(100, last_prerender_id()));
840 // Tests that prerendering doesn't launch rel=next prerenders without the field
841 // trial.
842 TEST_F(PrerenderTest, NoRelNextByDefault) {
843 GURL url("http://www.google.com/");
844 prerender_manager()->CreateNextPrerenderContents(
845 url, FINAL_STATUS_MANAGER_SHUTDOWN);
846 DummyPrerenderContents* null = NULL;
848 prerender_link_manager()->OnAddPrerender(
849 kDefaultChildId, GetNextPrerenderID(), url, PrerenderRelTypeNext,
850 Referrer(), kSize, kDefaultRenderViewRouteId);
851 EXPECT_EQ(null, prerender_manager()->FindEntry(url));
854 // Tests that prerendering does launch rel=next prerenders with the field trial.
855 TEST_F(PrerenderTest, RelNextByFieldTrial) {
856 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("PrerenderRelNextTrial",
857 "Yes"));
858 GURL url("http://www.google.com/");
859 DummyPrerenderContents* prerender_contents =
860 prerender_manager()->CreateNextPrerenderContents(
861 url, ORIGIN_LINK_REL_NEXT, FINAL_STATUS_USED);
863 prerender_link_manager()->OnAddPrerender(
864 kDefaultChildId, GetNextPrerenderID(), url, PrerenderRelTypeNext,
865 Referrer(), kSize, kDefaultRenderViewRouteId);
866 EXPECT_EQ(prerender_contents, prerender_manager()->FindAndUseEntry(url));
869 // Tests that prerendering is cancelled when we launch a second prerender of
870 // the same target within a short time interval.
871 TEST_F(PrerenderTest, RecentlyVisited) {
872 GURL url("http://www.google.com/");
874 prerender_manager()->RecordNavigation(url);
876 DummyPrerenderContents* prerender_contents =
877 prerender_manager()->CreateNextPrerenderContents(
878 url, FINAL_STATUS_RECENTLY_VISITED);
879 EXPECT_FALSE(AddSimplePrerender(url));
880 EXPECT_FALSE(prerender_contents->prerendering_has_started());
883 TEST_F(PrerenderTest, NotSoRecentlyVisited) {
884 GURL url("http://www.google.com/");
886 prerender_manager()->RecordNavigation(url);
887 prerender_manager()->AdvanceTimeTicks(
888 TimeDelta::FromMilliseconds(
889 UnitTestPrerenderManager::kNavigationRecordWindowMs + 500));
891 DummyPrerenderContents* prerender_contents =
892 prerender_manager()->CreateNextPrerenderContents(
893 url, FINAL_STATUS_USED);
894 EXPECT_TRUE(AddSimplePrerender(url));
895 EXPECT_TRUE(prerender_contents->prerendering_has_started());
896 ASSERT_EQ(prerender_contents, prerender_manager()->FindAndUseEntry(url));
899 // Tests that our PPLT dummy prerender gets created properly.
900 TEST_F(PrerenderTest, PPLTDummy) {
901 RestorePrerenderMode restore_prerender_mode;
902 PrerenderManager::SetMode(
903 PrerenderManager::PRERENDER_MODE_EXPERIMENT_MATCH_COMPLETE_GROUP);
905 GURL url("http://www.google.com/");
906 DummyPrerenderContents* prerender_contents =
907 prerender_manager()->CreateNextPrerenderContents(
908 url, FINAL_STATUS_UNSUPPORTED_SCHEME);
909 EXPECT_TRUE(AddSimplePrerender(url));
910 EXPECT_TRUE(prerender_contents->prerendering_has_started());
911 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
913 DummyPrerenderContents* pplt_dummy_contents =
914 prerender_manager()->CreateNextPrerenderContents(url,
915 FINAL_STATUS_USED);
916 GURL ftp_url("ftp://ftp.google.com/");
917 // Adding this ftp URL will force the expected unsupported scheme error.
918 prerender_contents->AddAliasURL(ftp_url);
919 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
921 ASSERT_EQ(pplt_dummy_contents, prerender_manager()->FindAndUseEntry(url));
922 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
925 // Tests that our PPLT dummy prerender gets created properly, even
926 // when navigating to a page that has been recently navigated to.
927 TEST_F(PrerenderTest, RecentlyVisitedPPLTDummy) {
928 RestorePrerenderMode restore_prerender_mode;
929 PrerenderManager::SetMode(
930 PrerenderManager::PRERENDER_MODE_EXPERIMENT_MATCH_COMPLETE_GROUP);
932 GURL url("http://www.google.com/");
933 DummyPrerenderContents* prerender_contents =
934 prerender_manager()->CreateNextPrerenderContents(
935 url, FINAL_STATUS_UNSUPPORTED_SCHEME);
936 EXPECT_TRUE(AddSimplePrerender(url));
937 EXPECT_TRUE(prerender_contents->prerendering_has_started());
939 DummyPrerenderContents* pplt_dummy_contents =
940 prerender_manager()->CreateNextPrerenderContents(url,
941 FINAL_STATUS_USED);
942 prerender_manager()->RecordNavigation(url);
943 GURL ftp_url("ftp://ftp.google.com/");
944 prerender_contents->AddAliasURL(ftp_url);
946 ASSERT_EQ(pplt_dummy_contents, prerender_manager()->FindAndUseEntry(url));
949 TEST_F(PrerenderTest, PPLTLateCancel) {
950 RestorePrerenderMode restore_prerender_mode;
951 PrerenderManager::SetMode(
952 PrerenderManager::PRERENDER_MODE_EXPERIMENT_MATCH_COMPLETE_GROUP);
954 GURL url("http://www.google.com");
955 DummyPrerenderContents* prerender_contents =
956 prerender_manager()->CreateNextPrerenderContents(
957 url, FINAL_STATUS_JAVASCRIPT_ALERT);
958 EXPECT_TRUE(AddSimplePrerender(url));
959 EXPECT_TRUE(prerender_contents->prerendering_has_started());
960 // Force the creation of a match complete dummy.
961 DummyPrerenderContents* duplicate_prerender_contents =
962 prerender_manager()->CreateNextPrerenderContents(url,
963 FINAL_STATUS_CANCELLED);
964 ASSERT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
965 prerender_contents->Destroy(FINAL_STATUS_JAVASCRIPT_ALERT);
966 ASSERT_EQ(duplicate_prerender_contents, prerender_manager()->FindEntry(url));
968 // Make sure that events on prerender handles propogate to the match
969 // complete replacement.
970 DummyPrerenderContents* null = NULL;
971 prerender_link_manager()->OnCancelPrerender(kDefaultChildId,
972 last_prerender_id());
973 ASSERT_EQ(null, prerender_manager()->FindEntry(url));
976 // Tests that the prerender manager matches include the fragment.
977 TEST_F(PrerenderTest, FragmentMatchesTest) {
978 GURL fragment_url("http://www.google.com/#test");
980 DummyPrerenderContents* prerender_contents =
981 prerender_manager()->CreateNextPrerenderContents(fragment_url,
982 FINAL_STATUS_USED);
983 EXPECT_TRUE(AddSimplePrerender(fragment_url));
984 EXPECT_TRUE(prerender_contents->prerendering_has_started());
985 ASSERT_EQ(prerender_contents,
986 prerender_manager()->FindAndUseEntry(fragment_url));
989 // Tests that the prerender manager uses fragment references when matching
990 // prerender URLs in the case a different fragment is in both URLs.
991 TEST_F(PrerenderTest, FragmentsDifferTest) {
992 GURL fragment_url("http://www.google.com/#test");
993 GURL other_fragment_url("http://www.google.com/#other_test");
995 DummyPrerenderContents* prerender_contents =
996 prerender_manager()->CreateNextPrerenderContents(fragment_url,
997 FINAL_STATUS_USED);
998 EXPECT_TRUE(AddSimplePrerender(fragment_url));
999 EXPECT_TRUE(prerender_contents->prerendering_has_started());
1001 DummyPrerenderContents* null = NULL;
1002 ASSERT_EQ(null, prerender_manager()->FindEntry(other_fragment_url));
1004 ASSERT_EQ(prerender_contents,
1005 prerender_manager()->FindAndUseEntry(fragment_url));
1008 // Make sure that clearing works as expected.
1009 TEST_F(PrerenderTest, ClearTest) {
1010 GURL url("http://www.google.com/");
1011 DummyPrerenderContents* prerender_contents =
1012 prerender_manager()->CreateNextPrerenderContents(
1013 url,
1014 FINAL_STATUS_CACHE_OR_HISTORY_CLEARED);
1015 EXPECT_TRUE(AddSimplePrerender(url));
1016 EXPECT_TRUE(prerender_contents->prerendering_has_started());
1017 prerender_manager()->ClearData(PrerenderManager::CLEAR_PRERENDER_CONTENTS);
1018 DummyPrerenderContents* null = NULL;
1019 EXPECT_EQ(null, prerender_manager()->FindEntry(url));
1022 // Make sure canceling works as expected.
1023 TEST_F(PrerenderTest, CancelAllTest) {
1024 GURL url("http://www.google.com/");
1025 DummyPrerenderContents* prerender_contents =
1026 prerender_manager()->CreateNextPrerenderContents(
1027 url, FINAL_STATUS_CANCELLED);
1028 EXPECT_TRUE(AddSimplePrerender(url));
1029 EXPECT_TRUE(prerender_contents->prerendering_has_started());
1030 prerender_manager()->CancelAllPrerenders();
1031 const DummyPrerenderContents* null = NULL;
1032 EXPECT_EQ(null, prerender_manager()->FindEntry(url));
1035 TEST_F(PrerenderTest, OmniboxNotAllowedWhenDisabled) {
1036 DisablePrerender();
1037 EXPECT_FALSE(prerender_manager()->AddPrerenderFromOmnibox(
1038 GURL("http://www.example.com"), NULL, gfx::Size()));
1041 TEST_F(PrerenderTest, LinkRelNotAllowedWhenDisabled) {
1042 DisablePrerender();
1043 EXPECT_FALSE(AddSimplePrerender(
1044 GURL("http://www.example.com")));
1047 TEST_F(PrerenderTest, LinkManagerCancel) {
1048 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1049 GURL url("http://www.myexample.com");
1050 DummyPrerenderContents* prerender_contents =
1051 prerender_manager()->CreateNextPrerenderContents(
1052 url, FINAL_STATUS_CANCELLED);
1054 EXPECT_TRUE(AddSimplePrerender(url));
1056 EXPECT_TRUE(prerender_contents->prerendering_has_started());
1057 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
1058 ASSERT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
1059 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
1060 prerender_link_manager()->OnCancelPrerender(kDefaultChildId,
1061 last_prerender_id());
1063 EXPECT_TRUE(prerender_contents->prerendering_has_been_cancelled());
1064 DummyPrerenderContents* null = NULL;
1065 ASSERT_EQ(null, prerender_manager()->FindEntry(url));
1066 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1069 TEST_F(PrerenderTest, LinkManagerCancelThenAbandon) {
1070 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1071 GURL url("http://www.myexample.com");
1072 DummyPrerenderContents* prerender_contents =
1073 prerender_manager()->CreateNextPrerenderContents(
1074 url, FINAL_STATUS_CANCELLED);
1076 EXPECT_TRUE(AddSimplePrerender(url));
1078 EXPECT_TRUE(prerender_contents->prerendering_has_started());
1079 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
1080 ASSERT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
1081 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
1082 prerender_link_manager()->OnCancelPrerender(kDefaultChildId,
1083 last_prerender_id());
1085 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1086 EXPECT_TRUE(prerender_contents->prerendering_has_been_cancelled());
1087 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId,
1088 last_prerender_id());
1090 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1091 EXPECT_TRUE(prerender_contents->prerendering_has_been_cancelled());
1092 DummyPrerenderContents* null = NULL;
1093 ASSERT_EQ(null, prerender_manager()->FindEntry(url));
1096 TEST_F(PrerenderTest, LinkManagerAbandon) {
1097 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1098 GURL url("http://www.myexample.com");
1099 DummyPrerenderContents* prerender_contents =
1100 prerender_manager()->CreateNextPrerenderContents(
1101 url, FINAL_STATUS_USED);
1103 EXPECT_TRUE(AddSimplePrerender(url));
1105 EXPECT_TRUE(prerender_contents->prerendering_has_started());
1106 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
1107 ASSERT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
1108 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
1109 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId,
1110 last_prerender_id());
1112 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
1113 ASSERT_EQ(prerender_contents, prerender_manager()->FindAndUseEntry(url));
1116 TEST_F(PrerenderTest, LinkManagerAbandonThenCancel) {
1117 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1118 GURL url("http://www.myexample.com");
1119 DummyPrerenderContents* prerender_contents =
1120 prerender_manager()->CreateNextPrerenderContents(
1121 url, FINAL_STATUS_CANCELLED);
1123 EXPECT_TRUE(AddSimplePrerender(url));
1125 EXPECT_TRUE(prerender_contents->prerendering_has_started());
1126 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
1127 ASSERT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
1128 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
1129 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId,
1130 last_prerender_id());
1132 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
1133 ASSERT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
1135 prerender_link_manager()->OnCancelPrerender(kDefaultChildId,
1136 last_prerender_id());
1137 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1138 EXPECT_TRUE(prerender_contents->prerendering_has_been_cancelled());
1139 DummyPrerenderContents* null = NULL;
1140 ASSERT_EQ(null, prerender_manager()->FindEntry(url));
1143 TEST_F(PrerenderTest, LinkManagerCancelTwice) {
1144 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1145 GURL url("http://www.myexample.com");
1146 DummyPrerenderContents* prerender_contents =
1147 prerender_manager()->CreateNextPrerenderContents(
1148 url, FINAL_STATUS_CANCELLED);
1150 EXPECT_TRUE(AddSimplePrerender(url));
1151 EXPECT_TRUE(prerender_contents->prerendering_has_started());
1152 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
1153 EXPECT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
1154 prerender_link_manager()->OnCancelPrerender(kDefaultChildId,
1155 last_prerender_id());
1157 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1158 EXPECT_TRUE(prerender_contents->prerendering_has_been_cancelled());
1159 DummyPrerenderContents* null = NULL;
1160 ASSERT_EQ(null, prerender_manager()->FindEntry(url));
1161 prerender_link_manager()->OnCancelPrerender(kDefaultChildId,
1162 last_prerender_id());
1165 TEST_F(PrerenderTest, LinkManagerAddTwiceCancelTwice) {
1166 SetConcurrency(2);
1167 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1168 GURL url("http://www.myexample.com");
1169 DummyPrerenderContents* prerender_contents =
1170 prerender_manager()->CreateNextPrerenderContents(
1171 url, FINAL_STATUS_CANCELLED);
1173 EXPECT_TRUE(AddSimplePrerender(url));
1175 const int first_prerender_id = last_prerender_id();
1176 EXPECT_TRUE(prerender_contents->prerendering_has_started());
1177 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
1178 EXPECT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
1179 EXPECT_TRUE(AddSimplePrerender(url));
1181 const int second_prerender_id = last_prerender_id();
1182 EXPECT_TRUE(prerender_contents->prerendering_has_started());
1183 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
1184 EXPECT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
1185 prerender_link_manager()->OnCancelPrerender(kDefaultChildId,
1186 first_prerender_id);
1188 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
1189 EXPECT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
1190 prerender_link_manager()->OnCancelPrerender(kDefaultChildId,
1191 second_prerender_id);
1193 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1194 EXPECT_TRUE(prerender_contents->prerendering_has_been_cancelled());
1195 DummyPrerenderContents* null = NULL;
1196 ASSERT_EQ(null, prerender_manager()->FindEntry(url));
1199 TEST_F(PrerenderTest, LinkManagerAddTwiceCancelTwiceThenAbandonTwice) {
1200 SetConcurrency(2);
1201 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1202 GURL url("http://www.myexample.com");
1203 DummyPrerenderContents* prerender_contents =
1204 prerender_manager()->CreateNextPrerenderContents(
1205 url, FINAL_STATUS_CANCELLED);
1207 EXPECT_TRUE(AddSimplePrerender(url));
1209 const int first_prerender_id = last_prerender_id();
1210 EXPECT_TRUE(prerender_contents->prerendering_has_started());
1211 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
1212 ASSERT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
1213 EXPECT_TRUE(AddSimplePrerender(url));
1215 const int second_prerender_id = last_prerender_id();
1216 EXPECT_TRUE(prerender_contents->prerendering_has_started());
1217 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
1218 ASSERT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
1219 prerender_link_manager()->OnCancelPrerender(kDefaultChildId,
1220 first_prerender_id);
1222 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
1223 ASSERT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
1224 prerender_link_manager()->OnCancelPrerender(kDefaultChildId,
1225 second_prerender_id);
1227 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1228 EXPECT_TRUE(prerender_contents->prerendering_has_been_cancelled());
1229 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId,
1230 first_prerender_id);
1232 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1233 EXPECT_TRUE(prerender_contents->prerendering_has_been_cancelled());
1234 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId,
1235 second_prerender_id);
1237 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1238 EXPECT_TRUE(prerender_contents->prerendering_has_been_cancelled());
1239 DummyPrerenderContents* null = NULL;
1240 ASSERT_EQ(null, prerender_manager()->FindEntry(url));
1243 // TODO(gavinp): Update this test after abandon has an effect on Prerenders,
1244 // like shortening the timeouts.
1245 TEST_F(PrerenderTest, LinkManagerAddTwiceAbandonTwiceUseTwice) {
1246 SetConcurrency(2);
1247 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1248 GURL url("http://www.myexample.com");
1249 DummyPrerenderContents* prerender_contents =
1250 prerender_manager()->CreateNextPrerenderContents(
1251 url, FINAL_STATUS_USED);
1253 EXPECT_TRUE(AddSimplePrerender(url));
1255 const int first_prerender_id = last_prerender_id();
1256 EXPECT_TRUE(prerender_contents->prerendering_has_started());
1257 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
1258 ASSERT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
1259 EXPECT_TRUE(AddSimplePrerender(url));
1261 const int second_prerender_id = last_prerender_id();
1262 EXPECT_TRUE(prerender_contents->prerendering_has_started());
1263 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
1264 ASSERT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
1265 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId,
1266 first_prerender_id);
1268 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
1269 ASSERT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
1270 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId,
1271 second_prerender_id);
1273 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
1274 ASSERT_EQ(prerender_contents, prerender_manager()->FindAndUseEntry(url));
1275 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1278 // TODO(gavinp): After abandon shortens the expire time on a Prerender,
1279 // add a series of tests testing advancing the time by either the abandon
1280 // or normal expire, and verifying the expected behaviour with groups
1281 // of links.
1282 TEST_F(PrerenderTest, LinkManagerExpireThenCancel) {
1283 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1284 GURL url("http://www.myexample.com");
1285 DummyPrerenderContents* prerender_contents =
1286 prerender_manager()->CreateNextPrerenderContents(
1287 url, FINAL_STATUS_TIMED_OUT);
1289 EXPECT_TRUE(AddSimplePrerender(url));
1291 EXPECT_TRUE(prerender_contents->prerendering_has_started());
1292 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
1293 ASSERT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
1294 prerender_manager()->AdvanceTimeTicks(
1295 prerender_manager()->config().time_to_live + TimeDelta::FromSeconds(1));
1297 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
1298 DummyPrerenderContents* null = NULL;
1299 ASSERT_EQ(null, prerender_manager()->FindEntry(url));
1300 prerender_link_manager()->OnCancelPrerender(kDefaultChildId,
1301 last_prerender_id());
1303 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1304 ASSERT_EQ(null, prerender_manager()->FindEntry(url));
1307 TEST_F(PrerenderTest, LinkManagerExpireThenAddAgain) {
1308 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1309 GURL url("http://www.myexample.com");
1310 DummyPrerenderContents* first_prerender_contents =
1311 prerender_manager()->CreateNextPrerenderContents(
1312 url, FINAL_STATUS_TIMED_OUT);
1313 EXPECT_TRUE(AddSimplePrerender(url));
1314 EXPECT_TRUE(first_prerender_contents->prerendering_has_started());
1315 EXPECT_FALSE(first_prerender_contents->prerendering_has_been_cancelled());
1316 ASSERT_EQ(first_prerender_contents,
1317 prerender_manager()->FindEntry(url));
1318 prerender_manager()->AdvanceTimeTicks(
1319 prerender_manager()->config().time_to_live + TimeDelta::FromSeconds(1));
1320 DummyPrerenderContents* null = NULL;
1321 ASSERT_EQ(null, prerender_manager()->FindEntry(url));
1322 DummyPrerenderContents* second_prerender_contents =
1323 prerender_manager()->CreateNextPrerenderContents(
1324 url, FINAL_STATUS_USED);
1325 EXPECT_TRUE(AddSimplePrerender(url));
1326 EXPECT_TRUE(second_prerender_contents->prerendering_has_started());
1327 ASSERT_EQ(second_prerender_contents,
1328 prerender_manager()->FindAndUseEntry(url));
1331 TEST_F(PrerenderTest, LinkManagerCancelThenAddAgain) {
1332 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1333 GURL url("http://www.myexample.com");
1334 DummyPrerenderContents* first_prerender_contents =
1335 prerender_manager()->CreateNextPrerenderContents(
1336 url, FINAL_STATUS_CANCELLED);
1337 EXPECT_TRUE(AddSimplePrerender(url));
1338 EXPECT_TRUE(first_prerender_contents->prerendering_has_started());
1339 EXPECT_FALSE(first_prerender_contents->prerendering_has_been_cancelled());
1340 ASSERT_EQ(first_prerender_contents, prerender_manager()->FindEntry(url));
1341 prerender_link_manager()->OnCancelPrerender(kDefaultChildId,
1342 last_prerender_id());
1343 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1344 EXPECT_TRUE(first_prerender_contents->prerendering_has_been_cancelled());
1345 DummyPrerenderContents* null = NULL;
1346 ASSERT_EQ(null, prerender_manager()->FindEntry(url));
1347 DummyPrerenderContents* second_prerender_contents =
1348 prerender_manager()->CreateNextPrerenderContents(
1349 url, FINAL_STATUS_USED);
1350 EXPECT_TRUE(AddSimplePrerender(url));
1351 EXPECT_TRUE(second_prerender_contents->prerendering_has_started());
1352 ASSERT_EQ(second_prerender_contents,
1353 prerender_manager()->FindAndUseEntry(url));
1356 TEST_F(PrerenderTest, LinkManagerChannelClosing) {
1357 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1358 GURL url("http://www.myexample.com");
1359 DummyPrerenderContents* prerender_contents =
1360 prerender_manager()->CreateNextPrerenderContents(
1361 url, FINAL_STATUS_TIMED_OUT);
1363 EXPECT_TRUE(AddSimplePrerender(url));
1364 EXPECT_TRUE(prerender_contents->prerendering_has_started());
1365 EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled());
1366 ASSERT_EQ(prerender_contents, prerender_manager()->FindEntry(url));
1368 prerender_link_manager()->OnChannelClosing(kDefaultChildId);
1370 prerender_manager()->AdvanceTimeTicks(
1371 prerender_manager()->config().abandon_time_to_live +
1372 TimeDelta::FromSeconds(1));
1374 DummyPrerenderContents* null = NULL;
1375 EXPECT_EQ(null, prerender_manager()->FindEntry(url));
1376 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1379 // Creates two prerenders, one of which should be blocked by the
1380 // max_link_concurrency; abandons both of them and waits to make sure both
1381 // are cleared from the PrerenderLinkManager.
1382 TEST_F(PrerenderTest, LinkManagerAbandonInactivePrerender) {
1383 SetConcurrency(1);
1384 ASSERT_LT(prerender_manager()->config().abandon_time_to_live,
1385 prerender_manager()->config().time_to_live);
1386 GURL first_url("http://www.myexample.com");
1387 DummyPrerenderContents* prerender_contents =
1388 prerender_manager()->CreateNextPrerenderContents(
1389 first_url, FINAL_STATUS_TIMED_OUT);
1390 EXPECT_TRUE(AddSimplePrerender(first_url));
1391 const int first_prerender_id = last_prerender_id();
1393 GURL second_url("http://www.neverlaunched.com");
1394 EXPECT_FALSE(AddSimplePrerender(second_url));
1395 const int second_prerender_id = last_prerender_id();
1397 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
1399 DummyPrerenderContents* null = NULL;
1400 EXPECT_EQ(prerender_contents, prerender_manager()->FindEntry(first_url));
1401 EXPECT_EQ(null, prerender_manager()->FindEntry(second_url));
1403 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId,
1404 first_prerender_id);
1405 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId,
1406 second_prerender_id);
1408 prerender_manager()->AdvanceTimeTicks(
1409 prerender_manager()->config().abandon_time_to_live +
1410 TimeDelta::FromSeconds(1));
1411 EXPECT_EQ(null, prerender_manager()->FindEntry(first_url));
1412 EXPECT_EQ(null, prerender_manager()->FindEntry(second_url));
1413 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1416 // Creates two prerenders, the second one started by the first, both of which
1417 // should be blocked by max_concurrency; abandons both of them and waits to make
1418 // sure both are cleared from the PrerenderLinkManager.
1419 TEST_F(PrerenderTest, LinkManagerClearOnPendingAbandon) {
1420 SetConcurrency(1);
1421 ASSERT_LT(prerender_manager()->config().abandon_time_to_live,
1422 prerender_manager()->config().time_to_live);
1423 GURL first_url("http://www.myexample.com");
1424 DummyPrerenderContents* prerender_contents =
1425 prerender_manager()->CreateNextPrerenderContents(
1426 first_url, FINAL_STATUS_TIMED_OUT);
1427 EXPECT_TRUE(AddSimplePrerender(first_url));
1428 const int first_prerender_id = last_prerender_id();
1430 int child_id;
1431 int route_id;
1432 ASSERT_TRUE(prerender_contents->GetChildId(&child_id));
1433 ASSERT_TRUE(prerender_contents->GetRouteId(&route_id));
1435 GURL pending_url("http://www.neverlaunched.com");
1436 prerender_link_manager()->OnAddPrerender(
1437 child_id, GetNextPrerenderID(), pending_url, kDefaultRelTypes,
1438 content::Referrer(), kSize, route_id);
1439 const int second_prerender_id = last_prerender_id();
1441 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
1443 DummyPrerenderContents* null = NULL;
1444 EXPECT_EQ(prerender_contents, prerender_manager()->FindEntry(first_url));
1445 EXPECT_EQ(null, prerender_manager()->FindEntry(pending_url));
1447 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId,
1448 first_prerender_id);
1449 prerender_link_manager()->OnAbandonPrerender(kDefaultChildId,
1450 second_prerender_id);
1452 prerender_manager()->AdvanceTimeTicks(
1453 prerender_manager()->config().abandon_time_to_live +
1454 TimeDelta::FromSeconds(1));
1455 EXPECT_EQ(null, prerender_manager()->FindEntry(first_url));
1456 EXPECT_EQ(null, prerender_manager()->FindEntry(pending_url));
1457 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1460 // Creates two prerenders, one of which should be blocked by the
1461 // max_link_concurrency; uses one after the max wait to launch, and
1462 // ensures the second prerender does not start.
1463 TEST_F(PrerenderTest, LinkManagerWaitToLaunchNotLaunched) {
1464 SetConcurrency(1);
1465 ASSERT_LT(prerender_manager()->config().max_wait_to_launch,
1466 prerender_manager()->config().time_to_live);
1467 GURL first_url("http://www.myexample.com");
1468 DummyPrerenderContents* prerender_contents =
1469 prerender_manager()->CreateNextPrerenderContents(
1470 first_url, FINAL_STATUS_USED);
1471 EXPECT_TRUE(AddSimplePrerender(first_url));
1473 GURL second_url("http://www.neverlaunched.com");
1474 EXPECT_FALSE(AddSimplePrerender(second_url));
1476 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
1478 DummyPrerenderContents* null = NULL;
1479 EXPECT_EQ(prerender_contents, prerender_manager()->FindEntry(first_url));
1480 EXPECT_EQ(null, prerender_manager()->FindEntry(second_url));
1482 prerender_manager()->AdvanceTimeTicks(
1483 prerender_manager()->config().max_wait_to_launch +
1484 TimeDelta::FromSeconds(1));
1485 EXPECT_EQ(prerender_contents, prerender_manager()->FindEntry(first_url));
1486 EXPECT_EQ(null, prerender_manager()->FindEntry(second_url));
1488 EXPECT_EQ(prerender_contents,
1489 prerender_manager()->FindAndUseEntry(first_url));
1491 EXPECT_EQ(null, prerender_manager()->FindEntry(first_url));
1492 EXPECT_EQ(null, prerender_manager()->FindEntry(second_url));
1493 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1496 // Creates two prerenders, one of which should start when the first one expires.
1497 TEST_F(PrerenderTest, LinkManagerExpireRevealingLaunch) {
1498 SetConcurrency(1);
1499 ASSERT_LT(prerender_manager()->config().max_wait_to_launch,
1500 prerender_manager()->config().time_to_live);
1502 GURL first_url("http://www.willexpire.com");
1503 DummyPrerenderContents* first_prerender_contents =
1504 prerender_manager()->CreateNextPrerenderContents(
1505 first_url, FINAL_STATUS_TIMED_OUT);
1506 EXPECT_TRUE(AddSimplePrerender(first_url));
1507 EXPECT_EQ(first_prerender_contents,
1508 prerender_manager()->FindEntry(first_url));
1510 // Insert the second prerender so it will be still be launchable when the
1511 // first expires.
1512 const TimeDelta wait_to_launch_second_prerender =
1513 prerender_manager()->config().time_to_live -
1514 prerender_manager()->config().max_wait_to_launch +
1515 TimeDelta::FromSeconds(2);
1516 const TimeDelta wait_for_first_prerender_to_expire =
1517 prerender_manager()->config().time_to_live -
1518 wait_to_launch_second_prerender +
1519 TimeDelta::FromSeconds(1);
1520 ASSERT_LT(prerender_manager()->config().time_to_live,
1521 wait_to_launch_second_prerender +
1522 wait_for_first_prerender_to_expire);
1523 ASSERT_GT(prerender_manager()->config().max_wait_to_launch.InSeconds(),
1524 wait_for_first_prerender_to_expire.InSeconds());
1526 prerender_manager()->AdvanceTimeTicks(wait_to_launch_second_prerender);
1527 GURL second_url("http://www.willlaunch.com");
1528 DummyPrerenderContents* second_prerender_contents =
1529 prerender_manager()->CreateNextPrerenderContents(
1530 second_url, FINAL_STATUS_USED);
1531 EXPECT_FALSE(AddSimplePrerender(second_url));
1533 // The first prerender is still running, but the second has not yet launched.
1534 EXPECT_EQ(first_prerender_contents,
1535 prerender_manager()->FindEntry(first_url));
1536 PrerenderContents* null = NULL;
1537 EXPECT_EQ(null, prerender_manager()->FindEntry(second_url));
1539 // The first prerender should have died, giving life to the second one.
1540 prerender_manager()->AdvanceTimeTicks(wait_for_first_prerender_to_expire);
1541 EXPECT_EQ(null, prerender_manager()->FindEntry(first_url));
1542 EXPECT_EQ(second_prerender_contents,
1543 prerender_manager()->FindAndUseEntry(second_url));
1546 TEST_F(PrerenderTest, InstantSearchNotAllowedWhenDisabled) {
1547 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
1548 "EmbeddedSearch",
1549 "Group82 espv:8 use_cacheable_ntp:1 prefetch_results:1"));
1550 DisablePrerender();
1551 EXPECT_FALSE(prerender_manager()->AddPrerenderForInstant(
1552 GURL("http://www.example.com/instant_search"), NULL, gfx::Size()));
1555 TEST_F(PrerenderTest, PrerenderContentsForInstantSearch) {
1556 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
1557 "EmbeddedSearch",
1558 "Group82 espv:8 use_cacheable_ntp:1 prefetch_results:1"));
1559 GURL url("http://www.example.com/instant_search");
1560 DummyPrerenderContents* prerender_contents =
1561 prerender_manager()->CreateNextPrerenderContents(url, ORIGIN_INSTANT,
1562 FINAL_STATUS_USED);
1563 scoped_ptr<PrerenderHandle> prerender_handle(
1564 prerender_manager()->AddPrerenderForInstant(url, NULL, kSize));
1565 CHECK(prerender_handle.get());
1566 EXPECT_TRUE(prerender_handle->IsPrerendering());
1567 EXPECT_TRUE(prerender_contents->prerendering_has_started());
1568 EXPECT_EQ(prerender_contents, prerender_handle->contents());
1569 EXPECT_EQ(ORIGIN_INSTANT, prerender_handle->contents()->origin());
1570 ASSERT_EQ(prerender_contents, prerender_manager()->FindAndUseEntry(url));
1571 EXPECT_FALSE(prerender_handle->IsPrerendering());
1574 } // namespace prerender