OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/safe_browsing/incident_reporting/state_store.h" | 5 #include "chrome/browser/safe_browsing/incident_reporting/state_store.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/test/test_simple_task_runner.h" | 14 #include "base/test/test_simple_task_runner.h" |
15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
18 #include "chrome/browser/prefs/browser_prefs.h" | 18 #include "chrome/browser/prefs/browser_prefs.h" |
19 #include "chrome/browser/safe_browsing/incident_reporting/incident.h" | 19 #include "chrome/browser/safe_browsing/incident_reporting/incident.h" |
20 #include "chrome/browser/safe_browsing/incident_reporting/platform_state_store.h
" | 20 #include "chrome/browser/safe_browsing/incident_reporting/platform_state_store.h
" |
21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "chrome/test/base/testing_browser_process.h" | 22 #include "chrome/test/base/testing_browser_process.h" |
23 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
24 #include "chrome/test/base/testing_profile_manager.h" | 24 #include "chrome/test/base/testing_profile_manager.h" |
25 #include "components/pref_registry/pref_registry_syncable.h" | 25 #include "components/pref_registry/pref_registry_syncable.h" |
26 #include "components/syncable_prefs/pref_service_syncable.h" | 26 #include "components/syncable_prefs/pref_service_syncable.h" |
27 #include "components/syncable_prefs/pref_service_syncable_factory.h" | 27 #include "components/syncable_prefs/pref_service_syncable_factory.h" |
| 28 #include "content/public/test/test_browser_thread_bundle.h" |
28 #include "extensions/browser/quota_service.h" | 29 #include "extensions/browser/quota_service.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
30 | 31 |
31 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
32 #include "base/test/test_reg_util_win.h" | 33 #include "base/test/test_reg_util_win.h" |
33 #endif | 34 #endif |
34 | 35 |
35 namespace safe_browsing { | 36 namespace safe_browsing { |
36 | 37 |
37 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
(...skipping 28 matching lines...) Expand all Loading... |
66 protected: | 67 protected: |
67 struct TestData { | 68 struct TestData { |
68 IncidentType type; | 69 IncidentType type; |
69 const char* key; | 70 const char* key; |
70 uint32_t digest; | 71 uint32_t digest; |
71 }; | 72 }; |
72 | 73 |
73 StateStoreTest() | 74 StateStoreTest() |
74 : profile_(nullptr), | 75 : profile_(nullptr), |
75 task_runner_(new base::TestSimpleTaskRunner()), | 76 task_runner_(new base::TestSimpleTaskRunner()), |
76 thread_task_runner_handle_(task_runner_), | |
77 profile_manager_(TestingBrowserProcess::GetGlobal()) {} | 77 profile_manager_(TestingBrowserProcess::GetGlobal()) {} |
78 | 78 |
79 void SetUp() override { | 79 void SetUp() override { |
80 PlatformStateStoreTestBase::SetUp(); | 80 PlatformStateStoreTestBase::SetUp(); |
| 81 base::MessageLoop::current()->SetTaskRunner(task_runner_); |
81 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 82 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
82 ASSERT_TRUE(profile_manager_.SetUp()); | 83 ASSERT_TRUE(profile_manager_.SetUp()); |
83 CreateProfile(); | 84 CreateProfile(); |
84 } | 85 } |
85 | 86 |
86 void DeleteProfile() { | 87 void DeleteProfile() { |
87 if (profile_) { | 88 if (profile_) { |
88 profile_ = nullptr; | 89 profile_ = nullptr; |
89 profile_manager_.DeleteTestingProfile(kProfileName_); | 90 profile_manager_.DeleteTestingProfile(kProfileName_); |
90 } | 91 } |
(...skipping 21 matching lines...) Expand all Loading... |
112 new user_prefs::PrefRegistrySyncable(); | 113 new user_prefs::PrefRegistrySyncable(); |
113 chrome::RegisterUserProfilePrefs(pref_registry); | 114 chrome::RegisterUserProfilePrefs(pref_registry); |
114 profile_ = profile_manager_.CreateTestingProfile( | 115 profile_ = profile_manager_.CreateTestingProfile( |
115 kProfileName_, factory.CreateSyncable(pref_registry), | 116 kProfileName_, factory.CreateSyncable(pref_registry), |
116 base::UTF8ToUTF16(kProfileName_), 0, std::string(), | 117 base::UTF8ToUTF16(kProfileName_), 0, std::string(), |
117 TestingProfile::TestingFactories()); | 118 TestingProfile::TestingFactories()); |
118 } | 119 } |
119 | 120 |
120 static const char kProfileName_[]; | 121 static const char kProfileName_[]; |
121 static const TestData kTestData_[]; | 122 static const TestData kTestData_[]; |
| 123 content::TestBrowserThreadBundle thread_bundle_; |
122 TestingProfile* profile_; | 124 TestingProfile* profile_; |
123 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 125 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
124 | 126 |
125 private: | 127 private: |
126 base::FilePath GetPrefsPath() { | 128 base::FilePath GetPrefsPath() { |
127 return temp_dir_.GetPath().AppendASCII("prefs"); | 129 return temp_dir_.GetPath().AppendASCII("prefs"); |
128 } | 130 } |
129 | 131 |
130 extensions::QuotaService::ScopedDisablePurgeForTesting | 132 extensions::QuotaService::ScopedDisablePurgeForTesting |
131 disable_purge_for_testing_; | 133 disable_purge_for_testing_; |
132 base::ScopedTempDir temp_dir_; | 134 base::ScopedTempDir temp_dir_; |
133 base::ThreadTaskRunnerHandle thread_task_runner_handle_; | |
134 TestingProfileManager profile_manager_; | 135 TestingProfileManager profile_manager_; |
135 | 136 |
136 DISALLOW_COPY_AND_ASSIGN(StateStoreTest); | 137 DISALLOW_COPY_AND_ASSIGN(StateStoreTest); |
137 }; | 138 }; |
138 | 139 |
139 // static | 140 // static |
140 const char StateStoreTest::kProfileName_[] = "test_profile"; | 141 const char StateStoreTest::kProfileName_[] = "test_profile"; |
141 const StateStoreTest::TestData StateStoreTest::kTestData_[] = { | 142 const StateStoreTest::TestData StateStoreTest::kTestData_[] = { |
142 {IncidentType::TRACKED_PREFERENCE, "tp_one", 1}, | 143 {IncidentType::TRACKED_PREFERENCE, "tp_one", 1}, |
143 {IncidentType::TRACKED_PREFERENCE, "tp_two", 2}, | 144 {IncidentType::TRACKED_PREFERENCE, "tp_two", 2}, |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 // Verify that the state survived. | 274 // Verify that the state survived. |
274 ASSERT_TRUE(state_store.HasBeenReported(data.type, data.key, data.digest)); | 275 ASSERT_TRUE(state_store.HasBeenReported(data.type, data.key, data.digest)); |
275 #else | 276 #else |
276 // Verify that the state did not survive. | 277 // Verify that the state did not survive. |
277 ASSERT_FALSE(state_store.HasBeenReported(data.type, data.key, data.digest)); | 278 ASSERT_FALSE(state_store.HasBeenReported(data.type, data.key, data.digest)); |
278 #endif | 279 #endif |
279 } | 280 } |
280 } | 281 } |
281 | 282 |
282 } // namespace safe_browsing | 283 } // namespace safe_browsing |
OLD | NEW |