Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: chrome/browser/chromeos/settings/device_settings_test_helper.cc

Issue 409743003: Use content::RunBlockingPoolTask() in tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/message_loop.h" 7 #include "base/message_loop/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/ownership/owner_settings_service.h" 10 #include "chrome/browser/chromeos/ownership/owner_settings_service.h"
11 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" 11 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h"
12 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" 12 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
13 #include "chrome/browser/chromeos/profiles/profile_helper.h" 13 #include "chrome/browser/chromeos/profiles/profile_helper.h"
14 #include "chrome/browser/chromeos/settings/device_settings_service.h" 14 #include "chrome/browser/chromeos/settings/device_settings_service.h"
15 #include "chrome/test/base/testing_browser_process.h" 15 #include "chrome/test/base/testing_browser_process.h"
16 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
17 #include "chromeos/dbus/dbus_thread_manager.h" 17 #include "chromeos/dbus/dbus_thread_manager.h"
18 #include "components/ownership/mock_owner_key_util.h" 18 #include "components/ownership/mock_owner_key_util.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/test/test_utils.h"
20 21
21 namespace chromeos { 22 namespace chromeos {
22 23
23 DeviceSettingsTestHelper::DeviceSettingsTestHelper() {} 24 DeviceSettingsTestHelper::DeviceSettingsTestHelper() {}
24 25
25 DeviceSettingsTestHelper::~DeviceSettingsTestHelper() {} 26 DeviceSettingsTestHelper::~DeviceSettingsTestHelper() {}
26 27
27 void DeviceSettingsTestHelper::FlushLoops() {
28 // DeviceSettingsService may trigger operations that hop back and forth
29 // between the message loop and the blocking pool. 2 iterations are currently
30 // sufficient (key loading, signing).
31 for (int i = 0; i < 2; ++i) {
32 base::MessageLoop::current()->RunUntilIdle();
33 content::BrowserThread::GetBlockingPool()->FlushForTesting();
34 }
35 base::MessageLoop::current()->RunUntilIdle();
36 }
37
38 void DeviceSettingsTestHelper::FlushStore() { 28 void DeviceSettingsTestHelper::FlushStore() {
39 std::vector<StorePolicyCallback> callbacks; 29 std::vector<StorePolicyCallback> callbacks;
40 callbacks.swap(device_policy_.store_callbacks_); 30 callbacks.swap(device_policy_.store_callbacks_);
41 for (std::vector<StorePolicyCallback>::iterator cb(callbacks.begin()); 31 for (std::vector<StorePolicyCallback>::iterator cb(callbacks.begin());
42 cb != callbacks.end(); ++cb) { 32 cb != callbacks.end(); ++cb) {
43 cb->Run(device_policy_.store_result_); 33 cb->Run(device_policy_.store_result_);
44 } 34 }
45 35
46 std::map<std::string, PolicyState>::iterator device_local_account_state; 36 std::map<std::string, PolicyState>::iterator device_local_account_state;
47 for (device_local_account_state = device_local_account_policy_.begin(); 37 for (device_local_account_state = device_local_account_policy_.begin();
(...skipping 23 matching lines...) Expand all
71 callbacks.swap(device_local_account_state->second.retrieve_callbacks_); 61 callbacks.swap(device_local_account_state->second.retrieve_callbacks_);
72 for (std::vector<RetrievePolicyCallback>::iterator cb(callbacks.begin()); 62 for (std::vector<RetrievePolicyCallback>::iterator cb(callbacks.begin());
73 cb != callbacks.end(); ++cb) { 63 cb != callbacks.end(); ++cb) {
74 cb->Run(device_local_account_state->second.policy_blob_); 64 cb->Run(device_local_account_state->second.policy_blob_);
75 } 65 }
76 } 66 }
77 } 67 }
78 68
79 void DeviceSettingsTestHelper::Flush() { 69 void DeviceSettingsTestHelper::Flush() {
80 do { 70 do {
81 FlushLoops(); 71 content::RunAllBlockingPoolTasksUntilIdle();
82 FlushStore(); 72 FlushStore();
83 FlushLoops(); 73 content::RunAllBlockingPoolTasksUntilIdle();
84 FlushRetrieve(); 74 FlushRetrieve();
85 FlushLoops(); 75 content::RunAllBlockingPoolTasksUntilIdle();
86 } while (HasPendingOperations()); 76 } while (HasPendingOperations());
87 } 77 }
88 78
89 bool DeviceSettingsTestHelper::HasPendingOperations() const { 79 bool DeviceSettingsTestHelper::HasPendingOperations() const {
90 if (device_policy_.HasPendingOperations()) 80 if (device_policy_.HasPendingOperations())
91 return true; 81 return true;
92 82
93 std::map<std::string, PolicyState>::const_iterator device_local_account_state; 83 std::map<std::string, PolicyState>::const_iterator device_local_account_state;
94 for (device_local_account_state = device_local_account_policy_.begin(); 84 for (device_local_account_state = device_local_account_policy_.begin();
95 device_local_account_state != device_local_account_policy_.end(); 85 device_local_account_state != device_local_account_policy_.end();
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 profile_.get()); 250 profile_.get());
261 } 251 }
262 OwnerSettingsService* service = 252 OwnerSettingsService* service =
263 OwnerSettingsServiceFactory::GetForProfile(profile_.get()); 253 OwnerSettingsServiceFactory::GetForProfile(profile_.get());
264 CHECK(service); 254 CHECK(service);
265 if (tpm_is_ready) 255 if (tpm_is_ready)
266 service->OnTPMTokenReady(); 256 service->OnTPMTokenReady();
267 } 257 }
268 258
269 } // namespace chromeos 259 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698