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

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

Issue 9109009: Introduce CloudPolicyClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Restore DCHECKS. Created 8 years, 7 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
« no previous file with comments | « no previous file | chrome/browser/policy/cloud_policy_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/auto_enrollment_client.h" 5 #include "chrome/browser/policy/auto_enrollment_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 11 matching lines...) Expand all
22 namespace policy { 22 namespace policy {
23 23
24 namespace { 24 namespace {
25 25
26 const char* kSerial = "serial"; 26 const char* kSerial = "serial";
27 const char* kSerialHash = 27 const char* kSerialHash =
28 "\x01\x44\xb1\xde\xfc\xf7\x56\x10\x87\x01\x5f\x8d\x83\x0d\x65\xb1" 28 "\x01\x44\xb1\xde\xfc\xf7\x56\x10\x87\x01\x5f\x8d\x83\x0d\x65\xb1"
29 "\x6f\x02\x4a\xd7\xeb\x92\x45\xfc\xd4\xe4\x37\xa1\x55\x2b\x13\x8a"; 29 "\x6f\x02\x4a\xd7\xeb\x92\x45\xfc\xd4\xe4\x37\xa1\x55\x2b\x13\x8a";
30 30
31 using ::testing::InSequence; 31 using ::testing::InSequence;
32 using ::testing::Invoke; 32 using ::testing::SaveArg;
33 using ::testing::_; 33 using ::testing::_;
34 34
35 class AutoEnrollmentClientTest : public testing::Test { 35 class AutoEnrollmentClientTest : public testing::Test {
36 protected: 36 protected:
37 AutoEnrollmentClientTest() 37 AutoEnrollmentClientTest()
38 : scoped_testing_local_state_( 38 : scoped_testing_local_state_(
39 static_cast<TestingBrowserProcess*>(g_browser_process)), 39 static_cast<TestingBrowserProcess*>(g_browser_process)),
40 local_state_(scoped_testing_local_state_.Get()), 40 local_state_(scoped_testing_local_state_.Get()),
41 service_(NULL), 41 service_(NULL),
42 completion_callback_count_(0) {} 42 completion_callback_count_(0) {}
43 43
44 virtual void SetUp() OVERRIDE { 44 virtual void SetUp() OVERRIDE {
45 CreateClient(kSerial, 4, 8); 45 CreateClient(kSerial, 4, 8);
46 ASSERT_FALSE(local_state_->GetUserPref(prefs::kShouldAutoEnroll)); 46 ASSERT_FALSE(local_state_->GetUserPref(prefs::kShouldAutoEnroll));
47 ASSERT_FALSE(local_state_->GetUserPref(prefs::kAutoEnrollmentPowerLimit)); 47 ASSERT_FALSE(local_state_->GetUserPref(prefs::kAutoEnrollmentPowerLimit));
48 } 48 }
49 49
50 void CreateClient(const std::string& serial, 50 void CreateClient(const std::string& serial,
51 int power_initial, 51 int power_initial,
52 int power_limit) { 52 int power_limit) {
53 service_ = new MockDeviceManagementService(); 53 service_ = new MockDeviceManagementService();
54 EXPECT_CALL(*service_, StartJob(_)) 54 EXPECT_CALL(*service_, StartJob(_, _, _, _, _, _, _))
55 .WillRepeatedly(Invoke(this, 55 .WillRepeatedly(SaveArg<6>(&last_request_));
56 &AutoEnrollmentClientTest::CaptureRequest));
57 base::Closure callback = 56 base::Closure callback =
58 base::Bind(&AutoEnrollmentClientTest::CompletionCallback, 57 base::Bind(&AutoEnrollmentClientTest::CompletionCallback,
59 base::Unretained(this)); 58 base::Unretained(this));
60 client_.reset(new AutoEnrollmentClient(callback, 59 client_.reset(new AutoEnrollmentClient(callback,
61 service_, 60 service_,
62 local_state_, 61 local_state_,
63 serial, 62 serial,
64 power_initial, 63 power_initial,
65 power_limit)); 64 power_limit));
66 } 65 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 base::FundamentalValue value_should_enroll(should_enroll); 102 base::FundamentalValue value_should_enroll(should_enroll);
104 base::FundamentalValue value_power_limit(power_limit); 103 base::FundamentalValue value_power_limit(power_limit);
105 EXPECT_TRUE(Value::Equals( 104 EXPECT_TRUE(Value::Equals(
106 &value_should_enroll, 105 &value_should_enroll,
107 local_state_->GetUserPref(prefs::kShouldAutoEnroll))); 106 local_state_->GetUserPref(prefs::kShouldAutoEnroll)));
108 EXPECT_TRUE(Value::Equals( 107 EXPECT_TRUE(Value::Equals(
109 &value_power_limit, 108 &value_power_limit,
110 local_state_->GetUserPref(prefs::kAutoEnrollmentPowerLimit))); 109 local_state_->GetUserPref(prefs::kAutoEnrollmentPowerLimit)));
111 } 110 }
112 111
112 const em::DeviceAutoEnrollmentRequest& auto_enrollment_request() {
113 return last_request_.auto_enrollment_request();
114 }
115
113 ScopedTestingLocalState scoped_testing_local_state_; 116 ScopedTestingLocalState scoped_testing_local_state_;
114 TestingPrefService* local_state_; 117 TestingPrefService* local_state_;
115 MockDeviceManagementService* service_; 118 MockDeviceManagementService* service_;
116 scoped_ptr<AutoEnrollmentClient> client_; 119 scoped_ptr<AutoEnrollmentClient> client_;
117 em::DeviceAutoEnrollmentRequest last_request_; 120 em::DeviceManagementRequest last_request_;
118 int completion_callback_count_; 121 int completion_callback_count_;
119 122
120 private: 123 private:
121 void CaptureRequest(DeviceManagementRequestJob* job) {
122 last_request_ = job->GetRequest()->auto_enrollment_request();
123 }
124
125 DISALLOW_COPY_AND_ASSIGN(AutoEnrollmentClientTest); 124 DISALLOW_COPY_AND_ASSIGN(AutoEnrollmentClientTest);
126 }; 125 };
127 126
128 TEST_F(AutoEnrollmentClientTest, NetworkFailure) { 127 TEST_F(AutoEnrollmentClientTest, NetworkFailure) {
129 ServerWillFail(DM_STATUS_TEMPORARY_UNAVAILABLE); 128 ServerWillFail(DM_STATUS_TEMPORARY_UNAVAILABLE);
130 client_->Start(); 129 client_->Start();
131 EXPECT_FALSE(client_->should_auto_enroll()); 130 EXPECT_FALSE(client_->should_auto_enroll());
132 EXPECT_EQ(1, completion_callback_count_); 131 EXPECT_EQ(1, completion_callback_count_);
133 VerifyCachedResult(false, 8); 132 VerifyCachedResult(false, 8);
134 } 133 }
135 134
136 TEST_F(AutoEnrollmentClientTest, EmptyReply) { 135 TEST_F(AutoEnrollmentClientTest, EmptyReply) {
137 ServerWillReply(-1, false, false); 136 ServerWillReply(-1, false, false);
138 client_->Start(); 137 client_->Start();
139 EXPECT_FALSE(client_->should_auto_enroll()); 138 EXPECT_FALSE(client_->should_auto_enroll());
140 EXPECT_EQ(1, completion_callback_count_); 139 EXPECT_EQ(1, completion_callback_count_);
141 VerifyCachedResult(false, 8); 140 VerifyCachedResult(false, 8);
142 } 141 }
143 142
144 TEST_F(AutoEnrollmentClientTest, ClientUploadsRightBits) { 143 TEST_F(AutoEnrollmentClientTest, ClientUploadsRightBits) {
145 ServerWillReply(-1, false, false); 144 ServerWillReply(-1, false, false);
146 client_->Start(); 145 client_->Start();
147 EXPECT_FALSE(client_->should_auto_enroll()); 146 EXPECT_FALSE(client_->should_auto_enroll());
148 EXPECT_EQ(1, completion_callback_count_); 147 EXPECT_EQ(1, completion_callback_count_);
149 EXPECT_TRUE(last_request_.has_remainder()); 148
150 EXPECT_TRUE(last_request_.has_modulus()); 149 EXPECT_TRUE(auto_enrollment_request().has_remainder());
151 EXPECT_EQ(16, last_request_.modulus()); 150 EXPECT_TRUE(auto_enrollment_request().has_modulus());
152 EXPECT_EQ(kSerialHash[31] & 0xf, last_request_.remainder()); 151 EXPECT_EQ(16, auto_enrollment_request().modulus());
152 EXPECT_EQ(kSerialHash[31] & 0xf, auto_enrollment_request().remainder());
153 VerifyCachedResult(false, 8); 153 VerifyCachedResult(false, 8);
154 } 154 }
155 155
156 TEST_F(AutoEnrollmentClientTest, AskForMoreThenFail) { 156 TEST_F(AutoEnrollmentClientTest, AskForMoreThenFail) {
157 InSequence sequence; 157 InSequence sequence;
158 ServerWillReply(32, false, false); 158 ServerWillReply(32, false, false);
159 ServerWillFail(DM_STATUS_TEMPORARY_UNAVAILABLE); 159 ServerWillFail(DM_STATUS_TEMPORARY_UNAVAILABLE);
160 client_->Start(); 160 client_->Start();
161 EXPECT_FALSE(client_->should_auto_enroll()); 161 EXPECT_FALSE(client_->should_auto_enroll());
162 EXPECT_EQ(1, completion_callback_count_); 162 EXPECT_EQ(1, completion_callback_count_);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 VerifyCachedResult(false, 8); 211 VerifyCachedResult(false, 8);
212 } 212 }
213 213
214 TEST_F(AutoEnrollmentClientTest, AskNonPowerOf2) { 214 TEST_F(AutoEnrollmentClientTest, AskNonPowerOf2) {
215 InSequence sequence; 215 InSequence sequence;
216 ServerWillReply(100, false, false); 216 ServerWillReply(100, false, false);
217 ServerWillReply(-1, false, false); 217 ServerWillReply(-1, false, false);
218 client_->Start(); 218 client_->Start();
219 EXPECT_FALSE(client_->should_auto_enroll()); 219 EXPECT_FALSE(client_->should_auto_enroll());
220 EXPECT_EQ(1, completion_callback_count_); 220 EXPECT_EQ(1, completion_callback_count_);
221 EXPECT_TRUE(last_request_.has_remainder()); 221 EXPECT_TRUE(auto_enrollment_request().has_remainder());
222 EXPECT_TRUE(last_request_.has_modulus()); 222 EXPECT_TRUE(auto_enrollment_request().has_modulus());
223 EXPECT_EQ(128, last_request_.modulus()); 223 EXPECT_EQ(128, auto_enrollment_request().modulus());
224 EXPECT_EQ(kSerialHash[31] & 0x7f, last_request_.remainder()); 224 EXPECT_EQ(kSerialHash[31] & 0x7f, auto_enrollment_request().remainder());
225 VerifyCachedResult(false, 8); 225 VerifyCachedResult(false, 8);
226 } 226 }
227 227
228 TEST_F(AutoEnrollmentClientTest, ConsumerDevice) { 228 TEST_F(AutoEnrollmentClientTest, ConsumerDevice) {
229 ServerWillReply(-1, true, false); 229 ServerWillReply(-1, true, false);
230 client_->Start(); 230 client_->Start();
231 EXPECT_FALSE(client_->should_auto_enroll()); 231 EXPECT_FALSE(client_->should_auto_enroll());
232 EXPECT_EQ(1, completion_callback_count_); 232 EXPECT_EQ(1, completion_callback_count_);
233 VerifyCachedResult(false, 8); 233 VerifyCachedResult(false, 8);
234 } 234 }
(...skipping 14 matching lines...) Expand all
249 EXPECT_FALSE(local_state_->GetUserPref(prefs::kShouldAutoEnroll)); 249 EXPECT_FALSE(local_state_->GetUserPref(prefs::kShouldAutoEnroll));
250 EXPECT_FALSE(local_state_->GetUserPref(prefs::kAutoEnrollmentPowerLimit)); 250 EXPECT_FALSE(local_state_->GetUserPref(prefs::kAutoEnrollmentPowerLimit));
251 } 251 }
252 252
253 TEST_F(AutoEnrollmentClientTest, NoBitsUploaded) { 253 TEST_F(AutoEnrollmentClientTest, NoBitsUploaded) {
254 CreateClient(kSerial, 0, 0); 254 CreateClient(kSerial, 0, 0);
255 ServerWillReply(-1, false, false); 255 ServerWillReply(-1, false, false);
256 client_->Start(); 256 client_->Start();
257 EXPECT_FALSE(client_->should_auto_enroll()); 257 EXPECT_FALSE(client_->should_auto_enroll());
258 EXPECT_EQ(1, completion_callback_count_); 258 EXPECT_EQ(1, completion_callback_count_);
259 EXPECT_TRUE(last_request_.has_remainder()); 259 EXPECT_TRUE(auto_enrollment_request().has_remainder());
260 EXPECT_TRUE(last_request_.has_modulus()); 260 EXPECT_TRUE(auto_enrollment_request().has_modulus());
261 EXPECT_EQ(1, last_request_.modulus()); 261 EXPECT_EQ(1, auto_enrollment_request().modulus());
262 EXPECT_EQ(0, last_request_.remainder()); 262 EXPECT_EQ(0, auto_enrollment_request().remainder());
263 VerifyCachedResult(false, 0); 263 VerifyCachedResult(false, 0);
264 } 264 }
265 265
266 TEST_F(AutoEnrollmentClientTest, ManyBitsUploaded) { 266 TEST_F(AutoEnrollmentClientTest, ManyBitsUploaded) {
267 int64 bottom62 = GG_INT64_C(0x14e437a1552b138a); 267 int64 bottom62 = GG_INT64_C(0x14e437a1552b138a);
268 for (int i = 0; i <= 62; ++i) { 268 for (int i = 0; i <= 62; ++i) {
269 completion_callback_count_ = 0; 269 completion_callback_count_ = 0;
270 CreateClient(kSerial, i, i); 270 CreateClient(kSerial, i, i);
271 ServerWillReply(-1, false, false); 271 ServerWillReply(-1, false, false);
272 client_->Start(); 272 client_->Start();
273 EXPECT_FALSE(client_->should_auto_enroll()); 273 EXPECT_FALSE(client_->should_auto_enroll());
274 EXPECT_EQ(1, completion_callback_count_); 274 EXPECT_EQ(1, completion_callback_count_);
275 EXPECT_TRUE(last_request_.has_remainder()); 275 EXPECT_TRUE(auto_enrollment_request().has_remainder());
276 EXPECT_TRUE(last_request_.has_modulus()); 276 EXPECT_TRUE(auto_enrollment_request().has_modulus());
277 EXPECT_EQ(GG_INT64_C(1) << i, last_request_.modulus()); 277 EXPECT_EQ(GG_INT64_C(1) << i, auto_enrollment_request().modulus());
278 EXPECT_EQ(bottom62 % (GG_INT64_C(1) << i), last_request_.remainder()); 278 EXPECT_EQ(bottom62 % (GG_INT64_C(1) << i),
279 auto_enrollment_request().remainder());
279 VerifyCachedResult(false, i); 280 VerifyCachedResult(false, i);
280 } 281 }
281 } 282 }
282 283
283 TEST_F(AutoEnrollmentClientTest, MoreThan32BitsUploaded) { 284 TEST_F(AutoEnrollmentClientTest, MoreThan32BitsUploaded) {
284 CreateClient(kSerial, 10, 37); 285 CreateClient(kSerial, 10, 37);
285 InSequence sequence; 286 InSequence sequence;
286 ServerWillReply(GG_INT64_C(1) << 37, false, false); 287 ServerWillReply(GG_INT64_C(1) << 37, false, false);
287 ServerWillReply(-1, true, true); 288 ServerWillReply(-1, true, true);
288 client_->Start(); 289 client_->Start();
(...skipping 25 matching lines...) Expand all
314 CreateClient(kSerial, 5, 10); 315 CreateClient(kSerial, 5, 10);
315 ServerWillReply(-1, true, true); 316 ServerWillReply(-1, true, true);
316 client_->Start(); 317 client_->Start();
317 EXPECT_TRUE(client_->should_auto_enroll()); 318 EXPECT_TRUE(client_->should_auto_enroll());
318 EXPECT_EQ(1, completion_callback_count_); 319 EXPECT_EQ(1, completion_callback_count_);
319 } 320 }
320 321
321 } // namespace 322 } // namespace
322 323
323 } // namespace policy 324 } // namespace policy
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/policy/cloud_policy_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698