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

Side by Side Diff: components/url_formatter/elide_url_unittest.cc

Issue 1959933002: Add FormatOriginForSecurityDisplay which takes a const url::Origin& origin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address brettw@'s comments Created 4 years, 7 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 | « components/url_formatter/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 "components/url_formatter/elide_url.h" 5 #include "components/url_formatter/elide_url.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/ios/ios_util.h" 9 #include "base/ios/ios_util.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "url/gurl.h" 14 #include "url/gurl.h"
15 #include "url/origin.h"
15 16
16 #if !defined(OS_ANDROID) 17 #if !defined(OS_ANDROID)
17 #include "ui/gfx/font_list.h" // nogncheck 18 #include "ui/gfx/font_list.h" // nogncheck
18 #include "ui/gfx/text_elider.h" // nogncheck 19 #include "ui/gfx/text_elider.h" // nogncheck
19 #include "ui/gfx/text_utils.h" // nogncheck 20 #include "ui/gfx/text_utils.h" // nogncheck
20 #endif 21 #endif
21 22
22 namespace { 23 namespace {
23 24
24 struct Testcase { 25 struct Testcase {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 EXPECT_EQ(base::UTF8ToUTF16(kEllipsisStr + ".google.com"), 224 EXPECT_EQ(base::UTF8ToUTF16(kEllipsisStr + ".google.com"),
224 url_formatter::ElideHost(GURL("http://subdomain.google.com"), 225 url_formatter::ElideHost(GURL("http://subdomain.google.com"),
225 gfx::FontList(), 2)); 226 gfx::FontList(), 2));
226 EXPECT_EQ( 227 EXPECT_EQ(
227 base::ASCIIToUTF16("foo.bar"), 228 base::ASCIIToUTF16("foo.bar"),
228 url_formatter::ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2)); 229 url_formatter::ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2));
229 } 230 }
230 231
231 #endif // !defined(OS_ANDROID) 232 #endif // !defined(OS_ANDROID)
232 233
234 struct OriginTestData {
235 const char* const description;
236 const char* const input;
237 const wchar_t* const output;
238 const wchar_t* const output_omit_web_scheme;
239 const wchar_t* const output_omit_cryptographic_scheme;
240 };
241
242 // Common test data for both FormatUrlForSecurityDisplay() and
243 // FormatOriginForSecurityDisplay()
244 const OriginTestData common_tests[] = {
245 {"Empty URL", "", L"", L"", L""},
246 {"HTTP URL", "http://www.google.com/", L"http://www.google.com",
247 L"www.google.com", L"http://www.google.com"},
248 {"HTTPS URL", "https://www.google.com/", L"https://www.google.com",
249 L"www.google.com", L"www.google.com"},
250 {"Standard HTTP port", "http://www.google.com:80/",
251 L"http://www.google.com", L"www.google.com", L"http://www.google.com"},
252 {"Standard HTTPS port", "https://www.google.com:443/",
253 L"https://www.google.com", L"www.google.com", L"www.google.com"},
254 {"Standard HTTP port, IDN Chinese",
255 "http://\xe4\xb8\xad\xe5\x9b\xbd.icom.museum:80",
256 L"http://xn--fiqs8s.icom.museum", L"xn--fiqs8s.icom.museum",
257 L"http://xn--fiqs8s.icom.museum"},
258 {"HTTP URL, IDN Hebrew (RTL)",
259 "http://"
260 "\xd7\x90\xd7\x99\xd7\xa7\xd7\x95\xd7\xb4\xd7\x9d."
261 "\xd7\x99\xd7\xa9\xd7\xa8\xd7\x90\xd7\x9c.museum/",
262 L"http://xn--4dbklr2c8d.xn--4dbrk0ce.museum",
263 L"xn--4dbklr2c8d.xn--4dbrk0ce.museum",
264 L"http://xn--4dbklr2c8d.xn--4dbrk0ce.museum"},
265 {"HTTP URL with query string, IDN Arabic (RTL)",
266 "http://\xd9\x85\xd8\xb5\xd8\xb1.icom.museum/foo.html?yes=no",
267 L"http://xn--wgbh1c.icom.museum", L"xn--wgbh1c.icom.museum",
268 L"http://xn--wgbh1c.icom.museum"},
269 {"Non-standard HTTP port", "http://www.google.com:9000/",
270 L"http://www.google.com:9000", L"www.google.com:9000",
271 L"http://www.google.com:9000"},
272 {"Non-standard HTTPS port", "https://www.google.com:9000/",
273 L"https://www.google.com:9000", L"www.google.com:9000",
274 L"www.google.com:9000"},
275 {"HTTP URL with path", "http://www.google.com/test.html",
276 L"http://www.google.com", L"www.google.com", L"http://www.google.com"},
277 {"HTTPS URL with path", "https://www.google.com/test.html",
278 L"https://www.google.com", L"www.google.com", L"www.google.com"},
279 {"Unusual secure scheme (wss)", "wss://www.google.com/",
280 L"wss://www.google.com", L"wss://www.google.com", L"www.google.com"},
281 {"Unusual non-secure scheme (gopher)", "gopher://www.google.com/",
282 L"gopher://www.google.com", L"gopher://www.google.com",
283 L"gopher://www.google.com"},
284 {"Unlisted scheme (chrome)", "chrome://version", L"chrome://version",
285 L"chrome://version", L"chrome://version"},
286 {"HTTP IP address", "http://173.194.65.103", L"http://173.194.65.103",
287 L"173.194.65.103", L"http://173.194.65.103"},
288 {"HTTPS IP address", "https://173.194.65.103", L"https://173.194.65.103",
289 L"173.194.65.103", L"173.194.65.103"},
290 {"HTTP IPv6 address", "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/",
291 L"http://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]",
292 L"http://[fe80::202:b3ff:fe1e:8329]"},
293 {"HTTPs IPv6 address", "https://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/",
294 L"https://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]",
295 L"[fe80::202:b3ff:fe1e:8329]"},
296 {"HTTP IPv6 address with port",
297 "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]:80/",
298 L"http://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]",
299 L"http://[fe80::202:b3ff:fe1e:8329]"},
300 {"HTTPs IPv6 address with port",
301 "https://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]:443/",
302 L"https://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]",
303 L"[fe80::202:b3ff:fe1e:8329]"},
304 {"HTTPS IP address, non-default port", "https://173.194.65.103:8443",
305 L"https://173.194.65.103:8443", L"173.194.65.103:8443",
306 L"173.194.65.103:8443"},
307 {"Invalid host 1", "https://www.cyber../wow.php", L"https://www.cyber..",
308 L"www.cyber..", L"www.cyber.."},
309 {"Invalid host 2", "https://www...cyber/wow.php", L"https://www...cyber",
310 L"www...cyber", L"www...cyber"},
311 {"Invalid port 3", "https://173.194.65.103:/hello.aspx",
312 L"https://173.194.65.103", L"173.194.65.103", L"173.194.65.103"},
313 {"Trailing dot in DNS name", "https://www.example.com./get/goat",
314 L"https://www.example.com.", L"www.example.com.", L"www.example.com."}};
315
233 TEST(TextEliderTest, FormatUrlForSecurityDisplay) { 316 TEST(TextEliderTest, FormatUrlForSecurityDisplay) {
234 struct OriginTestData { 317 for (size_t i = 0; i < arraysize(common_tests); ++i) {
235 const char* const description; 318 base::string16 formatted =
236 const char* const input; 319 url_formatter::FormatUrlForSecurityDisplay(GURL(common_tests[i].input));
237 const wchar_t* const output; 320 EXPECT_EQ(base::WideToUTF16(common_tests[i].output), formatted)
238 const wchar_t* const output_omit_web_scheme; 321 << common_tests[i].description;
239 const wchar_t* const output_omit_cryptographic_scheme; 322
240 }; 323 base::string16 formatted_omit_web_scheme =
324 url_formatter::FormatUrlForSecurityDisplay(
325 GURL(common_tests[i].input),
326 url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
327 EXPECT_EQ(base::WideToUTF16(common_tests[i].output_omit_web_scheme),
328 formatted_omit_web_scheme)
329 << common_tests[i].description;
330
331 base::string16 formatted_omit_cryptographic_scheme =
332 url_formatter::FormatUrlForSecurityDisplay(
333 GURL(common_tests[i].input),
334 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
335 EXPECT_EQ(
336 base::WideToUTF16(common_tests[i].output_omit_cryptographic_scheme),
337 formatted_omit_cryptographic_scheme)
338 << common_tests[i].description;
339 }
241 340
242 const OriginTestData tests[] = { 341 const OriginTestData tests[] = {
243 {"Empty URL", "", L"", L"", L""},
244 {"HTTP URL", "http://www.google.com/", L"http://www.google.com",
245 L"www.google.com", L"http://www.google.com"},
246 {"HTTPS URL", "https://www.google.com/", L"https://www.google.com",
247 L"www.google.com", L"www.google.com"},
248 {"Standard HTTP port", "http://www.google.com:80/",
249 L"http://www.google.com", L"www.google.com", L"http://www.google.com"},
250 {"Standard HTTPS port", "https://www.google.com:443/",
251 L"https://www.google.com", L"www.google.com", L"www.google.com"},
252 {"Standard HTTP port, IDN Chinese",
253 "http://\xe4\xb8\xad\xe5\x9b\xbd.icom.museum:80",
254 L"http://xn--fiqs8s.icom.museum", L"xn--fiqs8s.icom.museum",
255 L"http://xn--fiqs8s.icom.museum"},
256 {"HTTP URL, IDN Hebrew (RTL)",
257 "http://"
258 "\xd7\x90\xd7\x99\xd7\xa7\xd7\x95\xd7\xb4\xd7\x9d."
259 "\xd7\x99\xd7\xa9\xd7\xa8\xd7\x90\xd7\x9c.museum/",
260 L"http://xn--4dbklr2c8d.xn--4dbrk0ce.museum",
261 L"xn--4dbklr2c8d.xn--4dbrk0ce.museum",
262 L"http://xn--4dbklr2c8d.xn--4dbrk0ce.museum"},
263 {"HTTP URL with query string, IDN Arabic (RTL)",
264 "http://\xd9\x85\xd8\xb5\xd8\xb1.icom.museum/foo.html?yes=no",
265 L"http://xn--wgbh1c.icom.museum", L"xn--wgbh1c.icom.museum",
266 L"http://xn--wgbh1c.icom.museum"},
267 {"Non-standard HTTP port", "http://www.google.com:9000/",
268 L"http://www.google.com:9000", L"www.google.com:9000",
269 L"http://www.google.com:9000"},
270 {"Non-standard HTTPS port", "https://www.google.com:9000/",
271 L"https://www.google.com:9000", L"www.google.com:9000",
272 L"www.google.com:9000"},
273 {"File URI", "file:///usr/example/file.html", 342 {"File URI", "file:///usr/example/file.html",
274 L"file:///usr/example/file.html", L"file:///usr/example/file.html", 343 L"file:///usr/example/file.html", L"file:///usr/example/file.html",
275 L"file:///usr/example/file.html"}, 344 L"file:///usr/example/file.html"},
276 {"File URI with hostname", "file://localhost/usr/example/file.html", 345 {"File URI with hostname", "file://localhost/usr/example/file.html",
277 L"file:///usr/example/file.html", L"file:///usr/example/file.html", 346 L"file:///usr/example/file.html", L"file:///usr/example/file.html",
278 L"file:///usr/example/file.html"}, 347 L"file:///usr/example/file.html"},
279 {"UNC File URI 1", "file:///CONTOSO/accounting/money.xls", 348 {"UNC File URI 1", "file:///CONTOSO/accounting/money.xls",
280 L"file:///CONTOSO/accounting/money.xls", 349 L"file:///CONTOSO/accounting/money.xls",
281 L"file:///CONTOSO/accounting/money.xls", 350 L"file:///CONTOSO/accounting/money.xls",
282 L"file:///CONTOSO/accounting/money.xls"}, 351 L"file:///CONTOSO/accounting/money.xls"},
283 {"UNC File URI 2", 352 {"UNC File URI 2",
284 "file:///C:/Program%20Files/Music/Web%20Sys/main.html?REQUEST=RADIO", 353 "file:///C:/Program%20Files/Music/Web%20Sys/main.html?REQUEST=RADIO",
285 L"file:///C:/Program%20Files/Music/Web%20Sys/main.html", 354 L"file:///C:/Program%20Files/Music/Web%20Sys/main.html",
286 L"file:///C:/Program%20Files/Music/Web%20Sys/main.html", 355 L"file:///C:/Program%20Files/Music/Web%20Sys/main.html",
287 L"file:///C:/Program%20Files/Music/Web%20Sys/main.html"}, 356 L"file:///C:/Program%20Files/Music/Web%20Sys/main.html"},
288 {"HTTP URL with path", "http://www.google.com/test.html",
289 L"http://www.google.com", L"www.google.com", L"http://www.google.com"},
290 {"HTTPS URL with path", "https://www.google.com/test.html",
291 L"https://www.google.com", L"www.google.com", L"www.google.com"},
292 {"Unusual secure scheme (wss)", "wss://www.google.com/",
293 L"wss://www.google.com", L"wss://www.google.com", L"www.google.com"},
294 {"Unusual non-secure scheme (gopher)", "gopher://www.google.com/",
295 L"gopher://www.google.com", L"gopher://www.google.com",
296 L"gopher://www.google.com"},
297 {"Unlisted scheme (chrome)", "chrome://version", L"chrome://version",
298 L"chrome://version", L"chrome://version"},
299 {"HTTP IP address", "http://173.194.65.103", L"http://173.194.65.103",
300 L"173.194.65.103", L"http://173.194.65.103"},
301 {"HTTPS IP address", "https://173.194.65.103", L"https://173.194.65.103",
302 L"173.194.65.103", L"173.194.65.103"},
303 {"HTTP IPv6 address", "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/",
304 L"http://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]",
305 L"http://[fe80::202:b3ff:fe1e:8329]"},
306 {"HTTPs IPv6 address",
307 "https://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/",
308 L"https://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]",
309 L"[fe80::202:b3ff:fe1e:8329]"},
310 {"HTTP IPv6 address with port",
311 "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]:80/",
312 L"http://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]",
313 L"http://[fe80::202:b3ff:fe1e:8329]"},
314 {"HTTPs IPv6 address with port",
315 "https://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]:443/",
316 L"https://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]",
317 L"[fe80::202:b3ff:fe1e:8329]"},
318 {"Invalid IPv6 address", "https://[2001:db8:0:1]/", 357 {"Invalid IPv6 address", "https://[2001:db8:0:1]/",
319 L"https://[2001:db8:0:1]", L"https://[2001:db8:0:1]", 358 L"https://[2001:db8:0:1]", L"https://[2001:db8:0:1]",
320 L"https://[2001:db8:0:1]"}, 359 L"https://[2001:db8:0:1]"},
321 {"HTTPS IP address, non-default port", "https://173.194.65.103:8443",
322 L"https://173.194.65.103:8443", L"173.194.65.103:8443",
323 L"173.194.65.103:8443"},
324 {"HTTP filesystem: URL with path", 360 {"HTTP filesystem: URL with path",
325 "filesystem:http://www.google.com/temporary/test.html", 361 "filesystem:http://www.google.com/temporary/test.html",
326 L"filesystem:http://www.google.com", L"filesystem:http://www.google.com", 362 L"filesystem:http://www.google.com", L"filesystem:http://www.google.com",
327 L"filesystem:http://www.google.com"}, 363 L"filesystem:http://www.google.com"},
328 {"File filesystem: URL with path", 364 {"File filesystem: URL with path",
329 "filesystem:file://localhost/temporary/stuff/test.html?z=fun&goat=billy", 365 "filesystem:file://localhost/temporary/stuff/"
366 "test.html?z=fun&goat=billy",
330 L"filesystem:file:///temporary/stuff/test.html", 367 L"filesystem:file:///temporary/stuff/test.html",
331 L"filesystem:file:///temporary/stuff/test.html", 368 L"filesystem:file:///temporary/stuff/test.html",
332 L"filesystem:file:///temporary/stuff/test.html"}, 369 L"filesystem:file:///temporary/stuff/test.html"},
333 {"Invalid scheme 1", "twelve://www.cyber.org/wow.php", 370 {"Invalid scheme 1", "twelve://www.cyber.org/wow.php",
334 L"twelve://www.cyber.org/wow.php", L"twelve://www.cyber.org/wow.php", 371 L"twelve://www.cyber.org/wow.php", L"twelve://www.cyber.org/wow.php",
335 L"twelve://www.cyber.org/wow.php"}, 372 L"twelve://www.cyber.org/wow.php"},
336 {"Invalid scheme 2", "://www.cyber.org/wow.php", 373 {"Invalid scheme 2", "://www.cyber.org/wow.php",
337 L"://www.cyber.org/wow.php", L"://www.cyber.org/wow.php", 374 L"://www.cyber.org/wow.php", L"://www.cyber.org/wow.php",
338 L"://www.cyber.org/wow.php"}, 375 L"://www.cyber.org/wow.php"},
339 {"Invalid host 1", "https://www.cyber../wow.php", L"https://www.cyber..",
340 L"www.cyber..", L"www.cyber.."},
341 {"Invalid host 2", "https://www...cyber/wow.php", L"https://www...cyber",
342 L"www...cyber", L"www...cyber"},
343 {"Invalid port 1", "https://173.194.65.103:000", 376 {"Invalid port 1", "https://173.194.65.103:000",
344 L"https://173.194.65.103:0", L"173.194.65.103:0", L"173.194.65.103:0"}, 377 L"https://173.194.65.103:0", L"173.194.65.103:0", L"173.194.65.103:0"},
345 {"Invalid port 2", "https://173.194.65.103:gruffle", 378 {"Invalid port 2", "https://173.194.65.103:gruffle",
346 L"https://173.194.65.103:gruffle", L"https://173.194.65.103:gruffle", 379 L"https://173.194.65.103:gruffle", L"https://173.194.65.103:gruffle",
347 L"https://173.194.65.103:gruffle"}, 380 L"https://173.194.65.103:gruffle"},
348 {"Invalid port 3", "https://173.194.65.103:/hello.aspx",
349 L"https://173.194.65.103", L"173.194.65.103", L"173.194.65.103"},
350 {"Trailing dot in DNS name", "https://www.example.com./get/goat",
351 L"https://www.example.com.", L"www.example.com.", L"www.example.com."},
352 {"Blob URL", 381 {"Blob URL",
353 "blob:http://www.html5rocks.com/4d4ff040-6d61-4446-86d3-13ca07ec9ab9", 382 "blob:http://www.html5rocks.com/4d4ff040-6d61-4446-86d3-13ca07ec9ab9",
354 L"blob:http://www.html5rocks.com/" 383 L"blob:http://www.html5rocks.com/"
355 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9", 384 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9",
356 L"blob:http://www.html5rocks.com/" 385 L"blob:http://www.html5rocks.com/"
357 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9", 386 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9",
358 L"blob:http://www.html5rocks.com/" 387 L"blob:http://www.html5rocks.com/"
359 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9"}}; 388 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9"}};
360 389
361 for (size_t i = 0; i < arraysize(tests); ++i) { 390 for (size_t i = 0; i < arraysize(tests); ++i) {
(...skipping 12 matching lines...) Expand all
374 403
375 base::string16 formatted_omit_cryptographic_scheme = 404 base::string16 formatted_omit_cryptographic_scheme =
376 url_formatter::FormatUrlForSecurityDisplay( 405 url_formatter::FormatUrlForSecurityDisplay(
377 GURL(tests[i].input), 406 GURL(tests[i].input),
378 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC); 407 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
379 EXPECT_EQ(base::WideToUTF16(tests[i].output_omit_cryptographic_scheme), 408 EXPECT_EQ(base::WideToUTF16(tests[i].output_omit_cryptographic_scheme),
380 formatted_omit_cryptographic_scheme) 409 formatted_omit_cryptographic_scheme)
381 << tests[i].description; 410 << tests[i].description;
382 } 411 }
383 412
384 base::string16 formatted = 413 base::string16 formatted = url_formatter::FormatUrlForSecurityDisplay(GURL());
385 url_formatter::FormatUrlForSecurityDisplay(GURL());
386 EXPECT_EQ(base::string16(), formatted) 414 EXPECT_EQ(base::string16(), formatted)
387 << "Explicitly test the 0-argument GURL constructor"; 415 << "Explicitly test the 0-argument GURL constructor";
388 416
389 base::string16 formatted_omit_scheme = 417 base::string16 formatted_omit_scheme =
390 url_formatter::FormatUrlForSecurityDisplay( 418 url_formatter::FormatUrlForSecurityDisplay(
391 GURL(), url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS); 419 GURL(), url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
392 EXPECT_EQ(base::string16(), formatted_omit_scheme) 420 EXPECT_EQ(base::string16(), formatted_omit_scheme)
393 << "Explicitly test the 0-argument GURL constructor"; 421 << "Explicitly test the 0-argument GURL constructor";
394 422
395 formatted_omit_scheme = url_formatter::FormatUrlForSecurityDisplay( 423 formatted_omit_scheme = url_formatter::FormatUrlForSecurityDisplay(
396 GURL(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC); 424 GURL(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
397 EXPECT_EQ(base::string16(), formatted_omit_scheme) 425 EXPECT_EQ(base::string16(), formatted_omit_scheme)
398 << "Explicitly test the 0-argument GURL constructor"; 426 << "Explicitly test the 0-argument GURL constructor";
399 } 427 }
400 428
429 TEST(TextEliderTest, FormatOriginForSecurityDisplay) {
430 for (size_t i = 0; i < arraysize(common_tests); ++i) {
431 base::string16 formatted = url_formatter::FormatOriginForSecurityDisplay(
432 url::Origin(GURL(common_tests[i].input)));
433 EXPECT_EQ(base::WideToUTF16(common_tests[i].output), formatted)
434 << common_tests[i].description;
435
436 base::string16 formatted_omit_web_scheme =
437 url_formatter::FormatOriginForSecurityDisplay(
438 url::Origin(GURL(common_tests[i].input)),
439 url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
440 EXPECT_EQ(base::WideToUTF16(common_tests[i].output_omit_web_scheme),
441 formatted_omit_web_scheme)
442 << common_tests[i].description;
443
444 base::string16 formatted_omit_cryptographic_scheme =
445 url_formatter::FormatOriginForSecurityDisplay(
446 url::Origin(GURL(common_tests[i].input)),
447 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
448 EXPECT_EQ(
449 base::WideToUTF16(common_tests[i].output_omit_cryptographic_scheme),
450 formatted_omit_cryptographic_scheme)
451 << common_tests[i].description;
452 }
453
454 const OriginTestData tests[] = {
455 {"File URI", "file:///usr/example/file.html", L"file://", L"file://",
456 L"file://"},
457 {"File URI with hostname", "file://localhost/usr/example/file.html",
458 L"file://localhost", L"file://localhost", L"file://localhost"},
459 {"UNC File URI 1", "file:///CONTOSO/accounting/money.xls", L"file://",
460 L"file://", L"file://"},
461 {"UNC File URI 2",
462 "file:///C:/Program%20Files/Music/Web%20Sys/main.html?REQUEST=RADIO",
463 L"file://", L"file://", L"file://"},
464 {"Invalid IPv6 address", "https://[2001:db8:0:1]/", L"", L"", L""},
465 {"HTTP filesystem: URL with path",
466 "filesystem:http://www.google.com/temporary/test.html",
467 L"http://www.google.com", L"www.google.com", L"http://www.google.com"},
468 {"File filesystem: URL with path",
469 "filesystem:file://localhost/temporary/stuff/test.html?z=fun&goat=billy",
470 L"file://", L"file://", L"file://"},
471 {"Invalid scheme 1", "twelve://www.cyber.org/wow.php", L"", L"", L""},
472 {"Invalid scheme 2", "://www.cyber.org/wow.php", L"", L"", L""},
473 {"Invalid port 1", "https://173.194.65.103:000", L"", L"", L""},
474 {"Invalid port 2", "https://173.194.65.103:gruffle", L"", L"", L""},
475 {"Blob URL",
476 "blob:http://www.html5rocks.com/4d4ff040-6d61-4446-86d3-13ca07ec9ab9",
477 L"http://www.html5rocks.com", L"www.html5rocks.com",
478 L"http://www.html5rocks.com"}};
479
480 for (size_t i = 0; i < arraysize(tests); ++i) {
481 base::string16 formatted = url_formatter::FormatOriginForSecurityDisplay(
482 url::Origin(GURL(tests[i].input)));
483 EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted)
484 << tests[i].description;
485
486 base::string16 formatted_omit_web_scheme =
487 url_formatter::FormatOriginForSecurityDisplay(
488 url::Origin(GURL(tests[i].input)),
489 url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
490 EXPECT_EQ(base::WideToUTF16(tests[i].output_omit_web_scheme),
491 formatted_omit_web_scheme)
492 << tests[i].description;
493
494 base::string16 formatted_omit_cryptographic_scheme =
495 url_formatter::FormatOriginForSecurityDisplay(
496 url::Origin(GURL(tests[i].input)),
497 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
498 EXPECT_EQ(base::WideToUTF16(tests[i].output_omit_cryptographic_scheme),
499 formatted_omit_cryptographic_scheme)
500 << tests[i].description;
501 }
502
503 base::string16 formatted =
504 url_formatter::FormatOriginForSecurityDisplay(url::Origin(GURL()));
505 EXPECT_EQ(base::string16(), formatted)
506 << "Explicitly test the url::Origin which takes an empty, invalid URL";
507
508 base::string16 formatted_omit_scheme =
509 url_formatter::FormatOriginForSecurityDisplay(
510 url::Origin(GURL()),
511 url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
512 EXPECT_EQ(base::string16(), formatted_omit_scheme)
513 << "Explicitly test the url::Origin which takes an empty, invalid URL";
514
515 formatted_omit_scheme = url_formatter::FormatOriginForSecurityDisplay(
516 url::Origin(GURL()), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
517 EXPECT_EQ(base::string16(), formatted_omit_scheme)
518 << "Explicitly test the url::Origin which takes an empty, invalid URL";
519 }
520
401 } // namespace 521 } // namespace
OLDNEW
« no previous file with comments | « components/url_formatter/elide_url.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698