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

Unified Diff: chrome/renderer/prerender/prerender_dispatcher_unittest.cc

Issue 10918189: Add PrerenderStatusEvent on Prerenders (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: rebase to trunk, remove some unrelated fixes... Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/prerender/prerender_dispatcher.cc ('k') | chrome/test/data/prerender/prerender_loader.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/prerender/prerender_dispatcher_unittest.cc
diff --git a/chrome/renderer/prerender/prerender_dispatcher_unittest.cc b/chrome/renderer/prerender/prerender_dispatcher_unittest.cc
index f7170ba8b4c6a49c1bb7dc4fed4f8283f2ea5807..ebe807b5ee1ae8e383d9281ec4b6ca7b89dbfc3a 100644
--- a/chrome/renderer/prerender/prerender_dispatcher_unittest.cc
+++ b/chrome/renderer/prerender/prerender_dispatcher_unittest.cc
@@ -11,29 +11,62 @@
namespace prerender {
+namespace {
+
+int s_next_prerender_id = 0;
+
+} // namespace
+
+using WebKit::WebPrerender;
+
+// Since we can't mock out WebKit::WebPrerender in chrome, this test can't test
+// signalling to or from the WebKit side. Instead, it checks only that the
+// messages received from the browser generate consistant state in the
+// PrerenderDispatcher. Since prerenders couldn't even start or stop without the
+// WebKit signalling, we can expect PrerenderBrowserTest to provide adequate
+// coverage of this.
class PrerenderDispatcherTest : public testing::Test {
public:
PrerenderDispatcherTest() {}
bool is_prerender_url(const GURL& url) const {
- return prerender_dispatcher_.IsPrerenderURL(url);
+ // We cannot call PrerenderDispatcher::IsPrerenderURL, since it dereferences
+ // WebPrerender to call WebPrerender::url().
+ for (std::multimap<int, GURL>::const_iterator
+ it = prerender_dispatcher_.prerender_aliases_.begin();
+ it != prerender_dispatcher_.prerender_aliases_.end(); ++it) {
+ if (it->second == url)
+ return true;
+ }
+ return false;
+ }
+
+ const std::map<int, WebPrerender*>& prerenders() const {
+ return prerender_dispatcher_.prerenders_;
}
- const PrerenderDispatcher::PrerenderMap& urls() const {
- return prerender_dispatcher_.prerender_urls_;
+ int StartPrerender() {
+ prerender_dispatcher_.OnStartedPrerender(s_next_prerender_id);
+ return s_next_prerender_id++;
}
- void AddURL(const GURL& url) { prerender_dispatcher_.OnAddPrerenderURL(url); }
- void RemoveURL(const GURL& url) {
- prerender_dispatcher_.OnRemovePrerenderURL(url);
+ void AddAliasToPrerender(int prerender_id, const GURL& url) {
+ prerender_dispatcher_.OnAddAliasToPrerender(prerender_id, url);
+ }
+
+ void StopPrerender(int prerender_id) {
+ prerender_dispatcher_.OnStoppedPrerender(prerender_id);
}
int GetCountForURL(const GURL& url) const {
- PrerenderDispatcher::PrerenderMap::const_iterator entry = urls().find(url);
- if (entry == urls().end())
- return 0;
- EXPECT_GT(entry->second, 0);
- return entry->second;
+ int count = 0;
+ for (std::multimap<int, GURL>::const_iterator
+ it = prerender_dispatcher_.prerender_aliases_.begin();
+ it != prerender_dispatcher_.prerender_aliases_.end(); ++it) {
+ if (it->second == url)
+ count++;
+ }
+ return count;
}
private:
@@ -42,13 +75,14 @@ class PrerenderDispatcherTest : public testing::Test {
};
TEST_F(PrerenderDispatcherTest, PrerenderDispatcherEmpty) {
- EXPECT_EQ(0U, urls().size());
+ EXPECT_EQ(0U, prerenders().size());
}
TEST_F(PrerenderDispatcherTest, PrerenderDispatcherSingleAdd) {
GURL foo_url = GURL("http://foo.com");
EXPECT_FALSE(is_prerender_url(foo_url));
- AddURL(foo_url);
+ int foo_id = StartPrerender();
+ AddAliasToPrerender(foo_id, foo_url);
EXPECT_TRUE(is_prerender_url(foo_url));
EXPECT_EQ(1, GetCountForURL(foo_url));
}
@@ -59,16 +93,18 @@ TEST_F(PrerenderDispatcherTest, PrerenderDispatcherMultipleAdd) {
EXPECT_FALSE(is_prerender_url(foo_url));
EXPECT_FALSE(is_prerender_url(bar_url));
- AddURL(foo_url);
+ int foo_id = StartPrerender();
+ AddAliasToPrerender(foo_id, foo_url);
EXPECT_TRUE(is_prerender_url(foo_url));
EXPECT_FALSE(is_prerender_url(bar_url));
- AddURL(foo_url);
+ AddAliasToPrerender(foo_id, foo_url);
EXPECT_TRUE(is_prerender_url(foo_url));
EXPECT_FALSE(is_prerender_url(bar_url));
EXPECT_EQ(2, GetCountForURL(foo_url));
- AddURL(bar_url);
+ int bar_id = StartPrerender();
+ AddAliasToPrerender(bar_id, bar_url);
EXPECT_TRUE(is_prerender_url(foo_url));
EXPECT_TRUE(is_prerender_url(bar_url));
EXPECT_EQ(2, GetCountForURL(foo_url));
@@ -78,9 +114,10 @@ TEST_F(PrerenderDispatcherTest, PrerenderDispatcherMultipleAdd) {
TEST_F(PrerenderDispatcherTest, PrerenderDispatcherSingleRemove) {
GURL foo_url = GURL("http://foo.com");
EXPECT_FALSE(is_prerender_url(foo_url));
- AddURL(foo_url);
+ int foo_id = StartPrerender();
+ AddAliasToPrerender(foo_id, foo_url);
EXPECT_TRUE(is_prerender_url(foo_url));
- RemoveURL(foo_url);
+ StopPrerender(foo_id);
EXPECT_FALSE(is_prerender_url(foo_url));
EXPECT_EQ(0, GetCountForURL(foo_url));
}
@@ -88,17 +125,14 @@ TEST_F(PrerenderDispatcherTest, PrerenderDispatcherSingleRemove) {
TEST_F(PrerenderDispatcherTest, PrerenderDispatcherMultipleRemove) {
GURL foo_url = GURL("http://foo.com");
EXPECT_FALSE(is_prerender_url(foo_url));
- AddURL(foo_url);
+ int foo_id = StartPrerender();
+ AddAliasToPrerender(foo_id, foo_url);
EXPECT_TRUE(is_prerender_url(foo_url));
- AddURL(foo_url);
+ AddAliasToPrerender(foo_id, foo_url);
EXPECT_TRUE(is_prerender_url(foo_url));
EXPECT_EQ(2, GetCountForURL(foo_url));
- RemoveURL(foo_url);
- EXPECT_TRUE(is_prerender_url(foo_url));
- EXPECT_EQ(1, GetCountForURL(foo_url));
-
- RemoveURL(foo_url);
+ StopPrerender(foo_id);
EXPECT_FALSE(is_prerender_url(foo_url));
EXPECT_EQ(0, GetCountForURL(foo_url));
}
@@ -106,7 +140,8 @@ TEST_F(PrerenderDispatcherTest, PrerenderDispatcherMultipleRemove) {
TEST_F(PrerenderDispatcherTest, PrerenderDispatcherRemoveWithoutAdd) {
GURL foo_url = GURL("http://foo.com");
EXPECT_FALSE(is_prerender_url(foo_url));
- RemoveURL(foo_url);
+ int crazy_prerender_id = 13;
+ StopPrerender(crazy_prerender_id);
EXPECT_FALSE(is_prerender_url(foo_url));
EXPECT_EQ(0, GetCountForURL(foo_url));
}
@@ -114,11 +149,12 @@ TEST_F(PrerenderDispatcherTest, PrerenderDispatcherRemoveWithoutAdd) {
TEST_F(PrerenderDispatcherTest, PrerenderDispatcherRemoveTooMany) {
GURL foo_url = GURL("http://foo.com");
EXPECT_FALSE(is_prerender_url(foo_url));
- AddURL(foo_url);
+ int foo_id = StartPrerender();
+ AddAliasToPrerender(foo_id, foo_url);
EXPECT_TRUE(is_prerender_url(foo_url));
- RemoveURL(foo_url);
+ StopPrerender(foo_id);
EXPECT_FALSE(is_prerender_url(foo_url));
- RemoveURL(foo_url);
+ StopPrerender(foo_id);
EXPECT_FALSE(is_prerender_url(foo_url));
EXPECT_EQ(0, GetCountForURL(foo_url));
}
« no previous file with comments | « chrome/renderer/prerender/prerender_dispatcher.cc ('k') | chrome/test/data/prerender/prerender_loader.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698