| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 MessageLoop::current()->Run(); | 481 MessageLoop::current()->Run(); |
| 482 } else { | 482 } else { |
| 483 did_finish_async_form_submit_ = false; | 483 did_finish_async_form_submit_ = false; |
| 484 } | 484 } |
| 485 } | 485 } |
| 486 | 486 |
| 487 virtual void UploadFormData(const FormStructure& submitted_form) OVERRIDE { | 487 virtual void UploadFormData(const FormStructure& submitted_form) OVERRIDE { |
| 488 submitted_form_signature_ = submitted_form.FormSignature(); | 488 submitted_form_signature_ = submitted_form.FormSignature(); |
| 489 } | 489 } |
| 490 | 490 |
| 491 virtual void SendPasswordSyncStateToRenderer( | 491 virtual void SendPasswordGenerationStateToRenderer( |
| 492 content::RenderViewHost* host, bool enabled) OVERRIDE { | 492 content::RenderViewHost* host, bool enabled) OVERRIDE { |
| 493 sent_states_.push_back(enabled); | 493 sent_states_.push_back(enabled); |
| 494 } | 494 } |
| 495 | 495 |
| 496 const std::vector<bool>& GetSentStates() { | 496 const std::vector<bool>& GetSentStates() { |
| 497 return sent_states_; | 497 return sent_states_; |
| 498 } | 498 } |
| 499 | 499 |
| 500 void ClearSentStates() { | 500 void ClearSentStates() { |
| 501 sent_states_.clear(); | 501 sent_states_.clear(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 &personal_data_); | 576 &personal_data_); |
| 577 | 577 |
| 578 file_thread_.Start(); | 578 file_thread_.Start(); |
| 579 } | 579 } |
| 580 | 580 |
| 581 virtual void TearDown() OVERRIDE { | 581 virtual void TearDown() OVERRIDE { |
| 582 file_thread_.Stop(); | 582 file_thread_.Stop(); |
| 583 TabContentsWrapperTestHarness::TearDown(); | 583 TabContentsWrapperTestHarness::TearDown(); |
| 584 } | 584 } |
| 585 | 585 |
| 586 void UpdatePasswordSyncState(bool new_renderer) { | 586 void UpdatePasswordGenerationState(bool new_renderer) { |
| 587 autofill_manager_->UpdatePasswordSyncState(NULL, new_renderer); | 587 autofill_manager_->UpdatePasswordGenerationState(NULL, new_renderer); |
| 588 } | 588 } |
| 589 | 589 |
| 590 void GetAutofillSuggestions(int query_id, | 590 void GetAutofillSuggestions(int query_id, |
| 591 const webkit::forms::FormData& form, | 591 const webkit::forms::FormData& form, |
| 592 const webkit::forms::FormField& field) { | 592 const webkit::forms::FormField& field) { |
| 593 autofill_manager_->OnQueryFormFieldAutofill(query_id, | 593 autofill_manager_->OnQueryFormFieldAutofill(query_id, |
| 594 form, | 594 form, |
| 595 field, | 595 field, |
| 596 gfx::Rect(), | 596 gfx::Rect(), |
| 597 false); | 597 false); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 return autofill_manager_->sync_service_; | 677 return autofill_manager_->sync_service_; |
| 678 } | 678 } |
| 679 | 679 |
| 680 protected: | 680 protected: |
| 681 content::TestBrowserThread ui_thread_; | 681 content::TestBrowserThread ui_thread_; |
| 682 content::TestBrowserThread file_thread_; | 682 content::TestBrowserThread file_thread_; |
| 683 | 683 |
| 684 scoped_refptr<TestAutofillManager> autofill_manager_; | 684 scoped_refptr<TestAutofillManager> autofill_manager_; |
| 685 TestPersonalDataManager personal_data_; | 685 TestPersonalDataManager personal_data_; |
| 686 | 686 |
| 687 // Used when we want an off the record profile. This will store the original |
| 688 // profile from which the off the record profile is derived. |
| 689 scoped_ptr<Profile> other_browser_context_; |
| 690 |
| 687 private: | 691 private: |
| 688 DISALLOW_COPY_AND_ASSIGN(AutofillManagerTest); | 692 DISALLOW_COPY_AND_ASSIGN(AutofillManagerTest); |
| 689 }; | 693 }; |
| 690 | 694 |
| 691 class TestFormStructure : public FormStructure { | 695 class TestFormStructure : public FormStructure { |
| 692 public: | 696 public: |
| 693 explicit TestFormStructure(const FormData& form) : FormStructure(form) {} | 697 explicit TestFormStructure(const FormData& form) : FormStructure(form) {} |
| 694 virtual ~TestFormStructure() {} | 698 virtual ~TestFormStructure() {} |
| 695 | 699 |
| 696 void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types, | 700 void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types, |
| (...skipping 2183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2880 autofill_test::CreateTestFormField("", "20", "901", "text", &field); | 2884 autofill_test::CreateTestFormField("", "20", "901", "text", &field); |
| 2881 types.clear(); | 2885 types.clear(); |
| 2882 types.insert(UNKNOWN_TYPE); | 2886 types.insert(UNKNOWN_TYPE); |
| 2883 form.fields.push_back(field); | 2887 form.fields.push_back(field); |
| 2884 expected_types.push_back(types); | 2888 expected_types.push_back(types); |
| 2885 | 2889 |
| 2886 autofill_manager_->set_expected_submitted_field_types(expected_types); | 2890 autofill_manager_->set_expected_submitted_field_types(expected_types); |
| 2887 FormSubmitted(form); | 2891 FormSubmitted(form); |
| 2888 } | 2892 } |
| 2889 | 2893 |
| 2890 TEST_F(AutofillManagerTest, UpdatePasswordSyncState) { | 2894 TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) { |
| 2891 // Allow this test to control what should get synced. | 2895 // Allow this test to control what should get synced. |
| 2892 profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); | 2896 profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); |
| 2893 | 2897 |
| 2894 // Sync some things, but not passwords. Shouldn't send anything since | 2898 // Sync some things, but not passwords. Shouldn't send anything since |
| 2895 // password generation is disabled by default. | 2899 // password generation is disabled by default. |
| 2896 ProfileSyncService* sync_service = GetProfileSyncService(); | 2900 ProfileSyncService* sync_service = GetProfileSyncService(); |
| 2897 sync_service->SetSyncSetupCompleted(); | 2901 sync_service->SetSyncSetupCompleted(); |
| 2898 syncable::ModelTypeSet preferred_set; | 2902 syncable::ModelTypeSet preferred_set; |
| 2899 preferred_set.Put(syncable::EXTENSIONS); | 2903 preferred_set.Put(syncable::EXTENSIONS); |
| 2900 preferred_set.Put(syncable::PREFERENCES); | 2904 preferred_set.Put(syncable::PREFERENCES); |
| 2901 sync_service->ChangePreferredDataTypes(preferred_set); | 2905 sync_service->ChangePreferredDataTypes(preferred_set); |
| 2902 syncable::ModelTypeSet new_set = sync_service->GetPreferredDataTypes(); | 2906 syncable::ModelTypeSet new_set = sync_service->GetPreferredDataTypes(); |
| 2903 UpdatePasswordSyncState(false); | 2907 UpdatePasswordGenerationState(false); |
| 2904 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); | 2908 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); |
| 2905 | 2909 |
| 2906 // Now sync passwords. | 2910 // Now sync passwords. |
| 2907 preferred_set.Put(syncable::PASSWORDS); | 2911 preferred_set.Put(syncable::PASSWORDS); |
| 2908 sync_service->ChangePreferredDataTypes(preferred_set); | 2912 sync_service->ChangePreferredDataTypes(preferred_set); |
| 2909 UpdatePasswordSyncState(false); | 2913 UpdatePasswordGenerationState(false); |
| 2910 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); | 2914 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); |
| 2911 EXPECT_TRUE(autofill_manager_->GetSentStates()[0]); | 2915 EXPECT_TRUE(autofill_manager_->GetSentStates()[0]); |
| 2912 autofill_manager_->ClearSentStates(); | 2916 autofill_manager_->ClearSentStates(); |
| 2913 | 2917 |
| 2914 // Add some additional synced state. Nothing should be sent. | 2918 // Add some additional synced state. Nothing should be sent. |
| 2915 preferred_set.Put(syncable::THEMES); | 2919 preferred_set.Put(syncable::THEMES); |
| 2916 sync_service->ChangePreferredDataTypes(preferred_set); | 2920 sync_service->ChangePreferredDataTypes(preferred_set); |
| 2917 UpdatePasswordSyncState(false); | 2921 UpdatePasswordGenerationState(false); |
| 2918 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); | 2922 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); |
| 2919 | 2923 |
| 2920 // Disable syncing. This should be sent. | 2924 // Disable syncing. This should disable the feature. |
| 2921 sync_service->DisableForUser(); | 2925 sync_service->DisableForUser(); |
| 2922 UpdatePasswordSyncState(false); | 2926 UpdatePasswordGenerationState(false); |
| 2923 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); | 2927 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); |
| 2924 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); | 2928 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); |
| 2925 autofill_manager_->ClearSentStates(); | 2929 autofill_manager_->ClearSentStates(); |
| 2926 | 2930 |
| 2931 // Disable password manager by going incognito, and re-enable syncing. The |
| 2932 // feature should still be disabled, and nothing will be sent. |
| 2933 sync_service->SetSyncSetupCompleted(); |
| 2934 profile()->set_incognito(true); |
| 2935 UpdatePasswordGenerationState(false); |
| 2936 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); |
| 2937 |
| 2927 // When a new render_view is created, we send the state even if it's the | 2938 // When a new render_view is created, we send the state even if it's the |
| 2928 // same. | 2939 // same. |
| 2929 UpdatePasswordSyncState(true); | 2940 UpdatePasswordGenerationState(true); |
| 2930 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); | 2941 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); |
| 2931 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); | 2942 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); |
| 2932 autofill_manager_->ClearSentStates(); | 2943 autofill_manager_->ClearSentStates(); |
| 2933 } | 2944 } |
| 2934 | 2945 |
| 2935 namespace { | 2946 namespace { |
| 2936 | 2947 |
| 2937 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { | 2948 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { |
| 2938 public: | 2949 public: |
| 2939 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper, | 2950 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2992 | 3003 |
| 2993 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager(); | 3004 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager(); |
| 2994 EXPECT_TRUE(autofill_manager->external_delegate()); | 3005 EXPECT_TRUE(autofill_manager->external_delegate()); |
| 2995 | 3006 |
| 2996 AutocompleteHistoryManager* autocomplete_history_manager = | 3007 AutocompleteHistoryManager* autocomplete_history_manager = |
| 2997 contents_wrapper()->autocomplete_history_manager(); | 3008 contents_wrapper()->autocomplete_history_manager(); |
| 2998 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); | 3009 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); |
| 2999 } | 3010 } |
| 3000 | 3011 |
| 3001 #endif // OS_ANDROID | 3012 #endif // OS_ANDROID |
| OLD | NEW |