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

Side by Side Diff: chrome/browser/password_manager/password_generation_manager_unittest.cc

Issue 151413008: Move ownership of Password(Generation)Manager to ContentPasswordDriver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Handle WebContents having no PasswordManagerDelegateImpl attached Created 6 years, 10 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/password_manager/password_generation_manager.h" 9 #include "chrome/browser/password_manager/password_generation_manager.h"
10 #include "chrome/browser/password_manager/password_manager.h" 10 #include "chrome/browser/password_manager/password_manager.h"
(...skipping 23 matching lines...) Expand all
34 public: 34 public:
35 TestAutofillMetrics() {} 35 TestAutofillMetrics() {}
36 virtual ~TestAutofillMetrics() {} 36 virtual ~TestAutofillMetrics() {}
37 }; 37 };
38 38
39 } // anonymous namespace 39 } // anonymous namespace
40 40
41 class TestPasswordGenerationManager : public PasswordGenerationManager { 41 class TestPasswordGenerationManager : public PasswordGenerationManager {
42 public: 42 public:
43 explicit TestPasswordGenerationManager(content::WebContents* contents) 43 explicit TestPasswordGenerationManager(content::WebContents* contents)
44 : PasswordGenerationManager(contents) {} 44 : PasswordGenerationManager(
45 contents,
46 PasswordManagerDelegateImpl::FromWebContents(contents)) {}
45 virtual ~TestPasswordGenerationManager() {} 47 virtual ~TestPasswordGenerationManager() {}
46 48
47 virtual void SendAccountCreationFormsToRenderer( 49 virtual void SendAccountCreationFormsToRenderer(
48 content::RenderViewHost* host, 50 content::RenderViewHost* host,
49 const std::vector<autofill::FormData>& forms) OVERRIDE { 51 const std::vector<autofill::FormData>& forms) OVERRIDE {
50 sent_account_creation_forms_.insert( 52 sent_account_creation_forms_.insert(
51 sent_account_creation_forms_.begin(), forms.begin(), forms.end()); 53 sent_account_creation_forms_.begin(), forms.begin(), forms.end());
52 } 54 }
53 55
54 const std::vector<autofill::FormData>& GetSentAccountCreationForms() { 56 const std::vector<autofill::FormData>& GetSentAccountCreationForms() {
55 return sent_account_creation_forms_; 57 return sent_account_creation_forms_;
56 } 58 }
57 59
58 void ClearSentAccountCreationForms() { 60 void ClearSentAccountCreationForms() {
59 sent_account_creation_forms_.clear(); 61 sent_account_creation_forms_.clear();
60 } 62 }
61 63
62 private: 64 private:
63 std::vector<autofill::FormData> sent_account_creation_forms_; 65 std::vector<autofill::FormData> sent_account_creation_forms_;
64 66
65 DISALLOW_COPY_AND_ASSIGN(TestPasswordGenerationManager); 67 DISALLOW_COPY_AND_ASSIGN(TestPasswordGenerationManager);
66 }; 68 };
67 69
68 class PasswordGenerationManagerTest : public ChromeRenderViewHostTestHarness { 70 class PasswordGenerationManagerTest : public ChromeRenderViewHostTestHarness {
69 protected: 71 protected:
70 virtual void SetUp() OVERRIDE { 72 virtual void SetUp() OVERRIDE {
71 SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD); 73 SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD);
72 ChromeRenderViewHostTestHarness::SetUp(); 74 ChromeRenderViewHostTestHarness::SetUp();
73 75
76 PasswordManagerDelegateImpl::CreateForWebContents(web_contents());
74 password_generation_manager_.reset( 77 password_generation_manager_.reset(
75 new TestPasswordGenerationManager(web_contents())); 78 new TestPasswordGenerationManager(web_contents()));
76 } 79 }
77 80
78 virtual void TearDown() OVERRIDE { 81 virtual void TearDown() OVERRIDE {
79 ChromeRenderViewHostTestHarness::TearDown(); 82 ChromeRenderViewHostTestHarness::TearDown();
80 } 83 }
81 84
82 bool IsGenerationEnabled() { 85 bool IsGenerationEnabled() {
83 return password_generation_manager_->IsGenerationEnabled(); 86 return password_generation_manager_->IsGenerationEnabled();
(...skipping 13 matching lines...) Expand all
97 virtual content::BrowserContext* CreateBrowserContext() OVERRIDE { 100 virtual content::BrowserContext* CreateBrowserContext() OVERRIDE {
98 // Create an incognito profile. 101 // Create an incognito profile.
99 TestingProfile::Builder builder; 102 TestingProfile::Builder builder;
100 builder.SetIncognito(); 103 builder.SetIncognito();
101 scoped_ptr<TestingProfile> profile = builder.Build(); 104 scoped_ptr<TestingProfile> profile = builder.Build();
102 return profile.release(); 105 return profile.release();
103 } 106 }
104 }; 107 };
105 108
106 TEST_F(PasswordGenerationManagerTest, IsGenerationEnabled) { 109 TEST_F(PasswordGenerationManagerTest, IsGenerationEnabled) {
107 PasswordManagerDelegateImpl::CreateForWebContents(web_contents());
108 PasswordManager::CreateForWebContentsAndDelegate(
109 web_contents(),
110 PasswordManagerDelegateImpl::FromWebContents(web_contents()));
111
112 PrefService* prefs = profile()->GetPrefs(); 110 PrefService* prefs = profile()->GetPrefs();
113 111
114 // Enable syncing. Generation should be enabled. 112 // Enable syncing. Generation should be enabled.
115 prefs->SetBoolean(prefs::kSyncKeepEverythingSynced, false); 113 prefs->SetBoolean(prefs::kSyncKeepEverythingSynced, false);
116 ProfileSyncService* sync_service = ProfileSyncServiceFactory::GetForProfile( 114 ProfileSyncService* sync_service = ProfileSyncServiceFactory::GetForProfile(
117 profile()); 115 profile());
118 sync_service->SetSyncSetupCompleted(); 116 sync_service->SetSyncSetupCompleted();
119 syncer::ModelTypeSet preferred_set; 117 syncer::ModelTypeSet preferred_set;
120 preferred_set.Put(syncer::PASSWORDS); 118 preferred_set.Put(syncer::PASSWORDS);
121 sync_service->ChangePreferredDataTypes(preferred_set); 119 sync_service->ChangePreferredDataTypes(preferred_set);
122 EXPECT_TRUE(IsGenerationEnabled()); 120 EXPECT_TRUE(IsGenerationEnabled());
123 121
124 // Change syncing preferences to not include passwords. Generation should 122 // Change syncing preferences to not include passwords. Generation should
125 // be disabled. 123 // be disabled.
126 preferred_set.Put(syncer::EXTENSIONS); 124 preferred_set.Put(syncer::EXTENSIONS);
127 preferred_set.Remove(syncer::PASSWORDS); 125 preferred_set.Remove(syncer::PASSWORDS);
128 sync_service->ChangePreferredDataTypes(preferred_set); 126 sync_service->ChangePreferredDataTypes(preferred_set);
129 EXPECT_FALSE(IsGenerationEnabled()); 127 EXPECT_FALSE(IsGenerationEnabled());
130 128
131 // Disable syncing. Generation should also be disabled. 129 // Disable syncing. Generation should also be disabled.
132 sync_service->DisableForUser(); 130 sync_service->DisableForUser();
133 EXPECT_FALSE(IsGenerationEnabled()); 131 EXPECT_FALSE(IsGenerationEnabled());
134 } 132 }
135 133
136 TEST_F(PasswordGenerationManagerTest, DetectAccountCreationForms) { 134 TEST_F(PasswordGenerationManagerTest, DetectAccountCreationForms) {
137 // Setup so that IsGenerationEnabled() returns true. 135 // Setup so that IsGenerationEnabled() returns true.
138 PasswordManagerDelegateImpl::CreateForWebContents(web_contents());
139 PasswordManager::CreateForWebContentsAndDelegate(
140 web_contents(),
141 PasswordManagerDelegateImpl::FromWebContents(web_contents()));
142
143 ProfileSyncService* sync_service = ProfileSyncServiceFactory::GetForProfile( 136 ProfileSyncService* sync_service = ProfileSyncServiceFactory::GetForProfile(
144 profile()); 137 profile());
145 sync_service->SetSyncSetupCompleted(); 138 sync_service->SetSyncSetupCompleted();
146 139
147 autofill::FormData login_form; 140 autofill::FormData login_form;
148 login_form.origin = GURL("http://www.yahoo.com/login/"); 141 login_form.origin = GURL("http://www.yahoo.com/login/");
149 autofill::FormFieldData username; 142 autofill::FormFieldData username;
150 username.label = ASCIIToUTF16("username"); 143 username.label = ASCIIToUTF16("username");
151 username.name = ASCIIToUTF16("login"); 144 username.name = ASCIIToUTF16("login");
152 username.form_control_type = "text"; 145 username.form_control_type = "text";
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 password_generation_manager_->GetSentAccountCreationForms().size()); 183 password_generation_manager_->GetSentAccountCreationForms().size());
191 EXPECT_EQ( 184 EXPECT_EQ(
192 GURL("http://accounts.yahoo.com/"), 185 GURL("http://accounts.yahoo.com/"),
193 password_generation_manager_->GetSentAccountCreationForms()[0].origin); 186 password_generation_manager_->GetSentAccountCreationForms()[0].origin);
194 } 187 }
195 188
196 TEST_F(IncognitoPasswordGenerationManagerTest, 189 TEST_F(IncognitoPasswordGenerationManagerTest,
197 UpdatePasswordSyncStateIncognito) { 190 UpdatePasswordSyncStateIncognito) {
198 // Disable password manager by going incognito. Even though syncing is 191 // Disable password manager by going incognito. Even though syncing is
199 // enabled, generation should still be disabled. 192 // enabled, generation should still be disabled.
200 PasswordManagerDelegateImpl::CreateForWebContents(web_contents());
201 PasswordManager::CreateForWebContentsAndDelegate(
202 web_contents(),
203 PasswordManagerDelegateImpl::FromWebContents(web_contents()));
204
205 PrefService* prefs = profile()->GetPrefs(); 193 PrefService* prefs = profile()->GetPrefs();
206 194
207 // Allow this test to control what should get synced. 195 // Allow this test to control what should get synced.
208 prefs->SetBoolean(prefs::kSyncKeepEverythingSynced, false); 196 prefs->SetBoolean(prefs::kSyncKeepEverythingSynced, false);
209 197
210 browser_sync::SyncPrefs sync_prefs(profile()->GetPrefs()); 198 browser_sync::SyncPrefs sync_prefs(profile()->GetPrefs());
211 sync_prefs.SetSyncSetupCompleted(); 199 sync_prefs.SetSyncSetupCompleted();
212 EXPECT_FALSE(IsGenerationEnabled()); 200 EXPECT_FALSE(IsGenerationEnabled());
213 } 201 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_generation_manager.cc ('k') | chrome/browser/password_manager/password_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698