OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #import "chrome/browser/ui/cocoa/download/download_item_cell.h" |
| 6 |
5 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
6 #include "chrome/browser/download/download_item_model.h" | 8 #include "chrome/browser/download/download_item_model.h" |
7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
8 #import "chrome/browser/ui/cocoa/download/download_item_cell.h" | |
9 #include "content/public/test/mock_download_item.h" | 10 #include "content/public/test/mock_download_item.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "testing/platform_test.h" | 12 #include "testing/platform_test.h" |
12 | 13 |
| 14 using ::testing::_; |
13 using ::testing::Return; | 15 using ::testing::Return; |
14 | |
15 | |
16 | |
17 using ::testing::_; | |
18 using ::testing::ReturnRefOfCopy; | 16 using ::testing::ReturnRefOfCopy; |
19 | 17 |
20 | |
21 class DownloadItemCellTest : public CocoaTest { | 18 class DownloadItemCellTest : public CocoaTest { |
22 public: | 19 public: |
23 DownloadItemCellTest() : CocoaTest() { | 20 DownloadItemCellTest() : CocoaTest() { |
24 } | 21 } |
25 | 22 |
26 void SetUp() override { | 23 void SetUp() override { |
27 CocoaTest::SetUp(); | 24 CocoaTest::SetUp(); |
28 button_.reset([[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]); | 25 button_.reset([[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]); |
29 [[test_window() contentView] addSubview:button_]; | 26 [[test_window() contentView] addSubview:button_]; |
30 cell_.reset([[DownloadItemCell alloc] initTextCell:@""]); | 27 cell_.reset([[DownloadItemCell alloc] initTextCell:@""]); |
31 [button_ setCell:cell_]; | 28 [button_ setCell:cell_]; |
32 } | 29 } |
33 | 30 |
34 protected: | 31 protected: |
35 base::scoped_nsobject<DownloadItemCell> cell_; | 32 base::scoped_nsobject<DownloadItemCell> cell_; |
36 base::scoped_nsobject<NSButton> button_; | 33 base::scoped_nsobject<NSButton> button_; |
37 | 34 |
38 private: | 35 private: |
39 DISALLOW_COPY_AND_ASSIGN(DownloadItemCellTest); | 36 DISALLOW_COPY_AND_ASSIGN(DownloadItemCellTest); |
40 }; | 37 }; |
41 | 38 |
42 TEST_F(DownloadItemCellTest, ToggleStatusText) { | 39 TEST_F(DownloadItemCellTest, ToggleStatusText) { |
43 EXPECT_FALSE([cell_ isStatusTextVisible]); | 40 EXPECT_FALSE([cell_ isStatusTextVisible]); |
44 EXPECT_FLOAT_EQ(0.0, [cell_ statusTextAlpha]); | 41 EXPECT_FLOAT_EQ(0.0, [cell_ statusTextAlpha]); |
| 42 CGFloat titleYNoStatus = [cell_ titleY]; |
45 | 43 |
46 [cell_ showSecondaryTitle]; | 44 [cell_ showSecondaryTitle]; |
47 [cell_ skipVisibilityAnimation]; | 45 [cell_ skipVisibilityAnimation]; |
48 EXPECT_TRUE([cell_ isStatusTextVisible]); | 46 EXPECT_TRUE([cell_ isStatusTextVisible]); |
49 EXPECT_FLOAT_EQ(1.0, [cell_ statusTextAlpha]); | 47 EXPECT_FLOAT_EQ(1.0, [cell_ statusTextAlpha]); |
| 48 EXPECT_LT([cell_ titleY], titleYNoStatus); |
50 | 49 |
51 [cell_ hideSecondaryTitle]; | 50 [cell_ hideSecondaryTitle]; |
52 [cell_ skipVisibilityAnimation]; | 51 [cell_ skipVisibilityAnimation]; |
53 EXPECT_FALSE([cell_ isStatusTextVisible]); | 52 EXPECT_FALSE([cell_ isStatusTextVisible]); |
54 EXPECT_FLOAT_EQ(0.0, [cell_ statusTextAlpha]); | 53 EXPECT_FLOAT_EQ(0.0, [cell_ statusTextAlpha]); |
| 54 EXPECT_FLOAT_EQ(titleYNoStatus, [cell_ titleY]); |
55 } | 55 } |
56 | 56 |
57 TEST_F(DownloadItemCellTest, IndeterminateProgress) { | 57 TEST_F(DownloadItemCellTest, IndeterminateProgress) { |
58 testing::NiceMock<content::MockDownloadItem> item; | 58 testing::NiceMock<content::MockDownloadItem> item; |
59 ON_CALL(item, IsPaused()).WillByDefault(Return(false)); | 59 ON_CALL(item, IsPaused()).WillByDefault(Return(false)); |
60 ON_CALL(item, PercentComplete()).WillByDefault(Return(-1)); | 60 ON_CALL(item, PercentComplete()).WillByDefault(Return(-1)); |
61 ON_CALL(item, GetState()) | 61 ON_CALL(item, GetState()) |
62 .WillByDefault(Return(content::DownloadItem::IN_PROGRESS)); | 62 .WillByDefault(Return(content::DownloadItem::IN_PROGRESS)); |
63 ON_CALL(item, GetFileNameToReportUser()) | 63 ON_CALL(item, GetFileNameToReportUser()) |
64 .WillByDefault(Return(base::FilePath("foo.bar"))); | 64 .WillByDefault(Return(base::FilePath("foo.bar"))); |
65 DownloadItemModel model(&item); | 65 DownloadItemModel model(&item); |
66 | 66 |
67 // Set indeterminate state. | 67 // Set indeterminate state. |
68 EXPECT_FALSE([cell_ indeterminateProgressTimer]); | 68 EXPECT_FALSE([cell_ indeterminateProgressTimer]); |
69 [cell_ setStateFromDownload:&model]; | 69 [cell_ setStateFromDownload:&model]; |
70 EXPECT_TRUE([cell_ indeterminateProgressTimer]); | 70 EXPECT_TRUE([cell_ indeterminateProgressTimer]); |
71 | 71 |
72 // Draw. | 72 // Draw. |
73 [button_ lockFocus]; | 73 [button_ lockFocus]; |
74 [cell_ drawWithFrame:[button_ bounds] | 74 [cell_ drawWithFrame:[button_ bounds] |
75 inView:button_]; | 75 inView:button_]; |
76 [button_ unlockFocus]; | 76 [button_ unlockFocus]; |
77 | 77 |
78 // Unset indeterminate state. | 78 // Unset indeterminate state. |
79 ON_CALL(item, PercentComplete()).WillByDefault(Return(0)); | 79 ON_CALL(item, PercentComplete()).WillByDefault(Return(0)); |
80 [cell_ setStateFromDownload:&model]; | 80 [cell_ setStateFromDownload:&model]; |
81 EXPECT_FALSE([cell_ indeterminateProgressTimer]); | 81 EXPECT_FALSE([cell_ indeterminateProgressTimer]); |
82 } | 82 } |
OLD | NEW |