OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/password_manager.h" | 10 #include "chrome/browser/password_manager/password_manager.h" |
11 #include "chrome/browser/password_manager/password_manager_delegate.h" | 11 #include "chrome/browser/password_manager/password_manager_delegate.h" |
12 #include "chrome/browser/password_manager/password_store.h" | 12 #include "chrome/browser/password_manager/password_store.h" |
13 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
15 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
16 #include "content/browser/tab_contents/test_tab_contents.h" | 16 #include "content/browser/tab_contents/test_tab_contents.h" |
| 17 #include "content/public/browser/navigation_details.h" |
| 18 #include "content/public/common/frame_navigate_params.h" |
17 #include "content/test/test_browser_thread.h" | 19 #include "content/test/test_browser_thread.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
20 | 22 |
21 using content::BrowserThread; | 23 using content::BrowserThread; |
22 using webkit::forms::PasswordForm; | 24 using webkit::forms::PasswordForm; |
23 using testing::_; | 25 using testing::_; |
24 using testing::DoAll; | 26 using testing::DoAll; |
25 using ::testing::Exactly; | 27 using ::testing::Exactly; |
26 using ::testing::WithArg; | 28 using ::testing::WithArg; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 std::vector<PasswordForm*> result; // Empty password store. | 201 std::vector<PasswordForm*> result; // Empty password store. |
200 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 202 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
201 EXPECT_CALL(*store_, GetLogins(_,_)) | 203 EXPECT_CALL(*store_, GetLogins(_,_)) |
202 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); | 204 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); |
203 std::vector<PasswordForm> observed; | 205 std::vector<PasswordForm> observed; |
204 PasswordForm form(MakeSimpleForm()); | 206 PasswordForm form(MakeSimpleForm()); |
205 observed.push_back(form); | 207 observed.push_back(form); |
206 manager()->OnPasswordFormsFound(observed); // The initial load. | 208 manager()->OnPasswordFormsFound(observed); // The initial load. |
207 manager()->OnPasswordFormsVisible(observed); // The initial layout. | 209 manager()->OnPasswordFormsVisible(observed); // The initial layout. |
208 | 210 |
209 manager()->DidNavigate(); | 211 content::LoadCommittedDetails details; |
| 212 content::FrameNavigateParams params; |
| 213 params.password_form = form; |
| 214 manager()->DidNavigateAnyFrame(details, params); |
210 | 215 |
211 // No expected calls. | 216 // No expected calls. |
212 manager()->DidStopLoading(); | 217 manager()->DidStopLoading(); |
213 } | 218 } |
214 | 219 |
| 220 TEST_F(PasswordManagerTest, FormSubmitAfterNavigateSubframe) { |
| 221 // Test that navigating a subframe does not prevent us from showing the save |
| 222 // password infobar. |
| 223 std::vector<PasswordForm*> result; // Empty password store. |
| 224 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
| 225 EXPECT_CALL(*store_, GetLogins(_,_)) |
| 226 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); |
| 227 std::vector<PasswordForm> observed; |
| 228 PasswordForm form(MakeSimpleForm()); |
| 229 observed.push_back(form); |
| 230 manager()->OnPasswordFormsFound(observed); // The initial load. |
| 231 manager()->OnPasswordFormsVisible(observed); // The initial layout. |
| 232 |
| 233 scoped_ptr<PasswordFormManager> form_to_save; |
| 234 EXPECT_CALL(delegate_, AddSavePasswordInfoBar(_)) |
| 235 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
| 236 |
| 237 // Simulate navigating a sub-frame. |
| 238 content::LoadCommittedDetails details; |
| 239 content::FrameNavigateParams params; |
| 240 manager()->DidNavigateAnyFrame(details, params); |
| 241 |
| 242 // Simulate navigating the real page. |
| 243 params.password_form = form; |
| 244 manager()->DidNavigateAnyFrame(details, params); |
| 245 |
| 246 // Now the password manager waits for the navigation to complete. |
| 247 manager()->DidStopLoading(); |
| 248 |
| 249 ASSERT_FALSE(NULL == form_to_save.get()); |
| 250 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); |
| 251 |
| 252 // Simulate saving the form, as if the info bar was accepted. |
| 253 form_to_save->Save(); |
| 254 } |
| 255 |
215 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { | 256 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { |
216 std::vector<PasswordForm*> result; // Empty password store. | 257 std::vector<PasswordForm*> result; // Empty password store. |
217 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 258 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
218 EXPECT_CALL(*store_, GetLogins(_,_)) | 259 EXPECT_CALL(*store_, GetLogins(_,_)) |
219 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); | 260 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); |
220 std::vector<PasswordForm> observed; | 261 std::vector<PasswordForm> observed; |
221 PasswordForm form(MakeSimpleForm()); | 262 PasswordForm form(MakeSimpleForm()); |
222 observed.push_back(form); | 263 observed.push_back(form); |
223 manager()->OnPasswordFormsFound(observed); // The initial load. | 264 manager()->OnPasswordFormsFound(observed); // The initial load. |
224 manager()->OnPasswordFormsVisible(observed); // The initial layout. | 265 manager()->OnPasswordFormsVisible(observed); // The initial layout. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 EXPECT_CALL(*store_, GetLogins(_,_)) | 315 EXPECT_CALL(*store_, GetLogins(_,_)) |
275 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); | 316 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); |
276 std::vector<PasswordForm> observed; | 317 std::vector<PasswordForm> observed; |
277 PasswordForm form(MakeSimpleForm()); | 318 PasswordForm form(MakeSimpleForm()); |
278 observed.push_back(form); | 319 observed.push_back(form); |
279 manager()->OnPasswordFormsFound(observed); // The initial load. | 320 manager()->OnPasswordFormsFound(observed); // The initial load. |
280 // PasswordFormsVisible is not called. | 321 // PasswordFormsVisible is not called. |
281 | 322 |
282 manager()->DidStopLoading(); | 323 manager()->DidStopLoading(); |
283 } | 324 } |
OLD | NEW |