| 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/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" |
| 11 #include "chrome/browser/password_manager/password_manager.h" | 11 #include "chrome/browser/password_manager/password_manager.h" |
| 12 #include "chrome/browser/password_manager/password_manager_delegate.h" | 12 #include "chrome/browser/password_manager/password_manager_delegate.h" |
| 13 #include "chrome/browser/password_manager/password_store.h" | 13 #include "chrome/browser/password_manager/password_store.h" |
| 14 #include "chrome/browser/password_manager/password_store_factory.h" | 14 #include "chrome/browser/password_manager/password_store_factory.h" |
| 15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 18 #include "chrome/test/base/testing_pref_service_syncable.h" | 18 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 19 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
| 20 #include "content/public/browser/navigation_details.h" | 20 #include "content/public/browser/navigation_details.h" |
| 21 #include "content/public/common/frame_navigate_params.h" | 21 #include "content/public/common/frame_navigate_params.h" |
| 22 #include "content/public/test/test_browser_thread.h" | 22 #include "content/public/test/test_browser_thread.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 25 |
| 26 using content::BrowserThread; | |
| 27 using content::PasswordForm; | 26 using content::PasswordForm; |
| 28 using testing::_; | 27 using testing::_; |
| 29 using testing::DoAll; | 28 using testing::DoAll; |
| 30 using ::testing::Exactly; | 29 using testing::Exactly; |
| 31 using ::testing::WithArg; | 30 using testing::Return; |
| 32 using ::testing::Return; | 31 using testing::WithArg; |
| 33 | 32 |
| 34 class MockPasswordManagerDelegate : public PasswordManagerDelegate { | 33 class MockPasswordManagerDelegate : public PasswordManagerDelegate { |
| 35 public: | 34 public: |
| 36 MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&)); | 35 MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&)); |
| 37 MOCK_METHOD1(AddSavePasswordInfoBarIfPermitted, void(PasswordFormManager*)); | 36 MOCK_METHOD1(AddSavePasswordInfoBarIfPermitted, void(PasswordFormManager*)); |
| 38 MOCK_METHOD0(GetProfile, Profile*()); | 37 MOCK_METHOD0(GetProfile, Profile*()); |
| 39 MOCK_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); | 38 MOCK_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); |
| 40 }; | 39 }; |
| 41 | 40 |
| 42 ACTION_P(InvokeConsumer, forms) { | 41 ACTION_P(InvokeConsumer, forms) { |
| 43 arg0->OnGetPasswordStoreResults(forms); | 42 arg0->OnGetPasswordStoreResults(forms); |
| 44 } | 43 } |
| 45 | 44 |
| 46 ACTION_P(SaveToScopedPtr, scoped) { | 45 ACTION_P(SaveToScopedPtr, scoped) { |
| 47 scoped->reset(arg0); | 46 scoped->reset(arg0); |
| 48 } | 47 } |
| 49 | 48 |
| 50 class PasswordManagerTest : public ChromeRenderViewHostTestHarness { | 49 class PasswordManagerTest : public ChromeRenderViewHostTestHarness { |
| 51 public: | |
| 52 PasswordManagerTest() | |
| 53 : ui_thread_(BrowserThread::UI, base::MessageLoopForUI::current()) {} | |
| 54 virtual ~PasswordManagerTest() {} | |
| 55 | |
| 56 protected: | 50 protected: |
| 57 virtual void SetUp() { | 51 virtual void SetUp() { |
| 58 testing_profile_ = new TestingProfile; | 52 testing_profile_ = new TestingProfile; |
| 59 store_ = static_cast<MockPasswordStore*>( | 53 store_ = static_cast<MockPasswordStore*>( |
| 60 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse( | 54 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse( |
| 61 testing_profile_, MockPasswordStore::Build).get()); | 55 testing_profile_, MockPasswordStore::Build).get()); |
| 62 browser_context_.reset(testing_profile_); | 56 browser_context_.reset(testing_profile_); |
| 63 ChromeRenderViewHostTestHarness::SetUp(); | 57 ChromeRenderViewHostTestHarness::SetUp(); |
| 64 | 58 |
| 65 EXPECT_CALL(delegate_, GetProfile()).WillRepeatedly(Return(profile())); | 59 EXPECT_CALL(delegate_, GetProfile()).WillRepeatedly(Return(profile())); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 86 form.password_autocomplete_set = true; | 80 form.password_autocomplete_set = true; |
| 87 form.submit_element = ASCIIToUTF16("signIn"); | 81 form.submit_element = ASCIIToUTF16("signIn"); |
| 88 form.signon_realm = "http://www.google.com"; | 82 form.signon_realm = "http://www.google.com"; |
| 89 return form; | 83 return form; |
| 90 } | 84 } |
| 91 | 85 |
| 92 PasswordManager* manager() { | 86 PasswordManager* manager() { |
| 93 return PasswordManager::FromWebContents(web_contents()); | 87 return PasswordManager::FromWebContents(web_contents()); |
| 94 } | 88 } |
| 95 | 89 |
| 96 // We create a UI thread to satisfy PasswordStore. | |
| 97 content::TestBrowserThread ui_thread_; | |
| 98 | |
| 99 scoped_refptr<MockPasswordStore> store_; | 90 scoped_refptr<MockPasswordStore> store_; |
| 100 MockPasswordManagerDelegate delegate_; // Owned by manager_. | 91 MockPasswordManagerDelegate delegate_; // Owned by manager_. |
| 101 | 92 |
| 102 TestingProfile* testing_profile_; | 93 TestingProfile* testing_profile_; |
| 103 }; | 94 }; |
| 104 | 95 |
| 105 MATCHER_P(FormMatches, form, "") { | 96 MATCHER_P(FormMatches, form, "") { |
| 106 return form.signon_realm == arg.signon_realm && | 97 return form.signon_realm == arg.signon_realm && |
| 107 form.origin == arg.origin && | 98 form.origin == arg.origin && |
| 108 form.action == arg.action && | 99 form.action == arg.action && |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 // navigation occurs. | 474 // navigation occurs. |
| 484 EXPECT_CALL(delegate_, | 475 EXPECT_CALL(delegate_, |
| 485 AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(0)); | 476 AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(0)); |
| 486 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 477 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
| 487 | 478 |
| 488 // Now the password manager waits for the navigation to complete. | 479 // Now the password manager waits for the navigation to complete. |
| 489 observed.clear(); | 480 observed.clear(); |
| 490 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 481 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
| 491 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 482 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. |
| 492 } | 483 } |
| OLD | NEW |