[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / download / download_item_cell_unittest.mm
blobef4aa543b3fe9cc1dce1b3ef22e2cdb5ee9c9d87
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 #include "base/mac/scoped_nsobject.h"
6 #include "chrome/browser/download/download_item_model.h"
7 #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 "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h"
13 using ::testing::Return;
17 using ::testing::_;
18 using ::testing::ReturnRefOfCopy;
21 class DownloadItemCellTest : public CocoaTest {
22  public:
23   DownloadItemCellTest() : CocoaTest() {
24   }
26   virtual void SetUp() {
27     CocoaTest::SetUp();
28     button_.reset([[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
29     [[test_window() contentView] addSubview:button_];
30     cell_.reset([[DownloadItemCell alloc] initTextCell:@""]);
31     [button_ setCell:cell_];
32   }
34  protected:
35   base::scoped_nsobject<DownloadItemCell> cell_;
36   base::scoped_nsobject<NSButton> button_;
38  private:
39   DISALLOW_COPY_AND_ASSIGN(DownloadItemCellTest);
42 TEST_F(DownloadItemCellTest, ToggleStatusText) {
43   EXPECT_FALSE([cell_ isStatusTextVisible]);
44   EXPECT_FLOAT_EQ(0.0, [cell_ statusTextAlpha]);
46   [cell_ showSecondaryTitle];
47   [cell_ skipVisibilityAnimation];
48   EXPECT_TRUE([cell_ isStatusTextVisible]);
49   EXPECT_FLOAT_EQ(1.0, [cell_ statusTextAlpha]);
51   [cell_ hideSecondaryTitle];
52   [cell_ skipVisibilityAnimation];
53   EXPECT_FALSE([cell_ isStatusTextVisible]);
54   EXPECT_FLOAT_EQ(0.0, [cell_ statusTextAlpha]);
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]);
72   // Draw.
73   [button_ lockFocus];
74   [cell_ drawWithFrame:[button_ bounds]
75                 inView:button_];
76   [button_ unlockFocus];
78   // Unset indeterminate state.
79   ON_CALL(item, PercentComplete()).WillByDefault(Return(0));
80   [cell_ setStateFromDownload:&model];
81   EXPECT_FALSE([cell_ indeterminateProgressTimer]);