Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 "chrome/browser/ui/views/download/download_item_view.h" | |
| 6 | |
| 7 #include "base/strings/utf_string_conversions.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 #include "ui/views/controls/label.h" | |
| 10 | |
| 11 typedef testing::Test DownloadItemViewDangerousDownloadLabelTest; | |
|
Peter Kasting
2016/12/08 21:53:53
Nit: Prefer type alias ("using") to typedef.
Jialiu Lin
2016/12/08 22:44:03
Done.
| |
| 12 | |
| 13 // For very short label that can fit in a single line, no need to do any | |
| 14 // adjustment, return it directly. | |
| 15 TEST_F(DownloadItemViewDangerousDownloadLabelTest, | |
| 16 AdjustTextAndGetSize_VeryShortText) { | |
| 17 base::string16 label_text = base::ASCIIToUTF16("very short label"); | |
|
Peter Kasting
2016/12/08 21:53:53
Nit: I suggest just "short", to minimize the chanc
Jialiu Lin
2016/12/08 22:44:03
Done.
| |
| 18 views::Label label(label_text); | |
| 19 label.SetMultiLine(true); | |
| 20 DownloadItemView::AdjustTextAndGetSize(&label); | |
| 21 EXPECT_EQ(label_text, label.text()); | |
| 22 } | |
| 23 | |
| 24 // When we have multiple linebreaks that result in the same minimum width, we | |
| 25 // should place as much text as possible on the first line. | |
| 26 TEST_F(DownloadItemViewDangerousDownloadLabelTest, | |
| 27 AdjustTextAndGetSize_MoreTextOnFirstLine) { | |
| 28 base::string16 label_text = base::ASCIIToUTF16( | |
| 29 "aaaa aaaa aaaa aaaa aaaa aaaa bb aaaa aaaa aaaa aaaa aaaa aaaa"); | |
| 30 base::string16 expected_text = base::ASCIIToUTF16( | |
| 31 "aaaa aaaa aaaa aaaa aaaa aaaa bb\n" | |
| 32 "aaaa aaaa aaaa aaaa aaaa aaaa"); | |
| 33 views::Label label(label_text); | |
| 34 label.SetMultiLine(true); | |
| 35 DownloadItemView::AdjustTextAndGetSize(&label); | |
| 36 EXPECT_EQ(expected_text, label.text()); | |
| 37 } | |
| 38 | |
| 39 // If the label is a single word and extremely long, we should not break it into | |
| 40 // 2 lines. | |
| 41 TEST_F(DownloadItemViewDangerousDownloadLabelTest, | |
| 42 AdjustTextAndGetSize_VeryLongTextWithoutSpace) { | |
| 43 base::string16 label_text = base::ASCIIToUTF16( | |
| 44 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); | |
| 45 views::Label label(label_text); | |
| 46 label.SetMultiLine(true); | |
| 47 DownloadItemView::AdjustTextAndGetSize(&label); | |
| 48 EXPECT_EQ(label_text, label.text()); | |
| 49 } | |
| OLD | NEW |