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_
10 #include "base/files/scoped_temp_dir.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "extensions/common/manifest.h"
15 class ExtensionPrefValueMap
;
17 class PrefServiceSyncable
;
20 class DictionaryValue
;
21 class SequencedTaskRunner
;
24 namespace user_prefs
{
25 class PrefRegistrySyncable
;
28 namespace extensions
{
32 // This is a test class intended to make it easier to work with ExtensionPrefs
34 class TestExtensionPrefs
{
36 explicit TestExtensionPrefs(base::SequencedTaskRunner
* task_runner
);
37 virtual ~TestExtensionPrefs();
39 ExtensionPrefs
* prefs() { return prefs_
.get(); }
40 const ExtensionPrefs
& const_prefs() const {
43 PrefService
* pref_service();
44 const scoped_refptr
<user_prefs::PrefRegistrySyncable
>& pref_registry();
45 void ResetPrefRegistry();
46 const base::FilePath
& temp_dir() const { return temp_dir_
.path(); }
47 const base::FilePath
& extensions_dir() const { return extensions_dir_
; }
48 ExtensionPrefValueMap
* extension_pref_value_map() {
49 return extension_pref_value_map_
.get();
52 // This will cause the ExtensionPrefs to be deleted and recreated, based on
53 // any existing backing file we had previously created.
54 void RecreateExtensionPrefs();
56 // Creates a new Extension with the given name in our temp dir, adds it to
57 // our ExtensionPrefs, and returns it.
58 scoped_refptr
<Extension
> AddExtension(std::string name
);
60 // As above, but the extension is an app.
61 scoped_refptr
<Extension
> AddApp(std::string name
);
63 // Similar to AddExtension, but takes a dictionary with manifest values.
64 scoped_refptr
<Extension
> AddExtensionWithManifest(
65 const base::DictionaryValue
& manifest
,
66 Manifest::Location location
);
68 // Similar to AddExtension, but takes a dictionary with manifest values
69 // and extension flags.
70 scoped_refptr
<Extension
> AddExtensionWithManifestAndFlags(
71 const base::DictionaryValue
& manifest
,
72 Manifest::Location location
,
75 // Similar to AddExtension, this adds a new test Extension. This is useful for
76 // cases when you don't need the Extension object, but just the id it was
78 std::string
AddExtensionAndReturnId(std::string name
);
80 PrefService
* CreateIncognitoPrefService() const;
82 // Allows disabling the loading of preferences of extensions. Becomes
83 // active after calling RecreateExtensionPrefs(). Defaults to false.
84 void set_extensions_disabled(bool extensions_disabled
);
87 base::ScopedTempDir temp_dir_
;
88 base::FilePath preferences_file_
;
89 base::FilePath extensions_dir_
;
90 scoped_refptr
<user_prefs::PrefRegistrySyncable
> pref_registry_
;
91 scoped_ptr
<PrefServiceSyncable
> pref_service_
;
92 scoped_ptr
<ExtensionPrefs
> prefs_
;
93 scoped_ptr
<ExtensionPrefValueMap
> extension_pref_value_map_
;
94 const scoped_refptr
<base::SequencedTaskRunner
> task_runner_
;
97 bool extensions_disabled_
;
98 DISALLOW_COPY_AND_ASSIGN(TestExtensionPrefs
);
101 } // namespace extensions
103 #endif // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_PREFS_H_