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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_UNITTEST_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_UNITTEST_H_
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"
20 #if defined(OS_CHROMEOS)
21 #include "chrome/browser/chromeos/login/user_manager.h"
22 #include "chrome/browser/chromeos/settings/cros_settings.h"
23 #include "chrome/browser/chromeos/settings/device_settings_service.h"
28 namespace extensions {
29 class ManagementPolicy;
32 class ExtensionServiceTestBase : public testing::Test {
34 struct ExtensionServiceInitParams {
35 base::FilePath profile_path;
36 base::FilePath pref_file;
37 base::FilePath extensions_install_dir;
38 bool autoupdate_enabled;
40 bool profile_is_managed;
42 ExtensionServiceInitParams();
45 ExtensionServiceTestBase();
46 virtual ~ExtensionServiceTestBase();
48 void InitializeExtensionService(const ExtensionServiceInitParams& params);
50 static scoped_ptr<TestingProfile> CreateTestingProfile(
51 const ExtensionServiceInitParams& params);
53 static ExtensionService* InitializeExtensionServiceForProfile(
54 const ExtensionServiceInitParams& params,
57 void InitializeInstalledExtensionService(
58 const base::FilePath& prefs_file,
59 const base::FilePath& source_install_dir);
61 void InitializeGoodInstalledExtensionService();
63 void InitializeEmptyExtensionService();
65 void InitializeProcessManager();
67 void InitializeExtensionServiceWithUpdater();
69 void InitializeExtensionSyncService();
71 static void SetUpTestCase();
73 virtual void SetUp() OVERRIDE;
74 virtual void TearDown() OVERRIDE;
76 void set_extensions_enabled(bool enabled) {
77 service_->set_extensions_enabled(enabled);
81 ExtensionServiceInitParams CreateDefaultInitParams();
82 static ExtensionServiceInitParams CreateDefaultInitParamsInTempDir(
83 base::ScopedTempDir* temp_dir);
85 // Destroy temp_dir_ after thread_bundle_ so clean-up tasks can still use the
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_;
102 #if defined OS_CHROMEOS
103 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
104 chromeos::ScopedTestCrosSettings test_cros_settings_;
105 chromeos::ScopedTestUserManager test_user_manager_;
109 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_UNITTEST_H_