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{ | |
Peter Kasting
2016/12/08 01:05:56
Nit: Space before ':' and '{'
Jialiu Lin
2016/12/08 04:51:58
Done.
| |
14 public: | |
15 DownloadItemViewTest() { | |
16 base::FilePath empty_file_path; | |
17 EXPECT_CALL(download_, GetTargetFilePath()) | |
18 .WillRepeatedly(testing::ReturnRef(empty_file_path)); | |
19 view_ = new DownloadItemView(&download_, NULL); | |
Peter Kasting
2016/12/08 01:05:56
Nit: nullptr (2 places)
Jialiu Lin
2016/12/08 04:51:58
Done.
| |
20 } | |
21 | |
22 ~DownloadItemViewTest() override { | |
23 delete view_->dangerous_download_label_; | |
Peter Kasting
2016/12/08 01:05:56
This seems extremely dangerous. |view_| should be
Jialiu Lin
2016/12/08 04:51:58
Changed DownloadItemView constructor and destructo
| |
24 delete view_; | |
Peter Kasting
2016/12/08 01:05:56
Eliminate the need for this by using a std::unique
Jialiu Lin
2016/12/08 04:51:58
Done.
| |
25 view_ = NULL; | |
26 } | |
27 | |
28 void SetDownloadWarningLabelAndResize(const base::string16& label_text) { | |
29 view_->dangerous_download_label_sized_ = false; | |
30 view_->dangerous_download_label_ = new views::Label(label_text); | |
31 view_->dangerous_download_label_->SetMultiLine(true); | |
32 view_->dangerous_download_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
33 view_->dangerous_download_label_->SetAutoColorReadabilityEnabled(false); | |
34 view_->SizeLabelToMinWidth(); | |
35 } | |
36 | |
37 base::string16 GetLabelText() { | |
Peter Kasting
2016/12/08 01:05:56
Nit: Can be const
Jialiu Lin
2016/12/08 04:51:58
Done.
| |
38 return view_->dangerous_download_label_->text(); | |
39 } | |
40 | |
41 private: | |
42 content::MockDownloadItem download_; | |
43 DownloadItemView* view_; | |
44 }; | |
Peter Kasting
2016/12/08 01:05:56
Nit: DISALLOW_COPY_AND_ASSIGN
Jialiu Lin
2016/12/08 04:51:58
Done.
| |
45 | |
46 // For very short label that can fit in a single line, no need to do any | |
47 // adjustment, return it directly. | |
48 TEST_F(DownloadItemViewTest, SizeLabelToMinWidth_VeryShortText) { | |
49 base::string16 label_text(base::ASCIIToUTF16("very short label")); | |
Peter Kasting
2016/12/08 01:05:56
Nit: Prefer = to () for initializing strings (see
Jialiu Lin
2016/12/08 04:51:58
Thanks for the pointer!
| |
50 SetDownloadWarningLabelAndResize(label_text); | |
51 EXPECT_EQ(label_text, GetLabelText()); | |
52 } | |
53 | |
54 // when we have multiple linebreaks that result in the same minimum width, we | |
Peter Kasting
2016/12/08 01:05:56
Nit: Initial caps
Jialiu Lin
2016/12/08 04:51:58
Done.
| |
55 // should place as much text on the first line. | |
Peter Kasting
2016/12/08 01:05:56
Nit: as much text -> as much text as possible
Jialiu Lin
2016/12/08 04:51:58
Done.
| |
56 TEST_F(DownloadItemViewTest, SizeLabelToMinWidth_MoreTextOnFirstLine) { | |
57 base::string16 label_text( | |
58 base::ASCIIToUTF16( | |
59 "aaaa aaaa aaaa aaaa aaaa aaaa bb aaaa aaaa aaaa aaaa aaaa aaaa")); | |
60 SetDownloadWarningLabelAndResize(label_text); | |
61 base::string16 expected_text( | |
62 base::ASCIIToUTF16("aaaa aaaa aaaa aaaa aaaa aaaa bb\n" | |
63 "aaaa aaaa aaaa aaaa aaaa aaaa")); | |
64 EXPECT_EQ(expected_text, GetLabelText()); | |
65 } | |
66 | |
67 TEST_F(DownloadItemViewTest, SizeLabelToMinWidth_MaliciousDownloadWarnings) { | |
Peter Kasting
2016/12/08 01:05:56
Nit: Comment about what specific part of the algor
Jialiu Lin
2016/12/08 04:51:58
Removed these two, and add another test to check h
| |
68 base::string16 label_text( | |
69 base::ASCIIToUTF16( | |
70 "bad.exe is malicious, and Chrome has blocked it.")); | |
71 SetDownloadWarningLabelAndResize(label_text); | |
72 base::string16 expected_text( | |
73 base::ASCIIToUTF16("bad.exe is malicious, and\n" | |
74 "Chrome has blocked it.")); | |
75 EXPECT_EQ(expected_text, GetLabelText()); | |
76 } | |
77 | |
78 TEST_F(DownloadItemViewTest, SizeLabelToMinWidth_UncommonDownloadWarnings) { | |
79 base::string16 label_text( | |
80 base::ASCIIToUTF16( | |
81 "bad.exe is not commonly downloaded and could be dangerous.")); | |
82 SetDownloadWarningLabelAndResize(label_text); | |
83 base::string16 expected_text( | |
84 base::ASCIIToUTF16("bad.exe is not commonly\n" | |
85 "downloaded and could be dangerous.")); | |
86 EXPECT_EQ(expected_text, GetLabelText()); | |
87 } | |
88 | |
89 | |
90 | |
91 | |
OLD | NEW |