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/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/prefs/pref_registry_simple.h" | 8 #include "base/prefs/pref_registry_simple.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { | 203 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { |
204 // Test that observing a newly submitted form shows the save password bar. | 204 // Test that observing a newly submitted form shows the save password bar. |
205 std::vector<PasswordForm*> result; // Empty password store. | 205 std::vector<PasswordForm*> result; // Empty password store. |
206 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 206 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
207 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 207 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
208 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 208 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
209 std::vector<PasswordForm> observed; | 209 std::vector<PasswordForm> observed; |
210 PasswordForm form(MakeSimpleForm()); | 210 PasswordForm form(MakeSimpleForm()); |
211 observed.push_back(form); | 211 observed.push_back(form); |
212 manager()->OnPasswordFormsParsed(observed); // The initial load. | 212 manager()->OnPasswordFormsParsed(observed); // The initial load. |
213 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 213 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
214 | 214 |
215 // And the form submit contract is to call ProvisionallySavePassword. | 215 // And the form submit contract is to call ProvisionallySavePassword. |
216 manager()->ProvisionallySavePassword(form); | 216 manager()->ProvisionallySavePassword(form); |
217 | 217 |
218 scoped_ptr<PasswordFormManager> form_to_save; | 218 scoped_ptr<PasswordFormManager> form_to_save; |
219 EXPECT_CALL(client_, PromptUserToSavePassword(_)) | 219 EXPECT_CALL(client_, PromptUserToSavePassword(_)) |
220 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 220 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
221 | 221 |
222 // Now the password manager waits for the navigation to complete. | 222 // Now the password manager waits for the navigation to complete. |
223 observed.clear(); | 223 observed.clear(); |
224 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 224 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
225 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 225 manager()->OnPasswordFormsRendered(observed, |
| 226 true); // The post-navigation layout. |
226 | 227 |
227 ASSERT_TRUE(form_to_save.get()); | 228 ASSERT_TRUE(form_to_save.get()); |
228 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 229 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
229 | 230 |
230 // Simulate saving the form, as if the info bar was accepted. | 231 // Simulate saving the form, as if the info bar was accepted. |
231 form_to_save->Save(); | 232 form_to_save->Save(); |
232 } | 233 } |
233 | 234 |
234 TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { | 235 TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { |
235 // This test is the same FormSubmitEmptyStore, except that it simulates the | 236 // This test is the same FormSubmitEmptyStore, except that it simulates the |
236 // user generating the password through the browser. | 237 // user generating the password through the browser. |
237 std::vector<PasswordForm*> result; // Empty password store. | 238 std::vector<PasswordForm*> result; // Empty password store. |
238 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 239 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
239 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 240 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
240 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 241 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
241 std::vector<PasswordForm> observed; | 242 std::vector<PasswordForm> observed; |
242 PasswordForm form(MakeSimpleForm()); | 243 PasswordForm form(MakeSimpleForm()); |
243 observed.push_back(form); | 244 observed.push_back(form); |
244 manager()->OnPasswordFormsParsed(observed); // The initial load. | 245 manager()->OnPasswordFormsParsed(observed); // The initial load. |
245 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 246 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
246 | 247 |
247 // Simulate the user generating the password and submitting the form. | 248 // Simulate the user generating the password and submitting the form. |
248 manager()->SetFormHasGeneratedPassword(form); | 249 manager()->SetFormHasGeneratedPassword(form); |
249 manager()->ProvisionallySavePassword(form); | 250 manager()->ProvisionallySavePassword(form); |
250 | 251 |
251 // The user should not be presented with an infobar as they have already given | 252 // The user should not be presented with an infobar as they have already given |
252 // consent by using the generated password. The form should be saved once | 253 // consent by using the generated password. The form should be saved once |
253 // navigation occurs. | 254 // navigation occurs. |
254 EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(Exactly(0)); | 255 EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(Exactly(0)); |
255 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 256 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
256 | 257 |
257 // Now the password manager waits for the navigation to complete. | 258 // Now the password manager waits for the navigation to complete. |
258 observed.clear(); | 259 observed.clear(); |
259 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 260 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
260 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 261 manager()->OnPasswordFormsRendered(observed, |
| 262 true); // The post-navigation layout. |
261 } | 263 } |
262 | 264 |
263 TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { | 265 TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { |
264 // Same as above, except with an existing form for the same signon realm, | 266 // Same as above, except with an existing form for the same signon realm, |
265 // but different origin. Detailed cases like this are covered by | 267 // but different origin. Detailed cases like this are covered by |
266 // PasswordFormManagerTest. | 268 // PasswordFormManagerTest. |
267 std::vector<PasswordForm*> result; | 269 std::vector<PasswordForm*> result; |
268 PasswordForm* existing_different = new PasswordForm(MakeSimpleForm()); | 270 PasswordForm* existing_different = new PasswordForm(MakeSimpleForm()); |
269 existing_different->username_value = ASCIIToUTF16("google2"); | 271 existing_different->username_value = ASCIIToUTF16("google2"); |
270 result.push_back(existing_different); | 272 result.push_back(existing_different); |
271 EXPECT_CALL(driver_, FillPasswordForm(_)); | 273 EXPECT_CALL(driver_, FillPasswordForm(_)); |
272 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 274 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
273 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 275 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
274 | 276 |
275 std::vector<PasswordForm> observed; | 277 std::vector<PasswordForm> observed; |
276 PasswordForm form(MakeSimpleForm()); | 278 PasswordForm form(MakeSimpleForm()); |
277 observed.push_back(form); | 279 observed.push_back(form); |
278 manager()->OnPasswordFormsParsed(observed); // The initial load. | 280 manager()->OnPasswordFormsParsed(observed); // The initial load. |
279 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 281 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
280 manager()->ProvisionallySavePassword(form); | 282 manager()->ProvisionallySavePassword(form); |
281 | 283 |
282 // We still expect an add, since we didn't have a good match. | 284 // We still expect an add, since we didn't have a good match. |
283 scoped_ptr<PasswordFormManager> form_to_save; | 285 scoped_ptr<PasswordFormManager> form_to_save; |
284 EXPECT_CALL(client_, PromptUserToSavePassword(_)) | 286 EXPECT_CALL(client_, PromptUserToSavePassword(_)) |
285 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 287 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
286 | 288 |
287 // Now the password manager waits for the navigation to complete. | 289 // Now the password manager waits for the navigation to complete. |
288 observed.clear(); | 290 observed.clear(); |
289 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 291 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
290 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 292 manager()->OnPasswordFormsRendered(observed, |
| 293 true); // The post-navigation layout. |
291 | 294 |
292 ASSERT_TRUE(form_to_save.get()); | 295 ASSERT_TRUE(form_to_save.get()); |
293 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 296 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
294 | 297 |
295 // Simulate saving the form. | 298 // Simulate saving the form. |
296 form_to_save->Save(); | 299 form_to_save->Save(); |
297 } | 300 } |
298 | 301 |
299 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { | 302 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { |
300 std::vector<PasswordForm*> result; // Empty password store. | 303 std::vector<PasswordForm*> result; // Empty password store. |
301 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 304 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
302 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 305 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
303 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 306 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
304 std::vector<PasswordForm> observed; | 307 std::vector<PasswordForm> observed; |
305 PasswordForm form(MakeSimpleForm()); | 308 PasswordForm form(MakeSimpleForm()); |
306 observed.push_back(form); | 309 observed.push_back(form); |
307 manager()->OnPasswordFormsParsed(observed); // The initial load. | 310 manager()->OnPasswordFormsParsed(observed); // The initial load. |
308 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 311 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
309 | 312 |
310 // No message from the renderer that a password was submitted. No | 313 // No message from the renderer that a password was submitted. No |
311 // expected calls. | 314 // expected calls. |
312 EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(0); | 315 EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(0); |
313 observed.clear(); | 316 observed.clear(); |
314 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 317 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
315 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 318 manager()->OnPasswordFormsRendered(observed, |
| 319 true); // The post-navigation layout. |
316 } | 320 } |
317 | 321 |
318 TEST_F(PasswordManagerTest, FormSubmitAfterNavigateInPage) { | 322 TEST_F(PasswordManagerTest, FormSubmitAfterNavigateInPage) { |
319 // Test that navigating in the page does not prevent us from showing the save | 323 // Test that navigating in the page does not prevent us from showing the save |
320 // password infobar. | 324 // password infobar. |
321 std::vector<PasswordForm*> result; // Empty password store. | 325 std::vector<PasswordForm*> result; // Empty password store. |
322 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 326 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
323 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 327 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
324 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 328 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
325 std::vector<PasswordForm> observed; | 329 std::vector<PasswordForm> observed; |
326 PasswordForm form(MakeSimpleForm()); | 330 PasswordForm form(MakeSimpleForm()); |
327 observed.push_back(form); | 331 observed.push_back(form); |
328 manager()->OnPasswordFormsParsed(observed); // The initial load. | 332 manager()->OnPasswordFormsParsed(observed); // The initial load. |
329 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 333 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
330 | 334 |
331 // Simulate navigating in the page. | 335 // Simulate navigating in the page. |
332 manager()->DidNavigateMainFrame(true); | 336 manager()->DidNavigateMainFrame(true); |
333 | 337 |
334 // Simulate submitting the password. | 338 // Simulate submitting the password. |
335 OnPasswordFormSubmitted(form); | 339 OnPasswordFormSubmitted(form); |
336 | 340 |
337 // Now the password manager waits for the navigation to complete. | 341 // Now the password manager waits for the navigation to complete. |
338 scoped_ptr<PasswordFormManager> form_to_save; | 342 scoped_ptr<PasswordFormManager> form_to_save; |
339 EXPECT_CALL(client_, PromptUserToSavePassword(_)) | 343 EXPECT_CALL(client_, PromptUserToSavePassword(_)) |
340 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 344 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
341 | 345 |
342 observed.clear(); | 346 observed.clear(); |
343 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 347 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
344 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 348 manager()->OnPasswordFormsRendered(observed, |
| 349 true); // The post-navigation layout. |
345 | 350 |
346 ASSERT_FALSE(NULL == form_to_save.get()); | 351 ASSERT_FALSE(NULL == form_to_save.get()); |
347 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 352 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
348 | 353 |
349 // Simulate saving the form, as if the info bar was accepted. | 354 // Simulate saving the form, as if the info bar was accepted. |
350 form_to_save->Save(); | 355 form_to_save->Save(); |
351 } | 356 } |
352 | 357 |
353 // This test verifies a fix for http://crbug.com/236673 | 358 // This test verifies a fix for http://crbug.com/236673 |
354 TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { | 359 TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { |
355 std::vector<PasswordForm*> result; // Empty password store. | 360 std::vector<PasswordForm*> result; // Empty password store. |
356 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 361 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
357 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 362 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
358 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 363 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
359 PasswordForm first_form(MakeSimpleForm()); | 364 PasswordForm first_form(MakeSimpleForm()); |
360 first_form.origin = GURL("http://www.nytimes.com/"); | 365 first_form.origin = GURL("http://www.nytimes.com/"); |
361 first_form.action = GURL("https://myaccount.nytimes.com/auth/login"); | 366 first_form.action = GURL("https://myaccount.nytimes.com/auth/login"); |
362 first_form.signon_realm = "http://www.nytimes.com/"; | 367 first_form.signon_realm = "http://www.nytimes.com/"; |
363 PasswordForm second_form(MakeSimpleForm()); | 368 PasswordForm second_form(MakeSimpleForm()); |
364 second_form.origin = GURL("https://myaccount.nytimes.com/auth/login"); | 369 second_form.origin = GURL("https://myaccount.nytimes.com/auth/login"); |
365 second_form.action = GURL("https://myaccount.nytimes.com/auth/login"); | 370 second_form.action = GURL("https://myaccount.nytimes.com/auth/login"); |
366 second_form.signon_realm = "https://myaccount.nytimes.com/"; | 371 second_form.signon_realm = "https://myaccount.nytimes.com/"; |
367 | 372 |
368 // Pretend that the form is hidden on the first page. | 373 // Pretend that the form is hidden on the first page. |
369 std::vector<PasswordForm> observed; | 374 std::vector<PasswordForm> observed; |
370 observed.push_back(first_form); | 375 observed.push_back(first_form); |
371 manager()->OnPasswordFormsParsed(observed); | 376 manager()->OnPasswordFormsParsed(observed); |
372 observed.clear(); | 377 observed.clear(); |
373 manager()->OnPasswordFormsRendered(observed); | 378 manager()->OnPasswordFormsRendered(observed, true); |
374 | 379 |
375 // Now navigate to a second page. | 380 // Now navigate to a second page. |
376 manager()->DidNavigateMainFrame(false); | 381 manager()->DidNavigateMainFrame(false); |
377 | 382 |
378 // This page contains a form with the same markup, but on a different | 383 // This page contains a form with the same markup, but on a different |
379 // URL. | 384 // URL. |
380 observed.push_back(second_form); | 385 observed.push_back(second_form); |
381 manager()->OnPasswordFormsParsed(observed); | 386 manager()->OnPasswordFormsParsed(observed); |
382 manager()->OnPasswordFormsRendered(observed); | 387 manager()->OnPasswordFormsRendered(observed, true); |
383 | 388 |
384 // Now submit this form | 389 // Now submit this form |
385 OnPasswordFormSubmitted(second_form); | 390 OnPasswordFormSubmitted(second_form); |
386 | 391 |
387 // Navigation after form submit. | 392 // Navigation after form submit. |
388 scoped_ptr<PasswordFormManager> form_to_save; | 393 scoped_ptr<PasswordFormManager> form_to_save; |
389 EXPECT_CALL(client_, PromptUserToSavePassword(_)) | 394 EXPECT_CALL(client_, PromptUserToSavePassword(_)) |
390 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 395 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
391 observed.clear(); | 396 observed.clear(); |
392 manager()->OnPasswordFormsParsed(observed); | 397 manager()->OnPasswordFormsParsed(observed); |
393 manager()->OnPasswordFormsRendered(observed); | 398 manager()->OnPasswordFormsRendered(observed, true); |
394 | 399 |
395 // Make sure that the saved form matches the second form, not the first. | 400 // Make sure that the saved form matches the second form, not the first. |
396 ASSERT_TRUE(form_to_save.get()); | 401 ASSERT_TRUE(form_to_save.get()); |
397 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(second_form))); | 402 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(second_form))); |
398 | 403 |
399 // Simulate saving the form, as if the info bar was accepted. | 404 // Simulate saving the form, as if the info bar was accepted. |
400 form_to_save->Save(); | 405 form_to_save->Save(); |
401 } | 406 } |
402 | 407 |
403 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { | 408 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { |
404 std::vector<PasswordForm*> result; // Empty password store. | 409 std::vector<PasswordForm*> result; // Empty password store. |
405 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 410 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
406 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 411 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
407 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 412 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
408 std::vector<PasswordForm> observed; | 413 std::vector<PasswordForm> observed; |
409 PasswordForm form(MakeSimpleForm()); | 414 PasswordForm form(MakeSimpleForm()); |
410 observed.push_back(form); | 415 observed.push_back(form); |
411 manager()->OnPasswordFormsParsed(observed); // The initial load. | 416 manager()->OnPasswordFormsParsed(observed); // The initial load. |
412 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 417 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
413 | 418 |
414 manager()->ProvisionallySavePassword(form); | 419 manager()->ProvisionallySavePassword(form); |
415 | 420 |
416 // The form reappears, and is visible in the layout: | 421 // The form reappears, and is visible in the layout: |
417 // No expected calls to the PasswordStore... | 422 // No expected calls to the PasswordStore... |
418 manager()->OnPasswordFormsParsed(observed); | 423 manager()->OnPasswordFormsParsed(observed); |
419 manager()->OnPasswordFormsRendered(observed); | 424 manager()->OnPasswordFormsRendered(observed, true); |
420 } | 425 } |
421 | 426 |
422 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { | 427 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { |
423 // Tests fix of issue 28911: if the login form reappears on the subsequent | 428 // Tests fix of issue 28911: if the login form reappears on the subsequent |
424 // page, but is invisible, it shouldn't count as a failed login. | 429 // page, but is invisible, it shouldn't count as a failed login. |
425 std::vector<PasswordForm*> result; // Empty password store. | 430 std::vector<PasswordForm*> result; // Empty password store. |
426 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 431 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
427 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 432 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
428 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 433 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
429 std::vector<PasswordForm> observed; | 434 std::vector<PasswordForm> observed; |
430 PasswordForm form(MakeSimpleForm()); | 435 PasswordForm form(MakeSimpleForm()); |
431 observed.push_back(form); | 436 observed.push_back(form); |
432 manager()->OnPasswordFormsParsed(observed); // The initial load. | 437 manager()->OnPasswordFormsParsed(observed); // The initial load. |
433 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 438 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
434 | 439 |
435 manager()->ProvisionallySavePassword(form); | 440 manager()->ProvisionallySavePassword(form); |
436 | 441 |
437 // Expect info bar to appear: | 442 // Expect info bar to appear: |
438 scoped_ptr<PasswordFormManager> form_to_save; | 443 scoped_ptr<PasswordFormManager> form_to_save; |
439 EXPECT_CALL(client_, PromptUserToSavePassword(_)) | 444 EXPECT_CALL(client_, PromptUserToSavePassword(_)) |
440 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 445 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
441 | 446 |
442 // The form reappears, but is not visible in the layout: | 447 // The form reappears, but is not visible in the layout: |
443 manager()->OnPasswordFormsParsed(observed); | 448 manager()->OnPasswordFormsParsed(observed); |
444 observed.clear(); | 449 observed.clear(); |
445 manager()->OnPasswordFormsRendered(observed); | 450 manager()->OnPasswordFormsRendered(observed, true); |
446 | 451 |
447 ASSERT_TRUE(form_to_save.get()); | 452 ASSERT_TRUE(form_to_save.get()); |
448 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 453 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
449 | 454 |
450 // Simulate saving the form. | 455 // Simulate saving the form. |
451 form_to_save->Save(); | 456 form_to_save->Save(); |
452 } | 457 } |
453 | 458 |
454 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { | 459 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { |
455 // Make sure an invisible login form still gets autofilled. | 460 // Make sure an invisible login form still gets autofilled. |
456 std::vector<PasswordForm*> result; | 461 std::vector<PasswordForm*> result; |
457 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); | 462 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); |
458 result.push_back(existing); | 463 result.push_back(existing); |
459 EXPECT_CALL(driver_, FillPasswordForm(_)); | 464 EXPECT_CALL(driver_, FillPasswordForm(_)); |
460 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 465 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
461 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 466 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
462 std::vector<PasswordForm> observed; | 467 std::vector<PasswordForm> observed; |
463 PasswordForm form(MakeSimpleForm()); | 468 PasswordForm form(MakeSimpleForm()); |
464 observed.push_back(form); | 469 observed.push_back(form); |
465 manager()->OnPasswordFormsParsed(observed); // The initial load. | 470 manager()->OnPasswordFormsParsed(observed); // The initial load. |
466 observed.clear(); | 471 observed.clear(); |
467 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 472 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
468 | 473 |
469 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 474 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
470 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 475 manager()->OnPasswordFormsRendered(observed, |
| 476 true); // The post-navigation layout. |
471 } | 477 } |
472 | 478 |
473 TEST_F(PasswordManagerTest, SavingDependsOnManagerEnabledPreference) { | 479 TEST_F(PasswordManagerTest, SavingDependsOnManagerEnabledPreference) { |
474 // Test that saving passwords depends on the password manager enabled | 480 // Test that saving passwords depends on the password manager enabled |
475 // preference. | 481 // preference. |
476 prefs_.SetUserPref(prefs::kPasswordManagerEnabled, | 482 prefs_.SetUserPref(prefs::kPasswordManagerEnabled, |
477 base::Value::CreateBooleanValue(true)); | 483 base::Value::CreateBooleanValue(true)); |
478 EXPECT_TRUE(manager()->IsSavingEnabled()); | 484 EXPECT_TRUE(manager()->IsSavingEnabled()); |
479 prefs_.SetUserPref(prefs::kPasswordManagerEnabled, | 485 prefs_.SetUserPref(prefs::kPasswordManagerEnabled, |
480 base::Value::CreateBooleanValue(false)); | 486 base::Value::CreateBooleanValue(false)); |
(...skipping 23 matching lines...) Expand all Loading... |
504 // autocomplete=off. | 510 // autocomplete=off. |
505 std::vector<PasswordForm*> result; // Empty password store. | 511 std::vector<PasswordForm*> result; // Empty password store. |
506 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 512 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
507 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 513 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
508 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 514 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
509 std::vector<PasswordForm> observed; | 515 std::vector<PasswordForm> observed; |
510 PasswordForm form(MakeSimpleForm()); | 516 PasswordForm form(MakeSimpleForm()); |
511 form.password_autocomplete_set = false; | 517 form.password_autocomplete_set = false; |
512 observed.push_back(form); | 518 observed.push_back(form); |
513 manager()->OnPasswordFormsParsed(observed); // The initial load. | 519 manager()->OnPasswordFormsParsed(observed); // The initial load. |
514 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 520 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
515 | 521 |
516 // And the form submit contract is to call ProvisionallySavePassword. | 522 // And the form submit contract is to call ProvisionallySavePassword. |
517 manager()->ProvisionallySavePassword(form); | 523 manager()->ProvisionallySavePassword(form); |
518 | 524 |
519 // Password form should be saved. | 525 // Password form should be saved. |
520 scoped_ptr<PasswordFormManager> form_to_save; | 526 scoped_ptr<PasswordFormManager> form_to_save; |
521 EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(Exactly(1)).WillOnce( | 527 EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(Exactly(1)).WillOnce( |
522 WithArg<0>(SaveToScopedPtr(&form_to_save))); | 528 WithArg<0>(SaveToScopedPtr(&form_to_save))); |
523 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); | 529 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); |
524 | 530 |
525 // Now the password manager waits for the navigation to complete. | 531 // Now the password manager waits for the navigation to complete. |
526 observed.clear(); | 532 observed.clear(); |
527 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 533 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
528 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 534 manager()->OnPasswordFormsRendered(observed, |
| 535 true); // The post-navigation layout. |
529 | 536 |
530 ASSERT_TRUE(form_to_save.get()); | 537 ASSERT_TRUE(form_to_save.get()); |
531 } | 538 } |
532 | 539 |
533 TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) { | 540 TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) { |
534 // Test password form with generated password will still be saved if | 541 // Test password form with generated password will still be saved if |
535 // autocomplete=off. | 542 // autocomplete=off. |
536 std::vector<PasswordForm*> result; // Empty password store. | 543 std::vector<PasswordForm*> result; // Empty password store. |
537 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 544 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
538 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 545 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
539 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 546 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
540 std::vector<PasswordForm> observed; | 547 std::vector<PasswordForm> observed; |
541 PasswordForm form(MakeSimpleForm()); | 548 PasswordForm form(MakeSimpleForm()); |
542 form.password_autocomplete_set = false; | 549 form.password_autocomplete_set = false; |
543 observed.push_back(form); | 550 observed.push_back(form); |
544 manager()->OnPasswordFormsParsed(observed); // The initial load. | 551 manager()->OnPasswordFormsParsed(observed); // The initial load. |
545 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 552 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
546 | 553 |
547 // Simulate the user generating the password and submitting the form. | 554 // Simulate the user generating the password and submitting the form. |
548 manager()->SetFormHasGeneratedPassword(form); | 555 manager()->SetFormHasGeneratedPassword(form); |
549 manager()->ProvisionallySavePassword(form); | 556 manager()->ProvisionallySavePassword(form); |
550 | 557 |
551 // The user should not be presented with an infobar as they have already given | 558 // The user should not be presented with an infobar as they have already given |
552 // consent by using the generated password. The form should be saved once | 559 // consent by using the generated password. The form should be saved once |
553 // navigation occurs. | 560 // navigation occurs. |
554 EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(Exactly(0)); | 561 EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(Exactly(0)); |
555 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 562 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
556 | 563 |
557 // Now the password manager waits for the navigation to complete. | 564 // Now the password manager waits for the navigation to complete. |
558 observed.clear(); | 565 observed.clear(); |
559 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 566 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
560 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 567 manager()->OnPasswordFormsRendered(observed, |
| 568 true); // The post-navigation layout. |
561 } | 569 } |
562 | 570 |
563 TEST_F(PasswordManagerTest, SubmissionCallbackTest) { | 571 TEST_F(PasswordManagerTest, SubmissionCallbackTest) { |
564 manager()->AddSubmissionCallback(SubmissionCallback()); | 572 manager()->AddSubmissionCallback(SubmissionCallback()); |
565 PasswordForm form = MakeSimpleForm(); | 573 PasswordForm form = MakeSimpleForm(); |
566 OnPasswordFormSubmitted(form); | 574 OnPasswordFormSubmitted(form); |
567 EXPECT_TRUE(FormsAreEqual(form, submitted_form_)); | 575 EXPECT_TRUE(FormsAreEqual(form, submitted_form_)); |
568 } | 576 } |
569 | 577 |
570 TEST_F(PasswordManagerTest, PasswordFormReappearance) { | 578 TEST_F(PasswordManagerTest, PasswordFormReappearance) { |
571 // Test the heuristic to know if a password form reappears. | 579 // Test the heuristic to know if a password form reappears. |
572 // We assume that if we send our credentials and there | 580 // We assume that if we send our credentials and there |
573 // is at least one visible password form in the next page that | 581 // is at least one visible password form in the next page that |
574 // means that our previous login attempt failed. | 582 // means that our previous login attempt failed. |
575 std::vector<PasswordForm*> result; // Empty password store. | 583 std::vector<PasswordForm*> result; // Empty password store. |
576 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(0); | 584 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(0); |
577 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 585 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
578 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 586 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
579 std::vector<PasswordForm> observed; | 587 std::vector<PasswordForm> observed; |
580 PasswordForm login_form(MakeTwitterLoginForm()); | 588 PasswordForm login_form(MakeTwitterLoginForm()); |
581 observed.push_back(login_form); | 589 observed.push_back(login_form); |
582 manager()->OnPasswordFormsParsed(observed); // The initial load. | 590 manager()->OnPasswordFormsParsed(observed); // The initial load. |
583 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 591 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
584 | 592 |
585 manager()->ProvisionallySavePassword(login_form); | 593 manager()->ProvisionallySavePassword(login_form); |
586 | 594 |
587 PasswordForm failed_login_form(MakeTwitterFailedLoginForm()); | 595 PasswordForm failed_login_form(MakeTwitterFailedLoginForm()); |
588 observed.clear(); | 596 observed.clear(); |
589 observed.push_back(failed_login_form); | 597 observed.push_back(failed_login_form); |
590 // A PasswordForm appears, and is visible in the layout: | 598 // A PasswordForm appears, and is visible in the layout: |
591 // No expected calls to the PasswordStore... | 599 // No expected calls to the PasswordStore... |
592 manager()->OnPasswordFormsParsed(observed); | 600 manager()->OnPasswordFormsParsed(observed); |
593 manager()->OnPasswordFormsRendered(observed); | 601 manager()->OnPasswordFormsRendered(observed, true); |
594 } | 602 } |
595 | 603 |
596 } // namespace password_manager | 604 } // namespace password_manager |
OLD | NEW |