| 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 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 AutofillManagerTest() | 617 AutofillManagerTest() |
| 618 : ChromeRenderViewHostTestHarness(), | 618 : ChromeRenderViewHostTestHarness(), |
| 619 ui_thread_(BrowserThread::UI, &message_loop_), | 619 ui_thread_(BrowserThread::UI, &message_loop_), |
| 620 file_thread_(BrowserThread::FILE) { | 620 file_thread_(BrowserThread::FILE) { |
| 621 } | 621 } |
| 622 | 622 |
| 623 virtual ~AutofillManagerTest() { | 623 virtual ~AutofillManagerTest() { |
| 624 } | 624 } |
| 625 | 625 |
| 626 virtual void SetUp() OVERRIDE { | 626 virtual void SetUp() OVERRIDE { |
| 627 Profile* profile = new TestingProfile(); | 627 Profile* profile = CreateProfile(); |
| 628 browser_context_.reset(profile); | 628 browser_context_.reset(profile); |
| 629 PersonalDataManagerFactory::GetInstance()->SetTestingFactory( | 629 PersonalDataManagerFactory::GetInstance()->SetTestingFactory( |
| 630 profile, TestPersonalDataManager::Build); | 630 profile, TestPersonalDataManager::Build); |
| 631 | 631 |
| 632 ChromeRenderViewHostTestHarness::SetUp(); | 632 ChromeRenderViewHostTestHarness::SetUp(); |
| 633 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); | 633 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); |
| 634 personal_data_.SetBrowserContext(profile); | 634 personal_data_.SetBrowserContext(profile); |
| 635 autofill_manager_ = new TestAutofillManager( | 635 autofill_manager_ = new TestAutofillManager( |
| 636 web_contents(), | 636 web_contents(), |
| 637 TabAutofillManagerDelegate::FromWebContents(web_contents()), | 637 TabAutofillManagerDelegate::FromWebContents(web_contents()), |
| 638 &personal_data_); | 638 &personal_data_); |
| 639 | 639 |
| 640 file_thread_.Start(); | 640 file_thread_.Start(); |
| 641 } | 641 } |
| 642 | 642 |
| 643 virtual void TearDown() OVERRIDE { | 643 virtual void TearDown() OVERRIDE { |
| 644 // Order of destruction is important as AutofillManager relies on | 644 // Order of destruction is important as AutofillManager relies on |
| 645 // PersonalDataManager to be around when it gets destroyed. Also, a real | 645 // PersonalDataManager to be around when it gets destroyed. Also, a real |
| 646 // AutofillManager is tied to the lifetime of the WebContents, so it must | 646 // AutofillManager is tied to the lifetime of the WebContents, so it must |
| 647 // be destroyed at the destruction of the WebContents. | 647 // be destroyed at the destruction of the WebContents. |
| 648 autofill_manager_ = NULL; | 648 autofill_manager_ = NULL; |
| 649 file_thread_.Stop(); | 649 file_thread_.Stop(); |
| 650 ChromeRenderViewHostTestHarness::TearDown(); | 650 ChromeRenderViewHostTestHarness::TearDown(); |
| 651 } | 651 } |
| 652 | 652 |
| 653 virtual TestingProfile* CreateProfile() { |
| 654 return new TestingProfile(); |
| 655 } |
| 656 |
| 653 void UpdatePasswordGenerationState(bool new_renderer) { | 657 void UpdatePasswordGenerationState(bool new_renderer) { |
| 654 autofill_manager_->UpdatePasswordGenerationState(NULL, new_renderer); | 658 autofill_manager_->UpdatePasswordGenerationState(NULL, new_renderer); |
| 655 } | 659 } |
| 656 | 660 |
| 657 void GetAutofillSuggestions(int query_id, | 661 void GetAutofillSuggestions(int query_id, |
| 658 const FormData& form, | 662 const FormData& form, |
| 659 const FormFieldData& field) { | 663 const FormFieldData& field) { |
| 660 autofill_manager_->OnQueryFormFieldAutofill(query_id, | 664 autofill_manager_->OnQueryFormFieldAutofill(query_id, |
| 661 form, | 665 form, |
| 662 field, | 666 field, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 TestPersonalDataManager personal_data_; | 755 TestPersonalDataManager personal_data_; |
| 752 | 756 |
| 753 // Used when we want an off the record profile. This will store the original | 757 // Used when we want an off the record profile. This will store the original |
| 754 // profile from which the off the record profile is derived. | 758 // profile from which the off the record profile is derived. |
| 755 scoped_ptr<Profile> other_browser_context_; | 759 scoped_ptr<Profile> other_browser_context_; |
| 756 | 760 |
| 757 private: | 761 private: |
| 758 DISALLOW_COPY_AND_ASSIGN(AutofillManagerTest); | 762 DISALLOW_COPY_AND_ASSIGN(AutofillManagerTest); |
| 759 }; | 763 }; |
| 760 | 764 |
| 765 class IncognitoAutofillManagerTest : public AutofillManagerTest { |
| 766 public: |
| 767 IncognitoAutofillManagerTest() {} |
| 768 virtual ~IncognitoAutofillManagerTest() {} |
| 769 |
| 770 virtual TestingProfile* CreateProfile() OVERRIDE { |
| 771 // Create an incognito profile. |
| 772 TestingProfile::Builder builder; |
| 773 builder.SetOffTheRecord(); |
| 774 return builder.Build().release(); |
| 775 } |
| 776 }; |
| 777 |
| 761 class TestFormStructure : public FormStructure { | 778 class TestFormStructure : public FormStructure { |
| 762 public: | 779 public: |
| 763 explicit TestFormStructure(const FormData& form) : FormStructure(form) {} | 780 explicit TestFormStructure(const FormData& form) : FormStructure(form) {} |
| 764 virtual ~TestFormStructure() {} | 781 virtual ~TestFormStructure() {} |
| 765 | 782 |
| 766 void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types, | 783 void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types, |
| 767 const std::vector<AutofillFieldType>& server_types) { | 784 const std::vector<AutofillFieldType>& server_types) { |
| 768 ASSERT_EQ(field_count(), heuristic_types.size()); | 785 ASSERT_EQ(field_count(), heuristic_types.size()); |
| 769 ASSERT_EQ(field_count(), server_types.size()); | 786 ASSERT_EQ(field_count(), server_types.size()); |
| 770 | 787 |
| (...skipping 2299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3070 UpdatePasswordGenerationState(false); | 3087 UpdatePasswordGenerationState(false); |
| 3071 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); | 3088 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); |
| 3072 | 3089 |
| 3073 // Disable syncing. This should disable the feature. | 3090 // Disable syncing. This should disable the feature. |
| 3074 sync_service->DisableForUser(); | 3091 sync_service->DisableForUser(); |
| 3075 UpdatePasswordGenerationState(false); | 3092 UpdatePasswordGenerationState(false); |
| 3076 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); | 3093 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); |
| 3077 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); | 3094 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); |
| 3078 autofill_manager_->ClearSentStates(); | 3095 autofill_manager_->ClearSentStates(); |
| 3079 | 3096 |
| 3080 // Disable password manager by going incognito, and re-enable syncing. The | |
| 3081 // feature should still be disabled, and nothing will be sent. | |
| 3082 sync_service->SetSyncSetupCompleted(); | |
| 3083 profile()->set_incognito(true); | |
| 3084 UpdatePasswordGenerationState(false); | |
| 3085 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); | |
| 3086 | |
| 3087 // When a new render_view is created, we send the state even if it's the | 3097 // When a new render_view is created, we send the state even if it's the |
| 3088 // same. | 3098 // same. |
| 3089 UpdatePasswordGenerationState(true); | 3099 UpdatePasswordGenerationState(true); |
| 3090 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); | 3100 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); |
| 3091 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); | 3101 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); |
| 3092 autofill_manager_->ClearSentStates(); | 3102 autofill_manager_->ClearSentStates(); |
| 3093 } | 3103 } |
| 3094 | 3104 |
| 3105 TEST_F(IncognitoAutofillManagerTest, UpdatePasswordSyncStateIncognito) { |
| 3106 // Disable password manager by going incognito, and enable syncing. The |
| 3107 // feature should still be disabled, and nothing will be sent. |
| 3108 PasswordManagerDelegateImpl::CreateForWebContents(web_contents()); |
| 3109 PasswordManager::CreateForWebContentsAndDelegate( |
| 3110 web_contents(), |
| 3111 PasswordManagerDelegateImpl::FromWebContents(web_contents())); |
| 3112 |
| 3113 PrefServiceBase* prefs = PrefServiceBase::FromBrowserContext(profile()); |
| 3114 |
| 3115 // Allow this test to control what should get synced. |
| 3116 prefs->SetBoolean(prefs::kSyncKeepEverythingSynced, false); |
| 3117 // Always set password generation enabled check box so we can test the |
| 3118 // behavior of password sync. |
| 3119 prefs->SetBoolean(prefs::kPasswordGenerationEnabled, true); |
| 3120 |
| 3121 browser_sync::SyncPrefs sync_prefs(profile()->GetPrefs()); |
| 3122 sync_prefs.SetSyncSetupCompleted(); |
| 3123 UpdatePasswordGenerationState(false); |
| 3124 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); |
| 3125 } |
| 3126 |
| 3095 TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) { | 3127 TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) { |
| 3096 PasswordManagerDelegateImpl::CreateForWebContents(web_contents()); | 3128 PasswordManagerDelegateImpl::CreateForWebContents(web_contents()); |
| 3097 PasswordManager::CreateForWebContentsAndDelegate( | 3129 PasswordManager::CreateForWebContentsAndDelegate( |
| 3098 web_contents(), | 3130 web_contents(), |
| 3099 PasswordManagerDelegateImpl::FromWebContents(web_contents())); | 3131 PasswordManagerDelegateImpl::FromWebContents(web_contents())); |
| 3100 | 3132 |
| 3101 PrefServiceBase* prefs = PrefServiceBase::FromBrowserContext(profile()); | 3133 PrefServiceBase* prefs = PrefServiceBase::FromBrowserContext(profile()); |
| 3102 | 3134 |
| 3103 // Always set password sync enabled so we can test the behavior of password | 3135 // Always set password sync enabled so we can test the behavior of password |
| 3104 // generation. | 3136 // generation. |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3237 | 3269 |
| 3238 FormData form; | 3270 FormData form; |
| 3239 CreateTestAddressFormData(&form); | 3271 CreateTestAddressFormData(&form); |
| 3240 std::vector<FormData> forms(1, form); | 3272 std::vector<FormData> forms(1, form); |
| 3241 FormsSeen(forms); | 3273 FormsSeen(forms); |
| 3242 const FormFieldData& field = form.fields[0]; | 3274 const FormFieldData& field = form.fields[0]; |
| 3243 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3275 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
| 3244 | 3276 |
| 3245 autofill_manager_->SetExternalDelegate(NULL); | 3277 autofill_manager_->SetExternalDelegate(NULL); |
| 3246 } | 3278 } |
| OLD | NEW |