OLD | NEW |
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 <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/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 130 |
131 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { | 131 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { |
132 // Test that observing a newly submitted form shows the save password bar. | 132 // Test that observing a newly submitted form shows the save password bar. |
133 std::vector<PasswordForm*> result; // Empty password store. | 133 std::vector<PasswordForm*> result; // Empty password store. |
134 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 134 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
135 EXPECT_CALL(*store_, GetLogins(_,_)) | 135 EXPECT_CALL(*store_, GetLogins(_,_)) |
136 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); | 136 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); |
137 std::vector<PasswordForm> observed; | 137 std::vector<PasswordForm> observed; |
138 PasswordForm form(MakeSimpleForm()); | 138 PasswordForm form(MakeSimpleForm()); |
139 observed.push_back(form); | 139 observed.push_back(form); |
140 manager()->PasswordFormsFound(observed); // The initial load. | 140 manager()->OnPasswordFormsFound(observed); // The initial load. |
141 manager()->PasswordFormsVisible(observed); // The initial layout. | 141 manager()->OnPasswordFormsVisible(observed); // The initial layout. |
142 | 142 |
143 // And the form submit contract is to call ProvisionallySavePassword. | 143 // And the form submit contract is to call ProvisionallySavePassword. |
144 manager()->ProvisionallySavePassword(form); | 144 manager()->ProvisionallySavePassword(form); |
145 | 145 |
146 scoped_ptr<PasswordFormManager> form_to_save; | 146 scoped_ptr<PasswordFormManager> form_to_save; |
147 EXPECT_CALL(delegate_, AddSavePasswordInfoBar(_)) | 147 EXPECT_CALL(delegate_, AddSavePasswordInfoBar(_)) |
148 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 148 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
149 | 149 |
150 // Now the password manager waits for the navigation to complete. | 150 // Now the password manager waits for the navigation to complete. |
151 manager()->DidStopLoading(); | 151 manager()->DidStopLoading(); |
(...skipping 13 matching lines...) Expand all Loading... |
165 PasswordForm* existing_different = new PasswordForm(MakeSimpleForm()); | 165 PasswordForm* existing_different = new PasswordForm(MakeSimpleForm()); |
166 existing_different->username_value = ASCIIToUTF16("google2"); | 166 existing_different->username_value = ASCIIToUTF16("google2"); |
167 result.push_back(existing_different); | 167 result.push_back(existing_different); |
168 EXPECT_CALL(delegate_, FillPasswordForm(_)); | 168 EXPECT_CALL(delegate_, FillPasswordForm(_)); |
169 EXPECT_CALL(*store_, GetLogins(_,_)) | 169 EXPECT_CALL(*store_, GetLogins(_,_)) |
170 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); | 170 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); |
171 | 171 |
172 std::vector<PasswordForm> observed; | 172 std::vector<PasswordForm> observed; |
173 PasswordForm form(MakeSimpleForm()); | 173 PasswordForm form(MakeSimpleForm()); |
174 observed.push_back(form); | 174 observed.push_back(form); |
175 manager()->PasswordFormsFound(observed); // The initial load. | 175 manager()->OnPasswordFormsFound(observed); // The initial load. |
176 manager()->PasswordFormsVisible(observed); // The initial layout. | 176 manager()->OnPasswordFormsVisible(observed); // The initial layout. |
177 manager()->ProvisionallySavePassword(form); | 177 manager()->ProvisionallySavePassword(form); |
178 | 178 |
179 // We still expect an add, since we didn't have a good match. | 179 // We still expect an add, since we didn't have a good match. |
180 scoped_ptr<PasswordFormManager> form_to_save; | 180 scoped_ptr<PasswordFormManager> form_to_save; |
181 EXPECT_CALL(delegate_, AddSavePasswordInfoBar(_)) | 181 EXPECT_CALL(delegate_, AddSavePasswordInfoBar(_)) |
182 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 182 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
183 | 183 |
184 manager()->DidStopLoading(); | 184 manager()->DidStopLoading(); |
185 | 185 |
186 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); | 186 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); |
187 // Simulate saving the form. | 187 // Simulate saving the form. |
188 form_to_save->Save(); | 188 form_to_save->Save(); |
189 } | 189 } |
190 | 190 |
191 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { | 191 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { |
192 std::vector<PasswordForm*> result; // Empty password store. | 192 std::vector<PasswordForm*> result; // Empty password store. |
193 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 193 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
194 EXPECT_CALL(*store_, GetLogins(_,_)) | 194 EXPECT_CALL(*store_, GetLogins(_,_)) |
195 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); | 195 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); |
196 std::vector<PasswordForm> observed; | 196 std::vector<PasswordForm> observed; |
197 PasswordForm form(MakeSimpleForm()); | 197 PasswordForm form(MakeSimpleForm()); |
198 observed.push_back(form); | 198 observed.push_back(form); |
199 manager()->PasswordFormsFound(observed); // The initial load. | 199 manager()->OnPasswordFormsFound(observed); // The initial load. |
200 manager()->PasswordFormsVisible(observed); // The initial layout. | 200 manager()->OnPasswordFormsVisible(observed); // The initial layout. |
201 | 201 |
202 manager()->DidNavigate(); | 202 manager()->DidNavigate(); |
203 | 203 |
204 // No expected calls. | 204 // No expected calls. |
205 manager()->DidStopLoading(); | 205 manager()->DidStopLoading(); |
206 } | 206 } |
207 | 207 |
208 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { | 208 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { |
209 std::vector<PasswordForm*> result; // Empty password store. | 209 std::vector<PasswordForm*> result; // Empty password store. |
210 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 210 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
211 EXPECT_CALL(*store_, GetLogins(_,_)) | 211 EXPECT_CALL(*store_, GetLogins(_,_)) |
212 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); | 212 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); |
213 std::vector<PasswordForm> observed; | 213 std::vector<PasswordForm> observed; |
214 PasswordForm form(MakeSimpleForm()); | 214 PasswordForm form(MakeSimpleForm()); |
215 observed.push_back(form); | 215 observed.push_back(form); |
216 manager()->PasswordFormsFound(observed); // The initial load. | 216 manager()->OnPasswordFormsFound(observed); // The initial load. |
217 manager()->PasswordFormsVisible(observed); // The initial layout. | 217 manager()->OnPasswordFormsVisible(observed); // The initial layout. |
218 | 218 |
219 manager()->ProvisionallySavePassword(form); | 219 manager()->ProvisionallySavePassword(form); |
220 | 220 |
221 // The form reappears, and is visible in the layout: | 221 // The form reappears, and is visible in the layout: |
222 manager()->PasswordFormsFound(observed); | 222 manager()->OnPasswordFormsFound(observed); |
223 manager()->PasswordFormsVisible(observed); | 223 manager()->OnPasswordFormsVisible(observed); |
224 | 224 |
225 // No expected calls to the PasswordStore... | 225 // No expected calls to the PasswordStore... |
226 manager()->DidStopLoading(); | 226 manager()->DidStopLoading(); |
227 } | 227 } |
228 | 228 |
229 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { | 229 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { |
230 // Tests fix of issue 28911: if the login form reappears on the subsequent | 230 // Tests fix of issue 28911: if the login form reappears on the subsequent |
231 // page, but is invisible, it shouldn't count as a failed login. | 231 // page, but is invisible, it shouldn't count as a failed login. |
232 std::vector<PasswordForm*> result; // Empty password store. | 232 std::vector<PasswordForm*> result; // Empty password store. |
233 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 233 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
234 EXPECT_CALL(*store_, GetLogins(_,_)) | 234 EXPECT_CALL(*store_, GetLogins(_,_)) |
235 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); | 235 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); |
236 std::vector<PasswordForm> observed; | 236 std::vector<PasswordForm> observed; |
237 PasswordForm form(MakeSimpleForm()); | 237 PasswordForm form(MakeSimpleForm()); |
238 observed.push_back(form); | 238 observed.push_back(form); |
239 manager()->PasswordFormsFound(observed); // The initial load. | 239 manager()->OnPasswordFormsFound(observed); // The initial load. |
240 manager()->PasswordFormsVisible(observed); // The initial layout. | 240 manager()->OnPasswordFormsVisible(observed); // The initial layout. |
241 | 241 |
242 manager()->ProvisionallySavePassword(form); | 242 manager()->ProvisionallySavePassword(form); |
243 | 243 |
244 // The form reappears, but is not visible in the layout: | 244 // The form reappears, but is not visible in the layout: |
245 manager()->PasswordFormsFound(observed); | 245 manager()->OnPasswordFormsFound(observed); |
246 // No call to PasswordFormsVisible. | 246 // No call to PasswordFormsVisible. |
247 | 247 |
248 // Expect info bar to appear: | 248 // Expect info bar to appear: |
249 scoped_ptr<PasswordFormManager> form_to_save; | 249 scoped_ptr<PasswordFormManager> form_to_save; |
250 EXPECT_CALL(delegate_, AddSavePasswordInfoBar(_)) | 250 EXPECT_CALL(delegate_, AddSavePasswordInfoBar(_)) |
251 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 251 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
252 | 252 |
253 manager()->DidStopLoading(); | 253 manager()->DidStopLoading(); |
254 | 254 |
255 ASSERT_FALSE(NULL == form_to_save.get()); | 255 ASSERT_FALSE(NULL == form_to_save.get()); |
256 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); | 256 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); |
257 // Simulate saving the form. | 257 // Simulate saving the form. |
258 form_to_save->Save(); | 258 form_to_save->Save(); |
259 } | 259 } |
260 | 260 |
261 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { | 261 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { |
262 // Make sure an invisible login form still gets autofilled. | 262 // Make sure an invisible login form still gets autofilled. |
263 std::vector<PasswordForm*> result; | 263 std::vector<PasswordForm*> result; |
264 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); | 264 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); |
265 result.push_back(existing); | 265 result.push_back(existing); |
266 EXPECT_CALL(delegate_, FillPasswordForm(_)); | 266 EXPECT_CALL(delegate_, FillPasswordForm(_)); |
267 EXPECT_CALL(*store_, GetLogins(_,_)) | 267 EXPECT_CALL(*store_, GetLogins(_,_)) |
268 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); | 268 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); |
269 std::vector<PasswordForm> observed; | 269 std::vector<PasswordForm> observed; |
270 PasswordForm form(MakeSimpleForm()); | 270 PasswordForm form(MakeSimpleForm()); |
271 observed.push_back(form); | 271 observed.push_back(form); |
272 manager()->PasswordFormsFound(observed); // The initial load. | 272 manager()->OnPasswordFormsFound(observed); // The initial load. |
273 // PasswordFormsVisible is not called. | 273 // PasswordFormsVisible is not called. |
274 | 274 |
275 manager()->DidStopLoading(); | 275 manager()->DidStopLoading(); |
276 } | 276 } |
OLD | NEW |