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

Side by Side Diff: chrome/browser/ui/elide_url_unittest.cc

Issue 1147363005: Create FormatUrlForSecurityDisplay helper function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change testing strategy, respond to comments. Created 5 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
« no previous file with comments | « chrome/browser/ui/elide_url.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/ui/elide_url.h" 5 #include "chrome/browser/ui/elide_url.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/font_list.h" 9 #include "ui/gfx/font_list.h"
10 #include "ui/gfx/text_elider.h" 10 #include "ui/gfx/text_elider.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 197
198 // Trying to elide to a really short length will still keep the full TLD+1 198 // Trying to elide to a really short length will still keep the full TLD+1
199 EXPECT_EQ(base::ASCIIToUTF16("google.com"), 199 EXPECT_EQ(base::ASCIIToUTF16("google.com"),
200 ElideHost(GURL("http://google.com"), gfx::FontList(), 2)); 200 ElideHost(GURL("http://google.com"), gfx::FontList(), 2));
201 EXPECT_EQ(base::UTF8ToUTF16(kEllipsisStr + ".google.com"), 201 EXPECT_EQ(base::UTF8ToUTF16(kEllipsisStr + ".google.com"),
202 ElideHost(GURL("http://subdomain.google.com"), gfx::FontList(), 2)); 202 ElideHost(GURL("http://subdomain.google.com"), gfx::FontList(), 2));
203 EXPECT_EQ(base::ASCIIToUTF16("foo.bar"), 203 EXPECT_EQ(base::ASCIIToUTF16("foo.bar"),
204 ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2)); 204 ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2));
205 } 205 }
206 206
207 TEST(TextEliderTest, FormatUrlForSecurityDisplay) {
208 struct OriginTestData {
209 const char* const description;
210 const char* const input;
211 const wchar_t* const output;
212 };
213
214 const OriginTestData tests[] = {
215 {"Empty URL", "", L""},
216 {"HTTP URL", "http://www.google.com/", L"http://www.google.com"},
217 {"HTTPS URL", "https://www.google.com/", L"https://www.google.com"},
218 {"Standard HTTP port",
219 "http://www.google.com:80/",
220 L"http://www.google.com"},
221 {"Standard HTTPS port",
222 "https://www.google.com:443/",
223 L"https://www.google.com"},
224 {"Standard HTTP port, IDN Chinese",
225 "http://\xe4\xb8\xad\xe5\x9b\xbd.icom.museum:80",
226 L"http://xn--fiqs8s.icom.museum"},
227 {"HTTP URL, IDN Hebrew (RTL)",
228 "http://"
229 "\xd7\x90\xd7\x99\xd7\xa7\xd7\x95\xd7\xb4\xd7\x9d."
230 "\xd7\x99\xd7\xa9\xd7\xa8\xd7\x90\xd7\x9c.museum/",
231 L"http://xn--4dbklr2c8d.xn--4dbrk0ce.museum"},
232 {"HTTP URL with query string, IDN Arabic (RTL)",
233 "http://\xd9\x85\xd8\xb5\xd8\xb1.icom.museum/foo.html?yes=no",
234 L"http://xn--wgbh1c.icom.museum"},
235 {"Non-standard HTTP port",
236 "http://www.google.com:9000/",
237 L"http://www.google.com:9000"},
238 {"Non-standard HTTPS port",
239 "https://www.google.com:9000/",
240 L"https://www.google.com:9000"},
241 {"File URI",
242 "file:///usr/example/file.html",
243 L"file:///usr/example/file.html"},
244 {"File URI with hostname",
245 "file://localhost/usr/example/file.html",
246 L"file:///usr/example/file.html"},
247 {"UNC File URI 1",
248 "file:///CONTOSO/accounting/money.xls",
249 L"file:///CONTOSO/accounting/money.xls"},
250 {"UNC File URI 2",
251 "file:///C:/Program%20Files/Music/Web%20Sys/main.html?REQUEST=RADIO",
252 L"file:///C:/Program%20Files/Music/Web%20Sys/main.html"},
253 {"HTTP URL with path",
254 "http://www.google.com/test.html",
255 L"http://www.google.com"},
256 {"HTTPS URL with path",
257 "https://www.google.com/test.html",
258 L"https://www.google.com"},
259 {"Unusual secure scheme (wss)",
260 "wss://www.google.com/",
261 L"wss://www.google.com"},
262 {"Unusual non-secure scheme (gopher)",
263 "gopher://www.google.com/",
264 L"gopher://www.google.com"},
265 {"Unlisted scheme (chrome)", "chrome://version", L"chrome://version"},
266 {"HTTP IP address", "http://173.194.65.103", L"http://173.194.65.103"},
267 {"HTTPS IP address", "https://173.194.65.103", L"https://173.194.65.103"},
268 {"HTTP IPv6 address",
269 "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/",
270 L"http://[fe80::202:b3ff:fe1e:8329]"},
271 {"HTTPS IPv6 address with port",
272 "https://[2001:db8:0:1]:443/",
273 L"https://[2001:db8:0:1]"},
274 {"HTTPS IP address, non-default port",
275 "https://173.194.65.103:8443",
276 L"https://173.194.65.103:8443"},
277 {"HTTP filesystem: URL with path",
278 "filesystem:http://www.google.com/temporary/test.html",
279 L"filesystem:http://www.google.com"},
280 {"File filesystem: URL with path",
281 "filesystem:file://localhost/temporary/stuff/test.html?z=fun&goat=billy",
282 L"filesystem:file:///temporary/stuff/test.html"},
283 {"Invalid scheme 1",
284 "twelve://www.cyber.org/wow.php",
285 L"twelve://www.cyber.org/wow.php"},
286 {"Invalid scheme 2",
287 "://www.cyber.org/wow.php",
288 L"://www.cyber.org/wow.php"},
289 {"Invalid host 1", "https://www.cyber../wow.php", L"https://www.cyber.."},
290 {"Invalid host 2", "https://www...cyber/wow.php", L"https://www...cyber"},
291 {"Invalid port 1",
292 "https://173.194.65.103:000",
293 L"https://173.194.65.103:0"},
294 {"Invalid port 2",
295 "https://173.194.65.103:gruffle",
296 L"https://173.194.65.103:gruffle"},
297 {"Invalid port 3",
298 "https://173.194.65.103:/hello.aspx",
299 L"https://173.194.65.103"},
300 {"Trailing dot in DNS name",
301 "https://www.example.com./get/goat",
302 L"https://www.example.com."},
303 {"Blob URL",
304 "blob:http%3A//www.html5rocks.com/4d4ff040-6d61-4446-86d3-13ca07ec9ab9",
305 L"blob:http%3A//www.html5rocks.com/"
306 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9"},
307 };
308
309 const char languages[] = "zh-TW,en-US,en,am,ar-EG,ar";
310 for (size_t i = 0; i < arraysize(tests); ++i) {
311 base::string16 formatted =
312 FormatUrlForSecurityDisplay(GURL(tests[i].input), std::string());
313 EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted)
314 << tests[i].description;
315 base::string16 formatted_with_languages =
316 FormatUrlForSecurityDisplay(GURL(tests[i].input), languages);
317 EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted_with_languages)
318 << tests[i].description;
319 }
320
321 base::string16 formatted = FormatUrlForSecurityDisplay(GURL(), std::string());
322 EXPECT_EQ(base::string16(), formatted)
323 << "Explicitly test the 0-argument GURL constructor";
324 }
325
207 } // namespace 326 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/elide_url.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698