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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/policy/android_management_client_unittest.cc
diff --git a/chrome/browser/chromeos/policy/android_management_client_unittest.cc b/chrome/browser/chromeos/policy/android_management_client_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..09f4e0299bea642fa69382feecca7f783b2c11ed
--- /dev/null
+++ b/chrome/browser/chromeos/policy/android_management_client_unittest.cc
@@ -0,0 +1,108 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/time/time.h"
+#include "chrome/browser/chromeos/policy/android_management_client.h"
+#include "components/policy/core/common/cloud/mock_device_management_service.h"
+#include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
+#include "net/url_request/url_request_context_getter.h"
+#include "net/url_request/url_request_test_util.h"
+#include "policy/proto/device_management_backend.pb.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using testing::SaveArg;
+using testing::StrictMock;
+using testing::_;
+
+namespace em = enterprise_management;
+
+namespace policy {
+
+namespace {
+
+const char kAccountId[] = "fake-account-id";
+const char kRefreshToken[] = "fake-refresh-token";
+const char kOAuthToken[] = "fake-oauth-token";
+
+MATCHER_P(MatchProto, expected, "matches protobuf") {
+ return arg.SerializePartialAsString() == expected.SerializePartialAsString();
+}
+
+// A mock class to allow us to set expectations on upload callbacks.
+class MockStatusCallbackObserver {
+ public:
+ MockStatusCallbackObserver() {}
+
+ MOCK_METHOD1(OnCallbackComplete, void(AndroidManagementClient::Result));
+};
+
+} // namespace
+
+class AndroidManagementClientTest : public testing::Test {
+ protected:
+ AndroidManagementClientTest() {
+ android_management_request_.mutable_check_android_management_request();
+ android_management_response_.mutable_check_android_management_response();
+ }
+
+ // testing::Test:
+ void SetUp() override {
+ request_context_ =
+ new net::TestURLRequestContextGetter(loop_.task_runner());
+ client_.reset(new AndroidManagementClient(&service_, request_context_,
+ kAccountId, &token_service_));
+ }
+
+ // Request protobuf is used as extectation for the client requests.
+ em::DeviceManagementRequest android_management_request_;
+
+ // Protobuf is used in successfil responsees.
+ em::DeviceManagementResponse android_management_response_;
+
+ base::MessageLoop loop_;
+ MockDeviceManagementService service_;
+ StrictMock<MockStatusCallbackObserver> callback_observer_;
+ std::unique_ptr<AndroidManagementClient> client_;
+ // Pointer to the client's request context.
+ scoped_refptr<net::URLRequestContextGetter> request_context_;
+ std::string oauh_token_;
+ FakeProfileOAuth2TokenService token_service_;
+};
+
+TEST_F(AndroidManagementClientTest, CheckAndroidManagementCall) {
+ std::string client_id;
+ EXPECT_CALL(
+ service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_ANDROID_MANAGEMENT_CHECK,
+ request_context_))
+ .WillOnce(service_.SucceedJob(android_management_response_));
+ EXPECT_CALL(service_,
+ StartJob(dm_protocol::kValueRequestCheckAndroidManagement,
+ std::string(), kOAuthToken, std::string(), _,
+ MatchProto(android_management_request_)))
+ .WillOnce(SaveArg<4>(&client_id));
+ EXPECT_CALL(
+ callback_observer_,
+ OnCallbackComplete(AndroidManagementClient::Result::RESULT_UNMANAGED))
+ .Times(1);
+
+ AndroidManagementClient::StatusCallback callback =
+ base::Bind(&MockStatusCallbackObserver::OnCallbackComplete,
+ base::Unretained(&callback_observer_));
+
+ token_service_.UpdateCredentials(kAccountId, kRefreshToken);
+ client_->StartCheckAndroidManagement(callback);
+ token_service_.IssueAllTokensForAccount(kAccountId, kOAuthToken,
+ base::Time::Max());
+ ASSERT_LT(client_id.size(), 64U);
+}
+
+} // namespace policy
« 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