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

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

Issue 16296002: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/password_manager/mock_password_store.h" 10 #include "chrome/browser/password_manager/mock_password_store.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 form.password_element == arg.password_element && 110 form.password_element == arg.password_element &&
111 form.password_autocomplete_set == 111 form.password_autocomplete_set ==
112 arg.password_autocomplete_set && 112 arg.password_autocomplete_set &&
113 form.submit_element == arg.submit_element; 113 form.submit_element == arg.submit_element;
114 } 114 }
115 115
116 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { 116 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) {
117 // Test that observing a newly submitted form shows the save password bar. 117 // Test that observing a newly submitted form shows the save password bar.
118 std::vector<PasswordForm*> result; // Empty password store. 118 std::vector<PasswordForm*> result; // Empty password store.
119 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); 119 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0));
120 EXPECT_CALL(*store_, GetLogins(_,_)) 120 EXPECT_CALL(*store_.get(), GetLogins(_, _))
121 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); 121 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1)));
122 std::vector<PasswordForm> observed; 122 std::vector<PasswordForm> observed;
123 PasswordForm form(MakeSimpleForm()); 123 PasswordForm form(MakeSimpleForm());
124 observed.push_back(form); 124 observed.push_back(form);
125 manager()->OnPasswordFormsParsed(observed); // The initial load. 125 manager()->OnPasswordFormsParsed(observed); // The initial load.
126 manager()->OnPasswordFormsRendered(observed); // The initial layout. 126 manager()->OnPasswordFormsRendered(observed); // The initial layout.
127 127
128 // And the form submit contract is to call ProvisionallySavePassword. 128 // And the form submit contract is to call ProvisionallySavePassword.
129 manager()->ProvisionallySavePassword(form); 129 manager()->ProvisionallySavePassword(form);
130 130
131 scoped_ptr<PasswordFormManager> form_to_save; 131 scoped_ptr<PasswordFormManager> form_to_save;
132 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_)) 132 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_))
133 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); 133 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save)));
134 134
135 // Now the password manager waits for the navigation to complete. 135 // Now the password manager waits for the navigation to complete.
136 observed.clear(); 136 observed.clear();
137 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 137 manager()->OnPasswordFormsParsed(observed); // The post-navigation load.
138 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. 138 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout.
139 139
140 ASSERT_TRUE(form_to_save.get()); 140 ASSERT_TRUE(form_to_save.get());
141 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); 141 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form)));
142 142
143 // Simulate saving the form, as if the info bar was accepted. 143 // Simulate saving the form, as if the info bar was accepted.
144 form_to_save->Save(); 144 form_to_save->Save();
145 } 145 }
146 146
147 TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { 147 TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) {
148 // This test is the same FormSubmitEmptyStore, except that it simulates the 148 // This test is the same FormSubmitEmptyStore, except that it simulates the
149 // user generating the password through the browser. 149 // user generating the password through the browser.
150 std::vector<PasswordForm*> result; // Empty password store. 150 std::vector<PasswordForm*> result; // Empty password store.
151 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); 151 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0));
152 EXPECT_CALL(*store_, GetLogins(_,_)) 152 EXPECT_CALL(*store_.get(), GetLogins(_, _))
153 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); 153 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1)));
154 std::vector<PasswordForm> observed; 154 std::vector<PasswordForm> observed;
155 PasswordForm form(MakeSimpleForm()); 155 PasswordForm form(MakeSimpleForm());
156 observed.push_back(form); 156 observed.push_back(form);
157 manager()->OnPasswordFormsParsed(observed); // The initial load. 157 manager()->OnPasswordFormsParsed(observed); // The initial load.
158 manager()->OnPasswordFormsRendered(observed); // The initial layout. 158 manager()->OnPasswordFormsRendered(observed); // The initial layout.
159 159
160 // Simulate the user generating the password and submitting the form. 160 // Simulate the user generating the password and submitting the form.
161 manager()->SetFormHasGeneratedPassword(form); 161 manager()->SetFormHasGeneratedPassword(form);
162 manager()->ProvisionallySavePassword(form); 162 manager()->ProvisionallySavePassword(form);
163 163
164 // The user should not be presented with an infobar as they have already given 164 // The user should not be presented with an infobar as they have already given
165 // consent by using the generated password. The form should be saved once 165 // consent by using the generated password. The form should be saved once
166 // navigation occurs. 166 // navigation occurs.
167 EXPECT_CALL(delegate_, 167 EXPECT_CALL(delegate_,
168 AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(0)); 168 AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(0));
169 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); 169 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form)));
170 170
171 // Now the password manager waits for the navigation to complete. 171 // Now the password manager waits for the navigation to complete.
172 observed.clear(); 172 observed.clear();
173 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 173 manager()->OnPasswordFormsParsed(observed); // The post-navigation load.
174 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. 174 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout.
175 } 175 }
176 176
177 TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { 177 TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) {
178 // Same as above, except with an existing form for the same signon realm, 178 // Same as above, except with an existing form for the same signon realm,
179 // but different origin. Detailed cases like this are covered by 179 // but different origin. Detailed cases like this are covered by
180 // PasswordFormManagerTest. 180 // PasswordFormManagerTest.
181 std::vector<PasswordForm*> result; 181 std::vector<PasswordForm*> result;
182 PasswordForm* existing_different = new PasswordForm(MakeSimpleForm()); 182 PasswordForm* existing_different = new PasswordForm(MakeSimpleForm());
183 existing_different->username_value = ASCIIToUTF16("google2"); 183 existing_different->username_value = ASCIIToUTF16("google2");
184 result.push_back(existing_different); 184 result.push_back(existing_different);
185 EXPECT_CALL(delegate_, FillPasswordForm(_)); 185 EXPECT_CALL(delegate_, FillPasswordForm(_));
186 EXPECT_CALL(*store_, GetLogins(_,_)) 186 EXPECT_CALL(*store_.get(), GetLogins(_, _))
187 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); 187 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1)));
188 188
189 std::vector<PasswordForm> observed; 189 std::vector<PasswordForm> observed;
190 PasswordForm form(MakeSimpleForm()); 190 PasswordForm form(MakeSimpleForm());
191 observed.push_back(form); 191 observed.push_back(form);
192 manager()->OnPasswordFormsParsed(observed); // The initial load. 192 manager()->OnPasswordFormsParsed(observed); // The initial load.
193 manager()->OnPasswordFormsRendered(observed); // The initial layout. 193 manager()->OnPasswordFormsRendered(observed); // The initial layout.
194 manager()->ProvisionallySavePassword(form); 194 manager()->ProvisionallySavePassword(form);
195 195
196 // We still expect an add, since we didn't have a good match. 196 // We still expect an add, since we didn't have a good match.
197 scoped_ptr<PasswordFormManager> form_to_save; 197 scoped_ptr<PasswordFormManager> form_to_save;
198 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_)) 198 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_))
199 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); 199 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save)));
200 200
201 // Now the password manager waits for the navigation to complete. 201 // Now the password manager waits for the navigation to complete.
202 observed.clear(); 202 observed.clear();
203 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 203 manager()->OnPasswordFormsParsed(observed); // The post-navigation load.
204 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. 204 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout.
205 205
206 ASSERT_TRUE(form_to_save.get()); 206 ASSERT_TRUE(form_to_save.get());
207 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); 207 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form)));
208 208
209 // Simulate saving the form. 209 // Simulate saving the form.
210 form_to_save->Save(); 210 form_to_save->Save();
211 } 211 }
212 212
213 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { 213 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) {
214 std::vector<PasswordForm*> result; // Empty password store. 214 std::vector<PasswordForm*> result; // Empty password store.
215 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); 215 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0));
216 EXPECT_CALL(*store_, GetLogins(_,_)) 216 EXPECT_CALL(*store_.get(), GetLogins(_, _))
217 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); 217 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1)));
218 std::vector<PasswordForm> observed; 218 std::vector<PasswordForm> observed;
219 PasswordForm form(MakeSimpleForm()); 219 PasswordForm form(MakeSimpleForm());
220 observed.push_back(form); 220 observed.push_back(form);
221 manager()->OnPasswordFormsParsed(observed); // The initial load. 221 manager()->OnPasswordFormsParsed(observed); // The initial load.
222 manager()->OnPasswordFormsRendered(observed); // The initial layout. 222 manager()->OnPasswordFormsRendered(observed); // The initial layout.
223 223
224 PasswordForm empty_form(form); 224 PasswordForm empty_form(form);
225 empty_form.username_value = string16(); 225 empty_form.username_value = string16();
226 empty_form.password_value = string16(); 226 empty_form.password_value = string16();
227 content::LoadCommittedDetails details; 227 content::LoadCommittedDetails details;
228 content::FrameNavigateParams params; 228 content::FrameNavigateParams params;
229 params.password_form = empty_form; 229 params.password_form = empty_form;
230 manager()->DidNavigateAnyFrame(details, params); 230 manager()->DidNavigateAnyFrame(details, params);
231 231
232 // No expected calls. 232 // No expected calls.
233 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_)).Times(0); 233 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_)).Times(0);
234 observed.clear(); 234 observed.clear();
235 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 235 manager()->OnPasswordFormsParsed(observed); // The post-navigation load.
236 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. 236 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout.
237 } 237 }
238 238
239 TEST_F(PasswordManagerTest, FormSubmitAfterNavigateSubframe) { 239 TEST_F(PasswordManagerTest, FormSubmitAfterNavigateSubframe) {
240 // Test that navigating a subframe does not prevent us from showing the save 240 // Test that navigating a subframe does not prevent us from showing the save
241 // password infobar. 241 // password infobar.
242 std::vector<PasswordForm*> result; // Empty password store. 242 std::vector<PasswordForm*> result; // Empty password store.
243 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); 243 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0));
244 EXPECT_CALL(*store_, GetLogins(_,_)) 244 EXPECT_CALL(*store_.get(), GetLogins(_, _))
245 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); 245 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1)));
246 std::vector<PasswordForm> observed; 246 std::vector<PasswordForm> observed;
247 PasswordForm form(MakeSimpleForm()); 247 PasswordForm form(MakeSimpleForm());
248 observed.push_back(form); 248 observed.push_back(form);
249 manager()->OnPasswordFormsParsed(observed); // The initial load. 249 manager()->OnPasswordFormsParsed(observed); // The initial load.
250 manager()->OnPasswordFormsRendered(observed); // The initial layout. 250 manager()->OnPasswordFormsRendered(observed); // The initial layout.
251 251
252 // Simulate navigating a sub-frame. 252 // Simulate navigating a sub-frame.
253 content::LoadCommittedDetails details; 253 content::LoadCommittedDetails details;
254 details.is_main_frame = false; 254 details.is_main_frame = false;
255 content::FrameNavigateParams params; 255 content::FrameNavigateParams params;
256 manager()->DidNavigateAnyFrame(details, params); 256 manager()->DidNavigateAnyFrame(details, params);
257 257
258 // Simulate navigating the real page. 258 // Simulate navigating the real page.
259 details.is_main_frame = true; 259 details.is_main_frame = true;
260 params.password_form = form; 260 params.password_form = form;
261 manager()->DidNavigateAnyFrame(details, params); 261 manager()->DidNavigateAnyFrame(details, params);
262 262
263 // Now the password manager waits for the navigation to complete. 263 // Now the password manager waits for the navigation to complete.
264 scoped_ptr<PasswordFormManager> form_to_save; 264 scoped_ptr<PasswordFormManager> form_to_save;
265 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_)) 265 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_))
266 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); 266 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save)));
267 267
268 observed.clear(); 268 observed.clear();
269 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 269 manager()->OnPasswordFormsParsed(observed); // The post-navigation load.
270 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. 270 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout.
271 271
272 ASSERT_FALSE(NULL == form_to_save.get()); 272 ASSERT_FALSE(NULL == form_to_save.get());
273 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); 273 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form)));
274 274
275 // Simulate saving the form, as if the info bar was accepted. 275 // Simulate saving the form, as if the info bar was accepted.
276 form_to_save->Save(); 276 form_to_save->Save();
277 } 277 }
278 278
279 // This test verifies a fix for http://crbug.com/236673 279 // This test verifies a fix for http://crbug.com/236673
280 TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { 280 TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) {
281 std::vector<PasswordForm*> result; // Empty password store. 281 std::vector<PasswordForm*> result; // Empty password store.
282 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); 282 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0));
283 EXPECT_CALL(*store_, GetLogins(_,_)) 283 EXPECT_CALL(*store_.get(), GetLogins(_, _))
284 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); 284 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1)));
285 PasswordForm first_form(MakeSimpleForm()); 285 PasswordForm first_form(MakeSimpleForm());
286 first_form.origin = GURL("http://www.nytimes.com/"); 286 first_form.origin = GURL("http://www.nytimes.com/");
287 first_form.action = GURL("https://myaccount.nytimes.com/auth/login"); 287 first_form.action = GURL("https://myaccount.nytimes.com/auth/login");
288 first_form.signon_realm = "http://www.nytimes.com/"; 288 first_form.signon_realm = "http://www.nytimes.com/";
289 PasswordForm second_form(MakeSimpleForm()); 289 PasswordForm second_form(MakeSimpleForm());
290 second_form.origin = GURL("https://myaccount.nytimes.com/auth/login"); 290 second_form.origin = GURL("https://myaccount.nytimes.com/auth/login");
291 second_form.action = GURL("https://myaccount.nytimes.com/auth/login"); 291 second_form.action = GURL("https://myaccount.nytimes.com/auth/login");
292 second_form.signon_realm = "https://myaccount.nytimes.com/"; 292 second_form.signon_realm = "https://myaccount.nytimes.com/";
293 293
(...skipping 23 matching lines...) Expand all
317 // Navigation after form submit. 317 // Navigation after form submit.
318 scoped_ptr<PasswordFormManager> form_to_save; 318 scoped_ptr<PasswordFormManager> form_to_save;
319 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_)) 319 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_))
320 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); 320 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save)));
321 observed.clear(); 321 observed.clear();
322 manager()->OnPasswordFormsParsed(observed); 322 manager()->OnPasswordFormsParsed(observed);
323 manager()->OnPasswordFormsRendered(observed); 323 manager()->OnPasswordFormsRendered(observed);
324 324
325 // Make sure that the saved form matches the second form, not the first. 325 // Make sure that the saved form matches the second form, not the first.
326 ASSERT_TRUE(form_to_save.get()); 326 ASSERT_TRUE(form_to_save.get());
327 EXPECT_CALL(*store_, AddLogin(FormMatches(second_form))); 327 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(second_form)));
328 328
329 // Simulate saving the form, as if the info bar was accepted. 329 // Simulate saving the form, as if the info bar was accepted.
330 form_to_save->Save(); 330 form_to_save->Save();
331 } 331 }
332 332
333 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { 333 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) {
334 std::vector<PasswordForm*> result; // Empty password store. 334 std::vector<PasswordForm*> result; // Empty password store.
335 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); 335 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0));
336 EXPECT_CALL(*store_, GetLogins(_,_)) 336 EXPECT_CALL(*store_.get(), GetLogins(_, _))
337 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); 337 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1)));
338 std::vector<PasswordForm> observed; 338 std::vector<PasswordForm> observed;
339 PasswordForm form(MakeSimpleForm()); 339 PasswordForm form(MakeSimpleForm());
340 observed.push_back(form); 340 observed.push_back(form);
341 manager()->OnPasswordFormsParsed(observed); // The initial load. 341 manager()->OnPasswordFormsParsed(observed); // The initial load.
342 manager()->OnPasswordFormsRendered(observed); // The initial layout. 342 manager()->OnPasswordFormsRendered(observed); // The initial layout.
343 343
344 manager()->ProvisionallySavePassword(form); 344 manager()->ProvisionallySavePassword(form);
345 345
346 // The form reappears, and is visible in the layout: 346 // The form reappears, and is visible in the layout:
347 // No expected calls to the PasswordStore... 347 // No expected calls to the PasswordStore...
348 manager()->OnPasswordFormsParsed(observed); 348 manager()->OnPasswordFormsParsed(observed);
349 manager()->OnPasswordFormsRendered(observed); 349 manager()->OnPasswordFormsRendered(observed);
350 } 350 }
351 351
352 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { 352 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) {
353 // Tests fix of issue 28911: if the login form reappears on the subsequent 353 // Tests fix of issue 28911: if the login form reappears on the subsequent
354 // page, but is invisible, it shouldn't count as a failed login. 354 // page, but is invisible, it shouldn't count as a failed login.
355 std::vector<PasswordForm*> result; // Empty password store. 355 std::vector<PasswordForm*> result; // Empty password store.
356 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); 356 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0));
357 EXPECT_CALL(*store_, GetLogins(_,_)) 357 EXPECT_CALL(*store_.get(), GetLogins(_, _))
358 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); 358 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1)));
359 std::vector<PasswordForm> observed; 359 std::vector<PasswordForm> observed;
360 PasswordForm form(MakeSimpleForm()); 360 PasswordForm form(MakeSimpleForm());
361 observed.push_back(form); 361 observed.push_back(form);
362 manager()->OnPasswordFormsParsed(observed); // The initial load. 362 manager()->OnPasswordFormsParsed(observed); // The initial load.
363 manager()->OnPasswordFormsRendered(observed); // The initial layout. 363 manager()->OnPasswordFormsRendered(observed); // The initial layout.
364 364
365 manager()->ProvisionallySavePassword(form); 365 manager()->ProvisionallySavePassword(form);
366 366
367 // Expect info bar to appear: 367 // Expect info bar to appear:
368 scoped_ptr<PasswordFormManager> form_to_save; 368 scoped_ptr<PasswordFormManager> form_to_save;
369 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_)) 369 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_))
370 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); 370 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save)));
371 371
372 // The form reappears, but is not visible in the layout: 372 // The form reappears, but is not visible in the layout:
373 manager()->OnPasswordFormsParsed(observed); 373 manager()->OnPasswordFormsParsed(observed);
374 observed.clear(); 374 observed.clear();
375 manager()->OnPasswordFormsRendered(observed); 375 manager()->OnPasswordFormsRendered(observed);
376 376
377 ASSERT_TRUE(form_to_save.get()); 377 ASSERT_TRUE(form_to_save.get());
378 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); 378 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form)));
379 379
380 // Simulate saving the form. 380 // Simulate saving the form.
381 form_to_save->Save(); 381 form_to_save->Save();
382 } 382 }
383 383
384 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { 384 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) {
385 // Make sure an invisible login form still gets autofilled. 385 // Make sure an invisible login form still gets autofilled.
386 std::vector<PasswordForm*> result; 386 std::vector<PasswordForm*> result;
387 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); 387 PasswordForm* existing = new PasswordForm(MakeSimpleForm());
388 result.push_back(existing); 388 result.push_back(existing);
389 EXPECT_CALL(delegate_, FillPasswordForm(_)); 389 EXPECT_CALL(delegate_, FillPasswordForm(_));
390 EXPECT_CALL(*store_, GetLogins(_,_)) 390 EXPECT_CALL(*store_.get(), GetLogins(_, _))
391 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); 391 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1)));
392 std::vector<PasswordForm> observed; 392 std::vector<PasswordForm> observed;
393 PasswordForm form(MakeSimpleForm()); 393 PasswordForm form(MakeSimpleForm());
394 observed.push_back(form); 394 observed.push_back(form);
395 manager()->OnPasswordFormsParsed(observed); // The initial load. 395 manager()->OnPasswordFormsParsed(observed); // The initial load.
396 observed.clear(); 396 observed.clear();
397 manager()->OnPasswordFormsRendered(observed); // The initial layout. 397 manager()->OnPasswordFormsRendered(observed); // The initial layout.
398 398
399 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 399 manager()->OnPasswordFormsParsed(observed); // The post-navigation load.
400 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. 400 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout.
(...skipping 16 matching lines...) Expand all
417 // Test fix for issue 158296: Passwords must be filled even if the password 417 // Test fix for issue 158296: Passwords must be filled even if the password
418 // manager is disabled. 418 // manager is disabled.
419 std::vector<PasswordForm*> result; 419 std::vector<PasswordForm*> result;
420 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); 420 PasswordForm* existing = new PasswordForm(MakeSimpleForm());
421 result.push_back(existing); 421 result.push_back(existing);
422 TestingPrefServiceSyncable* prefService = 422 TestingPrefServiceSyncable* prefService =
423 testing_profile_->GetTestingPrefService(); 423 testing_profile_->GetTestingPrefService();
424 prefService->SetUserPref(prefs::kPasswordManagerEnabled, 424 prefService->SetUserPref(prefs::kPasswordManagerEnabled,
425 Value::CreateBooleanValue(false)); 425 Value::CreateBooleanValue(false));
426 EXPECT_CALL(delegate_, FillPasswordForm(_)); 426 EXPECT_CALL(delegate_, FillPasswordForm(_));
427 EXPECT_CALL(*store_, GetLogins(_, _)) 427 EXPECT_CALL(*store_.get(), GetLogins(_, _))
428 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); 428 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1)));
429 std::vector<PasswordForm> observed; 429 std::vector<PasswordForm> observed;
430 PasswordForm form(MakeSimpleForm()); 430 PasswordForm form(MakeSimpleForm());
431 observed.push_back(form); 431 observed.push_back(form);
432 manager()->OnPasswordFormsParsed(observed); 432 manager()->OnPasswordFormsParsed(observed);
433 } 433 }
434 434
435 TEST_F(PasswordManagerTest, FormNotSavedAutocompleteOff) { 435 TEST_F(PasswordManagerTest, FormNotSavedAutocompleteOff) {
436 // Test password form with non-generated password will not be saved if 436 // Test password form with non-generated password will not be saved if
437 // autocomplete=off. 437 // autocomplete=off.
438 std::vector<PasswordForm*> result; // Empty password store. 438 std::vector<PasswordForm*> result; // Empty password store.
439 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); 439 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0));
440 EXPECT_CALL(*store_, GetLogins(_,_)) 440 EXPECT_CALL(*store_.get(), GetLogins(_, _))
441 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); 441 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1)));
442 std::vector<PasswordForm> observed; 442 std::vector<PasswordForm> observed;
443 PasswordForm form(MakeSimpleForm()); 443 PasswordForm form(MakeSimpleForm());
444 form.password_autocomplete_set = false; 444 form.password_autocomplete_set = false;
445 observed.push_back(form); 445 observed.push_back(form);
446 manager()->OnPasswordFormsParsed(observed); // The initial load. 446 manager()->OnPasswordFormsParsed(observed); // The initial load.
447 manager()->OnPasswordFormsRendered(observed); // The initial layout. 447 manager()->OnPasswordFormsRendered(observed); // The initial layout.
448 448
449 // And the form submit contract is to call ProvisionallySavePassword. 449 // And the form submit contract is to call ProvisionallySavePassword.
450 manager()->ProvisionallySavePassword(form); 450 manager()->ProvisionallySavePassword(form);
451 451
452 // Password form should not be saved. 452 // Password form should not be saved.
453 EXPECT_CALL(delegate_, 453 EXPECT_CALL(delegate_,
454 AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(0)); 454 AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(0));
455 EXPECT_CALL(*store_, AddLogin(FormMatches(form))).Times(Exactly(0)); 455 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0));
456 456
457 // Now the password manager waits for the navigation to complete. 457 // Now the password manager waits for the navigation to complete.
458 observed.clear(); 458 observed.clear();
459 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 459 manager()->OnPasswordFormsParsed(observed); // The post-navigation load.
460 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. 460 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout.
461 } 461 }
462 462
463 TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) { 463 TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) {
464 // Test password form with generated password will still be saved if 464 // Test password form with generated password will still be saved if
465 // autocomplete=off. 465 // autocomplete=off.
466 std::vector<PasswordForm*> result; // Empty password store. 466 std::vector<PasswordForm*> result; // Empty password store.
467 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); 467 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0));
468 EXPECT_CALL(*store_, GetLogins(_,_)) 468 EXPECT_CALL(*store_.get(), GetLogins(_, _))
469 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); 469 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1)));
470 std::vector<PasswordForm> observed; 470 std::vector<PasswordForm> observed;
471 PasswordForm form(MakeSimpleForm()); 471 PasswordForm form(MakeSimpleForm());
472 form.password_autocomplete_set = false; 472 form.password_autocomplete_set = false;
473 observed.push_back(form); 473 observed.push_back(form);
474 manager()->OnPasswordFormsParsed(observed); // The initial load. 474 manager()->OnPasswordFormsParsed(observed); // The initial load.
475 manager()->OnPasswordFormsRendered(observed); // The initial layout. 475 manager()->OnPasswordFormsRendered(observed); // The initial layout.
476 476
477 // Simulate the user generating the password and submitting the form. 477 // Simulate the user generating the password and submitting the form.
478 manager()->SetFormHasGeneratedPassword(form); 478 manager()->SetFormHasGeneratedPassword(form);
479 manager()->ProvisionallySavePassword(form); 479 manager()->ProvisionallySavePassword(form);
480 480
481 // The user should not be presented with an infobar as they have already given 481 // The user should not be presented with an infobar as they have already given
482 // consent by using the generated password. The form should be saved once 482 // consent by using the generated password. The form should be saved once
483 // navigation occurs. 483 // navigation occurs.
484 EXPECT_CALL(delegate_, 484 EXPECT_CALL(delegate_,
485 AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(0)); 485 AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(0));
486 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); 486 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form)));
487 487
488 // Now the password manager waits for the navigation to complete. 488 // Now the password manager waits for the navigation to complete.
489 observed.clear(); 489 observed.clear();
490 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 490 manager()->OnPasswordFormsParsed(observed); // The post-navigation load.
491 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. 491 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout.
492 } 492 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698