| 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/sync_preferences/pref_service_syncable.h" |
| 27 #include "components/syncable_prefs/pref_service_syncable_factory.h" | 27 #include "components/sync_preferences/pref_service_syncable_factory.h" |
| 28 #include "content/public/test/test_browser_thread_bundle.h" | 28 #include "content/public/test/test_browser_thread_bundle.h" |
| 29 #include "extensions/browser/quota_service.h" | 29 #include "extensions/browser/quota_service.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 31 |
| 32 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
| 33 #include "base/test/test_reg_util_win.h" | 33 #include "base/test/test_reg_util_win.h" |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 namespace safe_browsing { | 36 namespace safe_browsing { |
| 37 | 37 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 ASSERT_NE(nullptr, prefs.get()); | 100 ASSERT_NE(nullptr, prefs.get()); |
| 101 base::DictionaryValue* dict = nullptr; | 101 base::DictionaryValue* dict = nullptr; |
| 102 ASSERT_TRUE(prefs->GetAsDictionary(&dict)); | 102 ASSERT_TRUE(prefs->GetAsDictionary(&dict)); |
| 103 ASSERT_TRUE(dict->Remove(prefs::kSafeBrowsingIncidentsSent, nullptr)); | 103 ASSERT_TRUE(dict->Remove(prefs::kSafeBrowsingIncidentsSent, nullptr)); |
| 104 ASSERT_TRUE(JSONFileValueSerializer(GetPrefsPath()).Serialize(*dict)); | 104 ASSERT_TRUE(JSONFileValueSerializer(GetPrefsPath()).Serialize(*dict)); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void CreateProfile() { | 107 void CreateProfile() { |
| 108 ASSERT_EQ(nullptr, profile_); | 108 ASSERT_EQ(nullptr, profile_); |
| 109 // Create the testing profile with a file-backed user pref store. | 109 // Create the testing profile with a file-backed user pref store. |
| 110 syncable_prefs::PrefServiceSyncableFactory factory; | 110 sync_preferences::PrefServiceSyncableFactory factory; |
| 111 factory.SetUserPrefsFile(GetPrefsPath(), task_runner_.get()); | 111 factory.SetUserPrefsFile(GetPrefsPath(), task_runner_.get()); |
| 112 user_prefs::PrefRegistrySyncable* pref_registry = | 112 user_prefs::PrefRegistrySyncable* pref_registry = |
| 113 new user_prefs::PrefRegistrySyncable(); | 113 new user_prefs::PrefRegistrySyncable(); |
| 114 chrome::RegisterUserProfilePrefs(pref_registry); | 114 chrome::RegisterUserProfilePrefs(pref_registry); |
| 115 profile_ = profile_manager_.CreateTestingProfile( | 115 profile_ = profile_manager_.CreateTestingProfile( |
| 116 kProfileName_, factory.CreateSyncable(pref_registry), | 116 kProfileName_, factory.CreateSyncable(pref_registry), |
| 117 base::UTF8ToUTF16(kProfileName_), 0, std::string(), | 117 base::UTF8ToUTF16(kProfileName_), 0, std::string(), |
| 118 TestingProfile::TestingFactories()); | 118 TestingProfile::TestingFactories()); |
| 119 } | 119 } |
| 120 | 120 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 // Verify that the state survived. | 274 // Verify that the state survived. |
| 275 ASSERT_TRUE(state_store.HasBeenReported(data.type, data.key, data.digest)); | 275 ASSERT_TRUE(state_store.HasBeenReported(data.type, data.key, data.digest)); |
| 276 #else | 276 #else |
| 277 // Verify that the state did not survive. | 277 // Verify that the state did not survive. |
| 278 ASSERT_FALSE(state_store.HasBeenReported(data.type, data.key, data.digest)); | 278 ASSERT_FALSE(state_store.HasBeenReported(data.type, data.key, data.digest)); |
| 279 #endif | 279 #endif |
| 280 } | 280 } |
| 281 } | 281 } |
| 282 | 282 |
| 283 } // namespace safe_browsing | 283 } // namespace safe_browsing |
| OLD | NEW |