| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/gcm_driver/gcm_account_mapper.h" | 5 #include "components/gcm_driver/gcm_account_mapper.h" |
| 6 | 6 |
| 7 #include "base/test/simple_test_clock.h" | 7 #include "base/test/simple_test_clock.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "components/gcm_driver/fake_gcm_driver.h" | 9 #include "components/gcm_driver/fake_gcm_driver.h" |
| 10 #include "google_apis/gcm/engine/account_mapping.h" | 10 #include "google_apis/gcm/engine/account_mapping.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 CustomFakeGCMDriver(); | 81 CustomFakeGCMDriver(); |
| 82 virtual ~CustomFakeGCMDriver(); | 82 virtual ~CustomFakeGCMDriver(); |
| 83 | 83 |
| 84 virtual void UpdateAccountMapping( | 84 virtual void UpdateAccountMapping( |
| 85 const AccountMapping& account_mapping) OVERRIDE; | 85 const AccountMapping& account_mapping) OVERRIDE; |
| 86 virtual void RemoveAccountMapping(const std::string& account_id) OVERRIDE; | 86 virtual void RemoveAccountMapping(const std::string& account_id) OVERRIDE; |
| 87 virtual void AddAppHandler(const std::string& app_id, | 87 virtual void AddAppHandler(const std::string& app_id, |
| 88 GCMAppHandler* handler) OVERRIDE; | 88 GCMAppHandler* handler) OVERRIDE; |
| 89 virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE; | 89 virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE; |
| 90 virtual void RegisterImpl( |
| 91 const std::string& app_id, |
| 92 const std::vector<std::string>& sender_ids) OVERRIDE; |
| 90 | 93 |
| 94 void CompleteRegister(const std::string& registration_id, |
| 95 GCMClient::Result result); |
| 91 void CompleteSend(const std::string& message_id, GCMClient::Result result); | 96 void CompleteSend(const std::string& message_id, GCMClient::Result result); |
| 92 void AcknowledgeSend(const std::string& message_id); | 97 void AcknowledgeSend(const std::string& message_id); |
| 93 void MessageSendError(const std::string& message_id); | 98 void MessageSendError(const std::string& message_id); |
| 94 | 99 |
| 95 void CompleteSendAllMessages(); | 100 void CompleteSendAllMessages(); |
| 96 void AcknowledgeSendAllMessages(); | 101 void AcknowledgeSendAllMessages(); |
| 97 | 102 |
| 98 void SetLastMessageAction(const std::string& message_id, | 103 void SetLastMessageAction(const std::string& message_id, |
| 99 LastMessageAction action); | 104 LastMessageAction action); |
| 100 void Clear(); | 105 void Clear(); |
| 101 | 106 |
| 102 const AccountMapping& last_account_mapping() const { | 107 const AccountMapping& last_account_mapping() const { |
| 103 return account_mapping_; | 108 return account_mapping_; |
| 104 } | 109 } |
| 105 const std::string& last_message_id() const { return last_message_id_; } | 110 const std::string& last_message_id() const { return last_message_id_; } |
| 106 const std::string& last_removed_account_id() const { | 111 const std::string& last_removed_account_id() const { |
| 107 return last_removed_account_id_; | 112 return last_removed_account_id_; |
| 108 } | 113 } |
| 109 LastMessageAction last_action() const { return last_action_; } | 114 LastMessageAction last_action() const { return last_action_; } |
| 115 bool registration_id_requested() const { return registration_id_requested_; } |
| 110 | 116 |
| 111 protected: | 117 protected: |
| 112 virtual void SendImpl(const std::string& app_id, | 118 virtual void SendImpl(const std::string& app_id, |
| 113 const std::string& receiver_id, | 119 const std::string& receiver_id, |
| 114 const GCMClient::OutgoingMessage& message) OVERRIDE; | 120 const GCMClient::OutgoingMessage& message) OVERRIDE; |
| 115 | 121 |
| 116 private: | 122 private: |
| 117 AccountMapping account_mapping_; | 123 AccountMapping account_mapping_; |
| 118 std::string last_message_id_; | 124 std::string last_message_id_; |
| 119 std::string last_removed_account_id_; | 125 std::string last_removed_account_id_; |
| 120 LastMessageAction last_action_; | 126 LastMessageAction last_action_; |
| 121 std::map<std::string, LastMessageAction> all_messages_; | 127 std::map<std::string, LastMessageAction> all_messages_; |
| 128 bool registration_id_requested_; |
| 122 }; | 129 }; |
| 123 | 130 |
| 124 CustomFakeGCMDriver::CustomFakeGCMDriver() : last_action_(NONE) { | 131 CustomFakeGCMDriver::CustomFakeGCMDriver() |
| 132 : last_action_(NONE), registration_id_requested_(false) { |
| 125 } | 133 } |
| 126 | 134 |
| 127 CustomFakeGCMDriver::~CustomFakeGCMDriver() { | 135 CustomFakeGCMDriver::~CustomFakeGCMDriver() { |
| 128 } | 136 } |
| 129 | 137 |
| 130 void CustomFakeGCMDriver::UpdateAccountMapping( | 138 void CustomFakeGCMDriver::UpdateAccountMapping( |
| 131 const AccountMapping& account_mapping) { | 139 const AccountMapping& account_mapping) { |
| 132 account_mapping_.email = account_mapping.email; | 140 account_mapping_.email = account_mapping.email; |
| 133 account_mapping_.account_id = account_mapping.account_id; | 141 account_mapping_.account_id = account_mapping.account_id; |
| 134 account_mapping_.access_token = account_mapping.access_token; | 142 account_mapping_.access_token = account_mapping.access_token; |
| 135 account_mapping_.status = account_mapping.status; | 143 account_mapping_.status = account_mapping.status; |
| 136 account_mapping_.status_change_timestamp = | 144 account_mapping_.status_change_timestamp = |
| 137 account_mapping.status_change_timestamp; | 145 account_mapping.status_change_timestamp; |
| 138 account_mapping_.last_message_id = account_mapping.last_message_id; | 146 account_mapping_.last_message_id = account_mapping.last_message_id; |
| 139 } | 147 } |
| 140 | 148 |
| 141 void CustomFakeGCMDriver::RemoveAccountMapping(const std::string& account_id) { | 149 void CustomFakeGCMDriver::RemoveAccountMapping(const std::string& account_id) { |
| 142 last_removed_account_id_ = account_id; | 150 last_removed_account_id_ = account_id; |
| 143 } | 151 } |
| 144 | 152 |
| 145 void CustomFakeGCMDriver::AddAppHandler(const std::string& app_id, | 153 void CustomFakeGCMDriver::AddAppHandler(const std::string& app_id, |
| 146 GCMAppHandler* handler) { | 154 GCMAppHandler* handler) { |
| 147 GCMDriver::AddAppHandler(app_id, handler); | 155 GCMDriver::AddAppHandler(app_id, handler); |
| 148 } | 156 } |
| 149 | 157 |
| 150 void CustomFakeGCMDriver::RemoveAppHandler(const std::string& app_id) { | 158 void CustomFakeGCMDriver::RemoveAppHandler(const std::string& app_id) { |
| 151 GCMDriver::RemoveAppHandler(app_id); | 159 GCMDriver::RemoveAppHandler(app_id); |
| 152 } | 160 } |
| 153 | 161 |
| 162 void CustomFakeGCMDriver::RegisterImpl( |
| 163 const std::string& app_id, |
| 164 const std::vector<std::string>& sender_ids) { |
| 165 DCHECK_EQ(kGCMAccountMapperAppId, app_id); |
| 166 DCHECK_EQ(1u, sender_ids.size()); |
| 167 DCHECK_EQ(kGCMAccountMapperSenderId, sender_ids[0]); |
| 168 registration_id_requested_ = true; |
| 169 } |
| 170 |
| 171 void CustomFakeGCMDriver::CompleteRegister(const std::string& registration_id, |
| 172 GCMClient::Result result) { |
| 173 RegisterFinished(kGCMAccountMapperAppId, registration_id, result); |
| 174 } |
| 175 |
| 154 void CustomFakeGCMDriver::CompleteSend(const std::string& message_id, | 176 void CustomFakeGCMDriver::CompleteSend(const std::string& message_id, |
| 155 GCMClient::Result result) { | 177 GCMClient::Result result) { |
| 156 SendFinished(kGCMAccountMapperAppId, message_id, result); | 178 SendFinished(kGCMAccountMapperAppId, message_id, result); |
| 157 SetLastMessageAction(message_id, SEND_FINISHED); | 179 SetLastMessageAction(message_id, SEND_FINISHED); |
| 158 } | 180 } |
| 159 | 181 |
| 160 void CustomFakeGCMDriver::AcknowledgeSend(const std::string& message_id) { | 182 void CustomFakeGCMDriver::AcknowledgeSend(const std::string& message_id) { |
| 161 GetAppHandler(kGCMAccountMapperAppId) | 183 GetAppHandler(kGCMAccountMapperAppId) |
| 162 ->OnSendAcknowledged(kGCMAccountMapperAppId, message_id); | 184 ->OnSendAcknowledged(kGCMAccountMapperAppId, message_id); |
| 163 SetLastMessageAction(message_id, SEND_ACKNOWLEDGED); | 185 SetLastMessageAction(message_id, SEND_ACKNOWLEDGED); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 if (iter->second == SEND_FINISHED) | 220 if (iter->second == SEND_FINISHED) |
| 199 AcknowledgeSend(iter->first); | 221 AcknowledgeSend(iter->first); |
| 200 } | 222 } |
| 201 } | 223 } |
| 202 | 224 |
| 203 void CustomFakeGCMDriver::Clear() { | 225 void CustomFakeGCMDriver::Clear() { |
| 204 account_mapping_ = AccountMapping(); | 226 account_mapping_ = AccountMapping(); |
| 205 last_message_id_.clear(); | 227 last_message_id_.clear(); |
| 206 last_removed_account_id_.clear(); | 228 last_removed_account_id_.clear(); |
| 207 last_action_ = NONE; | 229 last_action_ = NONE; |
| 230 registration_id_requested_ = false; |
| 208 } | 231 } |
| 209 | 232 |
| 210 void CustomFakeGCMDriver::SetLastMessageAction(const std::string& message_id, | 233 void CustomFakeGCMDriver::SetLastMessageAction(const std::string& message_id, |
| 211 LastMessageAction action) { | 234 LastMessageAction action) { |
| 212 last_action_ = action; | 235 last_action_ = action; |
| 213 last_message_id_ = message_id; | 236 last_message_id_ = message_id; |
| 214 all_messages_[message_id] = action; | 237 all_messages_[message_id] = action; |
| 215 } | 238 } |
| 216 | 239 |
| 217 } // namespace | 240 } // namespace |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 void GCMAccountMapperTest::Restart() { | 272 void GCMAccountMapperTest::Restart() { |
| 250 if (account_mapper_) | 273 if (account_mapper_) |
| 251 account_mapper_->ShutdownHandler(); | 274 account_mapper_->ShutdownHandler(); |
| 252 account_mapper_.reset(new GCMAccountMapper(&gcm_driver_)); | 275 account_mapper_.reset(new GCMAccountMapper(&gcm_driver_)); |
| 253 scoped_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); | 276 scoped_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); |
| 254 clock_ = clock.get(); | 277 clock_ = clock.get(); |
| 255 account_mapper_->SetClockForTesting(clock.PassAs<base::Clock>()); | 278 account_mapper_->SetClockForTesting(clock.PassAs<base::Clock>()); |
| 256 } | 279 } |
| 257 | 280 |
| 258 // Tests the initialization of account mappings (from the store) when empty. | 281 // Tests the initialization of account mappings (from the store) when empty. |
| 282 // It also checks that initialization triggers registration ID request. |
| 259 TEST_F(GCMAccountMapperTest, InitializeAccountMappingsEmpty) { | 283 TEST_F(GCMAccountMapperTest, InitializeAccountMappingsEmpty) { |
| 260 GCMAccountMapper::AccountMappings account_mappings; | 284 EXPECT_FALSE(gcm_driver().registration_id_requested()); |
| 261 mapper()->Initialize(account_mappings, ""); | 285 mapper()->Initialize(GCMAccountMapper::AccountMappings()); |
| 262 EXPECT_TRUE(GetAccounts().empty()); | 286 EXPECT_TRUE(GetAccounts().empty()); |
| 287 EXPECT_TRUE(gcm_driver().registration_id_requested()); |
| 288 } |
| 289 |
| 290 // Tests that registration is retried, unless there is async operation pending. |
| 291 TEST_F(GCMAccountMapperTest, RegistrationRetryUponFailure) { |
| 292 mapper()->Initialize(GCMAccountMapper::AccountMappings()); |
| 293 EXPECT_TRUE(gcm_driver().registration_id_requested()); |
| 294 gcm_driver().Clear(); |
| 295 gcm_driver().CompleteRegister(kRegistrationId, GCMClient::UNKNOWN_ERROR); |
| 296 EXPECT_TRUE(gcm_driver().registration_id_requested()); |
| 297 gcm_driver().Clear(); |
| 298 gcm_driver().CompleteRegister(kRegistrationId, |
| 299 GCMClient::ASYNC_OPERATION_PENDING); |
| 300 EXPECT_FALSE(gcm_driver().registration_id_requested()); |
| 263 } | 301 } |
| 264 | 302 |
| 265 // Tests the initialization of account mappings (from the store). | 303 // Tests the initialization of account mappings (from the store). |
| 266 TEST_F(GCMAccountMapperTest, InitializeAccountMappings) { | 304 TEST_F(GCMAccountMapperTest, InitializeAccountMappings) { |
| 267 GCMAccountMapper::AccountMappings account_mappings; | 305 GCMAccountMapper::AccountMappings account_mappings; |
| 268 AccountMapping account_mapping1 = MakeAccountMapping("acc_id1", | 306 AccountMapping account_mapping1 = MakeAccountMapping("acc_id1", |
| 269 AccountMapping::MAPPED, | 307 AccountMapping::MAPPED, |
| 270 base::Time::Now(), | 308 base::Time::Now(), |
| 271 std::string()); | 309 std::string()); |
| 272 AccountMapping account_mapping2 = MakeAccountMapping("acc_id2", | 310 AccountMapping account_mapping2 = MakeAccountMapping("acc_id2", |
| 273 AccountMapping::ADDING, | 311 AccountMapping::ADDING, |
| 274 base::Time::Now(), | 312 base::Time::Now(), |
| 275 "add_message_1"); | 313 "add_message_1"); |
| 276 account_mappings.push_back(account_mapping1); | 314 account_mappings.push_back(account_mapping1); |
| 277 account_mappings.push_back(account_mapping2); | 315 account_mappings.push_back(account_mapping2); |
| 278 | 316 |
| 279 mapper()->Initialize(account_mappings, ""); | 317 mapper()->Initialize(account_mappings); |
| 280 | 318 |
| 281 GCMAccountMapper::AccountMappings mappings = GetAccounts(); | 319 GCMAccountMapper::AccountMappings mappings = GetAccounts(); |
| 282 EXPECT_EQ(2UL, mappings.size()); | 320 EXPECT_EQ(2UL, mappings.size()); |
| 283 GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin(); | 321 GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin(); |
| 284 | 322 |
| 285 EXPECT_EQ(account_mapping1.account_id, iter->account_id); | 323 EXPECT_EQ(account_mapping1.account_id, iter->account_id); |
| 286 EXPECT_EQ(account_mapping1.email, iter->email); | 324 EXPECT_EQ(account_mapping1.email, iter->email); |
| 287 EXPECT_TRUE(account_mapping1.access_token.empty()); | 325 EXPECT_TRUE(account_mapping1.access_token.empty()); |
| 288 EXPECT_EQ(account_mapping1.status, iter->status); | 326 EXPECT_EQ(account_mapping1.status, iter->status); |
| 289 EXPECT_EQ(account_mapping1.status_change_timestamp, | 327 EXPECT_EQ(account_mapping1.status_change_timestamp, |
| 290 iter->status_change_timestamp); | 328 iter->status_change_timestamp); |
| 291 EXPECT_TRUE(account_mapping1.last_message_id.empty()); | 329 EXPECT_TRUE(account_mapping1.last_message_id.empty()); |
| 292 | 330 |
| 293 ++iter; | 331 ++iter; |
| 294 EXPECT_EQ(account_mapping2.account_id, iter->account_id); | 332 EXPECT_EQ(account_mapping2.account_id, iter->account_id); |
| 295 EXPECT_EQ(account_mapping2.email, iter->email); | 333 EXPECT_EQ(account_mapping2.email, iter->email); |
| 296 EXPECT_TRUE(account_mapping2.access_token.empty()); | 334 EXPECT_TRUE(account_mapping2.access_token.empty()); |
| 297 EXPECT_EQ(account_mapping2.status, iter->status); | 335 EXPECT_EQ(account_mapping2.status, iter->status); |
| 298 EXPECT_EQ(account_mapping2.status_change_timestamp, | 336 EXPECT_EQ(account_mapping2.status_change_timestamp, |
| 299 iter->status_change_timestamp); | 337 iter->status_change_timestamp); |
| 300 EXPECT_EQ(account_mapping2.last_message_id, iter->last_message_id); | 338 EXPECT_EQ(account_mapping2.last_message_id, iter->last_message_id); |
| 301 } | 339 } |
| 302 | 340 |
| 341 // Tests that account tokens are not processed until registration ID is |
| 342 // available. |
| 343 TEST_F(GCMAccountMapperTest, SetAccountTokensOnlyWorksWithRegisterationId) { |
| 344 // Start with empty list. |
| 345 mapper()->Initialize(GCMAccountMapper::AccountMappings()); |
| 346 |
| 347 std::vector<GCMClient::AccountTokenInfo> account_tokens; |
| 348 account_tokens.push_back(MakeAccountTokenInfo("acc_id")); |
| 349 mapper()->SetAccountTokens(account_tokens); |
| 350 |
| 351 EXPECT_TRUE(GetAccounts().empty()); |
| 352 |
| 353 account_tokens.clear(); |
| 354 account_tokens.push_back(MakeAccountTokenInfo("acc_id1")); |
| 355 account_tokens.push_back(MakeAccountTokenInfo("acc_id2")); |
| 356 mapper()->SetAccountTokens(account_tokens); |
| 357 |
| 358 EXPECT_TRUE(GetAccounts().empty()); |
| 359 |
| 360 gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS); |
| 361 |
| 362 GCMAccountMapper::AccountMappings mappings = GetAccounts(); |
| 363 EXPECT_EQ(2UL, mappings.size()); |
| 364 EXPECT_EQ("acc_id1", mappings[0].account_id); |
| 365 EXPECT_EQ("acc_id2", mappings[1].account_id); |
| 366 } |
| 367 |
| 303 // Tests the part where a new account is added with a token, to the point when | 368 // Tests the part where a new account is added with a token, to the point when |
| 304 // GCM message is sent. | 369 // GCM message is sent. |
| 305 TEST_F(GCMAccountMapperTest, AddMappingToMessageSent) { | 370 TEST_F(GCMAccountMapperTest, AddMappingToMessageSent) { |
| 306 mapper()->Initialize(GCMAccountMapper::AccountMappings(), kRegistrationId); | 371 mapper()->Initialize(GCMAccountMapper::AccountMappings()); |
| 372 gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS); |
| 307 | 373 |
| 308 std::vector<GCMClient::AccountTokenInfo> account_tokens; | 374 std::vector<GCMClient::AccountTokenInfo> account_tokens; |
| 309 GCMClient::AccountTokenInfo account_token = MakeAccountTokenInfo("acc_id"); | 375 GCMClient::AccountTokenInfo account_token = MakeAccountTokenInfo("acc_id"); |
| 310 account_tokens.push_back(account_token); | 376 account_tokens.push_back(account_token); |
| 311 mapper()->SetAccountTokens(account_tokens); | 377 mapper()->SetAccountTokens(account_tokens); |
| 312 | 378 |
| 313 GCMAccountMapper::AccountMappings mappings = GetAccounts(); | 379 GCMAccountMapper::AccountMappings mappings = GetAccounts(); |
| 314 EXPECT_EQ(1UL, mappings.size()); | 380 EXPECT_EQ(1UL, mappings.size()); |
| 315 GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin(); | 381 GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin(); |
| 316 EXPECT_EQ("acc_id", iter->account_id); | 382 EXPECT_EQ("acc_id", iter->account_id); |
| 317 EXPECT_EQ("acc_id@gmail.com", iter->email); | 383 EXPECT_EQ("acc_id@gmail.com", iter->email); |
| 318 EXPECT_EQ("acc_id_token", iter->access_token); | 384 EXPECT_EQ("acc_id_token", iter->access_token); |
| 319 EXPECT_EQ(AccountMapping::NEW, iter->status); | 385 EXPECT_EQ(AccountMapping::NEW, iter->status); |
| 320 EXPECT_EQ(base::Time(), iter->status_change_timestamp); | 386 EXPECT_EQ(base::Time(), iter->status_change_timestamp); |
| 321 | 387 |
| 322 EXPECT_TRUE(!gcm_driver().last_message_id().empty()); | 388 EXPECT_TRUE(!gcm_driver().last_message_id().empty()); |
| 323 } | 389 } |
| 324 | 390 |
| 325 // Tests the part where GCM message is successfully queued. | 391 // Tests the part where GCM message is successfully queued. |
| 326 TEST_F(GCMAccountMapperTest, AddMappingMessageQueued) { | 392 TEST_F(GCMAccountMapperTest, AddMappingMessageQueued) { |
| 327 mapper()->Initialize(GCMAccountMapper::AccountMappings(), kRegistrationId); | 393 mapper()->Initialize(GCMAccountMapper::AccountMappings()); |
| 394 gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS); |
| 328 | 395 |
| 329 std::vector<GCMClient::AccountTokenInfo> account_tokens; | 396 std::vector<GCMClient::AccountTokenInfo> account_tokens; |
| 330 GCMClient::AccountTokenInfo account_token = MakeAccountTokenInfo("acc_id"); | 397 GCMClient::AccountTokenInfo account_token = MakeAccountTokenInfo("acc_id"); |
| 331 account_tokens.push_back(account_token); | 398 account_tokens.push_back(account_token); |
| 332 mapper()->SetAccountTokens(account_tokens); | 399 mapper()->SetAccountTokens(account_tokens); |
| 333 | 400 |
| 334 clock()->SetNow(base::Time::Now()); | 401 clock()->SetNow(base::Time::Now()); |
| 335 gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS); | 402 gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS); |
| 336 | 403 |
| 337 EXPECT_EQ(account_token.email, gcm_driver().last_account_mapping().email); | 404 EXPECT_EQ(account_token.email, gcm_driver().last_account_mapping().email); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 350 EXPECT_EQ(account_token.email, iter->email); | 417 EXPECT_EQ(account_token.email, iter->email); |
| 351 EXPECT_EQ(account_token.account_id, iter->account_id); | 418 EXPECT_EQ(account_token.account_id, iter->account_id); |
| 352 EXPECT_EQ(account_token.access_token, iter->access_token); | 419 EXPECT_EQ(account_token.access_token, iter->access_token); |
| 353 EXPECT_EQ(AccountMapping::ADDING, iter->status); | 420 EXPECT_EQ(AccountMapping::ADDING, iter->status); |
| 354 EXPECT_EQ(clock()->Now(), iter->status_change_timestamp); | 421 EXPECT_EQ(clock()->Now(), iter->status_change_timestamp); |
| 355 EXPECT_EQ(gcm_driver().last_message_id(), iter->last_message_id); | 422 EXPECT_EQ(gcm_driver().last_message_id(), iter->last_message_id); |
| 356 } | 423 } |
| 357 | 424 |
| 358 // Tests status change from ADDING to MAPPED (Message is acknowledged). | 425 // Tests status change from ADDING to MAPPED (Message is acknowledged). |
| 359 TEST_F(GCMAccountMapperTest, AddMappingMessageAcknowledged) { | 426 TEST_F(GCMAccountMapperTest, AddMappingMessageAcknowledged) { |
| 360 mapper()->Initialize(GCMAccountMapper::AccountMappings(), kRegistrationId); | 427 mapper()->Initialize(GCMAccountMapper::AccountMappings()); |
| 428 gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS); |
| 361 | 429 |
| 362 std::vector<GCMClient::AccountTokenInfo> account_tokens; | 430 std::vector<GCMClient::AccountTokenInfo> account_tokens; |
| 363 GCMClient::AccountTokenInfo account_token = MakeAccountTokenInfo("acc_id"); | 431 GCMClient::AccountTokenInfo account_token = MakeAccountTokenInfo("acc_id"); |
| 364 account_tokens.push_back(account_token); | 432 account_tokens.push_back(account_token); |
| 365 mapper()->SetAccountTokens(account_tokens); | 433 mapper()->SetAccountTokens(account_tokens); |
| 366 | 434 |
| 367 clock()->SetNow(base::Time::Now()); | 435 clock()->SetNow(base::Time::Now()); |
| 368 gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS); | 436 gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS); |
| 369 clock()->SetNow(base::Time::Now()); | 437 clock()->SetNow(base::Time::Now()); |
| 370 gcm_driver().AcknowledgeSend(gcm_driver().last_message_id()); | 438 gcm_driver().AcknowledgeSend(gcm_driver().last_message_id()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 385 EXPECT_EQ(account_token.account_id, iter->account_id); | 453 EXPECT_EQ(account_token.account_id, iter->account_id); |
| 386 EXPECT_EQ(account_token.access_token, iter->access_token); | 454 EXPECT_EQ(account_token.access_token, iter->access_token); |
| 387 EXPECT_EQ(AccountMapping::MAPPED, iter->status); | 455 EXPECT_EQ(AccountMapping::MAPPED, iter->status); |
| 388 EXPECT_EQ(clock()->Now(), iter->status_change_timestamp); | 456 EXPECT_EQ(clock()->Now(), iter->status_change_timestamp); |
| 389 EXPECT_TRUE(iter->last_message_id.empty()); | 457 EXPECT_TRUE(iter->last_message_id.empty()); |
| 390 } | 458 } |
| 391 | 459 |
| 392 // Tests status change form ADDING to MAPPED (When message was acknowledged, | 460 // Tests status change form ADDING to MAPPED (When message was acknowledged, |
| 393 // after Chrome was restarted). | 461 // after Chrome was restarted). |
| 394 TEST_F(GCMAccountMapperTest, AddMappingMessageAckedAfterRestart) { | 462 TEST_F(GCMAccountMapperTest, AddMappingMessageAckedAfterRestart) { |
| 395 mapper()->Initialize(GCMAccountMapper::AccountMappings(), kRegistrationId); | 463 mapper()->Initialize(GCMAccountMapper::AccountMappings()); |
| 464 gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS); |
| 396 | 465 |
| 397 std::vector<GCMClient::AccountTokenInfo> account_tokens; | 466 std::vector<GCMClient::AccountTokenInfo> account_tokens; |
| 398 GCMClient::AccountTokenInfo account_token = MakeAccountTokenInfo("acc_id"); | 467 GCMClient::AccountTokenInfo account_token = MakeAccountTokenInfo("acc_id"); |
| 399 account_tokens.push_back(account_token); | 468 account_tokens.push_back(account_token); |
| 400 mapper()->SetAccountTokens(account_tokens); | 469 mapper()->SetAccountTokens(account_tokens); |
| 401 | 470 |
| 402 clock()->SetNow(base::Time::Now()); | 471 clock()->SetNow(base::Time::Now()); |
| 403 gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS); | 472 gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS); |
| 404 | 473 |
| 405 Restart(); | 474 Restart(); |
| 406 GCMAccountMapper::AccountMappings stored_mappings; | 475 GCMAccountMapper::AccountMappings stored_mappings; |
| 407 stored_mappings.push_back(gcm_driver().last_account_mapping()); | 476 stored_mappings.push_back(gcm_driver().last_account_mapping()); |
| 408 mapper()->Initialize(stored_mappings, kRegistrationId); | 477 mapper()->Initialize(stored_mappings); |
| 409 | 478 |
| 410 clock()->SetNow(base::Time::Now()); | 479 clock()->SetNow(base::Time::Now()); |
| 411 gcm_driver().AcknowledgeSend(gcm_driver().last_message_id()); | 480 gcm_driver().AcknowledgeSend(gcm_driver().last_message_id()); |
| 412 | 481 |
| 413 EXPECT_EQ(account_token.email, gcm_driver().last_account_mapping().email); | 482 EXPECT_EQ(account_token.email, gcm_driver().last_account_mapping().email); |
| 414 EXPECT_EQ(account_token.account_id, | 483 EXPECT_EQ(account_token.account_id, |
| 415 gcm_driver().last_account_mapping().account_id); | 484 gcm_driver().last_account_mapping().account_id); |
| 416 EXPECT_EQ(account_token.access_token, | 485 EXPECT_EQ(account_token.access_token, |
| 417 gcm_driver().last_account_mapping().access_token); | 486 gcm_driver().last_account_mapping().access_token); |
| 418 EXPECT_EQ(AccountMapping::MAPPED, gcm_driver().last_account_mapping().status); | 487 EXPECT_EQ(AccountMapping::MAPPED, gcm_driver().last_account_mapping().status); |
| 419 EXPECT_EQ(clock()->Now(), | 488 EXPECT_EQ(clock()->Now(), |
| 420 gcm_driver().last_account_mapping().status_change_timestamp); | 489 gcm_driver().last_account_mapping().status_change_timestamp); |
| 421 EXPECT_TRUE(gcm_driver().last_account_mapping().last_message_id.empty()); | 490 EXPECT_TRUE(gcm_driver().last_account_mapping().last_message_id.empty()); |
| 422 | 491 |
| 423 GCMAccountMapper::AccountMappings mappings = GetAccounts(); | 492 GCMAccountMapper::AccountMappings mappings = GetAccounts(); |
| 424 GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin(); | 493 GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin(); |
| 425 EXPECT_EQ(account_token.email, iter->email); | 494 EXPECT_EQ(account_token.email, iter->email); |
| 426 EXPECT_EQ(account_token.account_id, iter->account_id); | 495 EXPECT_EQ(account_token.account_id, iter->account_id); |
| 427 EXPECT_EQ(account_token.access_token, iter->access_token); | 496 EXPECT_EQ(account_token.access_token, iter->access_token); |
| 428 EXPECT_EQ(AccountMapping::MAPPED, iter->status); | 497 EXPECT_EQ(AccountMapping::MAPPED, iter->status); |
| 429 EXPECT_EQ(clock()->Now(), iter->status_change_timestamp); | 498 EXPECT_EQ(clock()->Now(), iter->status_change_timestamp); |
| 430 EXPECT_TRUE(iter->last_message_id.empty()); | 499 EXPECT_TRUE(iter->last_message_id.empty()); |
| 431 } | 500 } |
| 432 | 501 |
| 433 // Tests a case when ADD message times out for a new account. | 502 // Tests a case when ADD message times out for a new account. |
| 434 TEST_F(GCMAccountMapperTest, AddMappingMessageSendErrorForNewAccount) { | 503 TEST_F(GCMAccountMapperTest, AddMappingMessageSendErrorForNewAccount) { |
| 435 mapper()->Initialize(GCMAccountMapper::AccountMappings(), kRegistrationId); | 504 mapper()->Initialize(GCMAccountMapper::AccountMappings()); |
| 505 gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS); |
| 436 | 506 |
| 437 std::vector<GCMClient::AccountTokenInfo> account_tokens; | 507 std::vector<GCMClient::AccountTokenInfo> account_tokens; |
| 438 GCMClient::AccountTokenInfo account_token = MakeAccountTokenInfo("acc_id"); | 508 GCMClient::AccountTokenInfo account_token = MakeAccountTokenInfo("acc_id"); |
| 439 account_tokens.push_back(account_token); | 509 account_tokens.push_back(account_token); |
| 440 mapper()->SetAccountTokens(account_tokens); | 510 mapper()->SetAccountTokens(account_tokens); |
| 441 | 511 |
| 442 clock()->SetNow(base::Time::Now()); | 512 clock()->SetNow(base::Time::Now()); |
| 443 gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS); | 513 gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS); |
| 444 | 514 |
| 445 clock()->SetNow(base::Time::Now()); | 515 clock()->SetNow(base::Time::Now()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 457 TEST_F(GCMAccountMapperTest, AddMappingMessageSendErrorForMappedAccount) { | 527 TEST_F(GCMAccountMapperTest, AddMappingMessageSendErrorForMappedAccount) { |
| 458 // Start with one account that is mapped. | 528 // Start with one account that is mapped. |
| 459 base::Time status_change_timestamp = base::Time::Now(); | 529 base::Time status_change_timestamp = base::Time::Now(); |
| 460 AccountMapping mapping = MakeAccountMapping("acc_id", | 530 AccountMapping mapping = MakeAccountMapping("acc_id", |
| 461 AccountMapping::MAPPED, | 531 AccountMapping::MAPPED, |
| 462 status_change_timestamp, | 532 status_change_timestamp, |
| 463 "add_message_id"); | 533 "add_message_id"); |
| 464 | 534 |
| 465 GCMAccountMapper::AccountMappings stored_mappings; | 535 GCMAccountMapper::AccountMappings stored_mappings; |
| 466 stored_mappings.push_back(mapping); | 536 stored_mappings.push_back(mapping); |
| 467 mapper()->Initialize(stored_mappings, kRegistrationId); | 537 mapper()->Initialize(stored_mappings); |
| 538 gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS); |
| 468 | 539 |
| 469 clock()->SetNow(base::Time::Now()); | 540 clock()->SetNow(base::Time::Now()); |
| 470 gcm_driver().MessageSendError("add_message_id"); | 541 gcm_driver().MessageSendError("add_message_id"); |
| 471 | 542 |
| 472 // No new message is sent because of the send error, as the token is stale. | 543 // No new message is sent because of the send error, as the token is stale. |
| 473 // Because the account was new, the entry should be deleted. | 544 // Because the account was new, the entry should be deleted. |
| 474 EXPECT_TRUE(gcm_driver().last_message_id().empty()); | 545 EXPECT_TRUE(gcm_driver().last_message_id().empty()); |
| 475 | 546 |
| 476 GCMAccountMapper::AccountMappings mappings = GetAccounts(); | 547 GCMAccountMapper::AccountMappings mappings = GetAccounts(); |
| 477 GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin(); | 548 GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin(); |
| 478 EXPECT_EQ(mapping.email, iter->email); | 549 EXPECT_EQ(mapping.email, iter->email); |
| 479 EXPECT_EQ(mapping.account_id, iter->account_id); | 550 EXPECT_EQ(mapping.account_id, iter->account_id); |
| 480 EXPECT_EQ(mapping.access_token, iter->access_token); | 551 EXPECT_EQ(mapping.access_token, iter->access_token); |
| 481 EXPECT_EQ(AccountMapping::MAPPED, iter->status); | 552 EXPECT_EQ(AccountMapping::MAPPED, iter->status); |
| 482 EXPECT_EQ(status_change_timestamp, iter->status_change_timestamp); | 553 EXPECT_EQ(status_change_timestamp, iter->status_change_timestamp); |
| 483 EXPECT_TRUE(iter->last_message_id.empty()); | 554 EXPECT_TRUE(iter->last_message_id.empty()); |
| 484 } | 555 } |
| 485 | 556 |
| 486 // Tests that a missing token for an account will trigger removing of that | 557 // Tests that a missing token for an account will trigger removing of that |
| 487 // account. This test goes only until the message is passed to GCM. | 558 // account. This test goes only until the message is passed to GCM. |
| 488 TEST_F(GCMAccountMapperTest, RemoveMappingToMessageSent) { | 559 TEST_F(GCMAccountMapperTest, RemoveMappingToMessageSent) { |
| 489 // Start with one account that is mapped. | 560 // Start with one account that is mapped. |
| 490 AccountMapping mapping = MakeAccountMapping("acc_id", | 561 AccountMapping mapping = MakeAccountMapping("acc_id", |
| 491 AccountMapping::MAPPED, | 562 AccountMapping::MAPPED, |
| 492 base::Time::Now(), | 563 base::Time::Now(), |
| 493 std::string()); | 564 std::string()); |
| 494 | 565 |
| 495 GCMAccountMapper::AccountMappings stored_mappings; | 566 GCMAccountMapper::AccountMappings stored_mappings; |
| 496 stored_mappings.push_back(mapping); | 567 stored_mappings.push_back(mapping); |
| 497 mapper()->Initialize(stored_mappings, kRegistrationId); | 568 mapper()->Initialize(stored_mappings); |
| 569 gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS); |
| 498 clock()->SetNow(base::Time::Now()); | 570 clock()->SetNow(base::Time::Now()); |
| 499 | 571 |
| 500 mapper()->SetAccountTokens(std::vector<GCMClient::AccountTokenInfo>()); | 572 mapper()->SetAccountTokens(std::vector<GCMClient::AccountTokenInfo>()); |
| 501 | 573 |
| 502 EXPECT_EQ(mapping.account_id, gcm_driver().last_account_mapping().account_id); | 574 EXPECT_EQ(mapping.account_id, gcm_driver().last_account_mapping().account_id); |
| 503 EXPECT_EQ(mapping.email, gcm_driver().last_account_mapping().email); | 575 EXPECT_EQ(mapping.email, gcm_driver().last_account_mapping().email); |
| 504 EXPECT_EQ(AccountMapping::REMOVING, | 576 EXPECT_EQ(AccountMapping::REMOVING, |
| 505 gcm_driver().last_account_mapping().status); | 577 gcm_driver().last_account_mapping().status); |
| 506 EXPECT_EQ(clock()->Now(), | 578 EXPECT_EQ(clock()->Now(), |
| 507 gcm_driver().last_account_mapping().status_change_timestamp); | 579 gcm_driver().last_account_mapping().status_change_timestamp); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 521 // account. This test goes until the message is queued by GCM. | 593 // account. This test goes until the message is queued by GCM. |
| 522 TEST_F(GCMAccountMapperTest, RemoveMappingMessageQueued) { | 594 TEST_F(GCMAccountMapperTest, RemoveMappingMessageQueued) { |
| 523 // Start with one account that is mapped. | 595 // Start with one account that is mapped. |
| 524 AccountMapping mapping = MakeAccountMapping("acc_id", | 596 AccountMapping mapping = MakeAccountMapping("acc_id", |
| 525 AccountMapping::MAPPED, | 597 AccountMapping::MAPPED, |
| 526 base::Time::Now(), | 598 base::Time::Now(), |
| 527 std::string()); | 599 std::string()); |
| 528 | 600 |
| 529 GCMAccountMapper::AccountMappings stored_mappings; | 601 GCMAccountMapper::AccountMappings stored_mappings; |
| 530 stored_mappings.push_back(mapping); | 602 stored_mappings.push_back(mapping); |
| 531 mapper()->Initialize(stored_mappings, kRegistrationId); | 603 mapper()->Initialize(stored_mappings); |
| 604 gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS); |
| 532 clock()->SetNow(base::Time::Now()); | 605 clock()->SetNow(base::Time::Now()); |
| 533 base::Time status_change_timestamp = clock()->Now(); | 606 base::Time status_change_timestamp = clock()->Now(); |
| 534 | 607 |
| 535 mapper()->SetAccountTokens(std::vector<GCMClient::AccountTokenInfo>()); | 608 mapper()->SetAccountTokens(std::vector<GCMClient::AccountTokenInfo>()); |
| 536 clock()->SetNow(base::Time::Now()); | 609 clock()->SetNow(base::Time::Now()); |
| 537 gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS); | 610 gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS); |
| 538 | 611 |
| 539 EXPECT_EQ(mapping.account_id, gcm_driver().last_account_mapping().account_id); | 612 EXPECT_EQ(mapping.account_id, gcm_driver().last_account_mapping().account_id); |
| 540 EXPECT_EQ(mapping.email, gcm_driver().last_account_mapping().email); | 613 EXPECT_EQ(mapping.email, gcm_driver().last_account_mapping().email); |
| 541 EXPECT_EQ(AccountMapping::REMOVING, | 614 EXPECT_EQ(AccountMapping::REMOVING, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 561 // account mapping being completely gone. | 634 // account mapping being completely gone. |
| 562 TEST_F(GCMAccountMapperTest, RemoveMappingMessageAcknowledged) { | 635 TEST_F(GCMAccountMapperTest, RemoveMappingMessageAcknowledged) { |
| 563 // Start with one account that is mapped. | 636 // Start with one account that is mapped. |
| 564 AccountMapping mapping = MakeAccountMapping("acc_id", | 637 AccountMapping mapping = MakeAccountMapping("acc_id", |
| 565 AccountMapping::MAPPED, | 638 AccountMapping::MAPPED, |
| 566 base::Time::Now(), | 639 base::Time::Now(), |
| 567 std::string()); | 640 std::string()); |
| 568 | 641 |
| 569 GCMAccountMapper::AccountMappings stored_mappings; | 642 GCMAccountMapper::AccountMappings stored_mappings; |
| 570 stored_mappings.push_back(mapping); | 643 stored_mappings.push_back(mapping); |
| 571 mapper()->Initialize(stored_mappings, kRegistrationId); | 644 mapper()->Initialize(stored_mappings); |
| 645 gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS); |
| 572 clock()->SetNow(base::Time::Now()); | 646 clock()->SetNow(base::Time::Now()); |
| 573 | 647 |
| 574 mapper()->SetAccountTokens(std::vector<GCMClient::AccountTokenInfo>()); | 648 mapper()->SetAccountTokens(std::vector<GCMClient::AccountTokenInfo>()); |
| 575 gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS); | 649 gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS); |
| 576 gcm_driver().AcknowledgeSend(gcm_driver().last_message_id()); | 650 gcm_driver().AcknowledgeSend(gcm_driver().last_message_id()); |
| 577 | 651 |
| 578 EXPECT_EQ(mapping.account_id, gcm_driver().last_removed_account_id()); | 652 EXPECT_EQ(mapping.account_id, gcm_driver().last_removed_account_id()); |
| 579 | 653 |
| 580 GCMAccountMapper::AccountMappings mappings = GetAccounts(); | 654 GCMAccountMapper::AccountMappings mappings = GetAccounts(); |
| 581 EXPECT_TRUE(mappings.empty()); | 655 EXPECT_TRUE(mappings.empty()); |
| 582 } | 656 } |
| 583 | 657 |
| 584 // Tests that account removing proceeds, when a removing message is acked after | 658 // Tests that account removing proceeds, when a removing message is acked after |
| 585 // Chrome was restarted. | 659 // Chrome was restarted. |
| 586 TEST_F(GCMAccountMapperTest, RemoveMappingMessageAckedAfterRestart) { | 660 TEST_F(GCMAccountMapperTest, RemoveMappingMessageAckedAfterRestart) { |
| 587 // Start with one account that is mapped. | 661 // Start with one account that is mapped. |
| 588 AccountMapping mapping = MakeAccountMapping("acc_id", | 662 AccountMapping mapping = MakeAccountMapping("acc_id", |
| 589 AccountMapping::REMOVING, | 663 AccountMapping::REMOVING, |
| 590 base::Time::Now(), | 664 base::Time::Now(), |
| 591 "remove_message_id"); | 665 "remove_message_id"); |
| 592 | 666 |
| 593 GCMAccountMapper::AccountMappings stored_mappings; | 667 GCMAccountMapper::AccountMappings stored_mappings; |
| 594 stored_mappings.push_back(mapping); | 668 stored_mappings.push_back(mapping); |
| 595 mapper()->Initialize(stored_mappings, kRegistrationId); | 669 mapper()->Initialize(stored_mappings); |
| 596 | 670 |
| 597 gcm_driver().AcknowledgeSend("remove_message_id"); | 671 gcm_driver().AcknowledgeSend("remove_message_id"); |
| 598 | 672 |
| 599 EXPECT_EQ(mapping.account_id, gcm_driver().last_removed_account_id()); | 673 EXPECT_EQ(mapping.account_id, gcm_driver().last_removed_account_id()); |
| 600 | 674 |
| 601 GCMAccountMapper::AccountMappings mappings = GetAccounts(); | 675 GCMAccountMapper::AccountMappings mappings = GetAccounts(); |
| 602 EXPECT_TRUE(mappings.empty()); | 676 EXPECT_TRUE(mappings.empty()); |
| 603 } | 677 } |
| 604 | 678 |
| 605 // Tests that account removing proceeds, when a removing message is acked after | 679 // Tests that account removing proceeds, when a removing message is acked after |
| 606 // Chrome was restarted. | 680 // Chrome was restarted. |
| 607 TEST_F(GCMAccountMapperTest, RemoveMappingMessageSendError) { | 681 TEST_F(GCMAccountMapperTest, RemoveMappingMessageSendError) { |
| 608 // Start with one account that is mapped. | 682 // Start with one account that is mapped. |
| 609 base::Time status_change_timestamp = base::Time::Now(); | 683 base::Time status_change_timestamp = base::Time::Now(); |
| 610 AccountMapping mapping = MakeAccountMapping("acc_id", | 684 AccountMapping mapping = MakeAccountMapping("acc_id", |
| 611 AccountMapping::REMOVING, | 685 AccountMapping::REMOVING, |
| 612 status_change_timestamp, | 686 status_change_timestamp, |
| 613 "remove_message_id"); | 687 "remove_message_id"); |
| 614 | 688 |
| 615 GCMAccountMapper::AccountMappings stored_mappings; | 689 GCMAccountMapper::AccountMappings stored_mappings; |
| 616 stored_mappings.push_back(mapping); | 690 stored_mappings.push_back(mapping); |
| 617 mapper()->Initialize(stored_mappings, kRegistrationId); | 691 mapper()->Initialize(stored_mappings); |
| 618 | 692 |
| 619 clock()->SetNow(base::Time::Now()); | 693 clock()->SetNow(base::Time::Now()); |
| 620 gcm_driver().MessageSendError("remove_message_id"); | 694 gcm_driver().MessageSendError("remove_message_id"); |
| 621 | 695 |
| 622 EXPECT_TRUE(gcm_driver().last_removed_account_id().empty()); | 696 EXPECT_TRUE(gcm_driver().last_removed_account_id().empty()); |
| 623 | 697 |
| 624 EXPECT_EQ(mapping.account_id, gcm_driver().last_account_mapping().account_id); | 698 EXPECT_EQ(mapping.account_id, gcm_driver().last_account_mapping().account_id); |
| 625 EXPECT_EQ(mapping.email, gcm_driver().last_account_mapping().email); | 699 EXPECT_EQ(mapping.email, gcm_driver().last_account_mapping().email); |
| 626 EXPECT_EQ(AccountMapping::REMOVING, | 700 EXPECT_EQ(AccountMapping::REMOVING, |
| 627 gcm_driver().last_account_mapping().status); | 701 gcm_driver().last_account_mapping().status); |
| 628 EXPECT_EQ(status_change_timestamp, | 702 EXPECT_EQ(status_change_timestamp, |
| 629 gcm_driver().last_account_mapping().status_change_timestamp); | 703 gcm_driver().last_account_mapping().status_change_timestamp); |
| 630 // Message is not persisted, until send is completed. | 704 // Message is not persisted, until send is completed. |
| 631 EXPECT_TRUE(gcm_driver().last_account_mapping().last_message_id.empty()); | 705 EXPECT_TRUE(gcm_driver().last_account_mapping().last_message_id.empty()); |
| 632 | 706 |
| 633 GCMAccountMapper::AccountMappings mappings = GetAccounts(); | 707 GCMAccountMapper::AccountMappings mappings = GetAccounts(); |
| 634 GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin(); | 708 GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin(); |
| 635 EXPECT_EQ(mapping.email, iter->email); | 709 EXPECT_EQ(mapping.email, iter->email); |
| 636 EXPECT_EQ(mapping.account_id, iter->account_id); | 710 EXPECT_EQ(mapping.account_id, iter->account_id); |
| 637 EXPECT_TRUE(iter->access_token.empty()); | 711 EXPECT_TRUE(iter->access_token.empty()); |
| 638 EXPECT_EQ(AccountMapping::REMOVING, iter->status); | 712 EXPECT_EQ(AccountMapping::REMOVING, iter->status); |
| 639 EXPECT_EQ(status_change_timestamp, iter->status_change_timestamp); | 713 EXPECT_EQ(status_change_timestamp, iter->status_change_timestamp); |
| 640 EXPECT_TRUE(iter->last_message_id.empty()); | 714 EXPECT_TRUE(iter->last_message_id.empty()); |
| 641 } | 715 } |
| 642 | 716 |
| 643 // Tests that, if a new token arrives when the adding message is in progress | 717 // Tests that, if a new token arrives when the adding message is in progress |
| 644 // no new message is sent and account mapper still waits for the first one to | 718 // no new message is sent and account mapper still waits for the first one to |
| 645 // complete. | 719 // complete. |
| 646 TEST_F(GCMAccountMapperTest, TokenIsRefreshedWhenAdding) { | 720 TEST_F(GCMAccountMapperTest, TokenIsRefreshedWhenAdding) { |
| 647 mapper()->Initialize(GCMAccountMapper::AccountMappings(), kRegistrationId); | 721 mapper()->Initialize(GCMAccountMapper::AccountMappings()); |
| 722 gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS); |
| 648 | 723 |
| 649 clock()->SetNow(base::Time::Now()); | 724 clock()->SetNow(base::Time::Now()); |
| 650 std::vector<GCMClient::AccountTokenInfo> account_tokens; | 725 std::vector<GCMClient::AccountTokenInfo> account_tokens; |
| 651 GCMClient::AccountTokenInfo account_token = MakeAccountTokenInfo("acc_id"); | 726 GCMClient::AccountTokenInfo account_token = MakeAccountTokenInfo("acc_id"); |
| 652 account_tokens.push_back(account_token); | 727 account_tokens.push_back(account_token); |
| 653 mapper()->SetAccountTokens(account_tokens); | 728 mapper()->SetAccountTokens(account_tokens); |
| 654 DCHECK_EQ(CustomFakeGCMDriver::SEND_STARTED, gcm_driver().last_action()); | 729 DCHECK_EQ(CustomFakeGCMDriver::SEND_STARTED, gcm_driver().last_action()); |
| 655 | 730 |
| 656 clock()->SetNow(base::Time::Now()); | 731 clock()->SetNow(base::Time::Now()); |
| 657 gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS); | 732 gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS); |
| 658 DCHECK_EQ(CustomFakeGCMDriver::SEND_FINISHED, gcm_driver().last_action()); | 733 DCHECK_EQ(CustomFakeGCMDriver::SEND_FINISHED, gcm_driver().last_action()); |
| 659 | 734 |
| 660 // Providing another token and clearing status. | 735 // Providing another token and clearing status. |
| 661 gcm_driver().Clear(); | 736 gcm_driver().Clear(); |
| 662 mapper()->SetAccountTokens(account_tokens); | 737 mapper()->SetAccountTokens(account_tokens); |
| 663 DCHECK_EQ(CustomFakeGCMDriver::NONE, gcm_driver().last_action()); | 738 DCHECK_EQ(CustomFakeGCMDriver::NONE, gcm_driver().last_action()); |
| 664 } | 739 } |
| 665 | 740 |
| 666 // Tests that, if a new token arrives when a removing message is in progress | 741 // Tests that, if a new token arrives when a removing message is in progress |
| 667 // a new adding message is sent and while account mapping status is changed to | 742 // a new adding message is sent and while account mapping status is changed to |
| 668 // mapped. If the original Removing message arrives it is discarded. | 743 // mapped. If the original Removing message arrives it is discarded. |
| 669 TEST_F(GCMAccountMapperTest, TokenIsRefreshedWhenRemoving) { | 744 TEST_F(GCMAccountMapperTest, TokenIsRefreshedWhenRemoving) { |
| 670 // Start with one account that is mapped. | 745 // Start with one account that is mapped. |
| 671 AccountMapping mapping = MakeAccountMapping( | 746 AccountMapping mapping = MakeAccountMapping( |
| 672 "acc_id", AccountMapping::MAPPED, base::Time::Now(), std::string()); | 747 "acc_id", AccountMapping::MAPPED, base::Time::Now(), std::string()); |
| 673 | 748 |
| 674 GCMAccountMapper::AccountMappings stored_mappings; | 749 GCMAccountMapper::AccountMappings stored_mappings; |
| 675 stored_mappings.push_back(mapping); | 750 stored_mappings.push_back(mapping); |
| 676 mapper()->Initialize(stored_mappings, kRegistrationId); | 751 mapper()->Initialize(stored_mappings); |
| 752 gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS); |
| 677 clock()->SetNow(base::Time::Now()); | 753 clock()->SetNow(base::Time::Now()); |
| 678 | 754 |
| 679 // Remove the token to trigger a remove message to be sent | 755 // Remove the token to trigger a remove message to be sent |
| 680 mapper()->SetAccountTokens(std::vector<GCMClient::AccountTokenInfo>()); | 756 mapper()->SetAccountTokens(std::vector<GCMClient::AccountTokenInfo>()); |
| 681 EXPECT_EQ(CustomFakeGCMDriver::SEND_STARTED, gcm_driver().last_action()); | 757 EXPECT_EQ(CustomFakeGCMDriver::SEND_STARTED, gcm_driver().last_action()); |
| 682 gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS); | 758 gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS); |
| 683 EXPECT_EQ(CustomFakeGCMDriver::SEND_FINISHED, gcm_driver().last_action()); | 759 EXPECT_EQ(CustomFakeGCMDriver::SEND_FINISHED, gcm_driver().last_action()); |
| 684 | 760 |
| 685 std::string remove_message_id = gcm_driver().last_message_id(); | 761 std::string remove_message_id = gcm_driver().last_message_id(); |
| 686 gcm_driver().Clear(); | 762 gcm_driver().Clear(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 clock()->SetNow(base::Time::Now()); | 795 clock()->SetNow(base::Time::Now()); |
| 720 base::Time half_hour_ago = clock()->Now() - base::TimeDelta::FromMinutes(30); | 796 base::Time half_hour_ago = clock()->Now() - base::TimeDelta::FromMinutes(30); |
| 721 GCMAccountMapper::AccountMappings stored_mappings; | 797 GCMAccountMapper::AccountMappings stored_mappings; |
| 722 stored_mappings.push_back(MakeAccountMapping( | 798 stored_mappings.push_back(MakeAccountMapping( |
| 723 "acc_id_0", AccountMapping::ADDING, half_hour_ago, "acc_id_0_msg")); | 799 "acc_id_0", AccountMapping::ADDING, half_hour_ago, "acc_id_0_msg")); |
| 724 stored_mappings.push_back(MakeAccountMapping( | 800 stored_mappings.push_back(MakeAccountMapping( |
| 725 "acc_id_1", AccountMapping::MAPPED, half_hour_ago, "acc_id_1_msg")); | 801 "acc_id_1", AccountMapping::MAPPED, half_hour_ago, "acc_id_1_msg")); |
| 726 stored_mappings.push_back(MakeAccountMapping( | 802 stored_mappings.push_back(MakeAccountMapping( |
| 727 "acc_id_2", AccountMapping::REMOVING, half_hour_ago, "acc_id_2_msg")); | 803 "acc_id_2", AccountMapping::REMOVING, half_hour_ago, "acc_id_2_msg")); |
| 728 | 804 |
| 729 mapper()->Initialize(stored_mappings, kRegistrationId); | 805 mapper()->Initialize(stored_mappings); |
| 806 gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS); |
| 730 | 807 |
| 731 GCMAccountMapper::AccountMappings expected_mappings(stored_mappings); | 808 GCMAccountMapper::AccountMappings expected_mappings(stored_mappings); |
| 732 | 809 |
| 733 // Finish messages after a restart. | 810 // Finish messages after a restart. |
| 734 clock()->SetNow(base::Time::Now()); | 811 clock()->SetNow(base::Time::Now()); |
| 735 gcm_driver().AcknowledgeSend(expected_mappings[0].last_message_id); | 812 gcm_driver().AcknowledgeSend(expected_mappings[0].last_message_id); |
| 736 expected_mappings[0].status_change_timestamp = clock()->Now(); | 813 expected_mappings[0].status_change_timestamp = clock()->Now(); |
| 737 expected_mappings[0].status = AccountMapping::MAPPED; | 814 expected_mappings[0].status = AccountMapping::MAPPED; |
| 738 expected_mappings[0].last_message_id.clear(); | 815 expected_mappings[0].last_message_id.clear(); |
| 739 | 816 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 expected_mappings[1].status_change_timestamp = clock()->Now(); | 888 expected_mappings[1].status_change_timestamp = clock()->Now(); |
| 812 expected_mappings[1].status = AccountMapping::MAPPED; | 889 expected_mappings[1].status = AccountMapping::MAPPED; |
| 813 expected_mappings[2].status_change_timestamp = clock()->Now(); | 890 expected_mappings[2].status_change_timestamp = clock()->Now(); |
| 814 expected_mappings[2].status = AccountMapping::MAPPED; | 891 expected_mappings[2].status = AccountMapping::MAPPED; |
| 815 | 892 |
| 816 VerifyMappings( | 893 VerifyMappings( |
| 817 expected_mappings, GetAccounts(), "Step 6, Three mapped accounts"); | 894 expected_mappings, GetAccounts(), "Step 6, Three mapped accounts"); |
| 818 } | 895 } |
| 819 | 896 |
| 820 } // namespace gcm | 897 } // namespace gcm |
| OLD | NEW |