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.h"
11
12#if defined(OS_CHROMEOS)
13#include "chrome/browser/chromeos/login/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
22class ExtensionService;
23class TestingProfile;
24
25namespace base {
26class Value;
27}
28
29namespace content {
30class WebContents;
31}
32
33namespace extensions {
34
35class Extension;
36
37// This class provides a minimal environment in which to create
38// extensions and tabs for extension-related unittests.
39class TestExtensionEnvironment {
40 public:
41  TestExtensionEnvironment();
42  ~TestExtensionEnvironment();
43
44  TestingProfile* profile() const;
45
46  // Returns an ExtensionService created (and owned) by the
47  // TestExtensionSystem created by the TestingProfile.
48  ExtensionService* GetExtensionService();
49
50  // Creates an Extension and registers it with the ExtensionService.
51  // The Extension has a default manifest of {name: "Extension",
52  // version: "1.0", manifest_version: 2}, and values in
53  // manifest_extra override these defaults.
54  const Extension* MakeExtension(const base::Value& manifest_extra);
55
56  // Returns a test web contents that has a tab id.
57  scoped_ptr<content::WebContents> MakeTab() const;
58
59 private:
60  base::MessageLoopForUI loop_;
61  content::TestBrowserThread ui_thread_;
62  content::TestBrowserThread file_thread_;
63  content::TestBrowserThread file_blocking_thread_;
64  content::TestBrowserThread io_thread_;
65  // We may need to add the rest of the browser threads here.  This is
66  // likely to be indicated by memory leaks in which the object was
67  // expected to be freed by a DeleteSoon() call.
68
69#if defined(OS_CHROMEOS)
70  chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
71  chromeos::ScopedTestCrosSettings test_cros_settings_;
72  chromeos::ScopedTestUserManager test_user_manager_;
73#endif
74
75#if defined(OS_WIN)
76  ui::ScopedOleInitializer ole_initializer_;
77#endif
78  scoped_ptr<TestingProfile> profile_;
79  ExtensionService* extension_service_;
80};
81
82}  // namespace extensions
83
84#endif  // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_ENVIRONMENT_H_
85