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

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 unnecessary new SC_CONFLICT dm status. Created 4 years, 8 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 "base/memory/scoped_ptr.h"
12 #include "chrome/browser/chromeos/policy/android_management_client.h"
13 #include "components/policy/core/common/cloud/mock_device_management_service.h"
14 #include "net/url_request/url_request_context_getter.h"
15 #include "net/url_request/url_request_test_util.h"
16 #include "policy/proto/device_management_backend.pb.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 using testing::StrictMock;
21
22 namespace em = enterprise_management;
23
24 namespace policy {
25
26 namespace {
27
28 const char kOAuthToken[] = "fake-oauth-token";
29
30 MATCHER_P(MatchProto, expected, "matches protobuf") {
31 return arg.SerializePartialAsString() == expected.SerializePartialAsString();
32 }
33
34 // A mock class to allow us to set expectations on upload callbacks.
35 class MockStatusCallbackObserver {
36 public:
37 MockStatusCallbackObserver() {}
38
39 MOCK_METHOD1(OnCallbackComplete, void(AndroidManagementClient::Result));
40 };
41
42 } // namespace
43
44 class AndroidManagementClientTest : public testing::Test {
45 protected:
46 AndroidManagementClientTest() {
47 android_management_request_.mutable_check_android_management_request();
48 android_management_response_.mutable_check_android_management_response();
49 }
50
51 void SetUp() { CreateClient(); }
bartfab (slow) 2016/04/26 14:15:33 Nit: This one-line method does not look style guid
Polina Bondarenko 2016/04/26 14:22:56 It has happened after "git cl format", should I ch
bartfab (slow) 2016/04/26 14:23:58 No, no need to fight with clang-format. I am still
52
53 void ExpectCheckAndroidManagement(const std::string& oauth_token) {
54 EXPECT_CALL(
55 service_,
56 CreateJob(DeviceManagementRequestJob::TYPE_ANDROID_MANAGEMENT_CHECK,
57 request_context_))
58 .WillOnce(service_.SucceedJob(android_management_response_));
59 EXPECT_CALL(
60 service_,
61 StartJob(dm_protocol::kValueRequestCheckAndroidManagement, oauth_token,
62 std::string(), std::string(), std::string(),
63 MatchProto(android_management_request_)));
64 }
65
66 void CreateClient() {
67 request_context_ =
68 new net::TestURLRequestContextGetter(loop_.task_runner());
69 client_.reset(new AndroidManagementClient(&service_, request_context_));
70 }
71
72 // Request protobuf is used as extectation for the client requests.
73 em::DeviceManagementRequest android_management_request_;
74
75 // Protobuf is used in successfil responsees.
76 em::DeviceManagementResponse android_management_response_;
77
78 base::MessageLoop loop_;
79 MockDeviceManagementService service_;
80 StrictMock<MockStatusCallbackObserver> callback_observer_;
81 scoped_ptr<AndroidManagementClient> client_;
82 // Pointer to the client's request context.
83 scoped_refptr<net::URLRequestContextGetter> request_context_;
84 std::string oauh_token_;
85 };
86
87 TEST_F(AndroidManagementClientTest, CheckAndroidManagementCall) {
88 ExpectCheckAndroidManagement(kOAuthToken);
89 EXPECT_CALL(
90 callback_observer_,
91 OnCallbackComplete(AndroidManagementClient::Result::RESULT_UNMANAGED))
92 .Times(1);
93
94 AndroidManagementClient::StatusCallback callback =
95 base::Bind(&MockStatusCallbackObserver::OnCallbackComplete,
96 base::Unretained(&callback_observer_));
97 client_->CheckAndroidManagement(kOAuthToken, callback);
98 }
99
100 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/android_management_client.cc ('k') | chrome/chrome_browser_chromeos.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698