OLD | NEW |
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/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 arg0->OnGetPasswordStoreResults(forms); | 42 arg0->OnGetPasswordStoreResults(forms); |
43 } | 43 } |
44 | 44 |
45 ACTION_P(SaveToScopedPtr, scoped) { | 45 ACTION_P(SaveToScopedPtr, scoped) { |
46 scoped->reset(arg0); | 46 scoped->reset(arg0); |
47 } | 47 } |
48 | 48 |
49 class PasswordManagerTest : public ChromeRenderViewHostTestHarness { | 49 class PasswordManagerTest : public ChromeRenderViewHostTestHarness { |
50 protected: | 50 protected: |
51 virtual void SetUp() { | 51 virtual void SetUp() { |
52 testing_profile_ = new TestingProfile; | 52 ChromeRenderViewHostTestHarness::SetUp(); |
53 store_ = static_cast<MockPasswordStore*>( | 53 store_ = static_cast<MockPasswordStore*>( |
54 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse( | 54 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse( |
55 testing_profile_, MockPasswordStore::Build).get()); | 55 profile(), MockPasswordStore::Build).get()); |
56 browser_context_.reset(testing_profile_); | |
57 ChromeRenderViewHostTestHarness::SetUp(); | |
58 | 56 |
59 EXPECT_CALL(delegate_, GetProfile()).WillRepeatedly(Return(profile())); | 57 EXPECT_CALL(delegate_, GetProfile()).WillRepeatedly(Return(profile())); |
60 PasswordManager::CreateForWebContentsAndDelegate( | 58 PasswordManager::CreateForWebContentsAndDelegate( |
61 web_contents(), &delegate_); | 59 web_contents(), &delegate_); |
62 EXPECT_CALL(delegate_, DidLastPageLoadEncounterSSLErrors()) | 60 EXPECT_CALL(delegate_, DidLastPageLoadEncounterSSLErrors()) |
63 .WillRepeatedly(Return(false)); | 61 .WillRepeatedly(Return(false)); |
64 } | 62 } |
65 | 63 |
66 virtual void TearDown() { | 64 virtual void TearDown() { |
67 store_ = NULL; | 65 store_ = NULL; |
(...skipping 14 matching lines...) Expand all Loading... |
82 form.signon_realm = "http://www.google.com"; | 80 form.signon_realm = "http://www.google.com"; |
83 return form; | 81 return form; |
84 } | 82 } |
85 | 83 |
86 PasswordManager* manager() { | 84 PasswordManager* manager() { |
87 return PasswordManager::FromWebContents(web_contents()); | 85 return PasswordManager::FromWebContents(web_contents()); |
88 } | 86 } |
89 | 87 |
90 scoped_refptr<MockPasswordStore> store_; | 88 scoped_refptr<MockPasswordStore> store_; |
91 MockPasswordManagerDelegate delegate_; // Owned by manager_. | 89 MockPasswordManagerDelegate delegate_; // Owned by manager_. |
92 | |
93 TestingProfile* testing_profile_; | |
94 }; | 90 }; |
95 | 91 |
96 MATCHER_P(FormMatches, form, "") { | 92 MATCHER_P(FormMatches, form, "") { |
97 return form.signon_realm == arg.signon_realm && | 93 return form.signon_realm == arg.signon_realm && |
98 form.origin == arg.origin && | 94 form.origin == arg.origin && |
99 form.action == arg.action && | 95 form.action == arg.action && |
100 form.username_element == arg.username_element && | 96 form.username_element == arg.username_element && |
101 form.password_element == arg.password_element && | 97 form.password_element == arg.password_element && |
102 form.password_autocomplete_set == | 98 form.password_autocomplete_set == |
103 arg.password_autocomplete_set && | 99 arg.password_autocomplete_set && |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 384 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
389 | 385 |
390 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 386 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
391 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 387 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. |
392 } | 388 } |
393 | 389 |
394 TEST_F(PasswordManagerTest, SavingDependsOnManagerEnabledPreference) { | 390 TEST_F(PasswordManagerTest, SavingDependsOnManagerEnabledPreference) { |
395 // Test that saving passwords depends on the password manager enabled | 391 // Test that saving passwords depends on the password manager enabled |
396 // preference. | 392 // preference. |
397 TestingPrefServiceSyncable* prefService = | 393 TestingPrefServiceSyncable* prefService = |
398 testing_profile_->GetTestingPrefService(); | 394 profile()->GetTestingPrefService(); |
399 prefService->SetUserPref(prefs::kPasswordManagerEnabled, | 395 prefService->SetUserPref(prefs::kPasswordManagerEnabled, |
400 Value::CreateBooleanValue(true)); | 396 Value::CreateBooleanValue(true)); |
401 EXPECT_TRUE(manager()->IsSavingEnabled()); | 397 EXPECT_TRUE(manager()->IsSavingEnabled()); |
402 prefService->SetUserPref(prefs::kPasswordManagerEnabled, | 398 prefService->SetUserPref(prefs::kPasswordManagerEnabled, |
403 Value::CreateBooleanValue(false)); | 399 Value::CreateBooleanValue(false)); |
404 EXPECT_FALSE(manager()->IsSavingEnabled()); | 400 EXPECT_FALSE(manager()->IsSavingEnabled()); |
405 } | 401 } |
406 | 402 |
407 TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) { | 403 TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) { |
408 // Test fix for issue 158296: Passwords must be filled even if the password | 404 // Test fix for issue 158296: Passwords must be filled even if the password |
409 // manager is disabled. | 405 // manager is disabled. |
410 std::vector<PasswordForm*> result; | 406 std::vector<PasswordForm*> result; |
411 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); | 407 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); |
412 result.push_back(existing); | 408 result.push_back(existing); |
413 TestingPrefServiceSyncable* prefService = | 409 TestingPrefServiceSyncable* prefService = |
414 testing_profile_->GetTestingPrefService(); | 410 profile()->GetTestingPrefService(); |
415 prefService->SetUserPref(prefs::kPasswordManagerEnabled, | 411 prefService->SetUserPref(prefs::kPasswordManagerEnabled, |
416 Value::CreateBooleanValue(false)); | 412 Value::CreateBooleanValue(false)); |
417 EXPECT_CALL(delegate_, FillPasswordForm(_)); | 413 EXPECT_CALL(delegate_, FillPasswordForm(_)); |
418 EXPECT_CALL(*store_.get(), GetLogins(_, _)) | 414 EXPECT_CALL(*store_.get(), GetLogins(_, _)) |
419 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); | 415 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); |
420 std::vector<PasswordForm> observed; | 416 std::vector<PasswordForm> observed; |
421 PasswordForm form(MakeSimpleForm()); | 417 PasswordForm form(MakeSimpleForm()); |
422 observed.push_back(form); | 418 observed.push_back(form); |
423 manager()->OnPasswordFormsParsed(observed); | 419 manager()->OnPasswordFormsParsed(observed); |
424 } | 420 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 // navigation occurs. | 470 // navigation occurs. |
475 EXPECT_CALL(delegate_, | 471 EXPECT_CALL(delegate_, |
476 AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(0)); | 472 AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(0)); |
477 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 473 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
478 | 474 |
479 // Now the password manager waits for the navigation to complete. | 475 // Now the password manager waits for the navigation to complete. |
480 observed.clear(); | 476 observed.clear(); |
481 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 477 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
482 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 478 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. |
483 } | 479 } |
OLD | NEW |