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

Side by Side Diff: chrome/browser/policy/device_token_fetcher_unittest.cc

Issue 9403010: Add support for kiosk mode on the client. Make sure the settings are written in the lockbox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments and added two more tests and cleaned includes. Created 8 years, 10 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/policy/device_token_fetcher.h" 5 #include "chrome/browser/policy/device_token_fetcher.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/scoped_temp_dir.h" 8 #include "base/scoped_temp_dir.h"
9 #include "chrome/browser/policy/cloud_policy_data_store.h" 9 #include "chrome/browser/policy/cloud_policy_data_store.h"
10 #include "chrome/browser/policy/logging_work_scheduler.h" 10 #include "chrome/browser/policy/logging_work_scheduler.h"
(...skipping 17 matching lines...) Expand all
28 using testing::_; 28 using testing::_;
29 29
30 class DeviceTokenFetcherTest : public testing::Test { 30 class DeviceTokenFetcherTest : public testing::Test {
31 protected: 31 protected:
32 DeviceTokenFetcherTest() 32 DeviceTokenFetcherTest()
33 : ui_thread_(BrowserThread::UI, &loop_), 33 : ui_thread_(BrowserThread::UI, &loop_),
34 file_thread_(BrowserThread::FILE, &loop_) { 34 file_thread_(BrowserThread::FILE, &loop_) {
35 EXPECT_TRUE(temp_user_data_dir_.CreateUniqueTempDir()); 35 EXPECT_TRUE(temp_user_data_dir_.CreateUniqueTempDir());
36 successful_registration_response_.mutable_register_response()-> 36 successful_registration_response_.mutable_register_response()->
37 set_device_management_token("fake_token"); 37 set_device_management_token("fake_token");
38 successful_registration_response_.mutable_register_response()->
39 set_enrollment_type(em::DeviceRegisterResponse::ENTERPRISE);
38 } 40 }
39 41
40 virtual void SetUp() { 42 virtual void SetUp() {
41 cache_.reset(new UserPolicyCache( 43 cache_.reset(new UserPolicyCache(
42 temp_user_data_dir_.path().AppendASCII("DeviceTokenFetcherTest"), 44 temp_user_data_dir_.path().AppendASCII("DeviceTokenFetcherTest"),
43 false /* wait_for_policy_fetch */)); 45 false /* wait_for_policy_fetch */));
44 EXPECT_CALL(service_, StartJob(_)).Times(AnyNumber()); 46 EXPECT_CALL(service_, StartJob(_)).Times(AnyNumber());
45 data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); 47 data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies());
46 data_store_->AddObserver(&observer_); 48 data_store_->AddObserver(&observer_);
47 } 49 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 TEST_F(DeviceTokenFetcherTest, FetchToken) { 102 TEST_F(DeviceTokenFetcherTest, FetchToken) {
101 testing::InSequence s; 103 testing::InSequence s;
102 EXPECT_CALL(service_, 104 EXPECT_CALL(service_,
103 CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION)) 105 CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION))
104 .WillOnce(service_.SucceedJob(successful_registration_response_)); 106 .WillOnce(service_.SucceedJob(successful_registration_response_));
105 EXPECT_CALL(service_, StartJob(_)).WillOnce(VerifyRegisterRequest(false)); 107 EXPECT_CALL(service_, StartJob(_)).WillOnce(VerifyRegisterRequest(false));
106 DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(), 108 DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
107 &notifier_); 109 &notifier_);
108 EXPECT_CALL(observer_, OnDeviceTokenChanged()); 110 EXPECT_CALL(observer_, OnDeviceTokenChanged());
109 EXPECT_EQ("", data_store_->device_token()); 111 EXPECT_EQ("", data_store_->device_token());
112 EXPECT_EQ(DEVICE_MODE_UNKNOWN, data_store_->device_mode());
110 FetchToken(&fetcher); 113 FetchToken(&fetcher);
111 loop_.RunAllPending(); 114 loop_.RunAllPending();
112 Mock::VerifyAndClearExpectations(&observer_); 115 Mock::VerifyAndClearExpectations(&observer_);
113 std::string token = data_store_->device_token(); 116 std::string token = data_store_->device_token();
114 EXPECT_NE("", token); 117 EXPECT_NE("", token);
118 // User policy registration should not set enrollment mode.
119 EXPECT_EQ(DEVICE_MODE_UNKNOWN, data_store_->device_mode());
115 120
116 // Calling FetchToken() again should result in a new token being fetched. 121 // Calling FetchToken() again should result in a new token being fetched.
117 successful_registration_response_.mutable_register_response()-> 122 successful_registration_response_.mutable_register_response()->
118 set_device_management_token("new_fake_token"); 123 set_device_management_token("new_fake_token");
119 EXPECT_CALL(service_, 124 EXPECT_CALL(service_,
120 CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION)) 125 CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION))
121 .WillOnce(service_.SucceedJob(successful_registration_response_)); 126 .WillOnce(service_.SucceedJob(successful_registration_response_));
122 EXPECT_CALL(observer_, OnDeviceTokenChanged()); 127 EXPECT_CALL(observer_, OnDeviceTokenChanged());
123 FetchToken(&fetcher); 128 FetchToken(&fetcher);
124 loop_.RunAllPending(); 129 loop_.RunAllPending();
125 Mock::VerifyAndClearExpectations(&observer_); 130 Mock::VerifyAndClearExpectations(&observer_);
126 std::string token2 = data_store_->device_token(); 131 std::string token2 = data_store_->device_token();
127 EXPECT_NE("", token2); 132 EXPECT_NE("", token2);
128 EXPECT_NE(token, token2); 133 EXPECT_NE(token, token2);
129 } 134 }
130 135
136 // User token fetches does not have to carry enrollment type.
Mattias Nissler (ping if slow) 2012/02/21 10:37:46 That comment is misleading, since the test is real
pastarmovj 2012/02/21 14:57:08 Yep. I removed the comment here and put it down at
137 TEST_F(DeviceTokenFetcherTest, FetchDeviceToken) {
138 testing::InSequence s;
139 scoped_ptr<CloudPolicyDataStore> data_store(
140 CloudPolicyDataStore::CreateForDevicePolicies());
141 data_store->AddObserver(&observer_);
Mattias Nissler (ping if slow) 2012/02/21 10:37:46 do you actually need the observer for this test? I
pastarmovj 2012/02/21 14:57:08 Done.
142 EXPECT_CALL(service_,
143 CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION))
144 .WillOnce(service_.SucceedJob(successful_registration_response_));
145 EXPECT_CALL(service_, StartJob(_)).WillOnce(VerifyRegisterRequest(false));
146 DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store.get(),
147 &notifier_);
148 EXPECT_CALL(observer_, OnDeviceTokenChanged());
149 EXPECT_EQ("", data_store->device_token());
150 EXPECT_EQ(DEVICE_MODE_UNKNOWN, data_store->device_mode());
151 data_store->SetupForTesting("", "fake_device_id", "fake_user_name",
152 "fake_auth_token", true);
153 fetcher.FetchToken();
154 loop_.RunAllPending();
155 Mock::VerifyAndClearExpectations(&observer_);
156 EXPECT_NE("", data_store->device_token());
157 EXPECT_EQ(DEVICE_MODE_ENTERPRISE, data_store->device_mode());
158
159 data_store->RemoveObserver(&observer_);
160 }
161
162 // TODO(pastarmovj): This test must be changed in accordance with
163 // http://crosbug.com/26624.
164 TEST_F(DeviceTokenFetcherTest, FetchDeviceTokenMissingMode) {
165 testing::InSequence s;
166 scoped_ptr<CloudPolicyDataStore> data_store(
167 CloudPolicyDataStore::CreateForDevicePolicies());
168 data_store->AddObserver(&observer_);
Mattias Nissler (ping if slow) 2012/02/21 10:37:46 ditto
pastarmovj 2012/02/21 14:57:08 Done.
169 EXPECT_CALL(service_,
170 CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION))
171 .WillOnce(service_.SucceedJob(successful_registration_response_));
172 EXPECT_CALL(service_, StartJob(_)).WillOnce(VerifyRegisterRequest(false));
173 DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store.get(),
174 &notifier_);
175 EXPECT_CALL(observer_, OnDeviceTokenChanged());
176 EXPECT_EQ("", data_store->device_token());
177 EXPECT_EQ(DEVICE_MODE_UNKNOWN, data_store->device_mode());
178 data_store->SetupForTesting("", "fake_device_id", "fake_user_name",
179 "fake_auth_token", true);
Mattias Nissler (ping if slow) 2012/02/21 10:37:46 It looks like this setup code is now duplicated 3
pastarmovj 2012/02/21 14:57:08 Did some consolidation. Could push it further but
180 successful_registration_response_.mutable_register_response()->
181 clear_enrollment_type();
182 fetcher.FetchToken();
183 loop_.RunAllPending();
184 Mock::VerifyAndClearExpectations(&observer_);
185 EXPECT_NE("", data_store->device_token());
186 // TODO(pastarmovj): Modify when http://crosbug.com/26624 is resolved.
187 EXPECT_EQ(DEVICE_MODE_ENTERPRISE, data_store->device_mode());
188
189 data_store->RemoveObserver(&observer_);
190 }
191
131 TEST_F(DeviceTokenFetcherTest, RetryOnError) { 192 TEST_F(DeviceTokenFetcherTest, RetryOnError) {
132 testing::InSequence s; 193 testing::InSequence s;
133 EXPECT_CALL(service_, 194 EXPECT_CALL(service_,
134 CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION)) 195 CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION))
135 .WillOnce(service_.FailJob(DM_STATUS_REQUEST_FAILED)) 196 .WillOnce(service_.FailJob(DM_STATUS_REQUEST_FAILED))
136 .WillOnce(service_.SucceedJob(successful_registration_response_)); 197 .WillOnce(service_.SucceedJob(successful_registration_response_));
137 DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(), 198 DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
138 &notifier_, new DummyWorkScheduler); 199 &notifier_, new DummyWorkScheduler);
139 EXPECT_CALL(observer_, OnDeviceTokenChanged()); 200 EXPECT_CALL(observer_, OnDeviceTokenChanged());
140 FetchToken(&fetcher); 201 FetchToken(&fetcher);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 data_store_->set_known_machine_id(true); 277 data_store_->set_known_machine_id(true);
217 FetchToken(&fetcher); 278 FetchToken(&fetcher);
218 loop_.RunAllPending(); 279 loop_.RunAllPending();
219 280
220 Mock::VerifyAndClearExpectations(&observer_); 281 Mock::VerifyAndClearExpectations(&observer_);
221 std::string token = data_store_->device_token(); 282 std::string token = data_store_->device_token();
222 EXPECT_NE("", token); 283 EXPECT_NE("", token);
223 } 284 }
224 285
225 } // namespace policy 286 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698