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 #include "ui/views/test/views_test_base.h" |
| 11 |
| 12 using DownloadItemViewDangerousDownloadLabelTest = views::ViewsTestBase; |
| 13 |
| 14 TEST_F(DownloadItemViewDangerousDownloadLabelTest, AdjustTextAndGetSize) { |
| 15 // For very short label that can fit in a single line, no need to do any |
| 16 // adjustment, return it directly. |
| 17 base::string16 label_text = base::ASCIIToUTF16("short"); |
| 18 views::Label label(label_text); |
| 19 label.SetMultiLine(true); |
| 20 DownloadItemView::AdjustTextAndGetSize(&label); |
| 21 EXPECT_EQ(label_text, label.text()); |
| 22 |
| 23 // When we have multiple linebreaks that result in the same minimum width, we |
| 24 // should place as much text as possible on the first line. |
| 25 label_text = base::ASCIIToUTF16( |
| 26 "aaaa aaaa aaaa aaaa aaaa aaaa bb aaaa aaaa aaaa aaaa aaaa aaaa"); |
| 27 base::string16 expected_text = base::ASCIIToUTF16( |
| 28 "aaaa aaaa aaaa aaaa aaaa aaaa bb\n" |
| 29 "aaaa aaaa aaaa aaaa aaaa aaaa"); |
| 30 label.SetText(label_text); |
| 31 DownloadItemView::AdjustTextAndGetSize(&label); |
| 32 EXPECT_EQ(expected_text, label.text()); |
| 33 |
| 34 // If the label is a single word and extremely long, we should not break it |
| 35 // into 2 lines. |
| 36 label_text = base::ASCIIToUTF16( |
| 37 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); |
| 38 label.SetText(label_text); |
| 39 DownloadItemView::AdjustTextAndGetSize(&label); |
| 40 EXPECT_EQ(label_text, label.text()); |
| 41 } |
OLD | NEW |