Chromium Code Reviews| Index: chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm |
| =================================================================== |
| --- chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm (revision 83922) |
| +++ chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm (working copy) |
| @@ -70,42 +70,80 @@ |
| /////////////////////////////////////////////////////////////////////////// |
| // Test fixtures |
| -class LinkInfoBarControllerTest : public CocoaTest { |
| +class LinkInfoBarControllerTest : public CocoaTest, |
| + public MockLinkInfoBarDelegate::Owner { |
| public: |
| virtual void SetUp() { |
| CocoaTest::SetUp(); |
| + delegate_ = new MockLinkInfoBarDelegate(this); |
| controller_.reset( |
| - [[LinkInfoBarController alloc] initWithDelegate:&delegate_]); |
| + [[LinkInfoBarController alloc] initWithDelegate:delegate_]); |
| container_.reset( |
| [[InfoBarContainerTest alloc] initWithController:controller_]); |
| [controller_ setContainerController:container_]; |
| [[test_window() contentView] addSubview:[controller_ view]]; |
| + closed_delegate_link_clicked_ = false; |
| } |
| + virtual void TearDown() { |
| + if (delegate_) |
| + delete delegate_; |
| + CocoaTest::TearDown(); |
| + } |
| + |
| protected: |
| - MockLinkInfoBarDelegate delegate_; |
| + MockLinkInfoBarDelegate* delegate_; // Owns itself. |
| scoped_nsobject<id> container_; |
| scoped_nsobject<LinkInfoBarController> controller_; |
| + bool closed_delegate_link_clicked_; |
| + |
| + private: |
| + virtual void OnInfoBarDelegateClosed() { |
| + closed_delegate_link_clicked_ = delegate_->link_clicked(); |
| + delegate_ = NULL; |
| + } |
| }; |
| -class ConfirmInfoBarControllerTest : public CocoaTest { |
| +class ConfirmInfoBarControllerTest : public CocoaTest, |
| + public MockConfirmInfoBarDelegate::Owner { |
| public: |
| virtual void SetUp() { |
| CocoaTest::SetUp(); |
| + delegate_ = new MockConfirmInfoBarDelegate(this); |
| controller_.reset( |
| - [[ConfirmInfoBarController alloc] initWithDelegate:&delegate_]); |
| + [[ConfirmInfoBarController alloc] initWithDelegate:delegate_]); |
| container_.reset( |
| [[InfoBarContainerTest alloc] initWithController:controller_]); |
| [controller_ setContainerController:container_]; |
| [[test_window() contentView] addSubview:[controller_ view]]; |
| + closed_delegate_ok_clicked_ = false; |
| + closed_delegate_cancel_clicked_ = false; |
| + closed_delegate_link_clicked_ = false; |
| } |
| + virtual void TearDown() { |
| + if (delegate_) |
| + delete delegate_; |
| + CocoaTest::TearDown(); |
| + } |
| + |
| protected: |
| - MockConfirmInfoBarDelegate delegate_; |
| + MockConfirmInfoBarDelegate* delegate_; // Owns itself. |
| scoped_nsobject<id> container_; |
| scoped_nsobject<ConfirmInfoBarController> controller_; |
| + bool closed_delegate_ok_clicked_; |
| + bool closed_delegate_cancel_clicked_; |
| + bool closed_delegate_link_clicked_; |
| + |
| + private: |
| + virtual void OnInfoBarDelegateClosed() { |
| + closed_delegate_ok_clicked_ = delegate_->ok_clicked(); |
| + closed_delegate_cancel_clicked_ = delegate_->cancel_clicked(); |
| + closed_delegate_link_clicked_ = delegate_->link_clicked(); |
| + delegate_ = NULL; |
| + } |
| }; |
| @@ -116,125 +154,124 @@ |
| TEST_F(LinkInfoBarControllerTest, 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 that dismissing the infobar calls InfoBarClosed() on the delegate. |
| + // Check that dismissing the infobar deletes the delegate. |
| [controller_ dismiss:nil]; |
| - EXPECT_FALSE(delegate_.link_clicked()); |
| - EXPECT_TRUE(delegate_.closed()); |
| + ASSERT_TRUE(delegate_ == NULL); |
| + EXPECT_FALSE(closed_delegate_link_clicked_); |
| } |
| TEST_F(LinkInfoBarControllerTest, ShowAndClickLink) { |
| // Check that clicking on the link calls LinkClicked() on the |
| // delegate. It should also close the infobar. |
| [controller_ linkClicked]; |
| - EXPECT_TRUE(delegate_.link_clicked()); |
| - EXPECT_TRUE(delegate_.closed()); |
| + ASSERT_TRUE(delegate_ == NULL); |
|
Nico
2011/05/04 21:15:52
These would read better if there's a method on the
Peter Kasting
2011/05/04 22:54:56
Added "delegate_closed()".
|
| + EXPECT_TRUE(closed_delegate_link_clicked_); |
| } |
| TEST_F(LinkInfoBarControllerTest, 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]; |
| - EXPECT_TRUE(delegate_.link_clicked()); |
| - EXPECT_FALSE(delegate_.closed()); |
| + ASSERT_TRUE(delegate_ != NULL); |
| + EXPECT_TRUE(delegate_->link_clicked()); |
| } |
| TEST_F(LinkInfoBarControllerTest, DeallocController) { |
| - // Test that dealloc'ing the controller does not send an |
| - // InfoBarClosed() message to the delegate. |
| + // Test that dealloc'ing the controller does not delete the delegate. |
| controller_.reset(nil); |
| - EXPECT_FALSE(delegate_.closed()); |
| + ASSERT_TRUE(delegate_ != NULL); |
| } |
| TEST_VIEW(ConfirmInfoBarControllerTest, [controller_ view]); |
| 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, |
| base::SysNSStringToUTF8([controller_.get() labelString])); |
| - // Check that dismissing the infobar calls InfoBarClosed() on the delegate. |
| + // Check that dismissing the infobar deletes the delegate. |
| [controller_ dismiss:nil]; |
| - EXPECT_FALSE(delegate_.ok_clicked()); |
| - EXPECT_FALSE(delegate_.cancel_clicked()); |
| - EXPECT_FALSE(delegate_.link_clicked()); |
| - EXPECT_TRUE(delegate_.closed()); |
| + ASSERT_TRUE(delegate_ == NULL); |
| + EXPECT_FALSE(closed_delegate_ok_clicked_); |
| + EXPECT_FALSE(closed_delegate_cancel_clicked_); |
| + EXPECT_FALSE(closed_delegate_link_clicked_); |
| } |
| TEST_F(ConfirmInfoBarControllerTest, ShowAndClickOK) { |
| // Check that clicking the OK button calls Accept() and then closes |
| // the infobar. |
| [controller_ ok:nil]; |
| - EXPECT_TRUE(delegate_.ok_clicked()); |
| - EXPECT_FALSE(delegate_.cancel_clicked()); |
| - EXPECT_FALSE(delegate_.link_clicked()); |
| - EXPECT_TRUE(delegate_.closed()); |
| + ASSERT_TRUE(delegate_ == NULL); |
| + EXPECT_TRUE(closed_delegate_ok_clicked_); |
| + EXPECT_FALSE(closed_delegate_cancel_clicked_); |
| + EXPECT_FALSE(closed_delegate_link_clicked_); |
| } |
| 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]; |
| - EXPECT_TRUE(delegate_.ok_clicked()); |
| - EXPECT_FALSE(delegate_.cancel_clicked()); |
| - EXPECT_FALSE(delegate_.link_clicked()); |
| - EXPECT_FALSE(delegate_.closed()); |
| + ASSERT_TRUE(delegate_ != NULL); |
| + EXPECT_TRUE(delegate_->ok_clicked()); |
| + EXPECT_FALSE(delegate_->cancel_clicked()); |
| + EXPECT_FALSE(delegate_->link_clicked()); |
| } |
| TEST_F(ConfirmInfoBarControllerTest, ShowAndClickCancel) { |
| // Check that clicking the cancel button calls Cancel() and closes |
| // the infobar. |
| [controller_ cancel:nil]; |
| - EXPECT_FALSE(delegate_.ok_clicked()); |
| - EXPECT_TRUE(delegate_.cancel_clicked()); |
| - EXPECT_FALSE(delegate_.link_clicked()); |
| - EXPECT_TRUE(delegate_.closed()); |
| + ASSERT_TRUE(delegate_ == NULL); |
| + EXPECT_FALSE(closed_delegate_ok_clicked_); |
| + EXPECT_TRUE(closed_delegate_cancel_clicked_); |
| + EXPECT_FALSE(closed_delegate_link_clicked_); |
| } |
| 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]; |
| - EXPECT_FALSE(delegate_.ok_clicked()); |
| - EXPECT_TRUE(delegate_.cancel_clicked()); |
| - EXPECT_FALSE(delegate_.link_clicked()); |
| - EXPECT_FALSE(delegate_.closed()); |
| + ASSERT_TRUE(delegate_ != NULL); |
| + EXPECT_FALSE(delegate_->ok_clicked()); |
| + EXPECT_TRUE(delegate_->cancel_clicked()); |
| + EXPECT_FALSE(delegate_->link_clicked()); |
| } |
| TEST_F(ConfirmInfoBarControllerTest, ShowAndClickLink) { |
| // Check that clicking on the link calls LinkClicked() on the |
| // delegate. It should also close the infobar. |
| [controller_ linkClicked]; |
| - EXPECT_FALSE(delegate_.ok_clicked()); |
| - EXPECT_FALSE(delegate_.cancel_clicked()); |
| - EXPECT_TRUE(delegate_.link_clicked()); |
| - EXPECT_TRUE(delegate_.closed()); |
| + ASSERT_TRUE(delegate_ == NULL); |
| + EXPECT_FALSE(closed_delegate_ok_clicked_); |
| + EXPECT_FALSE(closed_delegate_cancel_clicked_); |
| + EXPECT_TRUE(closed_delegate_link_clicked_); |
| } |
| 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]; |
| - EXPECT_FALSE(delegate_.ok_clicked()); |
| - EXPECT_FALSE(delegate_.cancel_clicked()); |
| - EXPECT_TRUE(delegate_.link_clicked()); |
| - EXPECT_FALSE(delegate_.closed()); |
| + ASSERT_TRUE(delegate_ != NULL); |
| + EXPECT_FALSE(delegate_->ok_clicked()); |
| + EXPECT_FALSE(delegate_->cancel_clicked()); |
| + EXPECT_TRUE(delegate_->link_clicked()); |
| } |
| TEST_F(ConfirmInfoBarControllerTest, ResizeView) { |