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

Side by Side Diff: components/password_manager/core/browser/password_manager_unittest.cc

Issue 707173004: Refactor Autofill for out of process iframes (OOPIF). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mem leak Created 6 years 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
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 "components/password_manager/core/browser/password_manager.h" 5 #include "components/password_manager/core/browser/password_manager.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 28 matching lines...) Expand all
39 class MockPasswordManagerClient : public StubPasswordManagerClient { 39 class MockPasswordManagerClient : public StubPasswordManagerClient {
40 public: 40 public:
41 MOCK_CONST_METHOD0(IsPasswordManagerEnabledForCurrentPage, bool()); 41 MOCK_CONST_METHOD0(IsPasswordManagerEnabledForCurrentPage, bool());
42 MOCK_CONST_METHOD2(IsSyncAccountCredential, 42 MOCK_CONST_METHOD2(IsSyncAccountCredential,
43 bool(const std::string&, const std::string&)); 43 bool(const std::string&, const std::string&));
44 MOCK_METHOD1(PromptUserToSavePasswordPtr, void(PasswordFormManager*)); 44 MOCK_METHOD1(PromptUserToSavePasswordPtr, void(PasswordFormManager*));
45 MOCK_METHOD1(AutomaticPasswordSavePtr, void(PasswordFormManager*)); 45 MOCK_METHOD1(AutomaticPasswordSavePtr, void(PasswordFormManager*));
46 MOCK_METHOD0(GetPasswordStore, PasswordStore*()); 46 MOCK_METHOD0(GetPasswordStore, PasswordStore*());
47 MOCK_METHOD0(GetPrefs, PrefService*()); 47 MOCK_METHOD0(GetPrefs, PrefService*());
48 MOCK_METHOD0(GetDriver, PasswordManagerDriver*()); 48 MOCK_METHOD0(GetDriver, PasswordManagerDriver*());
49 MOCK_METHOD0(DidLastPageLoadEncounterSSLErrors, bool());
49 50
50 // Workaround for scoped_ptr<> lacking a copy constructor. 51 // Workaround for scoped_ptr<> lacking a copy constructor.
51 virtual bool PromptUserToSavePassword( 52 virtual bool PromptUserToSavePassword(
52 scoped_ptr<PasswordFormManager> manager) override { 53 scoped_ptr<PasswordFormManager> manager) override {
53 PromptUserToSavePasswordPtr(manager.release()); 54 PromptUserToSavePasswordPtr(manager.release());
54 return false; 55 return false;
55 } 56 }
56 virtual void AutomaticPasswordSave( 57 virtual void AutomaticPasswordSave(
57 scoped_ptr<PasswordFormManager> manager) override { 58 scoped_ptr<PasswordFormManager> manager) override {
58 AutomaticPasswordSavePtr(manager.release()); 59 AutomaticPasswordSavePtr(manager.release());
59 } 60 }
60 }; 61 };
61 62
62 class MockPasswordManagerDriver : public StubPasswordManagerDriver { 63 class MockPasswordManagerDriver : public StubPasswordManagerDriver {
63 public: 64 public:
64 MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&)); 65 MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&));
65 MOCK_METHOD0(GetPasswordManager, PasswordManager*()); 66 MOCK_METHOD0(GetPasswordManager, PasswordManager*());
66 MOCK_METHOD0(GetPasswordAutofillManager, PasswordAutofillManager*()); 67 MOCK_METHOD0(GetPasswordAutofillManager, PasswordAutofillManager*());
67 MOCK_METHOD0(DidLastPageLoadEncounterSSLErrors, bool());
68 }; 68 };
69 69
70 ACTION_P(InvokeConsumer, forms) { arg0->OnGetPasswordStoreResults(forms); } 70 ACTION_P(InvokeConsumer, forms) { arg0->OnGetPasswordStoreResults(forms); }
71 71
72 ACTION_P(SaveToScopedPtr, scoped) { scoped->reset(arg0); } 72 ACTION_P(SaveToScopedPtr, scoped) { scoped->reset(arg0); }
73 73
74 class TestPasswordManager : public PasswordManager { 74 class TestPasswordManager : public PasswordManager {
75 public: 75 public:
76 explicit TestPasswordManager(PasswordManagerClient* client) 76 explicit TestPasswordManager(PasswordManagerClient* client)
77 : PasswordManager(client) {} 77 : PasswordManager(client) {}
(...skipping 19 matching lines...) Expand all
97 .WillRepeatedly(Return(true)); 97 .WillRepeatedly(Return(true));
98 EXPECT_CALL(client_, IsSyncAccountCredential(_, _)) 98 EXPECT_CALL(client_, IsSyncAccountCredential(_, _))
99 .WillRepeatedly(Return(false)); 99 .WillRepeatedly(Return(false));
100 EXPECT_CALL(client_, GetPasswordStore()) 100 EXPECT_CALL(client_, GetPasswordStore())
101 .WillRepeatedly(Return(store_.get())); 101 .WillRepeatedly(Return(store_.get()));
102 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(&prefs_)); 102 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(&prefs_));
103 EXPECT_CALL(client_, GetDriver()).WillRepeatedly(Return(&driver_)); 103 EXPECT_CALL(client_, GetDriver()).WillRepeatedly(Return(&driver_));
104 104
105 manager_.reset(new TestPasswordManager(&client_)); 105 manager_.reset(new TestPasswordManager(&client_));
106 password_autofill_manager_.reset( 106 password_autofill_manager_.reset(
107 new PasswordAutofillManager(&client_, NULL)); 107 new PasswordAutofillManager(&client_, client_.GetDriver(), NULL));
108 108
109 EXPECT_CALL(driver_, GetPasswordManager()) 109 EXPECT_CALL(driver_, GetPasswordManager())
110 .WillRepeatedly(Return(manager_.get())); 110 .WillRepeatedly(Return(manager_.get()));
111 EXPECT_CALL(driver_, GetPasswordAutofillManager()) 111 EXPECT_CALL(driver_, GetPasswordAutofillManager())
112 .WillRepeatedly(Return(password_autofill_manager_.get())); 112 .WillRepeatedly(Return(password_autofill_manager_.get()));
113 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) 113 EXPECT_CALL(client_, DidLastPageLoadEncounterSSLErrors())
114 .WillRepeatedly(Return(false)); 114 .WillRepeatedly(Return(false));
115 } 115 }
116 116
117 void TearDown() override { 117 void TearDown() override {
118 store_->Shutdown(); 118 store_->Shutdown();
119 store_ = NULL; 119 store_ = NULL;
120 } 120 }
121 121
122 PasswordForm MakeSimpleForm() { 122 PasswordForm MakeSimpleForm() {
123 PasswordForm form; 123 PasswordForm form;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 if (lhs.submit_element != rhs.submit_element) 202 if (lhs.submit_element != rhs.submit_element)
203 return false; 203 return false;
204 if (lhs.signon_realm != rhs.signon_realm) 204 if (lhs.signon_realm != rhs.signon_realm)
205 return false; 205 return false;
206 return true; 206 return true;
207 } 207 }
208 208
209 TestPasswordManager* manager() { return manager_.get(); } 209 TestPasswordManager* manager() { return manager_.get(); }
210 210
211 void OnPasswordFormSubmitted(const autofill::PasswordForm& form) { 211 void OnPasswordFormSubmitted(const autofill::PasswordForm& form) {
212 manager()->OnPasswordFormSubmitted(form); 212 manager()->OnPasswordFormSubmitted(&driver_, form);
213 } 213 }
214 214
215 PasswordManager::PasswordSubmittedCallback SubmissionCallback() { 215 PasswordManager::PasswordSubmittedCallback SubmissionCallback() {
216 return base::Bind(&PasswordManagerTest::FormSubmitted, 216 return base::Bind(&PasswordManagerTest::FormSubmitted,
217 base::Unretained(this)); 217 base::Unretained(this));
218 } 218 }
219 219
220 void FormSubmitted(const autofill::PasswordForm& form) { 220 void FormSubmitted(const autofill::PasswordForm& form) {
221 submitted_form_ = form; 221 submitted_form_ = form;
222 } 222 }
(...skipping 19 matching lines...) Expand all
242 242
243 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { 243 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) {
244 // Test that observing a newly submitted form shows the save password bar. 244 // Test that observing a newly submitted form shows the save password bar.
245 std::vector<PasswordForm*> result; // Empty password store. 245 std::vector<PasswordForm*> result; // Empty password store.
246 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); 246 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0));
247 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) 247 EXPECT_CALL(*store_.get(), GetLogins(_, _, _))
248 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); 248 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
249 std::vector<PasswordForm> observed; 249 std::vector<PasswordForm> observed;
250 PasswordForm form(MakeSimpleForm()); 250 PasswordForm form(MakeSimpleForm());
251 observed.push_back(form); 251 observed.push_back(form);
252 manager()->OnPasswordFormsParsed(observed); // The initial load. 252 // The initial load.
253 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. 253 manager()->OnPasswordFormsParsed(&driver_, observed);
254 // The initial layout.
255 manager()->OnPasswordFormsRendered(&driver_, observed, true);
254 256
255 // And the form submit contract is to call ProvisionallySavePassword. 257 // And the form submit contract is to call ProvisionallySavePassword.
256 manager()->ProvisionallySavePassword(form); 258 manager()->ProvisionallySavePassword(form);
257 259
258 scoped_ptr<PasswordFormManager> form_to_save; 260 scoped_ptr<PasswordFormManager> form_to_save;
259 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) 261 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_))
260 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); 262 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save)));
261 263
262 // Now the password manager waits for the navigation to complete. 264 // Now the password manager waits for the navigation to complete.
263 observed.clear(); 265 observed.clear();
264 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 266 // The post-navigation load.
265 manager()->OnPasswordFormsRendered(observed, 267 manager()->OnPasswordFormsParsed(&driver_, observed);
266 true); // The post-navigation layout. 268 // The post-navigation layout.
269 manager()->OnPasswordFormsRendered(&driver_, observed, true);
267 270
268 ASSERT_TRUE(form_to_save.get()); 271 ASSERT_TRUE(form_to_save.get());
269 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); 272 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form)));
270 273
271 // Simulate saving the form, as if the info bar was accepted. 274 // Simulate saving the form, as if the info bar was accepted.
272 form_to_save->Save(); 275 form_to_save->Save();
273 } 276 }
274 277
275 TEST_F(PasswordManagerTest, FormSubmitWithOnlyNewPasswordField) { 278 TEST_F(PasswordManagerTest, FormSubmitWithOnlyNewPasswordField) {
276 // This test is the same as FormSubmitEmptyStore, except that it simulates the 279 // This test is the same as FormSubmitEmptyStore, except that it simulates the
277 // user entering credentials into a sign-up form that only has a new password 280 // user entering credentials into a sign-up form that only has a new password
278 // field. 281 // field.
279 std::vector<PasswordForm*> result; // Empty password store. 282 std::vector<PasswordForm*> result; // Empty password store.
280 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); 283 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0));
281 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) 284 EXPECT_CALL(*store_.get(), GetLogins(_, _, _))
282 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); 285 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
283 std::vector<PasswordForm> observed; 286 std::vector<PasswordForm> observed;
284 PasswordForm form(MakeFormWithOnlyNewPasswordField()); 287 PasswordForm form(MakeFormWithOnlyNewPasswordField());
285 observed.push_back(form); 288 observed.push_back(form);
286 manager()->OnPasswordFormsParsed(observed); 289 manager()->OnPasswordFormsParsed(&driver_, observed);
287 manager()->OnPasswordFormsRendered(observed, true); 290 manager()->OnPasswordFormsRendered(&driver_, observed, true);
288 291
289 // And the form submit contract is to call ProvisionallySavePassword. 292 // And the form submit contract is to call ProvisionallySavePassword.
290 manager()->ProvisionallySavePassword(form); 293 manager()->ProvisionallySavePassword(form);
291 294
292 scoped_ptr<PasswordFormManager> form_to_save; 295 scoped_ptr<PasswordFormManager> form_to_save;
293 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) 296 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_))
294 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); 297 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save)));
295 298
296 // Now the password manager waits for the navigation to complete. 299 // Now the password manager waits for the navigation to complete.
297 observed.clear(); 300 observed.clear();
298 manager()->OnPasswordFormsParsed(observed); 301 manager()->OnPasswordFormsParsed(&driver_, observed);
299 manager()->OnPasswordFormsRendered(observed, true); 302 manager()->OnPasswordFormsRendered(&driver_, observed, true);
300 303
301 ASSERT_TRUE(form_to_save.get()); 304 ASSERT_TRUE(form_to_save.get());
302 305
303 // Simulate saving the form, as if the info bar was accepted. 306 // Simulate saving the form, as if the info bar was accepted.
304 PasswordForm saved_form; 307 PasswordForm saved_form;
305 EXPECT_CALL(*store_.get(), AddLogin(_)) 308 EXPECT_CALL(*store_.get(), AddLogin(_))
306 .WillOnce(testing::SaveArg<0>(&saved_form)); 309 .WillOnce(testing::SaveArg<0>(&saved_form));
307 form_to_save->Save(); 310 form_to_save->Save();
308 311
309 // The value of the new password field should have been promoted to, and saved 312 // The value of the new password field should have been promoted to, and saved
(...skipping 10 matching lines...) Expand all
320 TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { 323 TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) {
321 // This test is the same as FormSubmitEmptyStore, except that it simulates the 324 // This test is the same as FormSubmitEmptyStore, except that it simulates the
322 // user generating the password through the browser. 325 // user generating the password through the browser.
323 std::vector<PasswordForm*> result; // Empty password store. 326 std::vector<PasswordForm*> result; // Empty password store.
324 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); 327 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0));
325 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) 328 EXPECT_CALL(*store_.get(), GetLogins(_, _, _))
326 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); 329 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
327 std::vector<PasswordForm> observed; 330 std::vector<PasswordForm> observed;
328 PasswordForm form(MakeSimpleForm()); 331 PasswordForm form(MakeSimpleForm());
329 observed.push_back(form); 332 observed.push_back(form);
330 manager()->OnPasswordFormsParsed(observed); // The initial load. 333 // The initial load.
331 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. 334 manager()->OnPasswordFormsParsed(&driver_, observed);
335 // The initial layout.
336 manager()->OnPasswordFormsRendered(&driver_, observed, true);
332 337
333 // Simulate the user generating the password and submitting the form. 338 // Simulate the user generating the password and submitting the form.
334 manager()->SetFormHasGeneratedPassword(form); 339 manager()->SetFormHasGeneratedPassword(&driver_, form);
335 manager()->ProvisionallySavePassword(form); 340 manager()->ProvisionallySavePassword(form);
336 341
337 // The user should not be presented with an infobar as they have already given 342 // The user should not be presented with an infobar as they have already given
338 // consent by using the generated password. The form should be saved once 343 // consent by using the generated password. The form should be saved once
339 // navigation occurs. The client will be informed that automatic saving has 344 // navigation occurs. The client will be informed that automatic saving has
340 // occured. 345 // occured.
341 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0)); 346 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0));
342 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); 347 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form)));
343 scoped_ptr<PasswordFormManager> saved_form_manager; 348 scoped_ptr<PasswordFormManager> saved_form_manager;
344 EXPECT_CALL(client_, AutomaticPasswordSavePtr(_)).Times(Exactly(1)) 349 EXPECT_CALL(client_, AutomaticPasswordSavePtr(_)).Times(Exactly(1))
345 .WillOnce(WithArg<0>(SaveToScopedPtr(&saved_form_manager))); 350 .WillOnce(WithArg<0>(SaveToScopedPtr(&saved_form_manager)));
346 351
347 // Now the password manager waits for the navigation to complete. 352 // Now the password manager waits for the navigation to complete.
348 observed.clear(); 353 observed.clear();
349 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 354 manager()->OnPasswordFormsParsed(&driver_,
350 manager()->OnPasswordFormsRendered(observed, 355 observed); // The post-navigation load.
356 manager()->OnPasswordFormsRendered(&driver_, observed,
351 true); // The post-navigation layout. 357 true); // The post-navigation layout.
352 } 358 }
353 359
354 TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { 360 TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) {
355 // Same as above, except with an existing form for the same signon realm, 361 // Same as above, except with an existing form for the same signon realm,
356 // but different origin. Detailed cases like this are covered by 362 // but different origin. Detailed cases like this are covered by
357 // PasswordFormManagerTest. 363 // PasswordFormManagerTest.
358 std::vector<PasswordForm*> result; 364 std::vector<PasswordForm*> result;
359 PasswordForm* existing_different = new PasswordForm(MakeSimpleForm()); 365 PasswordForm* existing_different = new PasswordForm(MakeSimpleForm());
360 existing_different->username_value = ASCIIToUTF16("google2"); 366 existing_different->username_value = ASCIIToUTF16("google2");
361 result.push_back(existing_different); 367 result.push_back(existing_different);
362 EXPECT_CALL(driver_, FillPasswordForm(_)); 368 EXPECT_CALL(driver_, FillPasswordForm(_));
363 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) 369 EXPECT_CALL(*store_.get(), GetLogins(_, _, _))
364 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); 370 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
365 371
366 std::vector<PasswordForm> observed; 372 std::vector<PasswordForm> observed;
367 PasswordForm form(MakeSimpleForm()); 373 PasswordForm form(MakeSimpleForm());
368 observed.push_back(form); 374 observed.push_back(form);
369 manager()->OnPasswordFormsParsed(observed); // The initial load. 375 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load.
370 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. 376 manager()->OnPasswordFormsRendered(&driver_, observed,
377 true); // The initial layout.
371 manager()->ProvisionallySavePassword(form); 378 manager()->ProvisionallySavePassword(form);
372 379
373 // We still expect an add, since we didn't have a good match. 380 // We still expect an add, since we didn't have a good match.
374 scoped_ptr<PasswordFormManager> form_to_save; 381 scoped_ptr<PasswordFormManager> form_to_save;
375 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) 382 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_))
376 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); 383 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save)));
377 384
378 // Now the password manager waits for the navigation to complete. 385 // Now the password manager waits for the navigation to complete.
379 observed.clear(); 386 observed.clear();
380 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 387 manager()->OnPasswordFormsParsed(&driver_,
381 manager()->OnPasswordFormsRendered(observed, 388 observed); // The post-navigation load.
389 manager()->OnPasswordFormsRendered(&driver_, observed,
382 true); // The post-navigation layout. 390 true); // The post-navigation layout.
383 391
384 ASSERT_TRUE(form_to_save.get()); 392 ASSERT_TRUE(form_to_save.get());
385 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); 393 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form)));
386 394
387 // Simulate saving the form. 395 // Simulate saving the form.
388 form_to_save->Save(); 396 form_to_save->Save();
389 } 397 }
390 398
391 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { 399 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) {
392 std::vector<PasswordForm*> result; // Empty password store. 400 std::vector<PasswordForm*> result; // Empty password store.
393 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); 401 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0));
394 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) 402 EXPECT_CALL(*store_.get(), GetLogins(_, _, _))
395 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); 403 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
396 std::vector<PasswordForm> observed; 404 std::vector<PasswordForm> observed;
397 PasswordForm form(MakeSimpleForm()); 405 PasswordForm form(MakeSimpleForm());
398 observed.push_back(form); 406 observed.push_back(form);
399 manager()->OnPasswordFormsParsed(observed); // The initial load. 407 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load.
400 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. 408 manager()->OnPasswordFormsRendered(&driver_, observed,
409 true); // The initial layout.
401 410
402 // No message from the renderer that a password was submitted. No 411 // No message from the renderer that a password was submitted. No
403 // expected calls. 412 // expected calls.
404 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(0); 413 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(0);
405 observed.clear(); 414 observed.clear();
406 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 415 manager()->OnPasswordFormsParsed(&driver_,
407 manager()->OnPasswordFormsRendered(observed, 416 observed); // The post-navigation load.
417 manager()->OnPasswordFormsRendered(&driver_, observed,
408 true); // The post-navigation layout. 418 true); // The post-navigation layout.
409 } 419 }
410 420
411 TEST_F(PasswordManagerTest, FormSubmitAfterNavigateInPage) { 421 TEST_F(PasswordManagerTest, FormSubmitAfterNavigateInPage) {
412 // Test that navigating in the page does not prevent us from showing the save 422 // Test that navigating in the page does not prevent us from showing the save
413 // password infobar. 423 // password infobar.
414 std::vector<PasswordForm*> result; // Empty password store. 424 std::vector<PasswordForm*> result; // Empty password store.
415 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); 425 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0));
416 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) 426 EXPECT_CALL(*store_.get(), GetLogins(_, _, _))
417 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); 427 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
418 std::vector<PasswordForm> observed; 428 std::vector<PasswordForm> observed;
419 PasswordForm form(MakeSimpleForm()); 429 PasswordForm form(MakeSimpleForm());
420 observed.push_back(form); 430 observed.push_back(form);
421 manager()->OnPasswordFormsParsed(observed); // The initial load. 431 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load.
422 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. 432 manager()->OnPasswordFormsRendered(&driver_, observed,
433 true); // The initial layout.
423 434
424 // Simulate navigating in the page. 435 // Simulate navigating in the page.
425 manager()->DidNavigateMainFrame(true); 436 manager()->DidNavigateMainFrame(true);
426 437
427 // Simulate submitting the password. 438 // Simulate submitting the password.
428 OnPasswordFormSubmitted(form); 439 OnPasswordFormSubmitted(form);
429 440
430 // Now the password manager waits for the navigation to complete. 441 // Now the password manager waits for the navigation to complete.
431 scoped_ptr<PasswordFormManager> form_to_save; 442 scoped_ptr<PasswordFormManager> form_to_save;
432 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) 443 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_))
433 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); 444 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save)));
434 445
435 observed.clear(); 446 observed.clear();
436 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 447 manager()->OnPasswordFormsParsed(&driver_,
437 manager()->OnPasswordFormsRendered(observed, 448 observed); // The post-navigation load.
449 manager()->OnPasswordFormsRendered(&driver_, observed,
438 true); // The post-navigation layout. 450 true); // The post-navigation layout.
439 451
440 ASSERT_FALSE(NULL == form_to_save.get()); 452 ASSERT_FALSE(NULL == form_to_save.get());
441 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); 453 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form)));
442 454
443 // Simulate saving the form, as if the info bar was accepted. 455 // Simulate saving the form, as if the info bar was accepted.
444 form_to_save->Save(); 456 form_to_save->Save();
445 } 457 }
446 458
447 // This test verifies a fix for http://crbug.com/236673 459 // This test verifies a fix for http://crbug.com/236673
448 TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { 460 TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) {
449 std::vector<PasswordForm*> result; // Empty password store. 461 std::vector<PasswordForm*> result; // Empty password store.
450 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); 462 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0));
451 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) 463 EXPECT_CALL(*store_.get(), GetLogins(_, _, _))
452 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); 464 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
453 PasswordForm first_form(MakeSimpleForm()); 465 PasswordForm first_form(MakeSimpleForm());
454 first_form.origin = GURL("http://www.nytimes.com/"); 466 first_form.origin = GURL("http://www.nytimes.com/");
455 first_form.action = GURL("https://myaccount.nytimes.com/auth/login"); 467 first_form.action = GURL("https://myaccount.nytimes.com/auth/login");
456 first_form.signon_realm = "http://www.nytimes.com/"; 468 first_form.signon_realm = "http://www.nytimes.com/";
457 PasswordForm second_form(MakeSimpleForm()); 469 PasswordForm second_form(MakeSimpleForm());
458 second_form.origin = GURL("https://myaccount.nytimes.com/auth/login"); 470 second_form.origin = GURL("https://myaccount.nytimes.com/auth/login");
459 second_form.action = GURL("https://myaccount.nytimes.com/auth/login"); 471 second_form.action = GURL("https://myaccount.nytimes.com/auth/login");
460 second_form.signon_realm = "https://myaccount.nytimes.com/"; 472 second_form.signon_realm = "https://myaccount.nytimes.com/";
461 473
462 // Pretend that the form is hidden on the first page. 474 // Pretend that the form is hidden on the first page.
463 std::vector<PasswordForm> observed; 475 std::vector<PasswordForm> observed;
464 observed.push_back(first_form); 476 observed.push_back(first_form);
465 manager()->OnPasswordFormsParsed(observed); 477 manager()->OnPasswordFormsParsed(&driver_, observed);
466 observed.clear(); 478 observed.clear();
467 manager()->OnPasswordFormsRendered(observed, true); 479 manager()->OnPasswordFormsRendered(&driver_, observed, true);
468 480
469 // Now navigate to a second page. 481 // Now navigate to a second page.
470 manager()->DidNavigateMainFrame(false); 482 manager()->DidNavigateMainFrame(false);
471 483
472 // This page contains a form with the same markup, but on a different 484 // This page contains a form with the same markup, but on a different
473 // URL. 485 // URL.
474 observed.push_back(second_form); 486 observed.push_back(second_form);
475 manager()->OnPasswordFormsParsed(observed); 487 manager()->OnPasswordFormsParsed(&driver_, observed);
476 manager()->OnPasswordFormsRendered(observed, true); 488 manager()->OnPasswordFormsRendered(&driver_, observed, true);
477 489
478 // Now submit this form 490 // Now submit this form
479 OnPasswordFormSubmitted(second_form); 491 OnPasswordFormSubmitted(second_form);
480 492
481 // Navigation after form submit. 493 // Navigation after form submit.
482 scoped_ptr<PasswordFormManager> form_to_save; 494 scoped_ptr<PasswordFormManager> form_to_save;
483 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) 495 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_))
484 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); 496 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save)));
485 observed.clear(); 497 observed.clear();
486 manager()->OnPasswordFormsParsed(observed); 498 manager()->OnPasswordFormsParsed(&driver_, observed);
487 manager()->OnPasswordFormsRendered(observed, true); 499 manager()->OnPasswordFormsRendered(&driver_, observed, true);
488 500
489 // Make sure that the saved form matches the second form, not the first. 501 // Make sure that the saved form matches the second form, not the first.
490 ASSERT_TRUE(form_to_save.get()); 502 ASSERT_TRUE(form_to_save.get());
491 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(second_form))); 503 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(second_form)));
492 504
493 // Simulate saving the form, as if the info bar was accepted. 505 // Simulate saving the form, as if the info bar was accepted.
494 form_to_save->Save(); 506 form_to_save->Save();
495 } 507 }
496 508
497 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { 509 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) {
498 std::vector<PasswordForm*> result; // Empty password store. 510 std::vector<PasswordForm*> result; // Empty password store.
499 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); 511 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0));
500 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) 512 EXPECT_CALL(*store_.get(), GetLogins(_, _, _))
501 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); 513 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
502 std::vector<PasswordForm> observed; 514 std::vector<PasswordForm> observed;
503 PasswordForm form(MakeSimpleForm()); 515 PasswordForm form(MakeSimpleForm());
504 observed.push_back(form); 516 observed.push_back(form);
505 manager()->OnPasswordFormsParsed(observed); // The initial load. 517 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load.
506 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. 518 manager()->OnPasswordFormsRendered(&driver_, observed,
519 true); // The initial layout.
507 520
508 manager()->ProvisionallySavePassword(form); 521 manager()->ProvisionallySavePassword(form);
509 522
510 // The form reappears, and is visible in the layout: 523 // The form reappears, and is visible in the layout:
511 // No expected calls to the PasswordStore... 524 // No expected calls to the PasswordStore...
512 manager()->OnPasswordFormsParsed(observed); 525 manager()->OnPasswordFormsParsed(&driver_, observed);
513 manager()->OnPasswordFormsRendered(observed, true); 526 manager()->OnPasswordFormsRendered(&driver_, observed, true);
514 } 527 }
515 528
516 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { 529 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) {
517 // Tests fix of issue 28911: if the login form reappears on the subsequent 530 // Tests fix of issue 28911: if the login form reappears on the subsequent
518 // page, but is invisible, it shouldn't count as a failed login. 531 // page, but is invisible, it shouldn't count as a failed login.
519 std::vector<PasswordForm*> result; // Empty password store. 532 std::vector<PasswordForm*> result; // Empty password store.
520 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); 533 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0));
521 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) 534 EXPECT_CALL(*store_.get(), GetLogins(_, _, _))
522 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); 535 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
523 std::vector<PasswordForm> observed; 536 std::vector<PasswordForm> observed;
524 PasswordForm form(MakeSimpleForm()); 537 PasswordForm form(MakeSimpleForm());
525 observed.push_back(form); 538 observed.push_back(form);
526 manager()->OnPasswordFormsParsed(observed); // The initial load. 539 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load.
527 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. 540 manager()->OnPasswordFormsRendered(&driver_, observed,
541 true); // The initial layout.
528 542
529 manager()->ProvisionallySavePassword(form); 543 manager()->ProvisionallySavePassword(form);
530 544
531 // Expect info bar to appear: 545 // Expect info bar to appear:
532 scoped_ptr<PasswordFormManager> form_to_save; 546 scoped_ptr<PasswordFormManager> form_to_save;
533 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) 547 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_))
534 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); 548 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save)));
535 549
536 // The form reappears, but is not visible in the layout: 550 // The form reappears, but is not visible in the layout:
537 manager()->OnPasswordFormsParsed(observed); 551 manager()->OnPasswordFormsParsed(&driver_, observed);
538 observed.clear(); 552 observed.clear();
539 manager()->OnPasswordFormsRendered(observed, true); 553 manager()->OnPasswordFormsRendered(&driver_, observed, true);
540 554
541 ASSERT_TRUE(form_to_save.get()); 555 ASSERT_TRUE(form_to_save.get());
542 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); 556 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form)));
543 557
544 // Simulate saving the form. 558 // Simulate saving the form.
545 form_to_save->Save(); 559 form_to_save->Save();
546 } 560 }
547 561
548 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { 562 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) {
549 // Make sure an invisible login form still gets autofilled. 563 // Make sure an invisible login form still gets autofilled.
550 std::vector<PasswordForm*> result; 564 std::vector<PasswordForm*> result;
551 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); 565 PasswordForm* existing = new PasswordForm(MakeSimpleForm());
552 result.push_back(existing); 566 result.push_back(existing);
553 EXPECT_CALL(driver_, FillPasswordForm(_)); 567 EXPECT_CALL(driver_, FillPasswordForm(_));
554 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) 568 EXPECT_CALL(*store_.get(), GetLogins(_, _, _))
555 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); 569 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
556 std::vector<PasswordForm> observed; 570 std::vector<PasswordForm> observed;
557 PasswordForm form(MakeSimpleForm()); 571 PasswordForm form(MakeSimpleForm());
558 observed.push_back(form); 572 observed.push_back(form);
559 manager()->OnPasswordFormsParsed(observed); // The initial load. 573 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load.
560 observed.clear(); 574 observed.clear();
561 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. 575 manager()->OnPasswordFormsRendered(&driver_, observed,
576 true); // The initial layout.
562 577
563 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 578 manager()->OnPasswordFormsParsed(&driver_,
564 manager()->OnPasswordFormsRendered(observed, 579 observed); // The post-navigation load.
580 manager()->OnPasswordFormsRendered(&driver_, observed,
565 true); // The post-navigation layout. 581 true); // The post-navigation layout.
566 } 582 }
567 583
568 TEST_F(PasswordManagerTest, SavingDependsOnManagerEnabledPreference) { 584 TEST_F(PasswordManagerTest, SavingDependsOnManagerEnabledPreference) {
569 // Test that saving passwords depends on the password manager enabled 585 // Test that saving passwords depends on the password manager enabled
570 // preference. 586 // preference.
571 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled, 587 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled,
572 new base::FundamentalValue(true)); 588 new base::FundamentalValue(true));
573 EXPECT_TRUE(manager()->IsSavingEnabledForCurrentPage()); 589 EXPECT_TRUE(manager()->IsSavingEnabledForCurrentPage());
574 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled, 590 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled,
575 new base::FundamentalValue(false)); 591 new base::FundamentalValue(false));
576 EXPECT_FALSE(manager()->IsSavingEnabledForCurrentPage()); 592 EXPECT_FALSE(manager()->IsSavingEnabledForCurrentPage());
577 } 593 }
578 594
579 TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) { 595 TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) {
580 // Test fix for issue 158296: Passwords must be filled even if the password 596 // Test fix for issue 158296: Passwords must be filled even if the password
581 // manager is disabled. 597 // manager is disabled.
582 std::vector<PasswordForm*> result; 598 std::vector<PasswordForm*> result;
583 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); 599 PasswordForm* existing = new PasswordForm(MakeSimpleForm());
584 result.push_back(existing); 600 result.push_back(existing);
585 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled, 601 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled,
586 new base::FundamentalValue(false)); 602 new base::FundamentalValue(false));
587 EXPECT_CALL(driver_, FillPasswordForm(_)); 603 EXPECT_CALL(driver_, FillPasswordForm(_));
588 EXPECT_CALL(*store_.get(), 604 EXPECT_CALL(*store_.get(),
589 GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _)) 605 GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _))
590 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); 606 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
591 std::vector<PasswordForm> observed; 607 std::vector<PasswordForm> observed;
592 PasswordForm form(MakeSimpleForm()); 608 PasswordForm form(MakeSimpleForm());
593 observed.push_back(form); 609 observed.push_back(form);
594 manager()->OnPasswordFormsParsed(observed); 610 manager()->OnPasswordFormsParsed(&driver_, observed);
595 } 611 }
596 612
597 TEST_F(PasswordManagerTest, FormSavedWithAutocompleteOff) { 613 TEST_F(PasswordManagerTest, FormSavedWithAutocompleteOff) {
598 // Test password form with non-generated password will be saved even if 614 // Test password form with non-generated password will be saved even if
599 // autocomplete=off. 615 // autocomplete=off.
600 std::vector<PasswordForm*> result; // Empty password store. 616 std::vector<PasswordForm*> result; // Empty password store.
601 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); 617 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0));
602 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) 618 EXPECT_CALL(*store_.get(), GetLogins(_, _, _))
603 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); 619 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
604 std::vector<PasswordForm> observed; 620 std::vector<PasswordForm> observed;
605 PasswordForm form(MakeSimpleForm()); 621 PasswordForm form(MakeSimpleForm());
606 form.password_autocomplete_set = false; 622 form.password_autocomplete_set = false;
607 observed.push_back(form); 623 observed.push_back(form);
608 manager()->OnPasswordFormsParsed(observed); // The initial load. 624 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load.
609 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. 625 manager()->OnPasswordFormsRendered(&driver_, observed,
626 true); // The initial layout.
610 627
611 // And the form submit contract is to call ProvisionallySavePassword. 628 // And the form submit contract is to call ProvisionallySavePassword.
612 manager()->ProvisionallySavePassword(form); 629 manager()->ProvisionallySavePassword(form);
613 630
614 // Password form should be saved. 631 // Password form should be saved.
615 scoped_ptr<PasswordFormManager> form_to_save; 632 scoped_ptr<PasswordFormManager> form_to_save;
616 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(1)) 633 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(1))
617 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); 634 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save)));
618 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); 635 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0));
619 636
620 // Now the password manager waits for the navigation to complete. 637 // Now the password manager waits for the navigation to complete.
621 observed.clear(); 638 observed.clear();
622 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 639 manager()->OnPasswordFormsParsed(&driver_,
623 manager()->OnPasswordFormsRendered(observed, 640 observed); // The post-navigation load.
641 manager()->OnPasswordFormsRendered(&driver_, observed,
624 true); // The post-navigation layout. 642 true); // The post-navigation layout.
625 643
626 ASSERT_TRUE(form_to_save.get()); 644 ASSERT_TRUE(form_to_save.get());
627 } 645 }
628 646
629 TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) { 647 TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) {
630 // Test password form with generated password will still be saved if 648 // Test password form with generated password will still be saved if
631 // autocomplete=off. 649 // autocomplete=off.
632 std::vector<PasswordForm*> result; // Empty password store. 650 std::vector<PasswordForm*> result; // Empty password store.
633 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); 651 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0));
634 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) 652 EXPECT_CALL(*store_.get(), GetLogins(_, _, _))
635 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); 653 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
636 std::vector<PasswordForm> observed; 654 std::vector<PasswordForm> observed;
637 PasswordForm form(MakeSimpleForm()); 655 PasswordForm form(MakeSimpleForm());
638 form.password_autocomplete_set = false; 656 form.password_autocomplete_set = false;
639 observed.push_back(form); 657 observed.push_back(form);
640 manager()->OnPasswordFormsParsed(observed); // The initial load. 658 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load.
641 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. 659 manager()->OnPasswordFormsRendered(&driver_, observed,
660 true); // The initial layout.
642 661
643 // Simulate the user generating the password and submitting the form. 662 // Simulate the user generating the password and submitting the form.
644 manager()->SetFormHasGeneratedPassword(form); 663 manager()->SetFormHasGeneratedPassword(&driver_, form);
645 manager()->ProvisionallySavePassword(form); 664 manager()->ProvisionallySavePassword(form);
646 665
647 // The user should not be presented with an infobar as they have already given 666 // The user should not be presented with an infobar as they have already given
648 // consent by using the generated password. The form should be saved once 667 // consent by using the generated password. The form should be saved once
649 // navigation occurs. The client will be informed that automatic saving has 668 // navigation occurs. The client will be informed that automatic saving has
650 // occured. 669 // occured.
651 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0)); 670 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0));
652 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); 671 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form)));
653 scoped_ptr<PasswordFormManager> saved_form_manager; 672 scoped_ptr<PasswordFormManager> saved_form_manager;
654 EXPECT_CALL(client_, AutomaticPasswordSavePtr(_)).Times(Exactly(1)) 673 EXPECT_CALL(client_, AutomaticPasswordSavePtr(_)).Times(Exactly(1))
655 .WillOnce(WithArg<0>(SaveToScopedPtr(&saved_form_manager))); 674 .WillOnce(WithArg<0>(SaveToScopedPtr(&saved_form_manager)));
656 675
657 // Now the password manager waits for the navigation to complete. 676 // Now the password manager waits for the navigation to complete.
658 observed.clear(); 677 observed.clear();
659 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 678 manager()->OnPasswordFormsParsed(&driver_,
660 manager()->OnPasswordFormsRendered(observed, 679 observed); // The post-navigation load.
680 manager()->OnPasswordFormsRendered(&driver_, observed,
661 true); // The post-navigation layout. 681 true); // The post-navigation layout.
662 } 682 }
663 683
664 TEST_F(PasswordManagerTest, SubmissionCallbackTest) { 684 TEST_F(PasswordManagerTest, SubmissionCallbackTest) {
665 manager()->AddSubmissionCallback(SubmissionCallback()); 685 manager()->AddSubmissionCallback(SubmissionCallback());
666 PasswordForm form = MakeSimpleForm(); 686 PasswordForm form = MakeSimpleForm();
667 OnPasswordFormSubmitted(form); 687 OnPasswordFormSubmitted(form);
668 EXPECT_TRUE(FormsAreEqual(form, submitted_form_)); 688 EXPECT_TRUE(FormsAreEqual(form, submitted_form_));
669 } 689 }
670 690
671 TEST_F(PasswordManagerTest, PasswordFormReappearance) { 691 TEST_F(PasswordManagerTest, PasswordFormReappearance) {
672 // Test the heuristic to know if a password form reappears. 692 // Test the heuristic to know if a password form reappears.
673 // We assume that if we send our credentials and there 693 // We assume that if we send our credentials and there
674 // is at least one visible password form in the next page that 694 // is at least one visible password form in the next page that
675 // means that our previous login attempt failed. 695 // means that our previous login attempt failed.
676 std::vector<PasswordForm*> result; // Empty password store. 696 std::vector<PasswordForm*> result; // Empty password store.
677 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(0); 697 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(0);
678 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) 698 EXPECT_CALL(*store_.get(), GetLogins(_, _, _))
679 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); 699 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
680 std::vector<PasswordForm> observed; 700 std::vector<PasswordForm> observed;
681 PasswordForm login_form(MakeTwitterLoginForm()); 701 PasswordForm login_form(MakeTwitterLoginForm());
682 observed.push_back(login_form); 702 observed.push_back(login_form);
683 manager()->OnPasswordFormsParsed(observed); // The initial load. 703 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load.
684 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. 704 manager()->OnPasswordFormsRendered(&driver_, observed,
705 true); // The initial layout.
685 706
686 manager()->ProvisionallySavePassword(login_form); 707 manager()->ProvisionallySavePassword(login_form);
687 708
688 PasswordForm failed_login_form(MakeTwitterFailedLoginForm()); 709 PasswordForm failed_login_form(MakeTwitterFailedLoginForm());
689 observed.clear(); 710 observed.clear();
690 observed.push_back(failed_login_form); 711 observed.push_back(failed_login_form);
691 // A PasswordForm appears, and is visible in the layout: 712 // A PasswordForm appears, and is visible in the layout:
692 // No expected calls to the PasswordStore... 713 // No expected calls to the PasswordStore...
693 manager()->OnPasswordFormsParsed(observed); 714 manager()->OnPasswordFormsParsed(&driver_, observed);
694 manager()->OnPasswordFormsRendered(observed, true); 715 manager()->OnPasswordFormsRendered(&driver_, observed, true);
695 } 716 }
696 717
697 TEST_F(PasswordManagerTest, SavingNotEnabledOnSSLErrors) { 718 TEST_F(PasswordManagerTest, SavingNotEnabledOnSSLErrors) {
698 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) 719 EXPECT_CALL(client_, DidLastPageLoadEncounterSSLErrors())
699 .WillRepeatedly(Return(true)); 720 .WillRepeatedly(Return(true));
700 EXPECT_FALSE(manager()->IsSavingEnabledForCurrentPage()); 721 EXPECT_FALSE(manager()->IsSavingEnabledForCurrentPage());
701 } 722 }
702 723
703 TEST_F(PasswordManagerTest, AutofillingNotEnabledOnSSLErrors) { 724 TEST_F(PasswordManagerTest, AutofillingNotEnabledOnSSLErrors) {
704 // Test that in the presence of SSL errors, the password manager does not 725 // Test that in the presence of SSL errors, the password manager does not
705 // attempt to autofill forms found on a website. 726 // attempt to autofill forms found on a website.
706 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) 727 EXPECT_CALL(client_, DidLastPageLoadEncounterSSLErrors())
707 .WillRepeatedly(Return(true)); 728 .WillRepeatedly(Return(true));
708 729
709 // Let us pretend some forms were found on a website. 730 // Let us pretend some forms were found on a website.
710 std::vector<PasswordForm> forms; 731 std::vector<PasswordForm> forms;
711 forms.push_back(MakeSimpleForm()); 732 forms.push_back(MakeSimpleForm());
712 733
713 // Feed those forms to |manager()| and check that it does not try to find 734 // Feed those forms to |manager()| and check that it does not try to find
714 // matching saved credentials for the forms. 735 // matching saved credentials for the forms.
715 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)).Times(Exactly(0)); 736 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)).Times(Exactly(0));
716 manager()->OnPasswordFormsParsed(forms); 737 manager()->OnPasswordFormsParsed(&driver_, forms);
717 } 738 }
718 739
719 TEST_F(PasswordManagerTest, SavingDisabledIfManagerDisabled) { 740 TEST_F(PasswordManagerTest, SavingDisabledIfManagerDisabled) {
720 EXPECT_CALL(client_, IsPasswordManagerEnabledForCurrentPage()) 741 EXPECT_CALL(client_, IsPasswordManagerEnabledForCurrentPage())
721 .WillRepeatedly(Return(false)); 742 .WillRepeatedly(Return(false));
722 EXPECT_FALSE(manager()->IsSavingEnabledForCurrentPage()); 743 EXPECT_FALSE(manager()->IsSavingEnabledForCurrentPage());
723 } 744 }
724 745
725 TEST_F(PasswordManagerTest, AutofillingDisabledIfManagerDisabled) { 746 TEST_F(PasswordManagerTest, AutofillingDisabledIfManagerDisabled) {
726 EXPECT_CALL(client_, IsPasswordManagerEnabledForCurrentPage()) 747 EXPECT_CALL(client_, IsPasswordManagerEnabledForCurrentPage())
727 .WillRepeatedly(Return(false)); 748 .WillRepeatedly(Return(false));
728 749
729 // Let us pretend some forms were found on a website. 750 // Let us pretend some forms were found on a website.
730 std::vector<PasswordForm> forms; 751 std::vector<PasswordForm> forms;
731 forms.push_back(MakeSimpleForm()); 752 forms.push_back(MakeSimpleForm());
732 753
733 // Feed those forms to |manager()| and check that it does not try to find 754 // Feed those forms to |manager()| and check that it does not try to find
734 // matching saved credentials for the forms. 755 // matching saved credentials for the forms.
735 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)).Times(Exactly(0)); 756 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)).Times(Exactly(0));
736 manager()->OnPasswordFormsParsed(forms); 757 manager()->OnPasswordFormsParsed(&driver_, forms);
737 } 758 }
738 759
739 TEST_F(PasswordManagerTest, SyncCredentialsNotSaved) { 760 TEST_F(PasswordManagerTest, SyncCredentialsNotSaved) {
740 EXPECT_CALL(client_, IsSyncAccountCredential(_, _)) 761 EXPECT_CALL(client_, IsSyncAccountCredential(_, _))
741 .WillRepeatedly(Return(true)); 762 .WillRepeatedly(Return(true));
742 763
743 // Simulate loading a simple form with no existing stored password. 764 // Simulate loading a simple form with no existing stored password.
744 std::vector<PasswordForm*> result; // Empty password store. 765 std::vector<PasswordForm*> result; // Empty password store.
745 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); 766 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0));
746 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) 767 EXPECT_CALL(*store_.get(), GetLogins(_, _, _))
747 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); 768 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
748 std::vector<PasswordForm> observed; 769 std::vector<PasswordForm> observed;
749 PasswordForm form(MakeSimpleForm()); 770 PasswordForm form(MakeSimpleForm());
750 form.password_autocomplete_set = false; 771 form.password_autocomplete_set = false;
751 observed.push_back(form); 772 observed.push_back(form);
752 manager()->OnPasswordFormsParsed(observed); // The initial load. 773 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load.
753 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. 774 manager()->OnPasswordFormsRendered(&driver_, observed,
775 true); // The initial layout.
754 776
755 // User should not be prompted and password should not be saved. 777 // User should not be prompted and password should not be saved.
756 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0)); 778 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0));
757 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); 779 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0));
758 780
759 // Submit form and finish navigation. 781 // Submit form and finish navigation.
760 manager()->ProvisionallySavePassword(form); 782 manager()->ProvisionallySavePassword(form);
761 observed.clear(); 783 observed.clear();
762 manager()->OnPasswordFormsParsed(observed); 784 manager()->OnPasswordFormsParsed(&driver_, observed);
763 manager()->OnPasswordFormsRendered(observed, true); 785 manager()->OnPasswordFormsRendered(&driver_, observed, true);
764 } 786 }
765 787
766 // On failed login attempts, the retry-form can have action scheme changed from 788 // On failed login attempts, the retry-form can have action scheme changed from
767 // HTTP to HTTPS (see http://crbug.com/400769). Check that such retry-form is 789 // HTTP to HTTPS (see http://crbug.com/400769). Check that such retry-form is
768 // considered equal to the original login form, and the attempt recognised as a 790 // considered equal to the original login form, and the attempt recognised as a
769 // failure. 791 // failure.
770 TEST_F(PasswordManagerTest, 792 TEST_F(PasswordManagerTest,
771 SeeingFormActionWithOnlyHttpHttpsChangeIsLoginFailure) { 793 SeeingFormActionWithOnlyHttpHttpsChangeIsLoginFailure) {
772 std::vector<PasswordForm*> result; // Empty password store. 794 std::vector<PasswordForm*> result; // Empty password store.
773 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); 795 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0));
774 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) 796 EXPECT_CALL(*store_.get(), GetLogins(_, _, _))
775 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); 797 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
776 798
777 PasswordForm first_form(MakeSimpleForm()); 799 PasswordForm first_form(MakeSimpleForm());
778 first_form.origin = GURL("http://www.xda-developers.com/"); 800 first_form.origin = GURL("http://www.xda-developers.com/");
779 first_form.action = GURL("http://forum.xda-developers.com/login.php"); 801 first_form.action = GURL("http://forum.xda-developers.com/login.php");
780 802
781 // |second_form|'s action differs only with it's scheme i.e. *https://*. 803 // |second_form|'s action differs only with it's scheme i.e. *https://*.
782 PasswordForm second_form(first_form); 804 PasswordForm second_form(first_form);
783 second_form.action = GURL("https://forum.xda-developers.com/login.php"); 805 second_form.action = GURL("https://forum.xda-developers.com/login.php");
784 806
785 std::vector<PasswordForm> observed; 807 std::vector<PasswordForm> observed;
786 observed.push_back(first_form); 808 observed.push_back(first_form);
787 manager()->OnPasswordFormsParsed(observed); 809 manager()->OnPasswordFormsParsed(&driver_, observed);
788 manager()->OnPasswordFormsRendered(observed, true); 810 manager()->OnPasswordFormsRendered(&driver_, observed, true);
789 observed.clear(); 811 observed.clear();
790 812
791 // Now submit the |first_form|. 813 // Now submit the |first_form|.
792 OnPasswordFormSubmitted(first_form); 814 OnPasswordFormSubmitted(first_form);
793 815
794 // Simulate loading a page, which contains |second_form| instead of 816 // Simulate loading a page, which contains |second_form| instead of
795 // |first_form|. 817 // |first_form|.
796 observed.push_back(second_form); 818 observed.push_back(second_form);
797 819
798 // Verify that no prompt to save the password is shown. 820 // Verify that no prompt to save the password is shown.
799 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0)); 821 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0));
800 manager()->OnPasswordFormsParsed(observed); 822 manager()->OnPasswordFormsParsed(&driver_, observed);
801 manager()->OnPasswordFormsRendered(observed, true); 823 manager()->OnPasswordFormsRendered(&driver_, observed, true);
802 observed.clear(); 824 observed.clear();
803 } 825 }
804 826
805 // Create a form with a new_password_element. Submit the form with the empty 827 // Create a form with a new_password_element. Submit the form with the empty
806 // new password value. It shouldn't overwrite the existing password. 828 // new password value. It shouldn't overwrite the existing password.
807 TEST_F(PasswordManagerTest, DoNotUpdateWithEmptyPassword) { 829 TEST_F(PasswordManagerTest, DoNotUpdateWithEmptyPassword) {
808 std::vector<PasswordForm*> result; // Empty password store. 830 std::vector<PasswordForm*> result; // Empty password store.
809 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) 831 EXPECT_CALL(*store_.get(), GetLogins(_, _, _))
810 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); 832 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
811 std::vector<PasswordForm> observed; 833 std::vector<PasswordForm> observed;
812 PasswordForm form(MakeSimpleForm()); 834 PasswordForm form(MakeSimpleForm());
813 form.new_password_element = ASCIIToUTF16("new_password_element"); 835 form.new_password_element = ASCIIToUTF16("new_password_element");
814 form.new_password_value.clear(); 836 form.new_password_value.clear();
815 observed.push_back(form); 837 observed.push_back(form);
816 manager()->OnPasswordFormsParsed(observed); // The initial load. 838 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load.
817 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. 839 manager()->OnPasswordFormsRendered(&driver_, observed,
840 true); // The initial layout.
818 841
819 // And the form submit contract is to call ProvisionallySavePassword. 842 // And the form submit contract is to call ProvisionallySavePassword.
820 OnPasswordFormSubmitted(form); 843 OnPasswordFormSubmitted(form);
821 844
822 scoped_ptr<PasswordFormManager> form_to_save; 845 scoped_ptr<PasswordFormManager> form_to_save;
823 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(0); 846 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(0);
824 847
825 // Now the password manager waits for the login to complete successfully. 848 // Now the password manager waits for the login to complete successfully.
826 observed.clear(); 849 observed.clear();
827 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 850 manager()->OnPasswordFormsParsed(&driver_,
828 manager()->OnPasswordFormsRendered(observed, 851 observed); // The post-navigation load.
852 manager()->OnPasswordFormsRendered(&driver_, observed,
829 true); // The post-navigation layout. 853 true); // The post-navigation layout.
830 } 854 }
831 855
832 TEST_F(PasswordManagerTest, FormSubmitWithOnlyPassowrdField) { 856 TEST_F(PasswordManagerTest, FormSubmitWithOnlyPassowrdField) {
833 // Test to verify that on submitting the HTML password form without having 857 // Test to verify that on submitting the HTML password form without having
834 // username input filed shows password save promt and saves the password to 858 // username input filed shows password save promt and saves the password to
835 // store. 859 // store.
836 std::vector<PasswordForm*> result; // Empty password store. 860 std::vector<PasswordForm*> result; // Empty password store.
837 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); 861 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0));
838 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) 862 EXPECT_CALL(*store_.get(), GetLogins(_, _, _))
839 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); 863 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
840 std::vector<PasswordForm> observed; 864 std::vector<PasswordForm> observed;
841 865
842 // Loads passsword form without username input field. 866 // Loads passsword form without username input field.
843 PasswordForm form(MakeSimpleFormWithOnlyPasswordField()); 867 PasswordForm form(MakeSimpleFormWithOnlyPasswordField());
844 observed.push_back(form); 868 observed.push_back(form);
845 manager()->OnPasswordFormsParsed(observed); // The initial load. 869 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load.
846 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. 870 manager()->OnPasswordFormsRendered(&driver_, observed,
871 true); // The initial layout.
847 872
848 // And the form submit contract is to call ProvisionallySavePassword. 873 // And the form submit contract is to call ProvisionallySavePassword.
849 manager()->ProvisionallySavePassword(form); 874 manager()->ProvisionallySavePassword(form);
850 875
851 scoped_ptr<PasswordFormManager> form_to_save; 876 scoped_ptr<PasswordFormManager> form_to_save;
852 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) 877 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_))
853 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); 878 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save)));
854 879
855 // Now the password manager waits for the navigation to complete. 880 // Now the password manager waits for the navigation to complete.
856 observed.clear(); 881 observed.clear();
857 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 882 manager()->OnPasswordFormsParsed(&driver_,
858 manager()->OnPasswordFormsRendered(observed, 883 observed); // The post-navigation load.
884 manager()->OnPasswordFormsRendered(&driver_, observed,
859 true); // The post-navigation layout. 885 true); // The post-navigation layout.
860 886
861 ASSERT_TRUE(form_to_save.get()); 887 ASSERT_TRUE(form_to_save.get());
862 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); 888 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form)));
863 889
864 // Simulate saving the form, as if the info bar was accepted. 890 // Simulate saving the form, as if the info bar was accepted.
865 form_to_save->Save(); 891 form_to_save->Save();
866 } 892 }
867 893
868 } // namespace password_manager 894 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698