Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1010)

Unified Diff: chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm

Issue 6926001: Replace the virtual InfoBarDelegate::InfoBarClosed() function with a non-virtual one. This is a ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm
===================================================================
--- chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm (revision 84141)
+++ chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm (working copy)
@@ -70,42 +70,86 @@
///////////////////////////////////////////////////////////////////////////
// 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_;
+ // Hopefully-obvious: If this returns true, you must not deref |delegate_|!
+ bool delegate_closed() const { return delegate_ == NULL; }
+
+ 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_;
+ // Hopefully-obvious: If this returns true, you must not deref |delegate_|!
+ bool delegate_closed() const { return delegate_ == NULL; }
+
+ 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 +160,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_closed());
+ 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_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_FALSE(delegate_closed());
+ 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_FALSE(delegate_closed());
}
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_closed());
+ 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_closed());
+ 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_FALSE(delegate_closed());
+ 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_closed());
+ 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_FALSE(delegate_closed());
+ 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_closed());
+ 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_FALSE(delegate_closed());
+ EXPECT_FALSE(delegate_->ok_clicked());
+ EXPECT_FALSE(delegate_->cancel_clicked());
+ EXPECT_TRUE(delegate_->link_clicked());
}
TEST_F(ConfirmInfoBarControllerTest, ResizeView) {

Powered by Google App Engine
This is Rietveld 408576698