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

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: 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 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..00b4be8be0c022618bd6f419459ff96d9f4bde41
--- /dev/null
+++ b/chrome/browser/chromeos/policy/android_management_client_unittest.cc
@@ -0,0 +1,100 @@
+// 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/memory/scoped_ptr.h"
+#include "chrome/browser/chromeos/policy/android_management_client.h"
+#include "components/policy/core/common/cloud/mock_device_management_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::StrictMock;
+
+namespace em = enterprise_management;
+
+namespace policy {
+
+namespace {
+
+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();
+ }
+
+ 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
+
+ void ExpectCheckAndroidManagement(const std::string& oauth_token) {
+ EXPECT_CALL(
+ service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_ANDROID_MANAGEMENT_CHECK,
+ request_context_))
+ .WillOnce(service_.SucceedJob(android_management_response_));
+ EXPECT_CALL(
+ service_,
+ StartJob(dm_protocol::kValueRequestCheckAndroidManagement, oauth_token,
+ std::string(), std::string(), std::string(),
+ MatchProto(android_management_request_)));
+ }
+
+ void CreateClient() {
+ request_context_ =
+ new net::TestURLRequestContextGetter(loop_.task_runner());
+ client_.reset(new AndroidManagementClient(&service_, request_context_));
+ }
+
+ // 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_;
+ scoped_ptr<AndroidManagementClient> client_;
+ // Pointer to the client's request context.
+ scoped_refptr<net::URLRequestContextGetter> request_context_;
+ std::string oauh_token_;
+};
+
+TEST_F(AndroidManagementClientTest, CheckAndroidManagementCall) {
+ ExpectCheckAndroidManagement(kOAuthToken);
+ EXPECT_CALL(
+ callback_observer_,
+ OnCallbackComplete(AndroidManagementClient::Result::RESULT_UNMANAGED))
+ .Times(1);
+
+ AndroidManagementClient::StatusCallback callback =
+ base::Bind(&MockStatusCallbackObserver::OnCallbackComplete,
+ base::Unretained(&callback_observer_));
+ client_->CheckAndroidManagement(kOAuthToken, callback);
+}
+
+} // 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