Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: chrome/browser/ui/passwords/password_manager_presenter_unittest.cc

Issue 1865213004: Convert //chrome/browser/ui from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/ui/passwords/password_manager_presenter.h" 5 #include "chrome/browser/ui/passwords/password_manager_presenter.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 30 matching lines...) Expand all
41 : profile_(profile), password_manager_presenter_(this) { 41 : profile_(profile), password_manager_presenter_(this) {
42 password_manager_presenter_.Initialize(); 42 password_manager_presenter_.Initialize();
43 } 43 }
44 ~MockPasswordUIView() override {} 44 ~MockPasswordUIView() override {}
45 Profile* GetProfile() override; 45 Profile* GetProfile() override;
46 #if !defined(OS_ANDROID) 46 #if !defined(OS_ANDROID)
47 gfx::NativeWindow GetNativeWindow() const override; 47 gfx::NativeWindow GetNativeWindow() const override;
48 #endif 48 #endif
49 MOCK_METHOD4(ShowPassword, void( 49 MOCK_METHOD4(ShowPassword, void(
50 size_t, const std::string&, const std::string&, const base::string16&)); 50 size_t, const std::string&, const std::string&, const base::string16&));
51 MOCK_METHOD1(SetPasswordList, 51 MOCK_METHOD1(
52 void(const std::vector<scoped_ptr<autofill::PasswordForm>>&)); 52 SetPasswordList,
53 MOCK_METHOD1(SetPasswordExceptionList, 53 void(const std::vector<std::unique_ptr<autofill::PasswordForm>>&));
54 void(const std::vector<scoped_ptr<autofill::PasswordForm>>&)); 54 MOCK_METHOD1(
55 SetPasswordExceptionList,
56 void(const std::vector<std::unique_ptr<autofill::PasswordForm>>&));
55 PasswordManagerPresenter* GetPasswordManagerPresenter() { 57 PasswordManagerPresenter* GetPasswordManagerPresenter() {
56 return &password_manager_presenter_; 58 return &password_manager_presenter_;
57 } 59 }
58 60
59 private: 61 private:
60 Profile* profile_; 62 Profile* profile_;
61 PasswordManagerPresenter password_manager_presenter_; 63 PasswordManagerPresenter password_manager_presenter_;
62 64
63 DISALLOW_COPY_AND_ASSIGN(MockPasswordUIView); 65 DISALLOW_COPY_AND_ASSIGN(MockPasswordUIView);
64 }; 66 };
(...skipping 21 matching lines...) Expand all
86 void AddPasswordException(const GURL& origin); 88 void AddPasswordException(const GURL& origin);
87 void UpdateLists(); 89 void UpdateLists();
88 MockPasswordUIView* GetUIController() { return mock_controller_.get(); } 90 MockPasswordUIView* GetUIController() { return mock_controller_.get(); }
89 void SortAndCheckPositions(const SortEntry test_entries[], 91 void SortAndCheckPositions(const SortEntry test_entries[],
90 size_t number_of_entries, 92 size_t number_of_entries,
91 bool username_and_password_in_key); 93 bool username_and_password_in_key);
92 94
93 private: 95 private:
94 content::TestBrowserThreadBundle thread_bundle_; 96 content::TestBrowserThreadBundle thread_bundle_;
95 TestingProfile profile_; 97 TestingProfile profile_;
96 scoped_ptr<MockPasswordUIView> mock_controller_; 98 std::unique_ptr<MockPasswordUIView> mock_controller_;
97 99
98 DISALLOW_COPY_AND_ASSIGN(PasswordManagerPresenterTest); 100 DISALLOW_COPY_AND_ASSIGN(PasswordManagerPresenterTest);
99 }; 101 };
100 102
101 void PasswordManagerPresenterTest::AddPasswordEntry( 103 void PasswordManagerPresenterTest::AddPasswordEntry(
102 const GURL& origin, 104 const GURL& origin,
103 const std::string& user_name, 105 const std::string& user_name,
104 const std::string& password) { 106 const std::string& password) {
105 scoped_ptr<autofill::PasswordForm> form(new autofill::PasswordForm()); 107 std::unique_ptr<autofill::PasswordForm> form(new autofill::PasswordForm());
106 form->origin = origin; 108 form->origin = origin;
107 form->username_element = base::ASCIIToUTF16("Email"); 109 form->username_element = base::ASCIIToUTF16("Email");
108 form->username_value = base::ASCIIToUTF16(user_name); 110 form->username_value = base::ASCIIToUTF16(user_name);
109 form->password_element = base::ASCIIToUTF16("Passwd"); 111 form->password_element = base::ASCIIToUTF16("Passwd");
110 form->password_value = base::ASCIIToUTF16(password); 112 form->password_value = base::ASCIIToUTF16(password);
111 mock_controller_->GetPasswordManagerPresenter()->password_list_.push_back( 113 mock_controller_->GetPasswordManagerPresenter()->password_list_.push_back(
112 std::move(form)); 114 std::move(form));
113 } 115 }
114 116
115 void PasswordManagerPresenterTest::AddPasswordException(const GURL& origin) { 117 void PasswordManagerPresenterTest::AddPasswordException(const GURL& origin) {
116 scoped_ptr<autofill::PasswordForm> form(new autofill::PasswordForm()); 118 std::unique_ptr<autofill::PasswordForm> form(new autofill::PasswordForm());
117 form->origin = origin; 119 form->origin = origin;
118 mock_controller_->GetPasswordManagerPresenter() 120 mock_controller_->GetPasswordManagerPresenter()
119 ->password_exception_list_.push_back(std::move(form)); 121 ->password_exception_list_.push_back(std::move(form));
120 } 122 }
121 123
122 void PasswordManagerPresenterTest::UpdateLists() { 124 void PasswordManagerPresenterTest::UpdateLists() {
123 mock_controller_->GetPasswordManagerPresenter()->SetPasswordList(); 125 mock_controller_->GetPasswordManagerPresenter()->SetPasswordList();
124 mock_controller_->GetPasswordManagerPresenter()->SetPasswordExceptionList(); 126 mock_controller_->GetPasswordManagerPresenter()->SetPasswordExceptionList();
125 } 127 }
126 128
127 void PasswordManagerPresenterTest::SortAndCheckPositions( 129 void PasswordManagerPresenterTest::SortAndCheckPositions(
128 const SortEntry test_entries[], 130 const SortEntry test_entries[],
129 size_t number_of_entries, 131 size_t number_of_entries,
130 bool username_and_password_in_key) { 132 bool username_and_password_in_key) {
131 std::vector<scoped_ptr<autofill::PasswordForm>> list; 133 std::vector<std::unique_ptr<autofill::PasswordForm>> list;
132 size_t expected_number_of_unique_entries = 0; 134 size_t expected_number_of_unique_entries = 0;
133 for (size_t i = 0; i < number_of_entries; i++) { 135 for (size_t i = 0; i < number_of_entries; i++) {
134 const SortEntry& entry = test_entries[i]; 136 const SortEntry& entry = test_entries[i];
135 scoped_ptr<autofill::PasswordForm> form(new autofill::PasswordForm()); 137 std::unique_ptr<autofill::PasswordForm> form(new autofill::PasswordForm());
136 form->signon_realm = entry.origin; 138 form->signon_realm = entry.origin;
137 form->origin = GURL(base::ASCIIToUTF16(entry.origin)); 139 form->origin = GURL(base::ASCIIToUTF16(entry.origin));
138 if (username_and_password_in_key) { 140 if (username_and_password_in_key) {
139 form->username_value = base::ASCIIToUTF16(entry.username); 141 form->username_value = base::ASCIIToUTF16(entry.username);
140 form->password_value = base::ASCIIToUTF16(entry.password); 142 form->password_value = base::ASCIIToUTF16(entry.password);
141 } 143 }
142 if (entry.affiliated_web_realm) 144 if (entry.affiliated_web_realm)
143 form->affiliated_web_realm = entry.affiliated_web_realm; 145 form->affiliated_web_realm = entry.affiliated_web_realm;
144 list.push_back(std::move(form)); 146 list.push_back(std::move(form));
145 if (entry.expected_position >= 0) 147 if (entry.expected_position >= 0)
(...skipping 20 matching lines...) Expand all
166 EXPECT_EQ(base::ASCIIToUTF16(entry.password), 168 EXPECT_EQ(base::ASCIIToUTF16(entry.password),
167 list[entry.expected_position]->password_value); 169 list[entry.expected_position]->password_value);
168 } 170 }
169 } 171 }
170 } 172 }
171 } 173 }
172 174
173 namespace { 175 namespace {
174 176
175 TEST_F(PasswordManagerPresenterTest, UIControllerIsCalled) { 177 TEST_F(PasswordManagerPresenterTest, UIControllerIsCalled) {
176 EXPECT_CALL( 178 EXPECT_CALL(*GetUIController(),
177 *GetUIController(), 179 SetPasswordList(Property(
178 SetPasswordList(Property( 180 &std::vector<std::unique_ptr<autofill::PasswordForm>>::size,
179 &std::vector<scoped_ptr<autofill::PasswordForm>>::size, Eq(0u)))); 181 Eq(0u))));
180 EXPECT_CALL( 182 EXPECT_CALL(*GetUIController(),
181 *GetUIController(), 183 SetPasswordExceptionList(Property(
182 SetPasswordExceptionList(Property( 184 &std::vector<std::unique_ptr<autofill::PasswordForm>>::size,
183 &std::vector<scoped_ptr<autofill::PasswordForm>>::size, Eq(0u)))); 185 Eq(0u))));
184 UpdateLists(); 186 UpdateLists();
185 GURL pass_origin("http://abc1.com"); 187 GURL pass_origin("http://abc1.com");
186 AddPasswordEntry(pass_origin, "test@gmail.com", "test"); 188 AddPasswordEntry(pass_origin, "test@gmail.com", "test");
187 EXPECT_CALL( 189 EXPECT_CALL(*GetUIController(),
188 *GetUIController(), 190 SetPasswordList(Property(
189 SetPasswordList(Property( 191 &std::vector<std::unique_ptr<autofill::PasswordForm>>::size,
190 &std::vector<scoped_ptr<autofill::PasswordForm>>::size, Eq(1u)))); 192 Eq(1u))));
191 EXPECT_CALL( 193 EXPECT_CALL(*GetUIController(),
192 *GetUIController(), 194 SetPasswordExceptionList(Property(
193 SetPasswordExceptionList(Property( 195 &std::vector<std::unique_ptr<autofill::PasswordForm>>::size,
194 &std::vector<scoped_ptr<autofill::PasswordForm>>::size, Eq(0u)))); 196 Eq(0u))));
195 UpdateLists(); 197 UpdateLists();
196 GURL except_origin("http://abc2.com"); 198 GURL except_origin("http://abc2.com");
197 AddPasswordException(except_origin); 199 AddPasswordException(except_origin);
198 EXPECT_CALL( 200 EXPECT_CALL(*GetUIController(),
199 *GetUIController(), 201 SetPasswordList(Property(
200 SetPasswordList(Property( 202 &std::vector<std::unique_ptr<autofill::PasswordForm>>::size,
201 &std::vector<scoped_ptr<autofill::PasswordForm>>::size, Eq(1u)))); 203 Eq(1u))));
202 EXPECT_CALL( 204 EXPECT_CALL(*GetUIController(),
203 *GetUIController(), 205 SetPasswordExceptionList(Property(
204 SetPasswordExceptionList(Property( 206 &std::vector<std::unique_ptr<autofill::PasswordForm>>::size,
205 &std::vector<scoped_ptr<autofill::PasswordForm>>::size, Eq(1u)))); 207 Eq(1u))));
206 UpdateLists(); 208 UpdateLists();
207 GURL pass_origin2("http://example.com"); 209 GURL pass_origin2("http://example.com");
208 AddPasswordEntry(pass_origin2, "test@gmail.com", "test"); 210 AddPasswordEntry(pass_origin2, "test@gmail.com", "test");
209 EXPECT_CALL( 211 EXPECT_CALL(*GetUIController(),
210 *GetUIController(), 212 SetPasswordList(Property(
211 SetPasswordList(Property( 213 &std::vector<std::unique_ptr<autofill::PasswordForm>>::size,
212 &std::vector<scoped_ptr<autofill::PasswordForm>>::size, Eq(2u)))); 214 Eq(2u))));
213 EXPECT_CALL( 215 EXPECT_CALL(*GetUIController(),
214 *GetUIController(), 216 SetPasswordExceptionList(Property(
215 SetPasswordExceptionList(Property( 217 &std::vector<std::unique_ptr<autofill::PasswordForm>>::size,
216 &std::vector<scoped_ptr<autofill::PasswordForm>>::size, Eq(1u)))); 218 Eq(1u))));
217 UpdateLists(); 219 UpdateLists();
218 } 220 }
219 221
220 TEST_F(PasswordManagerPresenterTest, Sorting_DifferentOrigins) { 222 TEST_F(PasswordManagerPresenterTest, Sorting_DifferentOrigins) {
221 const SortEntry test_cases[] = { 223 const SortEntry test_cases[] = {
222 {"http://example-b.com", "user_a", "pwd", nullptr, 2}, 224 {"http://example-b.com", "user_a", "pwd", nullptr, 2},
223 {"http://example-a.com", "user_a1", "pwd", nullptr, 0}, 225 {"http://example-a.com", "user_a1", "pwd", nullptr, 0},
224 {"http://example-a.com", "user_a2", "pwd", nullptr, 1}, 226 {"http://example-a.com", "user_a2", "pwd", nullptr, 1},
225 {"http://example-c.com", "user_a", "pwd", nullptr, 3}}; 227 {"http://example-c.com", "user_a", "pwd", nullptr, 3}};
226 SortAndCheckPositions(test_cases, arraysize(test_cases), true); 228 SortAndCheckPositions(test_cases, arraysize(test_cases), true);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 {"android://hash@com.alpha", "user", "secret", "https://alpha.com", -1}, 274 {"android://hash@com.alpha", "user", "secret", "https://alpha.com", -1},
273 {"android://hash@com.alpha", "user", "secret", nullptr, 2}, 275 {"android://hash@com.alpha", "user", "secret", nullptr, 2},
274 276
275 {"android://hash@com.betta.android", "user", "secret", 277 {"android://hash@com.betta.android", "user", "secret",
276 "https://betta.com", 3}, 278 "https://betta.com", 3},
277 {"android://hash@com.betta.android", "user", "secret", nullptr, 4}}; 279 {"android://hash@com.betta.android", "user", "secret", nullptr, 4}};
278 SortAndCheckPositions(test_cases, arraysize(test_cases), true); 280 SortAndCheckPositions(test_cases, arraysize(test_cases), true);
279 } 281 }
280 282
281 } // namespace 283 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/passwords/password_manager_presenter.cc ('k') | chrome/browser/ui/passwords/password_ui_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698