Chromium Code Reviews| Index: chrome/browser/ui/views/download/download_item_view_unittest.cc |
| diff --git a/chrome/browser/ui/views/download/download_item_view_unittest.cc b/chrome/browser/ui/views/download/download_item_view_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e1ac39b700c12be2b56aebb7d12e7a0cce3b6dd8 |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/download/download_item_view_unittest.cc |
| @@ -0,0 +1,68 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/views/download/download_item_view.h" |
| + |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "content/public/test/mock_download_item.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/views/controls/label.h" |
| +#include "ui/views/test/views_test_base.h" |
| + |
| +class DownloadItemViewTest : public views::ViewsTestBase { |
| + public: |
| + DownloadItemViewTest() { |
| + base::FilePath empty_file_path; |
| + EXPECT_CALL(download_, GetTargetFilePath()) |
| + .WillRepeatedly(testing::ReturnRef(empty_file_path)); |
| + view_.reset(new DownloadItemView(&download_, nullptr)); |
| + } |
| + |
| + void SetDownloadWarningLabelAndResize(const base::string16& label_text) { |
| + view_->dangerous_download_label_sized_ = false; |
| + view_->dangerous_download_label_->SetText(label_text); |
| + view_->dangerous_download_label_->SetMultiLine(true); |
| + view_->dangerous_download_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + view_->dangerous_download_label_->SetAutoColorReadabilityEnabled(false); |
| + view_->SizeLabelToMinWidth(); |
| + } |
| + |
| + base::string16 GetLabelText() const { |
| + return view_->dangerous_download_label_->text(); |
| + } |
| + |
| + private: |
| + content::MockDownloadItem download_; |
| + std::unique_ptr<DownloadItemView> view_; |
| + 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.
|
| +}; |
| + |
| +// For very short label that can fit in a single line, no need to do any |
| +// adjustment, return it directly. |
| +TEST_F(DownloadItemViewTest, SizeLabelToMinWidth_VeryShortText) { |
| + base::string16 label_text = base::ASCIIToUTF16("very short label"); |
| + SetDownloadWarningLabelAndResize(label_text); |
| + EXPECT_EQ(label_text, GetLabelText()); |
| +} |
| + |
| +// When we have multiple linebreaks that result in the same minimum width, we |
| +// should place as much text as possible on the first line. |
| +TEST_F(DownloadItemViewTest, SizeLabelToMinWidth_MoreTextOnFirstLine) { |
| + base::string16 label_text = base::ASCIIToUTF16( |
| + "aaaa aaaa aaaa aaaa aaaa aaaa bb aaaa aaaa aaaa aaaa aaaa aaaa"); |
| + SetDownloadWarningLabelAndResize(label_text); |
| + base::string16 expected_text = base::ASCIIToUTF16( |
| + "aaaa aaaa aaaa aaaa aaaa aaaa bb\n" |
| + "aaaa aaaa aaaa aaaa aaaa aaaa"); |
| + EXPECT_EQ(expected_text, GetLabelText()); |
| +} |
| + |
| +// If the label is a single word and extremely long, we should not break it into |
| +// 2 lines. |
| +TEST_F(DownloadItemViewTest, SizeLabelToMinWidth_VeryLongTextWithoutSpace) { |
| + base::string16 label_text = base::ASCIIToUTF16( |
| + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); |
| + SetDownloadWarningLabelAndResize(label_text); |
| + EXPECT_EQ(label_text, GetLabelText()); |
| +} |