| 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 "components/autofill/core/browser/personal_data_manager.h" | 5 #include "components/autofill/core/browser/personal_data_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <list> |
| 11 #include <map> |
| 10 #include <memory> | 12 #include <memory> |
| 11 #include <string> | 13 #include <string> |
| 12 #include <vector> | 14 #include <vector> |
| 13 | 15 |
| 14 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 15 #include "base/files/scoped_temp_dir.h" | 17 #include "base/files/scoped_temp_dir.h" |
| 16 #include "base/guid.h" | 18 #include "base/guid.h" |
| 17 #include "base/metrics/field_trial.h" | 19 #include "base/metrics/field_trial.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/synchronization/waitable_event.h" | 21 #include "base/synchronization/waitable_event.h" |
| 20 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 21 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 22 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 23 #include "components/autofill/core/browser/autofill_experiments.h" | 25 #include "components/autofill/core/browser/autofill_experiments.h" |
| 24 #include "components/autofill/core/browser/autofill_profile.h" | 26 #include "components/autofill/core/browser/autofill_profile.h" |
| 25 #include "components/autofill/core/browser/autofill_test_utils.h" | 27 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 26 #include "components/autofill/core/browser/field_types.h" | 28 #include "components/autofill/core/browser/field_types.h" |
| 27 #include "components/autofill/core/browser/form_structure.h" | 29 #include "components/autofill/core/browser/form_structure.h" |
| 28 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 30 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
| 29 #include "components/autofill/core/browser/webdata/autofill_table.h" | 31 #include "components/autofill/core/browser/webdata/autofill_table.h" |
| 30 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 32 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
| 31 #include "components/autofill/core/common/autofill_constants.h" | 33 #include "components/autofill/core/common/autofill_constants.h" |
| 32 #include "components/autofill/core/common/autofill_pref_names.h" | 34 #include "components/autofill/core/common/autofill_pref_names.h" |
| 33 #include "components/autofill/core/common/autofill_switches.h" | 35 #include "components/autofill/core/common/autofill_switches.h" |
| 34 #include "components/autofill/core/common/form_data.h" | 36 #include "components/autofill/core/common/form_data.h" |
| 37 #include "components/os_crypt/os_crypt_mocker.h" |
| 35 #include "components/prefs/pref_service.h" | 38 #include "components/prefs/pref_service.h" |
| 36 #include "components/signin/core/browser/account_tracker_service.h" | 39 #include "components/signin/core/browser/account_tracker_service.h" |
| 37 #include "components/signin/core/browser/fake_signin_manager.h" | 40 #include "components/signin/core/browser/fake_signin_manager.h" |
| 38 #include "components/signin/core/browser/test_signin_client.h" | 41 #include "components/signin/core/browser/test_signin_client.h" |
| 39 #include "components/signin/core/common/signin_pref_names.h" | 42 #include "components/signin/core/common/signin_pref_names.h" |
| 40 #include "components/variations/entropy_provider.h" | 43 #include "components/variations/entropy_provider.h" |
| 41 #include "components/variations/variations_associated_data.h" | 44 #include "components/variations/variations_associated_data.h" |
| 42 #include "components/webdata/common/web_data_service_base.h" | 45 #include "components/webdata/common/web_data_service_base.h" |
| 43 #include "components/webdata/common/web_database_service.h" | 46 #include "components/webdata/common/web_database_service.h" |
| 44 #include "testing/gmock/include/gmock/gmock.h" | 47 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 results_copy.end()); | 99 results_copy.end()); |
| 97 } | 100 } |
| 98 | 101 |
| 99 } // anonymous namespace | 102 } // anonymous namespace |
| 100 | 103 |
| 101 class PersonalDataManagerTest : public testing::Test { | 104 class PersonalDataManagerTest : public testing::Test { |
| 102 protected: | 105 protected: |
| 103 PersonalDataManagerTest() : autofill_table_(nullptr) {} | 106 PersonalDataManagerTest() : autofill_table_(nullptr) {} |
| 104 | 107 |
| 105 void SetUp() override { | 108 void SetUp() override { |
| 109 OSCryptMocker::SetUpWithSingleton(); |
| 106 prefs_ = test::PrefServiceForTesting(); | 110 prefs_ = test::PrefServiceForTesting(); |
| 107 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 111 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 108 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB"); | 112 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB"); |
| 109 web_database_ = | 113 web_database_ = |
| 110 new WebDatabaseService(path, base::ThreadTaskRunnerHandle::Get(), | 114 new WebDatabaseService(path, base::ThreadTaskRunnerHandle::Get(), |
| 111 base::ThreadTaskRunnerHandle::Get()); | 115 base::ThreadTaskRunnerHandle::Get()); |
| 112 | 116 |
| 113 // Setup account tracker. | 117 // Setup account tracker. |
| 114 signin_client_.reset(new TestSigninClient(prefs_.get())); | 118 signin_client_.reset(new TestSigninClient(prefs_.get())); |
| 115 account_tracker_.reset(new AccountTrackerService()); | 119 account_tracker_.reset(new AccountTrackerService()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 137 | 141 |
| 138 void TearDown() override { | 142 void TearDown() override { |
| 139 // Order of destruction is important as AutofillManager relies on | 143 // Order of destruction is important as AutofillManager relies on |
| 140 // PersonalDataManager to be around when it gets destroyed. | 144 // PersonalDataManager to be around when it gets destroyed. |
| 141 signin_manager_->Shutdown(); | 145 signin_manager_->Shutdown(); |
| 142 signin_manager_.reset(); | 146 signin_manager_.reset(); |
| 143 | 147 |
| 144 account_tracker_->Shutdown(); | 148 account_tracker_->Shutdown(); |
| 145 account_tracker_.reset(); | 149 account_tracker_.reset(); |
| 146 signin_client_.reset(); | 150 signin_client_.reset(); |
| 151 |
| 152 test::DisableSystemServices(prefs_.get()); |
| 153 OSCryptMocker::TearDown(); |
| 147 } | 154 } |
| 148 | 155 |
| 149 void ResetPersonalDataManager(UserMode user_mode) { | 156 void ResetPersonalDataManager(UserMode user_mode) { |
| 150 bool is_incognito = (user_mode == USER_MODE_INCOGNITO); | 157 bool is_incognito = (user_mode == USER_MODE_INCOGNITO); |
| 151 personal_data_.reset(new PersonalDataManager("en")); | 158 personal_data_.reset(new PersonalDataManager("en")); |
| 152 personal_data_->Init( | 159 personal_data_->Init( |
| 153 scoped_refptr<AutofillWebDataService>(autofill_database_service_), | 160 scoped_refptr<AutofillWebDataService>(autofill_database_service_), |
| 154 prefs_.get(), | 161 prefs_.get(), |
| 155 account_tracker_.get(), | 162 account_tracker_.get(), |
| 156 signin_manager_.get(), | 163 signin_manager_.get(), |
| (...skipping 4203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4360 EXPECT_EQ(5U, profile.use_count()); | 4367 EXPECT_EQ(5U, profile.use_count()); |
| 4361 // The use date and modification dates should have been set to less than 500 | 4368 // The use date and modification dates should have been set to less than 500 |
| 4362 // milliseconds ago. | 4369 // milliseconds ago. |
| 4363 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | 4370 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), |
| 4364 base::Time::Now() - profile.use_date()); | 4371 base::Time::Now() - profile.use_date()); |
| 4365 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | 4372 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), |
| 4366 base::Time::Now() - profile.modification_date()); | 4373 base::Time::Now() - profile.modification_date()); |
| 4367 } | 4374 } |
| 4368 | 4375 |
| 4369 } // namespace autofill | 4376 } // namespace autofill |
| OLD | NEW |