Chromium Code Reviews| 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( | |
|
Garrett Casto
2012/04/26 23:23:59
Remove this.
| |
| 492 content::RenderViewHost* host, bool enabled) OVERRIDE { | |
| 493 sent_sync_states_.push_back(enabled); | |
| 494 } | |
| 495 | |
| 491 virtual void SendPasswordGenerationStateToRenderer( | 496 virtual void SendPasswordGenerationStateToRenderer( |
| 492 content::RenderViewHost* host, bool enabled) OVERRIDE { | 497 content::RenderViewHost* host, bool enabled) OVERRIDE { |
| 493 sent_states_.push_back(enabled); | 498 sent_enabled_states_.push_back(enabled); |
| 494 } | 499 } |
| 495 | 500 |
| 496 const std::vector<bool>& GetSentStates() { | 501 const std::vector<bool>& GetSentSyncStates() { |
| 497 return sent_states_; | 502 return sent_sync_states_; |
| 498 } | 503 } |
| 499 | 504 |
| 500 void ClearSentStates() { | 505 const std::vector<bool>& GetSentEnabledStates() { |
| 501 sent_states_.clear(); | 506 return sent_enabled_states_; |
| 507 } | |
| 508 | |
| 509 void ClearSentSyncStates() { | |
| 510 sent_sync_states_.clear(); | |
| 511 } | |
| 512 | |
| 513 void ClearSentEnabledStates() { | |
| 514 sent_enabled_states_.clear(); | |
| 502 } | 515 } |
| 503 | 516 |
| 504 const std::string GetSubmittedFormSignature() { | 517 const std::string GetSubmittedFormSignature() { |
| 505 return submitted_form_signature_; | 518 return submitted_form_signature_; |
| 506 } | 519 } |
| 507 | 520 |
| 508 AutofillProfile* GetProfileWithGUID(const char* guid) { | 521 AutofillProfile* GetProfileWithGUID(const char* guid) { |
| 509 return personal_data_->GetProfileWithGUID(guid); | 522 return personal_data_->GetProfileWithGUID(guid); |
| 510 } | 523 } |
| 511 | 524 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 535 // Weak reference. | 548 // Weak reference. |
| 536 TestPersonalDataManager* personal_data_; | 549 TestPersonalDataManager* personal_data_; |
| 537 | 550 |
| 538 bool autofill_enabled_; | 551 bool autofill_enabled_; |
| 539 | 552 |
| 540 bool did_finish_async_form_submit_; | 553 bool did_finish_async_form_submit_; |
| 541 bool message_loop_is_running_; | 554 bool message_loop_is_running_; |
| 542 | 555 |
| 543 std::string submitted_form_signature_; | 556 std::string submitted_form_signature_; |
| 544 std::vector<FieldTypeSet> expected_submitted_field_types_; | 557 std::vector<FieldTypeSet> expected_submitted_field_types_; |
| 545 std::vector<bool> sent_states_; | 558 std::vector<bool> sent_sync_states_; |
| 559 std::vector<bool> sent_enabled_states_; | |
| 546 | 560 |
| 547 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 561 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
| 548 }; | 562 }; |
| 549 | 563 |
| 550 } // namespace | 564 } // namespace |
| 551 | 565 |
| 552 class AutofillManagerTest : public TabContentsWrapperTestHarness { | 566 class AutofillManagerTest : public TabContentsWrapperTestHarness { |
| 553 public: | 567 public: |
| 554 typedef AutofillManager::GUIDPair GUIDPair; | 568 typedef AutofillManager::GUIDPair GUIDPair; |
| 555 | 569 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 576 &personal_data_); | 590 &personal_data_); |
| 577 | 591 |
| 578 file_thread_.Start(); | 592 file_thread_.Start(); |
| 579 } | 593 } |
| 580 | 594 |
| 581 virtual void TearDown() OVERRIDE { | 595 virtual void TearDown() OVERRIDE { |
| 582 file_thread_.Stop(); | 596 file_thread_.Stop(); |
| 583 TabContentsWrapperTestHarness::TearDown(); | 597 TabContentsWrapperTestHarness::TearDown(); |
| 584 } | 598 } |
| 585 | 599 |
| 600 void UpdatePasswordSyncState(bool new_renderer) { | |
| 601 autofill_manager_->UpdatePasswordSyncState(NULL, new_renderer); | |
| 602 } | |
| 603 | |
| 586 void UpdatePasswordGenerationState(bool new_renderer) { | 604 void UpdatePasswordGenerationState(bool new_renderer) { |
| 587 autofill_manager_->UpdatePasswordGenerationState(NULL, new_renderer); | 605 autofill_manager_->UpdatePasswordGenerationState(NULL, new_renderer); |
| 588 } | 606 } |
| 589 | 607 |
| 590 void GetAutofillSuggestions(int query_id, | 608 void GetAutofillSuggestions(int query_id, |
| 591 const webkit::forms::FormData& form, | 609 const webkit::forms::FormData& form, |
| 592 const webkit::forms::FormField& field) { | 610 const webkit::forms::FormField& field) { |
| 593 autofill_manager_->OnQueryFormFieldAutofill(query_id, | 611 autofill_manager_->OnQueryFormFieldAutofill(query_id, |
| 594 form, | 612 form, |
| 595 field, | 613 field, |
| (...skipping 2288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2884 autofill_test::CreateTestFormField("", "20", "901", "text", &field); | 2902 autofill_test::CreateTestFormField("", "20", "901", "text", &field); |
| 2885 types.clear(); | 2903 types.clear(); |
| 2886 types.insert(UNKNOWN_TYPE); | 2904 types.insert(UNKNOWN_TYPE); |
| 2887 form.fields.push_back(field); | 2905 form.fields.push_back(field); |
| 2888 expected_types.push_back(types); | 2906 expected_types.push_back(types); |
| 2889 | 2907 |
| 2890 autofill_manager_->set_expected_submitted_field_types(expected_types); | 2908 autofill_manager_->set_expected_submitted_field_types(expected_types); |
| 2891 FormSubmitted(form); | 2909 FormSubmitted(form); |
| 2892 } | 2910 } |
| 2893 | 2911 |
| 2894 TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) { | 2912 TEST_F(AutofillManagerTest, UpdatePasswordSyncState) { |
| 2895 // Allow this test to control what should get synced. | 2913 // Allow this test to control what should get synced. |
| 2896 profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); | 2914 profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); |
| 2897 | 2915 |
| 2898 // Sync some things, but not passwords. Shouldn't send anything since | 2916 // Sync some things, but not passwords. Shouldn't send anything since |
| 2899 // password generation is disabled by default. | 2917 // password generation is disabled by default. |
| 2900 ProfileSyncService* sync_service = GetProfileSyncService(); | 2918 ProfileSyncService* sync_service = GetProfileSyncService(); |
| 2901 sync_service->SetSyncSetupCompleted(); | 2919 sync_service->SetSyncSetupCompleted(); |
| 2902 syncable::ModelTypeSet preferred_set; | 2920 syncable::ModelTypeSet preferred_set; |
| 2903 preferred_set.Put(syncable::EXTENSIONS); | 2921 preferred_set.Put(syncable::EXTENSIONS); |
| 2904 preferred_set.Put(syncable::PREFERENCES); | 2922 preferred_set.Put(syncable::PREFERENCES); |
| 2905 sync_service->ChangePreferredDataTypes(preferred_set); | 2923 sync_service->ChangePreferredDataTypes(preferred_set); |
| 2906 syncable::ModelTypeSet new_set = sync_service->GetPreferredDataTypes(); | 2924 syncable::ModelTypeSet new_set = sync_service->GetPreferredDataTypes(); |
| 2907 UpdatePasswordGenerationState(false); | 2925 UpdatePasswordSyncState(false); |
| 2908 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); | 2926 EXPECT_EQ(0u, autofill_manager_->GetSentSyncStates().size()); |
| 2909 | 2927 |
| 2910 // Now sync passwords. | 2928 // Now sync passwords. |
| 2911 preferred_set.Put(syncable::PASSWORDS); | 2929 preferred_set.Put(syncable::PASSWORDS); |
| 2912 sync_service->ChangePreferredDataTypes(preferred_set); | 2930 sync_service->ChangePreferredDataTypes(preferred_set); |
| 2913 UpdatePasswordGenerationState(false); | 2931 UpdatePasswordSyncState(false); |
| 2914 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); | 2932 EXPECT_EQ(1u, autofill_manager_->GetSentSyncStates().size()); |
| 2915 EXPECT_TRUE(autofill_manager_->GetSentStates()[0]); | 2933 EXPECT_TRUE(autofill_manager_->GetSentSyncStates()[0]); |
| 2916 autofill_manager_->ClearSentStates(); | 2934 autofill_manager_->ClearSentSyncStates(); |
| 2917 | 2935 |
| 2918 // Add some additional synced state. Nothing should be sent. | 2936 // Add some additional synced state. Nothing should be sent. |
| 2919 preferred_set.Put(syncable::THEMES); | 2937 preferred_set.Put(syncable::THEMES); |
| 2920 sync_service->ChangePreferredDataTypes(preferred_set); | 2938 sync_service->ChangePreferredDataTypes(preferred_set); |
| 2921 UpdatePasswordGenerationState(false); | 2939 UpdatePasswordSyncState(false); |
| 2922 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); | 2940 EXPECT_EQ(0u, autofill_manager_->GetSentSyncStates().size()); |
| 2923 | 2941 |
| 2924 // Disable syncing. This should disable the feature. | 2942 // Disable syncing. This should disable the feature. |
| 2925 sync_service->DisableForUser(); | 2943 sync_service->DisableForUser(); |
| 2926 UpdatePasswordGenerationState(false); | 2944 UpdatePasswordSyncState(false); |
| 2927 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); | 2945 EXPECT_EQ(1u, autofill_manager_->GetSentSyncStates().size()); |
| 2928 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); | 2946 EXPECT_FALSE(autofill_manager_->GetSentSyncStates()[0]); |
| 2929 autofill_manager_->ClearSentStates(); | 2947 autofill_manager_->ClearSentSyncStates(); |
| 2930 | 2948 |
| 2931 // Disable password manager by going incognito, and re-enable syncing. The | 2949 // Disable password manager by going incognito, and re-enable syncing. The |
| 2932 // feature should still be disabled, and nothing will be sent. | 2950 // feature should still be disabled, and nothing will be sent. |
| 2933 sync_service->SetSyncSetupCompleted(); | 2951 sync_service->SetSyncSetupCompleted(); |
| 2934 profile()->set_incognito(true); | 2952 profile()->set_incognito(true); |
| 2953 UpdatePasswordSyncState(false); | |
| 2954 EXPECT_EQ(0u, autofill_manager_->GetSentSyncStates().size()); | |
| 2955 | |
| 2956 // When a new render_view is created, we send the state even if it's the | |
| 2957 // same. | |
| 2958 UpdatePasswordSyncState(true); | |
| 2959 EXPECT_EQ(1u, autofill_manager_->GetSentSyncStates().size()); | |
| 2960 EXPECT_FALSE(autofill_manager_->GetSentSyncStates()[0]); | |
| 2961 autofill_manager_->ClearSentSyncStates(); | |
| 2962 } | |
| 2963 | |
| 2964 TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) { | |
| 2965 // Enabled state remains false, should not sent. | |
| 2966 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, false); | |
| 2935 UpdatePasswordGenerationState(false); | 2967 UpdatePasswordGenerationState(false); |
| 2936 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); | 2968 EXPECT_EQ(0u, autofill_manager_->GetSentEnabledStates().size()); |
| 2969 | |
| 2970 // Enabled state from false to true, should sent true. | |
| 2971 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true); | |
| 2972 UpdatePasswordGenerationState(false); | |
| 2973 EXPECT_EQ(1u, autofill_manager_->GetSentEnabledStates().size()); | |
| 2974 EXPECT_TRUE(autofill_manager_->GetSentEnabledStates()[0]); | |
| 2975 autofill_manager_->ClearSentEnabledStates(); | |
| 2976 | |
| 2977 // Enabled states remains true, should not sent. | |
| 2978 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true); | |
| 2979 UpdatePasswordGenerationState(false); | |
| 2980 EXPECT_EQ(0u, autofill_manager_->GetSentEnabledStates().size()); | |
| 2981 | |
| 2982 // Enabled states from true to false, should sent false. | |
| 2983 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, false); | |
| 2984 UpdatePasswordGenerationState(false); | |
| 2985 EXPECT_EQ(1u, autofill_manager_->GetSentEnabledStates().size()); | |
| 2986 EXPECT_FALSE(autofill_manager_->GetSentEnabledStates()[0]); | |
| 2987 autofill_manager_->ClearSentEnabledStates(); | |
| 2937 | 2988 |
| 2938 // When a new render_view is created, we send the state even if it's the | 2989 // When a new render_view is created, we send the state even if it's the |
| 2939 // same. | 2990 // same. |
| 2940 UpdatePasswordGenerationState(true); | 2991 UpdatePasswordGenerationState(true); |
| 2941 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); | 2992 EXPECT_EQ(1u, autofill_manager_->GetSentEnabledStates().size()); |
| 2942 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); | 2993 EXPECT_FALSE(autofill_manager_->GetSentEnabledStates()[0]); |
| 2943 autofill_manager_->ClearSentStates(); | 2994 autofill_manager_->ClearSentEnabledStates(); |
| 2944 } | 2995 } |
| 2945 | |
| 2946 namespace { | 2996 namespace { |
| 2947 | 2997 |
| 2948 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { | 2998 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { |
| 2949 public: | 2999 public: |
| 2950 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper, | 3000 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper, |
| 2951 AutofillManager* autofill_manager) | 3001 AutofillManager* autofill_manager) |
| 2952 : TestAutofillExternalDelegate(wrapper, autofill_manager) {} | 3002 : TestAutofillExternalDelegate(wrapper, autofill_manager) {} |
| 2953 virtual ~MockAutofillExternalDelegate() {} | 3003 virtual ~MockAutofillExternalDelegate() {} |
| 2954 | 3004 |
| 2955 MOCK_METHOD5(OnQuery, void(int query_id, | 3005 MOCK_METHOD5(OnQuery, void(int query_id, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3003 | 3053 |
| 3004 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager(); | 3054 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager(); |
| 3005 EXPECT_TRUE(autofill_manager->external_delegate()); | 3055 EXPECT_TRUE(autofill_manager->external_delegate()); |
| 3006 | 3056 |
| 3007 AutocompleteHistoryManager* autocomplete_history_manager = | 3057 AutocompleteHistoryManager* autocomplete_history_manager = |
| 3008 contents_wrapper()->autocomplete_history_manager(); | 3058 contents_wrapper()->autocomplete_history_manager(); |
| 3009 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); | 3059 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); |
| 3010 } | 3060 } |
| 3011 | 3061 |
| 3012 #endif // OS_ANDROID | 3062 #endif // OS_ANDROID |
| OLD | NEW |