| 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..c40e8919bd542ec802379793540f48515349e8f3 100644
|
| --- a/chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm
|
| +++ b/chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm
|
| @@ -7,34 +7,42 @@
|
| #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 {
|
| - virtual void SetUp() {
|
| - CocoaTest::SetUp();
|
| +class InfoBarContainerControllerTest : public CocoaProfileTest {
|
| + virtual void SetUp() OVERRIDE {
|
| + 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_ =
|
| - [[InfoBarContainerController alloc] initWithResizeDelegate:viewResizer];
|
| + controller_.reset([[InfoBarContainerController alloc]
|
| + initWithResizeDelegate:viewResizer]);
|
| NSView* view = [controller_ view];
|
| [[test_window() contentView] addSubview:view];
|
| }
|
|
|
| - virtual void TearDown() {
|
| + virtual void TearDown() OVERRIDE {
|
| [[controller_ view] removeFromSuperviewWithoutNeedingDisplay];
|
| - [controller_ release];
|
| - CocoaTest::TearDown();
|
| + controller_.reset();
|
| + CocoaProfileTest::TearDown();
|
| }
|
|
|
| public:
|
| base::scoped_nsobject<ViewResizerPong> resizeDelegate_;
|
| - InfoBarContainerController* controller_;
|
| + base::scoped_nsobject<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]);
|
| }
|
|
|
|
|