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 "content/public/test/mock_download_item.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 #include "ui/views/controls/label.h" | |
| 11 #include "ui/views/test/views_test_base.h" | |
| 12 | |
| 13 class DownloadItemViewTest : public views::ViewsTestBase { | |
| 14 public: | |
| 15 DownloadItemViewTest() { | |
| 16 base::FilePath empty_file_path; | |
| 17 EXPECT_CALL(download_, GetTargetFilePath()) | |
| 18 .WillRepeatedly(testing::ReturnRef(empty_file_path)); | |
| 19 view_.reset(new DownloadItemView(&download_, nullptr)); | |
| 20 } | |
| 21 | |
| 22 void SetDownloadWarningLabelAndResize(const base::string16& label_text) { | |
| 23 view_->dangerous_download_label_sized_ = false; | |
| 24 view_->dangerous_download_label_->SetText(label_text); | |
| 25 view_->dangerous_download_label_->SetMultiLine(true); | |
| 26 view_->dangerous_download_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 27 view_->dangerous_download_label_->SetAutoColorReadabilityEnabled(false); | |
| 28 view_->SizeLabelToMinWidth(); | |
| 29 } | |
| 30 | |
| 31 base::string16 GetLabelText() const { | |
| 32 return view_->dangerous_download_label_->text(); | |
| 33 } | |
| 34 | |
| 35 private: | |
| 36 content::MockDownloadItem download_; | |
| 37 std::unique_ptr<DownloadItemView> view_; | |
| 38 DISALLOW_COPY_AND_ASSIGN(DownloadItemViewTest); | |
|
Peter Kasting
2016/12/08 05:10:23
Nit: Suggest a blank line above this
Jialiu Lin
2016/12/08 07:47:40
Done.
| |
| 39 }; | |
| 40 | |
| 41 // For very short label that can fit in a single line, no need to do any | |
| 42 // adjustment, return it directly. | |
| 43 TEST_F(DownloadItemViewTest, SizeLabelToMinWidth_VeryShortText) { | |
| 44 base::string16 label_text = base::ASCIIToUTF16("very short label"); | |
| 45 SetDownloadWarningLabelAndResize(label_text); | |
| 46 EXPECT_EQ(label_text, GetLabelText()); | |
| 47 } | |
| 48 | |
| 49 // When we have multiple linebreaks that result in the same minimum width, we | |
| 50 // should place as much text as possible on the first line. | |
| 51 TEST_F(DownloadItemViewTest, SizeLabelToMinWidth_MoreTextOnFirstLine) { | |
| 52 base::string16 label_text = base::ASCIIToUTF16( | |
| 53 "aaaa aaaa aaaa aaaa aaaa aaaa bb aaaa aaaa aaaa aaaa aaaa aaaa"); | |
| 54 SetDownloadWarningLabelAndResize(label_text); | |
| 55 base::string16 expected_text = base::ASCIIToUTF16( | |
| 56 "aaaa aaaa aaaa aaaa aaaa aaaa bb\n" | |
| 57 "aaaa aaaa aaaa aaaa aaaa aaaa"); | |
| 58 EXPECT_EQ(expected_text, GetLabelText()); | |
| 59 } | |
| 60 | |
| 61 // If the label is a single word and extremely long, we should not break it into | |
| 62 // 2 lines. | |
| 63 TEST_F(DownloadItemViewTest, SizeLabelToMinWidth_VeryLongTextWithoutSpace) { | |
| 64 base::string16 label_text = base::ASCIIToUTF16( | |
| 65 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); | |
| 66 SetDownloadWarningLabelAndResize(label_text); | |
| 67 EXPECT_EQ(label_text, GetLabelText()); | |
| 68 } | |
| OLD | NEW |