Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1464)

Side by Side Diff: chrome/browser/autofill/autofill_manager_unittest.cc

Issue 10168017: Only enable password generation if password manager and autofill are both (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix linux_asan Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 file_thread_(BrowserThread::FILE) { 559 file_thread_(BrowserThread::FILE) {
560 } 560 }
561 561
562 virtual ~AutofillManagerTest() { 562 virtual ~AutofillManagerTest() {
563 // Order of destruction is important as AutofillManager relies on 563 // Order of destruction is important as AutofillManager relies on
564 // PersonalDataManager to be around when it gets destroyed. 564 // PersonalDataManager to be around when it gets destroyed.
565 autofill_manager_ = NULL; 565 autofill_manager_ = NULL;
566 } 566 }
567 567
568 virtual void SetUp() OVERRIDE { 568 virtual void SetUp() OVERRIDE {
569 Profile* profile = new TestingProfile(); 569 if (!browser_context_.get()) {
570 browser_context_.reset(profile); 570 Profile* profile = new TestingProfile();
571 PersonalDataManagerFactory::GetInstance()->SetTestingFactory( 571 browser_context_.reset(profile);
572 profile, TestPersonalDataManager::Build); 572 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(
573 profile, TestPersonalDataManager::Build);
574 }
573 575
574 TabContentsWrapperTestHarness::SetUp(); 576 TabContentsWrapperTestHarness::SetUp();
575 autofill_manager_ = new TestAutofillManager(contents_wrapper(), 577 autofill_manager_ = new TestAutofillManager(contents_wrapper(),
576 &personal_data_); 578 &personal_data_);
577 579
578 file_thread_.Start(); 580 file_thread_.Start();
579 } 581 }
580 582
581 virtual void TearDown() OVERRIDE { 583 virtual void TearDown() OVERRIDE {
582 file_thread_.Stop(); 584 file_thread_.Stop();
583 TabContentsWrapperTestHarness::TearDown(); 585 TabContentsWrapperTestHarness::TearDown();
584 } 586 }
585 587
586 void UpdatePasswordSyncState(bool new_renderer) { 588 void GoOffTheRecord() {
587 autofill_manager_->UpdatePasswordSyncState(NULL, new_renderer); 589 TearDown();
Ilya Sherman 2012/04/24 00:46:54 Hmm, I'm not sure this is safe. For example, chro
Garrett Casto 2012/04/24 18:49:56 I'm not sure how this is different from the normal
590 other_browser_context_.reset(new TestingProfile());
591 Profile* incognito =
592 Profile::FromBrowserContext(
593 other_browser_context_.get())->GetOffTheRecordProfile();
594 browser_context_.reset(incognito);
595 SetUp();
596 }
597
598 void UpdatePasswordGenerationState(bool new_renderer) {
599 autofill_manager_->UpdatePasswordGenerationState(NULL, new_renderer);
588 } 600 }
589 601
590 void GetAutofillSuggestions(int query_id, 602 void GetAutofillSuggestions(int query_id,
591 const webkit::forms::FormData& form, 603 const webkit::forms::FormData& form,
592 const webkit::forms::FormField& field) { 604 const webkit::forms::FormField& field) {
593 autofill_manager_->OnQueryFormFieldAutofill(query_id, 605 autofill_manager_->OnQueryFormFieldAutofill(query_id,
594 form, 606 form,
595 field, 607 field,
596 gfx::Rect(), 608 gfx::Rect(),
597 false); 609 false);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 return autofill_manager_->sync_service_; 689 return autofill_manager_->sync_service_;
678 } 690 }
679 691
680 protected: 692 protected:
681 content::TestBrowserThread ui_thread_; 693 content::TestBrowserThread ui_thread_;
682 content::TestBrowserThread file_thread_; 694 content::TestBrowserThread file_thread_;
683 695
684 scoped_refptr<TestAutofillManager> autofill_manager_; 696 scoped_refptr<TestAutofillManager> autofill_manager_;
685 TestPersonalDataManager personal_data_; 697 TestPersonalDataManager personal_data_;
686 698
699 // Used when we want an off the record profile. This will store the original
700 // profile from which the off the record profile is derived.
701 scoped_ptr<Profile> other_browser_context_;
702
687 private: 703 private:
688 DISALLOW_COPY_AND_ASSIGN(AutofillManagerTest); 704 DISALLOW_COPY_AND_ASSIGN(AutofillManagerTest);
689 }; 705 };
690 706
691 class TestFormStructure : public FormStructure { 707 class TestFormStructure : public FormStructure {
692 public: 708 public:
693 explicit TestFormStructure(const FormData& form) : FormStructure(form) {} 709 explicit TestFormStructure(const FormData& form) : FormStructure(form) {}
694 virtual ~TestFormStructure() {} 710 virtual ~TestFormStructure() {}
695 711
696 void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types, 712 void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types,
(...skipping 2183 matching lines...) Expand 10 before | Expand all | Expand 10 after
2880 autofill_test::CreateTestFormField("", "20", "901", "text", &field); 2896 autofill_test::CreateTestFormField("", "20", "901", "text", &field);
2881 types.clear(); 2897 types.clear();
2882 types.insert(UNKNOWN_TYPE); 2898 types.insert(UNKNOWN_TYPE);
2883 form.fields.push_back(field); 2899 form.fields.push_back(field);
2884 expected_types.push_back(types); 2900 expected_types.push_back(types);
2885 2901
2886 autofill_manager_->set_expected_submitted_field_types(expected_types); 2902 autofill_manager_->set_expected_submitted_field_types(expected_types);
2887 FormSubmitted(form); 2903 FormSubmitted(form);
2888 } 2904 }
2889 2905
2890 TEST_F(AutofillManagerTest, UpdatePasswordSyncState) { 2906 TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) {
2891 // Allow this test to control what should get synced. 2907 // Allow this test to control what should get synced.
2892 profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); 2908 profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false);
2893 2909
2894 // Sync some things, but not passwords. Shouldn't send anything since 2910 // Sync some things, but not passwords. Shouldn't send anything since
2895 // password generation is disabled by default. 2911 // password generation is disabled by default.
2896 ProfileSyncService* sync_service = GetProfileSyncService(); 2912 ProfileSyncService* sync_service = GetProfileSyncService();
2897 sync_service->SetSyncSetupCompleted(); 2913 sync_service->SetSyncSetupCompleted();
2898 syncable::ModelTypeSet preferred_set; 2914 syncable::ModelTypeSet preferred_set;
2899 preferred_set.Put(syncable::EXTENSIONS); 2915 preferred_set.Put(syncable::EXTENSIONS);
2900 preferred_set.Put(syncable::PREFERENCES); 2916 preferred_set.Put(syncable::PREFERENCES);
2901 sync_service->ChangePreferredDataTypes(preferred_set); 2917 sync_service->ChangePreferredDataTypes(preferred_set);
2902 syncable::ModelTypeSet new_set = sync_service->GetPreferredDataTypes(); 2918 syncable::ModelTypeSet new_set = sync_service->GetPreferredDataTypes();
2903 UpdatePasswordSyncState(false); 2919 UpdatePasswordGenerationState(false);
2904 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); 2920 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size());
2905 2921
2906 // Now sync passwords. 2922 // Now sync passwords.
2907 preferred_set.Put(syncable::PASSWORDS); 2923 preferred_set.Put(syncable::PASSWORDS);
2908 sync_service->ChangePreferredDataTypes(preferred_set); 2924 sync_service->ChangePreferredDataTypes(preferred_set);
2909 UpdatePasswordSyncState(false); 2925 UpdatePasswordGenerationState(false);
2910 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); 2926 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size());
2911 EXPECT_TRUE(autofill_manager_->GetSentStates()[0]); 2927 EXPECT_TRUE(autofill_manager_->GetSentStates()[0]);
2912 autofill_manager_->ClearSentStates(); 2928 autofill_manager_->ClearSentStates();
2913 2929
2914 // Add some additional synced state. Nothing should be sent. 2930 // Add some additional synced state. Nothing should be sent.
2915 preferred_set.Put(syncable::THEMES); 2931 preferred_set.Put(syncable::THEMES);
2916 sync_service->ChangePreferredDataTypes(preferred_set); 2932 sync_service->ChangePreferredDataTypes(preferred_set);
2917 UpdatePasswordSyncState(false); 2933 UpdatePasswordGenerationState(false);
2918 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); 2934 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size());
2919 2935
2920 // Disable syncing. This should be sent. 2936 // Disable autofill. This should be sent.
Ilya Sherman 2012/04/24 00:46:54 Hmm, why is this case (disabling sync) removed fro
Garrett Casto 2012/04/24 18:49:56 Re-added. Just got lost in the shuffle.
2921 sync_service->DisableForUser(); 2937 autofill_manager_->set_autofill_enabled(false);
2922 UpdatePasswordSyncState(false); 2938 UpdatePasswordGenerationState(false);
2923 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); 2939 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size());
2924 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); 2940 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]);
2925 autofill_manager_->ClearSentStates(); 2941 autofill_manager_->ClearSentStates();
2926 2942
2943 // Now re-enable autofill, but disable password manager by going incognito.
2944 // This should still leave the feature disabled, and shouldn't send anything.
Ilya Sherman 2012/04/24 00:46:54 nit: The "still" in this comment seems a little bi
Garrett Casto 2012/04/24 18:49:56 N/A
2945 GoOffTheRecord();
2946 autofill_manager_->set_autofill_enabled(true);
2947 UpdatePasswordGenerationState(false);
2948 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size());
2949
2927 // When a new render_view is created, we send the state even if it's the 2950 // When a new render_view is created, we send the state even if it's the
2928 // same. 2951 // same.
2929 UpdatePasswordSyncState(true); 2952 UpdatePasswordGenerationState(true);
2930 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); 2953 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size());
2931 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); 2954 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]);
2932 autofill_manager_->ClearSentStates(); 2955 autofill_manager_->ClearSentStates();
2933 } 2956 }
2934 2957
2935 namespace { 2958 namespace {
2936 2959
2937 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { 2960 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate {
2938 public: 2961 public:
2939 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper, 2962 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2992 3015
2993 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager(); 3016 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager();
2994 EXPECT_TRUE(autofill_manager->external_delegate()); 3017 EXPECT_TRUE(autofill_manager->external_delegate());
2995 3018
2996 AutocompleteHistoryManager* autocomplete_history_manager = 3019 AutocompleteHistoryManager* autocomplete_history_manager =
2997 contents_wrapper()->autocomplete_history_manager(); 3020 contents_wrapper()->autocomplete_history_manager();
2998 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); 3021 EXPECT_TRUE(autocomplete_history_manager->external_delegate());
2999 } 3022 }
3000 3023
3001 #endif // OS_ANDROID 3024 #endif // OS_ANDROID
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698