Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: chrome/browser/safe_browsing/incident_reporting/state_store_unittest.cc

Issue 1243293003: Platform-specific prune state storage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@prune1
Patch Set: compile fix Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/json/json_file_value_serializer.h" 8 #include "base/json/json_file_value_serializer.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/test/test_simple_task_runner.h" 12 #include "base/test/test_simple_task_runner.h"
13 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/prefs/browser_prefs.h" 15 #include "chrome/browser/prefs/browser_prefs.h"
16 #include "chrome/browser/prefs/pref_service_syncable.h" 16 #include "chrome/browser/prefs/pref_service_syncable.h"
17 #include "chrome/browser/prefs/pref_service_syncable_factory.h" 17 #include "chrome/browser/prefs/pref_service_syncable_factory.h"
18 #include "chrome/browser/safe_browsing/incident_reporting/incident.h" 18 #include "chrome/browser/safe_browsing/incident_reporting/incident.h"
19 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "chrome/test/base/testing_browser_process.h" 20 #include "chrome/test/base/testing_browser_process.h"
21 #include "chrome/test/base/testing_profile.h" 21 #include "chrome/test/base/testing_profile.h"
22 #include "chrome/test/base/testing_profile_manager.h" 22 #include "chrome/test/base/testing_profile_manager.h"
23 #include "components/pref_registry/pref_registry_syncable.h" 23 #include "components/pref_registry/pref_registry_syncable.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 25
26 #if defined(OS_WIN)
27 #include "base/test/test_reg_util_win.h"
28 #endif
29
26 namespace safe_browsing { 30 namespace safe_browsing {
27 31
32 #if defined(OS_WIN)
33
34 // A base test fixture that redirects HKCU for testing the platform state store
35 // backed by the Windows registry to prevent interference with existing Chrome
36 // installs or other tests.
37 class PlatformStateStoreTestBase : public ::testing::Test {
38 protected:
39 PlatformStateStoreTestBase() {}
40
41 void SetUp() override {
42 ::testing::Test::SetUp();
43 registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
44 }
45
46 private:
47 registry_util::RegistryOverrideManager registry_override_manager_;
48
49 DISALLOW_COPY_AND_ASSIGN(PlatformStateStoreTestBase);
50 };
51
52 #else // OS_WIN
53
54 using PlatformStateStoreTestBase = ::testing::Test;
55
56 #endif // !OS_WIN
57
28 // A test fixture with a testing profile that writes its user prefs to a json 58 // A test fixture with a testing profile that writes its user prefs to a json
29 // file. 59 // file.
30 class StateStoreTest : public ::testing::Test { 60 class StateStoreTest : public PlatformStateStoreTestBase {
31 protected: 61 protected:
32 struct TestData { 62 struct TestData {
33 IncidentType type; 63 IncidentType type;
34 const char* key; 64 const char* key;
35 uint32_t digest; 65 uint32_t digest;
36 }; 66 };
37 67
38 StateStoreTest() 68 StateStoreTest()
39 : profile_(nullptr), 69 : profile_(nullptr),
40 task_runner_(new base::TestSimpleTaskRunner()), 70 task_runner_(new base::TestSimpleTaskRunner()),
41 thread_task_runner_handle_(task_runner_), 71 thread_task_runner_handle_(task_runner_),
42 profile_manager_(TestingBrowserProcess::GetGlobal()) {} 72 profile_manager_(TestingBrowserProcess::GetGlobal()) {}
43 73
44 void SetUp() override { 74 void SetUp() override {
45 testing::Test::SetUp(); 75 PlatformStateStoreTestBase::SetUp();
46 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 76 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
47 ASSERT_TRUE(profile_manager_.SetUp()); 77 ASSERT_TRUE(profile_manager_.SetUp());
48 CreateProfile(); 78 CreateProfile();
49 } 79 }
50 80
51 void DeleteProfile() { 81 void DeleteProfile() {
52 if (profile_) { 82 if (profile_) {
53 profile_ = nullptr; 83 profile_ = nullptr;
54 profile_manager_.DeleteTestingProfile(kProfileName_); 84 profile_manager_.DeleteTestingProfile(kProfileName_);
55 } 85 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 222
193 // Delete the profile. 223 // Delete the profile.
194 DeleteProfile(); 224 DeleteProfile();
195 225
196 // Delete the state pref. 226 // Delete the state pref.
197 TrimPref(); 227 TrimPref();
198 228
199 // Recreate the profile. 229 // Recreate the profile.
200 CreateProfile(); 230 CreateProfile();
201 231
202 // Verify that the state did not survive. 232 // Verify that the state survived.
203 StateStore state_store(profile_); 233 StateStore state_store(profile_);
204 for (const auto& data : kTestData_) 234 for (const auto& data : kTestData_)
205 ASSERT_FALSE(state_store.HasBeenReported(data.type, data.key, data.digest)); 235 ASSERT_TRUE(state_store.HasBeenReported(data.type, data.key, data.digest));
206 } 236 }
207 237
208 } // namespace safe_browsing 238 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698