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

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: fixes addressing #9 and #10 Created 5 years, 4 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..a635aaa83c4b3f01afdaf58fc3cfcaa04477299f 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
@@ -54,13 +58,10 @@ class MockGCMDriver : public testing::StrictMock<gcm::FakeGCMDriver> {
class HeartbeatSchedulerTest : public testing::Test {
public:
- HeartbeatSchedulerTest()
- : task_runner_(new base::TestSimpleTaskRunner()),
- scheduler_(
- &gcm_driver_, kFakeEnrollmentDomain, kFakeDeviceId, task_runner_) {
- }
+ HeartbeatSchedulerTest() : task_runner_(new base::TestSimpleTaskRunner()) {}
void SetUp() override {
+ InitializeScheduler(nullptr);
Andrew T Wilson (Slow) 2015/08/06 11:17:06 why not set a mock cloud policy client here, then
binjin 2015/08/06 13:33:01 Done.
settings_helper_.ReplaceProvider(chromeos::kHeartbeatEnabled);
}
@@ -68,6 +69,12 @@ class HeartbeatSchedulerTest : public testing::Test {
content::RunAllBlockingPoolTasksUntilIdle();
}
+ void InitializeScheduler(policy::CloudPolicyClient* cloud_policy_client) {
+ scheduler_.reset(new policy::HeartbeatScheduler(
+ &gcm_driver_, cloud_policy_client, kFakeEnrollmentDomain, kFakeDeviceId,
+ task_runner_));
+ }
+
void CheckPendingTaskDelay(base::Time last_heartbeat,
base::TimeDelta expected_delay) {
EXPECT_FALSE(last_heartbeat.is_null());
@@ -98,11 +105,10 @@ class HeartbeatSchedulerTest : public testing::Test {
scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
// The HeartbeatScheduler instance under test.
- policy::HeartbeatScheduler scheduler_;
+ scoped_ptr<policy::HeartbeatScheduler> scheduler_;
};
TEST_F(HeartbeatSchedulerTest, Basic) {
- // Just makes sure we can spin up and shutdown the scheduler with
// heartbeats disabled.
settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, false);
ASSERT_TRUE(task_runner_->GetPendingTasks().empty());
@@ -164,7 +170,7 @@ TEST_F(HeartbeatSchedulerTest, ChangeHeartbeatFrequency) {
gcm_driver_.CompleteSend(
kHeartbeatGCMAppID, message.id, gcm::GCMClient::SERVER_ERROR);
EXPECT_EQ(1U, task_runner_->GetPendingTasks().size());
- CheckPendingTaskDelay(scheduler_.last_heartbeat(),
+ CheckPendingTaskDelay(scheduler_->last_heartbeat(),
base::TimeDelta::FromMilliseconds(new_delay));
}
@@ -188,7 +194,7 @@ TEST_F(HeartbeatSchedulerTest, DisableHeartbeats) {
// Should have a new heartbeat task posted.
ASSERT_EQ(1U, task_runner_->GetPendingTasks().size());
CheckPendingTaskDelay(
- scheduler_.last_heartbeat(),
+ scheduler_->last_heartbeat(),
base::TimeDelta::FromMilliseconds(
policy::HeartbeatScheduler::kDefaultHeartbeatIntervalMs));
testing::Mock::VerifyAndClearExpectations(&gcm_driver_);
@@ -222,4 +228,28 @@ 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));
+
+ InitializeScheduler(&cloud_policy_client);
+
+ // 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 got the update request, with a valid
+ // callback.
+ testing::Mock::VerifyAndClearExpectations(&cloud_policy_client);
+ EXPECT_FALSE(callback.is_null());
+ callback.Run(true);
+}
+
} // namespace
« no previous file with comments | « chrome/browser/chromeos/policy/heartbeat_scheduler.cc ('k') | components/policy/core/common/cloud/cloud_policy_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698