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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/download/download_item_cell.h"
7 #include "base/mac/scoped_nsobject.h"
8 #include "chrome/browser/download/download_item_model.h"
9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
10 #include "content/public/test/mock_download_item.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/platform_test.h"
15 using ::testing::Return;
16 using ::testing::ReturnRefOfCopy;
18 class DownloadItemCellTest : public CocoaTest {
20 DownloadItemCellTest() : CocoaTest() {
23 void SetUp() override {
25 button_.reset([[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
26 [[test_window() contentView] addSubview:button_];
27 cell_.reset([[DownloadItemCell alloc] initTextCell:@""]);
28 [button_ setCell:cell_];
32 base::scoped_nsobject<DownloadItemCell> cell_;
33 base::scoped_nsobject<NSButton> button_;
36 DISALLOW_COPY_AND_ASSIGN(DownloadItemCellTest);
39 TEST_F(DownloadItemCellTest, ToggleStatusText) {
40 EXPECT_FALSE([cell_ isStatusTextVisible]);
41 EXPECT_FLOAT_EQ(0.0, [cell_ statusTextAlpha]);
42 CGFloat titleYNoStatus = [cell_ titleY];
44 [cell_ showSecondaryTitle];
45 [cell_ skipVisibilityAnimation];
46 EXPECT_TRUE([cell_ isStatusTextVisible]);
47 EXPECT_FLOAT_EQ(1.0, [cell_ statusTextAlpha]);
48 EXPECT_LT([cell_ titleY], titleYNoStatus);
50 [cell_ hideSecondaryTitle];
51 [cell_ skipVisibilityAnimation];
52 EXPECT_FALSE([cell_ isStatusTextVisible]);
53 EXPECT_FLOAT_EQ(0.0, [cell_ statusTextAlpha]);
54 EXPECT_FLOAT_EQ(titleYNoStatus, [cell_ titleY]);
57 TEST_F(DownloadItemCellTest, IndeterminateProgress) {
58 testing::NiceMock<content::MockDownloadItem> item;
59 ON_CALL(item, IsPaused()).WillByDefault(Return(false));
60 ON_CALL(item, PercentComplete()).WillByDefault(Return(-1));
61 ON_CALL(item, GetState())
62 .WillByDefault(Return(content::DownloadItem::IN_PROGRESS));
63 ON_CALL(item, GetFileNameToReportUser())
64 .WillByDefault(Return(base::FilePath("foo.bar")));
65 DownloadItemModel model(&item);
67 // Set indeterminate state.
68 EXPECT_FALSE([cell_ indeterminateProgressTimer]);
69 [cell_ setStateFromDownload:&model];
70 EXPECT_TRUE([cell_ indeterminateProgressTimer]);
74 [cell_ drawWithFrame:[button_ bounds]
76 [button_ unlockFocus];
78 // Unset indeterminate state.
79 ON_CALL(item, PercentComplete()).WillByDefault(Return(0));
80 [cell_ setStateFromDownload:&model];
81 EXPECT_FALSE([cell_ indeterminateProgressTimer]);