[email protected] | 11d42c8 | 2013-02-01 00:14:32 | [diff] [blame] | 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 | |||||
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame^] | 8 | #include <memory> |
9 | |||||
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 10 | #include "base/macros.h" |
[email protected] | b19fe57 | 2013-07-18 04:54:26 | [diff] [blame] | 11 | #include "base/message_loop/message_loop.h" |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 12 | #include "build/build_config.h" |
[email protected] | 11d42c8 | 2013-02-01 00:14:32 | [diff] [blame] | 13 | |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 14 | #if defined(OS_WIN) |
15 | #include "ui/base/win/scoped_ole_initializer.h" | ||||
[email protected] | 79bac42 | 2013-04-22 15:44:26 | [diff] [blame] | 16 | #endif |
17 | |||||
[email protected] | 11d42c8 | 2013-02-01 00:14:32 | [diff] [blame] | 18 | class ExtensionService; |
[email protected] | e0ec3cb1 | 2013-04-03 17:35:30 | [diff] [blame] | 19 | class TestingProfile; |
20 | |||||
21 | namespace base { | ||||
22 | class Value; | ||||
23 | } | ||||
[email protected] | 11d42c8 | 2013-02-01 00:14:32 | [diff] [blame] | 24 | |
25 | namespace content { | ||||
26 | class WebContents; | ||||
tapted | c7bd3ce | 2015-06-16 02:50:44 | [diff] [blame] | 27 | class TestBrowserThreadBundle; |
[email protected] | 11d42c8 | 2013-02-01 00:14:32 | [diff] [blame] | 28 | } |
29 | |||||
30 | namespace extensions { | ||||
31 | |||||
32 | class Extension; | ||||
[email protected] | 94cf31c | 2013-12-07 03:58:32 | [diff] [blame] | 33 | class ExtensionPrefs; |
34 | class TestExtensionSystem; | ||||
[email protected] | 11d42c8 | 2013-02-01 00:14:32 | [diff] [blame] | 35 | |
36 | // This class provides a minimal environment in which to create | ||||
37 | // extensions and tabs for extension-related unittests. | ||||
38 | class TestExtensionEnvironment { | ||||
39 | public: | ||||
tapted | c7bd3ce | 2015-06-16 02:50:44 | [diff] [blame] | 40 | // Fetches the TestExtensionSystem in |profile| and creates a default |
41 | // ExtensionService there, | ||||
42 | static ExtensionService* CreateExtensionServiceForProfile( | ||||
43 | TestingProfile* profile); | ||||
44 | |||||
[email protected] | 11d42c8 | 2013-02-01 00:14:32 | [diff] [blame] | 45 | TestExtensionEnvironment(); |
tapted | c7bd3ce | 2015-06-16 02:50:44 | [diff] [blame] | 46 | |
47 | // Allows a test harness to pass its own message loop (typically | ||||
48 | // base::MessageLoopForUI::current()), rather than have | ||||
49 | // TestExtensionEnvironment create and own a TestBrowserThreadBundle. | ||||
50 | explicit TestExtensionEnvironment(base::MessageLoopForUI* message_loop); | ||||
51 | |||||
[email protected] | 11d42c8 | 2013-02-01 00:14:32 | [diff] [blame] | 52 | ~TestExtensionEnvironment(); |
53 | |||||
[email protected] | e0ec3cb1 | 2013-04-03 17:35:30 | [diff] [blame] | 54 | TestingProfile* profile() const; |
[email protected] | 11d42c8 | 2013-02-01 00:14:32 | [diff] [blame] | 55 | |
[email protected] | 94cf31c | 2013-12-07 03:58:32 | [diff] [blame] | 56 | // Returns the TestExtensionSystem created by the TestingProfile. |
57 | TestExtensionSystem* GetExtensionSystem(); | ||||
58 | |||||
[email protected] | 11d42c8 | 2013-02-01 00:14:32 | [diff] [blame] | 59 | // Returns an ExtensionService created (and owned) by the |
60 | // TestExtensionSystem created by the TestingProfile. | ||||
61 | ExtensionService* GetExtensionService(); | ||||
62 | |||||
[email protected] | 94cf31c | 2013-12-07 03:58:32 | [diff] [blame] | 63 | // Returns ExtensionPrefs created (and owned) by the |
64 | // TestExtensionSystem created by the TestingProfile. | ||||
65 | ExtensionPrefs* GetExtensionPrefs(); | ||||
66 | |||||
[email protected] | 11d42c8 | 2013-02-01 00:14:32 | [diff] [blame] | 67 | // Creates an Extension and registers it with the ExtensionService. |
68 | // The Extension has a default manifest of {name: "Extension", | ||||
69 | // version: "1.0", manifest_version: 2}, and values in | ||||
70 | // manifest_extra override these defaults. | ||||
[email protected] | e0ec3cb1 | 2013-04-03 17:35:30 | [diff] [blame] | 71 | const Extension* MakeExtension(const base::Value& manifest_extra); |
[email protected] | 11d42c8 | 2013-02-01 00:14:32 | [diff] [blame] | 72 | |
jackhou | c587f30 | 2015-04-13 08:16:39 | [diff] [blame] | 73 | // Use a specific extension ID instead of the default generated in |
74 | // Extension::Create. | ||||
75 | const Extension* MakeExtension(const base::Value& manifest_extra, | ||||
76 | const std::string& id); | ||||
77 | |||||
tapted | c7bd3ce | 2015-06-16 02:50:44 | [diff] [blame] | 78 | // Generates a valid packaged app manifest with the given ID. If |install| |
79 | // it gets added to the ExtensionService in |profile|. | ||||
80 | scoped_refptr<Extension> MakePackagedApp(const std::string& id, bool install); | ||||
81 | |||||
[email protected] | 11d42c8 | 2013-02-01 00:14:32 | [diff] [blame] | 82 | // Returns a test web contents that has a tab id. |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame^] | 83 | std::unique_ptr<content::WebContents> MakeTab() const; |
[email protected] | 11d42c8 | 2013-02-01 00:14:32 | [diff] [blame] | 84 | |
tapted | c7bd3ce | 2015-06-16 02:50:44 | [diff] [blame] | 85 | // Deletes the testing profile to test profile teardown. |
86 | void DeleteProfile(); | ||||
87 | |||||
[email protected] | 11d42c8 | 2013-02-01 00:14:32 | [diff] [blame] | 88 | private: |
tapted | dfd8eda | 2015-08-04 09:15:23 | [diff] [blame] | 89 | class ChromeOSEnv; |
[email protected] | 11d42c8 | 2013-02-01 00:14:32 | [diff] [blame] | 90 | |
tapted | dfd8eda | 2015-08-04 09:15:23 | [diff] [blame] | 91 | void Init(); |
92 | |||||
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame^] | 93 | std::unique_ptr<content::TestBrowserThreadBundle> thread_bundle_; |
94 | std::unique_ptr<ChromeOSEnv> chromeos_env_; | ||||
[email protected] | 363f527 | 2013-04-23 17:21:42 | [diff] [blame] | 95 | |
[email protected] | 11d42c8 | 2013-02-01 00:14:32 | [diff] [blame] | 96 | #if defined(OS_WIN) |
97 | ui::ScopedOleInitializer ole_initializer_; | ||||
98 | #endif | ||||
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame^] | 99 | std::unique_ptr<TestingProfile> profile_; |
[email protected] | 11d42c8 | 2013-02-01 00:14:32 | [diff] [blame] | 100 | ExtensionService* extension_service_; |
tapted | c7bd3ce | 2015-06-16 02:50:44 | [diff] [blame] | 101 | |
102 | DISALLOW_COPY_AND_ASSIGN(TestExtensionEnvironment); | ||||
[email protected] | 11d42c8 | 2013-02-01 00:14:32 | [diff] [blame] | 103 | }; |
104 | |||||
105 | } // namespace extensions | ||||
106 | |||||
107 | #endif // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_ENVIRONMENT_H_ |