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

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: Fixed comments. 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 "base/time/time.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 "components/signin/core/browser/fake_profile_oauth2_token_service.h"
15 #include "net/url_request/url_request_context_getter.h"
16 #include "net/url_request/url_request_test_util.h"
17 #include "policy/proto/device_management_backend.pb.h"
18 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20
21 using testing::SaveArg;
22 using testing::StrictMock;
23 using testing::_;
24
25 namespace em = enterprise_management;
26
27 namespace policy {
28
29 namespace {
30
31 const char kAccountId[] = "fake-account-id";
32 const char kRefreshToken[] = "fake-refresh-token";
33 const char kOAuthToken[] = "fake-oauth-token";
34
35 MATCHER_P(MatchProto, expected, "matches protobuf") {
36 return arg.SerializePartialAsString() == expected.SerializePartialAsString();
37 }
38
39 // A mock class to allow us to set expectations on upload callbacks.
40 class MockStatusCallbackObserver {
41 public:
42 MockStatusCallbackObserver() {}
43
44 MOCK_METHOD1(OnCallbackComplete, void(AndroidManagementClient::Result));
45 };
46
47 } // namespace
48
49 class AndroidManagementClientTest : public testing::Test {
50 protected:
51 AndroidManagementClientTest() {
52 android_management_request_.mutable_check_android_management_request();
53 android_management_response_.mutable_check_android_management_response();
54 }
55
56 // testing::Test:
57 void SetUp() override {
58 request_context_ =
59 new net::TestURLRequestContextGetter(loop_.task_runner());
60 client_.reset(new AndroidManagementClient(&service_, request_context_,
61 kAccountId, &token_service_));
62 }
63
64 // Request protobuf is used as extectation for the client requests.
65 em::DeviceManagementRequest android_management_request_;
66
67 // Protobuf is used in successfil responsees.
68 em::DeviceManagementResponse android_management_response_;
69
70 base::MessageLoop loop_;
71 MockDeviceManagementService service_;
72 StrictMock<MockStatusCallbackObserver> callback_observer_;
73 std::unique_ptr<AndroidManagementClient> client_;
74 // Pointer to the client's request context.
75 scoped_refptr<net::URLRequestContextGetter> request_context_;
76 std::string oauh_token_;
77 FakeProfileOAuth2TokenService token_service_;
78 };
79
80 TEST_F(AndroidManagementClientTest, CheckAndroidManagementCall) {
81 std::string client_id;
82 EXPECT_CALL(
83 service_,
84 CreateJob(DeviceManagementRequestJob::TYPE_ANDROID_MANAGEMENT_CHECK,
85 request_context_))
86 .WillOnce(service_.SucceedJob(android_management_response_));
87 EXPECT_CALL(service_,
88 StartJob(dm_protocol::kValueRequestCheckAndroidManagement,
89 std::string(), kOAuthToken, std::string(), _,
90 MatchProto(android_management_request_)))
91 .WillOnce(SaveArg<4>(&client_id));
92 EXPECT_CALL(
93 callback_observer_,
94 OnCallbackComplete(AndroidManagementClient::Result::RESULT_UNMANAGED))
95 .Times(1);
96
97 AndroidManagementClient::StatusCallback callback =
98 base::Bind(&MockStatusCallbackObserver::OnCallbackComplete,
99 base::Unretained(&callback_observer_));
100
101 token_service_.UpdateCredentials(kAccountId, kRefreshToken);
102 client_->StartCheckAndroidManagement(callback);
103 token_service_.IssueAllTokensForAccount(kAccountId, kOAuthToken,
104 base::Time::Max());
105 ASSERT_LT(client_id.size(), 64U);
106 }
107
108 } // 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