Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/strings/utf_string_conversions.h" | |
| 6 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" | |
| 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
| 8 #include "components/autofill/core/common/password_form.h" | |
| 9 #include "components/password_manager/core/browser/password_form_manager.h" | |
| 10 #include "components/password_manager/core/browser/password_manager_client.h" | |
| 11 #include "components/password_manager/core/browser/stub_password_manager_client. h" | |
| 12 #include "testing/gmock/include/gmock/gmock.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 class MockPasswordFormManager : public password_manager::PasswordFormManager { | |
| 16 public: | |
| 17 MOCK_METHOD0(PermanentlyBlacklist, void()); | |
| 18 | |
| 19 MockPasswordFormManager(password_manager::StubPasswordManagerClient* client, | |
| 20 autofill::PasswordForm form) | |
|
vabr (Chromium)
2015/04/02 13:32:17
const autofill::PasswordForm& ?
melandory
2015/04/02 15:49:17
Done.
| |
| 21 : PasswordFormManager( | |
| 22 nullptr, | |
| 23 client, | |
| 24 base::WeakPtr<password_manager::PasswordManagerDriver>(), | |
| 25 form, | |
| 26 false) {} | |
| 27 | |
| 28 ~MockPasswordFormManager() override {} | |
| 29 | |
| 30 private: | |
|
vabr (Chromium)
2015/04/02 13:32:17
Did you mean to add DISALLOW_COPY_AND_ASSIGN in th
melandory
2015/04/02 15:49:17
Done.
| |
| 31 }; | |
| 32 | |
| 33 class SaveInfoBarDelegateTest : public ChromeRenderViewHostTestHarness { | |
| 34 public: | |
| 35 SaveInfoBarDelegateTest(); | |
| 36 ~SaveInfoBarDelegateTest() override{}; | |
| 37 | |
| 38 void SetUp() override; | |
| 39 void TearDown() override; | |
| 40 | |
| 41 autofill::PasswordForm test_form() { return test_form_; } | |
|
vabr (Chromium)
2015/04/02 13:32:16
Please make this return a const ref instead of the
melandory
2015/04/02 15:49:17
Done.
| |
| 42 | |
| 43 protected: | |
| 44 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( | |
| 45 password_manager::CredentialSourceType type); | |
| 46 | |
| 47 password_manager::StubPasswordManagerClient client_; | |
| 48 scoped_ptr<MockPasswordFormManager> password_form_manager_; | |
| 49 autofill::PasswordForm test_form_; | |
| 50 | |
| 51 private: | |
| 52 DISALLOW_COPY_AND_ASSIGN(SaveInfoBarDelegateTest); | |
| 53 }; | |
| 54 | |
| 55 SaveInfoBarDelegateTest::SaveInfoBarDelegateTest() { | |
| 56 test_form_.origin = GURL("http://example.com"); | |
| 57 test_form_.username_value = base::ASCIIToUTF16("username"); | |
| 58 test_form_.password_value = base::ASCIIToUTF16("12345"); | |
| 59 } | |
| 60 | |
| 61 scoped_ptr<ConfirmInfoBarDelegate> SaveInfoBarDelegateTest::CreateDelegate( | |
| 62 password_manager::CredentialSourceType type) { | |
| 63 scoped_ptr<ConfirmInfoBarDelegate> delegate( | |
| 64 SavePasswordInfoBarDelegate::Create(password_form_manager_.Pass(), "", | |
| 65 type)); | |
| 66 return delegate.Pass(); | |
| 67 } | |
| 68 | |
| 69 void SaveInfoBarDelegateTest::SetUp() { | |
| 70 ChromeRenderViewHostTestHarness::SetUp(); | |
| 71 password_form_manager_.reset( | |
|
vabr (Chromium)
2015/04/02 13:32:17
Instead of keeping this as a member variable, plea
melandory
2015/04/02 15:49:17
I've created helper function which returns raw poi
| |
| 72 new MockPasswordFormManager(&client_, test_form())); | |
| 73 } | |
| 74 | |
| 75 void SaveInfoBarDelegateTest::TearDown() { | |
| 76 ChromeRenderViewHostTestHarness::TearDown(); | |
| 77 } | |
| 78 | |
| 79 TEST_F(SaveInfoBarDelegateTest, CancelTestCredentialSourceAPI) { | |
| 80 MockPasswordFormManager* password_form_manager = password_form_manager_.get(); | |
| 81 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( | |
| 82 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API)); | |
| 83 EXPECT_CALL(*password_form_manager, PermanentlyBlacklist()) | |
| 84 .Times(testing::Exactly(0)); | |
| 85 EXPECT_TRUE(infobar->Cancel()); | |
| 86 } | |
| 87 | |
| 88 TEST_F(SaveInfoBarDelegateTest, CancelTestCredentialSourcePasswordManager) { | |
| 89 MockPasswordFormManager* password_form_manager = password_form_manager_.get(); | |
| 90 scoped_ptr<ConfirmInfoBarDelegate> infobar( | |
| 91 CreateDelegate(password_manager::CredentialSourceType:: | |
| 92 CREDENTIAL_SOURCE_PASSWORD_MANAGER)); | |
| 93 EXPECT_CALL(*password_form_manager, PermanentlyBlacklist()) | |
| 94 .Times(testing::Exactly(1)); | |
| 95 EXPECT_TRUE(infobar->Cancel()); | |
| 96 } | |
| OLD | NEW |