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

Unified Diff: components/gcm_driver/gcm_account_mapper_unittest.cc

Issue 961533002: Adding Send to Gaia ID feature (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removign the callback on shutdown Created 5 years, 10 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_account_mapper_unittest.cc
diff --git a/components/gcm_driver/gcm_account_mapper_unittest.cc b/components/gcm_driver/gcm_account_mapper_unittest.cc
index 93dae03ddfc9e29c3646ffb58ad211c4ccc3f892..98e79b6542f6191d8def3eb11473a61d3109b11f 100644
--- a/components/gcm_driver/gcm_account_mapper_unittest.cc
+++ b/components/gcm_driver/gcm_account_mapper_unittest.cc
@@ -4,6 +4,7 @@
#include "components/gcm_driver/gcm_account_mapper.h"
+#include "base/bind.h"
#include "base/test/simple_test_clock.h"
#include "base/time/time.h"
#include "components/gcm_driver/fake_gcm_driver.h"
@@ -81,6 +82,7 @@ class CustomFakeGCMDriver : public FakeGCMDriver {
CustomFakeGCMDriver();
~CustomFakeGCMDriver() override;
+ // GCMDriver implementation:
void UpdateAccountMapping(const AccountMapping& account_mapping) override;
void RemoveAccountMapping(const std::string& account_id) override;
void AddAppHandler(const std::string& app_id,
@@ -97,7 +99,6 @@ class CustomFakeGCMDriver : public FakeGCMDriver {
void CompleteSendAllMessages();
void AcknowledgeSendAllMessages();
-
void SetLastMessageAction(const std::string& message_id,
LastMessageAction action);
void Clear();
@@ -244,20 +245,31 @@ class GCMAccountMapperTest : public testing::Test {
void Restart();
+ void Initialize(const GCMAccountMapper::AccountMappings mappings);
const GCMAccountMapper::AccountMappings& GetAccounts() const {
return account_mapper_->accounts_;
}
+ void MessageReceived(const std::string& app_id,
+ const GCMClient::IncomingMessage& message);
GCMAccountMapper* mapper() { return account_mapper_.get(); }
CustomFakeGCMDriver& gcm_driver() { return gcm_driver_; }
base::SimpleTestClock* clock() { return clock_; }
+ const std::string& last_received_app_id() const {
+ return last_received_app_id_;
+ }
+ const GCMClient::IncomingMessage& last_received_message() const {
+ return last_received_message_;
+ }
private:
CustomFakeGCMDriver gcm_driver_;
scoped_ptr<GCMAccountMapper> account_mapper_;
base::SimpleTestClock* clock_;
+ std::string last_received_app_id_;
+ GCMClient::IncomingMessage last_received_message_;
};
GCMAccountMapperTest::GCMAccountMapperTest() {
@@ -277,11 +289,25 @@ void GCMAccountMapperTest::Restart() {
account_mapper_->SetClockForTesting(clock.Pass());
}
+void GCMAccountMapperTest::Initialize(
+ const GCMAccountMapper::AccountMappings mappings) {
+ mapper()->Initialize(mappings,
+ base::Bind(&GCMAccountMapperTest::MessageReceived,
+ base::Unretained(this)));
+}
+
+void GCMAccountMapperTest::MessageReceived(
+ const std::string& app_id,
+ const GCMClient::IncomingMessage& message) {
+ last_received_app_id_ = app_id;
+ last_received_message_ = message;
+}
+
// Tests the initialization of account mappings (from the store) when empty.
// It also checks that initialization triggers registration ID request.
TEST_F(GCMAccountMapperTest, InitializeAccountMappingsEmpty) {
EXPECT_FALSE(gcm_driver().registration_id_requested());
- mapper()->Initialize(GCMAccountMapper::AccountMappings());
+ Initialize(GCMAccountMapper::AccountMappings());
EXPECT_TRUE(GetAccounts().empty());
EXPECT_TRUE(gcm_driver().registration_id_requested());
}
@@ -289,7 +315,7 @@ TEST_F(GCMAccountMapperTest, InitializeAccountMappingsEmpty) {
// Tests that registration is retried, when new tokens are delivered and in no
// other circumstances.
TEST_F(GCMAccountMapperTest, RegistrationRetryUponFailure) {
- mapper()->Initialize(GCMAccountMapper::AccountMappings());
+ Initialize(GCMAccountMapper::AccountMappings());
EXPECT_TRUE(gcm_driver().registration_id_requested());
gcm_driver().Clear();
@@ -322,7 +348,7 @@ TEST_F(GCMAccountMapperTest, InitializeAccountMappings) {
account_mappings.push_back(account_mapping1);
account_mappings.push_back(account_mapping2);
- mapper()->Initialize(account_mappings);
+ Initialize(account_mappings);
GCMAccountMapper::AccountMappings mappings = GetAccounts();
EXPECT_EQ(2UL, mappings.size());
@@ -350,7 +376,7 @@ TEST_F(GCMAccountMapperTest, InitializeAccountMappings) {
// available.
TEST_F(GCMAccountMapperTest, SetAccountTokensOnlyWorksWithRegisterationId) {
// Start with empty list.
- mapper()->Initialize(GCMAccountMapper::AccountMappings());
+ Initialize(GCMAccountMapper::AccountMappings());
std::vector<GCMClient::AccountTokenInfo> account_tokens;
account_tokens.push_back(MakeAccountTokenInfo("acc_id"));
@@ -376,7 +402,7 @@ TEST_F(GCMAccountMapperTest, SetAccountTokensOnlyWorksWithRegisterationId) {
// Tests the part where a new account is added with a token, to the point when
// GCM message is sent.
TEST_F(GCMAccountMapperTest, AddMappingToMessageSent) {
- mapper()->Initialize(GCMAccountMapper::AccountMappings());
+ Initialize(GCMAccountMapper::AccountMappings());
gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS);
std::vector<GCMClient::AccountTokenInfo> account_tokens;
@@ -398,7 +424,7 @@ TEST_F(GCMAccountMapperTest, AddMappingToMessageSent) {
// Tests the part where GCM message is successfully queued.
TEST_F(GCMAccountMapperTest, AddMappingMessageQueued) {
- mapper()->Initialize(GCMAccountMapper::AccountMappings());
+ Initialize(GCMAccountMapper::AccountMappings());
gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS);
std::vector<GCMClient::AccountTokenInfo> account_tokens;
@@ -432,7 +458,7 @@ TEST_F(GCMAccountMapperTest, AddMappingMessageQueued) {
// Tests status change from ADDING to MAPPED (Message is acknowledged).
TEST_F(GCMAccountMapperTest, AddMappingMessageAcknowledged) {
- mapper()->Initialize(GCMAccountMapper::AccountMappings());
+ Initialize(GCMAccountMapper::AccountMappings());
gcm_driver().AddAppHandler(kGCMAccountMapperAppId, mapper());
gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS);
@@ -469,7 +495,7 @@ TEST_F(GCMAccountMapperTest, AddMappingMessageAcknowledged) {
// Tests status change form ADDING to MAPPED (When message was acknowledged,
// after Chrome was restarted).
TEST_F(GCMAccountMapperTest, AddMappingMessageAckedAfterRestart) {
- mapper()->Initialize(GCMAccountMapper::AccountMappings());
+ Initialize(GCMAccountMapper::AccountMappings());
gcm_driver().AddAppHandler(kGCMAccountMapperAppId, mapper());
gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS);
@@ -484,7 +510,7 @@ TEST_F(GCMAccountMapperTest, AddMappingMessageAckedAfterRestart) {
Restart();
GCMAccountMapper::AccountMappings stored_mappings;
stored_mappings.push_back(gcm_driver().last_account_mapping());
- mapper()->Initialize(stored_mappings);
+ Initialize(stored_mappings);
gcm_driver().AddAppHandler(kGCMAccountMapperAppId, mapper());
clock()->SetNow(base::Time::Now());
@@ -512,7 +538,7 @@ TEST_F(GCMAccountMapperTest, AddMappingMessageAckedAfterRestart) {
// Tests a case when ADD message times out for a new account.
TEST_F(GCMAccountMapperTest, AddMappingMessageSendErrorForNewAccount) {
- mapper()->Initialize(GCMAccountMapper::AccountMappings());
+ Initialize(GCMAccountMapper::AccountMappings());
gcm_driver().AddAppHandler(kGCMAccountMapperAppId, mapper());
gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS);
@@ -546,7 +572,7 @@ TEST_F(GCMAccountMapperTest, AddMappingMessageSendErrorForMappedAccount) {
GCMAccountMapper::AccountMappings stored_mappings;
stored_mappings.push_back(mapping);
- mapper()->Initialize(stored_mappings);
+ Initialize(stored_mappings);
gcm_driver().AddAppHandler(kGCMAccountMapperAppId, mapper());
gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS);
@@ -578,7 +604,7 @@ TEST_F(GCMAccountMapperTest, RemoveMappingToMessageSent) {
GCMAccountMapper::AccountMappings stored_mappings;
stored_mappings.push_back(mapping);
- mapper()->Initialize(stored_mappings);
+ Initialize(stored_mappings);
gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS);
clock()->SetNow(base::Time::Now());
@@ -613,7 +639,7 @@ TEST_F(GCMAccountMapperTest, RemoveMappingMessageQueued) {
GCMAccountMapper::AccountMappings stored_mappings;
stored_mappings.push_back(mapping);
- mapper()->Initialize(stored_mappings);
+ Initialize(stored_mappings);
gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS);
clock()->SetNow(base::Time::Now());
base::Time status_change_timestamp = clock()->Now();
@@ -654,7 +680,7 @@ TEST_F(GCMAccountMapperTest, RemoveMappingMessageAcknowledged) {
GCMAccountMapper::AccountMappings stored_mappings;
stored_mappings.push_back(mapping);
- mapper()->Initialize(stored_mappings);
+ Initialize(stored_mappings);
gcm_driver().AddAppHandler(kGCMAccountMapperAppId, mapper());
gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS);
clock()->SetNow(base::Time::Now());
@@ -680,7 +706,7 @@ TEST_F(GCMAccountMapperTest, RemoveMappingMessageAckedAfterRestart) {
GCMAccountMapper::AccountMappings stored_mappings;
stored_mappings.push_back(mapping);
- mapper()->Initialize(stored_mappings);
+ Initialize(stored_mappings);
gcm_driver().AddAppHandler(kGCMAccountMapperAppId, mapper());
gcm_driver().AcknowledgeSend("remove_message_id");
@@ -703,7 +729,7 @@ TEST_F(GCMAccountMapperTest, RemoveMappingMessageSendError) {
GCMAccountMapper::AccountMappings stored_mappings;
stored_mappings.push_back(mapping);
- mapper()->Initialize(stored_mappings);
+ Initialize(stored_mappings);
gcm_driver().AddAppHandler(kGCMAccountMapperAppId, mapper());
clock()->SetNow(base::Time::Now());
@@ -734,7 +760,7 @@ TEST_F(GCMAccountMapperTest, RemoveMappingMessageSendError) {
// no new message is sent and account mapper still waits for the first one to
// complete.
TEST_F(GCMAccountMapperTest, TokenIsRefreshedWhenAdding) {
- mapper()->Initialize(GCMAccountMapper::AccountMappings());
+ Initialize(GCMAccountMapper::AccountMappings());
gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS);
clock()->SetNow(base::Time::Now());
@@ -764,7 +790,7 @@ TEST_F(GCMAccountMapperTest, TokenIsRefreshedWhenRemoving) {
GCMAccountMapper::AccountMappings stored_mappings;
stored_mappings.push_back(mapping);
- mapper()->Initialize(stored_mappings);
+ Initialize(stored_mappings);
gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS);
clock()->SetNow(base::Time::Now());
@@ -818,7 +844,7 @@ TEST_F(GCMAccountMapperTest, MultipleAccountMappings) {
stored_mappings.push_back(MakeAccountMapping(
"acc_id_2", AccountMapping::REMOVING, half_hour_ago, "acc_id_2_msg"));
- mapper()->Initialize(stored_mappings);
+ Initialize(stored_mappings);
gcm_driver().AddAppHandler(kGCMAccountMapperAppId, mapper());
gcm_driver().CompleteRegister(kRegistrationId, GCMClient::SUCCESS);
@@ -911,4 +937,24 @@ TEST_F(GCMAccountMapperTest, MultipleAccountMappings) {
expected_mappings, GetAccounts(), "Step 6, Three mapped accounts");
}
+TEST_F(GCMAccountMapperTest, DispatchMessageSentToGaiaID) {
+ Initialize(GCMAccountMapper::AccountMappings());
+ gcm_driver().AddAppHandler(kGCMAccountMapperAppId, mapper());
+ GCMClient::IncomingMessage message;
+ message.data["gcmb"] = "test_app_id";
Nicolas Zea 2015/02/27 21:33:21 nit: it's a bit cleaner to declare const chars for
fgorski 2015/02/27 22:12:19 Done.
+ message.data["app_key"] = "app_value";
+ message.collapse_key = "test_key";
+ message.sender_id = "test_sender_id";
+ mapper()->OnMessage(kGCMAccountMapperAppId, message);
+
+ EXPECT_EQ("test_app_id", last_received_app_id());
+ EXPECT_EQ(1UL, last_received_message().data.size());
+ GCMClient::MessageData::const_iterator it =
+ last_received_message().data.find("app_key");
+ EXPECT_TRUE(it != last_received_message().data.end());
+ EXPECT_EQ("app_value", it->second);
+ EXPECT_EQ("test_sender_id", last_received_message().sender_id);
+ EXPECT_EQ("test_key", last_received_message().collapse_key);
+}
+
} // namespace gcm

Powered by Google App Engine
This is Rietveld 408576698