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, UpdatePasswordSyncState) { |
2925 // Allow this test to control what should get synced. | 2925 // Allow this test to control what should get synced. |
2926 profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); | 2926 profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); |
| 2927 // Always set password generation enabled check box so we can test the |
| 2928 // behavior of password sync. |
| 2929 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true); |
2927 | 2930 |
2928 // Sync some things, but not passwords. Shouldn't send anything since | 2931 // Sync some things, but not passwords. Shouldn't send anything since |
2929 // password generation is disabled by default. | 2932 // password generation is disabled by default. |
2930 ProfileSyncService* sync_service = GetProfileSyncService(); | 2933 ProfileSyncService* sync_service = GetProfileSyncService(); |
2931 sync_service->SetSyncSetupCompleted(); | 2934 sync_service->SetSyncSetupCompleted(); |
2932 syncable::ModelTypeSet preferred_set; | 2935 syncable::ModelTypeSet preferred_set; |
2933 preferred_set.Put(syncable::EXTENSIONS); | 2936 preferred_set.Put(syncable::EXTENSIONS); |
2934 preferred_set.Put(syncable::PREFERENCES); | 2937 preferred_set.Put(syncable::PREFERENCES); |
2935 sync_service->ChangePreferredDataTypes(preferred_set); | 2938 sync_service->ChangePreferredDataTypes(preferred_set); |
2936 syncable::ModelTypeSet new_set = sync_service->GetPreferredDataTypes(); | 2939 syncable::ModelTypeSet new_set = sync_service->GetPreferredDataTypes(); |
(...skipping 29 matching lines...) Expand all Loading... |
2966 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); | 2969 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); |
2967 | 2970 |
2968 // When a new render_view is created, we send the state even if it's the | 2971 // When a new render_view is created, we send the state even if it's the |
2969 // same. | 2972 // same. |
2970 UpdatePasswordGenerationState(true); | 2973 UpdatePasswordGenerationState(true); |
2971 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); | 2974 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); |
2972 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); | 2975 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); |
2973 autofill_manager_->ClearSentStates(); | 2976 autofill_manager_->ClearSentStates(); |
2974 } | 2977 } |
2975 | 2978 |
| 2979 TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) { |
| 2980 // Always set password sync enabled so we can test the behavior of password |
| 2981 // generation. |
| 2982 profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); |
| 2983 ProfileSyncService* sync_service = GetProfileSyncService(); |
| 2984 sync_service->SetSyncSetupCompleted(); |
| 2985 syncable::ModelTypeSet preferred_set; |
| 2986 preferred_set.Put(syncable::PASSWORDS); |
| 2987 sync_service->ChangePreferredDataTypes(preferred_set); |
| 2988 |
| 2989 // Enabled state remains false, should not sent. |
| 2990 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, false); |
| 2991 UpdatePasswordGenerationState(false); |
| 2992 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); |
| 2993 |
| 2994 // Enabled state from false to true, should sent true. |
| 2995 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true); |
| 2996 UpdatePasswordGenerationState(false); |
| 2997 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); |
| 2998 EXPECT_TRUE(autofill_manager_->GetSentStates()[0]); |
| 2999 autofill_manager_->ClearSentStates(); |
| 3000 |
| 3001 // Enabled states remains true, should not sent. |
| 3002 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true); |
| 3003 UpdatePasswordGenerationState(false); |
| 3004 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); |
| 3005 |
| 3006 // Enabled states from true to false, should sent false. |
| 3007 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, false); |
| 3008 UpdatePasswordGenerationState(false); |
| 3009 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); |
| 3010 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); |
| 3011 autofill_manager_->ClearSentStates(); |
| 3012 |
| 3013 // When a new render_view is created, we send the state even if it's the |
| 3014 // same. |
| 3015 UpdatePasswordGenerationState(true); |
| 3016 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); |
| 3017 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); |
| 3018 autofill_manager_->ClearSentStates(); |
| 3019 } |
| 3020 |
2976 TEST_F(AutofillManagerTest, RemoveProfile) { | 3021 TEST_F(AutofillManagerTest, RemoveProfile) { |
2977 // Add and remove an Autofill profile. | 3022 // Add and remove an Autofill profile. |
2978 AutofillProfile* profile = new AutofillProfile; | 3023 AutofillProfile* profile = new AutofillProfile; |
2979 std::string guid = "00000000-0000-0000-0000-000000000102"; | 3024 std::string guid = "00000000-0000-0000-0000-000000000102"; |
2980 profile->set_guid(guid.c_str()); | 3025 profile->set_guid(guid.c_str()); |
2981 autofill_manager_->AddProfile(profile); | 3026 autofill_manager_->AddProfile(profile); |
2982 | 3027 |
2983 GUIDPair guid_pair(guid, 0); | 3028 GUIDPair guid_pair(guid, 0); |
2984 GUIDPair empty(std::string(), 0); | 3029 GUIDPair empty(std::string(), 0); |
2985 int id = PackGUIDs(empty, guid_pair); | 3030 int id = PackGUIDs(empty, guid_pair); |
(...skipping 98 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 |