Rename GetIconID to GetIconId
[chromium-blink-merge.git] / chrome / browser / extensions / test_extension_prefs.h
blob64772806de01ed106e9af9fc9c439585c3fde63f
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;
18 class PrefServiceSyncable;
20 namespace base {
21 class DictionaryValue;
22 class SequencedTaskRunner;
25 namespace user_prefs {
26 class PrefRegistrySyncable;
29 namespace extensions {
30 class ChromeAppSorting;
31 class Extension;
32 class ExtensionPrefs;
34 // This is a test class intended to make it easier to work with ExtensionPrefs
35 // in tests.
36 class TestExtensionPrefs {
37 public:
38 explicit TestExtensionPrefs(
39 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
40 virtual ~TestExtensionPrefs();
42 ExtensionPrefs* prefs();
44 PrefService* pref_service();
45 const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry();
46 void ResetPrefRegistry();
47 const base::FilePath& temp_dir() const { return temp_dir_.path(); }
48 const base::FilePath& extensions_dir() const { return extensions_dir_; }
49 ExtensionPrefValueMap* extension_pref_value_map() {
50 return extension_pref_value_map_.get();
53 // This will cause the ExtensionPrefs to be deleted and recreated, based on
54 // any existing backing file we had previously created.
55 void RecreateExtensionPrefs();
57 // Creates a new Extension with the given name in our temp dir, adds it to
58 // our ExtensionPrefs, and returns it.
59 scoped_refptr<Extension> AddExtension(const std::string& name);
61 // As above, but the extension is an app.
62 scoped_refptr<Extension> AddApp(const std::string& name);
64 // Similar to AddExtension, but takes a dictionary with manifest values.
65 scoped_refptr<Extension> AddExtensionWithManifest(
66 const base::DictionaryValue& manifest,
67 Manifest::Location location);
69 // Similar to AddExtension, but takes a dictionary with manifest values
70 // and extension flags.
71 scoped_refptr<Extension> AddExtensionWithManifestAndFlags(
72 const base::DictionaryValue& manifest,
73 Manifest::Location location,
74 int extra_flags);
76 // Similar to AddExtension, this adds a new test Extension. This is useful for
77 // cases when you don't need the Extension object, but just the id it was
78 // assigned.
79 std::string AddExtensionAndReturnId(const std::string& name);
81 // This will add extension in our ExtensionPrefs.
82 void AddExtension(Extension* extension);
84 PrefService* CreateIncognitoPrefService() const;
86 // Allows disabling the loading of preferences of extensions. Becomes
87 // active after calling RecreateExtensionPrefs(). Defaults to false.
88 void set_extensions_disabled(bool extensions_disabled);
90 ChromeAppSorting* app_sorting();
92 protected:
93 base::ScopedTempDir temp_dir_;
94 base::FilePath preferences_file_;
95 base::FilePath extensions_dir_;
96 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_;
97 scoped_ptr<PrefServiceSyncable> pref_service_;
98 scoped_ptr<ExtensionPrefValueMap> extension_pref_value_map_;
99 const scoped_refptr<base::SequencedTaskRunner> task_runner_;
101 private:
102 TestingProfile profile_;
103 bool extensions_disabled_;
104 DISALLOW_COPY_AND_ASSIGN(TestExtensionPrefs);
107 } // namespace extensions
109 #endif // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_PREFS_H_