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