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