Index: chrome/browser/prerender/prerender_unittest.cc |
diff --git a/chrome/browser/prerender/prerender_manager_unittest.cc b/chrome/browser/prerender/prerender_unittest.cc |
similarity index 78% |
rename from chrome/browser/prerender/prerender_manager_unittest.cc |
rename to chrome/browser/prerender/prerender_unittest.cc |
index dd023b194ff6157878d2fa35b627fb7077921393..dfc3786fe1ba9a2a49342653af850f9524742f0a 100644 |
--- a/chrome/browser/prerender/prerender_manager_unittest.cc |
+++ b/chrome/browser/prerender/prerender_unittest.cc |
@@ -7,6 +7,7 @@ |
#include "base/message_loop.h" |
#include "base/time.h" |
#include "chrome/browser/prerender/prerender_contents.h" |
+#include "chrome/browser/prerender/prerender_link_manager.h" |
#include "chrome/browser/prerender/prerender_manager.h" |
#include "chrome/browser/prerender/prerender_origin.h" |
#include "chrome/common/chrome_switches.h" |
@@ -16,6 +17,7 @@ |
#include "content/test/test_browser_thread.h" |
#include "googleurl/src/gurl.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#include "ui/gfx/size.h" |
using content::BrowserThread; |
@@ -61,6 +63,11 @@ class DummyPrerenderContents : public PrerenderContents { |
FinalStatus expected_final_status() const { return expected_final_status_; } |
+ bool prerendering_has_been_cancelled() const |
+ { |
+ return PrerenderContents::prerendering_has_been_cancelled(); |
+ } |
+ |
private: |
bool has_started_; |
FinalStatus expected_final_status_; |
@@ -141,13 +148,6 @@ class TestPrerenderManager : public PrerenderManager { |
return prerender_contents; |
} |
- // Shorthand to add a simple preload with a reasonable source. |
- bool AddSimplePrerender(const GURL& url) { |
- return AddPrerenderFromLinkRelPrerender(-1, -1, |
- url, |
- content::Referrer()); |
- } |
- |
void set_rate_limit_enabled(bool enabled) { |
mutable_config().rate_limit_enabled = enabled; |
} |
@@ -207,11 +207,17 @@ class RestorePrerenderMode { |
} // namespace |
-class PrerenderManagerTest : public testing::Test { |
+class PrerenderTest : public testing::Test { |
public: |
- PrerenderManagerTest() : ui_thread_(BrowserThread::UI, &message_loop_), |
- prerender_manager_( |
- new TestPrerenderManager(prerender_tracker())) { |
+ static const int kDefaultChildId = -1; |
+ static const int kDefaultRenderViewRouteId = -1; |
+ |
+ PrerenderTest() : ui_thread_(BrowserThread::UI, &message_loop_), |
+ prerender_manager_( |
+ new TestPrerenderManager(prerender_tracker())), |
+ prerender_link_manager_( |
+ new PrerenderLinkManager(prerender_manager_.get())), |
+ last_prerender_id_(0) { |
// Enable omnibox prerendering. |
CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
switches::kPrerenderFromOmnibox, |
@@ -222,7 +228,36 @@ class PrerenderManagerTest : public testing::Test { |
return prerender_manager_.get(); |
} |
+ PrerenderLinkManager* prerender_link_manager() { |
+ return prerender_link_manager_.get(); |
+ } |
+ |
+ int last_prerender_id() const { |
+ return last_prerender_id_; |
+ } |
+ |
+ // Shorthand to add a simple preload with a reasonable source. |
+ bool AddSimplePrerender(const GURL& url) { |
+ prerender_link_manager()->OnAddPrerender(GetNextPrerenderID(), |
+ kDefaultChildId, |
+ url, |
+ content::Referrer(), |
+ gfx::Size(0,0), |
+ kDefaultRenderViewRouteId); |
+ return prerender_manager()->IsPrerendering(url); |
+ } |
+ |
+ bool AddSimplePrerenderViaManager(const GURL& url) { |
mmenke
2012/04/24 15:26:15
This is little weird. Since all link rel prerende
gavinp
2012/04/26 23:55:39
Done, with the second option.
|
+ return prerender_manager()->AddPrerenderFromLinkRelPrerender( |
+ kDefaultChildId, kDefaultRenderViewRouteId, url, content::Referrer()); |
+ } |
+ |
private: |
+ int GetNextPrerenderID() { |
+ ++last_prerender_id_; |
+ return last_prerender_id_; |
+ } |
+ |
PrerenderTracker* prerender_tracker() { |
return g_browser_process->prerender_tracker(); |
} |
@@ -231,35 +266,37 @@ class PrerenderManagerTest : public testing::Test { |
MessageLoop message_loop_; |
content::TestBrowserThread ui_thread_; |
scoped_ptr<TestPrerenderManager> prerender_manager_; |
+ scoped_ptr<PrerenderLinkManager> prerender_link_manager_; |
+ int last_prerender_id_; |
}; |
-TEST_F(PrerenderManagerTest, EmptyTest) { |
+TEST_F(PrerenderTest, EmptyTest) { |
EXPECT_FALSE(prerender_manager()->MaybeUsePrerenderedPage( |
NULL, |
GURL("http://www.google.com/"))); |
} |
-TEST_F(PrerenderManagerTest, FoundTest) { |
+TEST_F(PrerenderTest, FoundTest) { |
GURL url("http://www.google.com/"); |
DummyPrerenderContents* prerender_contents = |
prerender_manager()->CreateNextPrerenderContents( |
url, |
FINAL_STATUS_USED); |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url)); |
+ EXPECT_TRUE(AddSimplePrerender(url)); |
EXPECT_TRUE(prerender_contents->has_started()); |
ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(url)); |
} |
// Make sure that if queue a request, and a second prerender request for the |
// same URL comes in, that we drop the second request and keep the first one. |
-TEST_F(PrerenderManagerTest, DropSecondRequestTest) { |
+TEST_F(PrerenderTest, DropSecondRequestTest) { |
GURL url("http://www.google.com/"); |
DummyPrerenderContents* prerender_contents = |
prerender_manager()->CreateNextPrerenderContents( |
url, |
FINAL_STATUS_USED); |
DummyPrerenderContents* null = NULL; |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url)); |
+ EXPECT_TRUE(AddSimplePrerender(url)); |
EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); |
EXPECT_TRUE(prerender_contents->has_started()); |
@@ -267,7 +304,7 @@ TEST_F(PrerenderManagerTest, DropSecondRequestTest) { |
prerender_manager()->CreateNextPrerenderContents( |
url, |
FINAL_STATUS_MANAGER_SHUTDOWN); |
- EXPECT_FALSE(prerender_manager()->AddSimplePrerender(url)); |
+ EXPECT_FALSE(AddSimplePrerenderViaManager(url)); |
EXPECT_EQ(prerender_contents1, |
prerender_manager()->next_prerender_contents()); |
EXPECT_FALSE(prerender_contents1->has_started()); |
@@ -276,14 +313,14 @@ TEST_F(PrerenderManagerTest, DropSecondRequestTest) { |
} |
// Ensure that we expire a prerendered page after the max. permitted time. |
-TEST_F(PrerenderManagerTest, ExpireTest) { |
+TEST_F(PrerenderTest, ExpireTest) { |
GURL url("http://www.google.com/"); |
DummyPrerenderContents* prerender_contents = |
prerender_manager()->CreateNextPrerenderContents( |
url, |
FINAL_STATUS_TIMED_OUT); |
DummyPrerenderContents* null = NULL; |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url)); |
+ EXPECT_TRUE(AddSimplePrerender(url)); |
EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); |
EXPECT_TRUE(prerender_contents->has_started()); |
prerender_manager()->AdvanceTime(prerender_manager()->GetMaxAge() + |
@@ -293,14 +330,14 @@ TEST_F(PrerenderManagerTest, ExpireTest) { |
// LRU Test. Make sure that if we prerender more than one request, that |
// the oldest one will be dropped. |
-TEST_F(PrerenderManagerTest, DropOldestRequestTest) { |
+TEST_F(PrerenderTest, DropOldestRequestTest) { |
GURL url("http://www.google.com/"); |
DummyPrerenderContents* prerender_contents = |
prerender_manager()->CreateNextPrerenderContents( |
url, |
FINAL_STATUS_EVICTED); |
DummyPrerenderContents* null = NULL; |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url)); |
+ EXPECT_TRUE(AddSimplePrerender(url)); |
EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); |
EXPECT_TRUE(prerender_contents->has_started()); |
@@ -309,7 +346,7 @@ TEST_F(PrerenderManagerTest, DropOldestRequestTest) { |
prerender_manager()->CreateNextPrerenderContents( |
url1, |
FINAL_STATUS_USED); |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url1)); |
+ EXPECT_TRUE(AddSimplePrerender(url1)); |
EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); |
EXPECT_TRUE(prerender_contents1->has_started()); |
@@ -319,7 +356,7 @@ TEST_F(PrerenderManagerTest, DropOldestRequestTest) { |
// Two element prerender test. Ensure that the LRU operates correctly if we |
// permit 2 elements to be kept prerendered. |
-TEST_F(PrerenderManagerTest, TwoElementPrerenderTest) { |
+TEST_F(PrerenderTest, TwoElementPrerenderTest) { |
prerender_manager()->mutable_config().max_elements = 2; |
GURL url("http://www.google.com/"); |
DummyPrerenderContents* prerender_contents = |
@@ -327,7 +364,7 @@ TEST_F(PrerenderManagerTest, TwoElementPrerenderTest) { |
url, |
FINAL_STATUS_EVICTED); |
DummyPrerenderContents* null = NULL; |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url)); |
+ EXPECT_TRUE(AddSimplePrerender(url)); |
EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); |
EXPECT_TRUE(prerender_contents->has_started()); |
@@ -336,7 +373,7 @@ TEST_F(PrerenderManagerTest, TwoElementPrerenderTest) { |
prerender_manager()->CreateNextPrerenderContents( |
url1, |
FINAL_STATUS_USED); |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url1)); |
+ EXPECT_TRUE(AddSimplePrerender(url1)); |
EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); |
EXPECT_TRUE(prerender_contents1->has_started()); |
@@ -345,7 +382,7 @@ TEST_F(PrerenderManagerTest, TwoElementPrerenderTest) { |
prerender_manager()->CreateNextPrerenderContents( |
url2, |
FINAL_STATUS_USED); |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url2)); |
+ EXPECT_TRUE(AddSimplePrerender(url2)); |
EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); |
EXPECT_TRUE(prerender_contents2->has_started()); |
@@ -354,7 +391,7 @@ TEST_F(PrerenderManagerTest, TwoElementPrerenderTest) { |
ASSERT_EQ(prerender_contents2, prerender_manager()->GetEntry(url2)); |
} |
-TEST_F(PrerenderManagerTest, AliasURLTest) { |
+TEST_F(PrerenderTest, AliasURLTest) { |
GURL url("http://www.google.com/"); |
GURL alias_url1("http://www.google.com/index.html"); |
GURL alias_url2("http://google.com/"); |
@@ -367,37 +404,37 @@ TEST_F(PrerenderManagerTest, AliasURLTest) { |
DummyPrerenderContents* prerender_contents = |
prerender_manager()->CreateNextPrerenderContents( |
url, alias_urls, FINAL_STATUS_USED); |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url)); |
+ EXPECT_TRUE(AddSimplePrerender(url)); |
ASSERT_EQ(NULL, prerender_manager()->GetEntry(not_an_alias_url)); |
ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(alias_url1)); |
prerender_contents = prerender_manager()->CreateNextPrerenderContents( |
url, alias_urls, FINAL_STATUS_USED); |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url)); |
+ EXPECT_TRUE(AddSimplePrerender(url)); |
ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(alias_url2)); |
prerender_contents = prerender_manager()->CreateNextPrerenderContents( |
url, alias_urls, FINAL_STATUS_USED); |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url)); |
+ EXPECT_TRUE(AddSimplePrerender(url)); |
ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(url)); |
// Test that alias URLs can not be added. |
prerender_contents = prerender_manager()->CreateNextPrerenderContents( |
url, alias_urls, FINAL_STATUS_USED); |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url)); |
- EXPECT_FALSE(prerender_manager()->AddSimplePrerender(url)); |
- EXPECT_FALSE(prerender_manager()->AddSimplePrerender(alias_url1)); |
- EXPECT_FALSE(prerender_manager()->AddSimplePrerender(alias_url2)); |
+ EXPECT_TRUE(AddSimplePrerender(url)); |
+ EXPECT_FALSE(AddSimplePrerenderViaManager(url)); |
+ EXPECT_FALSE(AddSimplePrerenderViaManager(alias_url1)); |
+ EXPECT_FALSE(AddSimplePrerenderViaManager(alias_url2)); |
ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(url)); |
} |
// Ensure that we ignore prerender requests within the rate limit. |
-TEST_F(PrerenderManagerTest, RateLimitInWindowTest) { |
+TEST_F(PrerenderTest, RateLimitInWindowTest) { |
GURL url("http://www.google.com/"); |
DummyPrerenderContents* prerender_contents = |
prerender_manager()->CreateNextPrerenderContents( |
url, |
FINAL_STATUS_MANAGER_SHUTDOWN); |
DummyPrerenderContents* null = NULL; |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url)); |
+ EXPECT_TRUE(AddSimplePrerender(url)); |
EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); |
EXPECT_TRUE(prerender_contents->has_started()); |
@@ -408,19 +445,19 @@ TEST_F(PrerenderManagerTest, RateLimitInWindowTest) { |
prerender_manager()->CreateNextPrerenderContents( |
url, |
FINAL_STATUS_MANAGER_SHUTDOWN); |
- EXPECT_FALSE(prerender_manager()->AddSimplePrerender(url1)); |
+ EXPECT_FALSE(AddSimplePrerender(url1)); |
prerender_manager()->set_rate_limit_enabled(false); |
} |
// Ensure that we don't ignore prerender requests outside the rate limit. |
-TEST_F(PrerenderManagerTest, RateLimitOutsideWindowTest) { |
+TEST_F(PrerenderTest, RateLimitOutsideWindowTest) { |
GURL url("http://www.google.com/"); |
DummyPrerenderContents* prerender_contents = |
prerender_manager()->CreateNextPrerenderContents( |
url, |
FINAL_STATUS_EVICTED); |
DummyPrerenderContents* null = NULL; |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url)); |
+ EXPECT_TRUE(AddSimplePrerender(url)); |
EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); |
EXPECT_TRUE(prerender_contents->has_started()); |
@@ -433,19 +470,19 @@ TEST_F(PrerenderManagerTest, RateLimitOutsideWindowTest) { |
prerender_manager()->CreateNextPrerenderContents( |
url1, |
FINAL_STATUS_MANAGER_SHUTDOWN); |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url1)); |
+ EXPECT_TRUE(AddSimplePrerender(url1)); |
EXPECT_EQ(null, prerender_manager()->next_prerender_contents()); |
EXPECT_TRUE(rate_limit_prerender_contents->has_started()); |
prerender_manager()->set_rate_limit_enabled(false); |
} |
-TEST_F(PrerenderManagerTest, PendingPrerenderTest) { |
+TEST_F(PrerenderTest, PendingPrerenderTest) { |
GURL url("http://www.google.com/"); |
DummyPrerenderContents* prerender_contents = |
prerender_manager()->CreateNextPrerenderContents( |
url, |
FINAL_STATUS_USED); |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url)); |
+ EXPECT_TRUE(AddSimplePrerender(url)); |
int child_id; |
int route_id; |
@@ -465,7 +502,7 @@ TEST_F(PrerenderManagerTest, PendingPrerenderTest) { |
// Tests that a PrerenderManager created for a browser session in the control |
// group works as expected. |
-TEST_F(PrerenderManagerTest, ControlGroup) { |
+TEST_F(PrerenderTest, ControlGroup) { |
RestorePrerenderMode restore_prerender_mode; |
PrerenderManager::SetMode( |
PrerenderManager::PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP); |
@@ -474,14 +511,14 @@ TEST_F(PrerenderManagerTest, ControlGroup) { |
prerender_manager()->CreateNextPrerenderContents( |
url, |
FINAL_STATUS_MANAGER_SHUTDOWN); |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url)); |
+ EXPECT_TRUE(AddSimplePrerender(url)); |
EXPECT_FALSE(prerender_contents->has_started()); |
} |
// Tests that prerendering is cancelled when the source render view does not |
// exist. On failure, the DCHECK in CreatePrerenderContents() above should be |
// triggered. |
-TEST_F(PrerenderManagerTest, SourceRenderViewClosed) { |
+TEST_F(PrerenderTest, SourceRenderViewClosed) { |
GURL url("http://www.google.com/"); |
prerender_manager()->CreateNextPrerenderContents( |
url, |
@@ -492,55 +529,55 @@ TEST_F(PrerenderManagerTest, SourceRenderViewClosed) { |
// Tests that the prerender manager ignores fragment references when matching |
// prerender URLs in the case the fragment is not in the prerender URL. |
-TEST_F(PrerenderManagerTest, PageMatchesFragmentTest) { |
+TEST_F(PrerenderTest, PageMatchesFragmentTest) { |
GURL url("http://www.google.com/"); |
GURL fragment_url("http://www.google.com/#test"); |
DummyPrerenderContents* prerender_contents = |
prerender_manager()->CreateNextPrerenderContents(url, |
FINAL_STATUS_USED); |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url)); |
+ EXPECT_TRUE(AddSimplePrerender(url)); |
EXPECT_TRUE(prerender_contents->has_started()); |
ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(fragment_url)); |
} |
// Tests that the prerender manager ignores fragment references when matching |
// prerender URLs in the case the fragment is in the prerender URL. |
-TEST_F(PrerenderManagerTest, FragmentMatchesPageTest) { |
+TEST_F(PrerenderTest, FragmentMatchesPageTest) { |
GURL url("http://www.google.com/"); |
GURL fragment_url("http://www.google.com/#test"); |
DummyPrerenderContents* prerender_contents = |
prerender_manager()->CreateNextPrerenderContents(fragment_url, |
FINAL_STATUS_USED); |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(fragment_url)); |
+ EXPECT_TRUE(AddSimplePrerenderViaManager(fragment_url)); |
EXPECT_TRUE(prerender_contents->has_started()); |
ASSERT_EQ(prerender_contents, prerender_manager()->GetEntry(url)); |
} |
// Tests that the prerender manager ignores fragment references when matching |
// prerender URLs in the case the fragment is in both URLs. |
-TEST_F(PrerenderManagerTest, FragmentMatchesFragmentTest) { |
+TEST_F(PrerenderTest, FragmentMatchesFragmentTest) { |
GURL fragment_url("http://www.google.com/#test"); |
GURL other_fragment_url("http://www.google.com/#other_test"); |
DummyPrerenderContents* prerender_contents = |
prerender_manager()->CreateNextPrerenderContents(fragment_url, |
FINAL_STATUS_USED); |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(fragment_url)); |
+ EXPECT_TRUE(AddSimplePrerenderViaManager(fragment_url)); |
EXPECT_TRUE(prerender_contents->has_started()); |
ASSERT_EQ(prerender_contents, |
prerender_manager()->GetEntry(other_fragment_url)); |
} |
// Make sure that clearing works as expected. |
-TEST_F(PrerenderManagerTest, ClearTest) { |
+TEST_F(PrerenderTest, ClearTest) { |
GURL url("http://www.google.com/"); |
DummyPrerenderContents* prerender_contents = |
prerender_manager()->CreateNextPrerenderContents( |
url, |
FINAL_STATUS_CACHE_OR_HISTORY_CLEARED); |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url)); |
+ EXPECT_TRUE(AddSimplePrerender(url)); |
EXPECT_TRUE(prerender_contents->has_started()); |
prerender_manager()->ClearData(PrerenderManager::CLEAR_PRERENDER_CONTENTS); |
DummyPrerenderContents* null = NULL; |
@@ -548,12 +585,12 @@ TEST_F(PrerenderManagerTest, ClearTest) { |
} |
// Make sure canceling works as expected. |
-TEST_F(PrerenderManagerTest, CancelAllTest) { |
+TEST_F(PrerenderTest, CancelAllTest) { |
GURL url("http://www.google.com/"); |
DummyPrerenderContents* prerender_contents = |
prerender_manager()->CreateNextPrerenderContents( |
url, FINAL_STATUS_CANCELLED); |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url)); |
+ EXPECT_TRUE(AddSimplePrerender(url)); |
EXPECT_TRUE(prerender_contents->has_started()); |
prerender_manager()->CancelAllPrerenders(); |
const DummyPrerenderContents* null = NULL; |
@@ -561,7 +598,7 @@ TEST_F(PrerenderManagerTest, CancelAllTest) { |
} |
// Make sure canceling for omnibox works as expected. |
-TEST_F(PrerenderManagerTest, CancelOmniboxRemovesOmniboxTest) { |
+TEST_F(PrerenderTest, CancelOmniboxRemovesOmniboxTest) { |
// Check canceling removes the Omnibox url. |
GURL url("http://www.google.com/"); |
DummyPrerenderContents* prerender_contents = |
@@ -574,28 +611,68 @@ TEST_F(PrerenderManagerTest, CancelOmniboxRemovesOmniboxTest) { |
EXPECT_EQ(null, prerender_manager()->FindEntry(url)); |
} |
-TEST_F(PrerenderManagerTest, CancelOmniboxDoesNotRemoveLinkTest) { |
+TEST_F(PrerenderTest, CancelOmniboxDoesNotRemoveLinkTest) { |
GURL url("http://www.google.com/"); |
DummyPrerenderContents* prerender_contents = |
prerender_manager()->CreateNextPrerenderContents( |
url, ORIGIN_LINK_REL_PRERENDER, FINAL_STATUS_MANAGER_SHUTDOWN); |
- EXPECT_TRUE(prerender_manager()->AddSimplePrerender(url)); |
+ EXPECT_TRUE(AddSimplePrerender(url)); |
EXPECT_TRUE(prerender_contents->has_started()); |
prerender_manager()->CancelOmniboxPrerenders(); |
const DummyPrerenderContents* null = NULL; |
EXPECT_NE(null, prerender_manager()->FindEntry(url)); |
} |
-TEST_F(PrerenderManagerTest, OmniboxNotAllowedWhenDisabled) { |
+TEST_F(PrerenderTest, OmniboxNotAllowedWhenDisabled) { |
prerender_manager()->set_enabled(false); |
EXPECT_FALSE(prerender_manager()->AddPrerenderFromOmnibox( |
GURL("http://www.example.com"), NULL)); |
} |
-TEST_F(PrerenderManagerTest, LinkRelNotAllowedWhenDisabled) { |
+TEST_F(PrerenderTest, LinkRelNotAllowedWhenDisabled) { |
prerender_manager()->set_enabled(false); |
- EXPECT_FALSE(prerender_manager()->AddSimplePrerender( |
+ EXPECT_FALSE(AddSimplePrerender( |
GURL("http://www.example.com"))); |
} |
+TEST_F(PrerenderTest, LinkManagerCancel) { |
mmenke
2012/04/24 15:26:15
Other test suggestions:
Cancel a prerender that's
gavinp
2012/04/26 23:55:39
Yes, but expired instead of cancelled.
|
+ GURL url("http://www.myexample.com"); |
+ DummyPrerenderContents* prerender_contents = |
+ prerender_manager()->CreateNextPrerenderContents( |
+ url, |
+ FINAL_STATUS_CANCELLED); |
+ EXPECT_TRUE(AddSimplePrerender(url)); |
+ EXPECT_TRUE(prerender_contents->has_started()); |
+ EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled()); |
+ ASSERT_EQ(prerender_contents, prerender_manager()->FindEntry(url)); |
+ prerender_link_manager()->OnCancelPrerender(last_prerender_id(), |
+ kDefaultChildId); |
+ EXPECT_TRUE(prerender_contents->prerendering_has_been_cancelled()); |
+ DummyPrerenderContents* null = NULL; |
+ ASSERT_EQ(null, prerender_manager()->GetEntry(url)); |
+ |
+} |
+ |
+TEST_F(PrerenderTest, LinkManagerCancelTwiceCrash) { |
+ GURL url("http://www.myexample.com"); |
+ DummyPrerenderContents* prerender_contents = |
+ prerender_manager()->CreateNextPrerenderContents( |
+ url, |
+ FINAL_STATUS_CANCELLED); |
+ EXPECT_TRUE(AddSimplePrerender(url)); |
+ EXPECT_TRUE(prerender_contents->has_started()); |
+ EXPECT_FALSE(prerender_contents->prerendering_has_been_cancelled()); |
+ ASSERT_EQ(prerender_contents, prerender_manager()->FindEntry(url)); |
+ prerender_link_manager()->OnCancelPrerender(last_prerender_id(), |
+ kDefaultChildId); |
+ EXPECT_TRUE(prerender_contents->prerendering_has_been_cancelled()); |
+ DummyPrerenderContents* null = NULL; |
+ ASSERT_EQ(null, prerender_manager()->GetEntry(url)); |
+ EXPECT_DEBUG_DEATH( |
+ prerender_link_manager()->OnCancelPrerender(last_prerender_id(), |
+ kDefaultChildId), |
+ "Canceling a prerender that doesn't exist"); |
+ |
+} |
+ |
} // namespace prerender |