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

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

Issue 2473813002: Notify GCMAppHandlers when the store is reset, so they clear cached IDs (Closed)
Patch Set: Update Cryptauth comment Created 4 years, 1 month 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 bcbc123aaa16a106199d5f0ffa93d0f8be3c4b6f..9272c0d06553929e2166b7681cb259d00f95db6d 100644
--- a/chrome/browser/chromeos/policy/heartbeat_scheduler_unittest.cc
+++ b/chrome/browser/chromeos/policy/heartbeat_scheduler_unittest.cc
@@ -100,6 +100,17 @@ class MockGCMDriver : public testing::StrictMock<gcm::FakeGCMDriver> {
.Times(AnyNumber());
}
+ void ResetStore() {
+ // Defensive copy in case OnStoreReset calls Add/RemoveAppHandler.
+ std::vector<gcm::GCMAppHandler*> app_handler_values;
+ for (const auto& key_value : app_handlers())
+ app_handler_values.push_back(key_value.second);
+ for (gcm::GCMAppHandler* app_handler : app_handler_values) {
+ app_handler->OnStoreReset();
+ // app_handler might now have been deleted.
+ }
+ }
+
private:
gcm::GCMConnectionObserver* observer_ = nullptr;
@@ -210,6 +221,59 @@ TEST_F(HeartbeatSchedulerTest, TemporarilyFailedGCMRegistration) {
task_runner_->RunPendingTasks();
}
+TEST_F(HeartbeatSchedulerTest, StoreResetDuringRegistration) {
+ IgnoreUpstreamNotificationMsg();
+
+ EXPECT_CALL(gcm_driver_, RegisterImpl(kHeartbeatGCMAppID, _));
+ settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, true);
+ testing::Mock::VerifyAndClearExpectations(&gcm_driver_);
+
+ gcm_driver_.ResetStore();
+
+ IgnoreUpstreamNotificationMsg();
+
+ // Successful registration handled ok despite store reset.
+ EXPECT_FALSE(task_runner_->HasPendingTask());
+ EXPECT_CALL(gcm_driver_, SendImpl(kHeartbeatGCMAppID, _, IsHeartbeatMsg()));
+ gcm_driver_.CompleteRegistration(
+ kHeartbeatGCMAppID, gcm::GCMClient::SUCCESS);
+ EXPECT_EQ(1U, task_runner_->NumPendingTasks());
+ task_runner_->RunPendingTasks();
+ testing::Mock::VerifyAndClearExpectations(&gcm_driver_);
+}
+
+TEST_F(HeartbeatSchedulerTest, StoreResetAfterRegistration) {
+ IgnoreUpstreamNotificationMsg();
+
+ // Start from a successful registration.
+ EXPECT_CALL(gcm_driver_, RegisterImpl(kHeartbeatGCMAppID, _));
+ settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, true);
+ EXPECT_CALL(gcm_driver_, SendImpl(kHeartbeatGCMAppID, _, IsHeartbeatMsg()));
+ gcm_driver_.CompleteRegistration(
+ kHeartbeatGCMAppID, gcm::GCMClient::SUCCESS);
+ EXPECT_EQ(1U, task_runner_->NumPendingTasks());
+ task_runner_->RunPendingTasks();
+ testing::Mock::VerifyAndClearExpectations(&gcm_driver_);
+
+ gcm_driver_.IgnoreDefaultHeartbeatsInterval();
+
+ // Reseting the store should trigger re-registration.
+ EXPECT_CALL(gcm_driver_, RegisterImpl(kHeartbeatGCMAppID, _));
+ gcm_driver_.ResetStore();
+ testing::Mock::VerifyAndClearExpectations(&gcm_driver_);
+
+ IgnoreUpstreamNotificationMsg();
+
+ // Once we have successfully re-registered, we should send a heartbeat.
+ EXPECT_FALSE(task_runner_->HasPendingTask());
+ EXPECT_CALL(gcm_driver_, SendImpl(kHeartbeatGCMAppID, _, IsHeartbeatMsg()));
+ gcm_driver_.CompleteRegistration(
+ kHeartbeatGCMAppID, gcm::GCMClient::SUCCESS);
+ EXPECT_EQ(1U, task_runner_->NumPendingTasks());
+ task_runner_->RunPendingTasks();
+ testing::Mock::VerifyAndClearExpectations(&gcm_driver_);
+}
+
TEST_F(HeartbeatSchedulerTest, ChangeHeartbeatFrequency) {
IgnoreUpstreamNotificationMsg();
« no previous file with comments | « chrome/browser/chromeos/policy/heartbeat_scheduler.cc ('k') | chrome/browser/extensions/extension_gcm_app_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698