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

Side by Side Diff: chrome/browser/extensions/extension_management_test_util.h

Issue 559603002: Add new ExtensionManagement preference (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes addressing #16 Created 6 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
(Empty)
1 // Copyright 2014 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_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_TEST_UTIL_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_TEST_UTIL_H_
7
8 #include <string>
9
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/values.h"
13 #include "chrome/browser/extensions/extension_management_constants.h"
14 #include "extensions/browser/pref_names.h"
15 #include "extensions/common/extension.h"
16
17 namespace extensions {
18
19 // Base class for essential routines on preference manipulation.
20 class ExtensionManagementPrefUpdaterBase {
21 public:
22 ExtensionManagementPrefUpdaterBase();
23 virtual ~ExtensionManagementPrefUpdaterBase();
24
25 // Helper functions for 'installation_mode' manipulation.
26 void SetBlacklistedByDefault(bool value);
27 void ClearInstallationModesForIndividualExtensions();
28 void SetIndividualExtensionInstallationAllowed(const ExtensionId& id,
29 bool allowed);
30 void SetIndividualExtensionAutoInstalled(const ExtensionId& id,
31 const std::string& update_url,
32 bool forced);
33
34 // Helper functions for 'install_sources' manipulation.
35 void UnsetInstallSources();
36 void ClearInstallSources();
37 void AddInstallSource(const std::string& install_source);
38 void RemoveInstallSource(const std::string& install_source);
39
40 // Helper functions for 'allowed_types' manipulation.
41 void UnsetAllowedTypes();
42 void ClearAllowedTypes();
43 void AddAllowedType(const std::string& allowed_type);
44 void RemoveAllowedType(const std::string& allowd_type);
45
46 // Expose a read-only preference to user.
47 const base::DictionaryValue* GetPref();
48
49 protected:
50 // Set the preference with |pref|, pass the ownership of it as well.
51 // This function must be called before accessing publicly exposed functions,
52 // for example in constructor of subclass.
53 void SetPref(base::DictionaryValue* pref);
54
55 // Take the preference. Caller takes ownership of it as well.
56 // This function must be called after accessing publicly exposed functions,
57 // for example in destructor of subclass.
58 scoped_ptr<base::DictionaryValue> TakePref();
59
60 private:
61 // Helper functions for manipulating sub properties like list of strings.
62 void ClearList(const std::string& path);
63 void AddStringToList(const std::string& path, const std::string& str);
64 void RemoveStringFromList(const std::string& path, const std::string& str);
65
66 scoped_ptr<base::DictionaryValue> pref_;
67
68 DISALLOW_COPY_AND_ASSIGN(ExtensionManagementPrefUpdaterBase);
69 };
70
71 // A helper class to manipulate the extension management preference in unit
72 // tests.
73 template <class TestingPrefService>
74 class ExtensionManagementPrefUpdater
75 : public ExtensionManagementPrefUpdaterBase {
76 public:
77 explicit ExtensionManagementPrefUpdater(TestingPrefService* service)
78 : service_(service) {
79 const base::Value* pref_value =
80 service_->GetManagedPref(pref_names::kExtensionManagement);
81 if (pref_value) {
82 const base::DictionaryValue* dict_value = NULL;
83 pref_value->GetAsDictionary(&dict_value);
84 SetPref(dict_value->DeepCopy());
85 } else {
86 SetPref(new base::DictionaryValue);
87 }
88 }
89
90 virtual ~ExtensionManagementPrefUpdater() {
91 service_->SetManagedPref(pref_names::kExtensionManagement,
92 TakePref().release());
93 }
94
95 private:
96 TestingPrefService* service_;
97
98 DISALLOW_COPY_AND_ASSIGN(ExtensionManagementPrefUpdater);
99 };
100
101 } // namespace extensions
102
103 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698