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

Side by Side Diff: chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm

Issue 2884051: Merge 53276 - AutoFill Empty profiles should not be saved from AutoFillDialog... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/472/src/
Patch Set: Created 10 years, 4 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include "base/ref_counted.h" 5 #include "base/ref_counted.h"
6 #import "chrome/browser/autofill/autofill_address_model_mac.h" 6 #import "chrome/browser/autofill/autofill_address_model_mac.h"
7 #import "chrome/browser/autofill/autofill_address_sheet_controller_mac.h" 7 #import "chrome/browser/autofill/autofill_address_sheet_controller_mac.h"
8 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h" 8 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h"
9 #import "chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.h" 9 #import "chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.h"
10 #import "chrome/browser/autofill/autofill_dialog_controller_mac.h" 10 #import "chrome/browser/autofill/autofill_dialog_controller_mac.h"
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 } 376 }
377 377
378 TEST_F(AutoFillDialogControllerTest, AddNewProfile) { 378 TEST_F(AutoFillDialogControllerTest, AddNewProfile) {
379 AutoFillProfile profile(ASCIIToUTF16("One"), 1); 379 AutoFillProfile profile(ASCIIToUTF16("One"), 1);
380 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); 380 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe"));
381 profiles().push_back(&profile); 381 profiles().push_back(&profile);
382 LoadDialog(); 382 LoadDialog();
383 [controller_ addNewAddress:nil]; 383 [controller_ addNewAddress:nil];
384 AutoFillAddressSheetController* sheet = [controller_ addressSheetController]; 384 AutoFillAddressSheetController* sheet = [controller_ addressSheetController];
385 ASSERT_TRUE(sheet != nil); 385 ASSERT_TRUE(sheet != nil);
386 AutoFillAddressModel* model = [sheet addressModel];
387 ASSERT_TRUE(model != nil);
388 [model setFullName:@"Don"];
386 [sheet save:nil]; 389 [sheet save:nil];
387 [controller_ save:nil]; 390 [controller_ save:nil];
388 391
389 // Should hit our observer. 392 // Should hit our observer.
390 ASSERT_TRUE(observer_.hit_); 393 ASSERT_TRUE(observer_.hit_);
391 394
392 // Sizes should be different. New size should be 2. 395 // Sizes should be different. New size should be 2.
393 ASSERT_NE(observer_.profiles_.size(), profiles().size()); 396 ASSERT_NE(observer_.profiles_.size(), profiles().size());
394 ASSERT_EQ(observer_.profiles_.size(), 2UL); 397 ASSERT_EQ(observer_.profiles_.size(), 2UL);
395 398
396 // New address should match. 399 // New address should match. Don't compare labels.
397 AutoFillProfile new_profile; 400 AutoFillProfile new_profile;
401 new_profile.SetInfo(AutoFillType(NAME_FULL), ASCIIToUTF16("Don"));
402 observer_.profiles_[1].set_label(string16());
398 ASSERT_EQ(observer_.profiles_[1], new_profile); 403 ASSERT_EQ(observer_.profiles_[1], new_profile);
399 } 404 }
400 405
401 TEST_F(AutoFillDialogControllerTest, AddNewCreditCard) { 406 TEST_F(AutoFillDialogControllerTest, AddNewCreditCard) {
402 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); 407 CreditCard credit_card(ASCIIToUTF16("Visa"), 1);
403 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); 408 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe"));
404 credit_cards().push_back(&credit_card); 409 credit_cards().push_back(&credit_card);
405 LoadDialog(); 410 LoadDialog();
406 [controller_ addNewCreditCard:nil]; 411 [controller_ addNewCreditCard:nil];
407 AutoFillCreditCardSheetController* sheet = 412 AutoFillCreditCardSheetController* sheet =
408 [controller_ creditCardSheetController]; 413 [controller_ creditCardSheetController];
409 ASSERT_TRUE(sheet != nil); 414 ASSERT_TRUE(sheet != nil);
415 AutoFillCreditCardModel* model = [sheet creditCardModel];
416 ASSERT_TRUE(model != nil);
417 [model setNameOnCard:@"Don"];
410 [sheet save:nil]; 418 [sheet save:nil];
411 [controller_ save:nil]; 419 [controller_ save:nil];
412 420
413 // Should hit our observer. 421 // Should hit our observer.
414 ASSERT_TRUE(observer_.hit_); 422 ASSERT_TRUE(observer_.hit_);
415 423
416 // Sizes should be different. New size should be 2. 424 // Sizes should be different. New size should be 2.
417 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size()); 425 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size());
418 ASSERT_EQ(observer_.credit_cards_.size(), 2UL); 426 ASSERT_EQ(observer_.credit_cards_.size(), 2UL);
419 427
420 // New address should match. 428 // New credit card should match. Don't compare labels.
421 CreditCard new_credit_card; 429 CreditCard new_credit_card;
430 new_credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Don"));
431 observer_.credit_cards_[1].set_label(string16());
422 ASSERT_EQ(observer_.credit_cards_[1], new_credit_card); 432 ASSERT_EQ(observer_.credit_cards_[1], new_credit_card);
423 } 433 }
424 434
435 TEST_F(AutoFillDialogControllerTest, AddNewEmptyProfile) {
436 AutoFillProfile profile(string16(), 1);
437 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe"));
438 profiles().push_back(&profile);
439 LoadDialog();
440 [controller_ addNewAddress:nil];
441 AutoFillAddressSheetController* sheet = [controller_ addressSheetController];
442 ASSERT_TRUE(sheet != nil);
443 [sheet save:nil];
444 [controller_ save:nil];
445
446 // Should hit our observer.
447 ASSERT_TRUE(observer_.hit_);
448
449 // Sizes should be same. Empty profile should not be saved.
450 ASSERT_EQ(observer_.profiles_.size(), profiles().size());
451 ASSERT_EQ(observer_.profiles_.size(), 1UL);
452
453 // Profile should match original.
454 observer_.profiles_[0].set_label(string16());
455 ASSERT_EQ(observer_.profiles_[0], profile);
456 }
457
458 TEST_F(AutoFillDialogControllerTest, AddNewEmptyCreditCard) {
459 CreditCard credit_card(string16(), 1);
460 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe"));
461 credit_cards().push_back(&credit_card);
462 LoadDialog();
463 [controller_ addNewCreditCard:nil];
464 AutoFillCreditCardSheetController* sheet =
465 [controller_ creditCardSheetController];
466 ASSERT_TRUE(sheet != nil);
467 [sheet save:nil];
468 [controller_ save:nil];
469
470 // Should hit our observer.
471 ASSERT_TRUE(observer_.hit_);
472
473 // Sizes should be same. Empty credit card should not be saved.
474 ASSERT_EQ(observer_.credit_cards_.size(), credit_cards().size());
475 ASSERT_EQ(observer_.credit_cards_.size(), 1UL);
476
477 // Credit card should match original.
478 observer_.credit_cards_[0].set_label(string16());
479 ASSERT_EQ(observer_.credit_cards_[0], credit_card);
480 }
481
425 TEST_F(AutoFillDialogControllerTest, DeleteProfile) { 482 TEST_F(AutoFillDialogControllerTest, DeleteProfile) {
426 AutoFillProfile profile(ASCIIToUTF16("One"), 1); 483 AutoFillProfile profile(ASCIIToUTF16("One"), 1);
427 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); 484 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe"));
428 profiles().push_back(&profile); 485 profiles().push_back(&profile);
429 LoadDialog(); 486 LoadDialog();
430 [controller_ selectAddressAtIndex:0]; 487 [controller_ selectAddressAtIndex:0];
431 [controller_ deleteSelection:nil]; 488 [controller_ deleteSelection:nil];
432 [controller_ save:nil]; 489 [controller_ save:nil];
433 490
434 // Should hit our observer. 491 // Should hit our observer.
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 754
698 // Should hit our observer. 755 // Should hit our observer.
699 ASSERT_TRUE(observer_.hit_); 756 ASSERT_TRUE(observer_.hit_);
700 757
701 // Auxiliary profiles setting should be unchanged. 758 // Auxiliary profiles setting should be unchanged.
702 ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean( 759 ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean(
703 prefs::kAutoFillEnabled)); 760 prefs::kAutoFillEnabled));
704 } 761 }
705 762
706 } // namespace 763 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_dialog_controller_mac.mm ('k') | chrome/browser/autofill/autofill_profile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698