| 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 "gfx/font.h" | 11 #include "gfx/font.h" |
| 11 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 const wchar_t kEllipsis[] = L"\x2026"; | 17 const wchar_t kEllipsis[] = L"\x2026"; |
| 17 | 18 |
| 18 struct Testcase { | 19 struct Testcase { |
| 19 const std::string input; | 20 const std::string input; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 L"fil " + kEllipsisStr + L".longext"}, | 172 L"fil " + kEllipsisStr + L".longext"}, |
| 172 {FILE_PATH_LITERAL("filename.longext"), | 173 {FILE_PATH_LITERAL("filename.longext"), |
| 173 L"file" + kEllipsisStr + L".longext"}, | 174 L"file" + kEllipsisStr + L".longext"}, |
| 174 {FILE_PATH_LITERAL("filename.middleext.longext"), | 175 {FILE_PATH_LITERAL("filename.middleext.longext"), |
| 175 L"filename.mid" + kEllipsisStr + L".longext"} | 176 L"filename.mid" + kEllipsisStr + L".longext"} |
| 176 }; | 177 }; |
| 177 | 178 |
| 178 static const gfx::Font font; | 179 static const gfx::Font font; |
| 179 for (size_t i = 0; i < arraysize(testcases); ++i) { | 180 for (size_t i = 0; i < arraysize(testcases); ++i) { |
| 180 FilePath filepath(testcases[i].input); | 181 FilePath filepath(testcases[i].input); |
| 181 std::wstring expected = testcases[i].output; | 182 string16 expected = WideToUTF16(testcases[i].output); |
| 182 base::i18n::GetDisplayStringInLTRDirectionality(&expected); | 183 expected = base::i18n::GetDisplayStringInLTRDirectionality(expected); |
| 183 EXPECT_EQ(expected, ElideFilename(filepath, | 184 EXPECT_EQ(expected, WideToUTF16(ElideFilename(filepath, |
| 184 font, | 185 font, |
| 185 font.GetStringWidth(testcases[i].output))); | 186 font.GetStringWidth(testcases[i].output)))); |
| 186 } | 187 } |
| 187 } | 188 } |
| 188 | 189 |
| 189 TEST(TextEliderTest, ElideTextLongStrings) { | 190 TEST(TextEliderTest, ElideTextLongStrings) { |
| 190 const std::wstring kEllipsisStr(kEllipsis); | 191 const std::wstring kEllipsisStr(kEllipsis); |
| 191 std::wstring data_scheme(L"data:text/plain,"); | 192 std::wstring data_scheme(L"data:text/plain,"); |
| 192 size_t data_scheme_length = data_scheme.length(); | 193 size_t data_scheme_length = data_scheme.length(); |
| 193 | 194 |
| 194 std::wstring ten_a(10, L'a'); | 195 std::wstring ten_a(10, L'a'); |
| 195 std::wstring hundred_a(100, L'a'); | 196 std::wstring hundred_a(100, L'a'); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 { "http://www.a/", "http://b/", -1 }, | 286 { "http://www.a/", "http://b/", -1 }, |
| 286 }; | 287 }; |
| 287 | 288 |
| 288 for (size_t i = 0; i < arraysize(tests); ++i) { | 289 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 289 gfx::SortedDisplayURL url1(GURL(tests[i].a), std::wstring()); | 290 gfx::SortedDisplayURL url1(GURL(tests[i].a), std::wstring()); |
| 290 gfx::SortedDisplayURL url2(GURL(tests[i].b), std::wstring()); | 291 gfx::SortedDisplayURL url2(GURL(tests[i].b), std::wstring()); |
| 291 EXPECT_EQ(tests[i].compare_result, url1.Compare(url2, collator.get())); | 292 EXPECT_EQ(tests[i].compare_result, url1.Compare(url2, collator.get())); |
| 292 EXPECT_EQ(-tests[i].compare_result, url2.Compare(url1, collator.get())); | 293 EXPECT_EQ(-tests[i].compare_result, url2.Compare(url1, collator.get())); |
| 293 } | 294 } |
| 294 } | 295 } |
| OLD | NEW |