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

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

Issue 11446028: Ignore autocomplete=off when password manager is saving the generated passwords during account crea… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address gcasto's comment Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/password_manager/mock_password_store.h" 10 #include "chrome/browser/password_manager/mock_password_store.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 web_contents(), &delegate_); 68 web_contents(), &delegate_);
69 EXPECT_CALL(delegate_, DidLastPageLoadEncounterSSLErrors()) 69 EXPECT_CALL(delegate_, DidLastPageLoadEncounterSSLErrors())
70 .WillRepeatedly(Return(false)); 70 .WillRepeatedly(Return(false));
71 } 71 }
72 72
73 virtual void TearDown() { 73 virtual void TearDown() {
74 store_ = NULL; 74 store_ = NULL;
75 ChromeRenderViewHostTestHarness::TearDown(); 75 ChromeRenderViewHostTestHarness::TearDown();
76 } 76 }
77 77
78 PasswordForm MakeSimpleForm() { 78 // Make default value of |autocomplete| to be true, such that we only need to
79 // add tests in autocomplete=off cases.
80 PasswordForm MakeSimpleForm(bool autocomplete = true) {
Ilya Sherman 2012/12/06 22:55:59 nit: Default function parameters are disallowed by
zysxqn 2012/12/06 23:54:49 Done.
79 PasswordForm form; 81 PasswordForm form;
80 form.origin = GURL("http://www.google.com/a/LoginAuth"); 82 form.origin = GURL("http://www.google.com/a/LoginAuth");
81 form.action = GURL("http://www.google.com/a/Login"); 83 form.action = GURL("http://www.google.com/a/Login");
82 form.username_element = ASCIIToUTF16("Email"); 84 form.username_element = ASCIIToUTF16("Email");
83 form.password_element = ASCIIToUTF16("Passwd"); 85 form.password_element = ASCIIToUTF16("Passwd");
84 form.username_value = ASCIIToUTF16("google"); 86 form.username_value = ASCIIToUTF16("google");
85 form.password_value = ASCIIToUTF16("password"); 87 form.password_value = ASCIIToUTF16("password");
88 form.password_should_autocomplete = autocomplete;
86 form.submit_element = ASCIIToUTF16("signIn"); 89 form.submit_element = ASCIIToUTF16("signIn");
87 form.signon_realm = "http://www.google.com"; 90 form.signon_realm = "http://www.google.com";
88 return form; 91 return form;
89 } 92 }
90 93
91 PasswordManager* manager() { 94 PasswordManager* manager() {
92 return PasswordManager::FromWebContents(web_contents()); 95 return PasswordManager::FromWebContents(web_contents());
93 } 96 }
94 97
95 // We create a UI thread to satisfy PasswordStore. 98 // We create a UI thread to satisfy PasswordStore.
96 content::TestBrowserThread ui_thread_; 99 content::TestBrowserThread ui_thread_;
97 100
98 scoped_refptr<MockPasswordStore> store_; 101 scoped_refptr<MockPasswordStore> store_;
99 MockPasswordManagerDelegate delegate_; // Owned by manager_. 102 MockPasswordManagerDelegate delegate_; // Owned by manager_.
100 103
101 TestingProfile* testing_profile_; 104 TestingProfile* testing_profile_;
102 }; 105 };
103 106
104 MATCHER_P(FormMatches, form, "") { 107 MATCHER_P(FormMatches, form, "") {
105 return form.signon_realm == arg.signon_realm && 108 return form.signon_realm == arg.signon_realm &&
106 form.origin == arg.origin && 109 form.origin == arg.origin &&
107 form.action == arg.action && 110 form.action == arg.action &&
108 form.username_element == arg.username_element && 111 form.username_element == arg.username_element &&
109 form.password_element == arg.password_element && 112 form.password_element == arg.password_element &&
113 form.password_should_autocomplete ==
114 arg.password_should_autocomplete &&
110 form.submit_element == arg.submit_element; 115 form.submit_element == arg.submit_element;
111 } 116 }
112 117
113 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { 118 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) {
114 // Test that observing a newly submitted form shows the save password bar. 119 // Test that observing a newly submitted form shows the save password bar.
115 std::vector<PasswordForm*> result; // Empty password store. 120 std::vector<PasswordForm*> result; // Empty password store.
116 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); 121 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0));
117 EXPECT_CALL(*store_, GetLogins(_,_)) 122 EXPECT_CALL(*store_, GetLogins(_,_))
118 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); 123 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0)));
119 std::vector<PasswordForm> observed; 124 std::vector<PasswordForm> observed;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 Value::CreateBooleanValue(false)); 368 Value::CreateBooleanValue(false));
364 EXPECT_CALL(delegate_, FillPasswordForm(_)); 369 EXPECT_CALL(delegate_, FillPasswordForm(_));
365 EXPECT_CALL(*store_, GetLogins(_, _)) 370 EXPECT_CALL(*store_, GetLogins(_, _))
366 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); 371 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0)));
367 std::vector<PasswordForm> observed; 372 std::vector<PasswordForm> observed;
368 PasswordForm form(MakeSimpleForm()); 373 PasswordForm form(MakeSimpleForm());
369 observed.push_back(form); 374 observed.push_back(form);
370 manager()->OnPasswordFormsParsed(observed); 375 manager()->OnPasswordFormsParsed(observed);
371 } 376 }
372 377
378 TEST_F(PasswordManagerTest, FormNotSubmitAutocompleteOff) {
Ilya Sherman 2012/12/06 22:55:59 nit: Perhaps "Saved" rather than "Submit", or else
zysxqn 2012/12/06 23:54:49 Done.
379 // Test password form with non-generated password will not be saved if
380 // autocomplete=off.
381 //
382 // This is mostly copied from FormSubmitEmptyStore.
Ilya Sherman 2012/12/06 22:55:59 No need to include this line in the comment, thoug
zysxqn 2012/12/06 23:54:49 Done.
383 std::vector<PasswordForm*> result; // Empty password store.
384 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0));
385 EXPECT_CALL(*store_, GetLogins(_,_))
386 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0)));
387 std::vector<PasswordForm> observed;
388 PasswordForm form(MakeSimpleForm(false));
389 observed.push_back(form);
390 manager()->OnPasswordFormsParsed(observed); // The initial load.
391 manager()->OnPasswordFormsRendered(observed); // The initial layout.
392
393 // And the form submit contract is to call ProvisionallySavePassword.
394 manager()->ProvisionallySavePassword(form);
395
396 // Now the password manager waits for the navigation to complete. No call
397 // should be expected since the form will not be save.
398 observed.clear();
399 manager()->OnPasswordFormsParsed(observed); // The post-navigation load.
400 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout.
401 }
Ilya Sherman 2012/12/06 22:55:59 This test isn't actually testing that the form isn
zysxqn 2012/12/06 23:54:49 Done.
402
403 TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitAutocompleteOff) {
404 // Test password form with generated password will still be saved if
405 // autocomplete=off.
406 //
407 // This is mostly copied from GenerartedPasswordFormSubmitEmptyStore.
408 std::vector<PasswordForm*> result; // Empty password store.
409 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0));
410 EXPECT_CALL(*store_, GetLogins(_,_))
411 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0)));
412 std::vector<PasswordForm> observed;
413 PasswordForm form(MakeSimpleForm(false));
414 observed.push_back(form);
415 manager()->OnPasswordFormsParsed(observed); // The initial load.
416 manager()->OnPasswordFormsRendered(observed); // The initial layout.
417
418 // Simulate the user generating the password and submitting the form.
419 manager()->SetFormHasGeneratedPassword(form);
420 manager()->ProvisionallySavePassword(form);
421
422 // The user should not be presented with an infobar as they have already given
423 // consent. The form should be saved once navigation occurs.
Ilya Sherman 2012/12/06 22:55:59 Where has the user given consent? Does this test
Ilya Sherman 2012/12/06 23:40:37 Never mind, I think I understand what this means:
zysxqn 2012/12/06 23:54:49 This is copied from GeneratedPasswordFormSubmitEmp
zysxqn 2012/12/06 23:54:49 Done.
424 EXPECT_CALL(delegate_,
425 AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(0));
426 EXPECT_CALL(*store_, AddLogin(FormMatches(form)));
427
428 // Now the password manager waits for the navigation to complete.
429 observed.clear();
430 manager()->OnPasswordFormsParsed(observed); // The post-navigation load.
431 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout.
432 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698