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

Unified Diff: chrome/renderer/searchbox/searchbox_unittest.cc

Issue 1017853002: [Icons NTP] Allow chrome-search:// large-icon and fallback-icon hosts to use <view_id>/<restricted_… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: LargeIconUrlParser not in chrome namespace; add tests. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/searchbox/searchbox_unittest.cc
diff --git a/chrome/renderer/searchbox/searchbox_unittest.cc b/chrome/renderer/searchbox/searchbox_unittest.cc
index 322d4f81e9c843f77a7e92f793a50a990de704ce..9371350524361ac51300695086c2a4adb9eb5c4c 100644
--- a/chrome/renderer/searchbox/searchbox_unittest.cc
+++ b/chrome/renderer/searchbox/searchbox_unittest.cc
@@ -20,6 +20,18 @@ bool GetRestrictedIDFromFaviconUrl(int render_view_id,
std::string* favicon_params,
InstantRestrictedID* rid);
+// Defined in searchbox.cc
+bool GetRestrictedIDFromLargeIconUrl(int render_view_id,
+ const GURL& url,
+ std::string* favicon_params,
+ InstantRestrictedID* rid);
+
+// Defined in searchbox.cc
+bool GetRestrictedIDFromFallbackIconUrl(int render_view_id,
+ const GURL& url,
+ std::string* favicon_params,
+ InstantRestrictedID* rid);
+
TEST(SearchBoxUtilTest, GetInstantRestrictedIDFromTransientURL) {
const int kInvalidRenderViewID = 920;
const int kValidRenderViewID = 1;
@@ -230,4 +242,184 @@ TEST(SearchBoxUtilTest, ParseRestrictedFaviconTransientUrl) {
}
}
+TEST(SearchBoxUtilTest, GetRestrictedIDFromLargeIconUrl) {
+ const int kInvalidRenderViewID = 920;
+ const int kValidRenderViewID = 1;
+
+ const struct {
+ int render_view_id;
+ GURL transient_url;
+ std::string expected_icon_params;
+ InstantRestrictedID expected_rid;
+ bool expected_return_val;
+ } test_cases[] = {
+ // RenderView ID matches the view id specified in the transient url.
+ {
+ kValidRenderViewID,
+ GURL("chrome-search://big-icon/96/1/2"),
+ "96/",
+ 2,
+ true
+ },
+
+ // RenderView ID does not match the view id specified in the transient url.
+ {
+ kInvalidRenderViewID,
+ GURL("chrome-search://big-icon/96/1/2"),
+ "96/",
+ 0,
+ true
+ },
+
+ // Invalid transient urls.
+ {
+ kValidRenderViewID,
+ GURL("chrome-search://big-icon"),
+ "",
+ 0,
+ false
+ },
+ {
+ kValidRenderViewID,
+ GURL("chrome-search://big-icon/"),
+ "",
+ 0,
+ false
+ },
+ {
+ kValidRenderViewID,
+ GURL("chrome-search://big-icon/96"),
+ "",
+ 0,
+ false
+ },
+ {
+ kValidRenderViewID,
+ GURL("chrome-search://big-icon/96/123"),
+ "96/",
+ 0,
+ true
+ },
+ {
+ kValidRenderViewID,
+ GURL("chrome-search://big-icon/96/xyz"),
+ "96/",
+ 0,
+ true
+ },
+ {
+ kValidRenderViewID,
+ GURL("chrome-search://big-icon/invalidparameter/96/1/2"),
+ "",
+ 0,
+ false // More stringent than chrome-search://favicon.
+ }
+ };
+
+ std::string icon_params = "";
+ InstantRestrictedID rid = 0;
+ for (size_t i = 0; i < arraysize(test_cases); ++i) {
+ bool return_val = GetRestrictedIDFromLargeIconUrl(
+ test_cases[i].render_view_id,
+ test_cases[i].transient_url,
+ &icon_params,
+ &rid);
+ EXPECT_EQ(test_cases[i].expected_return_val, return_val);
+ EXPECT_EQ(test_cases[i].expected_icon_params, icon_params);
+ EXPECT_EQ(test_cases[i].expected_rid, rid);
+ icon_params = "";
+ rid = 0;
+ }
+}
+
+TEST(SearchBoxUtilTest, GetRestrictedIDFromFallbackIconUrl) {
+ const int kInvalidRenderViewID = 920;
+ const int kValidRenderViewID = 1;
+
+ const struct {
+ int render_view_id;
+ GURL transient_url;
+ std::string expected_icon_params;
+ InstantRestrictedID expected_rid;
+ bool expected_return_val;
+ } test_cases[] = {
+ // RenderView ID matches the view id specified in the transient url.
+ {
+ kValidRenderViewID,
+ GURL("chrome-search://fallback-icon/,,,,/1/2"),
+ ",,,,/",
+ 2,
+ true
+ },
+
+ // RenderView ID does not match the view id specified in the transient url.
+ {
+ kInvalidRenderViewID,
+ GURL("chrome-search://fallback-icon/,,,,/1/2"),
+ ",,,,/",
+ 0,
+ true
+ },
+
+ // Invalid transient urls.
+ {
+ kValidRenderViewID,
+ GURL("chrome-search://fallback-icon"),
+ "",
+ 0,
+ false
+ },
+ {
+ kValidRenderViewID,
+ GURL("chrome-search://fallback-icon/"),
+ "",
+ 0,
+ false
+ },
+ {
+ kValidRenderViewID,
+ GURL("chrome-search://fallback-icon/,,,,"),
+ "",
+ 0,
+ false
+ },
+ {
+ kValidRenderViewID,
+ GURL("chrome-search://fallback-icon/,,,,/123"),
+ ",,,,/",
+ 0,
+ true
+ },
+ {
+ kValidRenderViewID,
+ GURL("chrome-search://fallback-icon/,,,,/xyz"),
+ ",,,,/",
+ 0,
+ true
+ },
+ {
+ kValidRenderViewID,
+ GURL("chrome-search://fallback-icon/invalidparameter/,,,,/1/2"),
+ "",
+ 0,
+ false // More stringent than chrome-search://favicon.
+ }
+ };
+
+ std::string icon_params = "";
+ InstantRestrictedID rid = 0;
+ for (size_t i = 0; i < arraysize(test_cases); ++i) {
+ bool return_val = GetRestrictedIDFromFallbackIconUrl(
+ test_cases[i].render_view_id,
+ test_cases[i].transient_url,
+ &icon_params,
+ &rid);
+ EXPECT_EQ(test_cases[i].expected_return_val, return_val);
+ EXPECT_EQ(test_cases[i].expected_icon_params, icon_params);
+ EXPECT_EQ(test_cases[i].expected_rid, rid);
+ icon_params = "";
+ rid = 0;
+ }
+}
+
} // namespace internal
« chrome/renderer/searchbox/searchbox.cc ('K') | « chrome/renderer/searchbox/searchbox.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698