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

Side by Side Diff: chrome/test/testing_pref_service.h

Issue 7537033: Move more files from chrome/test to chrome/test/base, part #5 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/test/test_tab_strip_model_observer.cc ('k') | chrome/test/testing_pref_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_TEST_TESTING_PREF_SERVICE_H_
6 #define CHROME_TEST_TESTING_PREF_SERVICE_H_
7 #pragma once
8
9 #include "base/memory/ref_counted.h"
10 #include "chrome/browser/prefs/pref_service.h"
11
12 class TestingBrowserProcess;
13 class TestingPrefStore;
14
15 // A PrefService subclass for testing. It operates totally in memory and
16 // provides additional API for manipulating preferences at the different levels
17 // (managed, extension, user) conveniently.
18 class TestingPrefServiceBase : public PrefService {
19 public:
20 virtual ~TestingPrefServiceBase();
21
22 // Read the value of a preference from the managed layer. Returns NULL if the
23 // preference is not defined at the managed layer.
24 const Value* GetManagedPref(const char* path) const;
25
26 // Set a preference on the managed layer and fire observers if the preference
27 // changed. Assumes ownership of |value|.
28 void SetManagedPref(const char* path, Value* value);
29
30 // Clear the preference on the managed layer and fire observers if the
31 // preference has been defined previously.
32 void RemoveManagedPref(const char* path);
33
34 // Similar to the above, but for user preferences.
35 const Value* GetUserPref(const char* path) const;
36 void SetUserPref(const char* path, Value* value);
37 void RemoveUserPref(const char* path);
38
39 // Similar to the above, but for recommended policy preferences.
40 const Value* GetRecommendedPref(const char* path) const;
41 void SetRecommendedPref(const char* path, Value* value);
42 void RemoveRecommendedPref(const char* path);
43
44 protected:
45 TestingPrefServiceBase(
46 TestingPrefStore* managed_platform_prefs,
47 TestingPrefStore* user_prefs,
48 TestingPrefStore* recommended_platform_prefs);
49
50 private:
51 // Reads the value of the preference indicated by |path| from |pref_store|.
52 // Returns NULL if the preference was not found.
53 const Value* GetPref(TestingPrefStore* pref_store, const char* path) const;
54
55 // Sets the value for |path| in |pref_store|.
56 void SetPref(TestingPrefStore* pref_store, const char* path, Value* value);
57
58 // Removes the preference identified by |path| from |pref_store|.
59 void RemovePref(TestingPrefStore* pref_store, const char* path);
60
61 // Pointers to the pref stores our value store uses.
62 scoped_refptr<TestingPrefStore> managed_platform_prefs_;
63 scoped_refptr<TestingPrefStore> user_prefs_;
64 scoped_refptr<TestingPrefStore> recommended_platform_prefs_;
65
66 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceBase);
67 };
68
69 // Class for simplified construction of TestPrefServiceBase objects.
70 class TestingPrefService : public TestingPrefServiceBase {
71 public:
72 TestingPrefService();
73 virtual ~TestingPrefService();
74
75 private:
76 DISALLOW_COPY_AND_ASSIGN(TestingPrefService);
77 };
78
79 // Helper class to temporarily set up a |local_state| in the global
80 // TestingBrowserProcess (for most unit tests it's NULL).
81 class ScopedTestingLocalState {
82 public:
83 explicit ScopedTestingLocalState(TestingBrowserProcess* browser_process);
84 ~ScopedTestingLocalState();
85
86 TestingPrefService* Get() {
87 return &local_state_;
88 }
89
90 private:
91 TestingBrowserProcess* browser_process_;
92 TestingPrefService local_state_;
93
94 DISALLOW_COPY_AND_ASSIGN(ScopedTestingLocalState);
95 };
96
97 #endif // CHROME_TEST_TESTING_PREF_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/test/test_tab_strip_model_observer.cc ('k') | chrome/test/testing_pref_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698