| Index: chrome/browser/ui/cocoa/infobars/confirm_infobar_controller_unittest.mm
|
| ===================================================================
|
| --- chrome/browser/ui/cocoa/infobars/confirm_infobar_controller_unittest.mm (revision 238220)
|
| +++ chrome/browser/ui/cocoa/infobars/confirm_infobar_controller_unittest.mm (working copy)
|
| @@ -89,14 +89,15 @@
|
| CocoaProfileTest::SetUp();
|
| web_contents_.reset(
|
| WebContents::Create(WebContents::CreateParams(profile())));
|
| - InfoBarService::CreateForWebContents(web_contents_.get());
|
| + InfoBarService::CreateForWebContents(web_contents_.get());
|
|
|
| - delegate_ = new MockConfirmInfoBarDelegate(this);
|
| - infobar_.reset(new InfoBarCocoa(
|
| - InfoBarService::FromWebContents(web_contents_.get()), delegate_));
|
| + scoped_ptr<InfoBarDelegate> delegate(
|
| + new MockConfirmInfoBarDelegate(this));
|
| + infobar_ = new InfoBarCocoa(delegate.Pass());
|
| + infobar_->SetOwner(InfoBarService::FromWebContents(web_contents_.get()));
|
|
|
| controller_.reset([[TestConfirmInfoBarController alloc]
|
| - initWithInfoBar:infobar_.get()]);
|
| + initWithInfoBar:infobar_]);
|
| infobar_->set_controller(controller_);
|
|
|
| container_.reset(
|
| @@ -106,20 +107,22 @@
|
| closed_delegate_ok_clicked_ = false;
|
| closed_delegate_cancel_clicked_ = false;
|
| closed_delegate_link_clicked_ = false;
|
| + delegate_closed_ = false;
|
| }
|
|
|
| virtual void TearDown() OVERRIDE {
|
| [controller_ removeSelf];
|
| - if (delegate_)
|
| - delete delegate_;
|
| CocoaProfileTest::TearDown();
|
| }
|
|
|
| protected:
|
| - // Hopefully-obvious: If this returns true, you must not deref |delegate_|!
|
| - bool delegate_closed() const { return delegate_ == NULL; }
|
| + // True if delegate is closed.
|
| + bool delegate_closed() const { return delegate_closed_; }
|
|
|
| - MockConfirmInfoBarDelegate* delegate_; // Owns itself.
|
| + MockConfirmInfoBarDelegate* delegate() const {
|
| + return static_cast<MockConfirmInfoBarDelegate*>(infobar_->delegate());
|
| + }
|
| +
|
| base::scoped_nsobject<id> container_;
|
| base::scoped_nsobject<ConfirmInfoBarController> controller_;
|
| bool closed_delegate_ok_clicked_;
|
| @@ -128,14 +131,16 @@
|
|
|
| private:
|
| virtual void OnInfoBarDelegateClosed() OVERRIDE {
|
| - closed_delegate_ok_clicked_ = delegate_->ok_clicked();
|
| - closed_delegate_cancel_clicked_ = delegate_->cancel_clicked();
|
| - closed_delegate_link_clicked_ = delegate_->link_clicked();
|
| - delegate_ = NULL;
|
| + closed_delegate_ok_clicked_ = delegate()->ok_clicked();
|
| + closed_delegate_cancel_clicked_ = delegate()->cancel_clicked();
|
| + closed_delegate_link_clicked_ = delegate()->link_clicked();
|
| + delegate_closed_ = true;
|
| + controller_.reset();
|
| }
|
|
|
| scoped_ptr<WebContents> web_contents_;
|
| - scoped_ptr<InfoBarCocoa> infobar_;
|
| + InfoBarCocoa* infobar_; // Weak, will delete itself.
|
| + bool delegate_closed_;
|
| };
|
|
|
|
|
| @@ -143,9 +148,9 @@
|
|
|
| TEST_F(ConfirmInfoBarControllerTest, ShowAndDismiss) {
|
| // Make sure someone looked at the message, link, and icon.
|
| - EXPECT_TRUE(delegate_->message_text_accessed());
|
| - EXPECT_TRUE(delegate_->link_text_accessed());
|
| - EXPECT_TRUE(delegate_->icon_accessed());
|
| + EXPECT_TRUE(delegate()->message_text_accessed());
|
| + EXPECT_TRUE(delegate()->link_text_accessed());
|
| + EXPECT_TRUE(delegate()->icon_accessed());
|
|
|
| // Check to make sure the infobar message was set properly.
|
| EXPECT_EQ(MockConfirmInfoBarDelegate::kMessage,
|
| @@ -170,15 +175,15 @@
|
| }
|
|
|
| TEST_F(ConfirmInfoBarControllerTest, ShowAndClickOKWithoutClosing) {
|
| - delegate_->set_dont_close_on_action();
|
| + delegate()->set_dont_close_on_action();
|
|
|
| // Check that clicking the OK button calls Accept() but does not close
|
| // the infobar.
|
| [controller_ ok:nil];
|
| ASSERT_FALSE(delegate_closed());
|
| - EXPECT_TRUE(delegate_->ok_clicked());
|
| - EXPECT_FALSE(delegate_->cancel_clicked());
|
| - EXPECT_FALSE(delegate_->link_clicked());
|
| + EXPECT_TRUE(delegate()->ok_clicked());
|
| + EXPECT_FALSE(delegate()->cancel_clicked());
|
| + EXPECT_FALSE(delegate()->link_clicked());
|
| }
|
|
|
| TEST_F(ConfirmInfoBarControllerTest, ShowAndClickCancel) {
|
| @@ -192,15 +197,15 @@
|
| }
|
|
|
| TEST_F(ConfirmInfoBarControllerTest, ShowAndClickCancelWithoutClosing) {
|
| - delegate_->set_dont_close_on_action();
|
| + delegate()->set_dont_close_on_action();
|
|
|
| // Check that clicking the cancel button calls Cancel() but does not close
|
| // the infobar.
|
| [controller_ cancel:nil];
|
| ASSERT_FALSE(delegate_closed());
|
| - EXPECT_FALSE(delegate_->ok_clicked());
|
| - EXPECT_TRUE(delegate_->cancel_clicked());
|
| - EXPECT_FALSE(delegate_->link_clicked());
|
| + EXPECT_FALSE(delegate()->ok_clicked());
|
| + EXPECT_TRUE(delegate()->cancel_clicked());
|
| + EXPECT_FALSE(delegate()->link_clicked());
|
| }
|
|
|
| TEST_F(ConfirmInfoBarControllerTest, ShowAndClickLink) {
|
| @@ -214,15 +219,15 @@
|
| }
|
|
|
| TEST_F(ConfirmInfoBarControllerTest, ShowAndClickLinkWithoutClosing) {
|
| - delegate_->set_dont_close_on_action();
|
| + delegate()->set_dont_close_on_action();
|
|
|
| // Check that clicking on the link calls LinkClicked() on the
|
| // delegate. It should not close the infobar.
|
| [controller_ linkClicked];
|
| ASSERT_FALSE(delegate_closed());
|
| - EXPECT_FALSE(delegate_->ok_clicked());
|
| - EXPECT_FALSE(delegate_->cancel_clicked());
|
| - EXPECT_TRUE(delegate_->link_clicked());
|
| + EXPECT_FALSE(delegate()->ok_clicked());
|
| + EXPECT_FALSE(delegate()->cancel_clicked());
|
| + EXPECT_TRUE(delegate()->link_clicked());
|
| }
|
|
|
| TEST_F(ConfirmInfoBarControllerTest, ResizeView) {
|
|
|