| 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 <map> | 5 #include <map> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 using ::i18n::addressinput::FieldProblemMap; | 76 using ::i18n::addressinput::FieldProblemMap; |
| 77 using testing::AtLeast; | 77 using testing::AtLeast; |
| 78 using testing::DoAll; | 78 using testing::DoAll; |
| 79 using testing::Return; | 79 using testing::Return; |
| 80 using testing::SetArgPointee; | 80 using testing::SetArgPointee; |
| 81 using testing::_; | 81 using testing::_; |
| 82 | 82 |
| 83 const char kSourceUrl[] = "http://localbike.shop"; | 83 const char kSourceUrl[] = "http://localbike.shop"; |
| 84 const char kFakeEmail[] = "user@chromium.org"; | 84 const char kFakeEmail[] = "user@chromium.org"; |
| 85 const char kFakeFingerprintEncoded[] = "CgVaAwiACA=="; | |
| 86 const char kEditedBillingAddress[] = "123 edited billing address"; | 85 const char kEditedBillingAddress[] = "123 edited billing address"; |
| 87 const char* kFieldsFromPage[] = | 86 const char* kFieldsFromPage[] = |
| 88 { "email", | 87 { "email", |
| 89 "cc-name", | 88 "cc-name", |
| 90 "cc-number", | 89 "cc-number", |
| 91 "cc-exp-month", | 90 "cc-exp-month", |
| 92 "cc-exp-year", | 91 "cc-exp-year", |
| 93 "cc-csc", | 92 "cc-csc", |
| 94 "billing name", | 93 "billing name", |
| 95 "billing address-line1", | 94 "billing address-line1", |
| (...skipping 29 matching lines...) Expand all Loading... |
| 125 | 124 |
| 126 scoped_ptr<wallet::WalletItems> CompleteAndValidWalletItems() { | 125 scoped_ptr<wallet::WalletItems> CompleteAndValidWalletItems() { |
| 127 scoped_ptr<wallet::WalletItems> items = | 126 scoped_ptr<wallet::WalletItems> items = |
| 128 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); | 127 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); |
| 129 items->AddAccount(wallet::GetTestGaiaAccount()); | 128 items->AddAccount(wallet::GetTestGaiaAccount()); |
| 130 items->AddInstrument(wallet::GetTestMaskedInstrument()); | 129 items->AddInstrument(wallet::GetTestMaskedInstrument()); |
| 131 items->AddAddress(wallet::GetTestShippingAddress()); | 130 items->AddAddress(wallet::GetTestShippingAddress()); |
| 132 return items.Pass(); | 131 return items.Pass(); |
| 133 } | 132 } |
| 134 | 133 |
| 135 scoped_ptr<risk::Fingerprint> GetFakeFingerprint() { | |
| 136 scoped_ptr<risk::Fingerprint> fingerprint(new risk::Fingerprint()); | |
| 137 // Add some data to the proto, else the encoded content is empty. | |
| 138 fingerprint->mutable_machine_characteristics()->mutable_screen_size()-> | |
| 139 set_width(1024); | |
| 140 return fingerprint.Pass(); | |
| 141 } | |
| 142 | |
| 143 bool HasAnyError(const ValidityMessages& messages, ServerFieldType field) { | 134 bool HasAnyError(const ValidityMessages& messages, ServerFieldType field) { |
| 144 return !messages.GetMessageOrDefault(field).text.empty(); | 135 return !messages.GetMessageOrDefault(field).text.empty(); |
| 145 } | 136 } |
| 146 | 137 |
| 147 bool HasUnsureError(const ValidityMessages& messages, ServerFieldType field) { | 138 bool HasUnsureError(const ValidityMessages& messages, ServerFieldType field) { |
| 148 const ValidityMessage& message = messages.GetMessageOrDefault(field); | 139 const ValidityMessage& message = messages.GetMessageOrDefault(field); |
| 149 return !message.text.empty() && !message.sure; | 140 return !message.text.empty() && !message.sure; |
| 150 } | 141 } |
| 151 | 142 |
| 152 class TestAutofillDialogView : public AutofillDialogView { | 143 class TestAutofillDialogView : public AutofillDialogView { |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 return messages.GetMessageOrDefault(CREDIT_CARD_NUMBER).text; | 552 return messages.GetMessageOrDefault(CREDIT_CARD_NUMBER).text; |
| 562 } | 553 } |
| 563 | 554 |
| 564 void SubmitWithWalletItems(scoped_ptr<wallet::WalletItems> wallet_items) { | 555 void SubmitWithWalletItems(scoped_ptr<wallet::WalletItems> wallet_items) { |
| 565 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 556 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 566 AcceptAndLoadFakeFingerprint(); | 557 AcceptAndLoadFakeFingerprint(); |
| 567 } | 558 } |
| 568 | 559 |
| 569 void AcceptAndLoadFakeFingerprint() { | 560 void AcceptAndLoadFakeFingerprint() { |
| 570 controller()->OnAccept(); | 561 controller()->OnAccept(); |
| 571 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); | 562 controller()->OnDidLoadRiskFingerprintData("a"); |
| 572 } | 563 } |
| 573 | 564 |
| 574 // Returns true if the given |section| contains a field of the given |type|. | 565 // Returns true if the given |section| contains a field of the given |type|. |
| 575 bool SectionContainsField(DialogSection section, ServerFieldType type) { | 566 bool SectionContainsField(DialogSection section, ServerFieldType type) { |
| 576 const DetailInputs& inputs = | 567 const DetailInputs& inputs = |
| 577 controller()->RequestedFieldsForSection(section); | 568 controller()->RequestedFieldsForSection(section); |
| 578 for (DetailInputs::const_iterator it = inputs.begin(); it != inputs.end(); | 569 for (DetailInputs::const_iterator it = inputs.begin(); it != inputs.end(); |
| 579 ++it) { | 570 ++it) { |
| 580 if (it->type == type) | 571 if (it->type == type) |
| 581 return true; | 572 return true; |
| (...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1535 | 1526 |
| 1536 scoped_ptr<wallet::WalletItems> wallet_items = | 1527 scoped_ptr<wallet::WalletItems> wallet_items = |
| 1537 CompleteAndValidWalletItems(); | 1528 CompleteAndValidWalletItems(); |
| 1538 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); | 1529 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); |
| 1539 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); | 1530 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); |
| 1540 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 1531 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 1541 EXPECT_FALSE(controller()->LegalDocumentLinks().empty()); | 1532 EXPECT_FALSE(controller()->LegalDocumentLinks().empty()); |
| 1542 | 1533 |
| 1543 controller()->OnAccept(); | 1534 controller()->OnAccept(); |
| 1544 controller()->OnDidAcceptLegalDocuments(); | 1535 controller()->OnDidAcceptLegalDocuments(); |
| 1545 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); | 1536 controller()->OnDidLoadRiskFingerprintData("a"); |
| 1546 | 1537 |
| 1547 // Now try it all over again with the location disclosure already accepted. | 1538 // Now try it all over again with the location disclosure already accepted. |
| 1548 // Nothing should change. | 1539 // Nothing should change. |
| 1549 Reset(); | 1540 Reset(); |
| 1550 base::ListValue preexisting_list; | 1541 base::ListValue preexisting_list; |
| 1551 preexisting_list.AppendString(kFakeEmail); | 1542 preexisting_list.AppendString(kFakeEmail); |
| 1552 g_browser_process->local_state()->Set( | 1543 g_browser_process->local_state()->Set( |
| 1553 ::prefs::kAutofillDialogWalletLocationAcceptance, | 1544 ::prefs::kAutofillDialogWalletLocationAcceptance, |
| 1554 preexisting_list); | 1545 preexisting_list); |
| 1555 } | 1546 } |
| (...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2431 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); | 2422 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); |
| 2432 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 2423 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 2433 | 2424 |
| 2434 testing::Mock::VerifyAndClear(controller()); | 2425 testing::Mock::VerifyAndClear(controller()); |
| 2435 EXPECT_CALL(*controller(), LoadRiskFingerprintData()); | 2426 EXPECT_CALL(*controller(), LoadRiskFingerprintData()); |
| 2436 | 2427 |
| 2437 controller()->OnAccept(); | 2428 controller()->OnAccept(); |
| 2438 | 2429 |
| 2439 // Simulate a risk load and verify |GetRiskData()| matches the encoded value. | 2430 // Simulate a risk load and verify |GetRiskData()| matches the encoded value. |
| 2440 controller()->OnDidAcceptLegalDocuments(); | 2431 controller()->OnDidAcceptLegalDocuments(); |
| 2441 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); | 2432 controller()->OnDidLoadRiskFingerprintData("a"); |
| 2442 EXPECT_EQ(kFakeFingerprintEncoded, controller()->GetRiskData()); | 2433 EXPECT_EQ("a", controller()->GetRiskData()); |
| 2443 } | 2434 } |
| 2444 | 2435 |
| 2445 TEST_F(AutofillDialogControllerTest, NoManageMenuItemForNewWalletUsers) { | 2436 TEST_F(AutofillDialogControllerTest, NoManageMenuItemForNewWalletUsers) { |
| 2446 // Make sure the menu model item is created for a returning Wallet user. | 2437 // Make sure the menu model item is created for a returning Wallet user. |
| 2447 scoped_ptr<wallet::WalletItems> wallet_items = | 2438 scoped_ptr<wallet::WalletItems> wallet_items = |
| 2448 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); | 2439 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); |
| 2449 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 2440 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
| 2450 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 2441 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
| 2451 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 2442 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 2452 | 2443 |
| (...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3646 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(2)->value); | 3637 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(2)->value); |
| 3647 EXPECT_EQ(ADDRESS_HOME_COUNTRY, | 3638 EXPECT_EQ(ADDRESS_HOME_COUNTRY, |
| 3648 form_structure()->field(3)->Type().GetStorableType()); | 3639 form_structure()->field(3)->Type().GetStorableType()); |
| 3649 EXPECT_EQ(ASCIIToUTF16("US"), form_structure()->field(3)->value); | 3640 EXPECT_EQ(ASCIIToUTF16("US"), form_structure()->field(3)->value); |
| 3650 EXPECT_EQ(ADDRESS_HOME_COUNTRY, | 3641 EXPECT_EQ(ADDRESS_HOME_COUNTRY, |
| 3651 form_structure()->field(4)->Type().GetStorableType()); | 3642 form_structure()->field(4)->Type().GetStorableType()); |
| 3652 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(4)->value); | 3643 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(4)->value); |
| 3653 } | 3644 } |
| 3654 | 3645 |
| 3655 } // namespace autofill | 3646 } // namespace autofill |
| OLD | NEW |