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 1656005: Fix password mgr heuristics for sites that keep the login form around after signin (Closed)
Patch Set: Responding to feedback Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/file_path.h" 5 #include "base/file_path.h"
6 #include "base/string_util.h" 6 #include "base/string_util.h"
7 #include "chrome/browser/password_manager/password_manager.h" 7 #include "chrome/browser/password_manager/password_manager.h"
8 #include "chrome/browser/password_manager/password_store.h" 8 #include "chrome/browser/password_manager/password_store.h"
9 #include "chrome/browser/pref_service.h" 9 #include "chrome/browser/pref_service.h"
10 #include "chrome/common/url_constants.h" 10 #include "chrome/common/url_constants.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 115
116 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { 116 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) {
117 // Test that observing a newly submitted form shows the save password bar. 117 // Test that observing a newly submitted form shows the save password bar.
118 std::vector<PasswordForm*> result; // Empty password store. 118 std::vector<PasswordForm*> result; // Empty password store.
119 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); 119 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0));
120 EXPECT_CALL(*store_, GetLogins(_,_)) 120 EXPECT_CALL(*store_, GetLogins(_,_))
121 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); 121 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0)));
122 std::vector<PasswordForm> observed; 122 std::vector<PasswordForm> observed;
123 PasswordForm form(MakeSimpleForm()); 123 PasswordForm form(MakeSimpleForm());
124 observed.push_back(form); 124 observed.push_back(form);
125 manager()->PasswordFormsSeen(observed); // The initial load. 125 manager()->PasswordFormsFound(observed); // The initial load.
126 manager()->PasswordFormsVisible(observed); // The initial layout.
126 127
127 // And the form submit contract is to call ProvisionallySavePassword. 128 // And the form submit contract is to call ProvisionallySavePassword.
128 manager()->ProvisionallySavePassword(form); 129 manager()->ProvisionallySavePassword(form);
129 130
130 scoped_ptr<PasswordFormManager> form_to_save; 131 scoped_ptr<PasswordFormManager> form_to_save;
131 EXPECT_CALL(delegate_, AddSavePasswordInfoBar(_)) 132 EXPECT_CALL(delegate_, AddSavePasswordInfoBar(_))
132 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); 133 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save)));
133 134
134 // Now the password manager waits for the navigation to complete. 135 // Now the password manager waits for the navigation to complete.
135 manager()->DidStopLoading(); 136 manager()->DidStopLoading();
136 137
137 EXPECT_FALSE(NULL == form_to_save.get()); 138 ASSERT_FALSE(NULL == form_to_save.get());
138 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); 139 EXPECT_CALL(*store_, AddLogin(FormMatches(form)));
139 140
140 // Simulate saving the form, as if the info bar was accepted. 141 // Simulate saving the form, as if the info bar was accepted.
141 form_to_save->Save(); 142 form_to_save->Save();
142 } 143 }
143 144
144 TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { 145 TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) {
145 // Same as above, except with an existing form for the same signon realm, 146 // Same as above, except with an existing form for the same signon realm,
146 // but different origin. Detailed cases like this are covered by 147 // but different origin. Detailed cases like this are covered by
147 // PasswordFormManagerTest. 148 // PasswordFormManagerTest.
148 std::vector<PasswordForm*> result; 149 std::vector<PasswordForm*> result;
149 PasswordForm* existing_different = new PasswordForm(MakeSimpleForm()); 150 PasswordForm* existing_different = new PasswordForm(MakeSimpleForm());
150 existing_different->username_value = ASCIIToUTF16("google2"); 151 existing_different->username_value = ASCIIToUTF16("google2");
151 result.push_back(existing_different); 152 result.push_back(existing_different);
152 EXPECT_CALL(delegate_, FillPasswordForm(_)); 153 EXPECT_CALL(delegate_, FillPasswordForm(_));
153 EXPECT_CALL(*store_, GetLogins(_,_)) 154 EXPECT_CALL(*store_, GetLogins(_,_))
154 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); 155 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0)));
155 156
156 std::vector<PasswordForm> observed; 157 std::vector<PasswordForm> observed;
157 PasswordForm form(MakeSimpleForm()); 158 PasswordForm form(MakeSimpleForm());
158 observed.push_back(form); 159 observed.push_back(form);
159 manager()->PasswordFormsSeen(observed); // The initial load. 160 manager()->PasswordFormsFound(observed); // The initial load.
161 manager()->PasswordFormsVisible(observed); // The initial layout.
160 manager()->ProvisionallySavePassword(form); 162 manager()->ProvisionallySavePassword(form);
161 163
162 // We still expect an add, since we didn't have a good match. 164 // We still expect an add, since we didn't have a good match.
163 scoped_ptr<PasswordFormManager> form_to_save; 165 scoped_ptr<PasswordFormManager> form_to_save;
164 EXPECT_CALL(delegate_, AddSavePasswordInfoBar(_)) 166 EXPECT_CALL(delegate_, AddSavePasswordInfoBar(_))
165 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); 167 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save)));
166 168
167 manager()->DidStopLoading(); 169 manager()->DidStopLoading();
168 170
169 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); 171 EXPECT_CALL(*store_, AddLogin(FormMatches(form)));
170 // Simulate saving the form. 172 // Simulate saving the form.
171 form_to_save->Save(); 173 form_to_save->Save();
172 } 174 }
173 175
174 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { 176 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) {
175 std::vector<PasswordForm*> result; // Empty password store. 177 std::vector<PasswordForm*> result; // Empty password store.
176 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); 178 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0));
177 EXPECT_CALL(*store_, GetLogins(_,_)) 179 EXPECT_CALL(*store_, GetLogins(_,_))
178 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); 180 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0)));
179 std::vector<PasswordForm> observed; 181 std::vector<PasswordForm> observed;
180 PasswordForm form(MakeSimpleForm()); 182 PasswordForm form(MakeSimpleForm());
181 observed.push_back(form); 183 observed.push_back(form);
182 manager()->PasswordFormsSeen(observed); // The initial load. 184 manager()->PasswordFormsFound(observed); // The initial load.
185 manager()->PasswordFormsVisible(observed); // The initial layout.
183 186
184 manager()->DidNavigate(); 187 manager()->DidNavigate();
185 188
186 // No expected calls. 189 // No expected calls.
187 manager()->DidStopLoading(); 190 manager()->DidStopLoading();
188 } 191 }
189 192
190 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { 193 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) {
191 std::vector<PasswordForm*> result; // Empty password store. 194 std::vector<PasswordForm*> result; // Empty password store.
192 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); 195 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0));
193 EXPECT_CALL(*store_, GetLogins(_,_)) 196 EXPECT_CALL(*store_, GetLogins(_,_))
194 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); 197 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0)));
195 std::vector<PasswordForm> observed; 198 std::vector<PasswordForm> observed;
196 PasswordForm form(MakeSimpleForm()); 199 PasswordForm form(MakeSimpleForm());
197 observed.push_back(form); 200 observed.push_back(form);
198 manager()->PasswordFormsSeen(observed); // The initial load. 201 manager()->PasswordFormsFound(observed); // The initial load.
202 manager()->PasswordFormsVisible(observed); // The initial layout.
199 203
200 manager()->ProvisionallySavePassword(form); 204 manager()->ProvisionallySavePassword(form);
201 205
202 manager()->PasswordFormsSeen(observed); // Simulated re-appearance. 206 // The form reappears, and is visible in the layout:
207 manager()->PasswordFormsFound(observed);
208 manager()->PasswordFormsVisible(observed);
203 209
204 // No expected calls to the PasswordStore... 210 // No expected calls to the PasswordStore...
205 manager()->DidStopLoading(); 211 manager()->DidStopLoading();
206 } 212 }
213
214 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) {
215 // Tests fix of issue 28911: if the login form reappears on the subsequent
216 // page, but is invisible, it shouldn't count as a failed login.
217 std::vector<PasswordForm*> result; // Empty password store.
218 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0));
219 EXPECT_CALL(*store_, GetLogins(_,_))
220 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0)));
221 std::vector<PasswordForm> observed;
222 PasswordForm form(MakeSimpleForm());
223 observed.push_back(form);
224 manager()->PasswordFormsFound(observed); // The initial load.
225 manager()->PasswordFormsVisible(observed); // The initial layout.
226
227 manager()->ProvisionallySavePassword(form);
228
229 // The form reappears, but is not visible in the layout:
230 manager()->PasswordFormsFound(observed);
231 // No call to PasswordFormsVisible.
232
233 // Expect info bar to appear:
234 scoped_ptr<PasswordFormManager> form_to_save;
235 EXPECT_CALL(delegate_, AddSavePasswordInfoBar(_))
236 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save)));
237
238 manager()->DidStopLoading();
239
240 ASSERT_FALSE(NULL == form_to_save.get());
241 EXPECT_CALL(*store_, AddLogin(FormMatches(form)));
242 // Simulate saving the form.
243 form_to_save->Save();
244 }
245
246 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) {
247 // Make sure an invisible login form still gets autofilled.
248 std::vector<PasswordForm*> result;
249 PasswordForm* existing = new PasswordForm(MakeSimpleForm());
250 result.push_back(existing);
251 EXPECT_CALL(delegate_, FillPasswordForm(_));
252 EXPECT_CALL(*store_, GetLogins(_,_))
253 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0)));
254 std::vector<PasswordForm> observed;
255 PasswordForm form(MakeSimpleForm());
256 observed.push_back(form);
257 manager()->PasswordFormsFound(observed); // The initial load.
258 // PasswordFormsVisible is not called.
259
260 manager()->DidStopLoading();
261 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_manager.cc ('k') | chrome/browser/renderer_host/render_view_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698