| 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/chrome_font.h" | 5 #include "app/gfx/chrome_font.h" |
| 6 #include "app/gfx/text_elider.h" | 6 #include "app/gfx/text_elider.h" |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 const std::wstring output; | 30 const std::wstring output; |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 struct TestData { | 33 struct TestData { |
| 34 const std::string a; | 34 const std::string a; |
| 35 const std::string b; | 35 const std::string b; |
| 36 const int compare_result; | 36 const int compare_result; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 void RunTest(Testcase* testcases, size_t num_testcases) { | 39 void RunTest(Testcase* testcases, size_t num_testcases) { |
| 40 static const ChromeFont font; | 40 static const gfx::Font font; |
| 41 for (size_t i = 0; i < num_testcases; ++i) { | 41 for (size_t i = 0; i < num_testcases; ++i) { |
| 42 const GURL url(testcases[i].input); | 42 const GURL url(testcases[i].input); |
| 43 // Should we test with non-empty language list? | 43 // Should we test with non-empty language list? |
| 44 // That's kinda redundant with net_util_unittests. | 44 // That's kinda redundant with net_util_unittests. |
| 45 EXPECT_EQ(testcases[i].output, | 45 EXPECT_EQ(testcases[i].output, |
| 46 ElideUrl(url, font, font.GetStringWidth(testcases[i].output), | 46 ElideUrl(url, font, font.GetStringWidth(testcases[i].output), |
| 47 std::wstring())); | 47 std::wstring())); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 {FILE_PATH_LITERAL("file name.longext"), | 168 {FILE_PATH_LITERAL("file name.longext"), |
| 169 L"file" + kEllipsisStr + L".longext"}, | 169 L"file" + kEllipsisStr + L".longext"}, |
| 170 {FILE_PATH_LITERAL("fil ename.longext"), | 170 {FILE_PATH_LITERAL("fil ename.longext"), |
| 171 L"fil " + kEllipsisStr + L".longext"}, | 171 L"fil " + kEllipsisStr + L".longext"}, |
| 172 {FILE_PATH_LITERAL("filename.longext"), | 172 {FILE_PATH_LITERAL("filename.longext"), |
| 173 L"file" + kEllipsisStr + L".longext"}, | 173 L"file" + kEllipsisStr + L".longext"}, |
| 174 {FILE_PATH_LITERAL("filename.middleext.longext"), | 174 {FILE_PATH_LITERAL("filename.middleext.longext"), |
| 175 L"filename.mid" + kEllipsisStr + L".longext"} | 175 L"filename.mid" + kEllipsisStr + L".longext"} |
| 176 }; | 176 }; |
| 177 | 177 |
| 178 static const ChromeFont font; | 178 static const gfx::Font font; |
| 179 for (size_t i = 0; i < arraysize(testcases); ++i) { | 179 for (size_t i = 0; i < arraysize(testcases); ++i) { |
| 180 FilePath filepath(testcases[i].input); | 180 FilePath filepath(testcases[i].input); |
| 181 EXPECT_EQ(testcases[i].output, ElideFilename(filepath, | 181 EXPECT_EQ(testcases[i].output, ElideFilename(filepath, |
| 182 font, | 182 font, |
| 183 font.GetStringWidth(testcases[i].output))); | 183 font.GetStringWidth(testcases[i].output))); |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 | 186 |
| 187 TEST(TextEliderTest, ElideTextLongStrings) { | 187 TEST(TextEliderTest, ElideTextLongStrings) { |
| 188 const std::wstring kEllipsisStr(kEllipsis); | 188 const std::wstring kEllipsisStr(kEllipsis); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 203 {data_scheme + thousand_a, | 203 {data_scheme + thousand_a, |
| 204 data_scheme + std::wstring(156, L'a') + kEllipsisStr}, | 204 data_scheme + std::wstring(156, L'a') + kEllipsisStr}, |
| 205 {data_scheme + ten_thousand_a, | 205 {data_scheme + ten_thousand_a, |
| 206 data_scheme + std::wstring(156, L'a') + kEllipsisStr}, | 206 data_scheme + std::wstring(156, L'a') + kEllipsisStr}, |
| 207 {data_scheme + hundred_thousand_a, | 207 {data_scheme + hundred_thousand_a, |
| 208 data_scheme + std::wstring(156, L'a') + kEllipsisStr}, | 208 data_scheme + std::wstring(156, L'a') + kEllipsisStr}, |
| 209 {data_scheme + million_a, | 209 {data_scheme + million_a, |
| 210 data_scheme + std::wstring(156, L'a') + kEllipsisStr}, | 210 data_scheme + std::wstring(156, L'a') + kEllipsisStr}, |
| 211 }; | 211 }; |
| 212 | 212 |
| 213 const ChromeFont font; | 213 const gfx::Font font; |
| 214 int ellipsis_width = font.GetStringWidth(kEllipsisStr); | 214 int ellipsis_width = font.GetStringWidth(kEllipsisStr); |
| 215 for (size_t i = 0; i < arraysize(testcases); ++i) { | 215 for (size_t i = 0; i < arraysize(testcases); ++i) { |
| 216 // Compare sizes rather than actual contents because if the test fails, | 216 // Compare sizes rather than actual contents because if the test fails, |
| 217 // output is rather long. | 217 // output is rather long. |
| 218 EXPECT_EQ(testcases[i].output.size(), | 218 EXPECT_EQ(testcases[i].output.size(), |
| 219 ElideText(testcases[i].input, font, | 219 ElideText(testcases[i].input, font, |
| 220 font.GetStringWidth(testcases[i].output)).size()); | 220 font.GetStringWidth(testcases[i].output)).size()); |
| 221 EXPECT_EQ(kEllipsisStr, | 221 EXPECT_EQ(kEllipsisStr, |
| 222 ElideText(testcases[i].input, font, ellipsis_width)); | 222 ElideText(testcases[i].input, font, ellipsis_width)); |
| 223 } | 223 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 { "http://www.a/", "http://b/", -1 }, | 258 { "http://www.a/", "http://b/", -1 }, |
| 259 }; | 259 }; |
| 260 | 260 |
| 261 for (size_t i = 0; i < arraysize(tests); ++i) { | 261 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 262 gfx::SortedDisplayURL url1(GURL(tests[i].a), std::wstring()); | 262 gfx::SortedDisplayURL url1(GURL(tests[i].a), std::wstring()); |
| 263 gfx::SortedDisplayURL url2(GURL(tests[i].b), std::wstring()); | 263 gfx::SortedDisplayURL url2(GURL(tests[i].b), std::wstring()); |
| 264 EXPECT_EQ(tests[i].compare_result, url1.Compare(url2, collator.get())); | 264 EXPECT_EQ(tests[i].compare_result, url1.Compare(url2, collator.get())); |
| 265 EXPECT_EQ(-tests[i].compare_result, url2.Compare(url1, collator.get())); | 265 EXPECT_EQ(-tests[i].compare_result, url2.Compare(url1, collator.get())); |
| 266 } | 266 } |
| 267 } | 267 } |
| OLD | NEW |