| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import <Cocoa/Cocoa.h> | |
| 6 | |
| 7 #include "base/scoped_nsobject.h" | |
| 8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | |
| 9 #import "chrome/browser/ui/cocoa/infobar_container_controller.h" | |
| 10 #include "chrome/browser/ui/cocoa/infobar_test_helper.h" | |
| 11 #import "chrome/browser/ui/cocoa/view_resizer_pong.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 #include "testing/platform_test.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 class InfoBarContainerControllerTest : public CocoaTest { | |
| 18 virtual void SetUp() { | |
| 19 CocoaTest::SetUp(); | |
| 20 resizeDelegate_.reset([[ViewResizerPong alloc] init]); | |
| 21 ViewResizerPong *viewResizer = resizeDelegate_.get(); | |
| 22 controller_ = | |
| 23 [[InfoBarContainerController alloc] initWithResizeDelegate:viewResizer]; | |
| 24 NSView* view = [controller_ view]; | |
| 25 [[test_window() contentView] addSubview:view]; | |
| 26 } | |
| 27 | |
| 28 virtual void TearDown() { | |
| 29 [[controller_ view] removeFromSuperviewWithoutNeedingDisplay]; | |
| 30 [controller_ release]; | |
| 31 CocoaTest::TearDown(); | |
| 32 } | |
| 33 | |
| 34 public: | |
| 35 scoped_nsobject<ViewResizerPong> resizeDelegate_; | |
| 36 InfoBarContainerController* controller_; | |
| 37 }; | |
| 38 | |
| 39 TEST_VIEW(InfoBarContainerControllerTest, [controller_ view]) | |
| 40 | |
| 41 TEST_F(InfoBarContainerControllerTest, BWCPong) { | |
| 42 // Call positionInfoBarsAndResize and check that |resizeDelegate_| got a | |
| 43 // resize message. | |
| 44 [resizeDelegate_ setHeight:-1]; | |
| 45 [controller_ positionInfoBarsAndRedraw]; | |
| 46 EXPECT_NE(-1, [resizeDelegate_ height]); | |
| 47 } | |
| 48 | |
| 49 TEST_F(InfoBarContainerControllerTest, AddAndRemoveInfoBars) { | |
| 50 NSView* view = [controller_ view]; | |
| 51 | |
| 52 // Add three infobars, one of each type, and then remove them. | |
| 53 // After each step check to make sure we have the correct number of | |
| 54 // infobar subviews. | |
| 55 MockAlertInfoBarDelegate alertDelegate; | |
| 56 MockLinkInfoBarDelegate linkDelegate; | |
| 57 MockConfirmInfoBarDelegate confirmDelegate; | |
| 58 | |
| 59 [controller_ addInfoBar:&alertDelegate animate:NO]; | |
| 60 EXPECT_EQ(1U, [[view subviews] count]); | |
| 61 | |
| 62 [controller_ addInfoBar:&linkDelegate animate:NO]; | |
| 63 EXPECT_EQ(2U, [[view subviews] count]); | |
| 64 | |
| 65 [controller_ addInfoBar:&confirmDelegate animate:NO]; | |
| 66 EXPECT_EQ(3U, [[view subviews] count]); | |
| 67 | |
| 68 // Just to mix things up, remove them in a different order. | |
| 69 [controller_ closeInfoBarsForDelegate:&linkDelegate animate:NO]; | |
| 70 EXPECT_EQ(2U, [[view subviews] count]); | |
| 71 | |
| 72 [controller_ closeInfoBarsForDelegate:&confirmDelegate animate:NO]; | |
| 73 EXPECT_EQ(1U, [[view subviews] count]); | |
| 74 | |
| 75 [controller_ closeInfoBarsForDelegate:&alertDelegate animate:NO]; | |
| 76 EXPECT_EQ(0U, [[view subviews] count]); | |
| 77 } | |
| 78 | |
| 79 TEST_F(InfoBarContainerControllerTest, RemoveAllInfoBars) { | |
| 80 NSView* view = [controller_ view]; | |
| 81 | |
| 82 // Add three infobars and then remove them all. | |
| 83 MockAlertInfoBarDelegate alertDelegate; | |
| 84 MockLinkInfoBarDelegate linkDelegate; | |
| 85 MockConfirmInfoBarDelegate confirmDelegate; | |
| 86 | |
| 87 [controller_ addInfoBar:&alertDelegate animate:NO]; | |
| 88 [controller_ addInfoBar:&linkDelegate animate:NO]; | |
| 89 [controller_ addInfoBar:&confirmDelegate animate:NO]; | |
| 90 EXPECT_EQ(3U, [[view subviews] count]); | |
| 91 | |
| 92 [controller_ removeAllInfoBars]; | |
| 93 EXPECT_EQ(0U, [[view subviews] count]); | |
| 94 } | |
| 95 } // namespace | |
| OLD | NEW |