| 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "base/memory/scoped_nsobject.h" | 7 #include "base/memory/scoped_nsobject.h" |
| 8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 9 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" | 9 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
| 10 #include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h" | 10 #include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h" |
| 11 #include "chrome/browser/ui/cocoa/infobars/mock_link_infobar_delegate.h" | |
| 12 #import "chrome/browser/ui/cocoa/view_resizer_pong.h" | 11 #import "chrome/browser/ui/cocoa/view_resizer_pong.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "testing/platform_test.h" | 13 #include "testing/platform_test.h" |
| 15 | 14 |
| 16 namespace { | 15 namespace { |
| 17 | 16 |
| 18 class InfoBarContainerControllerTest : public CocoaTest { | 17 class InfoBarContainerControllerTest : public CocoaTest { |
| 19 virtual void SetUp() { | 18 virtual void SetUp() { |
| 20 CocoaTest::SetUp(); | 19 CocoaTest::SetUp(); |
| 21 resizeDelegate_.reset([[ViewResizerPong alloc] init]); | 20 resizeDelegate_.reset([[ViewResizerPong alloc] init]); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 47 EXPECT_NE(-1, [resizeDelegate_ height]); | 46 EXPECT_NE(-1, [resizeDelegate_ height]); |
| 48 } | 47 } |
| 49 | 48 |
| 50 TEST_F(InfoBarContainerControllerTest, AddAndRemoveInfoBars) { | 49 TEST_F(InfoBarContainerControllerTest, AddAndRemoveInfoBars) { |
| 51 NSView* view = [controller_ view]; | 50 NSView* view = [controller_ view]; |
| 52 | 51 |
| 53 // Add three infobars and then remove them. | 52 // Add three infobars and then remove them. |
| 54 // After each step check to make sure we have the correct number of | 53 // After each step check to make sure we have the correct number of |
| 55 // infobar subviews. | 54 // infobar subviews. |
| 56 | 55 |
| 57 // These delegates delete themselves when they're told their infobars have | 56 // This delegate deletes itself when they're told their infobars have closed. |
| 58 // closed. | |
| 59 InfoBarDelegate* linkDelegate = new MockLinkInfoBarDelegate(NULL); | |
| 60 InfoBarDelegate* linkDelegate2 = new MockLinkInfoBarDelegate(NULL); | |
| 61 InfoBarDelegate* confirmDelegate = new MockConfirmInfoBarDelegate(NULL); | 57 InfoBarDelegate* confirmDelegate = new MockConfirmInfoBarDelegate(NULL); |
| 62 | 58 |
| 63 [controller_ addInfoBar:linkDelegate->CreateInfoBar(NULL) animate:NO]; | 59 [controller_ addInfoBar:confirmDelegate->CreateInfoBar(NULL) animate:NO]; |
| 64 EXPECT_EQ(1U, [[view subviews] count]); | 60 EXPECT_EQ(1U, [[view subviews] count]); |
| 65 | 61 |
| 66 [controller_ addInfoBar:confirmDelegate->CreateInfoBar(NULL) animate:NO]; | |
| 67 EXPECT_EQ(2U, [[view subviews] count]); | |
| 68 | |
| 69 [controller_ addInfoBar:linkDelegate2->CreateInfoBar(NULL) animate:NO]; | |
| 70 EXPECT_EQ(3U, [[view subviews] count]); | |
| 71 | |
| 72 // Just to mix things up, remove them in a different order. | 62 // Just to mix things up, remove them in a different order. |
| 73 [controller_ closeInfoBarsForDelegate:confirmDelegate animate:NO]; | 63 [controller_ closeInfoBarsForDelegate:confirmDelegate animate:NO]; |
| 74 EXPECT_EQ(2U, [[view subviews] count]); | |
| 75 | |
| 76 [controller_ closeInfoBarsForDelegate:linkDelegate animate:NO]; | |
| 77 EXPECT_EQ(1U, [[view subviews] count]); | |
| 78 | |
| 79 [controller_ closeInfoBarsForDelegate:linkDelegate2 animate:NO]; | |
| 80 EXPECT_EQ(0U, [[view subviews] count]); | 64 EXPECT_EQ(0U, [[view subviews] count]); |
| 81 } | 65 } |
| 82 | 66 |
| 83 TEST_F(InfoBarContainerControllerTest, RemoveAllInfoBars) { | 67 TEST_F(InfoBarContainerControllerTest, RemoveAllInfoBars) { |
| 84 NSView* view = [controller_ view]; | 68 NSView* view = [controller_ view]; |
| 85 | 69 |
| 86 // Add three infobars and then remove them all. | 70 // Add three infobars and then remove them all. |
| 87 | 71 |
| 88 // removeAllInfobars does not close these, so we stack-allocate them so | 72 // removeAllInfobars does not close these, so we stack-allocate them so |
| 89 // they'll get cleaned up. | 73 // they'll get cleaned up. |
| 90 MockLinkInfoBarDelegate linkDelegate(NULL); | |
| 91 MockConfirmInfoBarDelegate confirmDelegate(NULL); | 74 MockConfirmInfoBarDelegate confirmDelegate(NULL); |
| 92 MockConfirmInfoBarDelegate confirmDelegate2(NULL); | 75 MockConfirmInfoBarDelegate confirmDelegate2(NULL); |
| 93 InfoBarDelegate* linkDelegatePtr = &linkDelegate; | |
| 94 InfoBarDelegate* confirmDelegatePtr = &confirmDelegate; | 76 InfoBarDelegate* confirmDelegatePtr = &confirmDelegate; |
| 95 InfoBarDelegate* confirmDelegate2Ptr = &confirmDelegate2; | 77 InfoBarDelegate* confirmDelegate2Ptr = &confirmDelegate2; |
| 96 | 78 |
| 97 [controller_ addInfoBar:linkDelegatePtr->CreateInfoBar(NULL) animate:NO]; | |
| 98 [controller_ addInfoBar:confirmDelegatePtr->CreateInfoBar(NULL) animate:NO]; | 79 [controller_ addInfoBar:confirmDelegatePtr->CreateInfoBar(NULL) animate:NO]; |
| 99 [controller_ addInfoBar:confirmDelegate2Ptr->CreateInfoBar(NULL) animate:NO]; | 80 [controller_ addInfoBar:confirmDelegate2Ptr->CreateInfoBar(NULL) animate:NO]; |
| 100 EXPECT_EQ(3U, [[view subviews] count]); | 81 EXPECT_EQ(2U, [[view subviews] count]); |
| 101 | 82 |
| 102 [controller_ removeAllInfoBars]; | 83 [controller_ removeAllInfoBars]; |
| 103 EXPECT_EQ(0U, [[view subviews] count]); | 84 EXPECT_EQ(0U, [[view subviews] count]); |
| 104 } | 85 } |
| 86 |
| 105 } // namespace | 87 } // namespace |
| OLD | NEW |