Delete chrome.mediaGalleriesPrivate because the functionality unique to it has since...
[chromium-blink-merge.git] / chrome / renderer / searchbox / searchbox_unittest.cc
blob322d4f81e9c843f77a7e92f793a50a990de704ce
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
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "chrome/common/instant_types.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "url/gurl.h"
10 namespace internal {
12 // Defined in searchbox.cc
13 bool GetRestrictedIDFromThumbnailUrl(int render_view_id,
14 const GURL& url,
15 InstantRestrictedID* id);
17 // Defined in searchbox.cc
18 bool GetRestrictedIDFromFaviconUrl(int render_view_id,
19 const GURL& url,
20 std::string* favicon_params,
21 InstantRestrictedID* rid);
23 TEST(SearchBoxUtilTest, GetInstantRestrictedIDFromTransientURL) {
24 const int kInvalidRenderViewID = 920;
25 const int kValidRenderViewID = 1;
27 const struct {
28 int render_view_id;
29 GURL transient_url;
30 InstantRestrictedID expected_rid;
31 bool expected_return_val;
32 } test_cases[] = {
33 // RenderView ID matches the view id specified in the transient url.
34 {kValidRenderViewID, GURL("chrome-search://favicon/1/2"), 2, true},
35 {kValidRenderViewID, GURL("chrome-search://thumb/1/2"), 2, true},
37 // RenderView ID does not match the view id specified in the transient url.
38 {kInvalidRenderViewID, GURL("chrome-search://favicon/1/2"), 0, false},
39 {kInvalidRenderViewID, GURL("chrome-search://thumb/1/2"), 0, false},
41 // Invalid transient urls.
42 {kValidRenderViewID, GURL("chrome-search://thumb"), 0, false},
43 {kValidRenderViewID, GURL("chrome-search://thumb/"), 0, false},
44 {kValidRenderViewID, GURL("chrome-search://thumb/123"), 0, false},
45 {kValidRenderViewID, GURL("chrome-search://thumb/xyz"), 0, false},
46 {kValidRenderViewID, GURL("chrome-search://thumb/123/"), 0, false},
47 {kValidRenderViewID, GURL("chrome-search://thumb/123/xyz"), 0, false},
48 {kValidRenderViewID, GURL("chrome-search://favicon"), 0, false},
49 {kValidRenderViewID, GURL("chrome-search://favicon/"), 0, false},
50 {kValidRenderViewID, GURL("chrome-search://favicon/123"), 0, false},
51 {kValidRenderViewID, GURL("chrome-search://favicon/xyz"), 0, false},
52 {kValidRenderViewID, GURL("chrome-search://favicon/123/"), 0, false},
53 {kValidRenderViewID, GURL("chrome-search://favicon/123/xyz"), 0, false}
56 InstantRestrictedID rid = 0;
57 for (size_t i = 0; i < arraysize(test_cases); ++i) {
58 bool return_val = GetRestrictedIDFromThumbnailUrl(
59 test_cases[i].render_view_id, test_cases[i].transient_url, &rid);
60 EXPECT_EQ(test_cases[i].expected_return_val, return_val);
61 EXPECT_EQ(test_cases[i].expected_rid, rid);
62 rid = 0;
66 TEST(SearchBoxUtilTest, ParseRestrictedFaviconTransientUrl) {
67 const int kInvalidRenderViewID = 920;
68 const int kValidRenderViewID = 1;
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.
79 kValidRenderViewID,
80 GURL("chrome-search://favicon/1/2"),
81 "",
83 true
86 kValidRenderViewID,
87 GURL("chrome-search://favicon/size/16@2x/1/2"),
88 "size/16@2x/",
90 true
93 kValidRenderViewID,
94 GURL("chrome-search://favicon/largest/1/2"),
95 "largest/",
97 true
100 kValidRenderViewID,
101 GURL("chrome-search://favicon/origin/1/2"),
102 "origin/",
104 true
107 kValidRenderViewID,
108 GURL("chrome-search://favicon/iconurl/1/2"),
109 "iconurl/",
111 true
114 // RenderView ID does not match the view id specified in the transient url.
116 kInvalidRenderViewID,
117 GURL("chrome-search://favicon/1/2"),
120 true
123 kInvalidRenderViewID,
124 GURL("chrome-search://favicon/size/16@2x/1/2"),
125 "size/16@2x/",
127 true
130 kInvalidRenderViewID,
131 GURL("chrome-search://favicon/largest/1/2"),
132 "largest/",
134 true
137 kInvalidRenderViewID,
138 GURL("chrome-search://favicon/origin/1/2"),
139 "origin/",
141 true
144 kInvalidRenderViewID,
145 GURL("chrome-search://favicon/iconurl/1/2"),
146 "iconurl/",
148 true
151 // Invalid transient urls.
153 kValidRenderViewID,
154 GURL("chrome-search://favicon"),
157 false
160 kValidRenderViewID,
161 GURL("chrome-search://favicon/"),
164 false
167 kValidRenderViewID,
168 GURL("chrome-search://favicon/size/16@2x"),
171 false
174 kValidRenderViewID,
175 GURL("chrome-search://favicon/size"),
178 true
181 kValidRenderViewID,
182 GURL("chrome-search://favicon/size/16@2x/123"),
183 "size/16@2x/",
185 true
188 kValidRenderViewID,
189 GURL("chrome-search://favicon/size/16@2x/xyz"),
190 "size/16@2x/",
192 true
195 kValidRenderViewID,
196 GURL("chrome-search://favicon/size/16@2x/123/"),
197 "size/16@2x/",
199 true
202 kValidRenderViewID,
203 GURL("chrome-search://favicon/size/16@2x/123/xyz"),
204 "size/16@2x/",
206 true
209 kValidRenderViewID,
210 GURL("chrome-search://favicon/invalidparameter/16@2x/1/2"),
213 true
217 std::string favicon_params = "";
218 InstantRestrictedID rid = 0;
219 for (size_t i = 0; i < arraysize(test_cases); ++i) {
220 bool return_val = GetRestrictedIDFromFaviconUrl(
221 test_cases[i].render_view_id,
222 test_cases[i].transient_url,
223 &favicon_params,
224 &rid);
225 EXPECT_EQ(test_cases[i].expected_return_val, return_val);
226 EXPECT_EQ(test_cases[i].expected_favicon_params, favicon_params);
227 EXPECT_EQ(test_cases[i].expected_rid, rid);
228 favicon_params = "";
229 rid = 0;
233 } // namespace internal