• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2013 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_ENVIRONMENT_H_
6 #define CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_ENVIRONMENT_H_
7 
8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h"
10 #include "content/public/test/test_browser_thread_bundle.h"
11 
12 #if defined(OS_CHROMEOS)
13 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h"
14 #include "chrome/browser/chromeos/settings/cros_settings.h"
15 #include "chrome/browser/chromeos/settings/device_settings_service.h"
16 #endif
17 
18 #if defined(OS_WIN)
19 #include "ui/base/win/scoped_ole_initializer.h"
20 #endif
21 
22 class ExtensionService;
23 class TestingProfile;
24 
25 namespace base {
26 class Value;
27 }
28 
29 namespace content {
30 class WebContents;
31 }
32 
33 namespace extensions {
34 
35 class Extension;
36 class ExtensionPrefs;
37 class TestExtensionSystem;
38 
39 // This class provides a minimal environment in which to create
40 // extensions and tabs for extension-related unittests.
41 class TestExtensionEnvironment {
42  public:
43   TestExtensionEnvironment();
44   ~TestExtensionEnvironment();
45 
46   TestingProfile* profile() const;
47 
48   // Returns the TestExtensionSystem created by the TestingProfile.
49   TestExtensionSystem* GetExtensionSystem();
50 
51   // Returns an ExtensionService created (and owned) by the
52   // TestExtensionSystem created by the TestingProfile.
53   ExtensionService* GetExtensionService();
54 
55   // Returns ExtensionPrefs created (and owned) by the
56   // TestExtensionSystem created by the TestingProfile.
57   ExtensionPrefs* GetExtensionPrefs();
58 
59   // Creates an Extension and registers it with the ExtensionService.
60   // The Extension has a default manifest of {name: "Extension",
61   // version: "1.0", manifest_version: 2}, and values in
62   // manifest_extra override these defaults.
63   const Extension* MakeExtension(const base::Value& manifest_extra);
64 
65   // Returns a test web contents that has a tab id.
66   scoped_ptr<content::WebContents> MakeTab() const;
67 
68  private:
69   content::TestBrowserThreadBundle thread_bundle_;
70 
71 #if defined(OS_CHROMEOS)
72   chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
73   chromeos::ScopedTestCrosSettings test_cros_settings_;
74   chromeos::ScopedTestUserManager test_user_manager_;
75 #endif
76 
77 #if defined(OS_WIN)
78   ui::ScopedOleInitializer ole_initializer_;
79 #endif
80   scoped_ptr<TestingProfile> profile_;
81   ExtensionService* extension_service_;
82   ExtensionPrefs* extension_prefs_;
83 };
84 
85 }  // namespace extensions
86 
87 #endif  // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_ENVIRONMENT_H_
88