• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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_TEST_EXTENSION_PREFS_H_
6 #define CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_PREFS_H_
7 #pragma once
8 
9 #include <string>
10 
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_temp_dir.h"
13 #include "chrome/common/extensions/extension.h"
14 
15 class DictionaryValue;
16 class ExtensionPrefs;
17 class ExtensionPrefValueMap;
18 class PrefService;
19 
20 // This is a test class intended to make it easier to work with ExtensionPrefs
21 // in tests.
22 class TestExtensionPrefs {
23  public:
24   TestExtensionPrefs();
25   virtual ~TestExtensionPrefs();
26 
prefs()27   ExtensionPrefs* prefs() { return prefs_.get(); }
const_prefs()28   const ExtensionPrefs& const_prefs() const { return *prefs_.get(); }
pref_service()29   PrefService* pref_service() { return pref_service_.get(); }
temp_dir()30   const FilePath& temp_dir() const { return temp_dir_.path(); }
31 
32   // This will cause the ExtensionPrefs to be deleted and recreated, based on
33   // any existing backing file we had previously created.
34   void RecreateExtensionPrefs();
35 
36   // Creates a new Extension with the given name in our temp dir, adds it to
37   // our ExtensionPrefs, and returns it.
38   scoped_refptr<Extension> AddExtension(std::string name);
39 
40   // Similar to AddExtension, but takes a dictionary with manifest values.
41   scoped_refptr<Extension> AddExtensionWithManifest(
42       const DictionaryValue& manifest, Extension::Location location);
43 
44   // Similar to AddExtension, this adds a new test Extension. This is useful for
45   // cases when you don't need the Extension object, but just the id it was
46   // assigned.
47   std::string AddExtensionAndReturnId(std::string name);
48 
49   PrefService* CreateIncognitoPrefService() const;
50 
51  protected:
52   ScopedTempDir temp_dir_;
53   FilePath preferences_file_;
54   FilePath extensions_dir_;
55   scoped_ptr<PrefService> pref_service_;
56   scoped_ptr<ExtensionPrefs> prefs_;
57   scoped_ptr<ExtensionPrefValueMap> extension_pref_value_map_;
58 
59  private:
60   DISALLOW_COPY_AND_ASSIGN(TestExtensionPrefs);
61 };
62 
63 #endif  // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_PREFS_H_
64