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

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: Fix clang build. Created 8 years, 11 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/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 "chrome/browser/policy/mock_device_management_service.h" 9 #include "chrome/browser/policy/mock_device_management_service.h"
10 #include "crypto/sha2.h" 10 #include "crypto/sha2.h"
11 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace em = enterprise_management; 14 namespace em = enterprise_management;
15 15
16 namespace policy { 16 namespace policy {
17 17
18 namespace { 18 namespace {
19 19
20 const char* kSerial = "serial"; 20 const char* kSerial = "serial";
21 const char* kSerialHash = 21 const char* kSerialHash =
22 "\x01\x44\xb1\xde\xfc\xf7\x56\x10\x87\x01\x5f\x8d\x83\x0d\x65\xb1" 22 "\x01\x44\xb1\xde\xfc\xf7\x56\x10\x87\x01\x5f\x8d\x83\x0d\x65\xb1"
23 "\x6f\x02\x4a\xd7\xeb\x92\x45\xfc\xd4\xe4\x37\xa1\x55\x2b\x13\x8a"; 23 "\x6f\x02\x4a\xd7\xeb\x92\x45\xfc\xd4\xe4\x37\xa1\x55\x2b\x13\x8a";
24 24
25 using ::testing::InSequence; 25 using ::testing::InSequence;
26 using ::testing::Invoke; 26 using ::testing::Invoke;
27 using ::testing::Unused;
27 using ::testing::_; 28 using ::testing::_;
28 29
29 class AutoEnrollmentClientTest : public testing::Test { 30 class AutoEnrollmentClientTest : public testing::Test {
30 protected: 31 protected:
31 AutoEnrollmentClientTest() 32 AutoEnrollmentClientTest()
32 : service_(NULL), 33 : service_(NULL),
33 completion_callback_count_(0) {} 34 completion_callback_count_(0) {}
34 35
35 virtual void SetUp() OVERRIDE { 36 virtual void SetUp() OVERRIDE {
36 CreateClient(kSerial, 4, 8); 37 CreateClient(kSerial, 4, 8);
37 } 38 }
38 39
39 void CreateClient(const std::string& serial, 40 void CreateClient(const std::string& serial,
40 int power_initial, 41 int power_initial,
41 int power_limit) { 42 int power_limit) {
42 service_ = new MockDeviceManagementService(); 43 service_ = new MockDeviceManagementService();
43 EXPECT_CALL(*service_, StartJob(_)) 44 EXPECT_CALL(*service_, StartJob(_, _, _, _, _, _, _))
44 .WillRepeatedly(Invoke(this, 45 .WillRepeatedly(Invoke(this,
45 &AutoEnrollmentClientTest::CaptureRequest)); 46 &AutoEnrollmentClientTest::CaptureRequest));
46 base::Closure callback = 47 base::Closure callback =
47 base::Bind(&AutoEnrollmentClientTest::CompletionCallback, 48 base::Bind(&AutoEnrollmentClientTest::CompletionCallback,
48 base::Unretained(this)); 49 base::Unretained(this));
49 client_.reset(new AutoEnrollmentClient(callback, 50 client_.reset(new AutoEnrollmentClient(callback,
50 service_, 51 service_,
51 serial, 52 serial,
52 power_initial, 53 power_initial,
53 power_limit)); 54 power_limit));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 CreateJob(DeviceManagementRequestJob::TYPE_AUTO_ENROLLMENT)) 87 CreateJob(DeviceManagementRequestJob::TYPE_AUTO_ENROLLMENT))
87 .WillOnce(service_->SucceedJob(response)); 88 .WillOnce(service_->SucceedJob(response));
88 } 89 }
89 90
90 MockDeviceManagementService* service_; 91 MockDeviceManagementService* service_;
91 scoped_ptr<AutoEnrollmentClient> client_; 92 scoped_ptr<AutoEnrollmentClient> client_;
92 em::DeviceAutoEnrollmentRequest last_request_; 93 em::DeviceAutoEnrollmentRequest last_request_;
93 int completion_callback_count_; 94 int completion_callback_count_;
94 95
95 private: 96 private:
96 void CaptureRequest(DeviceManagementRequestJob* job) { 97 void CaptureRequest(Unused, Unused, Unused, Unused, Unused, Unused,
97 last_request_ = job->GetRequest()->auto_enrollment_request(); 98 const em::DeviceManagementRequest& request) {
99 last_request_ = request.auto_enrollment_request();
98 } 100 }
99 101
100 DISALLOW_COPY_AND_ASSIGN(AutoEnrollmentClientTest); 102 DISALLOW_COPY_AND_ASSIGN(AutoEnrollmentClientTest);
101 }; 103 };
102 104
103 TEST_F(AutoEnrollmentClientTest, NetworkFailure) { 105 TEST_F(AutoEnrollmentClientTest, NetworkFailure) {
104 ServerWillFail(DM_STATUS_TEMPORARY_UNAVAILABLE); 106 ServerWillFail(DM_STATUS_TEMPORARY_UNAVAILABLE);
105 client_->Start(); 107 client_->Start();
106 EXPECT_FALSE(client_->should_auto_enroll()); 108 EXPECT_FALSE(client_->should_auto_enroll());
107 EXPECT_EQ(1, completion_callback_count_); 109 EXPECT_EQ(1, completion_callback_count_);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 EXPECT_TRUE(last_request_.has_remainder()); 224 EXPECT_TRUE(last_request_.has_remainder());
223 EXPECT_TRUE(last_request_.has_modulus()); 225 EXPECT_TRUE(last_request_.has_modulus());
224 EXPECT_EQ((int64) 1 << i, last_request_.modulus()); 226 EXPECT_EQ((int64) 1 << i, last_request_.modulus());
225 EXPECT_EQ(bottom62 % ((int64) 1 << i), last_request_.remainder()); 227 EXPECT_EQ(bottom62 % ((int64) 1 << i), last_request_.remainder());
226 } 228 }
227 } 229 }
228 230
229 } // namespace 231 } // namespace
230 232
231 } // namespace policy 233 } // namespace policy
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/policy/cloud_policy_client.h » ('j') | chrome/browser/policy/cloud_policy_client.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698