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