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

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

Issue 2439953004: Remove invalid "suffix" assumption from CreateSortKey (Closed)
Patch Set: Fix typo Created 4 years, 2 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 void PasswordManagerPresenterTest::SortAndCheckPositions( 130 void PasswordManagerPresenterTest::SortAndCheckPositions(
131 const SortEntry test_entries[], 131 const SortEntry test_entries[],
132 size_t number_of_entries, 132 size_t number_of_entries,
133 PasswordEntryType entry_type) { 133 PasswordEntryType entry_type) {
134 std::vector<std::unique_ptr<autofill::PasswordForm>> list; 134 std::vector<std::unique_ptr<autofill::PasswordForm>> list;
135 size_t expected_number_of_unique_entries = 0; 135 size_t expected_number_of_unique_entries = 0;
136 for (size_t i = 0; i < number_of_entries; i++) { 136 for (size_t i = 0; i < number_of_entries; i++) {
137 const SortEntry& entry = test_entries[i]; 137 const SortEntry& entry = test_entries[i];
138 std::unique_ptr<autofill::PasswordForm> form(new autofill::PasswordForm()); 138 std::unique_ptr<autofill::PasswordForm> form(new autofill::PasswordForm());
139 form->signon_realm = entry.origin; 139 form->signon_realm = entry.origin;
140 form->origin = GURL(base::ASCIIToUTF16(entry.origin)); 140 form->origin = GURL(entry.origin);
141 if (entry_type == PasswordEntryType::SAVED) { 141 if (entry_type == PasswordEntryType::SAVED) {
142 form->username_value = base::ASCIIToUTF16(entry.username); 142 form->username_value = base::ASCIIToUTF16(entry.username);
143 form->password_value = base::ASCIIToUTF16(entry.password); 143 form->password_value = base::ASCIIToUTF16(entry.password);
144 if (entry.federation != nullptr) 144 if (entry.federation != nullptr)
145 form->federation_origin = url::Origin(GURL(entry.federation)); 145 form->federation_origin = url::Origin(GURL(entry.federation));
146 } 146 }
147 if (entry.affiliated_web_realm) 147 if (entry.affiliated_web_realm)
148 form->affiliated_web_realm = entry.affiliated_web_realm; 148 form->affiliated_web_realm = entry.affiliated_web_realm;
149 list.push_back(std::move(form)); 149 list.push_back(std::move(form));
150 if (entry.expected_position >= 0) 150 if (entry.expected_position >= 0)
151 expected_number_of_unique_entries++; 151 expected_number_of_unique_entries++;
152 } 152 }
153 153
154 DuplicatesMap duplicates; 154 DuplicatesMap duplicates;
155 mock_controller_->GetPasswordManagerPresenter()->SortEntriesAndHideDuplicates( 155 mock_controller_->GetPasswordManagerPresenter()->SortEntriesAndHideDuplicates(
156 &list, &duplicates, entry_type); 156 &list, &duplicates, entry_type);
157 157
158 ASSERT_EQ(expected_number_of_unique_entries, list.size()); 158 ASSERT_EQ(expected_number_of_unique_entries, list.size());
159 ASSERT_EQ(number_of_entries - expected_number_of_unique_entries, 159 ASSERT_EQ(number_of_entries - expected_number_of_unique_entries,
160 duplicates.size()); 160 duplicates.size());
161 for (size_t i = 0; i < number_of_entries; i++) { 161 for (size_t i = 0; i < number_of_entries; i++) {
162 const SortEntry& entry = test_entries[i]; 162 const SortEntry& entry = test_entries[i];
163 if (entry.expected_position >= 0) { 163 if (entry.expected_position >= 0) {
164 SCOPED_TRACE(testing::Message("position in sorted list: ") 164 SCOPED_TRACE(testing::Message("position in sorted list: ")
165 << entry.expected_position); 165 << entry.expected_position);
166 EXPECT_EQ(GURL(base::ASCIIToUTF16(entry.origin)), 166 EXPECT_EQ(GURL(entry.origin), list[entry.expected_position]->origin);
167 list[entry.expected_position]->origin);
168 if (entry_type == PasswordEntryType::SAVED) { 167 if (entry_type == PasswordEntryType::SAVED) {
169 EXPECT_EQ(base::ASCIIToUTF16(entry.username), 168 EXPECT_EQ(base::ASCIIToUTF16(entry.username),
170 list[entry.expected_position]->username_value); 169 list[entry.expected_position]->username_value);
171 EXPECT_EQ(base::ASCIIToUTF16(entry.password), 170 EXPECT_EQ(base::ASCIIToUTF16(entry.password),
172 list[entry.expected_position]->password_value); 171 list[entry.expected_position]->password_value);
173 if (entry.federation != nullptr) 172 if (entry.federation != nullptr)
174 EXPECT_EQ(url::Origin(GURL(entry.federation)), 173 EXPECT_EQ(url::Origin(GURL(entry.federation)),
175 list[entry.expected_position]->federation_origin); 174 list[entry.expected_position]->federation_origin);
176 } 175 }
177 } 176 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 {"http://example.com", "user_b", "pwd", nullptr, nullptr, 2}, 259 {"http://example.com", "user_b", "pwd", nullptr, nullptr, 2},
261 // Different password. 260 // Different password.
262 {"http://example.com", "user_a", "secret", nullptr, nullptr, 1}, 261 {"http://example.com", "user_a", "secret", nullptr, nullptr, 1},
263 // Different origin. 262 // Different origin.
264 {"http://sub1.example.com", "user_a", "pwd", nullptr, nullptr, 3}, 263 {"http://sub1.example.com", "user_a", "pwd", nullptr, nullptr, 3},
265 {"http://example.com", "user_a", "pwd", nullptr, nullptr, -1} // Hide it. 264 {"http://example.com", "user_a", "pwd", nullptr, nullptr, -1} // Hide it.
266 }; 265 };
267 SortAndCheckPositions(test_cases, arraysize(test_cases), 266 SortAndCheckPositions(test_cases, arraysize(test_cases),
268 PasswordEntryType::SAVED); 267 PasswordEntryType::SAVED);
269 } 268 }
270 269
kolos1 2016/10/24 03:35:35 To be sure we sort subdomains in the right way, pl
vabr (Chromium) 2016/10/24 08:54:02 Done.
271 TEST_F(PasswordManagerPresenterTest, Sorting_PasswordExceptions) { 270 TEST_F(PasswordManagerPresenterTest, Sorting_PasswordExceptions) {
272 const SortEntry test_cases[] = { 271 const SortEntry test_cases[] = {
273 {"http://example-b.com", nullptr, nullptr, nullptr, nullptr, 1}, 272 {"http://example-b.com", nullptr, nullptr, nullptr, nullptr, 1},
274 {"http://example-a.com", nullptr, nullptr, nullptr, nullptr, 0}, 273 {"http://example-a.com", nullptr, nullptr, nullptr, nullptr, 0},
275 {"http://example-a.com", nullptr, nullptr, nullptr, nullptr, 274 {"http://example-a.com", nullptr, nullptr, nullptr, nullptr,
276 -1}, // Hide it. 275 -1}, // Hide it.
277 {"http://example-c.com", nullptr, nullptr, nullptr, nullptr, 2}}; 276 {"http://example-c.com", nullptr, nullptr, nullptr, nullptr, 2}};
278 SortAndCheckPositions(test_cases, arraysize(test_cases), 277 SortAndCheckPositions(test_cases, arraysize(test_cases),
279 PasswordEntryType::BLACKLISTED); 278 PasswordEntryType::BLACKLISTED);
280 } 279 }
(...skipping 17 matching lines...) Expand all
298 TEST_F(PasswordManagerPresenterTest, Sorting_Federations) { 297 TEST_F(PasswordManagerPresenterTest, Sorting_Federations) {
299 const SortEntry test_cases[] = { 298 const SortEntry test_cases[] = {
300 {"https://example.com", "user", "secret", nullptr, nullptr, 0}, 299 {"https://example.com", "user", "secret", nullptr, nullptr, 0},
301 {"https://example.com", "user", "secret", nullptr, "https://fed1.com", 1}, 300 {"https://example.com", "user", "secret", nullptr, "https://fed1.com", 1},
302 {"https://example.com", "user", "secret", nullptr, "https://fed2.com", 301 {"https://example.com", "user", "secret", nullptr, "https://fed2.com",
303 2}}; 302 2}};
304 SortAndCheckPositions(test_cases, arraysize(test_cases), 303 SortAndCheckPositions(test_cases, arraysize(test_cases),
305 PasswordEntryType::SAVED); 304 PasswordEntryType::SAVED);
306 } 305 }
307 306
307 TEST_F(PasswordManagerPresenterTest, Sorting_SpecialCharacters) {
308 // URLs with encoded special characters should not cause crash during sorting.
309 const SortEntry test_cases[] = {
310 {"https://xn--bea5m6d.com/", "user_a", "pwd", nullptr, nullptr, 0},
kolos1 2016/10/24 03:35:35 Does this test cause a crash? Shall we use "žřč.co
vabr (Chromium) 2016/10/24 08:54:02 It does cause crash (without the fix, and on ASAN)
311 };
312 SortAndCheckPositions(test_cases, arraysize(test_cases),
kolos1 2016/10/24 03:35:35 Please add more items to |test_cases| to test if t
vabr (Chromium) 2016/10/24 08:54:02 Done.
313 PasswordEntryType::SAVED);
314 }
315
308 } // namespace 316 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698