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

Unified Diff: components/gcm_driver/gcm_client_impl_unittest.cc

Issue 378643002: [GCM] Check-in with signed in accounts associates device to user (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixing compilation issue on android Created 6 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: components/gcm_driver/gcm_client_impl_unittest.cc
diff --git a/components/gcm_driver/gcm_client_impl_unittest.cc b/components/gcm_driver/gcm_client_impl_unittest.cc
index be241776c0e7b93662cf1a220a5f518e656ea1ab..6cbbd7d4e6e8449c551768f97b73e3a781500ff9 100644
--- a/components/gcm_driver/gcm_client_impl_unittest.cc
+++ b/components/gcm_driver/gcm_client_impl_unittest.cc
@@ -262,6 +262,10 @@ class GCMClientImplTest : public testing::Test,
return gcm_client_->connection_factory_.get();
}
+ const GCMClientImpl::CheckinInfo& device_checkin_info() const {
+ return gcm_client_->device_checkin_info_;
+ }
+
void reset_last_event() {
last_event_ = NONE;
last_app_id_.clear();
@@ -519,6 +523,13 @@ TEST_F(GCMClientImplTest, LoadingCompleted) {
EXPECT_EQ(LOADING_COMPLETED, last_event());
EXPECT_EQ(kDeviceAndroidId, mcs_client()->last_android_id());
EXPECT_EQ(kDeviceSecurityToken, mcs_client()->last_security_token());
+
+ // Checking freshly loaded CheckinInfo.
+ EXPECT_EQ(kDeviceAndroidId, device_checkin_info().android_id);
+ EXPECT_EQ(kDeviceSecurityToken, device_checkin_info().secret);
+ EXPECT_EQ(0UL, device_checkin_info().last_checkin_accounts_count);
+ EXPECT_TRUE(device_checkin_info().accounts_set);
+ EXPECT_TRUE(device_checkin_info().account_tokens.empty());
}
TEST_F(GCMClientImplTest, CheckOut) {
@@ -748,6 +759,7 @@ TEST_F(GCMClientImplCheckinTest, PeriodicCheckin) {
kDeviceSecurityToken,
GServicesSettings::CalculateDigest(settings),
settings);
+
EXPECT_EQ(2, clock()->call_count());
PumpLoopUntilIdle();
@@ -785,6 +797,117 @@ TEST_F(GCMClientImplCheckinTest, LoadGSettingsFromStore) {
gservices_settings().GetMCSFallbackEndpoint());
}
+// This test only checks that periodic checkin happens.
+TEST_F(GCMClientImplCheckinTest, CheckinWithAccounts) {
+ std::map<std::string, std::string> settings;
+ settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval);
+ settings["checkin_url"] = "http://alternative.url/checkin";
+ settings["gcm_hostname"] = "alternative.gcm.host";
+ settings["gcm_secure_port"] = "7777";
+ settings["gcm_registration_url"] = "http://alternative.url/registration";
+ CompleteCheckin(kDeviceAndroidId,
+ kDeviceSecurityToken,
+ GServicesSettings::CalculateDigest(settings),
+ settings);
+
+ std::map<std::string, std::string> account_tokens;
+ account_tokens["test_user1@gmail.com"] = "token1";
+ account_tokens["test_user2@gmail.com"] = "token2";
+ gcm_client()->SetAccountsForCheckin(account_tokens, false);
+
+ EXPECT_EQ(0UL, device_checkin_info().last_checkin_accounts_count);
+ EXPECT_TRUE(device_checkin_info().accounts_set);
+ EXPECT_EQ(account_tokens, device_checkin_info().account_tokens);
+
+ PumpLoopUntilIdle();
+ CompleteCheckin(kDeviceAndroidId,
+ kDeviceSecurityToken,
+ GServicesSettings::CalculateDigest(settings),
+ settings);
+
+ EXPECT_EQ(2UL, device_checkin_info().last_checkin_accounts_count);
+ EXPECT_TRUE(device_checkin_info().accounts_set);
+ EXPECT_EQ(account_tokens, device_checkin_info().account_tokens);
+}
+
+// This test only checks that periodic checkin happens.
+TEST_F(GCMClientImplCheckinTest, CheckinWhenAccountRemoved) {
+ std::map<std::string, std::string> settings;
+ settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval);
+ settings["checkin_url"] = "http://alternative.url/checkin";
+ settings["gcm_hostname"] = "alternative.gcm.host";
+ settings["gcm_secure_port"] = "7777";
+ settings["gcm_registration_url"] = "http://alternative.url/registration";
+ CompleteCheckin(kDeviceAndroidId,
+ kDeviceSecurityToken,
+ GServicesSettings::CalculateDigest(settings),
+ settings);
+
+ std::map<std::string, std::string> account_tokens;
+ account_tokens["test_user1@gmail.com"] = "token1";
+ gcm_client()->SetAccountsForCheckin(account_tokens, true);
+
+ EXPECT_EQ(1UL, device_checkin_info().last_checkin_accounts_count);
+ EXPECT_TRUE(device_checkin_info().accounts_set);
+ EXPECT_EQ(account_tokens, device_checkin_info().account_tokens);
+
+ PumpLoopUntilIdle();
+ CompleteCheckin(kDeviceAndroidId,
+ kDeviceSecurityToken,
+ GServicesSettings::CalculateDigest(settings),
+ settings);
+
+ EXPECT_EQ(1UL, device_checkin_info().last_checkin_accounts_count);
+ EXPECT_TRUE(device_checkin_info().accounts_set);
+ EXPECT_EQ(account_tokens, device_checkin_info().account_tokens);
+}
+
+// This test only checks that periodic checkin happens.
+TEST_F(GCMClientImplCheckinTest, CheckinWhenAccountRemovalImplied) {
+ std::map<std::string, std::string> settings;
+ settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval);
+ settings["checkin_url"] = "http://alternative.url/checkin";
+ settings["gcm_hostname"] = "alternative.gcm.host";
+ settings["gcm_secure_port"] = "7777";
+ settings["gcm_registration_url"] = "http://alternative.url/registration";
+ CompleteCheckin(kDeviceAndroidId,
+ kDeviceSecurityToken,
+ GServicesSettings::CalculateDigest(settings),
+ settings);
+
+ std::map<std::string, std::string> account_tokens;
+ account_tokens["test_user1@gmail.com"] = "token1";
+ account_tokens["test_user2@gmail.com"] = "token2";
+ gcm_client()->SetAccountsForCheckin(account_tokens, false);
+
+ PumpLoopUntilIdle();
+ CompleteCheckin(kDeviceAndroidId,
+ kDeviceSecurityToken,
+ GServicesSettings::CalculateDigest(settings),
+ settings);
+
+ EXPECT_EQ(2UL, device_checkin_info().last_checkin_accounts_count);
+
+ // This should trigger another checkin, because there is less account tokens,
+ // than last reported. This could happen on a restart.
+ account_tokens.erase(account_tokens.find("test_user1@gmail.com"));
+ gcm_client()->SetAccountsForCheckin(account_tokens, false);
+
+ EXPECT_EQ(1UL, device_checkin_info().last_checkin_accounts_count);
+ EXPECT_TRUE(device_checkin_info().accounts_set);
+ EXPECT_EQ(account_tokens, device_checkin_info().account_tokens);
+
+ PumpLoopUntilIdle();
+ CompleteCheckin(kDeviceAndroidId,
+ kDeviceSecurityToken,
+ GServicesSettings::CalculateDigest(settings),
+ settings);
+
+ EXPECT_EQ(1UL, device_checkin_info().last_checkin_accounts_count);
+ EXPECT_TRUE(device_checkin_info().accounts_set);
+ EXPECT_EQ(account_tokens, device_checkin_info().account_tokens);
+}
+
class GCMClientImplStartAndStopTest : public GCMClientImplTest {
public:
GCMClientImplStartAndStopTest();

Powered by Google App Engine
This is Rietveld 408576698