OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" | 6 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" |
7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
8 #include "components/autofill/core/common/password_form.h" | 8 #include "components/autofill/core/common/password_form.h" |
9 #include "components/password_manager/core/browser/password_form_manager.h" | 9 #include "components/password_manager/core/browser/password_form_manager.h" |
10 #include "components/password_manager/core/browser/password_manager_client.h" | 10 #include "components/password_manager/core/browser/password_manager_client.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 class SavePasswordInfoBarDelegateTest : public ChromeRenderViewHostTestHarness { | 48 class SavePasswordInfoBarDelegateTest : public ChromeRenderViewHostTestHarness { |
49 public: | 49 public: |
50 SavePasswordInfoBarDelegateTest(); | 50 SavePasswordInfoBarDelegateTest(); |
51 ~SavePasswordInfoBarDelegateTest() override{}; | 51 ~SavePasswordInfoBarDelegateTest() override{}; |
52 | 52 |
53 void SetUp() override; | 53 void SetUp() override; |
54 void TearDown() override; | 54 void TearDown() override; |
55 | 55 |
56 const autofill::PasswordForm& test_form() { return test_form_; } | 56 const autofill::PasswordForm& test_form() { return test_form_; } |
57 MockPasswordFormManager* CreateMockFormManager(); | 57 scoped_ptr<MockPasswordFormManager> CreateMockFormManager(); |
58 | 58 |
59 protected: | 59 protected: |
60 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( | 60 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( |
61 MockPasswordFormManager* password_form_manager, | 61 scoped_ptr<password_manager::PasswordFormManager> password_form_manager, |
62 password_manager::CredentialSourceType type); | 62 password_manager::CredentialSourceType type); |
63 | 63 |
64 password_manager::StubPasswordManagerClient client_; | 64 password_manager::StubPasswordManagerClient client_; |
65 autofill::PasswordForm test_form_; | 65 autofill::PasswordForm test_form_; |
66 | 66 |
67 private: | 67 private: |
68 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegateTest); | 68 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegateTest); |
69 }; | 69 }; |
70 | 70 |
71 SavePasswordInfoBarDelegateTest::SavePasswordInfoBarDelegateTest() { | 71 SavePasswordInfoBarDelegateTest::SavePasswordInfoBarDelegateTest() { |
72 test_form_.origin = GURL("http://example.com"); | 72 test_form_.origin = GURL("http://example.com"); |
73 test_form_.username_value = base::ASCIIToUTF16("username"); | 73 test_form_.username_value = base::ASCIIToUTF16("username"); |
74 test_form_.password_value = base::ASCIIToUTF16("12345"); | 74 test_form_.password_value = base::ASCIIToUTF16("12345"); |
75 } | 75 } |
76 | 76 |
77 MockPasswordFormManager* | 77 scoped_ptr<MockPasswordFormManager> |
78 SavePasswordInfoBarDelegateTest::CreateMockFormManager() { | 78 SavePasswordInfoBarDelegateTest::CreateMockFormManager() { |
79 return new MockPasswordFormManager(&client_, test_form()); | 79 return scoped_ptr<MockPasswordFormManager>( |
| 80 new MockPasswordFormManager(&client_, test_form())); |
80 } | 81 } |
81 | 82 |
82 scoped_ptr<ConfirmInfoBarDelegate> | 83 scoped_ptr<ConfirmInfoBarDelegate> |
83 SavePasswordInfoBarDelegateTest::CreateDelegate( | 84 SavePasswordInfoBarDelegateTest::CreateDelegate( |
84 MockPasswordFormManager* password_form_manager, | 85 scoped_ptr<password_manager::PasswordFormManager> password_form_manager, |
85 password_manager::CredentialSourceType type) { | 86 password_manager::CredentialSourceType type) { |
86 scoped_ptr<ConfirmInfoBarDelegate> delegate( | 87 scoped_ptr<ConfirmInfoBarDelegate> delegate( |
87 new TestSavePasswordInfobarDelegate( | 88 new TestSavePasswordInfobarDelegate(password_form_manager.Pass(), type)); |
88 scoped_ptr<password_manager::PasswordFormManager>( | |
89 password_form_manager), | |
90 type)); | |
91 return delegate.Pass(); | 89 return delegate.Pass(); |
92 } | 90 } |
93 | 91 |
94 void SavePasswordInfoBarDelegateTest::SetUp() { | 92 void SavePasswordInfoBarDelegateTest::SetUp() { |
95 ChromeRenderViewHostTestHarness::SetUp(); | 93 ChromeRenderViewHostTestHarness::SetUp(); |
96 } | 94 } |
97 | 95 |
98 void SavePasswordInfoBarDelegateTest::TearDown() { | 96 void SavePasswordInfoBarDelegateTest::TearDown() { |
99 ChromeRenderViewHostTestHarness::TearDown(); | 97 ChromeRenderViewHostTestHarness::TearDown(); |
100 } | 98 } |
101 | 99 |
102 TEST_F(SavePasswordInfoBarDelegateTest, CancelTestCredentialSourceAPI) { | 100 TEST_F(SavePasswordInfoBarDelegateTest, CancelTestCredentialSourceAPI) { |
103 // SavePasswordInfoBarDelegate::Create takes ownership of | 101 scoped_ptr<MockPasswordFormManager> password_form_manager( |
104 // password_form_manager_ptr; | 102 CreateMockFormManager()); |
105 MockPasswordFormManager* password_form_manager_ptr = CreateMockFormManager(); | 103 EXPECT_CALL(*password_form_manager.get(), PermanentlyBlacklist()) |
| 104 .Times(testing::Exactly(0)); |
106 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( | 105 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
107 password_form_manager_ptr, | 106 password_form_manager.Pass(), |
108 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API)); | 107 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API)); |
109 EXPECT_CALL(*password_form_manager_ptr, PermanentlyBlacklist()) | |
110 .Times(testing::Exactly(0)); | |
111 EXPECT_TRUE(infobar->Cancel()); | 108 EXPECT_TRUE(infobar->Cancel()); |
112 } | 109 } |
113 | 110 |
114 TEST_F(SavePasswordInfoBarDelegateTest, | 111 TEST_F(SavePasswordInfoBarDelegateTest, |
115 CancelTestCredentialSourcePasswordManager) { | 112 CancelTestCredentialSourcePasswordManager) { |
116 // SavePasswordInfoBarDelegate::Create takes ownership of | 113 scoped_ptr<MockPasswordFormManager> password_form_manager( |
117 // password_form_manager_ptr; | 114 CreateMockFormManager()); |
118 MockPasswordFormManager* password_form_manager_ptr = CreateMockFormManager(); | 115 EXPECT_CALL(*password_form_manager.get(), PermanentlyBlacklist()) |
| 116 .Times(testing::Exactly(1)); |
119 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( | 117 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
120 password_form_manager_ptr, password_manager::CredentialSourceType:: | 118 password_form_manager.Pass(), password_manager::CredentialSourceType:: |
121 CREDENTIAL_SOURCE_PASSWORD_MANAGER)); | 119 CREDENTIAL_SOURCE_PASSWORD_MANAGER)); |
122 EXPECT_CALL(*password_form_manager_ptr, PermanentlyBlacklist()) | |
123 .Times(testing::Exactly(1)); | |
124 EXPECT_TRUE(infobar->Cancel()); | 120 EXPECT_TRUE(infobar->Cancel()); |
125 } | 121 } |
OLD | NEW |