| 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/api/prefs/pref_service_base.h" |
| 18 #include "chrome/browser/autofill/autocomplete_history_manager.h" | 18 #include "chrome/browser/autofill/autocomplete_history_manager.h" |
| 19 #include "chrome/browser/autofill/autofill_common_test.h" | 19 #include "chrome/browser/autofill/autofill_common_test.h" |
| 20 #include "chrome/browser/autofill/autofill_manager.h" | 20 #include "chrome/browser/autofill/autofill_manager.h" |
| 21 #include "chrome/browser/autofill/autofill_profile.h" | 21 #include "chrome/browser/autofill/autofill_profile.h" |
| 22 #include "chrome/browser/autofill/credit_card.h" | 22 #include "chrome/browser/autofill/credit_card.h" |
| 23 #include "chrome/browser/autofill/personal_data_manager.h" | 23 #include "chrome/browser/autofill/personal_data_manager.h" |
| 24 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 24 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 25 #include "chrome/browser/autofill/test_autofill_external_delegate.h" | 25 #include "chrome/browser/autofill/test_autofill_external_delegate.h" |
| 26 #include "chrome/browser/password_manager/password_manager.h" |
| 27 #include "chrome/browser/password_manager/password_manager_delegate_impl.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/sync/profile_sync_service.h" | 29 #include "chrome/browser/sync/profile_sync_service.h" |
| 28 #include "chrome/browser/sync/profile_sync_service_factory.h" | 30 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 29 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" | 31 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" |
| 30 #include "chrome/browser/ui/browser.h" | 32 #include "chrome/browser/ui/browser.h" |
| 31 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
| 32 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" | |
| 33 #include "chrome/common/autofill_messages.h" | 33 #include "chrome/common/autofill_messages.h" |
| 34 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
| 35 #include "chrome/common/form_data.h" | 35 #include "chrome/common/form_data.h" |
| 36 #include "chrome/common/form_field_data.h" | 36 #include "chrome/common/form_field_data.h" |
| 37 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
| 38 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 38 #include "chrome/test/base/testing_profile.h" | 39 #include "chrome/test/base/testing_profile.h" |
| 39 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 40 #include "content/public/test/mock_render_process_host.h" | 41 #include "content/public/test/mock_render_process_host.h" |
| 41 #include "content/public/test/test_browser_thread.h" | 42 #include "content/public/test/test_browser_thread.h" |
| 42 #include "googleurl/src/gurl.h" | 43 #include "googleurl/src/gurl.h" |
| 43 #include "grit/generated_resources.h" | 44 #include "grit/generated_resources.h" |
| 44 #include "ipc/ipc_test_sink.h" | 45 #include "ipc/ipc_test_sink.h" |
| 45 #include "testing/gmock/include/gmock/gmock.h" | 46 #include "testing/gmock/include/gmock/gmock.h" |
| 46 #include "testing/gtest/include/gtest/gtest.h" | 47 #include "testing/gtest/include/gtest/gtest.h" |
| 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 48 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 | 574 |
| 574 std::string submitted_form_signature_; | 575 std::string submitted_form_signature_; |
| 575 std::vector<FieldTypeSet> expected_submitted_field_types_; | 576 std::vector<FieldTypeSet> expected_submitted_field_types_; |
| 576 std::vector<bool> sent_states_; | 577 std::vector<bool> sent_states_; |
| 577 | 578 |
| 578 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 579 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
| 579 }; | 580 }; |
| 580 | 581 |
| 581 } // namespace | 582 } // namespace |
| 582 | 583 |
| 583 class AutofillManagerTest : public TabContentsTestHarness { | 584 class AutofillManagerTest : public ChromeRenderViewHostTestHarness { |
| 584 public: | 585 public: |
| 585 typedef AutofillManager::GUIDPair GUIDPair; | 586 typedef AutofillManager::GUIDPair GUIDPair; |
| 586 | 587 |
| 587 AutofillManagerTest() | 588 AutofillManagerTest() |
| 588 : TabContentsTestHarness(), | 589 : ChromeRenderViewHostTestHarness(), |
| 589 ui_thread_(BrowserThread::UI, &message_loop_), | 590 ui_thread_(BrowserThread::UI, &message_loop_), |
| 590 file_thread_(BrowserThread::FILE) { | 591 file_thread_(BrowserThread::FILE) { |
| 591 } | 592 } |
| 592 | 593 |
| 593 virtual ~AutofillManagerTest() { | 594 virtual ~AutofillManagerTest() { |
| 594 // Order of destruction is important as AutofillManager relies on | 595 // Order of destruction is important as AutofillManager relies on |
| 595 // PersonalDataManager to be around when it gets destroyed. | 596 // PersonalDataManager to be around when it gets destroyed. |
| 596 autofill_manager_ = NULL; | 597 autofill_manager_ = NULL; |
| 597 } | 598 } |
| 598 | 599 |
| 599 virtual void SetUp() OVERRIDE { | 600 virtual void SetUp() OVERRIDE { |
| 600 Profile* profile = new TestingProfile(); | 601 Profile* profile = new TestingProfile(); |
| 601 browser_context_.reset(profile); | 602 browser_context_.reset(profile); |
| 602 PersonalDataManagerFactory::GetInstance()->SetTestingFactory( | 603 PersonalDataManagerFactory::GetInstance()->SetTestingFactory( |
| 603 profile, TestPersonalDataManager::Build); | 604 profile, TestPersonalDataManager::Build); |
| 604 | 605 |
| 605 TabContentsTestHarness::SetUp(); | 606 ChromeRenderViewHostTestHarness::SetUp(); |
| 606 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); | 607 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); |
| 607 autofill_manager_ = new TestAutofillManager( | 608 autofill_manager_ = new TestAutofillManager( |
| 608 web_contents(), | 609 web_contents(), |
| 609 TabAutofillManagerDelegate::FromWebContents(web_contents()), | 610 TabAutofillManagerDelegate::FromWebContents(web_contents()), |
| 610 &personal_data_); | 611 &personal_data_); |
| 611 | 612 |
| 612 file_thread_.Start(); | 613 file_thread_.Start(); |
| 613 } | 614 } |
| 614 | 615 |
| 615 virtual void TearDown() OVERRIDE { | 616 virtual void TearDown() OVERRIDE { |
| 616 file_thread_.Stop(); | 617 file_thread_.Stop(); |
| 617 TabContentsTestHarness::TearDown(); | 618 ChromeRenderViewHostTestHarness::TearDown(); |
| 618 } | 619 } |
| 619 | 620 |
| 620 void UpdatePasswordGenerationState(bool new_renderer) { | 621 void UpdatePasswordGenerationState(bool new_renderer) { |
| 621 autofill_manager_->UpdatePasswordGenerationState(NULL, new_renderer); | 622 autofill_manager_->UpdatePasswordGenerationState(NULL, new_renderer); |
| 622 } | 623 } |
| 623 | 624 |
| 624 void GetAutofillSuggestions(int query_id, | 625 void GetAutofillSuggestions(int query_id, |
| 625 const FormData& form, | 626 const FormData& form, |
| 626 const FormFieldData& field) { | 627 const FormFieldData& field) { |
| 627 autofill_manager_->OnQueryFormFieldAutofill(query_id, | 628 autofill_manager_->OnQueryFormFieldAutofill(query_id, |
| (...skipping 2283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2911 types.clear(); | 2912 types.clear(); |
| 2912 types.insert(UNKNOWN_TYPE); | 2913 types.insert(UNKNOWN_TYPE); |
| 2913 form.fields.push_back(field); | 2914 form.fields.push_back(field); |
| 2914 expected_types.push_back(types); | 2915 expected_types.push_back(types); |
| 2915 | 2916 |
| 2916 autofill_manager_->set_expected_submitted_field_types(expected_types); | 2917 autofill_manager_->set_expected_submitted_field_types(expected_types); |
| 2917 FormSubmitted(form); | 2918 FormSubmitted(form); |
| 2918 } | 2919 } |
| 2919 | 2920 |
| 2920 TEST_F(AutofillManagerTest, UpdatePasswordSyncState) { | 2921 TEST_F(AutofillManagerTest, UpdatePasswordSyncState) { |
| 2922 PasswordManagerDelegateImpl::CreateForWebContents(web_contents()); |
| 2923 PasswordManager::CreateForWebContentsAndDelegate( |
| 2924 web_contents(), |
| 2925 PasswordManagerDelegateImpl::FromWebContents(web_contents())); |
| 2926 |
| 2921 PrefServiceBase* prefs = PrefServiceBase::FromBrowserContext(profile()); | 2927 PrefServiceBase* prefs = PrefServiceBase::FromBrowserContext(profile()); |
| 2922 | 2928 |
| 2923 // Allow this test to control what should get synced. | 2929 // Allow this test to control what should get synced. |
| 2924 prefs->SetBoolean(prefs::kSyncKeepEverythingSynced, false); | 2930 prefs->SetBoolean(prefs::kSyncKeepEverythingSynced, false); |
| 2925 // Always set password generation enabled check box so we can test the | 2931 // Always set password generation enabled check box so we can test the |
| 2926 // behavior of password sync. | 2932 // behavior of password sync. |
| 2927 prefs->SetBoolean(prefs::kPasswordGenerationEnabled, true); | 2933 prefs->SetBoolean(prefs::kPasswordGenerationEnabled, true); |
| 2928 | 2934 |
| 2929 // Sync some things, but not passwords. Shouldn't send anything since | 2935 // Sync some things, but not passwords. Shouldn't send anything since |
| 2930 // password generation is disabled by default. | 2936 // password generation is disabled by default. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2969 | 2975 |
| 2970 // When a new render_view is created, we send the state even if it's the | 2976 // When a new render_view is created, we send the state even if it's the |
| 2971 // same. | 2977 // same. |
| 2972 UpdatePasswordGenerationState(true); | 2978 UpdatePasswordGenerationState(true); |
| 2973 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); | 2979 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); |
| 2974 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); | 2980 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); |
| 2975 autofill_manager_->ClearSentStates(); | 2981 autofill_manager_->ClearSentStates(); |
| 2976 } | 2982 } |
| 2977 | 2983 |
| 2978 TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) { | 2984 TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) { |
| 2985 PasswordManagerDelegateImpl::CreateForWebContents(web_contents()); |
| 2986 PasswordManager::CreateForWebContentsAndDelegate( |
| 2987 web_contents(), |
| 2988 PasswordManagerDelegateImpl::FromWebContents(web_contents())); |
| 2989 |
| 2979 PrefServiceBase* prefs = PrefServiceBase::FromBrowserContext(profile()); | 2990 PrefServiceBase* prefs = PrefServiceBase::FromBrowserContext(profile()); |
| 2980 | 2991 |
| 2981 // Always set password sync enabled so we can test the behavior of password | 2992 // Always set password sync enabled so we can test the behavior of password |
| 2982 // generation. | 2993 // generation. |
| 2983 prefs->SetBoolean(prefs::kSyncKeepEverythingSynced, false); | 2994 prefs->SetBoolean(prefs::kSyncKeepEverythingSynced, false); |
| 2984 ProfileSyncService* sync_service = ProfileSyncServiceFactory::GetForProfile( | 2995 ProfileSyncService* sync_service = ProfileSyncServiceFactory::GetForProfile( |
| 2985 profile()); | 2996 profile()); |
| 2986 sync_service->SetSyncSetupCompleted(); | 2997 sync_service->SetSyncSetupCompleted(); |
| 2987 syncer::ModelTypeSet preferred_set; | 2998 syncer::ModelTypeSet preferred_set; |
| 2988 preferred_set.Put(syncer::PASSWORDS); | 2999 preferred_set.Put(syncer::PASSWORDS); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3132 AutofillManager* autofill_manager = | 3143 AutofillManager* autofill_manager = |
| 3133 AutofillManager::FromWebContents(contents); | 3144 AutofillManager::FromWebContents(contents); |
| 3134 EXPECT_TRUE(autofill_manager->external_delegate()); | 3145 EXPECT_TRUE(autofill_manager->external_delegate()); |
| 3135 | 3146 |
| 3136 AutocompleteHistoryManager* autocomplete_history_manager = | 3147 AutocompleteHistoryManager* autocomplete_history_manager = |
| 3137 AutocompleteHistoryManager::FromWebContents(contents); | 3148 AutocompleteHistoryManager::FromWebContents(contents); |
| 3138 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); | 3149 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); |
| 3139 } | 3150 } |
| 3140 | 3151 |
| 3141 #endif // OS_ANDROID | 3152 #endif // OS_ANDROID |
| OLD | NEW |