OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/guid.h" | 5 #include "base/guid.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" | 10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 virtual void UpdateAccountChooser() OVERRIDE {} | 48 virtual void UpdateAccountChooser() OVERRIDE {} |
49 virtual void UpdateButtonStrip() OVERRIDE {} | 49 virtual void UpdateButtonStrip() OVERRIDE {} |
50 virtual void UpdateSection(DialogSection section, UserInputAction action) | 50 virtual void UpdateSection(DialogSection section, UserInputAction action) |
51 OVERRIDE {} | 51 OVERRIDE {} |
52 virtual void GetUserInput(DialogSection section, DetailOutputMap* output) | 52 virtual void GetUserInput(DialogSection section, DetailOutputMap* output) |
53 OVERRIDE { | 53 OVERRIDE { |
54 *output = outputs_[section]; | 54 *output = outputs_[section]; |
55 } | 55 } |
56 | 56 |
57 virtual string16 GetCvc() OVERRIDE { return string16(); } | 57 virtual string16 GetCvc() OVERRIDE { return string16(); } |
58 virtual bool UseBillingForShipping() OVERRIDE { return false; } | |
59 virtual bool SaveDetailsLocally() OVERRIDE { return true; } | 58 virtual bool SaveDetailsLocally() OVERRIDE { return true; } |
60 virtual const content::NavigationController* ShowSignIn() OVERRIDE { | 59 virtual const content::NavigationController* ShowSignIn() OVERRIDE { |
61 return NULL; | 60 return NULL; |
62 } | 61 } |
63 virtual void HideSignIn() OVERRIDE {} | 62 virtual void HideSignIn() OVERRIDE {} |
64 virtual void UpdateProgressBar(double value) OVERRIDE {} | 63 virtual void UpdateProgressBar(double value) OVERRIDE {} |
65 virtual void SubmitForTesting() OVERRIDE {} | 64 virtual void SubmitForTesting() OVERRIDE {} |
66 virtual void CancelForTesting() OVERRIDE {} | 65 virtual void CancelForTesting() OVERRIDE {} |
67 | 66 |
68 MOCK_METHOD0(ModelChanged, void()); | 67 MOCK_METHOD0(ModelChanged, void()); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 iter != shipping_inputs.end(); ++iter) { | 356 iter != shipping_inputs.end(); ++iter) { |
358 controller()->InputIsValid(iter->type, string16()); | 357 controller()->InputIsValid(iter->type, string16()); |
359 } | 358 } |
360 } | 359 } |
361 } | 360 } |
362 | 361 |
363 TEST_F(AutofillDialogControllerTest, AutofillProfiles) { | 362 TEST_F(AutofillDialogControllerTest, AutofillProfiles) { |
364 ui::MenuModel* shipping_model = | 363 ui::MenuModel* shipping_model = |
365 controller()->MenuModelForSection(SECTION_SHIPPING); | 364 controller()->MenuModelForSection(SECTION_SHIPPING); |
366 // Since the PersonalDataManager is empty, this should only have the | 365 // Since the PersonalDataManager is empty, this should only have the |
367 // "add new" menu item. | 366 // "use billing", "add new" and "manage" menu items. |
368 EXPECT_EQ(1, shipping_model->GetItemCount()); | 367 EXPECT_EQ(3, shipping_model->GetItemCount()); |
369 | 368 |
370 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2); | 369 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2); |
371 | 370 |
372 // Empty profiles are ignored. | 371 // Empty profiles are ignored. |
373 AutofillProfile empty_profile(base::GenerateGUID()); | 372 AutofillProfile empty_profile(base::GenerateGUID()); |
374 empty_profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe")); | 373 empty_profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe")); |
375 controller()->GetTestingManager()->AddTestingProfile(&empty_profile); | 374 controller()->GetTestingManager()->AddTestingProfile(&empty_profile); |
376 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); | 375 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); |
377 EXPECT_EQ(1, shipping_model->GetItemCount()); | 376 EXPECT_EQ(3, shipping_model->GetItemCount()); |
378 | 377 |
379 // A full profile should be picked up. | 378 // A full profile should be picked up. |
380 AutofillProfile full_profile(test::GetFullProfile()); | 379 AutofillProfile full_profile(test::GetFullProfile()); |
381 full_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16()); | 380 full_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16()); |
382 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | 381 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
383 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); | 382 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); |
384 EXPECT_EQ(2, shipping_model->GetItemCount()); | 383 EXPECT_EQ(4, shipping_model->GetItemCount()); |
385 } | 384 } |
386 | 385 |
387 TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) { | 386 TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) { |
388 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); | 387 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); |
| 388 ui::MenuModel* email_model = |
| 389 controller()->MenuModelForSection(SECTION_EMAIL); |
| 390 EXPECT_EQ(2, email_model->GetItemCount()); |
389 | 391 |
390 // Set up some variant data. | 392 // Set up some variant data. |
391 AutofillProfile full_profile(test::GetFullProfile()); | 393 AutofillProfile full_profile(test::GetFullProfile()); |
392 std::vector<string16> names; | 394 std::vector<string16> names; |
393 names.push_back(ASCIIToUTF16("John Doe")); | 395 names.push_back(ASCIIToUTF16("John Doe")); |
394 names.push_back(ASCIIToUTF16("Jane Doe")); | 396 names.push_back(ASCIIToUTF16("Jane Doe")); |
395 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, names); | 397 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, names); |
396 const string16 kEmail1 = ASCIIToUTF16("user@example.com"); | 398 const string16 kEmail1 = ASCIIToUTF16("user@example.com"); |
397 const string16 kEmail2 = ASCIIToUTF16("admin@example.com"); | 399 const string16 kEmail2 = ASCIIToUTF16("admin@example.com"); |
398 std::vector<string16> emails; | 400 std::vector<string16> emails; |
399 emails.push_back(kEmail1); | 401 emails.push_back(kEmail1); |
400 emails.push_back(kEmail2); | 402 emails.push_back(kEmail2); |
401 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, emails); | 403 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, emails); |
402 | 404 |
403 // Respect variants for the email address field only. | 405 // Respect variants for the email address field only. |
404 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | 406 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
405 ui::MenuModel* shipping_model = | 407 ui::MenuModel* shipping_model = |
406 controller()->MenuModelForSection(SECTION_SHIPPING); | 408 controller()->MenuModelForSection(SECTION_SHIPPING); |
407 EXPECT_EQ(2, shipping_model->GetItemCount()); | 409 EXPECT_EQ(4, shipping_model->GetItemCount()); |
408 ui::MenuModel* email_model = | 410 email_model = controller()->MenuModelForSection(SECTION_EMAIL); |
409 controller()->MenuModelForSection(SECTION_EMAIL); | 411 EXPECT_EQ(4, email_model->GetItemCount()); |
410 EXPECT_EQ(3, email_model->GetItemCount()); | |
411 | 412 |
412 email_model->ActivatedAt(0); | 413 email_model->ActivatedAt(0); |
413 EXPECT_EQ(kEmail1, | 414 EXPECT_EQ(kEmail1, |
414 controller()->SuggestionStateForSection(SECTION_EMAIL).text); | 415 controller()->SuggestionStateForSection(SECTION_EMAIL).text); |
415 email_model->ActivatedAt(1); | 416 email_model->ActivatedAt(1); |
416 EXPECT_EQ(kEmail2, | 417 EXPECT_EQ(kEmail2, |
417 controller()->SuggestionStateForSection(SECTION_EMAIL).text); | 418 controller()->SuggestionStateForSection(SECTION_EMAIL).text); |
418 | 419 |
419 controller()->EditClickedForSection(SECTION_EMAIL); | 420 controller()->EditClickedForSection(SECTION_EMAIL); |
420 const DetailInputs& inputs = | 421 const DetailInputs& inputs = |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 TEST_F(AutofillDialogControllerTest, EditClickedCancelled) { | 490 TEST_F(AutofillDialogControllerTest, EditClickedCancelled) { |
490 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); | 491 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); |
491 | 492 |
492 AutofillProfile full_profile(test::GetFullProfile()); | 493 AutofillProfile full_profile(test::GetFullProfile()); |
493 const string16 kEmail = ASCIIToUTF16("first@johndoe.com"); | 494 const string16 kEmail = ASCIIToUTF16("first@johndoe.com"); |
494 full_profile.SetRawInfo(EMAIL_ADDRESS, kEmail); | 495 full_profile.SetRawInfo(EMAIL_ADDRESS, kEmail); |
495 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | 496 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
496 | 497 |
497 ui::MenuModel* email_model = | 498 ui::MenuModel* email_model = |
498 controller()->MenuModelForSection(SECTION_EMAIL); | 499 controller()->MenuModelForSection(SECTION_EMAIL); |
499 EXPECT_EQ(2, email_model->GetItemCount()); | 500 EXPECT_EQ(3, email_model->GetItemCount()); |
500 | 501 |
501 // When unedited, the initial_value should be empty. | 502 // When unedited, the initial_value should be empty. |
502 email_model->ActivatedAt(0); | 503 email_model->ActivatedAt(0); |
503 const DetailInputs& inputs0 = | 504 const DetailInputs& inputs0 = |
504 controller()->RequestedFieldsForSection(SECTION_EMAIL); | 505 controller()->RequestedFieldsForSection(SECTION_EMAIL); |
505 EXPECT_EQ(string16(), inputs0[0].initial_value); | 506 EXPECT_EQ(string16(), inputs0[0].initial_value); |
506 EXPECT_EQ(kEmail, | 507 EXPECT_EQ(kEmail, |
507 controller()->SuggestionStateForSection(SECTION_EMAIL).text); | 508 controller()->SuggestionStateForSection(SECTION_EMAIL).text); |
508 | 509 |
509 // When edited, the initial_value should contain the value. | 510 // When edited, the initial_value should contain the value. |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 811 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
811 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 812 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
812 | 813 |
813 EXPECT_TRUE(NotificationsOfType( | 814 EXPECT_TRUE(NotificationsOfType( |
814 DialogNotification::EXPLANATORY_MESSAGE).empty()); | 815 DialogNotification::EXPLANATORY_MESSAGE).empty()); |
815 EXPECT_TRUE(NotificationsOfType( | 816 EXPECT_TRUE(NotificationsOfType( |
816 DialogNotification::WALLET_USAGE_CONFIRMATION).empty()); | 817 DialogNotification::WALLET_USAGE_CONFIRMATION).empty()); |
817 } | 818 } |
818 | 819 |
819 } // namespace autofill | 820 } // namespace autofill |
OLD | NEW |