- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / download / download_shelf_mac_unittest.mm
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.
4
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"
10
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.
15
16 @interface FakeDownloadShelfController : NSObject {
17  @public
18   int callCountIsVisible;
19   int callCountShow;
20   int callCountHide;
21   int callCountCloseWithUserAction;
22 }
23
24 - (BOOL)isVisible;
25 - (void)showDownloadShelf:(BOOL)enable
26              isUserAction:(BOOL)isUserAction;
27 @end
28
29 @implementation FakeDownloadShelfController
30
31 - (BOOL)isVisible {
32   ++callCountIsVisible;
33   return YES;
34 }
35
36 - (void)showDownloadShelf:(BOOL)enable
37              isUserAction:(BOOL)isUserAction {
38   if (enable)
39     ++callCountShow;
40   else
41     ++callCountHide;
42   if (isUserAction && !enable)
43     ++callCountCloseWithUserAction;
44 }
45
46 @end
47
48
49 namespace {
50
51 class DownloadShelfMacTest : public CocoaProfileTest {
52
53   virtual void SetUp() {
54     CocoaProfileTest::SetUp();
55     shelf_controller_.reset([[FakeDownloadShelfController alloc] init]);
56   }
57
58  protected:
59   base::scoped_nsobject<FakeDownloadShelfController> shelf_controller_;
60 };
61
62 TEST_F(DownloadShelfMacTest, CreationDoesNotCallShow) {
63   // Also make sure the DownloadShelfMacTest constructor doesn't crash.
64   DownloadShelfMac shelf(browser(),
65       (DownloadShelfController*)shelf_controller_.get());
66   EXPECT_EQ(0, shelf_controller_.get()->callCountShow);
67 }
68
69 TEST_F(DownloadShelfMacTest, ForwardsShow) {
70   DownloadShelfMac shelf(browser(),
71       (DownloadShelfController*)shelf_controller_.get());
72   EXPECT_EQ(0, shelf_controller_.get()->callCountShow);
73   shelf.Show();
74   EXPECT_EQ(1, shelf_controller_.get()->callCountShow);
75 }
76
77 TEST_F(DownloadShelfMacTest, ForwardsHide) {
78   DownloadShelfMac shelf(browser(),
79       (DownloadShelfController*)shelf_controller_.get());
80   EXPECT_EQ(0, shelf_controller_.get()->callCountHide);
81   shelf.Close(DownloadShelf::AUTOMATIC);
82   EXPECT_EQ(1, shelf_controller_.get()->callCountHide);
83   EXPECT_EQ(0, shelf_controller_.get()->callCountCloseWithUserAction);
84 }
85
86 TEST_F(DownloadShelfMacTest, ForwardsHideWithUserAction) {
87   DownloadShelfMac shelf(browser(),
88       (DownloadShelfController*)shelf_controller_.get());
89   EXPECT_EQ(0, shelf_controller_.get()->callCountHide);
90   shelf.Close(DownloadShelf::USER_ACTION);
91   EXPECT_EQ(1, shelf_controller_.get()->callCountHide);
92   EXPECT_EQ(1, shelf_controller_.get()->callCountCloseWithUserAction);
93 }
94
95 TEST_F(DownloadShelfMacTest, ForwardsIsShowing) {
96   DownloadShelfMac shelf(browser(),
97       (DownloadShelfController*)shelf_controller_.get());
98   EXPECT_EQ(0, shelf_controller_.get()->callCountIsVisible);
99   shelf.IsShowing();
100   EXPECT_EQ(1, shelf_controller_.get()->callCountIsVisible);
101 }
102
103 }  // namespace