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 "base/mac/scoped_nsobject.h"
6 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
7 #include "chrome/browser/ui/cocoa/download/download_shelf_mac.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "testing/platform_test.h"
11 // A fake implementation of DownloadShelfController. It implements only the
12 // methods that DownloadShelfMac call during the tests in this file. We get this
13 // class into the DownloadShelfMac constructor by some questionable casting --
14 // Objective C is a dynamic language, so we pretend that's ok.
16 @interface FakeDownloadShelfController : NSObject {
18 int callCountIsVisible;
21 int callCountCloseWithUserAction;
25 - (void)showDownloadShelf:(BOOL)enable
26 isUserAction:(BOOL)isUserAction;
29 @implementation FakeDownloadShelfController
36 - (void)showDownloadShelf:(BOOL)enable
37 isUserAction:(BOOL)isUserAction {
42 if (isUserAction && !enable)
43 ++callCountCloseWithUserAction;
51 class DownloadShelfMacTest : public CocoaProfileTest {
52 void SetUp() override {
53 CocoaProfileTest::SetUp();
54 shelf_controller_.reset([[FakeDownloadShelfController alloc] init]);
58 base::scoped_nsobject<FakeDownloadShelfController> shelf_controller_;
61 TEST_F(DownloadShelfMacTest, CreationDoesNotCallShow) {
62 // Also make sure the DownloadShelfMacTest constructor doesn't crash.
63 DownloadShelfMac shelf(browser(),
64 (DownloadShelfController*)shelf_controller_.get());
65 EXPECT_EQ(0, shelf_controller_.get()->callCountShow);
68 TEST_F(DownloadShelfMacTest, ForwardsShow) {
69 DownloadShelfMac shelf(browser(),
70 (DownloadShelfController*)shelf_controller_.get());
71 EXPECT_EQ(0, shelf_controller_.get()->callCountShow);
73 EXPECT_EQ(1, shelf_controller_.get()->callCountShow);
76 TEST_F(DownloadShelfMacTest, ForwardsHide) {
77 DownloadShelfMac shelf(browser(),
78 (DownloadShelfController*)shelf_controller_.get());
79 EXPECT_EQ(0, shelf_controller_.get()->callCountHide);
80 shelf.Close(DownloadShelf::AUTOMATIC);
81 EXPECT_EQ(1, shelf_controller_.get()->callCountHide);
82 EXPECT_EQ(0, shelf_controller_.get()->callCountCloseWithUserAction);
85 TEST_F(DownloadShelfMacTest, ForwardsHideWithUserAction) {
86 DownloadShelfMac shelf(browser(),
87 (DownloadShelfController*)shelf_controller_.get());
88 EXPECT_EQ(0, shelf_controller_.get()->callCountHide);
89 shelf.Close(DownloadShelf::USER_ACTION);
90 EXPECT_EQ(1, shelf_controller_.get()->callCountHide);
91 EXPECT_EQ(1, shelf_controller_.get()->callCountCloseWithUserAction);
94 TEST_F(DownloadShelfMacTest, ForwardsIsShowing) {
95 DownloadShelfMac shelf(browser(),
96 (DownloadShelfController*)shelf_controller_.get());
97 EXPECT_EQ(0, shelf_controller_.get()->callCountIsVisible);
99 EXPECT_EQ(1, shelf_controller_.get()->callCountIsVisible);