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

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

Issue 402066: Moved a whole pile of unittests over to CocoaTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #import "chrome/browser/cocoa/cocoa_test_helper.h" 10 #import "chrome/browser/cocoa/cocoa_test_helper.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 DCHECK(controller_ == controller); 54 DCHECK(controller_ == controller);
55 controller_ = nil; 55 controller_ = nil;
56 } 56 }
57 @end 57 @end
58 58
59 namespace { 59 namespace {
60 60
61 /////////////////////////////////////////////////////////////////////////// 61 ///////////////////////////////////////////////////////////////////////////
62 // Test fixtures 62 // Test fixtures
63 63
64 class AlertInfoBarControllerTest : public PlatformTest { 64 class AlertInfoBarControllerTest : public CocoaTest {
65 public: 65 public:
66 virtual void SetUp() { 66 virtual void SetUp() {
67 PlatformTest::SetUp(); 67 CocoaTest::SetUp();
68 68
69 controller_.reset( 69 controller_.reset(
70 [[AlertInfoBarController alloc] initWithDelegate:&delegate_]); 70 [[AlertInfoBarController alloc] initWithDelegate:&delegate_]);
71 container_.reset( 71 container_.reset(
72 [[InfoBarContainerTest alloc] initWithController:controller_]); 72 [[InfoBarContainerTest alloc] initWithController:controller_]);
73 [controller_ setContainerController:container_]; 73 [controller_ setContainerController:container_];
74 [helper_.contentView() addSubview:[controller_ view]]; 74 [[test_window() contentView] addSubview:[controller_ view]];
75 } 75 }
76 76
77 protected: 77 protected:
78 CocoaTestHelper helper_;
79 MockAlertInfoBarDelegate delegate_; 78 MockAlertInfoBarDelegate delegate_;
80 scoped_nsobject<id> container_; 79 scoped_nsobject<id> container_;
81 scoped_nsobject<AlertInfoBarController> controller_; 80 scoped_nsobject<AlertInfoBarController> controller_;
82 }; 81 };
83 82
84 class LinkInfoBarControllerTest : public PlatformTest { 83 class LinkInfoBarControllerTest : public CocoaTest {
85 public: 84 public:
86 virtual void SetUp() { 85 virtual void SetUp() {
87 PlatformTest::SetUp(); 86 CocoaTest::SetUp();
88 87
89 controller_.reset( 88 controller_.reset(
90 [[LinkInfoBarController alloc] initWithDelegate:&delegate_]); 89 [[LinkInfoBarController alloc] initWithDelegate:&delegate_]);
91 container_.reset( 90 container_.reset(
92 [[InfoBarContainerTest alloc] initWithController:controller_]); 91 [[InfoBarContainerTest alloc] initWithController:controller_]);
93 [controller_ setContainerController:container_]; 92 [controller_ setContainerController:container_];
94 [helper_.contentView() addSubview:[controller_ view]]; 93 [[test_window() contentView] addSubview:[controller_ view]];
95 } 94 }
96 95
97 protected: 96 protected:
98 CocoaTestHelper helper_;
99 MockLinkInfoBarDelegate delegate_; 97 MockLinkInfoBarDelegate delegate_;
100 scoped_nsobject<id> container_; 98 scoped_nsobject<id> container_;
101 scoped_nsobject<LinkInfoBarController> controller_; 99 scoped_nsobject<LinkInfoBarController> controller_;
102 }; 100 };
103 101
104 class ConfirmInfoBarControllerTest : public PlatformTest { 102 class ConfirmInfoBarControllerTest : public CocoaTest {
105 public: 103 public:
106 virtual void SetUp() { 104 virtual void SetUp() {
107 PlatformTest::SetUp(); 105 CocoaTest::SetUp();
108 106
109 controller_.reset( 107 controller_.reset(
110 [[ConfirmInfoBarController alloc] initWithDelegate:&delegate_]); 108 [[ConfirmInfoBarController alloc] initWithDelegate:&delegate_]);
111 container_.reset( 109 container_.reset(
112 [[InfoBarContainerTest alloc] initWithController:controller_]); 110 [[InfoBarContainerTest alloc] initWithController:controller_]);
113 [controller_ setContainerController:container_]; 111 [controller_ setContainerController:container_];
114 [helper_.contentView() addSubview:[controller_ view]]; 112 [[test_window() contentView] addSubview:[controller_ view]];
115 } 113 }
116 114
117 protected: 115 protected:
118 CocoaTestHelper helper_;
119 MockConfirmInfoBarDelegate delegate_; 116 MockConfirmInfoBarDelegate delegate_;
120 scoped_nsobject<id> container_; 117 scoped_nsobject<id> container_;
121 scoped_nsobject<ConfirmInfoBarController> controller_; 118 scoped_nsobject<ConfirmInfoBarController> controller_;
122 }; 119 };
123 120
124 121
125 //////////////////////////////////////////////////////////////////////////// 122 ////////////////////////////////////////////////////////////////////////////
126 // Tests 123 // Tests
127 124
125 TEST_VIEW(AlertInfoBarControllerTest, [controller_ view]);
126
128 TEST_F(AlertInfoBarControllerTest, ShowAndDismiss) { 127 TEST_F(AlertInfoBarControllerTest, ShowAndDismiss) {
129 // Make sure someone looked at the message and icon. 128 // Make sure someone looked at the message and icon.
130 EXPECT_TRUE(delegate_.message_text_accessed); 129 EXPECT_TRUE(delegate_.message_text_accessed);
131 EXPECT_TRUE(delegate_.icon_accessed); 130 EXPECT_TRUE(delegate_.icon_accessed);
132 131
133 // Check to make sure the infobar message was set properly. 132 // Check to make sure the infobar message was set properly.
134 EXPECT_EQ(std::wstring(kMockAlertInfoBarMessage), 133 EXPECT_EQ(std::wstring(kMockAlertInfoBarMessage),
135 base::SysNSStringToWide([[controller_.get() label] stringValue])); 134 base::SysNSStringToWide([[controller_.get() label] stringValue]));
136 135
137 // Check that dismissing the infobar calls InfoBarClosed() on the delegate. 136 // Check that dismissing the infobar calls InfoBarClosed() on the delegate.
138 [controller_ dismiss:nil]; 137 [controller_ dismiss:nil];
139 EXPECT_TRUE(delegate_.closed); 138 EXPECT_TRUE(delegate_.closed);
140 } 139 }
141 140
142 TEST_F(AlertInfoBarControllerTest, DeallocController) { 141 TEST_F(AlertInfoBarControllerTest, DeallocController) {
143 // Test that dealloc'ing the controller does not send an 142 // Test that dealloc'ing the controller does not send an
144 // InfoBarClosed() message to the delegate. 143 // InfoBarClosed() message to the delegate.
145 controller_.reset(nil); 144 controller_.reset(nil);
146 EXPECT_FALSE(delegate_.closed); 145 EXPECT_FALSE(delegate_.closed);
147 } 146 }
148 147
148 TEST_VIEW(LinkInfoBarControllerTest, [controller_ view]);
149
149 TEST_F(LinkInfoBarControllerTest, ShowAndDismiss) { 150 TEST_F(LinkInfoBarControllerTest, ShowAndDismiss) {
150 // Make sure someone looked at the message, link, and icon. 151 // Make sure someone looked at the message, link, and icon.
151 EXPECT_TRUE(delegate_.message_text_accessed); 152 EXPECT_TRUE(delegate_.message_text_accessed);
152 EXPECT_TRUE(delegate_.link_text_accessed); 153 EXPECT_TRUE(delegate_.link_text_accessed);
153 EXPECT_TRUE(delegate_.icon_accessed); 154 EXPECT_TRUE(delegate_.icon_accessed);
154 155
155 // Check that dismissing the infobar calls InfoBarClosed() on the delegate. 156 // Check that dismissing the infobar calls InfoBarClosed() on the delegate.
156 [controller_ dismiss:nil]; 157 [controller_ dismiss:nil];
157 EXPECT_FALSE(delegate_.link_clicked); 158 EXPECT_FALSE(delegate_.link_clicked);
158 EXPECT_TRUE(delegate_.closed); 159 EXPECT_TRUE(delegate_.closed);
(...skipping 10 matching lines...) Expand all
169 TEST_F(LinkInfoBarControllerTest, ShowAndClickLinkWithoutClosing) { 170 TEST_F(LinkInfoBarControllerTest, ShowAndClickLinkWithoutClosing) {
170 delegate_.closes_on_action = false; 171 delegate_.closes_on_action = false;
171 172
172 // Check that clicking on the link calls LinkClicked() on the 173 // Check that clicking on the link calls LinkClicked() on the
173 // delegate. It should not close the infobar. 174 // delegate. It should not close the infobar.
174 [controller_ linkClicked]; 175 [controller_ linkClicked];
175 EXPECT_TRUE(delegate_.link_clicked); 176 EXPECT_TRUE(delegate_.link_clicked);
176 EXPECT_FALSE(delegate_.closed); 177 EXPECT_FALSE(delegate_.closed);
177 } 178 }
178 179
180 TEST_VIEW(ConfirmInfoBarControllerTest, [controller_ view]);
181
179 TEST_F(ConfirmInfoBarControllerTest, ShowAndDismiss) { 182 TEST_F(ConfirmInfoBarControllerTest, ShowAndDismiss) {
180 // Make sure someone looked at the message and icon. 183 // Make sure someone looked at the message and icon.
181 EXPECT_TRUE(delegate_.message_text_accessed); 184 EXPECT_TRUE(delegate_.message_text_accessed);
182 EXPECT_TRUE(delegate_.icon_accessed); 185 EXPECT_TRUE(delegate_.icon_accessed);
183 186
184 // Check to make sure the infobar message was set properly. 187 // Check to make sure the infobar message was set properly.
185 EXPECT_EQ(std::wstring(kMockConfirmInfoBarMessage), 188 EXPECT_EQ(std::wstring(kMockConfirmInfoBarMessage),
186 base::SysNSStringToWide([[controller_.get() label] stringValue])); 189 base::SysNSStringToWide([[controller_.get() label] stringValue]));
187 190
188 // Check that dismissing the infobar calls InfoBarClosed() on the delegate. 191 // Check that dismissing the infobar calls InfoBarClosed() on the delegate.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 229
227 // Check that clicking the cancel button calls Cancel() but does not close 230 // Check that clicking the cancel button calls Cancel() but does not close
228 // the infobar. 231 // the infobar.
229 [controller_ cancel:nil]; 232 [controller_ cancel:nil];
230 EXPECT_FALSE(delegate_.ok_clicked); 233 EXPECT_FALSE(delegate_.ok_clicked);
231 EXPECT_TRUE(delegate_.cancel_clicked); 234 EXPECT_TRUE(delegate_.cancel_clicked);
232 EXPECT_FALSE(delegate_.closed); 235 EXPECT_FALSE(delegate_.closed);
233 } 236 }
234 237
235 } // namespace 238 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/infobar_container_controller_unittest.mm ('k') | chrome/browser/cocoa/infobar_text_field_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698