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 20 matching lines...) Expand all Loading... |
31 #include "chrome/browser/sync/profile_sync_service_factory.h" | 31 #include "chrome/browser/sync/profile_sync_service_factory.h" |
32 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" | 32 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" |
33 #include "chrome/browser/ui/browser.h" | 33 #include "chrome/browser/ui/browser.h" |
34 #include "chrome/common/autofill_messages.h" | 34 #include "chrome/common/autofill_messages.h" |
35 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
36 #include "chrome/common/form_data.h" | 36 #include "chrome/common/form_data.h" |
37 #include "chrome/common/form_field_data.h" | 37 #include "chrome/common/form_field_data.h" |
38 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
39 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 39 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
40 #include "chrome/test/base/testing_profile.h" | 40 #include "chrome/test/base/testing_profile.h" |
| 41 #include "components/user_prefs/user_prefs.h" |
41 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
42 #include "content/public/common/ssl_status.h" | 43 #include "content/public/common/ssl_status.h" |
43 #include "content/public/test/mock_render_process_host.h" | 44 #include "content/public/test/mock_render_process_host.h" |
44 #include "content/public/test/test_browser_thread.h" | 45 #include "content/public/test/test_browser_thread.h" |
45 #include "googleurl/src/gurl.h" | 46 #include "googleurl/src/gurl.h" |
46 #include "grit/generated_resources.h" | 47 #include "grit/generated_resources.h" |
47 #include "ipc/ipc_test_sink.h" | 48 #include "ipc/ipc_test_sink.h" |
48 #include "testing/gmock/include/gmock/gmock.h" | 49 #include "testing/gmock/include/gmock/gmock.h" |
49 #include "testing/gtest/include/gtest/gtest.h" | 50 #include "testing/gtest/include/gtest/gtest.h" |
50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 51 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
(...skipping 1750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1801 | 1802 |
1802 int page_id = 0; | 1803 int page_id = 0; |
1803 FormData results; | 1804 FormData results; |
1804 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | 1805 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); |
1805 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); | 1806 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); |
1806 } | 1807 } |
1807 | 1808 |
1808 // Test that we correctly fill an address form from an auxiliary profile. | 1809 // Test that we correctly fill an address form from an auxiliary profile. |
1809 TEST_F(AutofillManagerTest, FillAddressFormFromAuxiliaryProfile) { | 1810 TEST_F(AutofillManagerTest, FillAddressFormFromAuxiliaryProfile) { |
1810 personal_data_.ClearAutofillProfiles(); | 1811 personal_data_.ClearAutofillProfiles(); |
1811 PrefService* prefs = PrefServiceFromBrowserContext(profile()); | 1812 PrefService* prefs = components::UserPrefs::Get(profile()); |
1812 prefs->SetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled, true); | 1813 prefs->SetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled, true); |
1813 personal_data_.CreateTestAuxiliaryProfiles(); | 1814 personal_data_.CreateTestAuxiliaryProfiles(); |
1814 | 1815 |
1815 // Set up our form data. | 1816 // Set up our form data. |
1816 FormData form; | 1817 FormData form; |
1817 CreateTestAddressFormData(&form); | 1818 CreateTestAddressFormData(&form); |
1818 std::vector<FormData> forms(1, form); | 1819 std::vector<FormData> forms(1, form); |
1819 FormsSeen(forms); | 1820 FormsSeen(forms); |
1820 | 1821 |
1821 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 1822 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2695 | 2696 |
2696 // Simulate form submission. We should not call into the PDM to try to save | 2697 // Simulate form submission. We should not call into the PDM to try to save |
2697 // the filled data, since the filled form is effectively missing an address. | 2698 // the filled data, since the filled form is effectively missing an address. |
2698 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(0); | 2699 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(0); |
2699 FormSubmitted(results); | 2700 FormSubmitted(results); |
2700 } | 2701 } |
2701 | 2702 |
2702 // Checks that resetting the auxiliary profile enabled preference does the right | 2703 // Checks that resetting the auxiliary profile enabled preference does the right |
2703 // thing on all platforms. | 2704 // thing on all platforms. |
2704 TEST_F(AutofillManagerTest, AuxiliaryProfilesReset) { | 2705 TEST_F(AutofillManagerTest, AuxiliaryProfilesReset) { |
2705 PrefService* prefs = PrefServiceFromBrowserContext(profile()); | 2706 PrefService* prefs = components::UserPrefs::Get(profile()); |
2706 #if defined(OS_MACOSX) | 2707 #if defined(OS_MACOSX) |
2707 // Auxiliary profiles is implemented on Mac only. It enables Mac Address | 2708 // Auxiliary profiles is implemented on Mac only. It enables Mac Address |
2708 // Book integration. | 2709 // Book integration. |
2709 ASSERT_TRUE(prefs->GetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled)); | 2710 ASSERT_TRUE(prefs->GetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled)); |
2710 prefs->SetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled, false); | 2711 prefs->SetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled, false); |
2711 prefs->ClearPref(prefs::kAutofillAuxiliaryProfilesEnabled); | 2712 prefs->ClearPref(prefs::kAutofillAuxiliaryProfilesEnabled); |
2712 ASSERT_TRUE(prefs->GetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled)); | 2713 ASSERT_TRUE(prefs->GetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled)); |
2713 #else | 2714 #else |
2714 ASSERT_FALSE(prefs->GetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled)); | 2715 ASSERT_FALSE(prefs->GetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled)); |
2715 prefs->SetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled, true); | 2716 prefs->SetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled, true); |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2996 autofill_manager_->set_expected_submitted_field_types(expected_types); | 2997 autofill_manager_->set_expected_submitted_field_types(expected_types); |
2997 FormSubmitted(form); | 2998 FormSubmitted(form); |
2998 } | 2999 } |
2999 | 3000 |
3000 TEST_F(AutofillManagerTest, UpdatePasswordSyncState) { | 3001 TEST_F(AutofillManagerTest, UpdatePasswordSyncState) { |
3001 PasswordManagerDelegateImpl::CreateForWebContents(web_contents()); | 3002 PasswordManagerDelegateImpl::CreateForWebContents(web_contents()); |
3002 PasswordManager::CreateForWebContentsAndDelegate( | 3003 PasswordManager::CreateForWebContentsAndDelegate( |
3003 web_contents(), | 3004 web_contents(), |
3004 PasswordManagerDelegateImpl::FromWebContents(web_contents())); | 3005 PasswordManagerDelegateImpl::FromWebContents(web_contents())); |
3005 | 3006 |
3006 PrefService* prefs = PrefServiceFromBrowserContext(profile()); | 3007 PrefService* prefs = components::UserPrefs::Get(profile()); |
3007 | 3008 |
3008 // Allow this test to control what should get synced. | 3009 // Allow this test to control what should get synced. |
3009 prefs->SetBoolean(prefs::kSyncKeepEverythingSynced, false); | 3010 prefs->SetBoolean(prefs::kSyncKeepEverythingSynced, false); |
3010 // Always set password generation enabled check box so we can test the | 3011 // Always set password generation enabled check box so we can test the |
3011 // behavior of password sync. | 3012 // behavior of password sync. |
3012 prefs->SetBoolean(prefs::kPasswordGenerationEnabled, true); | 3013 prefs->SetBoolean(prefs::kPasswordGenerationEnabled, true); |
3013 | 3014 |
3014 // Sync some things, but not passwords. Shouldn't send anything since | 3015 // Sync some things, but not passwords. Shouldn't send anything since |
3015 // password generation is disabled by default. | 3016 // password generation is disabled by default. |
3016 ProfileSyncService* sync_service = ProfileSyncServiceFactory::GetForProfile( | 3017 ProfileSyncService* sync_service = ProfileSyncServiceFactory::GetForProfile( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3054 } | 3055 } |
3055 | 3056 |
3056 TEST_F(IncognitoAutofillManagerTest, UpdatePasswordSyncStateIncognito) { | 3057 TEST_F(IncognitoAutofillManagerTest, UpdatePasswordSyncStateIncognito) { |
3057 // Disable password manager by going incognito, and enable syncing. The | 3058 // Disable password manager by going incognito, and enable syncing. The |
3058 // feature should still be disabled, and nothing will be sent. | 3059 // feature should still be disabled, and nothing will be sent. |
3059 PasswordManagerDelegateImpl::CreateForWebContents(web_contents()); | 3060 PasswordManagerDelegateImpl::CreateForWebContents(web_contents()); |
3060 PasswordManager::CreateForWebContentsAndDelegate( | 3061 PasswordManager::CreateForWebContentsAndDelegate( |
3061 web_contents(), | 3062 web_contents(), |
3062 PasswordManagerDelegateImpl::FromWebContents(web_contents())); | 3063 PasswordManagerDelegateImpl::FromWebContents(web_contents())); |
3063 | 3064 |
3064 PrefService* prefs = PrefServiceFromBrowserContext(profile()); | 3065 PrefService* prefs = components::UserPrefs::Get(profile()); |
3065 | 3066 |
3066 // Allow this test to control what should get synced. | 3067 // Allow this test to control what should get synced. |
3067 prefs->SetBoolean(prefs::kSyncKeepEverythingSynced, false); | 3068 prefs->SetBoolean(prefs::kSyncKeepEverythingSynced, false); |
3068 // Always set password generation enabled check box so we can test the | 3069 // Always set password generation enabled check box so we can test the |
3069 // behavior of password sync. | 3070 // behavior of password sync. |
3070 prefs->SetBoolean(prefs::kPasswordGenerationEnabled, true); | 3071 prefs->SetBoolean(prefs::kPasswordGenerationEnabled, true); |
3071 | 3072 |
3072 browser_sync::SyncPrefs sync_prefs(profile()->GetPrefs()); | 3073 browser_sync::SyncPrefs sync_prefs(profile()->GetPrefs()); |
3073 sync_prefs.SetSyncSetupCompleted(); | 3074 sync_prefs.SetSyncSetupCompleted(); |
3074 UpdatePasswordGenerationState(false); | 3075 UpdatePasswordGenerationState(false); |
3075 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); | 3076 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); |
3076 } | 3077 } |
3077 | 3078 |
3078 TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) { | 3079 TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) { |
3079 PasswordManagerDelegateImpl::CreateForWebContents(web_contents()); | 3080 PasswordManagerDelegateImpl::CreateForWebContents(web_contents()); |
3080 PasswordManager::CreateForWebContentsAndDelegate( | 3081 PasswordManager::CreateForWebContentsAndDelegate( |
3081 web_contents(), | 3082 web_contents(), |
3082 PasswordManagerDelegateImpl::FromWebContents(web_contents())); | 3083 PasswordManagerDelegateImpl::FromWebContents(web_contents())); |
3083 | 3084 |
3084 PrefService* prefs = PrefServiceFromBrowserContext(profile()); | 3085 PrefService* prefs = components::UserPrefs::Get(profile()); |
3085 | 3086 |
3086 // Always set password sync enabled so we can test the behavior of password | 3087 // Always set password sync enabled so we can test the behavior of password |
3087 // generation. | 3088 // generation. |
3088 prefs->SetBoolean(prefs::kSyncKeepEverythingSynced, false); | 3089 prefs->SetBoolean(prefs::kSyncKeepEverythingSynced, false); |
3089 ProfileSyncService* sync_service = ProfileSyncServiceFactory::GetForProfile( | 3090 ProfileSyncService* sync_service = ProfileSyncServiceFactory::GetForProfile( |
3090 profile()); | 3091 profile()); |
3091 sync_service->SetSyncSetupCompleted(); | 3092 sync_service->SetSyncSetupCompleted(); |
3092 syncer::ModelTypeSet preferred_set; | 3093 syncer::ModelTypeSet preferred_set; |
3093 preferred_set.Put(syncer::PASSWORDS); | 3094 preferred_set.Put(syncer::PASSWORDS); |
3094 sync_service->ChangePreferredDataTypes(preferred_set); | 3095 sync_service->ChangePreferredDataTypes(preferred_set); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3219 | 3220 |
3220 FormData form; | 3221 FormData form; |
3221 CreateTestAddressFormData(&form); | 3222 CreateTestAddressFormData(&form); |
3222 std::vector<FormData> forms(1, form); | 3223 std::vector<FormData> forms(1, form); |
3223 FormsSeen(forms); | 3224 FormsSeen(forms); |
3224 const FormFieldData& field = form.fields[0]; | 3225 const FormFieldData& field = form.fields[0]; |
3225 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3226 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
3226 | 3227 |
3227 autofill_manager_->SetExternalDelegate(NULL); | 3228 autofill_manager_->SetExternalDelegate(NULL); |
3228 } | 3229 } |
OLD | NEW |