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

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: new comment and unit test Created 5 years, 3 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/browser/safe_browsing/incident_reporting/platform_state_store.h "
19 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
20 #include "chrome/test/base/testing_browser_process.h" 21 #include "chrome/test/base/testing_browser_process.h"
21 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
22 #include "chrome/test/base/testing_profile_manager.h" 23 #include "chrome/test/base/testing_profile_manager.h"
23 #include "components/pref_registry/pref_registry_syncable.h" 24 #include "components/pref_registry/pref_registry_syncable.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 26
27 #if defined(OS_WIN)
28 #include "base/test/test_reg_util_win.h"
29 #endif
30
26 namespace safe_browsing { 31 namespace safe_browsing {
27 32
33 #if defined(OS_WIN)
34
35 // A base test fixture that redirects HKCU for testing the platform state store
36 // backed by the Windows registry to prevent interference with existing Chrome
37 // installs or other tests.
38 class PlatformStateStoreTestBase : public ::testing::Test {
39 protected:
40 PlatformStateStoreTestBase() {}
41
42 void SetUp() override {
43 ::testing::Test::SetUp();
44 registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
robertshield 2015/09/01 14:20:12 given that this and the declaration of registry_ov
grt (UTC plus 2) 2015/09/03 18:12:05 I decided to go this route since other platforms w
45 }
46
47 private:
48 registry_util::RegistryOverrideManager registry_override_manager_;
49
50 DISALLOW_COPY_AND_ASSIGN(PlatformStateStoreTestBase);
51 };
52
53 #else // OS_WIN
54
55 using PlatformStateStoreTestBase = ::testing::Test;
56
57 #endif // !OS_WIN
58
28 // A test fixture with a testing profile that writes its user prefs to a json 59 // A test fixture with a testing profile that writes its user prefs to a json
29 // file. 60 // file.
30 class StateStoreTest : public ::testing::Test { 61 class StateStoreTest : public PlatformStateStoreTestBase {
31 protected: 62 protected:
32 struct TestData { 63 struct TestData {
33 IncidentType type; 64 IncidentType type;
34 const char* key; 65 const char* key;
35 uint32_t digest; 66 uint32_t digest;
36 }; 67 };
37 68
38 StateStoreTest() 69 StateStoreTest()
39 : profile_(nullptr), 70 : profile_(nullptr),
40 task_runner_(new base::TestSimpleTaskRunner()), 71 task_runner_(new base::TestSimpleTaskRunner()),
41 thread_task_runner_handle_(task_runner_), 72 thread_task_runner_handle_(task_runner_),
42 profile_manager_(TestingBrowserProcess::GetGlobal()) {} 73 profile_manager_(TestingBrowserProcess::GetGlobal()) {}
43 74
44 void SetUp() override { 75 void SetUp() override {
45 testing::Test::SetUp(); 76 PlatformStateStoreTestBase::SetUp();
46 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 77 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
47 ASSERT_TRUE(profile_manager_.SetUp()); 78 ASSERT_TRUE(profile_manager_.SetUp());
48 CreateProfile(); 79 CreateProfile();
49 } 80 }
50 81
51 void DeleteProfile() { 82 void DeleteProfile() {
52 if (profile_) { 83 if (profile_) {
53 profile_ = nullptr; 84 profile_ = nullptr;
54 profile_manager_.DeleteTestingProfile(kProfileName_); 85 profile_manager_.DeleteTestingProfile(kProfileName_);
55 } 86 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 223
193 // Delete the profile. 224 // Delete the profile.
194 DeleteProfile(); 225 DeleteProfile();
195 226
196 // Delete the state pref. 227 // Delete the state pref.
197 TrimPref(); 228 TrimPref();
198 229
199 // Recreate the profile. 230 // Recreate the profile.
200 CreateProfile(); 231 CreateProfile();
201 232
202 // Verify that the state did not survive.
203 StateStore state_store(profile_); 233 StateStore state_store(profile_);
204 for (const auto& data : kTestData_) 234 for (const auto& data : kTestData_) {
235 #if defined(USE_PLATFORM_STATE_STORE)
236 // Verify that the state survived.
237 ASSERT_TRUE(state_store.HasBeenReported(data.type, data.key, data.digest));
238 #else
239 // Verify that the state did not survive.
205 ASSERT_FALSE(state_store.HasBeenReported(data.type, data.key, data.digest)); 240 ASSERT_FALSE(state_store.HasBeenReported(data.type, data.key, data.digest));
241 #endif
242 }
206 } 243 }
207 244
208 } // namespace safe_browsing 245 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698