Commit 18545630 authored by noel's avatar noel Committed by Commit bot

Revert of [GCM] Adding GCMAccountMapper tests (patchset #2 id:20001 of...

Revert of [GCM] Adding GCMAccountMapper tests (patchset #2 id:20001 of https://codereview.chromium.org/544363002/)

Reason for revert:
GCMAccountMapperTest.MultipleAccountMappings is failing on Win7 Debug.

http://build.chromium.org/p/chromium.win/builders/Win7%20Tests%20%28dbg%29%281%29/builds/30987

Original issue's description:
> [GCM] Adding GCMAccountMapper tests
>
> 1) When the status is ADDING (adding message is sent), the token is refreshed.
> 2) When the status is REMOVING (removing message is sent), the token is added
> again.
> 3) updating multiple account mappings
>
> BUG=374969
> R=jianli@chromium.org
>
> Committed: https://chromium.googlesource.com/chromium/src/+/a15249de25304c0d2173029bc22b2f136adac537

TBR=jianli@chromium.org,fgorski@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=374969

Review URL: https://codereview.chromium.org/554153003

Cr-Commit-Position: refs/heads/master@{#293825}
parent 40dbafab
...@@ -44,13 +44,6 @@ GCMClient::AccountTokenInfo MakeAccountTokenInfo( ...@@ -44,13 +44,6 @@ GCMClient::AccountTokenInfo MakeAccountTokenInfo(
class CustomFakeGCMDriver : public FakeGCMDriver { class CustomFakeGCMDriver : public FakeGCMDriver {
public: public:
enum LastMessageAction {
NONE,
SEND_STARTED,
SEND_FINISHED,
SEND_ACKNOWLEDGED
};
CustomFakeGCMDriver(); CustomFakeGCMDriver();
virtual ~CustomFakeGCMDriver(); virtual ~CustomFakeGCMDriver();
...@@ -62,16 +55,9 @@ class CustomFakeGCMDriver : public FakeGCMDriver { ...@@ -62,16 +55,9 @@ class CustomFakeGCMDriver : public FakeGCMDriver {
virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE; virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE;
void CompleteSend(const std::string& message_id, GCMClient::Result result); void CompleteSend(const std::string& message_id, GCMClient::Result result);
void AcknowledgeSend(const std::string& message_id); void SendAcknowledged(const std::string& message_id);
void MessageSendError(const std::string& message_id); void MessageSendError(const std::string& message_id);
void CompleteSendAllMessages();
void AcknowledgeSendAllMessages();
void SetLastMessageAction(const std::string& message_id,
LastMessageAction action);
void Clear();
const AccountMapping& last_account_mapping() const { const AccountMapping& last_account_mapping() const {
return account_mapping_; return account_mapping_;
} }
...@@ -79,7 +65,6 @@ class CustomFakeGCMDriver : public FakeGCMDriver { ...@@ -79,7 +65,6 @@ class CustomFakeGCMDriver : public FakeGCMDriver {
const std::string& last_removed_account_id() const { const std::string& last_removed_account_id() const {
return last_removed_account_id_; return last_removed_account_id_;
} }
LastMessageAction last_action() const { return last_action_; }
protected: protected:
virtual void SendImpl(const std::string& app_id, virtual void SendImpl(const std::string& app_id,
...@@ -90,11 +75,9 @@ class CustomFakeGCMDriver : public FakeGCMDriver { ...@@ -90,11 +75,9 @@ class CustomFakeGCMDriver : public FakeGCMDriver {
AccountMapping account_mapping_; AccountMapping account_mapping_;
std::string last_message_id_; std::string last_message_id_;
std::string last_removed_account_id_; std::string last_removed_account_id_;
LastMessageAction last_action_;
std::map<std::string, LastMessageAction> all_messages_;
}; };
CustomFakeGCMDriver::CustomFakeGCMDriver() : last_action_(NONE) { CustomFakeGCMDriver::CustomFakeGCMDriver() {
} }
CustomFakeGCMDriver::~CustomFakeGCMDriver() { CustomFakeGCMDriver::~CustomFakeGCMDriver() {
...@@ -127,13 +110,11 @@ void CustomFakeGCMDriver::RemoveAppHandler(const std::string& app_id) { ...@@ -127,13 +110,11 @@ void CustomFakeGCMDriver::RemoveAppHandler(const std::string& app_id) {
void CustomFakeGCMDriver::CompleteSend(const std::string& message_id, void CustomFakeGCMDriver::CompleteSend(const std::string& message_id,
GCMClient::Result result) { GCMClient::Result result) {
SendFinished(kGCMAccountMapperAppId, message_id, result); SendFinished(kGCMAccountMapperAppId, message_id, result);
SetLastMessageAction(message_id, SEND_FINISHED);
} }
void CustomFakeGCMDriver::AcknowledgeSend(const std::string& message_id) { void CustomFakeGCMDriver::SendAcknowledged(const std::string& message_id) {
GetAppHandler(kGCMAccountMapperAppId) GetAppHandler(kGCMAccountMapperAppId)
->OnSendAcknowledged(kGCMAccountMapperAppId, message_id); ->OnSendAcknowledged(kGCMAccountMapperAppId, message_id);
SetLastMessageAction(message_id, SEND_ACKNOWLEDGED);
} }
void CustomFakeGCMDriver::MessageSendError(const std::string& message_id) { void CustomFakeGCMDriver::MessageSendError(const std::string& message_id) {
...@@ -150,41 +131,7 @@ void CustomFakeGCMDriver::SendImpl(const std::string& app_id, ...@@ -150,41 +131,7 @@ void CustomFakeGCMDriver::SendImpl(const std::string& app_id,
DCHECK_EQ(kGCMAccountMapperAppId, app_id); DCHECK_EQ(kGCMAccountMapperAppId, app_id);
DCHECK_EQ(kGCMAccountMapperSenderId, receiver_id); DCHECK_EQ(kGCMAccountMapperSenderId, receiver_id);
SetLastMessageAction(message.id, SEND_STARTED); last_message_id_ = message.id;
}
void CustomFakeGCMDriver::CompleteSendAllMessages() {
for (std::map<std::string, LastMessageAction>::const_iterator iter =
all_messages_.begin();
iter != all_messages_.end();
++iter) {
if (iter->second == SEND_STARTED)
CompleteSend(iter->first, GCMClient::SUCCESS);
}
}
void CustomFakeGCMDriver::AcknowledgeSendAllMessages() {
for (std::map<std::string, LastMessageAction>::const_iterator iter =
all_messages_.begin();
iter != all_messages_.end();
++iter) {
if (iter->second == SEND_FINISHED)
AcknowledgeSend(iter->first);
}
}
void CustomFakeGCMDriver::Clear() {
account_mapping_ = AccountMapping();
last_message_id_.clear();
last_removed_account_id_.clear();
last_action_ = NONE;
}
void CustomFakeGCMDriver::SetLastMessageAction(const std::string& message_id,
LastMessageAction action) {
last_action_ = action;
last_message_id_ = message_id;
all_messages_[message_id] = action;
} }
} // namespace } // namespace
...@@ -196,7 +143,7 @@ class GCMAccountMapperTest : public testing::Test { ...@@ -196,7 +143,7 @@ class GCMAccountMapperTest : public testing::Test {
void Restart(); void Restart();
const GCMAccountMapper::AccountMappings& GetAccounts() const { const std::vector<AccountMapping>& GetAccounts() const {
return account_mapper_->accounts_; return account_mapper_->accounts_;
} }
...@@ -230,14 +177,14 @@ void GCMAccountMapperTest::Restart() { ...@@ -230,14 +177,14 @@ void GCMAccountMapperTest::Restart() {
// Tests the initialization of account mappings (from the store) when empty. // Tests the initialization of account mappings (from the store) when empty.
TEST_F(GCMAccountMapperTest, InitializeAccountMappingsEmpty) { TEST_F(GCMAccountMapperTest, InitializeAccountMappingsEmpty) {
GCMAccountMapper::AccountMappings account_mappings; std::vector<AccountMapping> account_mappings;
mapper()->Initialize(account_mappings, ""); mapper()->Initialize(account_mappings, "");
EXPECT_TRUE(GetAccounts().empty()); EXPECT_TRUE(GetAccounts().empty());
} }
// Tests the initialization of account mappings (from the store). // Tests the initialization of account mappings (from the store).
TEST_F(GCMAccountMapperTest, InitializeAccountMappings) { TEST_F(GCMAccountMapperTest, InitializeAccountMappings) {
GCMAccountMapper::AccountMappings account_mappings; std::vector<AccountMapping> account_mappings;
AccountMapping account_mapping1 = MakeAccountMapping("acc_id1", AccountMapping account_mapping1 = MakeAccountMapping("acc_id1",
AccountMapping::MAPPED, AccountMapping::MAPPED,
base::Time::Now(), base::Time::Now(),
...@@ -251,9 +198,9 @@ TEST_F(GCMAccountMapperTest, InitializeAccountMappings) { ...@@ -251,9 +198,9 @@ TEST_F(GCMAccountMapperTest, InitializeAccountMappings) {
mapper()->Initialize(account_mappings, ""); mapper()->Initialize(account_mappings, "");
GCMAccountMapper::AccountMappings mappings = GetAccounts(); std::vector<AccountMapping> mappings = GetAccounts();
EXPECT_EQ(2UL, mappings.size()); EXPECT_EQ(2UL, mappings.size());
GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin(); std::vector<AccountMapping>::const_iterator iter = mappings.begin();
EXPECT_EQ(account_mapping1.account_id, iter->account_id); EXPECT_EQ(account_mapping1.account_id, iter->account_id);
EXPECT_EQ(account_mapping1.email, iter->email); EXPECT_EQ(account_mapping1.email, iter->email);
...@@ -283,9 +230,9 @@ TEST_F(GCMAccountMapperTest, AddMappingToMessageSent) { ...@@ -283,9 +230,9 @@ TEST_F(GCMAccountMapperTest, AddMappingToMessageSent) {
account_tokens.push_back(account_token); account_tokens.push_back(account_token);
mapper()->SetAccountTokens(account_tokens); mapper()->SetAccountTokens(account_tokens);
GCMAccountMapper::AccountMappings mappings = GetAccounts(); std::vector<AccountMapping> mappings = GetAccounts();
EXPECT_EQ(1UL, mappings.size()); EXPECT_EQ(1UL, mappings.size());
GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin(); std::vector<AccountMapping>::const_iterator iter = mappings.begin();
EXPECT_EQ("acc_id", iter->account_id); EXPECT_EQ("acc_id", iter->account_id);
EXPECT_EQ("acc_id@gmail.com", iter->email); EXPECT_EQ("acc_id@gmail.com", iter->email);
EXPECT_EQ("acc_id_token", iter->access_token); EXPECT_EQ("acc_id_token", iter->access_token);
...@@ -318,8 +265,8 @@ TEST_F(GCMAccountMapperTest, AddMappingMessageQueued) { ...@@ -318,8 +265,8 @@ TEST_F(GCMAccountMapperTest, AddMappingMessageQueued) {
EXPECT_EQ(gcm_driver().last_message_id(), EXPECT_EQ(gcm_driver().last_message_id(),
gcm_driver().last_account_mapping().last_message_id); gcm_driver().last_account_mapping().last_message_id);
GCMAccountMapper::AccountMappings mappings = GetAccounts(); std::vector<AccountMapping> mappings = GetAccounts();
GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin(); std::vector<AccountMapping>::const_iterator iter = mappings.begin();
EXPECT_EQ(account_token.email, iter->email); EXPECT_EQ(account_token.email, iter->email);
EXPECT_EQ(account_token.account_id, iter->account_id); EXPECT_EQ(account_token.account_id, iter->account_id);
EXPECT_EQ(account_token.access_token, iter->access_token); EXPECT_EQ(account_token.access_token, iter->access_token);
...@@ -340,7 +287,7 @@ TEST_F(GCMAccountMapperTest, AddMappingMessageAcknowledged) { ...@@ -340,7 +287,7 @@ TEST_F(GCMAccountMapperTest, AddMappingMessageAcknowledged) {
clock()->SetNow(base::Time::Now()); clock()->SetNow(base::Time::Now());
gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS); gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS);
clock()->SetNow(base::Time::Now()); clock()->SetNow(base::Time::Now());
gcm_driver().AcknowledgeSend(gcm_driver().last_message_id()); gcm_driver().SendAcknowledged(gcm_driver().last_message_id());
EXPECT_EQ(account_token.email, gcm_driver().last_account_mapping().email); EXPECT_EQ(account_token.email, gcm_driver().last_account_mapping().email);
EXPECT_EQ(account_token.account_id, EXPECT_EQ(account_token.account_id,
...@@ -352,8 +299,8 @@ TEST_F(GCMAccountMapperTest, AddMappingMessageAcknowledged) { ...@@ -352,8 +299,8 @@ TEST_F(GCMAccountMapperTest, AddMappingMessageAcknowledged) {
gcm_driver().last_account_mapping().status_change_timestamp); gcm_driver().last_account_mapping().status_change_timestamp);
EXPECT_TRUE(gcm_driver().last_account_mapping().last_message_id.empty()); EXPECT_TRUE(gcm_driver().last_account_mapping().last_message_id.empty());
GCMAccountMapper::AccountMappings mappings = GetAccounts(); std::vector<AccountMapping> mappings = GetAccounts();
GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin(); std::vector<AccountMapping>::const_iterator iter = mappings.begin();
EXPECT_EQ(account_token.email, iter->email); EXPECT_EQ(account_token.email, iter->email);
EXPECT_EQ(account_token.account_id, iter->account_id); EXPECT_EQ(account_token.account_id, iter->account_id);
EXPECT_EQ(account_token.access_token, iter->access_token); EXPECT_EQ(account_token.access_token, iter->access_token);
...@@ -376,12 +323,12 @@ TEST_F(GCMAccountMapperTest, AddMappingMessageAckedAfterRestart) { ...@@ -376,12 +323,12 @@ TEST_F(GCMAccountMapperTest, AddMappingMessageAckedAfterRestart) {
gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS); gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS);
Restart(); Restart();
GCMAccountMapper::AccountMappings stored_mappings; std::vector<AccountMapping> stored_mappings;
stored_mappings.push_back(gcm_driver().last_account_mapping()); stored_mappings.push_back(gcm_driver().last_account_mapping());
mapper()->Initialize(stored_mappings, kRegistrationId); mapper()->Initialize(stored_mappings, kRegistrationId);
clock()->SetNow(base::Time::Now()); clock()->SetNow(base::Time::Now());
gcm_driver().AcknowledgeSend(gcm_driver().last_message_id()); gcm_driver().SendAcknowledged(gcm_driver().last_message_id());
EXPECT_EQ(account_token.email, gcm_driver().last_account_mapping().email); EXPECT_EQ(account_token.email, gcm_driver().last_account_mapping().email);
EXPECT_EQ(account_token.account_id, EXPECT_EQ(account_token.account_id,
...@@ -393,8 +340,8 @@ TEST_F(GCMAccountMapperTest, AddMappingMessageAckedAfterRestart) { ...@@ -393,8 +340,8 @@ TEST_F(GCMAccountMapperTest, AddMappingMessageAckedAfterRestart) {
gcm_driver().last_account_mapping().status_change_timestamp); gcm_driver().last_account_mapping().status_change_timestamp);
EXPECT_TRUE(gcm_driver().last_account_mapping().last_message_id.empty()); EXPECT_TRUE(gcm_driver().last_account_mapping().last_message_id.empty());
GCMAccountMapper::AccountMappings mappings = GetAccounts(); std::vector<AccountMapping> mappings = GetAccounts();
GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin(); std::vector<AccountMapping>::const_iterator iter = mappings.begin();
EXPECT_EQ(account_token.email, iter->email); EXPECT_EQ(account_token.email, iter->email);
EXPECT_EQ(account_token.account_id, iter->account_id); EXPECT_EQ(account_token.account_id, iter->account_id);
EXPECT_EQ(account_token.access_token, iter->access_token); EXPECT_EQ(account_token.access_token, iter->access_token);
...@@ -446,8 +393,8 @@ TEST_F(GCMAccountMapperTest, AddMappingMessageSendErrorForMappedAccount) { ...@@ -446,8 +393,8 @@ TEST_F(GCMAccountMapperTest, AddMappingMessageSendErrorForMappedAccount) {
// Because the account was new, the entry should be deleted. // Because the account was new, the entry should be deleted.
EXPECT_TRUE(gcm_driver().last_message_id().empty()); EXPECT_TRUE(gcm_driver().last_message_id().empty());
GCMAccountMapper::AccountMappings mappings = GetAccounts(); std::vector<AccountMapping> mappings = GetAccounts();
GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin(); std::vector<AccountMapping>::const_iterator iter = mappings.begin();
EXPECT_EQ(mapping.email, iter->email); EXPECT_EQ(mapping.email, iter->email);
EXPECT_EQ(mapping.account_id, iter->account_id); EXPECT_EQ(mapping.account_id, iter->account_id);
EXPECT_EQ(mapping.access_token, iter->access_token); EXPECT_EQ(mapping.access_token, iter->access_token);
...@@ -480,8 +427,8 @@ TEST_F(GCMAccountMapperTest, RemoveMappingToMessageSent) { ...@@ -480,8 +427,8 @@ TEST_F(GCMAccountMapperTest, RemoveMappingToMessageSent) {
gcm_driver().last_account_mapping().status_change_timestamp); gcm_driver().last_account_mapping().status_change_timestamp);
EXPECT_TRUE(gcm_driver().last_account_mapping().last_message_id.empty()); EXPECT_TRUE(gcm_driver().last_account_mapping().last_message_id.empty());
GCMAccountMapper::AccountMappings mappings = GetAccounts(); std::vector<AccountMapping> mappings = GetAccounts();
GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin(); std::vector<AccountMapping>::const_iterator iter = mappings.begin();
EXPECT_EQ(mapping.email, iter->email); EXPECT_EQ(mapping.email, iter->email);
EXPECT_EQ(mapping.account_id, iter->account_id); EXPECT_EQ(mapping.account_id, iter->account_id);
EXPECT_EQ(mapping.access_token, iter->access_token); EXPECT_EQ(mapping.access_token, iter->access_token);
...@@ -517,8 +464,8 @@ TEST_F(GCMAccountMapperTest, RemoveMappingMessageQueued) { ...@@ -517,8 +464,8 @@ TEST_F(GCMAccountMapperTest, RemoveMappingMessageQueued) {
gcm_driver().last_account_mapping().status_change_timestamp); gcm_driver().last_account_mapping().status_change_timestamp);
EXPECT_TRUE(!gcm_driver().last_account_mapping().last_message_id.empty()); EXPECT_TRUE(!gcm_driver().last_account_mapping().last_message_id.empty());
GCMAccountMapper::AccountMappings mappings = GetAccounts(); std::vector<AccountMapping> mappings = GetAccounts();
GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin(); std::vector<AccountMapping>::const_iterator iter = mappings.begin();
EXPECT_EQ(mapping.email, iter->email); EXPECT_EQ(mapping.email, iter->email);
EXPECT_EQ(mapping.account_id, iter->account_id); EXPECT_EQ(mapping.account_id, iter->account_id);
EXPECT_EQ(mapping.access_token, iter->access_token); EXPECT_EQ(mapping.access_token, iter->access_token);
...@@ -546,11 +493,11 @@ TEST_F(GCMAccountMapperTest, RemoveMappingMessageAcknowledged) { ...@@ -546,11 +493,11 @@ TEST_F(GCMAccountMapperTest, RemoveMappingMessageAcknowledged) {
mapper()->SetAccountTokens(std::vector<GCMClient::AccountTokenInfo>()); mapper()->SetAccountTokens(std::vector<GCMClient::AccountTokenInfo>());
gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS); gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS);
gcm_driver().AcknowledgeSend(gcm_driver().last_message_id()); gcm_driver().SendAcknowledged(gcm_driver().last_message_id());
EXPECT_EQ(mapping.account_id, gcm_driver().last_removed_account_id()); EXPECT_EQ(mapping.account_id, gcm_driver().last_removed_account_id());
GCMAccountMapper::AccountMappings mappings = GetAccounts(); std::vector<AccountMapping> mappings = GetAccounts();
EXPECT_TRUE(mappings.empty()); EXPECT_TRUE(mappings.empty());
} }
...@@ -567,11 +514,11 @@ TEST_F(GCMAccountMapperTest, RemoveMappingMessageAckedAfterRestart) { ...@@ -567,11 +514,11 @@ TEST_F(GCMAccountMapperTest, RemoveMappingMessageAckedAfterRestart) {
stored_mappings.push_back(mapping); stored_mappings.push_back(mapping);
mapper()->Initialize(stored_mappings, kRegistrationId); mapper()->Initialize(stored_mappings, kRegistrationId);
gcm_driver().AcknowledgeSend("remove_message_id"); gcm_driver().SendAcknowledged("remove_message_id");
EXPECT_EQ(mapping.account_id, gcm_driver().last_removed_account_id()); EXPECT_EQ(mapping.account_id, gcm_driver().last_removed_account_id());
GCMAccountMapper::AccountMappings mappings = GetAccounts(); std::vector<AccountMapping> mappings = GetAccounts();
EXPECT_TRUE(mappings.empty()); EXPECT_TRUE(mappings.empty());
} }
...@@ -603,8 +550,8 @@ TEST_F(GCMAccountMapperTest, RemoveMappingMessageSendError) { ...@@ -603,8 +550,8 @@ TEST_F(GCMAccountMapperTest, RemoveMappingMessageSendError) {
// Message is not persisted, until send is completed. // Message is not persisted, until send is completed.
EXPECT_TRUE(gcm_driver().last_account_mapping().last_message_id.empty()); EXPECT_TRUE(gcm_driver().last_account_mapping().last_message_id.empty());
GCMAccountMapper::AccountMappings mappings = GetAccounts(); std::vector<AccountMapping> mappings = GetAccounts();
GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin(); std::vector<AccountMapping>::const_iterator iter = mappings.begin();
EXPECT_EQ(mapping.email, iter->email); EXPECT_EQ(mapping.email, iter->email);
EXPECT_EQ(mapping.account_id, iter->account_id); EXPECT_EQ(mapping.account_id, iter->account_id);
EXPECT_TRUE(iter->access_token.empty()); EXPECT_TRUE(iter->access_token.empty());
...@@ -613,231 +560,4 @@ TEST_F(GCMAccountMapperTest, RemoveMappingMessageSendError) { ...@@ -613,231 +560,4 @@ TEST_F(GCMAccountMapperTest, RemoveMappingMessageSendError) {
EXPECT_TRUE(iter->last_message_id.empty()); EXPECT_TRUE(iter->last_message_id.empty());
} }
// Tests that, if a new token arrives when the adding message is in progress
// no new message is sent and account mapper still waits for the first one to
// complete.
TEST_F(GCMAccountMapperTest, TokenIsRefreshedWhenAdding) {
mapper()->Initialize(GCMAccountMapper::AccountMappings(), kRegistrationId);
clock()->SetNow(base::Time::Now());
std::vector<GCMClient::AccountTokenInfo> account_tokens;
GCMClient::AccountTokenInfo account_token = MakeAccountTokenInfo("acc_id");
account_tokens.push_back(account_token);
mapper()->SetAccountTokens(account_tokens);
DCHECK_EQ(CustomFakeGCMDriver::SEND_STARTED, gcm_driver().last_action());
clock()->SetNow(base::Time::Now());
gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS);
DCHECK_EQ(CustomFakeGCMDriver::SEND_FINISHED, gcm_driver().last_action());
// Providing another token and clearing status.
gcm_driver().Clear();
mapper()->SetAccountTokens(account_tokens);
DCHECK_EQ(CustomFakeGCMDriver::NONE, gcm_driver().last_action());
}
// Tests that, if a new token arrives when a removing message is in progress
// a new adding message is sent and while account mapping status is changed to
// mapped. If the original Removing message arrives it is discarded.
TEST_F(GCMAccountMapperTest, TokenIsRefreshedWhenRemoving) {
// Start with one account that is mapped.
AccountMapping mapping = MakeAccountMapping(
"acc_id", AccountMapping::MAPPED, base::Time::Now(), std::string());
GCMAccountMapper::AccountMappings stored_mappings;
stored_mappings.push_back(mapping);
mapper()->Initialize(stored_mappings, kRegistrationId);
clock()->SetNow(base::Time::Now());
// Remove the token to trigger a remove message to be sent
mapper()->SetAccountTokens(std::vector<GCMClient::AccountTokenInfo>());
EXPECT_EQ(CustomFakeGCMDriver::SEND_STARTED, gcm_driver().last_action());
gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS);
EXPECT_EQ(CustomFakeGCMDriver::SEND_FINISHED, gcm_driver().last_action());
std::string remove_message_id = gcm_driver().last_message_id();
gcm_driver().Clear();
// The account mapping for acc_id is now in status REMOVING.
// Adding the token for that account.
clock()->SetNow(base::Time::Now());
std::vector<GCMClient::AccountTokenInfo> account_tokens;
GCMClient::AccountTokenInfo account_token = MakeAccountTokenInfo("acc_id");
account_tokens.push_back(account_token);
mapper()->SetAccountTokens(account_tokens);
DCHECK_EQ(CustomFakeGCMDriver::SEND_STARTED, gcm_driver().last_action());
gcm_driver().CompleteSend(gcm_driver().last_message_id(), GCMClient::SUCCESS);
EXPECT_EQ(CustomFakeGCMDriver::SEND_FINISHED, gcm_driver().last_action());
std::string add_message_id = gcm_driver().last_message_id();
// A remove message confirmation arrives now, but should be ignored.
gcm_driver().AcknowledgeSend(remove_message_id);
GCMAccountMapper::AccountMappings mappings = GetAccounts();
GCMAccountMapper::AccountMappings::const_iterator iter = mappings.begin();
EXPECT_EQ(mapping.email, iter->email);
EXPECT_EQ(mapping.account_id, iter->account_id);
EXPECT_FALSE(iter->access_token.empty());
EXPECT_EQ(AccountMapping::MAPPED, iter->status);
// Status change timestamp is set to very long time ago, to make sure the next
// round of mapping picks it up.
EXPECT_EQ(base::Time(), iter->status_change_timestamp);
EXPECT_EQ(add_message_id, iter->last_message_id);
}
// Tests adding/removing works for multiple accounts, after a restart and when
// tokens are periodically delierverd.
TEST_F(GCMAccountMapperTest, MultipleAccountMappings) {
clock()->SetNow(base::Time::Now());
base::Time half_hour_ago = clock()->Now() - base::TimeDelta::FromMinutes(30);
GCMAccountMapper::AccountMappings stored_mappings;
stored_mappings.push_back(MakeAccountMapping(
"acc_id_0", AccountMapping::ADDING, half_hour_ago, "acc_id_0_msg"));
stored_mappings.push_back(MakeAccountMapping(
"acc_id_1", AccountMapping::MAPPED, half_hour_ago, "acc_id_1_msg"));
stored_mappings.push_back(MakeAccountMapping(
"acc_id_2", AccountMapping::REMOVING, half_hour_ago, "acc_id_2_msg"));
mapper()->Initialize(stored_mappings, kRegistrationId);
GCMAccountMapper::AccountMappings expected_mappings(stored_mappings);
// Finish messages after a restart.
clock()->SetNow(base::Time::Now());
gcm_driver().AcknowledgeSend(expected_mappings[0].last_message_id);
expected_mappings[0].status_change_timestamp = clock()->Now();
expected_mappings[0].status = AccountMapping::MAPPED;
expected_mappings[0].last_message_id.clear();
clock()->SetNow(base::Time::Now());
gcm_driver().AcknowledgeSend(expected_mappings[1].last_message_id);
expected_mappings[1].status_change_timestamp = clock()->Now();
expected_mappings[1].status = AccountMapping::MAPPED;
expected_mappings[1].last_message_id.clear();
// Upon success last element is removed.
clock()->SetNow(base::Time::Now());
gcm_driver().AcknowledgeSend(expected_mappings[2].last_message_id);
expected_mappings.pop_back();
GCMAccountMapper::AccountMappings mappings = GetAccounts();
EXPECT_EQ(expected_mappings.size(), mappings.size());
GCMAccountMapper::AccountMappings::const_iterator expected_iter =
expected_mappings.begin();
GCMAccountMapper::AccountMappings::const_iterator actual_iter =
mappings.begin();
for (; expected_iter != expected_mappings.end() &&
actual_iter != mappings.end();
++expected_iter, ++actual_iter) {
EXPECT_EQ(expected_iter->email, actual_iter->email);
EXPECT_EQ(expected_iter->account_id, actual_iter->account_id);
EXPECT_EQ(expected_iter->status, actual_iter->status);
EXPECT_EQ(expected_iter->status_change_timestamp,
actual_iter->status_change_timestamp);
}
// One of accounts gets removed.
std::vector<GCMClient::AccountTokenInfo> account_tokens;
account_tokens.push_back(MakeAccountTokenInfo("acc_id_0"));
// Advance a day to make sure existing mappings will be reported.
clock()->SetNow(clock()->Now() + base::TimeDelta::FromDays(1));
mapper()->SetAccountTokens(account_tokens);
expected_mappings[0].status = AccountMapping::MAPPED;
expected_mappings[1].status = AccountMapping::REMOVING;
expected_mappings[1].status_change_timestamp = clock()->Now();
gcm_driver().CompleteSendAllMessages();
for (; expected_iter != expected_mappings.end() &&
actual_iter != mappings.end();
++expected_iter, ++actual_iter) {
EXPECT_EQ(expected_iter->email, actual_iter->email);
EXPECT_EQ(expected_iter->account_id, actual_iter->account_id);
EXPECT_EQ(expected_iter->status, actual_iter->status);
EXPECT_EQ(expected_iter->status_change_timestamp,
actual_iter->status_change_timestamp);
}
clock()->SetNow(clock()->Now() + base::TimeDelta::FromSeconds(5));
gcm_driver().AcknowledgeSendAllMessages();
expected_mappings[0].status_change_timestamp = clock()->Now();
expected_mappings.pop_back();
for (; expected_iter != expected_mappings.end() &&
actual_iter != mappings.end();
++expected_iter, ++actual_iter) {
EXPECT_EQ(expected_iter->email, actual_iter->email);
EXPECT_EQ(expected_iter->account_id, actual_iter->account_id);
EXPECT_EQ(expected_iter->status, actual_iter->status);
EXPECT_EQ(expected_iter->status_change_timestamp,
actual_iter->status_change_timestamp);
}
account_tokens.clear();
account_tokens.push_back(MakeAccountTokenInfo("acc_id_0"));
account_tokens.push_back(MakeAccountTokenInfo("acc_id_3"));
account_tokens.push_back(MakeAccountTokenInfo("acc_id_4"));
// Advance a day to make sure existing mappings will be reported.
clock()->SetNow(clock()->Now() + base::TimeDelta::FromDays(1));
mapper()->SetAccountTokens(account_tokens);
// Mapping from acc_id_0 still in position 0
expected_mappings.push_back(MakeAccountMapping(
"acc_id_3", AccountMapping::ADDING, base::Time(), std::string()));
expected_mappings.push_back(MakeAccountMapping(
"acc_id_4", AccountMapping::ADDING, base::Time(), std::string()));
for (; expected_iter != expected_mappings.end() &&
actual_iter != mappings.end();
++expected_iter, ++actual_iter) {
EXPECT_EQ(expected_iter->email, actual_iter->email);
EXPECT_EQ(expected_iter->account_id, actual_iter->account_id);
EXPECT_EQ(expected_iter->status, actual_iter->status);
EXPECT_EQ(expected_iter->status_change_timestamp,
actual_iter->status_change_timestamp);
}
clock()->SetNow(clock()->Now() + base::TimeDelta::FromSeconds(1));
gcm_driver().CompleteSendAllMessages();
expected_mappings[1].status_change_timestamp = clock()->Now();
expected_mappings[2].status_change_timestamp = clock()->Now();
for (; expected_iter != expected_mappings.end() &&
actual_iter != mappings.end();
++expected_iter, ++actual_iter) {
EXPECT_EQ(expected_iter->email, actual_iter->email);
EXPECT_EQ(expected_iter->account_id, actual_iter->account_id);
EXPECT_EQ(expected_iter->status, actual_iter->status);
EXPECT_EQ(expected_iter->status_change_timestamp,
actual_iter->status_change_timestamp);
}
clock()->SetNow(clock()->Now() + base::TimeDelta::FromSeconds(5));
gcm_driver().AcknowledgeSendAllMessages();
expected_mappings[0].status_change_timestamp = clock()->Now();
expected_mappings[1].status_change_timestamp = clock()->Now();
expected_mappings[1].status = AccountMapping::MAPPED;
expected_mappings[2].status_change_timestamp = clock()->Now();
expected_mappings[2].status = AccountMapping::MAPPED;
for (; expected_iter != expected_mappings.end() &&
actual_iter != mappings.end();
++expected_iter, ++actual_iter) {
EXPECT_EQ(expected_iter->email, actual_iter->email);
EXPECT_EQ(expected_iter->account_id, actual_iter->account_id);
EXPECT_EQ(expected_iter->status, actual_iter->status);
EXPECT_EQ(expected_iter->status_change_timestamp,
actual_iter->status_change_timestamp);
}
}
} // namespace gcm } // namespace gcm
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment