| 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 "base/memory/scoped_nsobject.h" | 5 #import "base/memory/scoped_nsobject.h" |
| 6 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 6 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 7 #include "chrome/browser/ui/cocoa/download/download_shelf_mac.h" | 7 #include "chrome/browser/ui/cocoa/download/download_shelf_mac.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "testing/platform_test.h" | 9 #include "testing/platform_test.h" |
| 10 | 10 |
| 11 // A fake implementation of DownloadShelfController. It implements only the | 11 // A fake implementation of DownloadShelfController. It implements only the |
| 12 // methods that DownloadShelfMac call during the tests in this file. We get this | 12 // methods that DownloadShelfMac call during the tests in this file. We get this |
| 13 // class into the DownloadShelfMac constructor by some questionable casting -- | 13 // class into the DownloadShelfMac constructor by some questionable casting -- |
| 14 // Objective C is a dynamic language, so we pretend that's ok. | 14 // Objective C is a dynamic language, so we pretend that's ok. |
| 15 | 15 |
| 16 @interface FakeDownloadShelfController : NSObject { | 16 @interface FakeDownloadShelfController : NSObject { |
| 17 @public | 17 @public |
| 18 int callCountIsVisible; | 18 int callCountIsVisible; |
| 19 int callCountShow; | 19 int callCountShow; |
| 20 int callCountHide; | 20 int callCountHide; |
| 21 int callCountCloseWithUserAction; |
| 21 } | 22 } |
| 22 | 23 |
| 23 - (BOOL)isVisible; | 24 - (BOOL)isVisible; |
| 24 - (IBAction)show:(id)sender; | 25 - (void)showDownloadShelf:(BOOL)enable |
| 25 - (IBAction)hide:(id)sender; | 26 isUserAction:(BOOL)isUserAction; |
| 26 @end | 27 @end |
| 27 | 28 |
| 28 @implementation FakeDownloadShelfController | 29 @implementation FakeDownloadShelfController |
| 29 | 30 |
| 30 - (BOOL)isVisible { | 31 - (BOOL)isVisible { |
| 31 ++callCountIsVisible; | 32 ++callCountIsVisible; |
| 32 return YES; | 33 return YES; |
| 33 } | 34 } |
| 34 | 35 |
| 35 - (IBAction)show:(id)sender { | 36 - (void)showDownloadShelf:(BOOL)enable |
| 36 ++callCountShow; | 37 isUserAction:(BOOL)isUserAction { |
| 37 } | 38 if (enable) |
| 38 | 39 ++callCountShow; |
| 39 - (IBAction)hide:(id)sender { | 40 else |
| 40 ++callCountHide; | 41 ++callCountHide; |
| 42 if (isUserAction && !enable) |
| 43 ++callCountCloseWithUserAction; |
| 41 } | 44 } |
| 42 | 45 |
| 43 @end | 46 @end |
| 44 | 47 |
| 45 | 48 |
| 46 namespace { | 49 namespace { |
| 47 | 50 |
| 48 class DownloadShelfMacTest : public CocoaProfileTest { | 51 class DownloadShelfMacTest : public CocoaProfileTest { |
| 49 | 52 |
| 50 virtual void SetUp() { | 53 virtual void SetUp() { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 68 (DownloadShelfController*)shelf_controller_.get()); | 71 (DownloadShelfController*)shelf_controller_.get()); |
| 69 EXPECT_EQ(0, shelf_controller_.get()->callCountShow); | 72 EXPECT_EQ(0, shelf_controller_.get()->callCountShow); |
| 70 shelf.Show(); | 73 shelf.Show(); |
| 71 EXPECT_EQ(1, shelf_controller_.get()->callCountShow); | 74 EXPECT_EQ(1, shelf_controller_.get()->callCountShow); |
| 72 } | 75 } |
| 73 | 76 |
| 74 TEST_F(DownloadShelfMacTest, ForwardsHide) { | 77 TEST_F(DownloadShelfMacTest, ForwardsHide) { |
| 75 DownloadShelfMac shelf(browser(), | 78 DownloadShelfMac shelf(browser(), |
| 76 (DownloadShelfController*)shelf_controller_.get()); | 79 (DownloadShelfController*)shelf_controller_.get()); |
| 77 EXPECT_EQ(0, shelf_controller_.get()->callCountHide); | 80 EXPECT_EQ(0, shelf_controller_.get()->callCountHide); |
| 78 shelf.Close(); | 81 shelf.Close(DownloadShelf::AUTOMATIC); |
| 79 EXPECT_EQ(1, shelf_controller_.get()->callCountHide); | 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); |
| 80 } | 93 } |
| 81 | 94 |
| 82 TEST_F(DownloadShelfMacTest, ForwardsIsShowing) { | 95 TEST_F(DownloadShelfMacTest, ForwardsIsShowing) { |
| 83 DownloadShelfMac shelf(browser(), | 96 DownloadShelfMac shelf(browser(), |
| 84 (DownloadShelfController*)shelf_controller_.get()); | 97 (DownloadShelfController*)shelf_controller_.get()); |
| 85 EXPECT_EQ(0, shelf_controller_.get()->callCountIsVisible); | 98 EXPECT_EQ(0, shelf_controller_.get()->callCountIsVisible); |
| 86 shelf.IsShowing(); | 99 shelf.IsShowing(); |
| 87 EXPECT_EQ(1, shelf_controller_.get()->callCountIsVisible); | 100 EXPECT_EQ(1, shelf_controller_.get()->callCountIsVisible); |
| 88 } | 101 } |
| 89 | 102 |
| 90 } // namespace | 103 } // namespace |
| OLD | NEW |