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

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

Issue 10828032: Add DeviceSettingsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
6
7 #include "base/message_loop.h"
8 #include "base/threading/sequenced_worker_pool.h"
9 #include "chrome/browser/chromeos/settings/device_settings_service.h"
10 #include "chrome/browser/chromeos/settings/mock_owner_key_util.h"
11 #include "content/public/browser/browser_thread.h"
12
13 namespace chromeos {
14
15 DeviceSettingsTestHelper::DeviceSettingsTestHelper()
16 : store_result_(true) {}
17
18 DeviceSettingsTestHelper::~DeviceSettingsTestHelper() {}
19
20 void DeviceSettingsTestHelper::FlushLoops() {
21 // DeviceSettingsService may trigger operations that hop back and forth
22 // between the message loop and the blocking pool. 2 iterations are currently
23 // sufficient (key loading, signing).
24 for (int i = 0; i < 2; ++i) {
25 MessageLoop::current()->RunAllPending();
26 content::BrowserThread::GetBlockingPool()->FlushForTesting();
27 }
28 MessageLoop::current()->RunAllPending();
29 }
30
31 void DeviceSettingsTestHelper::FlushStore() {
32 std::vector<StorePolicyCallback> callbacks;
33 callbacks.swap(store_callbacks_);
34 for (std::vector<StorePolicyCallback>::iterator cb(callbacks.begin());
35 cb != callbacks.end(); ++cb) {
36 cb->Run(store_result_);
37 }
38 }
39
40 void DeviceSettingsTestHelper::FlushRetrieve() {
41 std::vector<RetrievePolicyCallback> callbacks;
42 callbacks.swap(retrieve_callbacks_);
43 for (std::vector<RetrievePolicyCallback>::iterator cb(callbacks.begin());
44 cb != callbacks.end(); ++cb) {
45 cb->Run(policy_blob_);
46 }
47 }
48
49 void DeviceSettingsTestHelper::Flush() {
50 do {
51 FlushLoops();
52 FlushStore();
53 FlushLoops();
54 FlushRetrieve();
55 FlushLoops();
56 } while (!store_callbacks_.empty() || !retrieve_callbacks_.empty());
57 }
58
59 void DeviceSettingsTestHelper::AddObserver(Observer* observer) {}
60
61 void DeviceSettingsTestHelper::RemoveObserver(Observer* observer) {}
62
63 bool DeviceSettingsTestHelper::HasObserver(Observer* observer) {
64 return false;
65 }
66
67 void DeviceSettingsTestHelper::EmitLoginPromptReady() {}
68
69 void DeviceSettingsTestHelper::EmitLoginPromptVisible() {}
70
71 void DeviceSettingsTestHelper::RestartJob(int pid,
72 const std::string& command_line) {}
73
74 void DeviceSettingsTestHelper::RestartEntd() {}
75
76 void DeviceSettingsTestHelper::StartSession(const std::string& user_email) {}
77
78 void DeviceSettingsTestHelper::StopSession() {}
79
80 void DeviceSettingsTestHelper::RequestLockScreen() {}
81
82 void DeviceSettingsTestHelper::RequestUnlockScreen() {}
83
84 bool DeviceSettingsTestHelper::GetIsScreenLocked() {
85 return false;
86 }
87
88 void DeviceSettingsTestHelper::RetrieveDevicePolicy(
89 const RetrievePolicyCallback& callback) {
90 retrieve_callbacks_.push_back(callback);
91 }
92
93 void DeviceSettingsTestHelper::RetrieveUserPolicy(
94 const RetrievePolicyCallback& callback) {
95 }
96
97 void DeviceSettingsTestHelper::StoreDevicePolicy(
98 const std::string& policy_blob,
99 const StorePolicyCallback& callback) {
100 policy_blob_ = policy_blob;
101 store_callbacks_.push_back(callback);
102 }
103
104 void DeviceSettingsTestHelper::StoreUserPolicy(
105 const std::string& policy_blob,
106 const StorePolicyCallback& callback) {}
107
108 ScopedDeviceSettingsTestHelper::ScopedDeviceSettingsTestHelper() {
109 DeviceSettingsService::Get()->Initialize(this, new MockOwnerKeyUtil());
110 DeviceSettingsService::Get()->Load();
111 Flush();
112 }
113
114 ScopedDeviceSettingsTestHelper::~ScopedDeviceSettingsTestHelper() {
115 Flush();
116 DeviceSettingsService::Get()->Shutdown();
117 }
118
119 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/settings/device_settings_test_helper.h ('k') | chrome/browser/chromeos/settings/mock_owner_key_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698