Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / chrome / browser / extensions / test_extension_prefs.h
blob29855ec64a8abda1271283db09919ed9a9da7c95
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_PREFS_H_
6 #define CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_PREFS_H_
8 #include <string>
10 #include "base/files/scoped_temp_dir.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chrome/test/base/testing_profile.h"
14 #include "extensions/common/manifest.h"
16 class ExtensionPrefValueMap;
17 class PrefService;
19 namespace base {
20 class DictionaryValue;
21 class SequencedTaskRunner;
24 namespace syncable_prefs {
25 class PrefServiceSyncable;
28 namespace user_prefs {
29 class PrefRegistrySyncable;
32 namespace extensions {
33 class ChromeAppSorting;
34 class Extension;
35 class ExtensionPrefs;
37 // This is a test class intended to make it easier to work with ExtensionPrefs
38 // in tests.
39 class TestExtensionPrefs {
40 public:
41 explicit TestExtensionPrefs(
42 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
43 virtual ~TestExtensionPrefs();
45 ExtensionPrefs* prefs();
47 PrefService* pref_service();
48 const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry();
49 void ResetPrefRegistry();
50 const base::FilePath& temp_dir() const { return temp_dir_.path(); }
51 const base::FilePath& extensions_dir() const { return extensions_dir_; }
52 ExtensionPrefValueMap* extension_pref_value_map() {
53 return extension_pref_value_map_.get();
56 // This will cause the ExtensionPrefs to be deleted and recreated, based on
57 // any existing backing file we had previously created.
58 void RecreateExtensionPrefs();
60 // Creates a new Extension with the given name in our temp dir, adds it to
61 // our ExtensionPrefs, and returns it.
62 scoped_refptr<Extension> AddExtension(const std::string& name);
64 // As above, but the extension is an app.
65 scoped_refptr<Extension> AddApp(const std::string& name);
67 // Similar to AddExtension, but takes a dictionary with manifest values.
68 scoped_refptr<Extension> AddExtensionWithManifest(
69 const base::DictionaryValue& manifest,
70 Manifest::Location location);
72 // Similar to AddExtension, but takes a dictionary with manifest values
73 // and extension flags.
74 scoped_refptr<Extension> AddExtensionWithManifestAndFlags(
75 const base::DictionaryValue& manifest,
76 Manifest::Location location,
77 int extra_flags);
79 // Similar to AddExtension, this adds a new test Extension. This is useful for
80 // cases when you don't need the Extension object, but just the id it was
81 // assigned.
82 std::string AddExtensionAndReturnId(const std::string& name);
84 // This will add extension in our ExtensionPrefs.
85 void AddExtension(Extension* extension);
87 PrefService* CreateIncognitoPrefService() const;
89 // Allows disabling the loading of preferences of extensions. Becomes
90 // active after calling RecreateExtensionPrefs(). Defaults to false.
91 void set_extensions_disabled(bool extensions_disabled);
93 ChromeAppSorting* app_sorting();
95 protected:
96 base::ScopedTempDir temp_dir_;
97 base::FilePath preferences_file_;
98 base::FilePath extensions_dir_;
99 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_;
100 scoped_ptr<syncable_prefs::PrefServiceSyncable> pref_service_;
101 scoped_ptr<ExtensionPrefValueMap> extension_pref_value_map_;
102 const scoped_refptr<base::SequencedTaskRunner> task_runner_;
104 private:
105 TestingProfile profile_;
106 bool extensions_disabled_;
107 DISALLOW_COPY_AND_ASSIGN(TestExtensionPrefs);
110 } // namespace extensions
112 #endif // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_PREFS_H_