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

Side by Side Diff: chrome/renderer/searchbox/searchbox_unittest.cc

Issue 15388002: Supporting high dpi favicons in Instant Extended. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing Samarth's comments Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "chrome/common/instant_types.h" 6 #include "chrome/common/instant_types.h"
7 #include "googleurl/src/gurl.h" 7 #include "googleurl/src/gurl.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace internal { 10 namespace internal {
11 11
12 // Defined in searchbox_extension.cc 12 // Defined in searchbox_extension.cc
13 bool GetInstantRestrictedIDFromURL(int render_view_id, 13 bool GetInstantRestrictedIDFromURL(int render_view_id,
14 const GURL& url, 14 const GURL& url,
15 InstantRestrictedID* id); 15 InstantRestrictedID* id);
16 16
17 // Defined in searchbox_extension.cc
18 bool ParseRestrictedFaviconUrl(int render_view_id,
19 const GURL& url,
20 std::string* favicon_params,
21 InstantRestrictedID* rid);
22
17 TEST(SearchBoxUtilTest, GetInstantRestrictedIDFromTransientURL) { 23 TEST(SearchBoxUtilTest, GetInstantRestrictedIDFromTransientURL) {
18 const int kInvalidRenderViewID = 920; 24 const int kInvalidRenderViewID = 920;
19 const int kValidRenderViewID = 1; 25 const int kValidRenderViewID = 1;
20 26
21 const struct { 27 const struct {
22 int render_view_id; 28 int render_view_id;
23 GURL transient_url; 29 GURL transient_url;
24 InstantRestrictedID expected_rid; 30 InstantRestrictedID expected_rid;
25 bool expected_return_val; 31 bool expected_return_val;
26 } test_cases[] = { 32 } test_cases[] = {
(...skipping 23 matching lines...) Expand all
50 InstantRestrictedID rid = 0; 56 InstantRestrictedID rid = 0;
51 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { 57 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
52 bool return_val = GetInstantRestrictedIDFromURL( 58 bool return_val = GetInstantRestrictedIDFromURL(
53 test_cases[i].render_view_id, test_cases[i].transient_url, &rid); 59 test_cases[i].render_view_id, test_cases[i].transient_url, &rid);
54 EXPECT_EQ(test_cases[i].expected_return_val, return_val); 60 EXPECT_EQ(test_cases[i].expected_return_val, return_val);
55 EXPECT_EQ(test_cases[i].expected_rid, rid); 61 EXPECT_EQ(test_cases[i].expected_rid, rid);
56 rid = 0; 62 rid = 0;
57 } 63 }
58 } 64 }
59 65
66 TEST(SearchBoxUtilTest, ParseRestrictedFaviconTransientUrl) {
67 const int kInvalidRenderViewID = 920;
68 const int kValidRenderViewID = 1;
69
70 const struct {
71 int render_view_id;
72 GURL transient_url;
73 std::string expected_favicon_params;
74 InstantRestrictedID expected_rid;
75 bool expected_return_val;
76 } test_cases[] = {
77 // RenderView ID matches the view id specified in the transient url.
78 {
79 kValidRenderViewID,
80 GURL("chrome-search://favicon/1/2"),
81 "",
82 2,
83 true
84 },
85 {
86 kValidRenderViewID,
87 GURL("chrome-search://favicon/size/16@2x/1/2"),
88 "size/16@2x/",
89 2,
90 true
91 },
92 {
93 kValidRenderViewID,
94 GURL("chrome-search://favicon/largest/1/2"),
95 "largest/",
96 2,
97 true
98 },
99 {
100 kValidRenderViewID,
101 GURL("chrome-search://favicon/origin/1/2"),
102 "origin/",
103 2,
104 true
105 },
106 {
107 kValidRenderViewID,
108 GURL("chrome-search://favicon/iconurl/1/2"),
109 "iconurl/",
110 2,
111 true
112 },
113
114 // RenderView ID does not match the view id specified in the transient url.
115 {
116 kInvalidRenderViewID,
117 GURL("chrome-search://favicon/1/2"),
118 "",
119 0,
120 false
121 },
122 {
123 kInvalidRenderViewID,
124 GURL("chrome-search://favicon/size/16@2x/1/2"),
125 "",
126 0,
127 false
128 },
129 {
130 kInvalidRenderViewID,
131 GURL("chrome-search://favicon/largest/1/2"),
132 "",
133 0,
134 false
135 },
136 {
137 kInvalidRenderViewID,
138 GURL("chrome-search://favicon/origin/1/2"),
139 "",
140 0,
141 false
142 },
143 {
144 kInvalidRenderViewID,
145 GURL("chrome-search://favicon/iconurl/1/2"),
146 "",
147 0,
148 false
149 },
150
151 // Invalid transient urls.
152 {
153 kValidRenderViewID,
154 GURL("chrome-search://favicon"),
155 "",
156 0,
157 false
158 },
159 {
160 kValidRenderViewID,
161 GURL("chrome-search://favicon/"),
162 "",
163 0,
164 false
165 },
166 {
167 kValidRenderViewID,
168 GURL("chrome-search://favicon/size"),
169 "",
170 0,
171 false
172 },
173 {
174 kValidRenderViewID,
175 GURL("chrome-search://favicon/size/16@2x"),
176 "",
177 0,
178 false
179 },
180 {
181 kValidRenderViewID,
182 GURL("chrome-search://favicon/size/16@2x/123"),
183 "",
184 0,
185 false
186 },
187 {
188 kValidRenderViewID,
189 GURL("chrome-search://favicon/size/16@2x/xyz"),
190 "",
191 0,
192 false
193 },
194 {
195 kValidRenderViewID,
196 GURL("chrome-search://favicon/size/16@2x/123/"),
197 "",
198 0,
199 false
200 },
201 {
202 kValidRenderViewID,
203 GURL("chrome-search://favicon/size/16@2x/123/xyz"),
204 "",
205 0,
206 false
207 },
208 {
209 kValidRenderViewID,
210 GURL("chrome-search://favicon/invalidparameter/16@2x/1/2"),
211 "",
212 0,
213 false
214 }
215 };
216
217 std::string favicon_params = "";
218 InstantRestrictedID rid = 0;
219 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
220 bool return_val = ParseRestrictedFaviconUrl(test_cases[i].render_view_id,
221 test_cases[i].transient_url, &favicon_params, &rid);
222 EXPECT_EQ(test_cases[i].expected_return_val, return_val);
223 EXPECT_EQ(test_cases[i].expected_favicon_params, favicon_params);
224 EXPECT_EQ(test_cases[i].expected_rid, rid);
225 favicon_params = "";
226 rid = 0;
227 }
228 }
229
60 } // namespace internal 230 } // namespace internal
OLDNEW
« chrome/renderer/searchbox/searchbox.cc ('K') | « chrome/renderer/searchbox/searchbox_extension.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698