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

Side by Side Diff: components/autofill/core/browser/autofill_manager_unittest.cc

Issue 575283003: mac: Don't show access Address Book prompt if user has any Autofill state. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix another unit test. Fix some broken (unused) logic in that unit test. Created 6 years, 3 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 88 }
89 89
90 void AddCreditCard(CreditCard* credit_card) { 90 void AddCreditCard(CreditCard* credit_card) {
91 credit_cards_.push_back(credit_card); 91 credit_cards_.push_back(credit_card);
92 } 92 }
93 93
94 virtual void RemoveByGUID(const std::string& guid) OVERRIDE { 94 virtual void RemoveByGUID(const std::string& guid) OVERRIDE {
95 CreditCard* credit_card = GetCreditCardWithGUID(guid.c_str()); 95 CreditCard* credit_card = GetCreditCardWithGUID(guid.c_str());
96 if (credit_card) { 96 if (credit_card) {
97 credit_cards_.erase( 97 credit_cards_.erase(
98 std::remove(credit_cards_.begin(), credit_cards_.end(), credit_card), 98 std::find(credit_cards_.begin(), credit_cards_.end(), credit_card));
erikchen 2014/09/18 21:02:54 This logic is incorrect. std::remove and erase() b
99 credit_cards_.end());
100 } 99 }
101 100
102 AutofillProfile* profile = GetProfileWithGUID(guid.c_str()); 101 AutofillProfile* profile = GetProfileWithGUID(guid.c_str());
103 if (profile) { 102 if (profile) {
104 web_profiles_.erase( 103 web_profiles_.erase(
105 std::remove(web_profiles_.begin(), web_profiles_.end(), profile), 104 std::find(web_profiles_.begin(), web_profiles_.end(), profile));
106 web_profiles_.end());
107 } 105 }
108 } 106 }
109 107
110 // Do nothing (auxiliary profiles will be created in 108 // Do nothing (auxiliary profiles will be created in
111 // CreateTestAuxiliaryProfile). 109 // CreateTestAuxiliaryProfile).
112 virtual void LoadAuxiliaryProfiles(bool record_metrics) const OVERRIDE {} 110 virtual void LoadAuxiliaryProfiles(bool record_metrics) const OVERRIDE {}
113 111
114 void ClearAutofillProfiles() { 112 void ClearAutofillProfiles() {
115 web_profiles_.clear(); 113 web_profiles_.clear();
116 } 114 }
(...skipping 2663 matching lines...) Expand 10 before | Expand all | Expand 10 after
2780 EXPECT_TRUE(autofill_manager_->GetProfileWithGUID(guid.c_str())); 2778 EXPECT_TRUE(autofill_manager_->GetProfileWithGUID(guid.c_str()));
2781 } 2779 }
2782 2780
2783 #if defined(OS_MACOSX) && !defined(OS_IOS) 2781 #if defined(OS_MACOSX) && !defined(OS_IOS)
2784 TEST_F(AutofillManagerTest, AccessAddressBookPrompt) { 2782 TEST_F(AutofillManagerTest, AccessAddressBookPrompt) {
2785 FormData form; 2783 FormData form;
2786 test::CreateTestAddressFormData(&form); 2784 test::CreateTestAddressFormData(&form);
2787 std::vector<FormData> forms(1, form); 2785 std::vector<FormData> forms(1, form);
2788 FormsSeen(forms); 2786 FormsSeen(forms);
2789 FormFieldData& field = form.fields[0]; 2787 FormFieldData& field = form.fields[0];
2788 field.should_autocomplete = true;
2789
2790 // A profile already exists.
2791 EXPECT_FALSE(
2792 autofill_manager_->ShouldShowAccessAddressBookSuggestion(form, field));
2793
2794 // Remove all profiles.
2795 personal_data_.ClearAutofillProfiles();
2796 EXPECT_TRUE(
2797 autofill_manager_->ShouldShowAccessAddressBookSuggestion(form, field));
2790 2798
2791 field.should_autocomplete = false; 2799 field.should_autocomplete = false;
2792 EXPECT_FALSE( 2800 EXPECT_FALSE(
2793 autofill_manager_->ShouldShowAccessAddressBookSuggestion(form, field)); 2801 autofill_manager_->ShouldShowAccessAddressBookSuggestion(form, field));
2794
2795 field.should_autocomplete = true;
2796 EXPECT_TRUE(
2797 autofill_manager_->ShouldShowAccessAddressBookSuggestion(form, field));
2798 } 2802 }
2799 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 2803 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
2800 2804
2801 namespace { 2805 namespace {
2802 2806
2803 class MockAutofillClient : public TestAutofillClient { 2807 class MockAutofillClient : public TestAutofillClient {
2804 public: 2808 public:
2805 MockAutofillClient() {} 2809 MockAutofillClient() {}
2806 2810
2807 virtual ~MockAutofillClient() {} 2811 virtual ~MockAutofillClient() {}
(...skipping 26 matching lines...) Expand all
2834 test::CreateTestAddressFormData(&form); 2838 test::CreateTestAddressFormData(&form);
2835 std::vector<FormData> forms(1, form); 2839 std::vector<FormData> forms(1, form);
2836 FormsSeen(forms); 2840 FormsSeen(forms);
2837 const FormFieldData& field = form.fields[0]; 2841 const FormFieldData& field = form.fields[0];
2838 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() 2842 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery()
2839 2843
2840 EXPECT_TRUE(external_delegate_->on_query_seen()); 2844 EXPECT_TRUE(external_delegate_->on_query_seen());
2841 } 2845 }
2842 2846
2843 } // namespace autofill 2847 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698