Chromium Code Reviews| Index: chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm |
| diff --git a/chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm b/chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm |
| index 617cf3fc1a1e59c51d1d73fdefaf7624756a6e09..9eff0a2734fad5ea1a11c53be9284215d52e1c1a 100644 |
| --- a/chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm |
| +++ b/chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm |
| @@ -7,17 +7,24 @@ |
| #import <Cocoa/Cocoa.h> |
| #include "base/mac/scoped_nsobject.h" |
| -#import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| +#include "chrome/browser/infobars/infobar_service.h" |
| +#include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| +#include "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" |
| #include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h" |
| #import "chrome/browser/ui/cocoa/view_resizer_pong.h" |
| +#import "content/public/browser/web_contents.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "testing/platform_test.h" |
| namespace { |
| -class InfoBarContainerControllerTest : public CocoaTest { |
| +class InfoBarContainerControllerTest : public CocoaProfileTest { |
| virtual void SetUp() { |
|
Robert Sesek
2013/08/26 19:35:02
OVERRIDE
sail
2013/08/26 21:58:44
Done.
|
| - CocoaTest::SetUp(); |
| + CocoaProfileTest::SetUp(); |
| + web_contents_.reset(content::WebContents::Create( |
| + content::WebContents::CreateParams(profile()))); |
| + InfoBarService::CreateForWebContents(web_contents_.get()); |
| + |
| resizeDelegate_.reset([[ViewResizerPong alloc] init]); |
| ViewResizerPong *viewResizer = resizeDelegate_.get(); |
| controller_ = |
| @@ -29,12 +36,13 @@ class InfoBarContainerControllerTest : public CocoaTest { |
| virtual void TearDown() { |
|
Robert Sesek
2013/08/26 19:35:02
OVERRIDE
sail
2013/08/26 21:58:44
Done.
|
| [[controller_ view] removeFromSuperviewWithoutNeedingDisplay]; |
| [controller_ release]; |
|
Robert Sesek
2013/08/26 19:35:02
Keep this in a scoper?
sail
2013/08/26 21:58:44
Done.
|
| - CocoaTest::TearDown(); |
| + CocoaProfileTest::TearDown(); |
| } |
| public: |
| base::scoped_nsobject<ViewResizerPong> resizeDelegate_; |
| InfoBarContainerController* controller_; |
| + scoped_ptr<content::WebContents> web_contents_; |
| }; |
| TEST_VIEW(InfoBarContainerControllerTest, [controller_ view]) |
| @@ -42,46 +50,25 @@ TEST_VIEW(InfoBarContainerControllerTest, [controller_ view]) |
| TEST_F(InfoBarContainerControllerTest, BWCPong) { |
| // Call positionInfoBarsAndResize and check that |resizeDelegate_| got a |
| // resize message. |
| - [resizeDelegate_ setHeight:-1]; |
| - [controller_ positionInfoBarsAndRedraw]; |
| + [resizeDelegate_ resizeView:[controller_ view] newHeight:-1]; |
| + [controller_ positionInfoBarsAndRedraw:NO]; |
| EXPECT_NE(-1, [resizeDelegate_ height]); |
| } |
| TEST_F(InfoBarContainerControllerTest, AddAndRemoveInfoBars) { |
| NSView* view = [controller_ view]; |
| - // Add three infobars and then remove them. |
| - // After each step check to make sure we have the correct number of |
| - // infobar subviews. |
| - |
| // This delegate deletes itself when they're told their infobars have closed. |
| InfoBarDelegate* confirmDelegate = new MockConfirmInfoBarDelegate(NULL); |
| - [controller_ addInfoBar:confirmDelegate->CreateInfoBar(NULL) animate:NO]; |
| + InfoBarService* infobar_service = |
| + InfoBarService::FromWebContents(web_contents_.get()); |
| + scoped_ptr<InfoBarCocoa> infobar(static_cast<InfoBarCocoa*>( |
| + confirmDelegate->CreateInfoBar(infobar_service))); |
| + [controller_ addInfoBar:infobar.get() position:0]; |
| EXPECT_EQ(1U, [[view subviews] count]); |
| - // Just to mix things up, remove them in a different order. |
| - [controller_ closeInfoBarsForDelegate:confirmDelegate animate:NO]; |
| - EXPECT_EQ(0U, [[view subviews] count]); |
| -} |
| - |
| -TEST_F(InfoBarContainerControllerTest, RemoveAllInfoBars) { |
| - NSView* view = [controller_ view]; |
| - |
| - // Add three infobars and then remove them all. |
| - |
| - // removeAllInfobars does not close these, so we stack-allocate them so |
| - // they'll get cleaned up. |
| - MockConfirmInfoBarDelegate confirmDelegate(NULL); |
| - MockConfirmInfoBarDelegate confirmDelegate2(NULL); |
| - InfoBarDelegate* confirmDelegatePtr = &confirmDelegate; |
| - InfoBarDelegate* confirmDelegate2Ptr = &confirmDelegate2; |
| - |
| - [controller_ addInfoBar:confirmDelegatePtr->CreateInfoBar(NULL) animate:NO]; |
| - [controller_ addInfoBar:confirmDelegate2Ptr->CreateInfoBar(NULL) animate:NO]; |
| - EXPECT_EQ(2U, [[view subviews] count]); |
| - |
| - [controller_ removeAllInfoBars]; |
| + [controller_ removeInfoBar:infobar.release()]; |
| EXPECT_EQ(0U, [[view subviews] count]); |
| } |