Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| 270 TEST_F(PasswordManagerPresenterTest, Sorting_Subdomains) { | |
| 271 const SortEntry test_cases[] = { | |
| 272 {"http://example.com", "u", "p", nullptr, nullptr, 0}, | |
| 273 {"http://b.example.com", "u", "p", nullptr, nullptr, 6}, | |
| 274 {"http://a.example.com", "u", "p", nullptr, nullptr, 1}, | |
| 275 {"http://1.a.example.com", "u", "p", nullptr, nullptr, 2}, | |
| 276 {"http://2.a.example.com", "u", "p", nullptr, nullptr, 3}, | |
| 277 {"http://x.2.a.example.com", "u", "p", nullptr, nullptr, 4}, | |
| 278 {"http://y.2.a.example.com", "u", "p", nullptr, nullptr, 5}, | |
| 279 }; | |
| 280 SortAndCheckPositions(test_cases, arraysize(test_cases), | |
| 281 PasswordEntryType::SAVED); | |
| 282 } | |
| 283 | |
| 271 TEST_F(PasswordManagerPresenterTest, Sorting_PasswordExceptions) { | 284 TEST_F(PasswordManagerPresenterTest, Sorting_PasswordExceptions) { |
| 272 const SortEntry test_cases[] = { | 285 const SortEntry test_cases[] = { |
| 273 {"http://example-b.com", nullptr, nullptr, nullptr, nullptr, 1}, | 286 {"http://example-b.com", nullptr, nullptr, nullptr, nullptr, 1}, |
| 274 {"http://example-a.com", nullptr, nullptr, nullptr, nullptr, 0}, | 287 {"http://example-a.com", nullptr, nullptr, nullptr, nullptr, 0}, |
| 275 {"http://example-a.com", nullptr, nullptr, nullptr, nullptr, | 288 {"http://example-a.com", nullptr, nullptr, nullptr, nullptr, |
| 276 -1}, // Hide it. | 289 -1}, // Hide it. |
| 277 {"http://example-c.com", nullptr, nullptr, nullptr, nullptr, 2}}; | 290 {"http://example-c.com", nullptr, nullptr, nullptr, nullptr, 2}}; |
| 278 SortAndCheckPositions(test_cases, arraysize(test_cases), | 291 SortAndCheckPositions(test_cases, arraysize(test_cases), |
| 279 PasswordEntryType::BLACKLISTED); | 292 PasswordEntryType::BLACKLISTED); |
| 280 } | 293 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 298 TEST_F(PasswordManagerPresenterTest, Sorting_Federations) { | 311 TEST_F(PasswordManagerPresenterTest, Sorting_Federations) { |
| 299 const SortEntry test_cases[] = { | 312 const SortEntry test_cases[] = { |
| 300 {"https://example.com", "user", "secret", nullptr, nullptr, 0}, | 313 {"https://example.com", "user", "secret", nullptr, nullptr, 0}, |
| 301 {"https://example.com", "user", "secret", nullptr, "https://fed1.com", 1}, | 314 {"https://example.com", "user", "secret", nullptr, "https://fed1.com", 1}, |
| 302 {"https://example.com", "user", "secret", nullptr, "https://fed2.com", | 315 {"https://example.com", "user", "secret", nullptr, "https://fed2.com", |
| 303 2}}; | 316 2}}; |
| 304 SortAndCheckPositions(test_cases, arraysize(test_cases), | 317 SortAndCheckPositions(test_cases, arraysize(test_cases), |
| 305 PasswordEntryType::SAVED); | 318 PasswordEntryType::SAVED); |
| 306 } | 319 } |
| 307 | 320 |
| 321 TEST_F(PasswordManagerPresenterTest, Sorting_SpecialCharacters) { | |
| 322 // URLs with encoded special characters should not cause crash during sorting. | |
| 323 LOG(INFO) << GURL("http://abč.com"); | |
|
kolos1
2016/11/15 12:50:53
Hi Vaclav,
Is it your intention to output these U
vabr (Chromium)
2016/11/15 17:55:20
Oops, definitely unintentional. Thanks for spottin
| |
| 324 LOG(INFO) << GURL("http://abc.com"); | |
| 325 LOG(INFO) << GURL("http://ábc.com"); | |
| 326 LOG(INFO) << GURL("http://uoy.com"); | |
| 327 LOG(INFO) << GURL("http://üöÿ.com"); | |
| 328 LOG(INFO) << GURL("http://zrc.com"); | |
| 329 LOG(INFO) << GURL("http://žřč.com"); | |
| 330 const SortEntry test_cases[] = { | |
| 331 {"https://xn--bea5m6d.com/", "user_a", "pwd", nullptr, nullptr, 4}, | |
| 332 {"https://uoy.com/", "user_a", "pwd", nullptr, nullptr, 1}, | |
| 333 {"https://zrc.com/", "user_a", "pwd", nullptr, nullptr, 6}, | |
| 334 {"https://abc.com/", "user_a", "pwd", nullptr, nullptr, 0}, | |
| 335 {"https://xn--ab-fma.com/", "user_a", "pwd", nullptr, nullptr, 2}, | |
| 336 {"https://xn--bc-lia.com/", "user_a", "pwd", nullptr, nullptr, 3}, | |
| 337 {"https://xn--ndalk.com/", "user_a", "pwd", nullptr, nullptr, 5}, | |
| 338 }; | |
| 339 SortAndCheckPositions(test_cases, arraysize(test_cases), | |
| 340 PasswordEntryType::SAVED); | |
| 341 } | |
| 342 | |
| 308 } // namespace | 343 } // namespace |
| OLD | NEW |