| 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..868c4cfed375024b9a6039ee4c0cc07c7428a858 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_,
|
| + &cloud_policy_client_,
|
| + kFakeEnrollmentDomain,
|
| + kFakeDeviceId,
|
| + task_runner_) {}
|
|
|
| void SetUp() override {
|
| settings_helper_.ReplaceProvider(chromeos::kHeartbeatEnabled);
|
| @@ -93,6 +99,7 @@ class HeartbeatSchedulerTest : public testing::Test {
|
| base::MessageLoop loop_;
|
| MockGCMDriver gcm_driver_;
|
| chromeos::ScopedCrosSettingsTestHelper settings_helper_;
|
| + testing::NiceMock<policy::MockCloudPolicyClient> cloud_policy_client_;
|
|
|
| // TaskRunner used to run individual tests.
|
| scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
|
| @@ -222,4 +229,25 @@ TEST_F(HeartbeatSchedulerTest, CheckMessageContents) {
|
| EXPECT_EQ(kFakeDeviceId, message.data["device_id"]);
|
| }
|
|
|
| +TEST_F(HeartbeatSchedulerTest, SendGcmIdUpdate) {
|
| + // Verifies that GCM id update request was sent after GCM registration.
|
| + cloud_policy_client_.SetDMToken(kDMToken);
|
| + policy::CloudPolicyClient::StatusCallback callback;
|
| + EXPECT_CALL(cloud_policy_client_, UpdateGcmId(kRegistrationId, _))
|
| + .WillOnce(SaveArg<1>(&callback));
|
| +
|
| + // Enable heartbeats.
|
| + 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
|
|
|