| Index: ui/secure_display/elide_url_unittest.cc
|
| diff --git a/chrome/browser/ui/elide_url_unittest.cc b/ui/secure_display/elide_url_unittest.cc
|
| similarity index 69%
|
| rename from chrome/browser/ui/elide_url_unittest.cc
|
| rename to ui/secure_display/elide_url_unittest.cc
|
| index 312d8ed8981e942bda9ed362638fb9bdf428a144..d6cf56c75b07a2dfd9ecfde074e96b3bda2fa3a5 100644
|
| --- a/chrome/browser/ui/elide_url_unittest.cc
|
| +++ b/ui/secure_display/elide_url_unittest.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/ui/elide_url.h"
|
| +#include "ui/secure_display/elide_url.h"
|
|
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| @@ -31,7 +31,8 @@ void RunUrlTest(Testcase* testcases, size_t num_testcases) {
|
| const float available_width =
|
| GetStringWidthF(UTF8ToUTF16(testcases[i].output), font_list);
|
| EXPECT_EQ(UTF8ToUTF16(testcases[i].output),
|
| - ElideUrl(url, font_list, available_width, std::string()));
|
| + secure_display::ElideUrl(url, font_list, available_width,
|
| + std::string()));
|
| }
|
| }
|
|
|
| @@ -39,23 +40,22 @@ void RunUrlTest(Testcase* testcases, size_t num_testcases) {
|
| TEST(TextEliderTest, TestGeneralEliding) {
|
| const std::string kEllipsisStr(kEllipsis);
|
| Testcase testcases[] = {
|
| - {"http://www.google.com/intl/en/ads/",
|
| - "www.google.com/intl/en/ads/"},
|
| - {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"},
|
| - {"http://www.google.com/intl/en/ads/",
|
| - "google.com/intl/" + kEllipsisStr + "/ads/"},
|
| - {"http://www.google.com/intl/en/ads/",
|
| - "google.com/" + kEllipsisStr + "/ads/"},
|
| - {"http://www.google.com/intl/en/ads/", "google.com/" + kEllipsisStr},
|
| - {"http://www.google.com/intl/en/ads/", "goog" + kEllipsisStr},
|
| - {"https://subdomain.foo.com/bar/filename.html",
|
| - "subdomain.foo.com/bar/filename.html"},
|
| - {"https://subdomain.foo.com/bar/filename.html",
|
| - "subdomain.foo.com/" + kEllipsisStr + "/filename.html"},
|
| - {"http://subdomain.foo.com/bar/filename.html",
|
| - kEllipsisStr + "foo.com/" + kEllipsisStr + "/filename.html"},
|
| - {"http://www.google.com/intl/en/ads/?aLongQueryWhichIsNotRequired",
|
| - "www.google.com/intl/en/ads/?aLongQ" + kEllipsisStr},
|
| + {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"},
|
| + {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"},
|
| + {"http://www.google.com/intl/en/ads/",
|
| + "google.com/intl/" + kEllipsisStr + "/ads/"},
|
| + {"http://www.google.com/intl/en/ads/",
|
| + "google.com/" + kEllipsisStr + "/ads/"},
|
| + {"http://www.google.com/intl/en/ads/", "google.com/" + kEllipsisStr},
|
| + {"http://www.google.com/intl/en/ads/", "goog" + kEllipsisStr},
|
| + {"https://subdomain.foo.com/bar/filename.html",
|
| + "subdomain.foo.com/bar/filename.html"},
|
| + {"https://subdomain.foo.com/bar/filename.html",
|
| + "subdomain.foo.com/" + kEllipsisStr + "/filename.html"},
|
| + {"http://subdomain.foo.com/bar/filename.html",
|
| + kEllipsisStr + "foo.com/" + kEllipsisStr + "/filename.html"},
|
| + {"http://www.google.com/intl/en/ads/?aLongQueryWhichIsNotRequired",
|
| + "www.google.com/intl/en/ads/?aLongQ" + kEllipsisStr},
|
| };
|
|
|
| RunUrlTest(testcases, arraysize(testcases));
|
| @@ -83,17 +83,17 @@ TEST(TextEliderTest, TestTrailingEllipsisSlashEllipsisHack) {
|
| font_list),
|
| GetStringWidthF(UTF8ToUTF16("d" + kEllipsisStr), font_list));
|
| GURL long_url("http://battersbox.com/directorynameisreallylongtoforcetrunc");
|
| - base::string16 expected =
|
| - ElideUrl(long_url, font_list, available_width, std::string());
|
| + base::string16 expected = secure_display::ElideUrl(
|
| + long_url, font_list, available_width, std::string());
|
| // Ensure that the expected result still contains part of the directory name.
|
| ASSERT_GT(expected.length(), std::string("battersbox.com/d").length());
|
| - EXPECT_EQ(expected,
|
| - ElideUrl(url, font_list, available_width, std::string()));
|
| + EXPECT_EQ(expected, secure_display::ElideUrl(url, font_list, available_width,
|
| + std::string()));
|
|
|
| // More space available - elide directories, partially elide filename.
|
| Testcase testcases[] = {
|
| - {"http://battersbox.com/directory/foo/peter_paul_and_mary.html",
|
| - "battersbox.com/" + kEllipsisStr + "/peter" + kEllipsisStr},
|
| + {"http://battersbox.com/directory/foo/peter_paul_and_mary.html",
|
| + "battersbox.com/" + kEllipsisStr + "/peter" + kEllipsisStr},
|
| };
|
| RunUrlTest(testcases, arraysize(testcases));
|
| }
|
| @@ -102,35 +102,37 @@ TEST(TextEliderTest, TestTrailingEllipsisSlashEllipsisHack) {
|
| TEST(TextEliderTest, TestMoreEliding) {
|
| const std::string kEllipsisStr(kEllipsis);
|
| Testcase testcases[] = {
|
| - {"http://www.google.com/foo?bar", "www.google.com/foo?bar"},
|
| - {"http://xyz.google.com/foo?bar", "xyz.google.com/foo?" + kEllipsisStr},
|
| - {"http://xyz.google.com/foo?bar", "xyz.google.com/foo" + kEllipsisStr},
|
| - {"http://xyz.google.com/foo?bar", "xyz.google.com/fo" + kEllipsisStr},
|
| - {"http://a.b.com/pathname/c?d", "a.b.com/" + kEllipsisStr + "/c?d"},
|
| - {"", ""},
|
| - {"http://foo.bar..example.com...hello/test/filename.html",
|
| - "foo.bar..example.com...hello/" + kEllipsisStr + "/filename.html"},
|
| - {"http://foo.bar../", "foo.bar.."},
|
| - {"http://xn--1lq90i.cn/foo", "\xe5\x8c\x97\xe4\xba\xac.cn/foo"},
|
| - {"http://me:mypass@secrethost.com:99/foo?bar#baz",
|
| - "secrethost.com:99/foo?bar#baz"},
|
| - {"http://me:mypass@ss%xxfdsf.com/foo", "ss%25xxfdsf.com/foo"},
|
| - {"mailto:elgoato@elgoato.com", "mailto:elgoato@elgoato.com"},
|
| - {"javascript:click(0)", "javascript:click(0)"},
|
| - {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename",
|
| - "chess.eecs.berkeley.edu:4430/login/arbitfilename"},
|
| - {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename",
|
| - kEllipsisStr + "berkeley.edu:4430/" + kEllipsisStr + "/arbitfilename"},
|
| + {"http://www.google.com/foo?bar", "www.google.com/foo?bar"},
|
| + {"http://xyz.google.com/foo?bar", "xyz.google.com/foo?" + kEllipsisStr},
|
| + {"http://xyz.google.com/foo?bar", "xyz.google.com/foo" + kEllipsisStr},
|
| + {"http://xyz.google.com/foo?bar", "xyz.google.com/fo" + kEllipsisStr},
|
| + {"http://a.b.com/pathname/c?d", "a.b.com/" + kEllipsisStr + "/c?d"},
|
| + {"", ""},
|
| + {"http://foo.bar..example.com...hello/test/filename.html",
|
| + "foo.bar..example.com...hello/" + kEllipsisStr + "/filename.html"},
|
| + {"http://foo.bar../", "foo.bar.."},
|
| + {"http://xn--1lq90i.cn/foo", "\xe5\x8c\x97\xe4\xba\xac.cn/foo"},
|
| + {"http://me:mypass@secrethost.com:99/foo?bar#baz",
|
| + "secrethost.com:99/foo?bar#baz"},
|
| + {"http://me:mypass@ss%xxfdsf.com/foo", "ss%25xxfdsf.com/foo"},
|
| + {"mailto:elgoato@elgoato.com", "mailto:elgoato@elgoato.com"},
|
| + {"javascript:click(0)", "javascript:click(0)"},
|
| + {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename",
|
| + "chess.eecs.berkeley.edu:4430/login/arbitfilename"},
|
| + {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename",
|
| + kEllipsisStr + "berkeley.edu:4430/" + kEllipsisStr + "/arbitfilename"},
|
|
|
| - // Unescaping.
|
| - {"http://www/%E4%BD%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0",
|
| - "www/\xe4\xbd\xa0\xe5\xa5\xbd?q=\xe4\xbd\xa0\xe5\xa5\xbd#\xe4\xbd\xa0"},
|
| + // Unescaping.
|
| + {"http://www/%E4%BD%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0",
|
| + "www/\xe4\xbd\xa0\xe5\xa5\xbd?q=\xe4\xbd\xa0\xe5\xa5\xbd#\xe4\xbd\xa0"},
|
|
|
| - // Invalid unescaping for path. The ref will always be valid UTF-8. We don't
|
| - // bother to do too many edge cases, since these are handled by the escaper
|
| - // unittest.
|
| - {"http://www/%E4%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0",
|
| - "www/%E4%A0%E5%A5%BD?q=\xe4\xbd\xa0\xe5\xa5\xbd#\xe4\xbd\xa0"},
|
| + // Invalid unescaping for path. The ref will always be valid UTF-8. We
|
| + // don't
|
| + // bother to do too many edge cases, since these are handled by the
|
| + // escaper
|
| + // unittest.
|
| + {"http://www/%E4%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0",
|
| + "www/%E4%A0%E5%A5%BD?q=\xe4\xbd\xa0\xe5\xa5\xbd#\xe4\xbd\xa0"},
|
| };
|
|
|
| RunUrlTest(testcases, arraysize(testcases));
|
| @@ -142,8 +144,7 @@ TEST(TextEliderTest, TestFileURLEliding) {
|
| Testcase testcases[] = {
|
| {"file:///C:/path1/path2/path3/filename",
|
| "file:///C:/path1/path2/path3/filename"},
|
| - {"file:///C:/path1/path2/path3/filename",
|
| - "C:/path1/path2/path3/filename"},
|
| + {"file:///C:/path1/path2/path3/filename", "C:/path1/path2/path3/filename"},
|
| // GURL parses "file:///C:path" differently on windows than it does on posix.
|
| #if defined(OS_WIN)
|
| {"file:///C:path1/path2/path3/filename",
|
| @@ -173,7 +174,7 @@ TEST(TextEliderTest, TestHostEliding) {
|
| {"http://google.com", "google.com"},
|
| {"http://subdomain.google.com", kEllipsisStr + ".google.com"},
|
| {"http://reallyreallyreallylongdomainname.com",
|
| - "reallyreallyreallylongdomainname.com"},
|
| + "reallyreallyreallylongdomainname.com"},
|
| {"http://a.b.c.d.e.f.com", kEllipsisStr + "f.com"},
|
| {"http://foo", "foo"},
|
| {"http://foo.bar", "foo.bar"},
|
| @@ -183,7 +184,7 @@ TEST(TextEliderTest, TestHostEliding) {
|
| // many kerned letters on the default font set.
|
| #if !defined(OS_IOS)
|
| {"http://subdomain.reallylongdomainname.com",
|
| - kEllipsisStr + "ain.reallylongdomainname.com"},
|
| + kEllipsisStr + "ain.reallylongdomainname.com"},
|
| {"http://a.b.c.d.e.f.com", kEllipsisStr + ".e.f.com"},
|
| #endif
|
| };
|
| @@ -191,17 +192,21 @@ TEST(TextEliderTest, TestHostEliding) {
|
| for (size_t i = 0; i < arraysize(testcases); ++i) {
|
| const float available_width =
|
| GetStringWidthF(UTF8ToUTF16(testcases[i].output), gfx::FontList());
|
| - EXPECT_EQ(UTF8ToUTF16(testcases[i].output), ElideHost(
|
| - GURL(testcases[i].input), gfx::FontList(), available_width));
|
| + EXPECT_EQ(UTF8ToUTF16(testcases[i].output),
|
| + secure_display::ElideHost(GURL(testcases[i].input),
|
| + gfx::FontList(), available_width));
|
| }
|
|
|
| // Trying to elide to a really short length will still keep the full TLD+1
|
| - EXPECT_EQ(base::ASCIIToUTF16("google.com"),
|
| - ElideHost(GURL("http://google.com"), gfx::FontList(), 2));
|
| + EXPECT_EQ(
|
| + base::ASCIIToUTF16("google.com"),
|
| + secure_display::ElideHost(GURL("http://google.com"), gfx::FontList(), 2));
|
| EXPECT_EQ(base::UTF8ToUTF16(kEllipsisStr + ".google.com"),
|
| - ElideHost(GURL("http://subdomain.google.com"), gfx::FontList(), 2));
|
| - EXPECT_EQ(base::ASCIIToUTF16("foo.bar"),
|
| - ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2));
|
| + secure_display::ElideHost(GURL("http://subdomain.google.com"),
|
| + gfx::FontList(), 2));
|
| + EXPECT_EQ(
|
| + base::ASCIIToUTF16("foo.bar"),
|
| + secure_display::ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2));
|
| }
|
|
|
| TEST(TextEliderTest, FormatUrlForSecurityDisplay) {
|
| @@ -308,17 +313,19 @@ TEST(TextEliderTest, FormatUrlForSecurityDisplay) {
|
|
|
| const char languages[] = "zh-TW,en-US,en,am,ar-EG,ar";
|
| for (size_t i = 0; i < arraysize(tests); ++i) {
|
| - base::string16 formatted =
|
| - FormatUrlForSecurityDisplay(GURL(tests[i].input), std::string());
|
| + base::string16 formatted = secure_display::FormatUrlForSecurityDisplay(
|
| + GURL(tests[i].input), std::string());
|
| EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted)
|
| << tests[i].description;
|
| base::string16 formatted_with_languages =
|
| - FormatUrlForSecurityDisplay(GURL(tests[i].input), languages);
|
| + secure_display::FormatUrlForSecurityDisplay(GURL(tests[i].input),
|
| + languages);
|
| EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted_with_languages)
|
| << tests[i].description;
|
| }
|
|
|
| - base::string16 formatted = FormatUrlForSecurityDisplay(GURL(), std::string());
|
| + base::string16 formatted =
|
| + secure_display::FormatUrlForSecurityDisplay(GURL(), std::string());
|
| EXPECT_EQ(base::string16(), formatted)
|
| << "Explicitly test the 0-argument GURL constructor";
|
| }
|
|
|