| OLD | NEW |
| 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 "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "url/gurl.h" | 8 #include "url/gurl.h" |
| 9 | 9 |
| 10 namespace internal { | 10 namespace internal { |
| 11 | 11 |
| 12 // Defined in searchbox_extension.cc | 12 // Defined in searchbox.cc |
| 13 bool GetInstantRestrictedIDFromURL(int render_view_id, | 13 bool GetRestrictedIDFromThumbnailUrl(int render_view_id, |
| 14 const GURL& url, |
| 15 InstantRestrictedID* id); |
| 16 |
| 17 // Defined in searchbox.cc |
| 18 bool GetRestrictedIDFromFaviconUrl(int render_view_id, |
| 14 const GURL& url, | 19 const GURL& url, |
| 15 InstantRestrictedID* id); | 20 std::string* favicon_params, |
| 21 InstantRestrictedID* rid); |
| 16 | 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; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 42 {kValidRenderViewID, GURL("chrome-search://favicon"), 0, false}, | 48 {kValidRenderViewID, GURL("chrome-search://favicon"), 0, false}, |
| 43 {kValidRenderViewID, GURL("chrome-search://favicon/"), 0, false}, | 49 {kValidRenderViewID, GURL("chrome-search://favicon/"), 0, false}, |
| 44 {kValidRenderViewID, GURL("chrome-search://favicon/123"), 0, false}, | 50 {kValidRenderViewID, GURL("chrome-search://favicon/123"), 0, false}, |
| 45 {kValidRenderViewID, GURL("chrome-search://favicon/xyz"), 0, false}, | 51 {kValidRenderViewID, GURL("chrome-search://favicon/xyz"), 0, false}, |
| 46 {kValidRenderViewID, GURL("chrome-search://favicon/123/"), 0, false}, | 52 {kValidRenderViewID, GURL("chrome-search://favicon/123/"), 0, false}, |
| 47 {kValidRenderViewID, GURL("chrome-search://favicon/123/xyz"), 0, false} | 53 {kValidRenderViewID, GURL("chrome-search://favicon/123/xyz"), 0, false} |
| 48 }; | 54 }; |
| 49 | 55 |
| 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 = GetRestrictedIDFromThumbnailUrl( |
| 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 true |
| 121 }, |
| 122 { |
| 123 kInvalidRenderViewID, |
| 124 GURL("chrome-search://favicon/size/16@2x/1/2"), |
| 125 "size/16@2x/", |
| 126 0, |
| 127 true |
| 128 }, |
| 129 { |
| 130 kInvalidRenderViewID, |
| 131 GURL("chrome-search://favicon/largest/1/2"), |
| 132 "largest/", |
| 133 0, |
| 134 true |
| 135 }, |
| 136 { |
| 137 kInvalidRenderViewID, |
| 138 GURL("chrome-search://favicon/origin/1/2"), |
| 139 "origin/", |
| 140 0, |
| 141 true |
| 142 }, |
| 143 { |
| 144 kInvalidRenderViewID, |
| 145 GURL("chrome-search://favicon/iconurl/1/2"), |
| 146 "iconurl/", |
| 147 0, |
| 148 true |
| 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/16@2x"), |
| 169 "", |
| 170 0, |
| 171 false |
| 172 }, |
| 173 { |
| 174 kValidRenderViewID, |
| 175 GURL("chrome-search://favicon/size"), |
| 176 "", |
| 177 0, |
| 178 true |
| 179 }, |
| 180 { |
| 181 kValidRenderViewID, |
| 182 GURL("chrome-search://favicon/size/16@2x/123"), |
| 183 "size/16@2x/", |
| 184 0, |
| 185 true |
| 186 }, |
| 187 { |
| 188 kValidRenderViewID, |
| 189 GURL("chrome-search://favicon/size/16@2x/xyz"), |
| 190 "size/16@2x/", |
| 191 0, |
| 192 true |
| 193 }, |
| 194 { |
| 195 kValidRenderViewID, |
| 196 GURL("chrome-search://favicon/size/16@2x/123/"), |
| 197 "size/16@2x/", |
| 198 0, |
| 199 true |
| 200 }, |
| 201 { |
| 202 kValidRenderViewID, |
| 203 GURL("chrome-search://favicon/size/16@2x/123/xyz"), |
| 204 "size/16@2x/", |
| 205 0, |
| 206 true |
| 207 }, |
| 208 { |
| 209 kValidRenderViewID, |
| 210 GURL("chrome-search://favicon/invalidparameter/16@2x/1/2"), |
| 211 "", |
| 212 0, |
| 213 true |
| 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 = 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; |
| 230 } |
| 231 } |
| 232 |
| 60 } // namespace internal | 233 } // namespace internal |
| OLD | NEW |