OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 { "http://www.a/", "http://b/", -1 }, | 288 { "http://www.a/", "http://b/", -1 }, |
289 }; | 289 }; |
290 | 290 |
291 for (size_t i = 0; i < arraysize(tests); ++i) { | 291 for (size_t i = 0; i < arraysize(tests); ++i) { |
292 gfx::SortedDisplayURL url1(GURL(tests[i].a), std::wstring()); | 292 gfx::SortedDisplayURL url1(GURL(tests[i].a), std::wstring()); |
293 gfx::SortedDisplayURL url2(GURL(tests[i].b), std::wstring()); | 293 gfx::SortedDisplayURL url2(GURL(tests[i].b), std::wstring()); |
294 EXPECT_EQ(tests[i].compare_result, url1.Compare(url2, collator.get())); | 294 EXPECT_EQ(tests[i].compare_result, url1.Compare(url2, collator.get())); |
295 EXPECT_EQ(-tests[i].compare_result, url2.Compare(url1, collator.get())); | 295 EXPECT_EQ(-tests[i].compare_result, url2.Compare(url1, collator.get())); |
296 } | 296 } |
297 } | 297 } |
| 298 |
| 299 TEST(TextEliderTest, ElideString) { |
| 300 struct TestData { |
| 301 const wchar_t* input; |
| 302 int max_len; |
| 303 bool result; |
| 304 const wchar_t* output; |
| 305 } cases[] = { |
| 306 { L"Hello", 0, true, L"" }, |
| 307 { L"", 0, false, L"" }, |
| 308 { L"Hello, my name is Tom", 1, true, L"H" }, |
| 309 { L"Hello, my name is Tom", 2, true, L"He" }, |
| 310 { L"Hello, my name is Tom", 3, true, L"H.m" }, |
| 311 { L"Hello, my name is Tom", 4, true, L"H..m" }, |
| 312 { L"Hello, my name is Tom", 5, true, L"H...m" }, |
| 313 { L"Hello, my name is Tom", 6, true, L"He...m" }, |
| 314 { L"Hello, my name is Tom", 7, true, L"He...om" }, |
| 315 { L"Hello, my name is Tom", 10, true, L"Hell...Tom" }, |
| 316 { L"Hello, my name is Tom", 100, false, L"Hello, my name is Tom" } |
| 317 }; |
| 318 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
| 319 std::wstring output; |
| 320 EXPECT_EQ(cases[i].result, |
| 321 gfx::ElideString(cases[i].input, cases[i].max_len, &output)); |
| 322 EXPECT_TRUE(output == cases[i].output); |
| 323 } |
| 324 } |
OLD | NEW |