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

Side by Side Diff: chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm

Issue 7981045: Make infobars ignore button clicks when closing. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "base/memory/scoped_nsobject.h" 7 #include "base/memory/scoped_nsobject.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
10 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 10 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 [self close]; 83 [self close];
84 } 84 }
85 @end 85 @end
86 86
87 namespace { 87 namespace {
88 88
89 /////////////////////////////////////////////////////////////////////////// 89 ///////////////////////////////////////////////////////////////////////////
90 // Test fixtures 90 // Test fixtures
91 91
92 class LinkInfoBarControllerTest : public CocoaTest, 92 class LinkInfoBarControllerTest : public CocoaTest,
93 public TabContentsWrapperTestHarness,
93 public MockLinkInfoBarDelegate::Owner { 94 public MockLinkInfoBarDelegate::Owner {
94 public: 95 public:
96 LinkInfoBarControllerTest() {
97 contents_wrapper()->infobar_tab_helper()->set_infobars_enabled(false);
98 }
95 virtual void SetUp() { 99 virtual void SetUp() {
96 CocoaTest::SetUp(); 100 CocoaTest::SetUp();
97 101
98 delegate_ = new MockLinkInfoBarDelegate(this); 102 delegate_ = new MockLinkInfoBarDelegate(this);
99 controller_.reset( 103 controller_.reset([[TestLinkInfoBarController alloc]
100 [[TestLinkInfoBarController alloc] initWithDelegate:delegate_ 104 initWithDelegate:delegate_
101 owner:NULL]); 105 owner:contents_wrapper()]);
102 container_.reset( 106 container_.reset(
103 [[InfoBarContainerTest alloc] initWithController:controller_]); 107 [[InfoBarContainerTest alloc] initWithController:controller_]);
104 [controller_ setContainerController:container_]; 108 [controller_ setContainerController:container_];
105 [[test_window() contentView] addSubview:[controller_ view]]; 109 [[test_window() contentView] addSubview:[controller_ view]];
106 closed_delegate_link_clicked_ = false; 110 closed_delegate_link_clicked_ = false;
107 } 111 }
108 112
109 virtual void TearDown() { 113 virtual void TearDown() {
110 if (delegate_) 114 if (delegate_)
111 delete delegate_; 115 delete delegate_;
(...skipping 10 matching lines...) Expand all
122 bool closed_delegate_link_clicked_; 126 bool closed_delegate_link_clicked_;
123 127
124 private: 128 private:
125 virtual void OnInfoBarDelegateClosed() { 129 virtual void OnInfoBarDelegateClosed() {
126 closed_delegate_link_clicked_ = delegate_->link_clicked(); 130 closed_delegate_link_clicked_ = delegate_->link_clicked();
127 delegate_ = NULL; 131 delegate_ = NULL;
128 } 132 }
129 }; 133 };
130 134
131 class ConfirmInfoBarControllerTest : public CocoaTest, 135 class ConfirmInfoBarControllerTest : public CocoaTest,
136 public TabContentsWrapperTestHarness,
132 public MockConfirmInfoBarDelegate::Owner { 137 public MockConfirmInfoBarDelegate::Owner {
133 public: 138 public:
139 ConfirmInfoBarControllerTest() {
140 contents_wrapper()->infobar_tab_helper()->set_infobars_enabled(false);
141 }
134 virtual void SetUp() { 142 virtual void SetUp() {
135 CocoaTest::SetUp(); 143 CocoaTest::SetUp();
136 144
137 delegate_ = new MockConfirmInfoBarDelegate(this); 145 delegate_ = new MockConfirmInfoBarDelegate(this);
138 controller_.reset( 146 controller_.reset([[TestConfirmInfoBarController alloc]
139 [[TestConfirmInfoBarController alloc] initWithDelegate:delegate_ 147 initWithDelegate:delegate_
140 owner:NULL]); 148 owner:contents_wrapper()]);
141 container_.reset( 149 container_.reset(
142 [[InfoBarContainerTest alloc] initWithController:controller_]); 150 [[InfoBarContainerTest alloc] initWithController:controller_]);
143 [controller_ setContainerController:container_]; 151 [controller_ setContainerController:container_];
144 [[test_window() contentView] addSubview:[controller_ view]]; 152 [[test_window() contentView] addSubview:[controller_ view]];
145 closed_delegate_ok_clicked_ = false; 153 closed_delegate_ok_clicked_ = false;
146 closed_delegate_cancel_clicked_ = false; 154 closed_delegate_cancel_clicked_ = false;
147 closed_delegate_link_clicked_ = false; 155 closed_delegate_link_clicked_ = false;
148 } 156 }
149 157
150 virtual void TearDown() { 158 virtual void TearDown() {
(...skipping 28 matching lines...) Expand all
179 187
180 TEST_VIEW(LinkInfoBarControllerTest, [controller_ view]); 188 TEST_VIEW(LinkInfoBarControllerTest, [controller_ view]);
181 189
182 TEST_F(LinkInfoBarControllerTest, ShowAndDismiss) { 190 TEST_F(LinkInfoBarControllerTest, ShowAndDismiss) {
183 // Make sure someone looked at the message, link, and icon. 191 // Make sure someone looked at the message, link, and icon.
184 EXPECT_TRUE(delegate_->message_text_accessed()); 192 EXPECT_TRUE(delegate_->message_text_accessed());
185 EXPECT_TRUE(delegate_->link_text_accessed()); 193 EXPECT_TRUE(delegate_->link_text_accessed());
186 EXPECT_TRUE(delegate_->icon_accessed()); 194 EXPECT_TRUE(delegate_->icon_accessed());
187 195
188 // Check that dismissing the infobar deletes the delegate. 196 // Check that dismissing the infobar deletes the delegate.
189 [controller_ dismiss:nil]; 197 [controller_ removeSelf];
190 ASSERT_TRUE(delegate_closed()); 198 ASSERT_TRUE(delegate_closed());
191 EXPECT_FALSE(closed_delegate_link_clicked_); 199 EXPECT_FALSE(closed_delegate_link_clicked_);
192 } 200 }
193 201
194 TEST_F(LinkInfoBarControllerTest, ShowAndClickLink) { 202 TEST_F(LinkInfoBarControllerTest, ShowAndClickLink) {
195 // Check that clicking on the link calls LinkClicked() on the 203 // Check that clicking on the link calls LinkClicked() on the
196 // delegate. It should also close the infobar. 204 // delegate. It should also close the infobar.
197 [controller_ linkClicked]; 205 [controller_ linkClicked];
198 206
199 // Spin the runloop because the invocation for closing the infobar is done on 207 // Spin the runloop because the invocation for closing the infobar is done on
(...skipping 26 matching lines...) Expand all
226 // Make sure someone looked at the message, link, and icon. 234 // Make sure someone looked at the message, link, and icon.
227 EXPECT_TRUE(delegate_->message_text_accessed()); 235 EXPECT_TRUE(delegate_->message_text_accessed());
228 EXPECT_TRUE(delegate_->link_text_accessed()); 236 EXPECT_TRUE(delegate_->link_text_accessed());
229 EXPECT_TRUE(delegate_->icon_accessed()); 237 EXPECT_TRUE(delegate_->icon_accessed());
230 238
231 // Check to make sure the infobar message was set properly. 239 // Check to make sure the infobar message was set properly.
232 EXPECT_EQ(MockConfirmInfoBarDelegate::kMessage, 240 EXPECT_EQ(MockConfirmInfoBarDelegate::kMessage,
233 base::SysNSStringToUTF8([controller_.get() labelString])); 241 base::SysNSStringToUTF8([controller_.get() labelString]));
234 242
235 // Check that dismissing the infobar deletes the delegate. 243 // Check that dismissing the infobar deletes the delegate.
236 [controller_ dismiss:nil]; 244 [controller_ removeSelf];
237 ASSERT_TRUE(delegate_closed()); 245 ASSERT_TRUE(delegate_closed());
238 EXPECT_FALSE(closed_delegate_ok_clicked_); 246 EXPECT_FALSE(closed_delegate_ok_clicked_);
239 EXPECT_FALSE(closed_delegate_cancel_clicked_); 247 EXPECT_FALSE(closed_delegate_cancel_clicked_);
240 EXPECT_FALSE(closed_delegate_link_clicked_); 248 EXPECT_FALSE(closed_delegate_link_clicked_);
241 } 249 }
242 250
243 TEST_F(ConfirmInfoBarControllerTest, ShowAndClickOK) { 251 TEST_F(ConfirmInfoBarControllerTest, ShowAndClickOK) {
244 // Check that clicking the OK button calls Accept() and then closes 252 // Check that clicking the OK button calls Accept() and then closes
245 // the infobar. 253 // the infobar.
246 [controller_ ok:nil]; 254 [controller_ ok:nil];
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 const CGFloat width = 20; 322 const CGFloat width = 20;
315 NSRect newViewFrame = [[controller_ view] frame]; 323 NSRect newViewFrame = [[controller_ view] frame];
316 newViewFrame.size.width += width; 324 newViewFrame.size.width += width;
317 [[controller_ view] setFrame:newViewFrame]; 325 [[controller_ view] setFrame:newViewFrame];
318 326
319 NSRect newLabelFrame = [controller_ labelFrame]; 327 NSRect newLabelFrame = [controller_ labelFrame];
320 EXPECT_EQ(NSWidth(newLabelFrame), NSWidth(originalLabelFrame) + width); 328 EXPECT_EQ(NSWidth(newLabelFrame), NSWidth(originalLabelFrame) + width);
321 } 329 }
322 330
323 } // namespace 331 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698