OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "app/text_elider.h" | 5 #include "app/text_elider.h" |
6 #include "app/l10n_util.h" | 6 #include "app/l10n_util.h" |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "gfx/font.h" | 10 #include "gfx/font.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 } // namespace | 51 } // namespace |
52 | 52 |
53 // Test eliding of commonplace URLs. | 53 // Test eliding of commonplace URLs. |
54 TEST(TextEliderTest, TestGeneralEliding) { | 54 TEST(TextEliderTest, TestGeneralEliding) { |
55 const std::wstring kEllipsisStr(kEllipsis); | 55 const std::wstring kEllipsisStr(kEllipsis); |
56 Testcase testcases[] = { | 56 Testcase testcases[] = { |
57 {"http://www.google.com/intl/en/ads/", | 57 {"http://www.google.com/intl/en/ads/", |
58 L"http://www.google.com/intl/en/ads/"}, | 58 L"www.google.com/intl/en/ads/"}, |
59 {"http://www.google.com/intl/en/ads/", L"www.google.com/intl/en/ads/"}, | 59 {"http://www.google.com/intl/en/ads/", L"www.google.com/intl/en/ads/"}, |
60 // TODO(port): make this test case work on mac. | 60 // TODO(port): make this test case work on mac. |
61 #if !defined(OS_MACOSX) | 61 #if !defined(OS_MACOSX) |
62 {"http://www.google.com/intl/en/ads/", | 62 {"http://www.google.com/intl/en/ads/", |
63 L"google.com/intl/" + kEllipsisStr + L"/ads/"}, | 63 L"google.com/intl/" + kEllipsisStr + L"/ads/"}, |
64 #endif | 64 #endif |
65 {"http://www.google.com/intl/en/ads/", | 65 {"http://www.google.com/intl/en/ads/", |
66 L"google.com/" + kEllipsisStr + L"/ads/"}, | 66 L"google.com/" + kEllipsisStr + L"/ads/"}, |
67 {"http://www.google.com/intl/en/ads/", L"google.com/" + kEllipsisStr}, | 67 {"http://www.google.com/intl/en/ads/", L"google.com/" + kEllipsisStr}, |
68 {"http://www.google.com/intl/en/ads/", L"goog" + kEllipsisStr}, | 68 {"http://www.google.com/intl/en/ads/", L"goog" + kEllipsisStr}, |
69 {"https://subdomain.foo.com/bar/filename.html", | 69 {"https://subdomain.foo.com/bar/filename.html", |
70 L"subdomain.foo.com/bar/filename.html"}, | 70 L"subdomain.foo.com/bar/filename.html"}, |
71 {"https://subdomain.foo.com/bar/filename.html", | 71 {"https://subdomain.foo.com/bar/filename.html", |
72 L"subdomain.foo.com/" + kEllipsisStr + L"/filename.html"}, | 72 L"subdomain.foo.com/" + kEllipsisStr + L"/filename.html"}, |
73 {"http://subdomain.foo.com/bar/filename.html", | 73 {"http://subdomain.foo.com/bar/filename.html", |
74 kEllipsisStr + L"foo.com/" + kEllipsisStr + L"/filename.html"}, | 74 kEllipsisStr + L"foo.com/" + kEllipsisStr + L"/filename.html"}, |
75 {"http://www.google.com/intl/en/ads/?aLongQueryWhichIsNotRequired", | 75 {"http://www.google.com/intl/en/ads/?aLongQueryWhichIsNotRequired", |
76 L"http://www.google.com/intl/en/ads/?aLongQ" + kEllipsisStr}, | 76 L"www.google.com/intl/en/ads/?aLongQ" + kEllipsisStr}, |
77 }; | 77 }; |
78 | 78 |
79 RunTest(testcases, arraysize(testcases)); | 79 RunTest(testcases, arraysize(testcases)); |
80 } | 80 } |
81 | 81 |
82 // Test eliding of empty strings, URLs with ports, passwords, queries, etc. | 82 // Test eliding of empty strings, URLs with ports, passwords, queries, etc. |
83 TEST(TextEliderTest, TestMoreEliding) { | 83 TEST(TextEliderTest, TestMoreEliding) { |
84 const std::wstring kEllipsisStr(kEllipsis); | 84 const std::wstring kEllipsisStr(kEllipsis); |
85 Testcase testcases[] = { | 85 Testcase testcases[] = { |
86 {"http://www.google.com/foo?bar", L"http://www.google.com/foo?bar"}, | 86 {"http://www.google.com/foo?bar", L"www.google.com/foo?bar"}, |
87 {"http://xyz.google.com/foo?bar", L"xyz.google.com/foo?" + kEllipsisStr}, | 87 {"http://xyz.google.com/foo?bar", L"xyz.google.com/foo?" + kEllipsisStr}, |
88 {"http://xyz.google.com/foo?bar", L"xyz.google.com/foo" + kEllipsisStr}, | 88 {"http://xyz.google.com/foo?bar", L"xyz.google.com/foo" + kEllipsisStr}, |
89 {"http://xyz.google.com/foo?bar", L"xyz.google.com/fo" + kEllipsisStr}, | 89 {"http://xyz.google.com/foo?bar", L"xyz.google.com/fo" + kEllipsisStr}, |
90 {"http://a.b.com/pathname/c?d", L"a.b.com/" + kEllipsisStr + L"/c?d"}, | 90 {"http://a.b.com/pathname/c?d", L"a.b.com/" + kEllipsisStr + L"/c?d"}, |
91 {"", L""}, | 91 {"", L""}, |
92 {"http://foo.bar..example.com...hello/test/filename.html", | 92 {"http://foo.bar..example.com...hello/test/filename.html", |
93 L"foo.bar..example.com...hello/" + kEllipsisStr + L"/filename.html"}, | 93 L"foo.bar..example.com...hello/" + kEllipsisStr + L"/filename.html"}, |
94 {"http://foo.bar../", L"http://foo.bar../"}, | 94 {"http://foo.bar../", L"foo.bar../"}, |
95 {"http://xn--1lq90i.cn/foo", L"http://\x5317\x4eac.cn/foo"}, | 95 {"http://xn--1lq90i.cn/foo", L"\x5317\x4eac.cn/foo"}, |
96 {"http://me:mypass@secrethost.com:99/foo?bar#baz", | 96 {"http://me:mypass@secrethost.com:99/foo?bar#baz", |
97 L"http://secrethost.com:99/foo?bar#baz"}, | 97 L"secrethost.com:99/foo?bar#baz"}, |
98 {"http://me:mypass@ss%xxfdsf.com/foo", L"http://ss%25xxfdsf.com/foo"}, | 98 {"http://me:mypass@ss%xxfdsf.com/foo", L"ss%25xxfdsf.com/foo"}, |
99 {"mailto:elgoato@elgoato.com", L"mailto:elgoato@elgoato.com"}, | 99 {"mailto:elgoato@elgoato.com", L"mailto:elgoato@elgoato.com"}, |
100 {"javascript:click(0)", L"javascript:click(0)"}, | 100 {"javascript:click(0)", L"javascript:click(0)"}, |
101 {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename", | 101 {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename", |
102 L"chess.eecs.berkeley.edu:4430/login/arbitfilename"}, | 102 L"chess.eecs.berkeley.edu:4430/login/arbitfilename"}, |
103 {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename", | 103 {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename", |
104 kEllipsisStr + L"berkeley.edu:4430/" + kEllipsisStr + L"/arbitfilename"}, | 104 kEllipsisStr + L"berkeley.edu:4430/" + kEllipsisStr + L"/arbitfilename"}, |
105 | 105 |
106 // Unescaping. | 106 // Unescaping. |
107 {"http://www/%E4%BD%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0", | 107 {"http://www/%E4%BD%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0", |
108 L"http://www/\x4f60\x597d?q=\x4f60\x597d#\x4f60"}, | 108 L"www/\x4f60\x597d?q=\x4f60\x597d#\x4f60"}, |
109 | 109 |
110 // Invalid unescaping for path. The ref will always be valid UTF-8. We don't | 110 // Invalid unescaping for path. The ref will always be valid UTF-8. We don't |
111 // bother to do too many edge cases, since these are handled by the escaper | 111 // bother to do too many edge cases, since these are handled by the escaper |
112 // unittest. | 112 // unittest. |
113 {"http://www/%E4%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0", | 113 {"http://www/%E4%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0", |
114 L"http://www/%E4%A0%E5%A5%BD?q=\x4f60\x597d#\x4f60"}, | 114 L"www/%E4%A0%E5%A5%BD?q=\x4f60\x597d#\x4f60"}, |
115 }; | 115 }; |
116 | 116 |
117 RunTest(testcases, arraysize(testcases)); | 117 RunTest(testcases, arraysize(testcases)); |
118 } | 118 } |
119 | 119 |
120 // Test eliding of file: URLs. | 120 // Test eliding of file: URLs. |
121 TEST(TextEliderTest, TestFileURLEliding) { | 121 TEST(TextEliderTest, TestFileURLEliding) { |
122 const std::wstring kEllipsisStr(kEllipsis); | 122 const std::wstring kEllipsisStr(kEllipsis); |
123 Testcase testcases[] = { | 123 Testcase testcases[] = { |
124 {"file:///C:/path1/path2/path3/filename", | 124 {"file:///C:/path1/path2/path3/filename", |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 ElideText(testcases[i].input, font, | 222 ElideText(testcases[i].input, font, |
223 font.GetStringWidth(testcases[i].output)).size()); | 223 font.GetStringWidth(testcases[i].output)).size()); |
224 EXPECT_EQ(kEllipsisStr, | 224 EXPECT_EQ(kEllipsisStr, |
225 ElideText(testcases[i].input, font, ellipsis_width)); | 225 ElideText(testcases[i].input, font, ellipsis_width)); |
226 } | 226 } |
227 } | 227 } |
228 | 228 |
229 // Verifies display_url is set correctly. | 229 // Verifies display_url is set correctly. |
230 TEST(TextEliderTest, SortedDisplayURL) { | 230 TEST(TextEliderTest, SortedDisplayURL) { |
231 gfx::SortedDisplayURL d_url(GURL("http://www.google.com/"), std::wstring()); | 231 gfx::SortedDisplayURL d_url(GURL("http://www.google.com/"), std::wstring()); |
232 EXPECT_EQ("http://www.google.com/", UTF16ToASCII(d_url.display_url())); | 232 EXPECT_EQ("www.google.com/", UTF16ToASCII(d_url.display_url())); |
233 } | 233 } |
234 | 234 |
235 // Verifies DisplayURL::Compare works correctly. | 235 // Verifies DisplayURL::Compare works correctly. |
236 TEST(TextEliderTest, SortedDisplayURLCompare) { | 236 TEST(TextEliderTest, SortedDisplayURLCompare) { |
237 UErrorCode create_status = U_ZERO_ERROR; | 237 UErrorCode create_status = U_ZERO_ERROR; |
238 scoped_ptr<icu::Collator> collator( | 238 scoped_ptr<icu::Collator> collator( |
239 icu::Collator::createInstance(create_status)); | 239 icu::Collator::createInstance(create_status)); |
240 if (!U_SUCCESS(create_status)) | 240 if (!U_SUCCESS(create_status)) |
241 return; | 241 return; |
242 | 242 |
(...skipping 19 matching lines...) Expand all Loading... |
262 { "http://www.a/", "http://b/", -1 }, | 262 { "http://www.a/", "http://b/", -1 }, |
263 }; | 263 }; |
264 | 264 |
265 for (size_t i = 0; i < arraysize(tests); ++i) { | 265 for (size_t i = 0; i < arraysize(tests); ++i) { |
266 gfx::SortedDisplayURL url1(GURL(tests[i].a), std::wstring()); | 266 gfx::SortedDisplayURL url1(GURL(tests[i].a), std::wstring()); |
267 gfx::SortedDisplayURL url2(GURL(tests[i].b), std::wstring()); | 267 gfx::SortedDisplayURL url2(GURL(tests[i].b), std::wstring()); |
268 EXPECT_EQ(tests[i].compare_result, url1.Compare(url2, collator.get())); | 268 EXPECT_EQ(tests[i].compare_result, url1.Compare(url2, collator.get())); |
269 EXPECT_EQ(-tests[i].compare_result, url2.Compare(url1, collator.get())); | 269 EXPECT_EQ(-tests[i].compare_result, url2.Compare(url1, collator.get())); |
270 } | 270 } |
271 } | 271 } |
OLD | NEW |