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

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

Issue 1841653003: Drop |languages| from {Format,Elide}Url* and IDNToUnicode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo in elide_url.cc Created 4 years, 8 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') | components/url_formatter/url_fixer.cc » ('j') | 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"
(...skipping 18 matching lines...) Expand all
29 NO_IOS9_OR_LATER, 29 NO_IOS9_OR_LATER,
30 NO_IOS, 30 NO_IOS,
31 } platforms; 31 } platforms;
32 }; 32 };
33 33
34 #if !defined(OS_ANDROID) 34 #if !defined(OS_ANDROID)
35 void RunUrlTest(Testcase* testcases, size_t num_testcases) { 35 void RunUrlTest(Testcase* testcases, size_t num_testcases) {
36 static const gfx::FontList font_list; 36 static const gfx::FontList font_list;
37 for (size_t i = 0; i < num_testcases; ++i) { 37 for (size_t i = 0; i < num_testcases; ++i) {
38 const GURL url(testcases[i].input); 38 const GURL url(testcases[i].input);
39 // Should we test with non-empty language list?
40 // That's kinda redundant with net_util_unittests.
41 const float available_width = 39 const float available_width =
42 gfx::GetStringWidthF(base::UTF8ToUTF16(testcases[i].output), font_list); 40 gfx::GetStringWidthF(base::UTF8ToUTF16(testcases[i].output), font_list);
43 EXPECT_EQ(base::UTF8ToUTF16(testcases[i].output), 41 EXPECT_EQ(base::UTF8ToUTF16(testcases[i].output),
44 url_formatter::ElideUrl(url, font_list, available_width, 42 url_formatter::ElideUrl(url, font_list, available_width));
45 std::string()));
46 } 43 }
47 } 44 }
48 45
49 // Test eliding of commonplace URLs. 46 // Test eliding of commonplace URLs.
50 TEST(TextEliderTest, TestGeneralEliding) { 47 TEST(TextEliderTest, TestGeneralEliding) {
51 const std::string kEllipsisStr(gfx::kEllipsis); 48 const std::string kEllipsisStr(gfx::kEllipsis);
52 Testcase testcases[] = { 49 Testcase testcases[] = {
53 {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"}, 50 {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"},
54 {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"}, 51 {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"},
55 {"http://www.google.com/intl/en/ads/", 52 {"http://www.google.com/intl/en/ads/",
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // Create the expected string, after elision. Depending on font size, the 85 // Create the expected string, after elision. Depending on font size, the
89 // directory might become /dir... or /di... or/d... - it never should be 86 // directory might become /dir... or /di... or/d... - it never should be
90 // shorter than that. (If it is, the font considers d... to be longer 87 // shorter than that. (If it is, the font considers d... to be longer
91 // than .../... - that should never happen). 88 // than .../... - that should never happen).
92 ASSERT_GT( 89 ASSERT_GT(
93 gfx::GetStringWidthF(base::UTF8ToUTF16(kEllipsisStr + "/" + kEllipsisStr), 90 gfx::GetStringWidthF(base::UTF8ToUTF16(kEllipsisStr + "/" + kEllipsisStr),
94 font_list), 91 font_list),
95 gfx::GetStringWidthF(base::UTF8ToUTF16("d" + kEllipsisStr), font_list)); 92 gfx::GetStringWidthF(base::UTF8ToUTF16("d" + kEllipsisStr), font_list));
96 GURL long_url("http://battersbox.com/directorynameisreallylongtoforcetrunc"); 93 GURL long_url("http://battersbox.com/directorynameisreallylongtoforcetrunc");
97 base::string16 expected = url_formatter::ElideUrl( 94 base::string16 expected = url_formatter::ElideUrl(
98 long_url, font_list, available_width, std::string()); 95 long_url, font_list, available_width);
99 // Ensure that the expected result still contains part of the directory name. 96 // Ensure that the expected result still contains part of the directory name.
100 ASSERT_GT(expected.length(), std::string("battersbox.com/d").length()); 97 ASSERT_GT(expected.length(), std::string("battersbox.com/d").length());
101 EXPECT_EQ(expected, url_formatter::ElideUrl(url, font_list, available_width, 98 EXPECT_EQ(expected, url_formatter::ElideUrl(url, font_list, available_width));
102 std::string()));
103 99
104 // More space available - elide directories, partially elide filename. 100 // More space available - elide directories, partially elide filename.
105 Testcase testcases[] = { 101 Testcase testcases[] = {
106 {"http://battersbox.com/directory/foo/peter_paul_and_mary.html", 102 {"http://battersbox.com/directory/foo/peter_paul_and_mary.html",
107 "battersbox.com/" + kEllipsisStr + "/peter" + kEllipsisStr}, 103 "battersbox.com/" + kEllipsisStr + "/peter" + kEllipsisStr},
108 }; 104 };
109 RunUrlTest(testcases, arraysize(testcases)); 105 RunUrlTest(testcases, arraysize(testcases));
110 } 106 }
111 107
112 // Test eliding of empty strings, URLs with ports, passwords, queries, etc. 108 // Test eliding of empty strings, URLs with ports, passwords, queries, etc.
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 L"https://173.194.65.103", L"173.194.65.103"}, 316 L"https://173.194.65.103", L"173.194.65.103"},
321 {"Trailing dot in DNS name", "https://www.example.com./get/goat", 317 {"Trailing dot in DNS name", "https://www.example.com./get/goat",
322 L"https://www.example.com.", L"www.example.com."}, 318 L"https://www.example.com.", L"www.example.com."},
323 {"Blob URL", 319 {"Blob URL",
324 "blob:http%3A//www.html5rocks.com/4d4ff040-6d61-4446-86d3-13ca07ec9ab9", 320 "blob:http%3A//www.html5rocks.com/4d4ff040-6d61-4446-86d3-13ca07ec9ab9",
325 L"blob:http%3A//www.html5rocks.com/" 321 L"blob:http%3A//www.html5rocks.com/"
326 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9", 322 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9",
327 L"blob:http%3A//www.html5rocks.com/" 323 L"blob:http%3A//www.html5rocks.com/"
328 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9"}}; 324 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9"}};
329 325
330 const char languages[] = "zh-TW,en-US,en,am,ar-EG,ar";
331 for (size_t i = 0; i < arraysize(tests); ++i) { 326 for (size_t i = 0; i < arraysize(tests); ++i) {
332 base::string16 formatted = url_formatter::FormatUrlForSecurityDisplay( 327 base::string16 formatted =
333 GURL(tests[i].input), std::string()); 328 url_formatter::FormatUrlForSecurityDisplay(GURL(tests[i].input));
334 EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted) 329 EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted)
335 << tests[i].description; 330 << tests[i].description;
336 331
337 base::string16 formatted_omit_scheme = 332 base::string16 formatted_omit_scheme =
338 url_formatter::FormatUrlForSecurityDisplayOmitScheme( 333 url_formatter::FormatUrlForSecurityDisplayOmitScheme(
339 GURL(tests[i].input), std::string()); 334 GURL(tests[i].input));
340 EXPECT_EQ(base::WideToUTF16(tests[i].output_omit_scheme), 335 EXPECT_EQ(base::WideToUTF16(tests[i].output_omit_scheme),
341 formatted_omit_scheme) 336 formatted_omit_scheme)
342 << tests[i].description; 337 << tests[i].description;
343
344 base::string16 formatted_with_languages =
345 url_formatter::FormatUrlForSecurityDisplay(GURL(tests[i].input),
346 languages);
347 EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted_with_languages)
348 << tests[i].description;
349
350 base::string16 formatted_with_languages_omit_scheme =
351 url_formatter::FormatUrlForSecurityDisplayOmitScheme(
352 GURL(tests[i].input), languages);
353 EXPECT_EQ(base::WideToUTF16(tests[i].output_omit_scheme),
354 formatted_with_languages_omit_scheme)
355 << tests[i].description;
356 } 338 }
357 339
358 base::string16 formatted = 340 base::string16 formatted =
359 url_formatter::FormatUrlForSecurityDisplay(GURL(), std::string()); 341 url_formatter::FormatUrlForSecurityDisplay(GURL());
360 EXPECT_EQ(base::string16(), formatted) 342 EXPECT_EQ(base::string16(), formatted)
361 << "Explicitly test the 0-argument GURL constructor"; 343 << "Explicitly test the 0-argument GURL constructor";
362 344
363 base::string16 formatted_omit_scheme = 345 base::string16 formatted_omit_scheme =
364 url_formatter::FormatUrlForSecurityDisplayOmitScheme(GURL(), 346 url_formatter::FormatUrlForSecurityDisplayOmitScheme(GURL());
365 std::string());
366 EXPECT_EQ(base::string16(), formatted_omit_scheme) 347 EXPECT_EQ(base::string16(), formatted_omit_scheme)
367 << "Explicitly test the 0-argument GURL constructor"; 348 << "Explicitly test the 0-argument GURL constructor";
368 } 349 }
369 350
370 } // namespace 351 } // namespace
OLDNEW
« no previous file with comments | « components/url_formatter/elide_url.cc ('k') | components/url_formatter/url_fixer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698