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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_ENVIRONMENT_H_
6 #define CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_ENVIRONMENT_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h"
12 #include "ui/base/win/scoped_ole_initializer.h"
15 class ExtensionService
;
24 class TestBrowserThreadBundle
;
27 namespace extensions
{
31 class TestExtensionSystem
;
33 // This class provides a minimal environment in which to create
34 // extensions and tabs for extension-related unittests.
35 class TestExtensionEnvironment
{
37 // Fetches the TestExtensionSystem in |profile| and creates a default
38 // ExtensionService there,
39 static ExtensionService
* CreateExtensionServiceForProfile(
40 TestingProfile
* profile
);
42 TestExtensionEnvironment();
44 // Allows a test harness to pass its own message loop (typically
45 // base::MessageLoopForUI::current()), rather than have
46 // TestExtensionEnvironment create and own a TestBrowserThreadBundle.
47 explicit TestExtensionEnvironment(base::MessageLoopForUI
* message_loop
);
49 ~TestExtensionEnvironment();
51 TestingProfile
* profile() const;
53 // Returns the TestExtensionSystem created by the TestingProfile.
54 TestExtensionSystem
* GetExtensionSystem();
56 // Returns an ExtensionService created (and owned) by the
57 // TestExtensionSystem created by the TestingProfile.
58 ExtensionService
* GetExtensionService();
60 // Returns ExtensionPrefs created (and owned) by the
61 // TestExtensionSystem created by the TestingProfile.
62 ExtensionPrefs
* GetExtensionPrefs();
64 // Creates an Extension and registers it with the ExtensionService.
65 // The Extension has a default manifest of {name: "Extension",
66 // version: "1.0", manifest_version: 2}, and values in
67 // manifest_extra override these defaults.
68 const Extension
* MakeExtension(const base::Value
& manifest_extra
);
70 // Use a specific extension ID instead of the default generated in
72 const Extension
* MakeExtension(const base::Value
& manifest_extra
,
73 const std::string
& id
);
75 // Generates a valid packaged app manifest with the given ID. If |install|
76 // it gets added to the ExtensionService in |profile|.
77 scoped_refptr
<Extension
> MakePackagedApp(const std::string
& id
, bool install
);
79 // Returns a test web contents that has a tab id.
80 scoped_ptr
<content::WebContents
> MakeTab() const;
82 // Deletes the testing profile to test profile teardown.
90 scoped_ptr
<content::TestBrowserThreadBundle
> thread_bundle_
;
91 scoped_ptr
<ChromeOSEnv
> chromeos_env_
;
94 ui::ScopedOleInitializer ole_initializer_
;
96 scoped_ptr
<TestingProfile
> profile_
;
97 ExtensionService
* extension_service_
;
99 DISALLOW_COPY_AND_ASSIGN(TestExtensionEnvironment
);
102 } // namespace extensions
104 #endif // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_ENVIRONMENT_H_