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

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

Issue 6262018: Cleanup:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 11 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/scoped_nsobject.h" 7 #include "base/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/infobar_delegate.h" 10 #include "chrome/browser/tab_contents/infobar_delegate.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 DCHECK(controller_ == controller); 58 DCHECK(controller_ == controller);
59 controller_ = nil; 59 controller_ = nil;
60 } 60 }
61 @end 61 @end
62 62
63 namespace { 63 namespace {
64 64
65 /////////////////////////////////////////////////////////////////////////// 65 ///////////////////////////////////////////////////////////////////////////
66 // Test fixtures 66 // Test fixtures
67 67
68 class AlertInfoBarControllerTest : public CocoaTest {
69 public:
70 virtual void SetUp() {
71 CocoaTest::SetUp();
72
73 controller_.reset(
74 [[AlertInfoBarController alloc] initWithDelegate:&delegate_]);
75 container_.reset(
76 [[InfoBarContainerTest alloc] initWithController:controller_]);
77 [controller_ setContainerController:container_];
78 [[test_window() contentView] addSubview:[controller_ view]];
79 }
80
81 protected:
82 MockAlertInfoBarDelegate delegate_;
83 scoped_nsobject<id> container_;
84 scoped_nsobject<AlertInfoBarController> controller_;
85 };
86
87 class LinkInfoBarControllerTest : public CocoaTest { 68 class LinkInfoBarControllerTest : public CocoaTest {
88 public: 69 public:
89 virtual void SetUp() { 70 virtual void SetUp() {
90 CocoaTest::SetUp(); 71 CocoaTest::SetUp();
91 72
92 controller_.reset( 73 controller_.reset(
93 [[LinkInfoBarController alloc] initWithDelegate:&delegate_]); 74 [[LinkInfoBarController alloc] initWithDelegate:&delegate_]);
94 container_.reset( 75 container_.reset(
95 [[InfoBarContainerTest alloc] initWithController:controller_]); 76 [[InfoBarContainerTest alloc] initWithController:controller_]);
96 [controller_ setContainerController:container_]; 77 [controller_ setContainerController:container_];
(...skipping 22 matching lines...) Expand all
119 protected: 100 protected:
120 MockConfirmInfoBarDelegate delegate_; 101 MockConfirmInfoBarDelegate delegate_;
121 scoped_nsobject<id> container_; 102 scoped_nsobject<id> container_;
122 scoped_nsobject<ConfirmInfoBarController> controller_; 103 scoped_nsobject<ConfirmInfoBarController> controller_;
123 }; 104 };
124 105
125 106
126 //////////////////////////////////////////////////////////////////////////// 107 ////////////////////////////////////////////////////////////////////////////
127 // Tests 108 // Tests
128 109
129 TEST_VIEW(AlertInfoBarControllerTest, [controller_ view]);
130
131 TEST_F(AlertInfoBarControllerTest, ShowAndDismiss) {
132 // Make sure someone looked at the message and icon.
133 EXPECT_TRUE(delegate_.message_text_accessed());
134 EXPECT_TRUE(delegate_.icon_accessed());
135
136 // Check to make sure the infobar message was set properly.
137 EXPECT_EQ(MockAlertInfoBarDelegate::kMessage,
138 base::SysNSStringToUTF8([controller_.get() labelString]));
139
140 // Check that dismissing the infobar calls InfoBarClosed() on the delegate.
141 [controller_ dismiss:nil];
142 EXPECT_TRUE(delegate_.closed());
143 }
144
145 TEST_F(AlertInfoBarControllerTest, DeallocController) {
146 // Test that dealloc'ing the controller does not send an
147 // InfoBarClosed() message to the delegate.
148 controller_.reset(nil);
149 EXPECT_FALSE(delegate_.closed());
150 }
151
152 TEST_F(AlertInfoBarControllerTest, ResizeView) {
153 NSRect originalLabelFrame = [controller_ labelFrame];
154
155 // Expand the view by 20 pixels and make sure the label frame changes
156 // accordingly.
157 const CGFloat width = 20;
158 NSRect newViewFrame = [[controller_ view] frame];
159 newViewFrame.size.width += width;
160 [[controller_ view] setFrame:newViewFrame];
161
162 NSRect newLabelFrame = [controller_ labelFrame];
163 EXPECT_EQ(NSWidth(newLabelFrame), NSWidth(originalLabelFrame) + width);
164 }
165
166 TEST_VIEW(LinkInfoBarControllerTest, [controller_ view]); 110 TEST_VIEW(LinkInfoBarControllerTest, [controller_ view]);
167 111
168 TEST_F(LinkInfoBarControllerTest, ShowAndDismiss) { 112 TEST_F(LinkInfoBarControllerTest, ShowAndDismiss) {
169 // Make sure someone looked at the message, link, and icon. 113 // Make sure someone looked at the message, link, and icon.
170 EXPECT_TRUE(delegate_.message_text_accessed()); 114 EXPECT_TRUE(delegate_.message_text_accessed());
171 EXPECT_TRUE(delegate_.link_text_accessed()); 115 EXPECT_TRUE(delegate_.link_text_accessed());
172 EXPECT_TRUE(delegate_.icon_accessed()); 116 EXPECT_TRUE(delegate_.icon_accessed());
173 117
174 // Check that dismissing the infobar calls InfoBarClosed() on the delegate. 118 // Check that dismissing the infobar calls InfoBarClosed() on the delegate.
175 [controller_ dismiss:nil]; 119 [controller_ dismiss:nil];
(...skipping 12 matching lines...) Expand all
188 TEST_F(LinkInfoBarControllerTest, ShowAndClickLinkWithoutClosing) { 132 TEST_F(LinkInfoBarControllerTest, ShowAndClickLinkWithoutClosing) {
189 delegate_.set_dont_close_on_action(); 133 delegate_.set_dont_close_on_action();
190 134
191 // Check that clicking on the link calls LinkClicked() on the 135 // Check that clicking on the link calls LinkClicked() on the
192 // delegate. It should not close the infobar. 136 // delegate. It should not close the infobar.
193 [controller_ linkClicked]; 137 [controller_ linkClicked];
194 EXPECT_TRUE(delegate_.link_clicked()); 138 EXPECT_TRUE(delegate_.link_clicked());
195 EXPECT_FALSE(delegate_.closed()); 139 EXPECT_FALSE(delegate_.closed());
196 } 140 }
197 141
142 TEST_F(LinkInfoBarControllerTest, DeallocController) {
143 // Test that dealloc'ing the controller does not send an
144 // InfoBarClosed() message to the delegate.
145 controller_.reset(nil);
146 EXPECT_FALSE(delegate_.closed());
147 }
148
198 TEST_VIEW(ConfirmInfoBarControllerTest, [controller_ view]); 149 TEST_VIEW(ConfirmInfoBarControllerTest, [controller_ view]);
199 150
200 TEST_F(ConfirmInfoBarControllerTest, ShowAndDismiss) { 151 TEST_F(ConfirmInfoBarControllerTest, ShowAndDismiss) {
201 // Make sure someone looked at the message, link, and icon. 152 // Make sure someone looked at the message, link, and icon.
202 EXPECT_TRUE(delegate_.message_text_accessed()); 153 EXPECT_TRUE(delegate_.message_text_accessed());
203 EXPECT_TRUE(delegate_.link_text_accessed()); 154 EXPECT_TRUE(delegate_.link_text_accessed());
204 EXPECT_TRUE(delegate_.icon_accessed()); 155 EXPECT_TRUE(delegate_.icon_accessed());
205 156
206 // Check to make sure the infobar message was set properly. 157 // Check to make sure the infobar message was set properly.
207 EXPECT_EQ(MockConfirmInfoBarDelegate::kMessage, 158 EXPECT_EQ(MockConfirmInfoBarDelegate::kMessage,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 225
275 // Check that clicking on the link calls LinkClicked() on the 226 // Check that clicking on the link calls LinkClicked() on the
276 // delegate. It should not close the infobar. 227 // delegate. It should not close the infobar.
277 [controller_ linkClicked]; 228 [controller_ linkClicked];
278 EXPECT_FALSE(delegate_.ok_clicked()); 229 EXPECT_FALSE(delegate_.ok_clicked());
279 EXPECT_FALSE(delegate_.cancel_clicked()); 230 EXPECT_FALSE(delegate_.cancel_clicked());
280 EXPECT_TRUE(delegate_.link_clicked()); 231 EXPECT_TRUE(delegate_.link_clicked());
281 EXPECT_FALSE(delegate_.closed()); 232 EXPECT_FALSE(delegate_.closed());
282 } 233 }
283 234
235 TEST_F(ConfirmInfoBarControllerTest, ResizeView) {
236 NSRect originalLabelFrame = [controller_ labelFrame];
237
238 // Expand the view by 20 pixels and make sure the label frame changes
239 // accordingly.
240 const CGFloat width = 20;
241 NSRect newViewFrame = [[controller_ view] frame];
242 newViewFrame.size.width += width;
243 [[controller_ view] setFrame:newViewFrame];
244
245 NSRect newLabelFrame = [controller_ labelFrame];
246 EXPECT_EQ(NSWidth(newLabelFrame), NSWidth(originalLabelFrame) + width);
247 }
248
284 } // namespace 249 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698