1 // Copyright 2020 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_FORCED_EXTENSIONS_FORCE_INSTALLED_TEST_BASE_H_ 6 #define CHROME_BROWSER_EXTENSIONS_FORCED_EXTENSIONS_FORCE_INSTALLED_TEST_BASE_H_ 7 8 #include "chrome/test/base/testing_profile.h" 9 #include "chrome/test/base/testing_profile_manager.h" 10 #include "components/policy/core/common/mock_configuration_policy_provider.h" 11 #include "content/public/test/browser_task_environment.h" 12 #include "testing/gtest/include/gtest/gtest.h" 13 14 namespace sync_preferences { 15 class TestingPrefServiceSyncable; 16 } 17 18 namespace extensions { 19 20 class ExtensionRegistry; 21 class InstallStageTracker; 22 class ForceInstalledTracker; 23 24 // This class is extended by tests to provide a setup for tracking installation 25 // of force extensions. It also provides helper functions for creating and 26 // setting ExtensionInstallForcelist policy value. 27 class ForceInstalledTestBase : public testing::Test { 28 public: 29 ForceInstalledTestBase(); 30 ~ForceInstalledTestBase() override; 31 32 ForceInstalledTestBase(const ForceInstalledTestBase&) = delete; 33 ForceInstalledTestBase& operator=(const ForceInstalledTestBase&) = delete; 34 35 protected: 36 void SetUp() override; 37 38 // Creates and sets value for ExtensionInstallForcelist policy and 39 // kInstallForceList preference. |is_from_store| tells whether the extensions 40 // specified in the policy should have an update URL from CWS or not. 41 void SetupForceList(bool is_from_store); 42 43 // Creates and sets empty value for ExtensionInstallForcelist policy and 44 // kInstallForceList preference. 45 void SetupEmptyForceList(); 46 profile()47 Profile* profile() const { return profile_; } 48 prefs()49 sync_preferences::TestingPrefServiceSyncable* prefs() const { return prefs_; } 50 registry()51 ExtensionRegistry* registry() const { return registry_; } 52 install_stage_tracker()53 InstallStageTracker* install_stage_tracker() const { 54 return install_stage_tracker_; 55 } 56 force_installed_tracker()57 ForceInstalledTracker* force_installed_tracker() const { 58 return force_installed_tracker_.get(); 59 } 60 61 static const char kExtensionId1[]; 62 static const char kExtensionId2[]; 63 static const char kExtensionName1[]; 64 static const char kExtensionName2[]; 65 static const char kExtensionUpdateUrl[]; 66 static const char kOffStoreUpdateUrl[]; 67 68 content::BrowserTaskEnvironment task_environment_{ 69 base::test::TaskEnvironment::TimeSource::MOCK_TIME}; 70 71 private: 72 policy::MockConfigurationPolicyProvider policy_provider_; 73 std::unique_ptr<TestingProfileManager> profile_manager_; 74 TestingProfile* profile_; 75 sync_preferences::TestingPrefServiceSyncable* prefs_; 76 ExtensionRegistry* registry_; 77 InstallStageTracker* install_stage_tracker_; 78 std::unique_ptr<ForceInstalledTracker> force_installed_tracker_; 79 }; 80 81 } // namespace extensions 82 83 #endif // CHROME_BROWSER_EXTENSIONS_FORCED_EXTENSIONS_FORCE_INSTALLED_TEST_BASE_H_ 84