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

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

Issue 11721003: Eliminate the LinkInfoBar[Delegate] classes entirely. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: kill LinkInfoBar classes Created 7 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/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/api/infobars/confirm_infobar_delegate.h" 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
11 #include "chrome/browser/api/infobars/infobar_service.h" 11 #include "chrome/browser/api/infobars/infobar_service.h"
12 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" 12 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
13 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" 13 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
14 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" 14 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h"
15 #include "chrome/browser/ui/cocoa/infobars/mock_alternate_nav_infobar_delegate.h "
15 #include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h" 16 #include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h"
16 #include "chrome/browser/ui/cocoa/infobars/mock_link_infobar_delegate.h"
17 #include "chrome/browser/ui/cocoa/run_loop_testing.h" 17 #include "chrome/browser/ui/cocoa/run_loop_testing.h"
18 #import "content/public/browser/web_contents.h" 18 #import "content/public/browser/web_contents.h"
19 #include "ipc/ipc_message.h" 19 #include "ipc/ipc_message.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "testing/platform_test.h" 21 #include "testing/platform_test.h"
22 22
23 using content::WebContents; 23 using content::WebContents;
24 24
25 @interface InfoBarController (ExposedForTesting) 25 @interface InfoBarController (ExposedForTesting)
26 - (NSString*)labelString; 26 - (NSString*)labelString;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 63
64 - (BrowserWindowController*)browserWindowController { 64 - (BrowserWindowController*)browserWindowController {
65 return nil; 65 return nil;
66 } 66 }
67 @end 67 @end
68 68
69 // Calls to removeSelf normally start an animation, which removes the infobar 69 // Calls to removeSelf normally start an animation, which removes the infobar
70 // completely when finished. For testing purposes, we create a mock controller 70 // completely when finished. For testing purposes, we create a mock controller
71 // which calls close: immediately, rather than kicking off an animation. 71 // which calls close: immediately, rather than kicking off an animation.
72 @interface TestLinkInfoBarController : LinkInfoBarController 72 @interface TestAlternateNavInfoBarController : AlternateNavInfoBarController
73 - (void)removeSelf; 73 - (void)removeSelf;
74 @end 74 @end
75 75
76 @implementation TestLinkInfoBarController 76 @implementation TestAlternateNavInfoBarController
77 - (void)removeSelf { 77 - (void)removeSelf {
78 [self close]; 78 [self close];
79 } 79 }
80 @end 80 @end
81 81
82 @interface TestConfirmInfoBarController : ConfirmInfoBarController 82 @interface TestConfirmInfoBarController : ConfirmInfoBarController
83 - (void)removeSelf; 83 - (void)removeSelf;
84 @end 84 @end
85 85
86 @implementation TestConfirmInfoBarController 86 @implementation TestConfirmInfoBarController
87 - (void)removeSelf { 87 - (void)removeSelf {
88 [self close]; 88 [self close];
89 } 89 }
90 @end 90 @end
91 91
92 namespace { 92 namespace {
93 93
94 /////////////////////////////////////////////////////////////////////////// 94 ///////////////////////////////////////////////////////////////////////////
95 // Test fixtures 95 // Test fixtures
96 96
97 class LinkInfoBarControllerTest : public CocoaProfileTest, 97 class AlternateNavInfoBarControllerTest
98 public MockLinkInfoBarDelegate::Owner { 98 : public CocoaProfileTest,
99 public MockAlternateNavInfoBarDelegate::Owner {
99 public: 100 public:
100 virtual void SetUp() { 101 virtual void SetUp() {
101 CocoaProfileTest::SetUp(); 102 CocoaProfileTest::SetUp();
102 web_contents_.reset( 103 web_contents_.reset(
103 WebContents::Create(WebContents::CreateParams(profile()))); 104 WebContents::Create(WebContents::CreateParams(profile())));
104 InfoBarService::CreateForWebContents(web_contents_.get()); 105 InfoBarService::CreateForWebContents(web_contents_.get());
105 106
106 InfoBarService* infobar_service = 107 InfoBarService* infobar_service =
107 InfoBarService::FromWebContents(web_contents_.get()); 108 InfoBarService::FromWebContents(web_contents_.get());
108 delegate_ = new MockLinkInfoBarDelegate(this); 109 delegate_ = new MockAlternateNavInfoBarDelegate(this);
109 controller_.reset([[TestLinkInfoBarController alloc] 110 controller_.reset([[TestAlternateNavInfoBarController alloc]
110 initWithDelegate:delegate_ owner:infobar_service]); 111 initWithDelegate:delegate_ owner:infobar_service]);
111 container_.reset( 112 container_.reset(
112 [[InfoBarContainerTest alloc] initWithController:controller_]); 113 [[InfoBarContainerTest alloc] initWithController:controller_]);
113 [controller_ setContainerController:container_]; 114 [controller_ setContainerController:container_];
114 [[test_window() contentView] addSubview:[controller_ view]]; 115 [[test_window() contentView] addSubview:[controller_ view]];
115 closed_delegate_link_clicked_ = false; 116 closed_delegate_link_clicked_ = false;
116 } 117 }
117 118
118 virtual void TearDown() { 119 virtual void TearDown() {
119 if (delegate_) 120 if (delegate_)
120 delete delegate_; 121 delete delegate_;
121 CocoaProfileTest::TearDown(); 122 CocoaProfileTest::TearDown();
122 } 123 }
123 124
124 protected: 125 protected:
125 // Hopefully-obvious: If this returns true, you must not deref |delegate_|! 126 // Hopefully-obvious: If this returns true, you must not deref |delegate_|!
126 bool delegate_closed() const { return delegate_ == NULL; } 127 bool delegate_closed() const { return delegate_ == NULL; }
127 128
128 MockLinkInfoBarDelegate* delegate_; // Owns itself. 129 MockAlternateNavInfoBarDelegate* delegate_; // Owns itself.
129 scoped_nsobject<id> container_; 130 scoped_nsobject<id> container_;
130 scoped_nsobject<LinkInfoBarController> controller_; 131 scoped_nsobject<AlternateNavInfoBarController> controller_;
131 bool closed_delegate_link_clicked_; 132 bool closed_delegate_link_clicked_;
132 133
133 private: 134 private:
134 virtual void OnInfoBarDelegateClosed() { 135 virtual void OnInfoBarDelegateClosed() {
135 closed_delegate_link_clicked_ = delegate_->link_clicked(); 136 closed_delegate_link_clicked_ = delegate_->link_clicked();
136 delegate_ = NULL; 137 delegate_ = NULL;
137 } 138 }
138 139
139 scoped_ptr<WebContents> web_contents_; 140 scoped_ptr<WebContents> web_contents_;
140 }; 141 };
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 delegate_ = NULL; 188 delegate_ = NULL;
188 } 189 }
189 190
190 scoped_ptr<WebContents> web_contents_; 191 scoped_ptr<WebContents> web_contents_;
191 }; 192 };
192 193
193 194
194 //////////////////////////////////////////////////////////////////////////// 195 ////////////////////////////////////////////////////////////////////////////
195 // Tests 196 // Tests
196 197
197 TEST_VIEW(LinkInfoBarControllerTest, [controller_ view]); 198 TEST_VIEW(AlternateNavInfoBarControllerTest, [controller_ view]);
198 199
199 TEST_F(LinkInfoBarControllerTest, ShowAndDismiss) { 200 TEST_F(AlternateNavInfoBarControllerTest, ShowAndDismiss) {
200 // Make sure someone looked at the message, link, and icon. 201 // Make sure someone looked at the message, link, and icon.
201 EXPECT_TRUE(delegate_->message_text_accessed()); 202 EXPECT_TRUE(delegate_->message_text_accessed());
202 EXPECT_TRUE(delegate_->link_text_accessed()); 203 EXPECT_TRUE(delegate_->link_text_accessed());
203 EXPECT_TRUE(delegate_->icon_accessed()); 204 EXPECT_TRUE(delegate_->icon_accessed());
204 205
205 // Check that dismissing the infobar deletes the delegate. 206 // Check that dismissing the infobar deletes the delegate.
206 [controller_ removeSelf]; 207 [controller_ removeSelf];
207 ASSERT_TRUE(delegate_closed()); 208 ASSERT_TRUE(delegate_closed());
208 EXPECT_FALSE(closed_delegate_link_clicked_); 209 EXPECT_FALSE(closed_delegate_link_clicked_);
209 } 210 }
210 211
211 TEST_F(LinkInfoBarControllerTest, ShowAndClickLink) { 212 TEST_F(AlternateNavInfoBarControllerTest, ShowAndClickLink) {
212 // Check that clicking on the link calls LinkClicked() on the 213 // Check that clicking on the link calls LinkClicked() on the
213 // delegate. It should also close the infobar. 214 // delegate. It should also close the infobar.
214 [controller_ linkClicked]; 215 [controller_ linkClicked];
215 216
216 // Spin the runloop because the invocation for closing the infobar is done on 217 // Spin the runloop because the invocation for closing the infobar is done on
217 // a 0-timer delayed selector. 218 // a 0-timer delayed selector.
218 chrome::testing::NSRunLoopRunAllPending(); 219 chrome::testing::NSRunLoopRunAllPending();
219 220
220 ASSERT_TRUE(delegate_closed()); 221 ASSERT_TRUE(delegate_closed());
221 EXPECT_TRUE(closed_delegate_link_clicked_); 222 EXPECT_TRUE(closed_delegate_link_clicked_);
222 } 223 }
223 224
224 TEST_F(LinkInfoBarControllerTest, ShowAndClickLinkWithoutClosing) { 225 TEST_F(AlternateNavInfoBarControllerTest, ShowAndClickLinkWithoutClosing) {
225 delegate_->set_dont_close_on_action(); 226 delegate_->set_dont_close_on_action();
226 227
227 // Check that clicking on the link calls LinkClicked() on the 228 // Check that clicking on the link calls LinkClicked() on the
228 // delegate. It should not close the infobar. 229 // delegate. It should not close the infobar.
229 [controller_ linkClicked]; 230 [controller_ linkClicked];
230 ASSERT_FALSE(delegate_closed()); 231 ASSERT_FALSE(delegate_closed());
231 EXPECT_TRUE(delegate_->link_clicked()); 232 EXPECT_TRUE(delegate_->link_clicked());
232 } 233 }
233 234
234 TEST_F(LinkInfoBarControllerTest, DeallocController) { 235 TEST_F(AlternateNavInfoBarControllerTest, DeallocController) {
235 // Test that dealloc'ing the controller does not delete the delegate. 236 // Test that dealloc'ing the controller does not delete the delegate.
236 controller_.reset(nil); 237 controller_.reset(nil);
237 ASSERT_FALSE(delegate_closed()); 238 ASSERT_FALSE(delegate_closed());
238 } 239 }
239 240
240 TEST_VIEW(ConfirmInfoBarControllerTest, [controller_ view]); 241 TEST_VIEW(ConfirmInfoBarControllerTest, [controller_ view]);
241 242
242 TEST_F(ConfirmInfoBarControllerTest, ShowAndDismiss) { 243 TEST_F(ConfirmInfoBarControllerTest, ShowAndDismiss) {
243 // Make sure someone looked at the message, link, and icon. 244 // Make sure someone looked at the message, link, and icon.
244 EXPECT_TRUE(delegate_->message_text_accessed()); 245 EXPECT_TRUE(delegate_->message_text_accessed());
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 const CGFloat width = 20; 332 const CGFloat width = 20;
332 NSRect newViewFrame = [[controller_ view] frame]; 333 NSRect newViewFrame = [[controller_ view] frame];
333 newViewFrame.size.width += width; 334 newViewFrame.size.width += width;
334 [[controller_ view] setFrame:newViewFrame]; 335 [[controller_ view] setFrame:newViewFrame];
335 336
336 NSRect newLabelFrame = [controller_ labelFrame]; 337 NSRect newLabelFrame = [controller_ labelFrame];
337 EXPECT_EQ(NSWidth(newLabelFrame), NSWidth(originalLabelFrame) + width); 338 EXPECT_EQ(NSWidth(newLabelFrame), NSWidth(originalLabelFrame) + width);
338 } 339 }
339 340
340 } // namespace 341 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698