| 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 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | 5 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/threading/sequenced_worker_pool.h" | 9 #include "base/threading/sequenced_worker_pool.h" |
| 10 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 10 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 // sufficient (key loading, signing). | 24 // sufficient (key loading, signing). |
| 25 for (int i = 0; i < 2; ++i) { | 25 for (int i = 0; i < 2; ++i) { |
| 26 MessageLoop::current()->RunUntilIdle(); | 26 MessageLoop::current()->RunUntilIdle(); |
| 27 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 27 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 28 } | 28 } |
| 29 MessageLoop::current()->RunUntilIdle(); | 29 MessageLoop::current()->RunUntilIdle(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void DeviceSettingsTestHelper::FlushStore() { | 32 void DeviceSettingsTestHelper::FlushStore() { |
| 33 std::vector<StorePolicyCallback> callbacks; | 33 std::vector<StorePolicyCallback> callbacks; |
| 34 callbacks.swap(device_policy_.store_callbacks_); | 34 callbacks.swap(policy_state_.store_callbacks_); |
| 35 for (std::vector<StorePolicyCallback>::iterator cb(callbacks.begin()); | 35 for (std::vector<StorePolicyCallback>::iterator cb(callbacks.begin()); |
| 36 cb != callbacks.end(); ++cb) { | 36 cb != callbacks.end(); ++cb) { |
| 37 cb->Run(device_policy_.store_result_); | 37 cb->Run(policy_state_.store_result_); |
| 38 } | 38 } |
| 39 | 39 |
| 40 std::map<std::string, PolicyState>::iterator device_local_account_state; | 40 std::map<std::string, PolicyState>::iterator device_local_account_state; |
| 41 for (device_local_account_state = device_local_account_policy_.begin(); | 41 for (device_local_account_state = device_local_account_policy_.begin(); |
| 42 device_local_account_state != device_local_account_policy_.end(); | 42 device_local_account_state != device_local_account_policy_.end(); |
| 43 ++device_local_account_state) { | 43 ++device_local_account_state) { |
| 44 callbacks.swap(device_local_account_state->second.store_callbacks_); | 44 callbacks.swap(device_local_account_state->second.store_callbacks_); |
| 45 for (std::vector<StorePolicyCallback>::iterator cb(callbacks.begin()); | 45 for (std::vector<StorePolicyCallback>::iterator cb(callbacks.begin()); |
| 46 cb != callbacks.end(); ++cb) { | 46 cb != callbacks.end(); ++cb) { |
| 47 cb->Run(device_local_account_state->second.store_result_); | 47 cb->Run(device_local_account_state->second.store_result_); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 void DeviceSettingsTestHelper::FlushRetrieve() { | 52 void DeviceSettingsTestHelper::FlushRetrieve() { |
| 53 std::vector<RetrievePolicyCallback> callbacks; | 53 std::vector<RetrievePolicyCallback> callbacks; |
| 54 callbacks.swap(device_policy_.retrieve_callbacks_); | 54 callbacks.swap(policy_state_.retrieve_callbacks_); |
| 55 for (std::vector<RetrievePolicyCallback>::iterator cb(callbacks.begin()); | 55 for (std::vector<RetrievePolicyCallback>::iterator cb(callbacks.begin()); |
| 56 cb != callbacks.end(); ++cb) { | 56 cb != callbacks.end(); ++cb) { |
| 57 cb->Run(device_policy_.policy_blob_); | 57 cb->Run(policy_state_.policy_blob_); |
| 58 } | 58 } |
| 59 | 59 |
| 60 std::map<std::string, PolicyState>::iterator device_local_account_state; | 60 std::map<std::string, PolicyState>::iterator device_local_account_state; |
| 61 for (device_local_account_state = device_local_account_policy_.begin(); | 61 for (device_local_account_state = device_local_account_policy_.begin(); |
| 62 device_local_account_state != device_local_account_policy_.end(); | 62 device_local_account_state != device_local_account_policy_.end(); |
| 63 ++device_local_account_state) { | 63 ++device_local_account_state) { |
| 64 callbacks.swap(device_local_account_state->second.retrieve_callbacks_); | 64 callbacks.swap(device_local_account_state->second.retrieve_callbacks_); |
| 65 for (std::vector<RetrievePolicyCallback>::iterator cb(callbacks.begin()); | 65 for (std::vector<RetrievePolicyCallback>::iterator cb(callbacks.begin()); |
| 66 cb != callbacks.end(); ++cb) { | 66 cb != callbacks.end(); ++cb) { |
| 67 cb->Run(device_local_account_state->second.policy_blob_); | 67 cb->Run(device_local_account_state->second.policy_blob_); |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 void DeviceSettingsTestHelper::Flush() { | 72 void DeviceSettingsTestHelper::Flush() { |
| 73 do { | 73 do { |
| 74 FlushLoops(); | 74 FlushLoops(); |
| 75 FlushStore(); | 75 FlushStore(); |
| 76 FlushLoops(); | 76 FlushLoops(); |
| 77 FlushRetrieve(); | 77 FlushRetrieve(); |
| 78 FlushLoops(); | 78 FlushLoops(); |
| 79 } while (HasPendingOperations()); | 79 } while (HasPendingOperations()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 bool DeviceSettingsTestHelper::HasPendingOperations() const { | 82 bool DeviceSettingsTestHelper::HasPendingOperations() const { |
| 83 if (device_policy_.HasPendingOperations()) | 83 if (policy_state_.HasPendingOperations()) |
| 84 return true; | 84 return true; |
| 85 | 85 |
| 86 std::map<std::string, PolicyState>::const_iterator device_local_account_state; | 86 std::map<std::string, PolicyState>::const_iterator device_local_account_state; |
| 87 for (device_local_account_state = device_local_account_policy_.begin(); | 87 for (device_local_account_state = device_local_account_policy_.begin(); |
| 88 device_local_account_state != device_local_account_policy_.end(); | 88 device_local_account_state != device_local_account_policy_.end(); |
| 89 ++device_local_account_state) { | 89 ++device_local_account_state) { |
| 90 if (device_local_account_state->second.HasPendingOperations()) | 90 if (device_local_account_state->second.HasPendingOperations()) |
| 91 return true; | 91 return true; |
| 92 } | 92 } |
| 93 | 93 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 120 void DeviceSettingsTestHelper::RequestLockScreen() {} | 120 void DeviceSettingsTestHelper::RequestLockScreen() {} |
| 121 | 121 |
| 122 void DeviceSettingsTestHelper::NotifyLockScreenShown() {} | 122 void DeviceSettingsTestHelper::NotifyLockScreenShown() {} |
| 123 | 123 |
| 124 void DeviceSettingsTestHelper::RequestUnlockScreen() {} | 124 void DeviceSettingsTestHelper::RequestUnlockScreen() {} |
| 125 | 125 |
| 126 void DeviceSettingsTestHelper::NotifyLockScreenDismissed() {} | 126 void DeviceSettingsTestHelper::NotifyLockScreenDismissed() {} |
| 127 | 127 |
| 128 void DeviceSettingsTestHelper::RetrieveDevicePolicy( | 128 void DeviceSettingsTestHelper::RetrieveDevicePolicy( |
| 129 const RetrievePolicyCallback& callback) { | 129 const RetrievePolicyCallback& callback) { |
| 130 device_policy_.retrieve_callbacks_.push_back(callback); | 130 policy_state_.retrieve_callbacks_.push_back(callback); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void DeviceSettingsTestHelper::RetrieveUserPolicy( | 133 void DeviceSettingsTestHelper::RetrieveUserPolicy( |
| 134 const RetrievePolicyCallback& callback) { | 134 const RetrievePolicyCallback& callback) { |
| 135 } | 135 } |
| 136 | 136 |
| 137 void DeviceSettingsTestHelper::RetrieveDeviceLocalAccountPolicy( | 137 void DeviceSettingsTestHelper::RetrieveDeviceLocalAccountPolicy( |
| 138 const std::string& account_id, | 138 const std::string& account_id, |
| 139 const RetrievePolicyCallback& callback) { | 139 const RetrievePolicyCallback& callback) { |
| 140 device_local_account_policy_[account_id].retrieve_callbacks_.push_back( | 140 device_local_account_policy_[account_id].retrieve_callbacks_.push_back( |
| 141 callback); | 141 callback); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void DeviceSettingsTestHelper::StoreDevicePolicy( | 144 void DeviceSettingsTestHelper::StoreDevicePolicy( |
| 145 const std::string& policy_blob, | 145 const std::string& policy_blob, |
| 146 const StorePolicyCallback& callback) { | 146 const StorePolicyCallback& callback) { |
| 147 device_policy_.policy_blob_ = policy_blob; | 147 policy_state_.policy_blob_ = policy_blob; |
| 148 device_policy_.store_callbacks_.push_back(callback); | 148 policy_state_.store_callbacks_.push_back(callback); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void DeviceSettingsTestHelper::StoreUserPolicy( | 151 void DeviceSettingsTestHelper::StoreUserPolicy( |
| 152 const std::string& policy_blob, | 152 const std::string& policy_blob, |
| 153 const StorePolicyCallback& callback) { | 153 const StorePolicyCallback& callback) { |
| 154 } | 154 } |
| 155 | 155 |
| 156 void DeviceSettingsTestHelper::StoreDeviceLocalAccountPolicy( | 156 void DeviceSettingsTestHelper::StoreDeviceLocalAccountPolicy( |
| 157 const std::string& account_id, | 157 const std::string& account_id, |
| 158 const std::string& policy_blob, | 158 const std::string& policy_blob, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 void DeviceSettingsTestBase::FlushDeviceSettings() { | 207 void DeviceSettingsTestBase::FlushDeviceSettings() { |
| 208 device_settings_test_helper_.Flush(); | 208 device_settings_test_helper_.Flush(); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void DeviceSettingsTestBase::ReloadDeviceSettings() { | 211 void DeviceSettingsTestBase::ReloadDeviceSettings() { |
| 212 device_settings_service_.OwnerKeySet(true); | 212 device_settings_service_.OwnerKeySet(true); |
| 213 FlushDeviceSettings(); | 213 FlushDeviceSettings(); |
| 214 } | 214 } |
| 215 | 215 |
| 216 } // namespace chromeos | 216 } // namespace chromeos |
| OLD | NEW |