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" |
11 #include "base/string16.h" | 11 #include "base/string16.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "base/tuple.h" | 15 #include "base/tuple.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/api/prefs/pref_service_base.h" |
17 #include "chrome/browser/autofill/autocomplete_history_manager.h" | 18 #include "chrome/browser/autofill/autocomplete_history_manager.h" |
18 #include "chrome/browser/autofill/autofill_common_test.h" | 19 #include "chrome/browser/autofill/autofill_common_test.h" |
19 #include "chrome/browser/autofill/autofill_manager.h" | 20 #include "chrome/browser/autofill/autofill_manager.h" |
20 #include "chrome/browser/autofill/autofill_profile.h" | 21 #include "chrome/browser/autofill/autofill_profile.h" |
21 #include "chrome/browser/autofill/credit_card.h" | 22 #include "chrome/browser/autofill/credit_card.h" |
22 #include "chrome/browser/autofill/personal_data_manager.h" | 23 #include "chrome/browser/autofill/personal_data_manager.h" |
23 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 24 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
24 #include "chrome/browser/autofill/test_autofill_external_delegate.h" | 25 #include "chrome/browser/autofill/test_autofill_external_delegate.h" |
25 #include "chrome/browser/prefs/pref_service.h" | |
26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/browser/sync/profile_sync_service.h" | 27 #include "chrome/browser/sync/profile_sync_service.h" |
28 #include "chrome/browser/sync/profile_sync_service_factory.h" | 28 #include "chrome/browser/sync/profile_sync_service_factory.h" |
29 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
30 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 30 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
31 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" | 31 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" |
32 #include "chrome/common/autofill_messages.h" | 32 #include "chrome/common/autofill_messages.h" |
33 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
34 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
35 #include "chrome/test/base/testing_profile.h" | 35 #include "chrome/test/base/testing_profile.h" |
(...skipping 2575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2611 | 2611 |
2612 // Simulate form submission. We should not call into the PDM to try to save | 2612 // Simulate form submission. We should not call into the PDM to try to save |
2613 // the filled data, since the filled form is effectively missing an address. | 2613 // the filled data, since the filled form is effectively missing an address. |
2614 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(0); | 2614 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(0); |
2615 FormSubmitted(results); | 2615 FormSubmitted(results); |
2616 } | 2616 } |
2617 | 2617 |
2618 // Checks that resetting the auxiliary profile enabled preference does the right | 2618 // Checks that resetting the auxiliary profile enabled preference does the right |
2619 // thing on all platforms. | 2619 // thing on all platforms. |
2620 TEST_F(AutofillManagerTest, AuxiliaryProfilesReset) { | 2620 TEST_F(AutofillManagerTest, AuxiliaryProfilesReset) { |
| 2621 PrefServiceBase* prefs = PrefServiceBase::ForProfile(profile()); |
2621 #if defined(OS_MACOSX) | 2622 #if defined(OS_MACOSX) |
2622 // Auxiliary profiles is implemented on Mac only. It enables Mac Address | 2623 // Auxiliary profiles is implemented on Mac only. It enables Mac Address |
2623 // Book integration. | 2624 // Book integration. |
2624 ASSERT_TRUE(profile()->GetPrefs()->GetBoolean( | 2625 ASSERT_TRUE(prefs->GetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled)); |
2625 prefs::kAutofillAuxiliaryProfilesEnabled)); | 2626 prefs->SetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled, false); |
2626 profile()->GetPrefs()->SetBoolean( | 2627 prefs->ClearPref(prefs::kAutofillAuxiliaryProfilesEnabled); |
2627 prefs::kAutofillAuxiliaryProfilesEnabled, false); | 2628 ASSERT_TRUE(prefs->GetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled)); |
2628 profile()->GetPrefs()->ClearPref(prefs::kAutofillAuxiliaryProfilesEnabled); | |
2629 ASSERT_TRUE(profile()->GetPrefs()->GetBoolean( | |
2630 prefs::kAutofillAuxiliaryProfilesEnabled)); | |
2631 #else | 2629 #else |
2632 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( | 2630 ASSERT_FALSE(prefs->GetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled)); |
2633 prefs::kAutofillAuxiliaryProfilesEnabled)); | 2631 prefs->SetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled, true); |
2634 profile()->GetPrefs()->SetBoolean( | 2632 prefs->ClearPref(prefs::kAutofillAuxiliaryProfilesEnabled); |
2635 prefs::kAutofillAuxiliaryProfilesEnabled, true); | 2633 ASSERT_FALSE(prefs->GetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled)); |
2636 profile()->GetPrefs()->ClearPref(prefs::kAutofillAuxiliaryProfilesEnabled); | |
2637 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( | |
2638 prefs::kAutofillAuxiliaryProfilesEnabled)); | |
2639 #endif | 2634 #endif |
2640 } | 2635 } |
2641 | 2636 |
2642 TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload) { | 2637 TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload) { |
2643 FormData form; | 2638 FormData form; |
2644 form.name = ASCIIToUTF16("MyForm"); | 2639 form.name = ASCIIToUTF16("MyForm"); |
2645 form.method = ASCIIToUTF16("POST"); | 2640 form.method = ASCIIToUTF16("POST"); |
2646 form.origin = GURL("http://myform.com/form.html"); | 2641 form.origin = GURL("http://myform.com/form.html"); |
2647 form.action = GURL("http://myform.com/submit.html"); | 2642 form.action = GURL("http://myform.com/submit.html"); |
2648 form.user_submitted = true; | 2643 form.user_submitted = true; |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2912 types.clear(); | 2907 types.clear(); |
2913 types.insert(UNKNOWN_TYPE); | 2908 types.insert(UNKNOWN_TYPE); |
2914 form.fields.push_back(field); | 2909 form.fields.push_back(field); |
2915 expected_types.push_back(types); | 2910 expected_types.push_back(types); |
2916 | 2911 |
2917 autofill_manager_->set_expected_submitted_field_types(expected_types); | 2912 autofill_manager_->set_expected_submitted_field_types(expected_types); |
2918 FormSubmitted(form); | 2913 FormSubmitted(form); |
2919 } | 2914 } |
2920 | 2915 |
2921 TEST_F(AutofillManagerTest, UpdatePasswordSyncState) { | 2916 TEST_F(AutofillManagerTest, UpdatePasswordSyncState) { |
| 2917 PrefServiceBase* prefs = PrefServiceBase::ForProfile(profile()); |
| 2918 |
2922 // Allow this test to control what should get synced. | 2919 // Allow this test to control what should get synced. |
2923 profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); | 2920 prefs->SetBoolean(prefs::kSyncKeepEverythingSynced, false); |
2924 // Always set password generation enabled check box so we can test the | 2921 // Always set password generation enabled check box so we can test the |
2925 // behavior of password sync. | 2922 // behavior of password sync. |
2926 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true); | 2923 prefs->SetBoolean(prefs::kPasswordGenerationEnabled, true); |
2927 | 2924 |
2928 // Sync some things, but not passwords. Shouldn't send anything since | 2925 // Sync some things, but not passwords. Shouldn't send anything since |
2929 // password generation is disabled by default. | 2926 // password generation is disabled by default. |
2930 ProfileSyncService* sync_service = ProfileSyncServiceFactory::GetForProfile( | 2927 ProfileSyncService* sync_service = ProfileSyncServiceFactory::GetForProfile( |
2931 profile()); | 2928 profile()); |
2932 sync_service->SetSyncSetupCompleted(); | 2929 sync_service->SetSyncSetupCompleted(); |
2933 syncer::ModelTypeSet preferred_set; | 2930 syncer::ModelTypeSet preferred_set; |
2934 preferred_set.Put(syncer::EXTENSIONS); | 2931 preferred_set.Put(syncer::EXTENSIONS); |
2935 preferred_set.Put(syncer::PREFERENCES); | 2932 preferred_set.Put(syncer::PREFERENCES); |
2936 sync_service->ChangePreferredDataTypes(preferred_set); | 2933 sync_service->ChangePreferredDataTypes(preferred_set); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2968 | 2965 |
2969 // When a new render_view is created, we send the state even if it's the | 2966 // When a new render_view is created, we send the state even if it's the |
2970 // same. | 2967 // same. |
2971 UpdatePasswordGenerationState(true); | 2968 UpdatePasswordGenerationState(true); |
2972 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); | 2969 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); |
2973 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); | 2970 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); |
2974 autofill_manager_->ClearSentStates(); | 2971 autofill_manager_->ClearSentStates(); |
2975 } | 2972 } |
2976 | 2973 |
2977 TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) { | 2974 TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) { |
| 2975 PrefServiceBase* prefs = PrefServiceBase::ForProfile(profile()); |
| 2976 |
2978 // Always set password sync enabled so we can test the behavior of password | 2977 // Always set password sync enabled so we can test the behavior of password |
2979 // generation. | 2978 // generation. |
2980 profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); | 2979 prefs->SetBoolean(prefs::kSyncKeepEverythingSynced, false); |
2981 ProfileSyncService* sync_service = ProfileSyncServiceFactory::GetForProfile( | 2980 ProfileSyncService* sync_service = ProfileSyncServiceFactory::GetForProfile( |
2982 profile()); | 2981 profile()); |
2983 sync_service->SetSyncSetupCompleted(); | 2982 sync_service->SetSyncSetupCompleted(); |
2984 syncer::ModelTypeSet preferred_set; | 2983 syncer::ModelTypeSet preferred_set; |
2985 preferred_set.Put(syncer::PASSWORDS); | 2984 preferred_set.Put(syncer::PASSWORDS); |
2986 sync_service->ChangePreferredDataTypes(preferred_set); | 2985 sync_service->ChangePreferredDataTypes(preferred_set); |
2987 | 2986 |
2988 // Enabled state remains false, should not sent. | 2987 // Enabled state remains false, should not sent. |
2989 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, false); | 2988 prefs->SetBoolean(prefs::kPasswordGenerationEnabled, false); |
2990 UpdatePasswordGenerationState(false); | 2989 UpdatePasswordGenerationState(false); |
2991 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); | 2990 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); |
2992 | 2991 |
2993 // Enabled state from false to true, should sent true. | 2992 // Enabled state from false to true, should sent true. |
2994 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true); | 2993 prefs->SetBoolean(prefs::kPasswordGenerationEnabled, true); |
2995 UpdatePasswordGenerationState(false); | 2994 UpdatePasswordGenerationState(false); |
2996 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); | 2995 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); |
2997 EXPECT_TRUE(autofill_manager_->GetSentStates()[0]); | 2996 EXPECT_TRUE(autofill_manager_->GetSentStates()[0]); |
2998 autofill_manager_->ClearSentStates(); | 2997 autofill_manager_->ClearSentStates(); |
2999 | 2998 |
3000 // Enabled states remains true, should not sent. | 2999 // Enabled states remains true, should not sent. |
3001 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true); | 3000 prefs->SetBoolean(prefs::kPasswordGenerationEnabled, true); |
3002 UpdatePasswordGenerationState(false); | 3001 UpdatePasswordGenerationState(false); |
3003 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); | 3002 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); |
3004 | 3003 |
3005 // Enabled states from true to false, should sent false. | 3004 // Enabled states from true to false, should sent false. |
3006 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, false); | 3005 prefs->SetBoolean(prefs::kPasswordGenerationEnabled, false); |
3007 UpdatePasswordGenerationState(false); | 3006 UpdatePasswordGenerationState(false); |
3008 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); | 3007 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); |
3009 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); | 3008 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); |
3010 autofill_manager_->ClearSentStates(); | 3009 autofill_manager_->ClearSentStates(); |
3011 | 3010 |
3012 // When a new render_view is created, we send the state even if it's the | 3011 // When a new render_view is created, we send the state even if it's the |
3013 // same. | 3012 // same. |
3014 UpdatePasswordGenerationState(true); | 3013 UpdatePasswordGenerationState(true); |
3015 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); | 3014 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); |
3016 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); | 3015 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3128 | 3127 |
3129 AutofillManager* autofill_manager = tab_contents()->autofill_manager(); | 3128 AutofillManager* autofill_manager = tab_contents()->autofill_manager(); |
3130 EXPECT_TRUE(autofill_manager->external_delegate()); | 3129 EXPECT_TRUE(autofill_manager->external_delegate()); |
3131 | 3130 |
3132 AutocompleteHistoryManager* autocomplete_history_manager = | 3131 AutocompleteHistoryManager* autocomplete_history_manager = |
3133 tab_contents()->autocomplete_history_manager(); | 3132 tab_contents()->autocomplete_history_manager(); |
3134 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); | 3133 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); |
3135 } | 3134 } |
3136 | 3135 |
3137 #endif // OS_ANDROID | 3136 #endif // OS_ANDROID |
OLD | NEW |