OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef EXTENSIONS_BROWSER_EXTENSIONS_TEST_H_ | 5 #ifndef EXTENSIONS_BROWSER_EXTENSIONS_TEST_H_ |
6 #define EXTENSIONS_BROWSER_EXTENSIONS_TEST_H_ | 6 #define EXTENSIONS_BROWSER_EXTENSIONS_TEST_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "content/public/test/test_content_client_initializer.h" | 12 #include "content/public/test/test_content_client_initializer.h" |
13 #include "content/public/test/test_renderer_host.h" | 13 #include "content/public/test/test_renderer_host.h" |
14 #include "extensions/browser/mock_extension_system.h" | 14 #include "extensions/browser/mock_extension_system.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
| 17 class ExtensionPrefValueMap; |
| 18 class PrefService; |
| 19 |
17 namespace content { | 20 namespace content { |
18 class BrowserContext; | 21 class BrowserContext; |
19 class ContentBrowserClient; | 22 class ContentBrowserClient; |
20 class ContentUtilityClient; | 23 class ContentUtilityClient; |
21 class RenderViewHostTestEnabler; | 24 class RenderViewHostTestEnabler; |
22 } | 25 } |
23 | 26 |
24 namespace extensions { | 27 namespace extensions { |
25 class TestExtensionsBrowserClient; | 28 class TestExtensionsBrowserClient; |
26 | 29 |
27 // Base class for extensions module unit tests of browser process code. Sets up | 30 // Base class for extensions module unit tests of browser process code. Sets up |
28 // the content module and extensions module client interfaces. Initializes | 31 // the content module and extensions module client interfaces. Initializes |
29 // services for a browser context. | 32 // services for a browser context. |
30 // | 33 // |
31 // NOTE: Use this class only in extensions_unittests, not in Chrome unit_tests. | 34 // NOTE: Use this class only in extensions_unittests, not in Chrome unit_tests. |
32 // BrowserContextKeyedServiceFactory singletons persist between tests. | 35 // BrowserContextKeyedServiceFactory singletons persist between tests. |
33 // In Chrome those factories assume any BrowserContext is a Profile and will | 36 // In Chrome those factories assume any BrowserContext is a Profile and will |
34 // cause crashes if it is not. http://crbug.com/395820 | 37 // cause crashes if it is not. http://crbug.com/395820 |
35 class ExtensionsTest : public testing::Test { | 38 class ExtensionsTest : public testing::Test { |
36 public: | 39 public: |
37 ExtensionsTest(); | 40 ExtensionsTest(); |
38 ~ExtensionsTest() override; | 41 ~ExtensionsTest() override; |
39 | 42 |
40 // Returned as a BrowserContext since most users don't need methods from | 43 // Returned as a BrowserContext since most users don't need methods from |
41 // TestBrowserContext. | 44 // TestBrowserContext. |
42 content::BrowserContext* browser_context() { return browser_context_.get(); } | 45 content::BrowserContext* browser_context() { return browser_context_.get(); } |
43 | 46 |
| 47 // Returns the incognito context associated with the ExtensionsBrowserClient. |
| 48 content::BrowserContext* incognito_context() { |
| 49 return incognito_context_.get(); |
| 50 } |
| 51 |
44 // Returned as a TestExtensionsBrowserClient since most users need to call | 52 // Returned as a TestExtensionsBrowserClient since most users need to call |
45 // test-specific methods on it. | 53 // test-specific methods on it. |
46 TestExtensionsBrowserClient* extensions_browser_client() { | 54 TestExtensionsBrowserClient* extensions_browser_client() { |
47 return extensions_browser_client_.get(); | 55 return extensions_browser_client_.get(); |
48 } | 56 } |
49 | 57 |
| 58 PrefService* pref_service() { return pref_service_.get(); } |
| 59 |
50 // testing::Test overrides: | 60 // testing::Test overrides: |
51 void SetUp() override; | 61 void SetUp() override; |
52 void TearDown() override; | 62 void TearDown() override; |
53 | 63 |
54 private: | 64 private: |
55 content::TestContentClientInitializer content_client_initializer_; | 65 content::TestContentClientInitializer content_client_initializer_; |
56 std::unique_ptr<content::ContentBrowserClient> content_browser_client_; | 66 std::unique_ptr<content::ContentBrowserClient> content_browser_client_; |
57 std::unique_ptr<content::ContentUtilityClient> content_utility_client_; | 67 std::unique_ptr<content::ContentUtilityClient> content_utility_client_; |
58 std::unique_ptr<content::BrowserContext> browser_context_; | 68 std::unique_ptr<content::BrowserContext> browser_context_; |
| 69 std::unique_ptr<content::BrowserContext> incognito_context_; |
59 std::unique_ptr<TestExtensionsBrowserClient> extensions_browser_client_; | 70 std::unique_ptr<TestExtensionsBrowserClient> extensions_browser_client_; |
| 71 std::unique_ptr<ExtensionPrefValueMap> extension_pref_value_map_; |
| 72 std::unique_ptr<PrefService> pref_service_; |
60 | 73 |
61 // The existence of this object enables tests via | 74 // The existence of this object enables tests via |
62 // RenderViewHostTester. | 75 // RenderViewHostTester. |
63 content::RenderViewHostTestEnabler rvh_test_enabler_; | 76 content::RenderViewHostTestEnabler rvh_test_enabler_; |
64 | 77 |
65 MockExtensionSystemFactory<MockExtensionSystem> extension_system_factory_; | 78 MockExtensionSystemFactory<MockExtensionSystem> extension_system_factory_; |
66 | 79 |
67 DISALLOW_COPY_AND_ASSIGN(ExtensionsTest); | 80 DISALLOW_COPY_AND_ASSIGN(ExtensionsTest); |
68 }; | 81 }; |
69 | 82 |
70 } // namespace extensions | 83 } // namespace extensions |
71 | 84 |
72 #endif // EXTENSIONS_BROWSER_EXTENSIONS_TEST_H_ | 85 #endif // EXTENSIONS_BROWSER_EXTENSIONS_TEST_H_ |
OLD | NEW |