OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "app/text_elider.h" | |
6 #include "base/file_path.h" | |
7 #include "base/i18n/rtl.h" | |
8 #include "base/scoped_ptr.h" | |
9 #include "base/string_util.h" | |
10 #include "base/utf_string_conversions.h" | |
11 #include "gfx/font.h" | |
12 #include "googleurl/src/gurl.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | |
15 namespace { | |
16 | |
17 const wchar_t kEllipsis[] = L"\x2026"; | |
18 | |
19 struct Testcase { | |
20 const std::string input; | |
21 const std::wstring output; | |
22 }; | |
23 | |
24 struct FileTestcase { | |
25 const FilePath::StringType input; | |
26 const std::wstring output; | |
27 }; | |
28 | |
29 struct UTF16Testcase { | |
30 const string16 input; | |
31 const string16 output; | |
32 }; | |
33 | |
34 struct TestData { | |
35 const std::string a; | |
36 const std::string b; | |
37 const int compare_result; | |
38 }; | |
39 | |
40 void RunTest(Testcase* testcases, size_t num_testcases) { | |
41 static const gfx::Font font; | |
42 for (size_t i = 0; i < num_testcases; ++i) { | |
43 const GURL url(testcases[i].input); | |
44 // Should we test with non-empty language list? | |
45 // That's kinda redundant with net_util_unittests. | |
46 EXPECT_EQ(WideToUTF16(testcases[i].output), | |
47 ElideUrl(url, font, | |
48 font.GetStringWidth(WideToUTF16(testcases[i].output)), | |
49 std::wstring())); | |
50 } | |
51 } | |
52 | |
53 } // namespace | |
54 | |
55 // Test eliding of commonplace URLs. | |
56 TEST(TextEliderTest, TestGeneralEliding) { | |
57 const std::wstring kEllipsisStr(kEllipsis); | |
58 Testcase testcases[] = { | |
59 {"http://www.google.com/intl/en/ads/", | |
60 L"www.google.com/intl/en/ads/"}, | |
61 {"http://www.google.com/intl/en/ads/", L"www.google.com/intl/en/ads/"}, | |
62 // TODO(port): make this test case work on mac. | |
63 #if !defined(OS_MACOSX) | |
64 {"http://www.google.com/intl/en/ads/", | |
65 L"google.com/intl/" + kEllipsisStr + L"/ads/"}, | |
66 #endif | |
67 {"http://www.google.com/intl/en/ads/", | |
68 L"google.com/" + kEllipsisStr + L"/ads/"}, | |
69 {"http://www.google.com/intl/en/ads/", L"google.com/" + kEllipsisStr}, | |
70 {"http://www.google.com/intl/en/ads/", L"goog" + kEllipsisStr}, | |
71 {"https://subdomain.foo.com/bar/filename.html", | |
72 L"subdomain.foo.com/bar/filename.html"}, | |
73 {"https://subdomain.foo.com/bar/filename.html", | |
74 L"subdomain.foo.com/" + kEllipsisStr + L"/filename.html"}, | |
75 {"http://subdomain.foo.com/bar/filename.html", | |
76 kEllipsisStr + L"foo.com/" + kEllipsisStr + L"/filename.html"}, | |
77 {"http://www.google.com/intl/en/ads/?aLongQueryWhichIsNotRequired", | |
78 L"www.google.com/intl/en/ads/?aLongQ" + kEllipsisStr}, | |
79 }; | |
80 | |
81 RunTest(testcases, arraysize(testcases)); | |
82 } | |
83 | |
84 // Test eliding of empty strings, URLs with ports, passwords, queries, etc. | |
85 TEST(TextEliderTest, TestMoreEliding) { | |
86 const std::wstring kEllipsisStr(kEllipsis); | |
87 Testcase testcases[] = { | |
88 {"http://www.google.com/foo?bar", L"www.google.com/foo?bar"}, | |
89 {"http://xyz.google.com/foo?bar", L"xyz.google.com/foo?" + kEllipsisStr}, | |
90 {"http://xyz.google.com/foo?bar", L"xyz.google.com/foo" + kEllipsisStr}, | |
91 {"http://xyz.google.com/foo?bar", L"xyz.google.com/fo" + kEllipsisStr}, | |
92 {"http://a.b.com/pathname/c?d", L"a.b.com/" + kEllipsisStr + L"/c?d"}, | |
93 {"", L""}, | |
94 {"http://foo.bar..example.com...hello/test/filename.html", | |
95 L"foo.bar..example.com...hello/" + kEllipsisStr + L"/filename.html"}, | |
96 {"http://foo.bar../", L"foo.bar.."}, | |
97 {"http://xn--1lq90i.cn/foo", L"\x5317\x4eac.cn/foo"}, | |
98 {"http://me:mypass@secrethost.com:99/foo?bar#baz", | |
99 L"secrethost.com:99/foo?bar#baz"}, | |
100 {"http://me:mypass@ss%xxfdsf.com/foo", L"ss%25xxfdsf.com/foo"}, | |
101 {"mailto:elgoato@elgoato.com", L"mailto:elgoato@elgoato.com"}, | |
102 {"javascript:click(0)", L"javascript:click(0)"}, | |
103 {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename", | |
104 L"chess.eecs.berkeley.edu:4430/login/arbitfilename"}, | |
105 {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename", | |
106 kEllipsisStr + L"berkeley.edu:4430/" + kEllipsisStr + L"/arbitfilename"}, | |
107 | |
108 // Unescaping. | |
109 {"http://www/%E4%BD%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0", | |
110 L"www/\x4f60\x597d?q=\x4f60\x597d#\x4f60"}, | |
111 | |
112 // Invalid unescaping for path. The ref will always be valid UTF-8. We don't | |
113 // bother to do too many edge cases, since these are handled by the escaper | |
114 // unittest. | |
115 {"http://www/%E4%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0", | |
116 L"www/%E4%A0%E5%A5%BD?q=\x4f60\x597d#\x4f60"}, | |
117 }; | |
118 | |
119 RunTest(testcases, arraysize(testcases)); | |
120 } | |
121 | |
122 // Test eliding of file: URLs. | |
123 TEST(TextEliderTest, TestFileURLEliding) { | |
124 const std::wstring kEllipsisStr(kEllipsis); | |
125 Testcase testcases[] = { | |
126 {"file:///C:/path1/path2/path3/filename", | |
127 L"file:///C:/path1/path2/path3/filename"}, | |
128 {"file:///C:/path1/path2/path3/filename", | |
129 L"C:/path1/path2/path3/filename"}, | |
130 // GURL parses "file:///C:path" differently on windows than it does on posix. | |
131 #if defined(OS_WIN) | |
132 {"file:///C:path1/path2/path3/filename", | |
133 L"C:/path1/path2/" + kEllipsisStr + L"/filename"}, | |
134 {"file:///C:path1/path2/path3/filename", | |
135 L"C:/path1/" + kEllipsisStr + L"/filename"}, | |
136 {"file:///C:path1/path2/path3/filename", | |
137 L"C:/" + kEllipsisStr + L"/filename"}, | |
138 #endif | |
139 {"file://filer/foo/bar/file", L"filer/foo/bar/file"}, | |
140 {"file://filer/foo/bar/file", L"filer/foo/" + kEllipsisStr + L"/file"}, | |
141 {"file://filer/foo/bar/file", L"filer/" + kEllipsisStr + L"/file"}, | |
142 }; | |
143 | |
144 RunTest(testcases, arraysize(testcases)); | |
145 } | |
146 | |
147 TEST(TextEliderTest, TestFilenameEliding) { | |
148 const std::wstring kEllipsisStr(kEllipsis); | |
149 const FilePath::StringType kPathSeparator = | |
150 FilePath::StringType().append(1, FilePath::kSeparators[0]); | |
151 | |
152 FileTestcase testcases[] = { | |
153 {FILE_PATH_LITERAL(""), L""}, | |
154 {FILE_PATH_LITERAL("."), L"."}, | |
155 {FILE_PATH_LITERAL("filename.exe"), L"filename.exe"}, | |
156 {FILE_PATH_LITERAL(".longext"), L".longext"}, | |
157 {FILE_PATH_LITERAL("pie"), L"pie"}, | |
158 {FILE_PATH_LITERAL("c:") + kPathSeparator + FILE_PATH_LITERAL("path") + | |
159 kPathSeparator + FILE_PATH_LITERAL("filename.pie"), | |
160 L"filename.pie"}, | |
161 {FILE_PATH_LITERAL("c:") + kPathSeparator + FILE_PATH_LITERAL("path") + | |
162 kPathSeparator + FILE_PATH_LITERAL("longfilename.pie"), | |
163 L"long" + kEllipsisStr + L".pie"}, | |
164 {FILE_PATH_LITERAL("http://path.com/filename.pie"), L"filename.pie"}, | |
165 {FILE_PATH_LITERAL("http://path.com/longfilename.pie"), | |
166 L"long" + kEllipsisStr + L".pie"}, | |
167 {FILE_PATH_LITERAL("piesmashingtacularpants"), L"pie" + kEllipsisStr}, | |
168 {FILE_PATH_LITERAL(".piesmashingtacularpants"), L".pie" + kEllipsisStr}, | |
169 {FILE_PATH_LITERAL("cheese."), L"cheese."}, | |
170 {FILE_PATH_LITERAL("file name.longext"), | |
171 L"file" + kEllipsisStr + L".longext"}, | |
172 {FILE_PATH_LITERAL("fil ename.longext"), | |
173 L"fil " + kEllipsisStr + L".longext"}, | |
174 {FILE_PATH_LITERAL("filename.longext"), | |
175 L"file" + kEllipsisStr + L".longext"}, | |
176 {FILE_PATH_LITERAL("filename.middleext.longext"), | |
177 L"filename.mid" + kEllipsisStr + L".longext"} | |
178 }; | |
179 | |
180 static const gfx::Font font; | |
181 for (size_t i = 0; i < arraysize(testcases); ++i) { | |
182 FilePath filepath(testcases[i].input); | |
183 string16 expected = WideToUTF16(testcases[i].output); | |
184 expected = base::i18n::GetDisplayStringInLTRDirectionality(expected); | |
185 EXPECT_EQ(expected, ElideFilename(filepath, | |
186 font, | |
187 font.GetStringWidth(WideToUTF16(testcases[i].output)))); | |
188 } | |
189 } | |
190 | |
191 TEST(TextEliderTest, ElideTextLongStrings) { | |
192 const string16 kEllipsisStr(WideToUTF16(kEllipsis)); | |
193 string16 data_scheme(UTF8ToUTF16("data:text/plain,")); | |
194 size_t data_scheme_length = data_scheme.length(); | |
195 | |
196 string16 ten_a(10, 'a'); | |
197 string16 hundred_a(100, 'a'); | |
198 string16 thousand_a(1000, 'a'); | |
199 string16 ten_thousand_a(10000, 'a'); | |
200 string16 hundred_thousand_a(100000, 'a'); | |
201 string16 million_a(1000000, 'a'); | |
202 | |
203 size_t number_of_as = 156; | |
204 string16 long_string_end( | |
205 data_scheme + string16(number_of_as, 'a') + kEllipsisStr); | |
206 UTF16Testcase testcases_end[] = { | |
207 {data_scheme + ten_a, data_scheme + ten_a}, | |
208 {data_scheme + hundred_a, data_scheme + hundred_a}, | |
209 {data_scheme + thousand_a, long_string_end}, | |
210 {data_scheme + ten_thousand_a, long_string_end}, | |
211 {data_scheme + hundred_thousand_a, long_string_end}, | |
212 {data_scheme + million_a, long_string_end}, | |
213 }; | |
214 | |
215 const gfx::Font font; | |
216 int ellipsis_width = font.GetStringWidth(kEllipsisStr); | |
217 for (size_t i = 0; i < arraysize(testcases_end); ++i) { | |
218 // Compare sizes rather than actual contents because if the test fails, | |
219 // output is rather long. | |
220 EXPECT_EQ(testcases_end[i].output.size(), | |
221 ElideText(testcases_end[i].input, font, | |
222 font.GetStringWidth(testcases_end[i].output), | |
223 false).size()); | |
224 EXPECT_EQ(kEllipsisStr, | |
225 ElideText(testcases_end[i].input, font, ellipsis_width, false)); | |
226 } | |
227 | |
228 size_t number_of_trailing_as = (data_scheme_length + number_of_as) / 2; | |
229 string16 long_string_middle(data_scheme + | |
230 string16(number_of_as - number_of_trailing_as, 'a') + kEllipsisStr + | |
231 string16(number_of_trailing_as, 'a')); | |
232 UTF16Testcase testcases_middle[] = { | |
233 {data_scheme + ten_a, data_scheme + ten_a}, | |
234 {data_scheme + hundred_a, data_scheme + hundred_a}, | |
235 {data_scheme + thousand_a, long_string_middle}, | |
236 {data_scheme + ten_thousand_a, long_string_middle}, | |
237 {data_scheme + hundred_thousand_a, long_string_middle}, | |
238 {data_scheme + million_a, long_string_middle}, | |
239 }; | |
240 | |
241 for (size_t i = 0; i < arraysize(testcases_middle); ++i) { | |
242 // Compare sizes rather than actual contents because if the test fails, | |
243 // output is rather long. | |
244 EXPECT_EQ(testcases_middle[i].output.size(), | |
245 ElideText(testcases_middle[i].input, font, | |
246 font.GetStringWidth(testcases_middle[i].output), | |
247 false).size()); | |
248 EXPECT_EQ(kEllipsisStr, | |
249 ElideText(testcases_middle[i].input, font, ellipsis_width, | |
250 false)); | |
251 } | |
252 } | |
253 | |
254 // Verifies display_url is set correctly. | |
255 TEST(TextEliderTest, SortedDisplayURL) { | |
256 gfx::SortedDisplayURL d_url(GURL("http://www.google.com"), std::wstring()); | |
257 EXPECT_EQ("www.google.com", UTF16ToASCII(d_url.display_url())); | |
258 } | |
259 | |
260 // Verifies DisplayURL::Compare works correctly. | |
261 TEST(TextEliderTest, SortedDisplayURLCompare) { | |
262 UErrorCode create_status = U_ZERO_ERROR; | |
263 scoped_ptr<icu::Collator> collator( | |
264 icu::Collator::createInstance(create_status)); | |
265 if (!U_SUCCESS(create_status)) | |
266 return; | |
267 | |
268 TestData tests[] = { | |
269 // IDN comparison. Hosts equal, so compares on path. | |
270 { "http://xn--1lq90i.cn/a", "http://xn--1lq90i.cn/b", -1}, | |
271 | |
272 // Because the host and after host match, this compares the full url. | |
273 { "http://www.x/b", "http://x/b", -1 }, | |
274 | |
275 // Because the host and after host match, this compares the full url. | |
276 { "http://www.a:1/b", "http://a:1/b", 1 }, | |
277 | |
278 // The hosts match, so these end up comparing on the after host portion. | |
279 { "http://www.x:0/b", "http://x:1/b", -1 }, | |
280 { "http://www.x/a", "http://x/b", -1 }, | |
281 { "http://x/b", "http://www.x/a", 1 }, | |
282 | |
283 // Trivial Equality. | |
284 { "http://a/", "http://a/", 0 }, | |
285 | |
286 // Compares just hosts. | |
287 { "http://www.a/", "http://b/", -1 }, | |
288 }; | |
289 | |
290 for (size_t i = 0; i < arraysize(tests); ++i) { | |
291 gfx::SortedDisplayURL url1(GURL(tests[i].a), std::wstring()); | |
292 gfx::SortedDisplayURL url2(GURL(tests[i].b), std::wstring()); | |
293 EXPECT_EQ(tests[i].compare_result, url1.Compare(url2, collator.get())); | |
294 EXPECT_EQ(-tests[i].compare_result, url2.Compare(url1, collator.get())); | |
295 } | |
296 } | |
297 | |
298 TEST(TextEliderTest, ElideString) { | |
299 struct TestData { | |
300 const wchar_t* input; | |
301 int max_len; | |
302 bool result; | |
303 const wchar_t* output; | |
304 } cases[] = { | |
305 { L"Hello", 0, true, L"" }, | |
306 { L"", 0, false, L"" }, | |
307 { L"Hello, my name is Tom", 1, true, L"H" }, | |
308 { L"Hello, my name is Tom", 2, true, L"He" }, | |
309 { L"Hello, my name is Tom", 3, true, L"H.m" }, | |
310 { L"Hello, my name is Tom", 4, true, L"H..m" }, | |
311 { L"Hello, my name is Tom", 5, true, L"H...m" }, | |
312 { L"Hello, my name is Tom", 6, true, L"He...m" }, | |
313 { L"Hello, my name is Tom", 7, true, L"He...om" }, | |
314 { L"Hello, my name is Tom", 10, true, L"Hell...Tom" }, | |
315 { L"Hello, my name is Tom", 100, false, L"Hello, my name is Tom" } | |
316 }; | |
317 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | |
318 std::wstring output; | |
319 EXPECT_EQ(cases[i].result, | |
320 gfx::ElideString(cases[i].input, cases[i].max_len, &output)); | |
321 EXPECT_EQ(cases[i].output, output); | |
322 } | |
323 } | |
324 | |
325 TEST(TextEliderTest, ElideRectangleString) { | |
326 struct TestData { | |
327 const wchar_t* input; | |
328 int max_rows; | |
329 int max_cols; | |
330 bool result; | |
331 const wchar_t* output; | |
332 } cases[] = { | |
333 { L"", 0, 0, false, L"" }, | |
334 { L"", 1, 1, false, L"" }, | |
335 { L"Hi, my name is\nTom", 0, 0, true, L"..." }, | |
336 { L"Hi, my name is\nTom", 1, 0, true, L"\n..." }, | |
337 { L"Hi, my name is\nTom", 0, 1, true, L"..." }, | |
338 { L"Hi, my name is\nTom", 1, 1, true, L"H\n..." }, | |
339 { L"Hi, my name is\nTom", 2, 1, true, L"H\ni\n..." }, | |
340 { L"Hi, my name is\nTom", 3, 1, true, L"H\ni\n,\n..." }, | |
341 { L"Hi, my name is\nTom", 4, 1, true, L"H\ni\n,\n \n..." }, | |
342 { L"Hi, my name is\nTom", 5, 1, true, L"H\ni\n,\n \nm\n..." }, | |
343 { L"Hi, my name is\nTom", 0, 2, true, L"..." }, | |
344 { L"Hi, my name is\nTom", 1, 2, true, L"Hi\n..." }, | |
345 { L"Hi, my name is\nTom", 2, 2, true, L"Hi\n, \n..." }, | |
346 { L"Hi, my name is\nTom", 3, 2, true, L"Hi\n, \nmy\n..." }, | |
347 { L"Hi, my name is\nTom", 4, 2, true, L"Hi\n, \nmy\n n\n..." }, | |
348 { L"Hi, my name is\nTom", 5, 2, true, L"Hi\n, \nmy\n n\nam\n..." }, | |
349 { L"Hi, my name is\nTom", 0, 3, true, L"..." }, | |
350 { L"Hi, my name is\nTom", 1, 3, true, L"Hi,\n..." }, | |
351 { L"Hi, my name is\nTom", 2, 3, true, L"Hi,\n my\n..." }, | |
352 { L"Hi, my name is\nTom", 3, 3, true, L"Hi,\n my\n na\n..." }, | |
353 { L"Hi, my name is\nTom", 4, 3, true, L"Hi,\n my\n na\nme \n..." }, | |
354 { L"Hi, my name is\nTom", 5, 3, true, L"Hi,\n my\n na\nme \nis\n..." }, | |
355 { L"Hi, my name is\nTom", 1, 4, true, L"Hi, \n..." }, | |
356 { L"Hi, my name is\nTom", 2, 4, true, L"Hi, \nmy n\n..." }, | |
357 { L"Hi, my name is\nTom", 3, 4, true, L"Hi, \nmy n\name \n..." }, | |
358 { L"Hi, my name is\nTom", 4, 4, true, L"Hi, \nmy n\name \nis\n..." }, | |
359 { L"Hi, my name is\nTom", 5, 4, false, L"Hi, \nmy n\name \nis\nTom" }, | |
360 { L"Hi, my name is\nTom", 1, 5, true, L"Hi, \n..." }, | |
361 { L"Hi, my name is\nTom", 2, 5, true, L"Hi, \nmy na\n..." }, | |
362 { L"Hi, my name is\nTom", 3, 5, true, L"Hi, \nmy na\nme \n..." }, | |
363 { L"Hi, my name is\nTom", 4, 5, true, L"Hi, \nmy na\nme \nis\n..." }, | |
364 { L"Hi, my name is\nTom", 5, 5, false, L"Hi, \nmy na\nme \nis\nTom" }, | |
365 { L"Hi, my name is\nTom", 1, 6, true, L"Hi, \n..." }, | |
366 { L"Hi, my name is\nTom", 2, 6, true, L"Hi, \nmy \n..." }, | |
367 { L"Hi, my name is\nTom", 3, 6, true, L"Hi, \nmy \nname \n..." }, | |
368 { L"Hi, my name is\nTom", 4, 6, true, L"Hi, \nmy \nname \nis\n..." }, | |
369 { L"Hi, my name is\nTom", 5, 6, false, L"Hi, \nmy \nname \nis\nTom" }, | |
370 { L"Hi, my name is\nTom", 1, 7, true, L"Hi, \n..." }, | |
371 { L"Hi, my name is\nTom", 2, 7, true, L"Hi, \nmy \n..." }, | |
372 { L"Hi, my name is\nTom", 3, 7, true, L"Hi, \nmy \nname \n..." }, | |
373 { L"Hi, my name is\nTom", 4, 7, true, L"Hi, \nmy \nname \nis\n..." }, | |
374 { L"Hi, my name is\nTom", 5, 7, false, L"Hi, \nmy \nname \nis\nTom" }, | |
375 { L"Hi, my name is\nTom", 1, 8, true, L"Hi, my \n..." }, | |
376 { L"Hi, my name is\nTom", 2, 8, true, L"Hi, my \nname \n..." }, | |
377 { L"Hi, my name is\nTom", 3, 8, true, L"Hi, my \nname \nis\n..." }, | |
378 { L"Hi, my name is\nTom", 4, 8, false, L"Hi, my \nname \nis\nTom" }, | |
379 { L"Hi, my name is\nTom", 1, 9, true, L"Hi, my \n..." }, | |
380 { L"Hi, my name is\nTom", 2, 9, true, L"Hi, my \nname is\n..." }, | |
381 { L"Hi, my name is\nTom", 3, 9, false, L"Hi, my \nname is\nTom" }, | |
382 { L"Hi, my name is\nTom", 1, 10, true, L"Hi, my \n..." }, | |
383 { L"Hi, my name is\nTom", 2, 10, true, L"Hi, my \nname is\n..." }, | |
384 { L"Hi, my name is\nTom", 3, 10, false, L"Hi, my \nname is\nTom" }, | |
385 { L"Hi, my name is\nTom", 1, 11, true, L"Hi, my \n..." }, | |
386 { L"Hi, my name is\nTom", 2, 11, true, L"Hi, my \nname is\n..." }, | |
387 { L"Hi, my name is\nTom", 3, 11, false, L"Hi, my \nname is\nTom" }, | |
388 { L"Hi, my name is\nTom", 1, 12, true, L"Hi, my \n..." }, | |
389 { L"Hi, my name is\nTom", 2, 12, true, L"Hi, my \nname is\n..." }, | |
390 { L"Hi, my name is\nTom", 3, 12, false, L"Hi, my \nname is\nTom" }, | |
391 { L"Hi, my name is\nTom", 1, 13, true, L"Hi, my name \n..." }, | |
392 { L"Hi, my name is\nTom", 2, 13, true, L"Hi, my name \nis\n..." }, | |
393 { L"Hi, my name is\nTom", 3, 13, false, L"Hi, my name \nis\nTom" }, | |
394 { L"Hi, my name is\nTom", 1, 20, true, L"Hi, my name is\n..." }, | |
395 { L"Hi, my name is\nTom", 2, 20, false, L"Hi, my name is\nTom" }, | |
396 { L"Hi, my name is Tom", 1, 40, false, L"Hi, my name is Tom" }, | |
397 }; | |
398 string16 output; | |
399 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | |
400 EXPECT_EQ(cases[i].result, | |
401 gfx::ElideRectangleString(WideToUTF16(cases[i].input), | |
402 cases[i].max_rows, cases[i].max_cols, | |
403 &output)); | |
404 EXPECT_EQ(cases[i].output, UTF16ToWide(output)); | |
405 } | |
406 } | |
407 | |
408 TEST(TextEliderTest, ElideRectangleWide16) { | |
409 // Two greek words separated by space. | |
410 const string16 str(WideToUTF16( | |
411 L"\x03a0\x03b1\x03b3\x03ba\x03cc\x03c3\x03bc\x03b9" | |
412 L"\x03bf\x03c2\x0020\x0399\x03c3\x03c4\x03cc\x03c2")); | |
413 const string16 out1(WideToUTF16( | |
414 L"\x03a0\x03b1\x03b3\x03ba\n" | |
415 L"\x03cc\x03c3\x03bc\x03b9\n" | |
416 L"...")); | |
417 const string16 out2(WideToUTF16( | |
418 L"\x03a0\x03b1\x03b3\x03ba\x03cc\x03c3\x03bc\x03b9\x03bf\x03c2\x0020\n" | |
419 L"\x0399\x03c3\x03c4\x03cc\x03c2")); | |
420 string16 output; | |
421 EXPECT_TRUE(gfx::ElideRectangleString(str, 2, 4, &output)); | |
422 EXPECT_EQ(out1, output); | |
423 EXPECT_FALSE(gfx::ElideRectangleString(str, 2, 12, &output)); | |
424 EXPECT_EQ(out2, output); | |
425 } | |
426 | |
427 TEST(TextEliderTest, ElideRectangleWide32) { | |
428 // Four U+1D49C MATHEMATICAL SCRIPT CAPITAL A followed by space "aaaaa". | |
429 const string16 str(UTF8ToUTF16( | |
430 "\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C" | |
431 " aaaaa")); | |
432 const string16 out(UTF8ToUTF16( | |
433 "\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\n" | |
434 "\xF0\x9D\x92\x9C \naaa\n...")); | |
435 string16 output; | |
436 EXPECT_TRUE(gfx::ElideRectangleString(str, 3, 3, &output)); | |
437 EXPECT_EQ(out, output); | |
438 } | |
439 | |
OLD | NEW |