Chromium Code Reviews| 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 <algorithm> | |
| 5 #include <vector> | 6 #include <vector> |
| 6 | 7 |
| 7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| 10 #include "base/string16.h" | 11 #include "base/string16.h" |
| 11 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 12 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 13 #include "base/time.h" | 14 #include "base/time.h" |
| 14 #include "base/tuple.h" | 15 #include "base/tuple.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 36 #include "content/test/test_browser_thread.h" | 37 #include "content/test/test_browser_thread.h" |
| 37 #include "googleurl/src/gurl.h" | 38 #include "googleurl/src/gurl.h" |
| 38 #include "grit/generated_resources.h" | 39 #include "grit/generated_resources.h" |
| 39 #include "ipc/ipc_test_sink.h" | 40 #include "ipc/ipc_test_sink.h" |
| 40 #include "testing/gmock/include/gmock/gmock.h" | 41 #include "testing/gmock/include/gmock/gmock.h" |
| 41 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
| 42 #include "ui/base/l10n/l10n_util.h" | 43 #include "ui/base/l10n/l10n_util.h" |
| 43 #include "ui/gfx/rect.h" | 44 #include "ui/gfx/rect.h" |
| 44 #include "webkit/forms/form_data.h" | 45 #include "webkit/forms/form_data.h" |
| 45 #include "webkit/forms/form_field.h" | 46 #include "webkit/forms/form_field.h" |
| 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
|
Ilya Sherman
2012/04/19 21:01:57
nit: alpha-sort
csharp
2012/04/20 15:03:18
Done.
| |
| 47 | 48 |
| 48 using content::BrowserThread; | 49 using content::BrowserThread; |
| 49 using content::WebContents; | 50 using content::WebContents; |
| 50 using testing::_; | 51 using testing::_; |
| 51 using webkit::forms::FormData; | 52 using webkit::forms::FormData; |
| 52 using webkit::forms::FormField; | 53 using webkit::forms::FormField; |
| 53 | 54 |
| 54 namespace { | 55 namespace { |
| 55 | 56 |
| 56 // The page ID sent to the AutofillManager from the RenderView, used to send | 57 // The page ID sent to the AutofillManager from the RenderView, used to send |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 79 | 80 |
| 80 AutofillProfile* GetProfileWithGUID(const char* guid) { | 81 AutofillProfile* GetProfileWithGUID(const char* guid) { |
| 81 for (std::vector<AutofillProfile *>::iterator it = web_profiles_.begin(); | 82 for (std::vector<AutofillProfile *>::iterator it = web_profiles_.begin(); |
| 82 it != web_profiles_.end(); ++it) { | 83 it != web_profiles_.end(); ++it) { |
| 83 if (!(*it)->guid().compare(guid)) | 84 if (!(*it)->guid().compare(guid)) |
| 84 return *it; | 85 return *it; |
| 85 } | 86 } |
| 86 return NULL; | 87 return NULL; |
| 87 } | 88 } |
| 88 | 89 |
| 90 CreditCard* GetCreditCardWithGUID(const char* guid) { | |
| 91 for (std::vector<CreditCard *>::iterator it = credit_cards_.begin(); | |
| 92 it != credit_cards_.end(); ++it){ | |
| 93 if (!(*it)->guid().compare(guid)) | |
| 94 return *it; | |
| 95 } | |
| 96 return NULL; | |
| 97 } | |
| 98 | |
| 89 void AddProfile(AutofillProfile* profile) { | 99 void AddProfile(AutofillProfile* profile) { |
| 90 web_profiles_->push_back(profile); | 100 web_profiles_->push_back(profile); |
| 91 } | 101 } |
| 92 | 102 |
| 93 void AddCreditCard(CreditCard* credit_card) { | 103 void AddCreditCard(CreditCard* credit_card) { |
| 94 credit_cards_->push_back(credit_card); | 104 credit_cards_->push_back(credit_card); |
| 95 } | 105 } |
| 96 | 106 |
| 107 virtual void RemoveProfile(const std::string& guid) OVERRIDE { | |
| 108 AutofillProfile* profile = GetProfileWithGUID(guid.c_str()); | |
| 109 | |
| 110 web_profiles_.erase( | |
| 111 std::remove(web_profiles_.begin(), web_profiles_.end(), profile), | |
| 112 web_profiles_.end()); | |
|
Ilya Sherman
2012/04/19 21:01:57
nit: Isn't just """std::remove(web_profiles_.begin
csharp
2012/04/20 15:03:18
I don't believe so. std::remove (as I understand i
Ilya Sherman
2012/04/20 21:30:48
Ah, I think you're right -- sorry 'bout that. I g
| |
| 113 } | |
| 114 | |
| 115 virtual void RemoveCreditCard(const std::string& guid) OVERRIDE { | |
| 116 CreditCard* credit_card = GetCreditCardWithGUID(guid.c_str()); | |
| 117 | |
| 118 credit_cards_.erase( | |
| 119 std::remove(credit_cards_.begin(), credit_cards_.end(), credit_card), | |
| 120 credit_cards_.end()); | |
| 121 } | |
| 122 | |
| 97 void ClearAutofillProfiles() { | 123 void ClearAutofillProfiles() { |
| 98 web_profiles_.reset(); | 124 web_profiles_.reset(); |
| 99 } | 125 } |
| 100 | 126 |
| 101 void ClearCreditCards() { | 127 void ClearCreditCards() { |
| 102 credit_cards_.reset(); | 128 credit_cards_.reset(); |
| 103 } | 129 } |
| 104 | 130 |
| 105 void CreateTestCreditCardsYearAndMonth(const char* year, const char* month) { | 131 void CreateTestCreditCardsYearAndMonth(const char* year, const char* month) { |
| 106 ClearCreditCards(); | 132 ClearCreditCards(); |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 } | 528 } |
| 503 | 529 |
| 504 const std::string GetSubmittedFormSignature() { | 530 const std::string GetSubmittedFormSignature() { |
| 505 return submitted_form_signature_; | 531 return submitted_form_signature_; |
| 506 } | 532 } |
| 507 | 533 |
| 508 AutofillProfile* GetProfileWithGUID(const char* guid) { | 534 AutofillProfile* GetProfileWithGUID(const char* guid) { |
| 509 return personal_data_->GetProfileWithGUID(guid); | 535 return personal_data_->GetProfileWithGUID(guid); |
| 510 } | 536 } |
| 511 | 537 |
| 538 CreditCard* GetCreditCardWithGUID(const char* guid) { | |
| 539 return personal_data_->GetCreditCardWithGUID(guid); | |
| 540 } | |
| 541 | |
| 512 void AddProfile(AutofillProfile* profile) { | 542 void AddProfile(AutofillProfile* profile) { |
| 513 personal_data_->AddProfile(profile); | 543 personal_data_->AddProfile(profile); |
| 514 } | 544 } |
| 515 | 545 |
| 516 void AddCreditCard(CreditCard* credit_card) { | 546 void AddCreditCard(CreditCard* credit_card) { |
| 517 personal_data_->AddCreditCard(credit_card); | 547 personal_data_->AddCreditCard(credit_card); |
| 518 } | 548 } |
| 519 | 549 |
| 520 int GetPackedCreditCardID(int credit_card_id) { | 550 int GetPackedCreditCardID(int credit_card_id) { |
| 521 std::string credit_card_guid = | 551 std::string credit_card_guid = |
| (...skipping 2403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2925 autofill_manager_->ClearSentStates(); | 2955 autofill_manager_->ClearSentStates(); |
| 2926 | 2956 |
| 2927 // When a new render_view is created, we send the state even if it's the | 2957 // When a new render_view is created, we send the state even if it's the |
| 2928 // same. | 2958 // same. |
| 2929 UpdatePasswordSyncState(true); | 2959 UpdatePasswordSyncState(true); |
| 2930 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); | 2960 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); |
| 2931 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); | 2961 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); |
| 2932 autofill_manager_->ClearSentStates(); | 2962 autofill_manager_->ClearSentStates(); |
| 2933 } | 2963 } |
| 2934 | 2964 |
| 2965 TEST_F(AutofillManagerTest, RemoveProfile) { | |
| 2966 // Add and remove an Autofill profile. | |
| 2967 AutofillProfile* profile = new AutofillProfile; | |
| 2968 std::string guid = "00000000-0000-0000-0000-000000000102"; | |
| 2969 profile->set_guid(guid.c_str()); | |
| 2970 autofill_manager_->AddProfile(profile); | |
| 2971 | |
| 2972 GUIDPair guid_pair(guid, 1); | |
| 2973 GUIDPair empty(std::string(), 0); | |
| 2974 int id = PackGUIDs(empty, guid_pair); | |
| 2975 | |
| 2976 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); | |
| 2977 | |
| 2978 EXPECT_FALSE(autofill_manager_->GetProfileWithGUID(guid.c_str())); | |
| 2979 } | |
| 2980 | |
| 2981 TEST_F(AutofillManagerTest, RemoveCreditCard){ | |
| 2982 // Add and remove an Autofill credit card. | |
| 2983 CreditCard* credit_card = new CreditCard; | |
| 2984 std::string guid = "00000000-0000-0000-0000-000000100007"; | |
| 2985 credit_card->set_guid(guid.c_str()); | |
| 2986 autofill_manager_->AddCreditCard(credit_card); | |
| 2987 | |
| 2988 GUIDPair guid_pair(guid, 1); | |
| 2989 GUIDPair empty(std::string(), 0); | |
| 2990 int id = PackGUIDs(guid_pair, empty); | |
| 2991 | |
| 2992 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); | |
| 2993 | |
| 2994 EXPECT_FALSE(autofill_manager_->GetCreditCardWithGUID(guid.c_str())); | |
| 2995 } | |
| 2996 | |
| 2935 namespace { | 2997 namespace { |
| 2936 | 2998 |
| 2937 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { | 2999 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { |
| 2938 public: | 3000 public: |
| 2939 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper, | 3001 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper, |
| 2940 AutofillManager* autofill_manager) | 3002 AutofillManager* autofill_manager) |
| 2941 : TestAutofillExternalDelegate(wrapper, autofill_manager) {} | 3003 : TestAutofillExternalDelegate(wrapper, autofill_manager) {} |
| 2942 virtual ~MockAutofillExternalDelegate() {} | 3004 virtual ~MockAutofillExternalDelegate() {} |
| 2943 | 3005 |
| 2944 MOCK_METHOD5(OnQuery, void(int query_id, | 3006 MOCK_METHOD5(OnQuery, void(int query_id, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2992 | 3054 |
| 2993 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager(); | 3055 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager(); |
| 2994 EXPECT_TRUE(autofill_manager->external_delegate()); | 3056 EXPECT_TRUE(autofill_manager->external_delegate()); |
| 2995 | 3057 |
| 2996 AutocompleteHistoryManager* autocomplete_history_manager = | 3058 AutocompleteHistoryManager* autocomplete_history_manager = |
| 2997 contents_wrapper()->autocomplete_history_manager(); | 3059 contents_wrapper()->autocomplete_history_manager(); |
| 2998 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); | 3060 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); |
| 2999 } | 3061 } |
| 3000 | 3062 |
| 3001 #endif // OS_ANDROID | 3063 #endif // OS_ANDROID |
| OLD | NEW |