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

Side by Side Diff: ios/chrome/browser/autofill/form_suggestion_controller_unittest.mm

Issue 2593283002: [ios] Removed keyCode from FormActivityRegistered API. (Closed)
Patch Set: Created 4 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/chrome/browser/autofill/form_suggestion_controller.h" 5 #import "ios/chrome/browser/autofill/form_suggestion_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/ios/ios_util.h" 10 #include "base/ios/ios_util.h"
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 [[mock_js_suggestion_manager_ expect] inject]; 278 [[mock_js_suggestion_manager_ expect] inject];
279 [suggestion_controller_ webStateDidLoadPage:web_state()]; 279 [suggestion_controller_ webStateDidLoadPage:web_state()];
280 EXPECT_OCMOCK_VERIFY(mock_js_suggestion_manager_); 280 EXPECT_OCMOCK_VERIFY(mock_js_suggestion_manager_);
281 281
282 // Trigger form activity, which should set up the suggestions view. 282 // Trigger form activity, which should set up the suggestions view.
283 [accessory_controller_ webState:web_state() 283 [accessory_controller_ webState:web_state()
284 didRegisterFormActivityWithFormNamed:"form" 284 didRegisterFormActivityWithFormNamed:"form"
285 fieldName:"field" 285 fieldName:"field"
286 type:"type" 286 type:"type"
287 value:"value" 287 value:"value"
288 keyCode:web::WebStateObserver::
289 kInvalidFormKeyCode
290 inputMissing:false]; 288 inputMissing:false];
291 EXPECT_TRUE(GetSuggestionView(input_accessory_view_)); 289 EXPECT_TRUE(GetSuggestionView(input_accessory_view_));
292 290
293 // Trigger another page load. The suggestions accessory view should 291 // Trigger another page load. The suggestions accessory view should
294 // not be present. 292 // not be present.
295 [accessory_controller_ webStateDidLoadPage:web_state()]; 293 [accessory_controller_ webStateDidLoadPage:web_state()];
296 EXPECT_FALSE(GetSuggestionView(input_accessory_view_)); 294 EXPECT_FALSE(GetSuggestionView(input_accessory_view_));
297 } 295 }
298 296
299 // Tests that "blur" events are ignored. 297 // Tests that "blur" events are ignored.
300 TEST_F(FormSuggestionControllerTest, FormActivityBlurShouldBeIgnored) { 298 TEST_F(FormSuggestionControllerTest, FormActivityBlurShouldBeIgnored) {
301 [accessory_controller_ webState:web_state() 299 [accessory_controller_ webState:web_state()
302 didRegisterFormActivityWithFormNamed:"form" 300 didRegisterFormActivityWithFormNamed:"form"
303 fieldName:"field" 301 fieldName:"field"
304 type:"blur" // blur! 302 type:"blur" // blur!
305 value:"value" 303 value:"value"
306 keyCode:web::WebStateObserver::
307 kInvalidFormKeyCode
308 inputMissing:false]; 304 inputMissing:false];
309 EXPECT_FALSE(GetSuggestionView(input_accessory_view_)); 305 EXPECT_FALSE(GetSuggestionView(input_accessory_view_));
310 } 306 }
311 307
312 // Tests that no suggestions are displayed when no providers are registered. 308 // Tests that no suggestions are displayed when no providers are registered.
313 TEST_F(FormSuggestionControllerTest, 309 TEST_F(FormSuggestionControllerTest,
314 FormActivityShouldRetrieveSuggestions_NoProvidersAvailable) { 310 FormActivityShouldRetrieveSuggestions_NoProvidersAvailable) {
315 // Set up the controller without any providers. 311 // Set up the controller without any providers.
316 SetUpController(@[]); 312 SetUpController(@[]);
317 SetCurrentUrl("http://foo.com"); 313 SetCurrentUrl("http://foo.com");
318 [accessory_controller_ webState:web_state() 314 [accessory_controller_ webState:web_state()
319 didRegisterFormActivityWithFormNamed:"form" 315 didRegisterFormActivityWithFormNamed:"form"
320 fieldName:"field" 316 fieldName:"field"
321 type:"type" 317 type:"type"
322 value:"value" 318 value:"value"
323 keyCode:web::WebStateObserver::
324 kInvalidFormKeyCode
325 inputMissing:false]; 319 inputMissing:false];
326 320
327 // The suggestions accessory view should be empty. 321 // The suggestions accessory view should be empty.
328 FormSuggestionView* suggestionView = GetSuggestionView(input_accessory_view_); 322 FormSuggestionView* suggestionView = GetSuggestionView(input_accessory_view_);
329 EXPECT_TRUE(suggestionView); 323 EXPECT_TRUE(suggestionView);
330 EXPECT_EQ(0U, [suggestionView.suggestions count]); 324 EXPECT_EQ(0U, [suggestionView.suggestions count]);
331 } 325 }
332 326
333 // Tests that, when no providers have suggestions to offer for a form/field, 327 // Tests that, when no providers have suggestions to offer for a form/field,
334 // they aren't asked and no suggestions are displayed. 328 // they aren't asked and no suggestions are displayed.
335 TEST_F(FormSuggestionControllerTest, 329 TEST_F(FormSuggestionControllerTest,
336 FormActivityShouldRetrieveSuggestions_NoSuggestionsAvailable) { 330 FormActivityShouldRetrieveSuggestions_NoSuggestionsAvailable) {
337 // Set up the controller with some providers, but none of them will 331 // Set up the controller with some providers, but none of them will
338 // have suggestions available. 332 // have suggestions available.
339 TestSuggestionProvider* provider1 = 333 TestSuggestionProvider* provider1 =
340 [[TestSuggestionProvider alloc] initWithSuggestions:@[]]; 334 [[TestSuggestionProvider alloc] initWithSuggestions:@[]];
341 TestSuggestionProvider* provider2 = 335 TestSuggestionProvider* provider2 =
342 [[TestSuggestionProvider alloc] initWithSuggestions:@[]]; 336 [[TestSuggestionProvider alloc] initWithSuggestions:@[]];
343 SetUpController(@[ provider1, provider2 ]); 337 SetUpController(@[ provider1, provider2 ]);
344 SetCurrentUrl("http://foo.com"); 338 SetCurrentUrl("http://foo.com");
345 339
346 [accessory_controller_ webState:web_state() 340 [accessory_controller_ webState:web_state()
347 didRegisterFormActivityWithFormNamed:"form" 341 didRegisterFormActivityWithFormNamed:"form"
348 fieldName:"field" 342 fieldName:"field"
349 type:"type" 343 type:"type"
350 value:"value" 344 value:"value"
351 keyCode:web::WebStateObserver::
352 kInvalidFormKeyCode
353 inputMissing:false]; 345 inputMissing:false];
354 346
355 // The providers should each be asked if they have suggestions for the 347 // The providers should each be asked if they have suggestions for the
356 // form in question. 348 // form in question.
357 EXPECT_TRUE([provider1 askedIfSuggestionsAvailable]); 349 EXPECT_TRUE([provider1 askedIfSuggestionsAvailable]);
358 EXPECT_TRUE([provider2 askedIfSuggestionsAvailable]); 350 EXPECT_TRUE([provider2 askedIfSuggestionsAvailable]);
359 351
360 // Since none of the providers had suggestions available, none of them 352 // Since none of the providers had suggestions available, none of them
361 // should have been asked for suggestions. 353 // should have been asked for suggestions.
362 EXPECT_FALSE([provider1 askedForSuggestions]); 354 EXPECT_FALSE([provider1 askedForSuggestions]);
(...skipping 27 matching lines...) Expand all
390 TestSuggestionProvider* provider2 = 382 TestSuggestionProvider* provider2 =
391 [[TestSuggestionProvider alloc] initWithSuggestions:@[]]; 383 [[TestSuggestionProvider alloc] initWithSuggestions:@[]];
392 SetUpController(@[ provider1, provider2 ]); 384 SetUpController(@[ provider1, provider2 ]);
393 SetCurrentUrl("http://foo.com"); 385 SetCurrentUrl("http://foo.com");
394 386
395 [accessory_controller_ webState:web_state() 387 [accessory_controller_ webState:web_state()
396 didRegisterFormActivityWithFormNamed:"form" 388 didRegisterFormActivityWithFormNamed:"form"
397 fieldName:"field" 389 fieldName:"field"
398 type:"type" 390 type:"type"
399 value:"value" 391 value:"value"
400 keyCode:web::WebStateObserver::
401 kInvalidFormKeyCode
402 inputMissing:false]; 392 inputMissing:false];
403 393
404 // Since the first provider has suggestions available, it and only it 394 // Since the first provider has suggestions available, it and only it
405 // should have been asked. 395 // should have been asked.
406 EXPECT_TRUE([provider1 askedIfSuggestionsAvailable]); 396 EXPECT_TRUE([provider1 askedIfSuggestionsAvailable]);
407 EXPECT_FALSE([provider2 askedIfSuggestionsAvailable]); 397 EXPECT_FALSE([provider2 askedIfSuggestionsAvailable]);
408 398
409 // Since the first provider said it had suggestions, it and only it 399 // Since the first provider said it had suggestions, it and only it
410 // should have been asked to provide them. 400 // should have been asked to provide them.
411 EXPECT_TRUE([provider1 askedForSuggestions]); 401 EXPECT_TRUE([provider1 askedForSuggestions]);
(...skipping 17 matching lines...) Expand all
429 ]; 419 ];
430 TestSuggestionProvider* provider = 420 TestSuggestionProvider* provider =
431 [[TestSuggestionProvider alloc] initWithSuggestions:suggestions]; 421 [[TestSuggestionProvider alloc] initWithSuggestions:suggestions];
432 SetUpController(@[ provider ]); 422 SetUpController(@[ provider ]);
433 SetCurrentUrl("http://foo.com"); 423 SetCurrentUrl("http://foo.com");
434 [accessory_controller_ webState:web_state() 424 [accessory_controller_ webState:web_state()
435 didRegisterFormActivityWithFormNamed:"form" 425 didRegisterFormActivityWithFormNamed:"form"
436 fieldName:"field" 426 fieldName:"field"
437 type:"type" 427 type:"type"
438 value:"value" 428 value:"value"
439 keyCode:web::WebStateObserver::
440 kInvalidFormKeyCode
441 inputMissing:false]; 429 inputMissing:false];
442 430
443 // Selecting a suggestion should notify the delegate. 431 // Selecting a suggestion should notify the delegate.
444 [suggestion_controller_ didSelectSuggestion:suggestions[0]]; 432 [suggestion_controller_ didSelectSuggestion:suggestions[0]];
445 EXPECT_TRUE([provider selected]); 433 EXPECT_TRUE([provider selected]);
446 EXPECT_NSEQ(@"form", [provider formName]); 434 EXPECT_NSEQ(@"form", [provider formName]);
447 EXPECT_NSEQ(@"field", [provider fieldName]); 435 EXPECT_NSEQ(@"field", [provider fieldName]);
448 EXPECT_NSEQ(suggestions[0], [provider suggestion]); 436 EXPECT_NSEQ(suggestions[0], [provider suggestion]);
449 } 437 }
450 438
451 } // namespace 439 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698