blob: 889452bb38debe28ec820dc3fd0922adb9c95352 [file] [log] [blame]
[email protected]11d42c82013-02-01 00:14:321// 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
dchengc963c7142016-04-08 03:55:228#include <memory>
9
avia2f4804a2015-12-24 23:11:1310#include "base/macros.h"
[email protected]b19fe572013-07-18 04:54:2611#include "base/message_loop/message_loop.h"
avia2f4804a2015-12-24 23:11:1312#include "build/build_config.h"
[email protected]11d42c82013-02-01 00:14:3213
[email protected]9a68d3a2013-04-22 16:26:5414#if defined(OS_WIN)
15#include "ui/base/win/scoped_ole_initializer.h"
[email protected]79bac422013-04-22 15:44:2616#endif
17
[email protected]11d42c82013-02-01 00:14:3218class ExtensionService;
[email protected]e0ec3cb12013-04-03 17:35:3019class TestingProfile;
20
21namespace base {
22class Value;
23}
[email protected]11d42c82013-02-01 00:14:3224
25namespace content {
26class WebContents;
taptedc7bd3ce2015-06-16 02:50:4427class TestBrowserThreadBundle;
[email protected]11d42c82013-02-01 00:14:3228}
29
30namespace extensions {
31
32class Extension;
[email protected]94cf31c2013-12-07 03:58:3233class ExtensionPrefs;
34class TestExtensionSystem;
[email protected]11d42c82013-02-01 00:14:3235
36// This class provides a minimal environment in which to create
37// extensions and tabs for extension-related unittests.
38class TestExtensionEnvironment {
39 public:
taptedc7bd3ce2015-06-16 02:50:4440 // Fetches the TestExtensionSystem in |profile| and creates a default
41 // ExtensionService there,
42 static ExtensionService* CreateExtensionServiceForProfile(
43 TestingProfile* profile);
44
[email protected]11d42c82013-02-01 00:14:3245 TestExtensionEnvironment();
taptedc7bd3ce2015-06-16 02:50:4446
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]11d42c82013-02-01 00:14:3252 ~TestExtensionEnvironment();
53
[email protected]e0ec3cb12013-04-03 17:35:3054 TestingProfile* profile() const;
[email protected]11d42c82013-02-01 00:14:3255
[email protected]94cf31c2013-12-07 03:58:3256 // Returns the TestExtensionSystem created by the TestingProfile.
57 TestExtensionSystem* GetExtensionSystem();
58
[email protected]11d42c82013-02-01 00:14:3259 // Returns an ExtensionService created (and owned) by the
60 // TestExtensionSystem created by the TestingProfile.
61 ExtensionService* GetExtensionService();
62
[email protected]94cf31c2013-12-07 03:58:3263 // Returns ExtensionPrefs created (and owned) by the
64 // TestExtensionSystem created by the TestingProfile.
65 ExtensionPrefs* GetExtensionPrefs();
66
[email protected]11d42c82013-02-01 00:14:3267 // 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]e0ec3cb12013-04-03 17:35:3071 const Extension* MakeExtension(const base::Value& manifest_extra);
[email protected]11d42c82013-02-01 00:14:3272
jackhouc587f302015-04-13 08:16:3973 // 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
taptedc7bd3ce2015-06-16 02:50:4478 // 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]11d42c82013-02-01 00:14:3282 // Returns a test web contents that has a tab id.
dchengc963c7142016-04-08 03:55:2283 std::unique_ptr<content::WebContents> MakeTab() const;
[email protected]11d42c82013-02-01 00:14:3284
taptedc7bd3ce2015-06-16 02:50:4485 // Deletes the testing profile to test profile teardown.
86 void DeleteProfile();
87
[email protected]11d42c82013-02-01 00:14:3288 private:
tapteddfd8eda2015-08-04 09:15:2389 class ChromeOSEnv;
[email protected]11d42c82013-02-01 00:14:3290
tapteddfd8eda2015-08-04 09:15:2391 void Init();
92
dchengc963c7142016-04-08 03:55:2293 std::unique_ptr<content::TestBrowserThreadBundle> thread_bundle_;
94 std::unique_ptr<ChromeOSEnv> chromeos_env_;
[email protected]363f5272013-04-23 17:21:4295
[email protected]11d42c82013-02-01 00:14:3296#if defined(OS_WIN)
97 ui::ScopedOleInitializer ole_initializer_;
98#endif
dchengc963c7142016-04-08 03:55:2299 std::unique_ptr<TestingProfile> profile_;
[email protected]11d42c82013-02-01 00:14:32100 ExtensionService* extension_service_;
taptedc7bd3ce2015-06-16 02:50:44101
102 DISALLOW_COPY_AND_ASSIGN(TestExtensionEnvironment);
[email protected]11d42c82013-02-01 00:14:32103};
104
105} // namespace extensions
106
107#endif // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_ENVIRONMENT_H_