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