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

Side by Side Diff: ios/shared/chrome/browser/ui/commands/command_dispatcher_unittest.mm

Issue 2779213003: [clean] Use CommandDispatcher to show/close Settings. (Closed)
Patch Set: Fix tests Created 3 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 unified diff | Download patch
« no previous file with comments | « ios/shared/chrome/browser/ui/commands/command_dispatcher.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "ios/shared/chrome/browser/ui/commands/command_dispatcher.h" 5 #import "ios/shared/chrome/browser/ui/commands/command_dispatcher.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 NSObject* object_argument = [[NSObject alloc] init]; 153 NSObject* object_argument = [[NSObject alloc] init];
154 [dispatcher methodWithObject:object_argument]; 154 [dispatcher methodWithObject:object_argument];
155 EXPECT_FALSE(target.intMethodCalled); 155 EXPECT_FALSE(target.intMethodCalled);
156 EXPECT_TRUE(target.objectMethodCalled); 156 EXPECT_TRUE(target.objectMethodCalled);
157 EXPECT_EQ(object_argument, target.objectArgument); 157 EXPECT_EQ(object_argument, target.objectArgument);
158 158
159 [target resetProperties]; 159 [target resetProperties];
160 EXPECT_EQ(13, [dispatcher methodToAddFirstArgument:7 toSecond:6]); 160 EXPECT_EQ(13, [dispatcher methodToAddFirstArgument:7 toSecond:6]);
161 EXPECT_FALSE(target.intMethodCalled); 161 EXPECT_FALSE(target.intMethodCalled);
162 EXPECT_FALSE(target.objectMethodCalled); 162 EXPECT_FALSE(target.objectMethodCalled);
163 EXPECT_EQ(42, [dispatcher methodToAddFirstArgument:34 toSecond:8]);
164 } 163 }
165 164
166 // Tests that messages are routed to the proper handler when multiple targets 165 // Tests that messages are routed to the proper handler when multiple targets
167 // are registered. 166 // are registered.
168 TEST(CommandDispatcherTest, MultipleTargets) { 167 TEST(CommandDispatcherTest, MultipleTargets) {
169 id dispatcher = [[CommandDispatcher alloc] init]; 168 id dispatcher = [[CommandDispatcher alloc] init];
170 CommandDispatcherTestSimpleTarget* showTarget = 169 CommandDispatcherTestSimpleTarget* showTarget =
171 [[CommandDispatcherTestSimpleTarget alloc] init]; 170 [[CommandDispatcherTestSimpleTarget alloc] init];
172 CommandDispatcherTestSimpleTarget* hideTarget = 171 CommandDispatcherTestSimpleTarget* hideTarget =
173 [[CommandDispatcherTestSimpleTarget alloc] init]; 172 [[CommandDispatcherTestSimpleTarget alloc] init];
174 173
175 [dispatcher startDispatchingToTarget:showTarget forSelector:@selector(show)]; 174 [dispatcher startDispatchingToTarget:showTarget forSelector:@selector(show)];
176 [dispatcher startDispatchingToTarget:hideTarget forSelector:@selector(hide)]; 175 [dispatcher startDispatchingToTarget:hideTarget forSelector:@selector(hide)];
177 176
178 [dispatcher show]; 177 [dispatcher show];
179 EXPECT_TRUE(showTarget.showCalled); 178 EXPECT_TRUE(showTarget.showCalled);
180 EXPECT_FALSE(hideTarget.showCalled); 179 EXPECT_FALSE(hideTarget.showCalled);
181 180
182 [showTarget resetProperties]; 181 [showTarget resetProperties];
183 [dispatcher hide]; 182 [dispatcher hide];
184 EXPECT_FALSE(showTarget.hideCalled); 183 EXPECT_FALSE(showTarget.hideCalled);
185 EXPECT_TRUE(hideTarget.hideCalled); 184 EXPECT_TRUE(hideTarget.hideCalled);
186 } 185 }
187 186
188 // Tests that handlers are no longer forwarded messages after deregistration. 187 // Tests that handlers are no longer forwarded messages after selector
189 TEST(CommandDispatcherTest, Deregistration) { 188 // deregistration.
189 TEST(CommandDispatcherTest, SelectorDeregistration) {
190 id dispatcher = [[CommandDispatcher alloc] init];
191 CommandDispatcherTestSimpleTarget* target =
192 [[CommandDispatcherTestSimpleTarget alloc] init];
193
194 [dispatcher startDispatchingToTarget:target forSelector:@selector(show)];
195 [dispatcher startDispatchingToTarget:target forSelector:@selector(hide)];
196
197 [dispatcher show];
198 EXPECT_TRUE(target.showCalled);
199 EXPECT_FALSE(target.hideCalled);
200
201 [target resetProperties];
202 [dispatcher stopDispatchingForSelector:@selector(show)];
203 bool exception_caught = false;
204 @try {
205 [dispatcher show];
206 } @catch (NSException* exception) {
207 EXPECT_EQ(NSInvalidArgumentException, [exception name]);
208 exception_caught = true;
209 }
210 EXPECT_TRUE(exception_caught);
211
212 [dispatcher hide];
213 EXPECT_FALSE(target.showCalled);
214 EXPECT_TRUE(target.hideCalled);
215 }
216
217 // Tests that handlers are no longer forwarded messages after target
218 // deregistration.
219 TEST(CommandDispatcherTest, TargetDeregistration) {
190 id dispatcher = [[CommandDispatcher alloc] init]; 220 id dispatcher = [[CommandDispatcher alloc] init];
191 CommandDispatcherTestSimpleTarget* showTarget = 221 CommandDispatcherTestSimpleTarget* showTarget =
192 [[CommandDispatcherTestSimpleTarget alloc] init]; 222 [[CommandDispatcherTestSimpleTarget alloc] init];
193 CommandDispatcherTestSimpleTarget* hideTarget = 223 CommandDispatcherTestSimpleTarget* hideTarget =
194 [[CommandDispatcherTestSimpleTarget alloc] init]; 224 [[CommandDispatcherTestSimpleTarget alloc] init];
195 225
196 [dispatcher startDispatchingToTarget:showTarget forSelector:@selector(show)]; 226 [dispatcher startDispatchingToTarget:showTarget forSelector:@selector(show)];
197 [dispatcher startDispatchingToTarget:hideTarget forSelector:@selector(hide)]; 227 [dispatcher startDispatchingToTarget:hideTarget forSelector:@selector(hide)];
198 228
199 [dispatcher show]; 229 [dispatcher show];
(...skipping 27 matching lines...) Expand all
227 bool exception_caught = false; 257 bool exception_caught = false;
228 @try { 258 @try {
229 [dispatcher hide]; 259 [dispatcher hide];
230 } @catch (NSException* exception) { 260 } @catch (NSException* exception) {
231 EXPECT_EQ(NSInvalidArgumentException, [exception name]); 261 EXPECT_EQ(NSInvalidArgumentException, [exception name]);
232 exception_caught = true; 262 exception_caught = true;
233 } 263 }
234 264
235 EXPECT_TRUE(exception_caught); 265 EXPECT_TRUE(exception_caught);
236 } 266 }
OLDNEW
« no previous file with comments | « ios/shared/chrome/browser/ui/commands/command_dispatcher.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698