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"
12 // Defined in searchbox.cc
13 bool GetRestrictedIDFromThumbnailUrl(int render_view_id
,
15 InstantRestrictedID
* id
);
17 // Defined in searchbox.cc
18 bool GetRestrictedIDFromFaviconUrl(int render_view_id
,
20 std::string
* favicon_params
,
21 InstantRestrictedID
* rid
);
23 TEST(SearchBoxUtilTest
, GetInstantRestrictedIDFromTransientURL
) {
24 const int kInvalidRenderViewID
= 920;
25 const int kValidRenderViewID
= 1;
30 InstantRestrictedID expected_rid
;
31 bool expected_return_val
;
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
);
66 TEST(SearchBoxUtilTest
, ParseRestrictedFaviconTransientUrl
) {
67 const int kInvalidRenderViewID
= 920;
68 const int kValidRenderViewID
= 1;
73 std::string expected_favicon_params
;
74 InstantRestrictedID expected_rid
;
75 bool expected_return_val
;
77 // RenderView ID matches the view id specified in the transient url.
80 GURL("chrome-search://favicon/1/2"),
87 GURL("chrome-search://favicon/size/16@2x/1/2"),
94 GURL("chrome-search://favicon/largest/1/2"),
101 GURL("chrome-search://favicon/origin/1/2"),
108 GURL("chrome-search://favicon/iconurl/1/2"),
114 // RenderView ID does not match the view id specified in the transient url.
116 kInvalidRenderViewID
,
117 GURL("chrome-search://favicon/1/2"),
123 kInvalidRenderViewID
,
124 GURL("chrome-search://favicon/size/16@2x/1/2"),
130 kInvalidRenderViewID
,
131 GURL("chrome-search://favicon/largest/1/2"),
137 kInvalidRenderViewID
,
138 GURL("chrome-search://favicon/origin/1/2"),
144 kInvalidRenderViewID
,
145 GURL("chrome-search://favicon/iconurl/1/2"),
151 // Invalid transient urls.
154 GURL("chrome-search://favicon"),
161 GURL("chrome-search://favicon/"),
168 GURL("chrome-search://favicon/size/16@2x"),
175 GURL("chrome-search://favicon/size"),
182 GURL("chrome-search://favicon/size/16@2x/123"),
189 GURL("chrome-search://favicon/size/16@2x/xyz"),
196 GURL("chrome-search://favicon/size/16@2x/123/"),
203 GURL("chrome-search://favicon/size/16@2x/123/xyz"),
210 GURL("chrome-search://favicon/invalidparameter/16@2x/1/2"),
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
,
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
);
233 } // namespace internal