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

Side by Side Diff: chrome/browser/chromeos/policy/android_management_client_unittest.cc

Issue 1892093002: Add AndroidManagementClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed ptr_util.h Created 4 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
OLDNEW
(Empty)
1 // Copyright (c) 2016 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 <string>
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h"
11 #include "chrome/browser/chromeos/policy/android_management_client.h"
12 #include "components/policy/core/common/cloud/mock_device_management_service.h"
13 #include "net/url_request/url_request_context_getter.h"
14 #include "net/url_request/url_request_test_util.h"
15 #include "policy/proto/device_management_backend.pb.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 using testing::SaveArg;
20 using testing::StrictMock;
21 using testing::_;
22
23 namespace em = enterprise_management;
24
25 namespace policy {
26
27 namespace {
28
29 const char kOAuthToken[] = "fake-oauth-token";
30
31 MATCHER_P(MatchProto, expected, "matches protobuf") {
32 return arg.SerializePartialAsString() == expected.SerializePartialAsString();
33 }
34
35 // A mock class to allow us to set expectations on upload callbacks.
36 class MockStatusCallbackObserver {
37 public:
38 MockStatusCallbackObserver() {}
39
40 MOCK_METHOD1(OnCallbackComplete, void(AndroidManagementClient::Result));
41 };
42
43 } // namespace
44
45 class AndroidManagementClientTest : public testing::Test {
46 protected:
47 AndroidManagementClientTest() {
48 android_management_request_.mutable_check_android_management_request();
49 android_management_response_.mutable_check_android_management_response();
50 }
51
52 void SetUp() { CreateClient(); }
53
54 void ExpectCheckAndroidManagement(const std::string& oauth_token,
Thiemo Nagel 2016/04/28 13:27:00 Since this is only used once, I'd consider it more
Polina Bondarenko 2016/04/28 16:18:40 Done.
55 std::string* client_id) {
56 EXPECT_CALL(
57 service_,
58 CreateJob(DeviceManagementRequestJob::TYPE_ANDROID_MANAGEMENT_CHECK,
59 request_context_))
60 .WillOnce(service_.SucceedJob(android_management_response_));
61 EXPECT_CALL(service_,
62 StartJob(dm_protocol::kValueRequestCheckAndroidManagement,
63 std::string(), oauth_token, std::string(), _,
64 MatchProto(android_management_request_)))
65 .WillOnce(SaveArg<4>(client_id));
66 }
67
68 void CreateClient() {
69 request_context_ =
70 new net::TestURLRequestContextGetter(loop_.task_runner());
71 AndroidManagementClient::SetAccessTokenForTesting(kOAuthToken);
72 client_.reset(
73 new AndroidManagementClient(&service_, request_context_, "", nullptr));
74 }
75
76 // Request protobuf is used as extectation for the client requests.
77 em::DeviceManagementRequest android_management_request_;
78
79 // Protobuf is used in successfil responsees.
80 em::DeviceManagementResponse android_management_response_;
81
82 base::MessageLoop loop_;
83 MockDeviceManagementService service_;
84 StrictMock<MockStatusCallbackObserver> callback_observer_;
85 std::unique_ptr<AndroidManagementClient> client_;
86 // Pointer to the client's request context.
87 scoped_refptr<net::URLRequestContextGetter> request_context_;
88 std::string oauh_token_;
89 };
90
91 TEST_F(AndroidManagementClientTest, CheckAndroidManagementCall) {
92 std::string client_id;
93 ExpectCheckAndroidManagement(kOAuthToken, &client_id);
94 EXPECT_CALL(
95 callback_observer_,
96 OnCallbackComplete(AndroidManagementClient::Result::RESULT_UNMANAGED))
97 .Times(1);
98
99 AndroidManagementClient::StatusCallback callback =
100 base::Bind(&MockStatusCallbackObserver::OnCallbackComplete,
101 base::Unretained(&callback_observer_));
102 client_->StartCheckAndroidManagement(callback);
103 ASSERT_LT(client_id.size(), 64U);
104 }
105
106 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698