| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_TEST_HELPER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_TEST_HELPER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_TEST_HELPER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_TEST_HELPER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 18 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 19 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 19 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 20 #include "chrome/browser/chromeos/policy/device_policy_builder.h" | 20 #include "chrome/browser/chromeos/policy/device_policy_builder.h" |
| 21 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 21 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 22 #include "chromeos/dbus/session_manager_client.h" | 22 #include "chromeos/dbus/mock_session_manager_client.h" |
| 23 #include "components/ownership/mock_owner_key_util.h" | 23 #include "components/ownership/mock_owner_key_util.h" |
| 24 #include "content/public/test/test_browser_thread_bundle.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 26 |
| 27 class TestingProfile; | 27 class TestingProfile; |
| 28 | 28 |
| 29 namespace chromeos { | 29 namespace chromeos { |
| 30 | 30 |
| 31 class DBusThreadManagerSetter; | 31 class DBusThreadManagerSetter; |
| 32 | 32 |
| 33 // A helper class for tests mocking out session_manager's device settings | 33 // A helper class for tests mocking out session_manager's device settings |
| 34 // interface. The pattern is to initialize DeviceSettingsService with the helper | 34 // interface. The pattern is to initialize DeviceSettingsService with the helper |
| 35 // for the SessionManagerClient pointer. The helper records calls made by | 35 // for the SessionManagerClient pointer. The helper records calls made by |
| 36 // DeviceSettingsService. The test can then verify state, after which it should | 36 // DeviceSettingsService. The test can then verify state, after which it should |
| 37 // call one of the Flush() variants that will resume processing. | 37 // call one of the Flush() variants that will resume processing. |
| 38 class DeviceSettingsTestHelper : public SessionManagerClient { | 38 class DeviceSettingsTestHelper : public MockSessionManagerClient { |
| 39 public: | 39 public: |
| 40 // Wraps a device settings service instance for testing. | 40 // Wraps a device settings service instance for testing. |
| 41 DeviceSettingsTestHelper(); | 41 DeviceSettingsTestHelper(); |
| 42 ~DeviceSettingsTestHelper() override; | 42 ~DeviceSettingsTestHelper() override; |
| 43 | 43 |
| 44 // Runs all pending store callbacks. | 44 // Runs all pending store callbacks. |
| 45 void FlushStore(); | 45 void FlushStore(); |
| 46 | 46 |
| 47 // Runs all pending retrieve callbacks. | 47 // Runs all pending retrieve callbacks. |
| 48 void FlushRetrieve(); | 48 void FlushRetrieve(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 74 return entry == device_local_account_policy_.end() ? | 74 return entry == device_local_account_policy_.end() ? |
| 75 base::EmptyString() : entry->second.policy_blob_; | 75 base::EmptyString() : entry->second.policy_blob_; |
| 76 } | 76 } |
| 77 | 77 |
| 78 void set_device_local_account_policy_blob(const std::string& id, | 78 void set_device_local_account_policy_blob(const std::string& id, |
| 79 const std::string& policy_blob) { | 79 const std::string& policy_blob) { |
| 80 device_local_account_policy_[id].policy_blob_ = policy_blob; | 80 device_local_account_policy_[id].policy_blob_ = policy_blob; |
| 81 } | 81 } |
| 82 | 82 |
| 83 // SessionManagerClient: | 83 // SessionManagerClient: |
| 84 void Init(dbus::Bus* bus) override; | |
| 85 void SetStubDelegate(SessionManagerClient::StubDelegate* delegate) override; | |
| 86 void AddObserver(Observer* observer) override; | |
| 87 void RemoveObserver(Observer* observer) override; | |
| 88 bool HasObserver(const Observer* observer) const override; | |
| 89 bool IsScreenLocked() const override; | |
| 90 void EmitLoginPromptVisible() override; | |
| 91 void RestartJob(int socket_fd, | |
| 92 const std::vector<std::string>& argv, | |
| 93 const VoidDBusMethodCallback& callback) override; | |
| 94 void StartSession(const cryptohome::Identification& cryptohome_id) override; | |
| 95 void StopSession() override; | |
| 96 void NotifySupervisedUserCreationStarted() override; | |
| 97 void NotifySupervisedUserCreationFinished() override; | |
| 98 void StartDeviceWipe() override; | |
| 99 void RequestLockScreen() override; | |
| 100 void NotifyLockScreenShown() override; | |
| 101 void NotifyLockScreenDismissed() override; | |
| 102 void RetrieveActiveSessions(const ActiveSessionsCallback& callback) override; | |
| 103 void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) override; | 84 void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) override; |
| 104 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id, | |
| 105 const RetrievePolicyCallback& callback) override; | |
| 106 std::string BlockingRetrievePolicyForUser( | |
| 107 const cryptohome::Identification& cryptohome_id) override; | |
| 108 void RetrieveDeviceLocalAccountPolicy( | 85 void RetrieveDeviceLocalAccountPolicy( |
| 109 const std::string& account_id, | 86 const std::string& account_id, |
| 110 const RetrievePolicyCallback& callback) override; | 87 const RetrievePolicyCallback& callback) override; |
| 111 void StoreDevicePolicy(const std::string& policy_blob, | 88 void StoreDevicePolicy(const std::string& policy_blob, |
| 112 const StorePolicyCallback& callback) override; | 89 const StorePolicyCallback& callback) override; |
| 113 void StorePolicyForUser(const cryptohome::Identification& cryptohome_id, | |
| 114 const std::string& policy_blob, | |
| 115 const StorePolicyCallback& callback) override; | |
| 116 void StoreDeviceLocalAccountPolicy( | 90 void StoreDeviceLocalAccountPolicy( |
| 117 const std::string& account_id, | 91 const std::string& account_id, |
| 118 const std::string& policy_blob, | 92 const std::string& policy_blob, |
| 119 const StorePolicyCallback& callback) override; | 93 const StorePolicyCallback& callback) override; |
| 120 bool SupportsRestartToApplyUserFlags() const override; | |
| 121 void SetFlagsForUser(const cryptohome::Identification& cryptohome_id, | |
| 122 const std::vector<std::string>& flags) override; | |
| 123 void GetServerBackedStateKeys(const StateKeysCallback& callback) override; | |
| 124 | |
| 125 void CheckArcAvailability(const ArcCallback& callback) override; | |
| 126 void StartArcInstance(const cryptohome::Identification& cryptohome_id, | |
| 127 bool disable_boot_completed_broadcast, | |
| 128 const StartArcInstanceCallback& callback) override; | |
| 129 void StopArcInstance(const ArcCallback& callback) override; | |
| 130 void SetArcCpuRestriction( | |
| 131 login_manager::ContainerCpuRestrictionState restriction_state, | |
| 132 const ArcCallback& callback) override; | |
| 133 void EmitArcBooted(const cryptohome::Identification& cryptohome_id, | |
| 134 const ArcCallback& callback) override; | |
| 135 void GetArcStartTime(const GetArcStartTimeCallback& callback) override; | |
| 136 void RemoveArcData(const cryptohome::Identification& cryptohome_id, | |
| 137 const ArcCallback& callback) override; | |
| 138 | 94 |
| 139 private: | 95 private: |
| 140 struct PolicyState { | 96 struct PolicyState { |
| 141 bool store_result_; | 97 bool store_result_; |
| 142 std::string policy_blob_; | 98 std::string policy_blob_; |
| 143 std::vector<StorePolicyCallback> store_callbacks_; | 99 std::vector<StorePolicyCallback> store_callbacks_; |
| 144 std::vector<RetrievePolicyCallback> retrieve_callbacks_; | 100 std::vector<RetrievePolicyCallback> retrieve_callbacks_; |
| 145 | 101 |
| 146 PolicyState(); | 102 PolicyState(); |
| 147 PolicyState(const PolicyState& other); | 103 PolicyState(const PolicyState& other); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 163 |
| 208 std::unique_ptr<DBusThreadManagerSetter> dbus_setter_; | 164 std::unique_ptr<DBusThreadManagerSetter> dbus_setter_; |
| 209 | 165 |
| 210 private: | 166 private: |
| 211 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsTestBase); | 167 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsTestBase); |
| 212 }; | 168 }; |
| 213 | 169 |
| 214 } // namespace chromeos | 170 } // namespace chromeos |
| 215 | 171 |
| 216 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_TEST_HELPER_H_ | 172 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_TEST_HELPER_H_ |
| OLD | NEW |