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 <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 2903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2914 autofill_test::CreateTestFormField("", "20", "901", "text", &field); | 2914 autofill_test::CreateTestFormField("", "20", "901", "text", &field); |
| 2915 types.clear(); | 2915 types.clear(); |
| 2916 types.insert(UNKNOWN_TYPE); | 2916 types.insert(UNKNOWN_TYPE); |
| 2917 form.fields.push_back(field); | 2917 form.fields.push_back(field); |
| 2918 expected_types.push_back(types); | 2918 expected_types.push_back(types); |
| 2919 | 2919 |
| 2920 autofill_manager_->set_expected_submitted_field_types(expected_types); | 2920 autofill_manager_->set_expected_submitted_field_types(expected_types); |
| 2921 FormSubmitted(form); | 2921 FormSubmitted(form); |
| 2922 } | 2922 } |
| 2923 | 2923 |
| 2924 TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) { | 2924 TEST_F(AutofillManagerTest, RemoveProfile) { |
| 2925 // Add and remove an Autofill profile. | |
| 2926 AutofillProfile* profile = new AutofillProfile; | |
| 2927 std::string guid = "00000000-0000-0000-0000-000000000102"; | |
| 2928 profile->set_guid(guid.c_str()); | |
| 2929 autofill_manager_->AddProfile(profile); | |
| 2930 | |
| 2931 GUIDPair guid_pair(guid, 0); | |
| 2932 GUIDPair empty(std::string(), 0); | |
| 2933 int id = PackGUIDs(empty, guid_pair); | |
| 2934 | |
| 2935 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); | |
| 2936 | |
| 2937 EXPECT_FALSE(autofill_manager_->GetProfileWithGUID(guid.c_str())); | |
| 2938 } | |
|
Ilya Sherman
2012/05/04 06:04:50
nit: Why is it helpful to move this test? Again,
zysxqn
2012/05/04 18:52:54
Done.
| |
| 2939 | |
| 2940 TEST_F(AutofillManagerTest, RemoveCreditCard){ | |
| 2941 // Add and remove an Autofill credit card. | |
| 2942 CreditCard* credit_card = new CreditCard; | |
| 2943 std::string guid = "00000000-0000-0000-0000-000000100007"; | |
| 2944 credit_card->set_guid(guid.c_str()); | |
| 2945 autofill_manager_->AddCreditCard(credit_card); | |
| 2946 | |
| 2947 GUIDPair guid_pair(guid, 0); | |
| 2948 GUIDPair empty(std::string(), 0); | |
| 2949 int id = PackGUIDs(guid_pair, empty); | |
| 2950 | |
| 2951 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); | |
| 2952 | |
| 2953 EXPECT_FALSE(autofill_manager_->GetCreditCardWithGUID(guid.c_str())); | |
| 2954 } | |
| 2955 | |
| 2956 TEST_F(AutofillManagerTest, RemoveProfileVariant) { | |
| 2957 // Add and remove an Autofill profile. | |
| 2958 AutofillProfile* profile = new AutofillProfile; | |
| 2959 std::string guid = "00000000-0000-0000-0000-000000000102"; | |
| 2960 profile->set_guid(guid.c_str()); | |
| 2961 autofill_manager_->AddProfile(profile); | |
| 2962 | |
| 2963 GUIDPair guid_pair(guid, 1); | |
| 2964 GUIDPair empty(std::string(), 0); | |
| 2965 int id = PackGUIDs(empty, guid_pair); | |
| 2966 | |
| 2967 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); | |
| 2968 | |
| 2969 // TODO(csharp): Currently variants should not be deleted, but once they are | |
| 2970 // update these expectations. | |
| 2971 // http://crbug.com/124211 | |
| 2972 EXPECT_TRUE(autofill_manager_->GetProfileWithGUID(guid.c_str())); | |
| 2973 } | |
| 2974 | |
| 2975 TEST_F(AutofillManagerTest, UpdatePasswordSyncState) { | |
| 2925 // Allow this test to control what should get synced. | 2976 // Allow this test to control what should get synced. |
| 2926 profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); | 2977 profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); |
| 2978 // Always set password generation enabled check box so we can test the | |
| 2979 // behavior of password sync. | |
| 2980 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true); | |
| 2927 | 2981 |
| 2928 // Sync some things, but not passwords. Shouldn't send anything since | 2982 // Sync some things, but not passwords. Shouldn't send anything since |
| 2929 // password generation is disabled by default. | 2983 // password generation is disabled by default. |
| 2930 ProfileSyncService* sync_service = GetProfileSyncService(); | 2984 ProfileSyncService* sync_service = GetProfileSyncService(); |
| 2931 sync_service->SetSyncSetupCompleted(); | 2985 sync_service->SetSyncSetupCompleted(); |
| 2932 syncable::ModelTypeSet preferred_set; | 2986 syncable::ModelTypeSet preferred_set; |
| 2933 preferred_set.Put(syncable::EXTENSIONS); | 2987 preferred_set.Put(syncable::EXTENSIONS); |
| 2934 preferred_set.Put(syncable::PREFERENCES); | 2988 preferred_set.Put(syncable::PREFERENCES); |
| 2935 sync_service->ChangePreferredDataTypes(preferred_set); | 2989 sync_service->ChangePreferredDataTypes(preferred_set); |
| 2936 syncable::ModelTypeSet new_set = sync_service->GetPreferredDataTypes(); | 2990 syncable::ModelTypeSet new_set = sync_service->GetPreferredDataTypes(); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 2966 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); | 3020 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); |
| 2967 | 3021 |
| 2968 // When a new render_view is created, we send the state even if it's the | 3022 // When a new render_view is created, we send the state even if it's the |
| 2969 // same. | 3023 // same. |
| 2970 UpdatePasswordGenerationState(true); | 3024 UpdatePasswordGenerationState(true); |
| 2971 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); | 3025 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); |
| 2972 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); | 3026 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); |
| 2973 autofill_manager_->ClearSentStates(); | 3027 autofill_manager_->ClearSentStates(); |
| 2974 } | 3028 } |
| 2975 | 3029 |
| 2976 TEST_F(AutofillManagerTest, RemoveProfile) { | 3030 TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) { |
| 2977 // Add and remove an Autofill profile. | 3031 // Always set password sync enabled so we can test the behavior of password |
| 2978 AutofillProfile* profile = new AutofillProfile; | 3032 // generation. |
| 2979 std::string guid = "00000000-0000-0000-0000-000000000102"; | 3033 profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); |
| 2980 profile->set_guid(guid.c_str()); | 3034 ProfileSyncService* sync_service = GetProfileSyncService(); |
| 2981 autofill_manager_->AddProfile(profile); | 3035 sync_service->SetSyncSetupCompleted(); |
| 3036 syncable::ModelTypeSet preferred_set; | |
| 3037 preferred_set.Put(syncable::PASSWORDS); | |
| 3038 sync_service->ChangePreferredDataTypes(preferred_set); | |
| 2982 | 3039 |
| 2983 GUIDPair guid_pair(guid, 0); | 3040 // Enabled state remains false, should not sent. |
| 2984 GUIDPair empty(std::string(), 0); | 3041 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, false); |
| 2985 int id = PackGUIDs(empty, guid_pair); | 3042 UpdatePasswordGenerationState(false); |
| 3043 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); | |
| 2986 | 3044 |
| 2987 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); | 3045 // Enabled state from false to true, should sent true. |
| 3046 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true); | |
| 3047 UpdatePasswordGenerationState(false); | |
| 3048 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); | |
| 3049 EXPECT_TRUE(autofill_manager_->GetSentStates()[0]); | |
| 3050 autofill_manager_->ClearSentStates(); | |
| 2988 | 3051 |
| 2989 EXPECT_FALSE(autofill_manager_->GetProfileWithGUID(guid.c_str())); | 3052 // Enabled states remains true, should not sent. |
| 2990 } | 3053 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true); |
| 3054 UpdatePasswordGenerationState(false); | |
| 3055 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); | |
| 2991 | 3056 |
| 2992 TEST_F(AutofillManagerTest, RemoveCreditCard){ | 3057 // Enabled states from true to false, should sent false. |
| 2993 // Add and remove an Autofill credit card. | 3058 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, false); |
| 2994 CreditCard* credit_card = new CreditCard; | 3059 UpdatePasswordGenerationState(false); |
| 2995 std::string guid = "00000000-0000-0000-0000-000000100007"; | 3060 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); |
| 2996 credit_card->set_guid(guid.c_str()); | 3061 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); |
| 2997 autofill_manager_->AddCreditCard(credit_card); | 3062 autofill_manager_->ClearSentStates(); |
| 2998 | 3063 |
| 2999 GUIDPair guid_pair(guid, 0); | 3064 // When a new render_view is created, we send the state even if it's the |
| 3000 GUIDPair empty(std::string(), 0); | 3065 // same. |
| 3001 int id = PackGUIDs(guid_pair, empty); | 3066 UpdatePasswordGenerationState(true); |
| 3002 | 3067 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); |
| 3003 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); | 3068 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); |
| 3004 | 3069 autofill_manager_->ClearSentStates(); |
| 3005 EXPECT_FALSE(autofill_manager_->GetCreditCardWithGUID(guid.c_str())); | |
| 3006 } | |
| 3007 | |
| 3008 TEST_F(AutofillManagerTest, RemoveProfileVariant) { | |
| 3009 // Add and remove an Autofill profile. | |
| 3010 AutofillProfile* profile = new AutofillProfile; | |
| 3011 std::string guid = "00000000-0000-0000-0000-000000000102"; | |
| 3012 profile->set_guid(guid.c_str()); | |
| 3013 autofill_manager_->AddProfile(profile); | |
| 3014 | |
| 3015 GUIDPair guid_pair(guid, 1); | |
| 3016 GUIDPair empty(std::string(), 0); | |
| 3017 int id = PackGUIDs(empty, guid_pair); | |
| 3018 | |
| 3019 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); | |
| 3020 | |
| 3021 // TODO(csharp): Currently variants should not be deleted, but once they are | |
| 3022 // update these expectations. | |
| 3023 // http://crbug.com/124211 | |
| 3024 EXPECT_TRUE(autofill_manager_->GetProfileWithGUID(guid.c_str())); | |
| 3025 } | 3070 } |
| 3026 | 3071 |
| 3027 namespace { | 3072 namespace { |
| 3028 | 3073 |
| 3029 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { | 3074 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { |
| 3030 public: | 3075 public: |
| 3031 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper, | 3076 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper, |
| 3032 AutofillManager* autofill_manager) | 3077 AutofillManager* autofill_manager) |
| 3033 : TestAutofillExternalDelegate(wrapper, autofill_manager) {} | 3078 : TestAutofillExternalDelegate(wrapper, autofill_manager) {} |
| 3034 virtual ~MockAutofillExternalDelegate() {} | 3079 virtual ~MockAutofillExternalDelegate() {} |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3084 | 3129 |
| 3085 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager(); | 3130 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager(); |
| 3086 EXPECT_TRUE(autofill_manager->external_delegate()); | 3131 EXPECT_TRUE(autofill_manager->external_delegate()); |
| 3087 | 3132 |
| 3088 AutocompleteHistoryManager* autocomplete_history_manager = | 3133 AutocompleteHistoryManager* autocomplete_history_manager = |
| 3089 contents_wrapper()->autocomplete_history_manager(); | 3134 contents_wrapper()->autocomplete_history_manager(); |
| 3090 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); | 3135 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); |
| 3091 } | 3136 } |
| 3092 | 3137 |
| 3093 #endif // OS_ANDROID | 3138 #endif // OS_ANDROID |
| OLD | NEW |