OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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_EXTENSION_SERVICE_UNITTEST_H_ | |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_UNITTEST_H_ | |
7 | |
8 #include "base/at_exit.h" | |
9 #include "base/files/file_path.h" | |
10 #include "base/files/scoped_temp_dir.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/message_loop/message_loop.h" | |
14 #include "chrome/browser/extensions/extension_service.h" | |
15 #include "content/public/test/test_browser_thread_bundle.h" | |
16 #include "content/public/test/test_utils.h" | |
17 #include "extensions/common/feature_switch.h" | |
18 #include "testing/gtest/include/gtest/gtest.h" | |
19 | |
20 #if defined(OS_CHROMEOS) | |
21 #include "chrome/browser/chromeos/login/users/user_manager.h" | |
22 #include "chrome/browser/chromeos/settings/cros_settings.h" | |
23 #include "chrome/browser/chromeos/settings/device_settings_service.h" | |
24 #endif | |
25 | |
26 class TestingProfile; | |
27 | |
28 namespace extensions { | |
29 class ManagementPolicy; | |
30 } | |
31 | |
32 class ExtensionServiceTestBase : public testing::Test { | |
33 public: | |
34 struct ExtensionServiceInitParams { | |
35 base::FilePath profile_path; | |
36 base::FilePath pref_file; | |
37 base::FilePath extensions_install_dir; | |
38 bool autoupdate_enabled; | |
39 bool is_first_run; | |
40 bool profile_is_managed; | |
41 | |
42 ExtensionServiceInitParams(); | |
43 }; | |
44 | |
45 ExtensionServiceTestBase(); | |
46 virtual ~ExtensionServiceTestBase(); | |
47 | |
48 void InitializeExtensionService(const ExtensionServiceInitParams& params); | |
49 | |
50 static scoped_ptr<TestingProfile> CreateTestingProfile( | |
51 const ExtensionServiceInitParams& params); | |
52 | |
53 static ExtensionService* InitializeExtensionServiceForProfile( | |
54 const ExtensionServiceInitParams& params, | |
55 Profile* profile); | |
56 | |
57 void InitializeInstalledExtensionService( | |
58 const base::FilePath& prefs_file, | |
59 const base::FilePath& source_install_dir); | |
60 | |
61 void InitializeGoodInstalledExtensionService(); | |
62 | |
63 void InitializeEmptyExtensionService(); | |
64 | |
65 void InitializeProcessManager(); | |
66 | |
67 void InitializeExtensionServiceWithUpdater(); | |
68 | |
69 void InitializeExtensionSyncService(); | |
70 | |
71 static void SetUpTestCase(); | |
72 | |
73 virtual void SetUp() OVERRIDE; | |
74 virtual void TearDown() OVERRIDE; | |
75 | |
76 void set_extensions_enabled(bool enabled) { | |
77 service_->set_extensions_enabled(enabled); | |
78 } | |
79 | |
80 protected: | |
81 ExtensionServiceInitParams CreateDefaultInitParams(); | |
82 static ExtensionServiceInitParams CreateDefaultInitParamsInTempDir( | |
83 base::ScopedTempDir* temp_dir); | |
84 | |
85 // Destroy temp_dir_ after thread_bundle_ so clean-up tasks can still use the | |
86 // directory. | |
87 base::ScopedTempDir temp_dir_; | |
88 // Destroying at_exit_manager_ will delete all LazyInstances, so it must come | |
89 // after thread_bundle_ in the destruction order. | |
90 base::ShadowingAtExitManager at_exit_manager_; | |
91 content::TestBrowserThreadBundle thread_bundle_; | |
92 scoped_ptr<TestingProfile> profile_; | |
93 base::FilePath extensions_install_dir_; | |
94 base::FilePath data_dir_; | |
95 // Managed by extensions::ExtensionSystemFactory. | |
96 ExtensionService* service_; | |
97 extensions::ManagementPolicy* management_policy_; | |
98 scoped_ptr<ExtensionSyncService> extension_sync_service_; | |
99 size_t expected_extensions_count_; | |
100 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; | |
101 | |
102 extensions::ExtensionRegistry* registry_; | |
103 | |
104 #if defined OS_CHROMEOS | |
105 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | |
106 chromeos::ScopedTestCrosSettings test_cros_settings_; | |
107 chromeos::ScopedTestUserManager test_user_manager_; | |
108 #endif | |
109 }; | |
110 | |
111 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_UNITTEST_H_ | |
OLD | NEW |