1 // Copyright 2019 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_CHROMEOS_CROSTINI_FAKE_CROSTINI_FEATURES_H_ 6 #define CHROME_BROWSER_CHROMEOS_CROSTINI_FAKE_CROSTINI_FEATURES_H_ 7 8 #include "base/macros.h" 9 #include "base/optional.h" 10 #include "chrome/browser/chromeos/crostini/crostini_features.h" 11 12 class Profile; 13 14 namespace crostini { 15 16 // FakeCrostiniFeatures implements a fake version of CrostiniFeatures which can 17 // be used for testing. It captures the current global CrostiniFeatures object 18 // and replaces it for the scope of this object. It overrides only the 19 // features that you set and uses the previous object for other features. 20 class FakeCrostiniFeatures : public CrostiniFeatures { 21 public: 22 FakeCrostiniFeatures(); 23 ~FakeCrostiniFeatures() override; 24 25 // CrostiniFeatures: 26 bool IsAllowed(Profile* profile) override; 27 bool IsUIAllowed(Profile* profile, bool check_policy) override; 28 bool IsEnabled(Profile* profile) override; 29 bool IsExportImportUIAllowed(Profile* profile) override; 30 bool IsRootAccessAllowed(Profile* profile) override; 31 bool IsContainerUpgradeUIAllowed(Profile* profile) override; 32 void CanChangeAdbSideloading( 33 Profile* profile, 34 CanChangeAdbSideloadingCallback callback) override; 35 bool IsPortForwardingAllowed(Profile* profile) override; 36 37 void SetAll(bool flag); 38 void ClearAll(); 39 set_allowed(bool allowed)40 void set_allowed(bool allowed) { 41 allowed_ = allowed; 42 } set_ui_allowed(bool allowed)43 void set_ui_allowed(bool allowed) { 44 ui_allowed_ = allowed; 45 } set_enabled(bool enabled)46 void set_enabled(bool enabled) { 47 enabled_ = enabled; 48 } set_export_import_ui_allowed(bool allowed)49 void set_export_import_ui_allowed(bool allowed) { 50 export_import_ui_allowed_ = allowed; 51 } set_root_access_allowed(bool allowed)52 void set_root_access_allowed(bool allowed) { 53 root_access_allowed_ = allowed; 54 } set_container_upgrade_ui_allowed(bool allowed)55 void set_container_upgrade_ui_allowed(bool allowed) { 56 container_upgrade_ui_allowed_ = allowed; 57 } 58 set_can_change_adb_sideloading(bool can_change)59 void set_can_change_adb_sideloading(bool can_change) { 60 can_change_adb_sideloading_ = can_change; 61 } 62 set_port_forwarding_allowed(bool allowed)63 void set_port_forwarding_allowed(bool allowed) { 64 port_forwarding_allowed_ = allowed; 65 } 66 67 private: 68 // Original global static when this instance is created. It is captured when 69 // FakeCrostiniFeatures is created and replaced at destruction. 70 CrostiniFeatures* original_features_; 71 72 base::Optional<bool> allowed_; 73 base::Optional<bool> ui_allowed_; 74 base::Optional<bool> enabled_; 75 base::Optional<bool> export_import_ui_allowed_; 76 base::Optional<bool> root_access_allowed_; 77 base::Optional<bool> container_upgrade_ui_allowed_; 78 base::Optional<bool> can_change_adb_sideloading_; 79 base::Optional<bool> port_forwarding_allowed_; 80 }; 81 82 } // namespace crostini 83 84 #endif // CHROME_BROWSER_CHROMEOS_CROSTINI_FAKE_CROSTINI_FEATURES_H_ 85