| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <stdarg.h> | 5 #include <stdarg.h> |
| 6 #include <stddef.h> | 6 #include <stddef.h> |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/test/scoped_task_environment.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 19 #include "chrome/browser/password_manager/native_backend_libsecret.h" | 20 #include "chrome/browser/password_manager/native_backend_libsecret.h" |
| 20 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
| 21 #include "components/autofill/core/common/password_form.h" | 22 #include "components/autofill/core/common/password_form.h" |
| 22 #include "components/password_manager/core/browser/psl_matching_helper.h" | 23 #include "components/password_manager/core/browser/psl_matching_helper.h" |
| 23 #include "components/password_manager/core/common/password_manager_pref_names.h" | 24 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 24 #include "components/prefs/pref_service.h" | 25 #include "components/prefs/pref_service.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 protected: | 267 protected: |
| 267 enum UpdateType { // Used in CheckPSLUpdate(). | 268 enum UpdateType { // Used in CheckPSLUpdate(). |
| 268 UPDATE_BY_UPDATELOGIN, | 269 UPDATE_BY_UPDATELOGIN, |
| 269 UPDATE_BY_ADDLOGIN, | 270 UPDATE_BY_ADDLOGIN, |
| 270 }; | 271 }; |
| 271 enum RemoveBetweenMethod { // Used in CheckRemoveLoginsBetween(). | 272 enum RemoveBetweenMethod { // Used in CheckRemoveLoginsBetween(). |
| 272 CREATED, | 273 CREATED, |
| 273 SYNCED, | 274 SYNCED, |
| 274 }; | 275 }; |
| 275 | 276 |
| 276 NativeBackendLibsecretTest() {} | 277 NativeBackendLibsecretTest() |
| 278 : scoped_task_environment_( |
| 279 base::test::ScopedTaskEnvironment::MainThreadType::UI) {} |
| 277 | 280 |
| 278 void SetUp() override { | 281 void SetUp() override { |
| 279 ASSERT_FALSE(global_mock_libsecret_items); | 282 ASSERT_FALSE(global_mock_libsecret_items); |
| 280 global_mock_libsecret_items = &mock_libsecret_items_; | 283 global_mock_libsecret_items = &mock_libsecret_items_; |
| 281 | 284 |
| 282 ASSERT_TRUE(MockLibsecretLoader::LoadMockLibsecret()); | 285 ASSERT_TRUE(MockLibsecretLoader::LoadMockLibsecret()); |
| 283 | 286 |
| 284 form_google_.origin = GURL("http://www.google.com/"); | 287 form_google_.origin = GURL("http://www.google.com/"); |
| 285 form_google_.action = GURL("http://www.google.com/login"); | 288 form_google_.action = GURL("http://www.google.com/login"); |
| 286 form_google_.username_element = UTF8ToUTF16("user"); | 289 form_google_.username_element = UTF8ToUTF16("user"); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 expected_changes.push_back( | 594 expected_changes.push_back( |
| 592 PasswordStoreChange(PasswordStoreChange::REMOVE, form_isc_)); | 595 PasswordStoreChange(PasswordStoreChange::REMOVE, form_isc_)); |
| 593 | 596 |
| 594 EXPECT_TRUE(base::Bind(method, base::Unretained(&backend), next_day, | 597 EXPECT_TRUE(base::Bind(method, base::Unretained(&backend), next_day, |
| 595 base::Time(), &changes).Run()); | 598 base::Time(), &changes).Run()); |
| 596 CheckPasswordChanges(expected_changes, changes); | 599 CheckPasswordChanges(expected_changes, changes); |
| 597 | 600 |
| 598 EXPECT_TRUE(global_mock_libsecret_items->empty()); | 601 EXPECT_TRUE(global_mock_libsecret_items->empty()); |
| 599 } | 602 } |
| 600 | 603 |
| 601 base::MessageLoopForUI message_loop_; | 604 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 602 | 605 |
| 603 // Provide some test forms to avoid having to set them up in each test. | 606 // Provide some test forms to avoid having to set them up in each test. |
| 604 PasswordForm form_google_; | 607 PasswordForm form_google_; |
| 605 PasswordForm form_facebook_; | 608 PasswordForm form_facebook_; |
| 606 PasswordForm form_isc_; | 609 PasswordForm form_isc_; |
| 607 PasswordForm other_auth_; | 610 PasswordForm other_auth_; |
| 608 | 611 |
| 609 std::vector<std::unique_ptr<MockSecretItem>> mock_libsecret_items_; | 612 std::vector<std::unique_ptr<MockSecretItem>> mock_libsecret_items_; |
| 610 }; | 613 }; |
| 611 | 614 |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 EXPECT_EQ(form_google_, *form_list[0]); | 1017 EXPECT_EQ(form_google_, *form_list[0]); |
| 1015 | 1018 |
| 1016 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 1019 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 1017 if (!global_mock_libsecret_items->empty()) { | 1020 if (!global_mock_libsecret_items->empty()) { |
| 1018 CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_, | 1021 CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_, |
| 1019 "chrome-42"); | 1022 "chrome-42"); |
| 1020 } | 1023 } |
| 1021 } | 1024 } |
| 1022 | 1025 |
| 1023 // TODO(mdm): add more basic tests here at some point. | 1026 // TODO(mdm): add more basic tests here at some point. |
| OLD | NEW |