| 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/gfx/font.h" | 5 #include "app/gfx/font.h" |
| 6 #include "app/text_elider.h" | 6 #include "app/text_elider.h" |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/i18n/rtl.h" |
| 9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 10 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 const wchar_t kEllipsis[] = L"\x2026"; | 16 const wchar_t kEllipsis[] = L"\x2026"; |
| 16 | 17 |
| 17 struct Testcase { | 18 struct Testcase { |
| 18 const std::string input; | 19 const std::string input; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 {FILE_PATH_LITERAL("filename.longext"), | 172 {FILE_PATH_LITERAL("filename.longext"), |
| 172 L"file" + kEllipsisStr + L".longext"}, | 173 L"file" + kEllipsisStr + L".longext"}, |
| 173 {FILE_PATH_LITERAL("filename.middleext.longext"), | 174 {FILE_PATH_LITERAL("filename.middleext.longext"), |
| 174 L"filename.mid" + kEllipsisStr + L".longext"} | 175 L"filename.mid" + kEllipsisStr + L".longext"} |
| 175 }; | 176 }; |
| 176 | 177 |
| 177 static const gfx::Font font; | 178 static const gfx::Font font; |
| 178 for (size_t i = 0; i < arraysize(testcases); ++i) { | 179 for (size_t i = 0; i < arraysize(testcases); ++i) { |
| 179 FilePath filepath(testcases[i].input); | 180 FilePath filepath(testcases[i].input); |
| 180 std::wstring expected = testcases[i].output; | 181 std::wstring expected = testcases[i].output; |
| 181 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) | 182 if (base::i18n::IsRTL()) |
| 182 l10n_util::WrapStringWithLTRFormatting(&expected); | 183 base::i18n::WrapStringWithLTRFormatting(&expected); |
| 183 EXPECT_EQ(expected, ElideFilename(filepath, | 184 EXPECT_EQ(expected, 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 | 193 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 { "http://www.a/", "http://b/", -1 }, | 262 { "http://www.a/", "http://b/", -1 }, |
| 262 }; | 263 }; |
| 263 | 264 |
| 264 for (size_t i = 0; i < arraysize(tests); ++i) { | 265 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 265 gfx::SortedDisplayURL url1(GURL(tests[i].a), std::wstring()); | 266 gfx::SortedDisplayURL url1(GURL(tests[i].a), std::wstring()); |
| 266 gfx::SortedDisplayURL url2(GURL(tests[i].b), std::wstring()); | 267 gfx::SortedDisplayURL url2(GURL(tests[i].b), std::wstring()); |
| 267 EXPECT_EQ(tests[i].compare_result, url1.Compare(url2, collator.get())); | 268 EXPECT_EQ(tests[i].compare_result, url1.Compare(url2, collator.get())); |
| 268 EXPECT_EQ(-tests[i].compare_result, url2.Compare(url1, collator.get())); | 269 EXPECT_EQ(-tests[i].compare_result, url2.Compare(url1, collator.get())); |
| 269 } | 270 } |
| 270 } | 271 } |
| OLD | NEW |