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

Unified Diff: chrome/browser/chromeos/policy/heartbeat_scheduler_unittest.cc

Issue 1258313002: Send GCM id to DMServer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add tests Created 5 years, 5 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
Index: chrome/browser/chromeos/policy/heartbeat_scheduler_unittest.cc
diff --git a/chrome/browser/chromeos/policy/heartbeat_scheduler_unittest.cc b/chrome/browser/chromeos/policy/heartbeat_scheduler_unittest.cc
index 6b409f3537de804df957bdae2f23d46fe9462efa..0d1d91272f9a21e0ed76e1bbdbb15790ef8e6e7e 100644
--- a/chrome/browser/chromeos/policy/heartbeat_scheduler_unittest.cc
+++ b/chrome/browser/chromeos/policy/heartbeat_scheduler_unittest.cc
@@ -9,6 +9,8 @@
#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h"
#include "chromeos/settings/cros_settings_names.h"
#include "components/gcm_driver/fake_gcm_driver.h"
+#include "components/policy/core/common/cloud/cloud_policy_client.h"
+#include "components/policy/core/common/cloud/mock_cloud_policy_client.h"
#include "content/public/test/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -20,6 +22,8 @@ namespace {
const char* const kFakeEnrollmentDomain = "example.com";
const char* const kFakeDeviceId = "fake_device_id";
const char* const kHeartbeatGCMAppID = "com.google.chromeos.monitoring";
+const char* const kRegistrationId = "registration_id";
+const char* const kDMToken = "fake_dm_token";
class MockGCMDriver : public testing::StrictMock<gcm::FakeGCMDriver> {
public:
@@ -40,7 +44,7 @@ class MockGCMDriver : public testing::StrictMock<gcm::FakeGCMDriver> {
// Register().
void CompleteRegistration(const std::string& app_id,
gcm::GCMClient::Result result) {
- RegisterFinished(app_id, "registration_id", result);
+ RegisterFinished(app_id, kRegistrationId, result);
}
// Helper function to complete a send operation previously started by
@@ -56,9 +60,11 @@ class HeartbeatSchedulerTest : public testing::Test {
public:
HeartbeatSchedulerTest()
: task_runner_(new base::TestSimpleTaskRunner()),
- scheduler_(
- &gcm_driver_, kFakeEnrollmentDomain, kFakeDeviceId, task_runner_) {
- }
+ scheduler_(&gcm_driver_,
+ nullptr,
+ kFakeEnrollmentDomain,
+ kFakeDeviceId,
+ task_runner_) {}
void SetUp() override {
settings_helper_.ReplaceProvider(chromeos::kHeartbeatEnabled);
@@ -222,4 +228,31 @@ TEST_F(HeartbeatSchedulerTest, CheckMessageContents) {
EXPECT_EQ(kFakeDeviceId, message.data["device_id"]);
}
+TEST_F(HeartbeatSchedulerTest, SendGcmIdMappingUpdate) {
+ // Verifies that GCM id mapping update was sent after GCM registration.
+ policy::MockCloudPolicyClient cloud_policy_client;
+ cloud_policy_client.SetDMToken(kDMToken);
+ policy::CloudPolicyClient::StatusCallback callback;
+ EXPECT_CALL(cloud_policy_client, UpdateGcmIdMapping(kRegistrationId, _))
+ .WillOnce(SaveArg<1>(&callback));
+
+ scheduler_.SetCloudPolicyClientForTesting(&cloud_policy_client);
+
+ EXPECT_FALSE(scheduler_.latest_gcm_id_mapping_succeeded());
+
+ // Enable heartbests.
+ EXPECT_CALL(gcm_driver_, RegisterImpl(kHeartbeatGCMAppID, _));
+ EXPECT_CALL(gcm_driver_, SendImpl(kHeartbeatGCMAppID, _, _));
+ settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, true);
+ gcm_driver_.CompleteRegistration(kHeartbeatGCMAppID, gcm::GCMClient::SUCCESS);
+ task_runner_->RunPendingTasks();
+
+ // Verifies that CloudPolicyClient get the update request, and call the
+ // callback with success flag.
+ testing::Mock::VerifyAndClearExpectations(&cloud_policy_client);
+ callback.Run(true);
+
+ EXPECT_TRUE(scheduler_.latest_gcm_id_mapping_succeeded());
Andrew T Wilson (Slow) 2015/08/03 13:52:26 Don't think these checks of latest_gcm_id_mapping_
binjin 2015/08/03 17:54:25 Done.
+}
+
} // namespace

Powered by Google App Engine
This is Rietveld 408576698