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