| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "base/scoped_nsautorelease_pool.h" | 7 #include "base/scoped_nsautorelease_pool.h" |
| 8 #include "base/scoped_nsobject.h" | 8 #include "base/scoped_nsobject.h" |
| 9 #include "chrome/browser/cocoa/browser_test_helper.h" | 9 #include "chrome/browser/cocoa/browser_test_helper.h" |
| 10 #import "chrome/browser/cocoa/browser_window_controller.h" | |
| 11 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 10 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| 12 #import "chrome/browser/cocoa/infobar_container_controller.h" | 11 #import "chrome/browser/cocoa/infobar_container_controller.h" |
| 13 #include "chrome/browser/cocoa/infobar_test_helper.h" | 12 #include "chrome/browser/cocoa/infobar_test_helper.h" |
| 13 #import "chrome/browser/cocoa/view_resizer_pong.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 // Objective-C classes must be defined outside the namespace. | |
| 17 @interface BrowserWindowControllerPong : BrowserWindowController { | |
| 18 BOOL pong_; | |
| 19 } | |
| 20 @property(readonly) BOOL pong; | |
| 21 @end | |
| 22 | |
| 23 @implementation BrowserWindowControllerPong | |
| 24 @synthesize pong = pong_; | |
| 25 | |
| 26 - (id)initWithBrowser:(Browser*)browser { | |
| 27 if ((self = [super initWithBrowser:browser takeOwnership:NO])) { | |
| 28 pong_ = NO; | |
| 29 } | |
| 30 return self; | |
| 31 } | |
| 32 | |
| 33 - (void)infoBarResized:(float)newHeight { | |
| 34 pong_ = TRUE; | |
| 35 } | |
| 36 @end | |
| 37 | |
| 38 namespace { | 16 namespace { |
| 39 | 17 |
| 40 class InfoBarContainerControllerTest : public testing::Test { | 18 class InfoBarContainerControllerTest : public testing::Test { |
| 41 virtual void SetUp() { | 19 virtual void SetUp() { |
| 42 browserController_.reset([[BrowserWindowControllerPong alloc] | 20 resizeDelegate_.reset([[ViewResizerPong alloc] init]); |
| 43 initWithBrowser:browser_helper_.browser()]); | |
| 44 TabStripModel* model = browser_helper_.browser()->tabstrip_model(); | 21 TabStripModel* model = browser_helper_.browser()->tabstrip_model(); |
| 45 controller_.reset([[InfoBarContainerController alloc] | 22 controller_.reset([[InfoBarContainerController alloc] |
| 46 initWithTabStripModel:model | 23 initWithTabStripModel:model |
| 47 browserWindowController:browserController_]); | 24 resizeDelegate:resizeDelegate_.get()]); |
| 48 } | 25 } |
| 49 | 26 |
| 50 public: | 27 public: |
| 51 // Order is very important here. We want the controller deleted | 28 // Order is very important here. We want the controller deleted |
| 52 // before the pool, and want the pool deleted before | 29 // before the pool, and want the pool deleted before |
| 53 // BrowserTestHelper. | 30 // BrowserTestHelper. |
| 54 CocoaTestHelper cocoa_helper_; | 31 CocoaTestHelper cocoa_helper_; |
| 55 BrowserTestHelper browser_helper_; | 32 BrowserTestHelper browser_helper_; |
| 56 base::ScopedNSAutoreleasePool pool_; | 33 base::ScopedNSAutoreleasePool pool_; |
| 57 scoped_nsobject<BrowserWindowControllerPong> browserController_; | 34 scoped_nsobject<ViewResizerPong> resizeDelegate_; |
| 58 scoped_nsobject<InfoBarContainerController> controller_; | 35 scoped_nsobject<InfoBarContainerController> controller_; |
| 59 }; | 36 }; |
| 60 | 37 |
| 61 TEST_F(InfoBarContainerControllerTest, Show) { | 38 TEST_F(InfoBarContainerControllerTest, Show) { |
| 62 // Make sure the container's view is non-nil and draws without crashing. | 39 // Make sure the container's view is non-nil and draws without crashing. |
| 63 NSView* view = [controller_ view]; | 40 NSView* view = [controller_ view]; |
| 64 EXPECT_TRUE(view != nil); | 41 EXPECT_TRUE(view != nil); |
| 65 | 42 |
| 66 [cocoa_helper_.contentView() addSubview:view]; | 43 [cocoa_helper_.contentView() addSubview:view]; |
| 67 } | 44 } |
| 68 | 45 |
| 69 TEST_F(InfoBarContainerControllerTest, BWCPong) { | 46 TEST_F(InfoBarContainerControllerTest, BWCPong) { |
| 70 // Call positionInfoBarsAndResize and check that the BWC got a resize message. | 47 // Call positionInfoBarsAndResize and check that |resizeDelegate_| got a |
| 48 // resize message. |
| 49 [resizeDelegate_ setHeight:-1]; |
| 71 [controller_ positionInfoBarsAndRedraw]; | 50 [controller_ positionInfoBarsAndRedraw]; |
| 72 EXPECT_TRUE([browserController_ pong]); | 51 EXPECT_NE(-1, [resizeDelegate_ height]); |
| 73 } | 52 } |
| 74 | 53 |
| 75 TEST_F(InfoBarContainerControllerTest, AddAndRemoveInfoBars) { | 54 TEST_F(InfoBarContainerControllerTest, AddAndRemoveInfoBars) { |
| 76 NSView* view = [controller_ view]; | 55 NSView* view = [controller_ view]; |
| 77 [cocoa_helper_.contentView() addSubview:view]; | 56 [cocoa_helper_.contentView() addSubview:view]; |
| 78 | 57 |
| 79 // Add three infobars, one of each type, and then remove them. | 58 // Add three infobars, one of each type, and then remove them. |
| 80 // After each step check to make sure we have the correct number of | 59 // After each step check to make sure we have the correct number of |
| 81 // infobar subviews. | 60 // infobar subviews. |
| 82 MockAlertInfoBarDelegate alertDelegate; | 61 MockAlertInfoBarDelegate alertDelegate; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 93 |
| 115 [controller_ addInfoBar:&alertDelegate]; | 94 [controller_ addInfoBar:&alertDelegate]; |
| 116 [controller_ addInfoBar:&linkDelegate]; | 95 [controller_ addInfoBar:&linkDelegate]; |
| 117 [controller_ addInfoBar:&confirmDelegate]; | 96 [controller_ addInfoBar:&confirmDelegate]; |
| 118 EXPECT_EQ(3U, [[view subviews] count]); | 97 EXPECT_EQ(3U, [[view subviews] count]); |
| 119 | 98 |
| 120 [controller_ removeAllInfoBars]; | 99 [controller_ removeAllInfoBars]; |
| 121 EXPECT_EQ(0U, [[view subviews] count]); | 100 EXPECT_EQ(0U, [[view subviews] count]); |
| 122 } | 101 } |
| 123 } // namespace | 102 } // namespace |
| OLD | NEW |