Re-land: C++ readability review
[chromium-blink-merge.git] / components / gcm_driver / gcm_client_impl_unittest.cc
bloba9a2429a9d5f02b3a91ae5f7beeee61a11ec0a05
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
3 // found in the LICENSE file.
5 #include "components/gcm_driver/gcm_client_impl.h"
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h"
14 #include "base/strings/string_number_conversions.h"
15 #include "base/time/clock.h"
16 #include "base/timer/timer.h"
17 #include "google_apis/gcm/base/fake_encryptor.h"
18 #include "google_apis/gcm/base/mcs_message.h"
19 #include "google_apis/gcm/base/mcs_util.h"
20 #include "google_apis/gcm/engine/fake_connection_factory.h"
21 #include "google_apis/gcm/engine/fake_connection_handler.h"
22 #include "google_apis/gcm/engine/gservices_settings.h"
23 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h"
24 #include "google_apis/gcm/protocol/android_checkin.pb.h"
25 #include "google_apis/gcm/protocol/checkin.pb.h"
26 #include "google_apis/gcm/protocol/mcs.pb.h"
27 #include "net/url_request/test_url_fetcher_factory.h"
28 #include "net/url_request/url_fetcher_delegate.h"
29 #include "net/url_request/url_request_test_util.h"
30 #include "testing/gtest/include/gtest/gtest.h"
32 namespace gcm {
34 namespace {
36 enum LastEvent {
37 NONE,
38 LOADING_COMPLETED,
39 REGISTRATION_COMPLETED,
40 UNREGISTRATION_COMPLETED,
41 MESSAGE_SEND_ERROR,
42 MESSAGE_SEND_ACK,
43 MESSAGE_RECEIVED,
44 MESSAGES_DELETED,
47 const uint64 kDeviceAndroidId = 54321;
48 const uint64 kDeviceSecurityToken = 12345;
49 const uint64 kDeviceAndroidId2 = 11111;
50 const uint64 kDeviceSecurityToken2 = 2222;
51 const int64 kSettingsCheckinInterval = 16 * 60 * 60;
52 const char kAppId[] = "app_id";
53 const char kSender[] = "project_id";
54 const char kSender2[] = "project_id2";
55 const char kSender3[] = "project_id3";
56 const char kRegistrationResponsePrefix[] = "token=";
57 const char kUnregistrationResponsePrefix[] = "deleted=";
59 // Helper for building arbitrary data messages.
60 MCSMessage BuildDownstreamMessage(
61 const std::string& project_id,
62 const std::string& app_id,
63 const std::map<std::string, std::string>& data) {
64 mcs_proto::DataMessageStanza data_message;
65 data_message.set_from(project_id);
66 data_message.set_category(app_id);
67 for (std::map<std::string, std::string>::const_iterator iter = data.begin();
68 iter != data.end();
69 ++iter) {
70 mcs_proto::AppData* app_data = data_message.add_app_data();
71 app_data->set_key(iter->first);
72 app_data->set_value(iter->second);
74 return MCSMessage(kDataMessageStanzaTag, data_message);
77 GCMClient::AccountTokenInfo MakeAccountToken(const std::string& email,
78 const std::string& token) {
79 GCMClient::AccountTokenInfo account_token;
80 account_token.email = email;
81 account_token.access_token = token;
82 return account_token;
85 std::map<std::string, std::string> MakeEmailToTokenMap(
86 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) {
87 std::map<std::string, std::string> email_token_map;
88 for (std::vector<GCMClient::AccountTokenInfo>::const_iterator iter =
89 account_tokens.begin(); iter != account_tokens.end(); ++iter) {
90 email_token_map[iter->email] = iter->access_token;
92 return email_token_map;
95 class FakeMCSClient : public MCSClient {
96 public:
97 FakeMCSClient(base::Clock* clock,
98 ConnectionFactory* connection_factory,
99 GCMStore* gcm_store,
100 GCMStatsRecorder* recorder);
101 ~FakeMCSClient() override;
102 void Login(uint64 android_id, uint64 security_token) override;
103 void SendMessage(const MCSMessage& message) override;
105 uint64 last_android_id() const { return last_android_id_; }
106 uint64 last_security_token() const { return last_security_token_; }
107 uint8 last_message_tag() const { return last_message_tag_; }
108 const mcs_proto::DataMessageStanza& last_data_message_stanza() const {
109 return last_data_message_stanza_;
112 private:
113 uint64 last_android_id_;
114 uint64 last_security_token_;
115 uint8 last_message_tag_;
116 mcs_proto::DataMessageStanza last_data_message_stanza_;
119 FakeMCSClient::FakeMCSClient(base::Clock* clock,
120 ConnectionFactory* connection_factory,
121 GCMStore* gcm_store,
122 GCMStatsRecorder* recorder)
123 : MCSClient("", clock, connection_factory, gcm_store, recorder),
124 last_android_id_(0u),
125 last_security_token_(0u),
126 last_message_tag_(kNumProtoTypes) {
129 FakeMCSClient::~FakeMCSClient() {
132 void FakeMCSClient::Login(uint64 android_id, uint64 security_token) {
133 last_android_id_ = android_id;
134 last_security_token_ = security_token;
137 void FakeMCSClient::SendMessage(const MCSMessage& message) {
138 last_message_tag_ = message.tag();
139 if (last_message_tag_ == kDataMessageStanzaTag) {
140 last_data_message_stanza_.CopyFrom(
141 reinterpret_cast<const mcs_proto::DataMessageStanza&>(
142 message.GetProtobuf()));
146 class AutoAdvancingTestClock : public base::Clock {
147 public:
148 explicit AutoAdvancingTestClock(base::TimeDelta auto_increment_time_delta);
149 ~AutoAdvancingTestClock() override;
151 base::Time Now() override;
152 void Advance(TimeDelta delta);
153 int call_count() const { return call_count_; }
155 private:
156 int call_count_;
157 base::TimeDelta auto_increment_time_delta_;
158 base::Time now_;
160 DISALLOW_COPY_AND_ASSIGN(AutoAdvancingTestClock);
163 AutoAdvancingTestClock::AutoAdvancingTestClock(
164 base::TimeDelta auto_increment_time_delta)
165 : call_count_(0), auto_increment_time_delta_(auto_increment_time_delta) {
168 AutoAdvancingTestClock::~AutoAdvancingTestClock() {
171 base::Time AutoAdvancingTestClock::Now() {
172 call_count_++;
173 now_ += auto_increment_time_delta_;
174 return now_;
177 void AutoAdvancingTestClock::Advance(base::TimeDelta delta) {
178 now_ += delta;
181 class FakeGCMInternalsBuilder : public GCMInternalsBuilder {
182 public:
183 FakeGCMInternalsBuilder(base::TimeDelta clock_step);
184 ~FakeGCMInternalsBuilder() override;
186 scoped_ptr<base::Clock> BuildClock() override;
187 scoped_ptr<MCSClient> BuildMCSClient(const std::string& version,
188 base::Clock* clock,
189 ConnectionFactory* connection_factory,
190 GCMStore* gcm_store,
191 GCMStatsRecorder* recorder) override;
192 scoped_ptr<ConnectionFactory> BuildConnectionFactory(
193 const std::vector<GURL>& endpoints,
194 const net::BackoffEntry::Policy& backoff_policy,
195 const scoped_refptr<net::HttpNetworkSession>& gcm_network_session,
196 const scoped_refptr<net::HttpNetworkSession>& http_network_session,
197 net::NetLog* net_log,
198 GCMStatsRecorder* recorder) override;
200 private:
201 base::TimeDelta clock_step_;
204 FakeGCMInternalsBuilder::FakeGCMInternalsBuilder(base::TimeDelta clock_step)
205 : clock_step_(clock_step) {
208 FakeGCMInternalsBuilder::~FakeGCMInternalsBuilder() {}
210 scoped_ptr<base::Clock> FakeGCMInternalsBuilder::BuildClock() {
211 return make_scoped_ptr<base::Clock>(new AutoAdvancingTestClock(clock_step_));
214 scoped_ptr<MCSClient> FakeGCMInternalsBuilder::BuildMCSClient(
215 const std::string& version,
216 base::Clock* clock,
217 ConnectionFactory* connection_factory,
218 GCMStore* gcm_store,
219 GCMStatsRecorder* recorder) {
220 return make_scoped_ptr<MCSClient>(new FakeMCSClient(clock,
221 connection_factory,
222 gcm_store,
223 recorder));
226 scoped_ptr<ConnectionFactory> FakeGCMInternalsBuilder::BuildConnectionFactory(
227 const std::vector<GURL>& endpoints,
228 const net::BackoffEntry::Policy& backoff_policy,
229 const scoped_refptr<net::HttpNetworkSession>& gcm_network_session,
230 const scoped_refptr<net::HttpNetworkSession>& http_network_session,
231 net::NetLog* net_log,
232 GCMStatsRecorder* recorder) {
233 return make_scoped_ptr<ConnectionFactory>(new FakeConnectionFactory());
236 } // namespace
238 class GCMClientImplTest : public testing::Test,
239 public GCMClient::Delegate {
240 public:
241 GCMClientImplTest();
242 ~GCMClientImplTest() override;
244 void SetUp() override;
246 void SetUpUrlFetcherFactory();
248 void BuildGCMClient(base::TimeDelta clock_step);
249 void InitializeGCMClient();
250 void StartGCMClient();
251 void ReceiveMessageFromMCS(const MCSMessage& message);
252 void ReceiveOnMessageSentToMCS(
253 const std::string& app_id,
254 const std::string& message_id,
255 const MCSClient::MessageSendStatus status);
256 void CompleteCheckin(uint64 android_id,
257 uint64 security_token,
258 const std::string& digest,
259 const std::map<std::string, std::string>& settings);
260 void CompleteRegistration(const std::string& registration_id);
261 void CompleteUnregistration(const std::string& app_id);
262 void VerifyPendingRequestFetcherDeleted();
264 bool ExistsRegistration(const std::string& app_id) const;
265 void AddRegistration(const std::string& app_id,
266 const std::vector<std::string>& sender_ids,
267 const std::string& registration_id);
269 // GCMClient::Delegate overrides (for verification).
270 void OnRegisterFinished(const std::string& app_id,
271 const std::string& registration_id,
272 GCMClient::Result result) override;
273 void OnUnregisterFinished(const std::string& app_id,
274 GCMClient::Result result) override;
275 void OnSendFinished(const std::string& app_id,
276 const std::string& message_id,
277 GCMClient::Result result) override {}
278 void OnMessageReceived(const std::string& registration_id,
279 const GCMClient::IncomingMessage& message) override;
280 void OnMessagesDeleted(const std::string& app_id) override;
281 void OnMessageSendError(
282 const std::string& app_id,
283 const gcm::GCMClient::SendErrorDetails& send_error_details) override;
284 void OnSendAcknowledged(const std::string& app_id,
285 const std::string& message_id) override;
286 void OnGCMReady(const std::vector<AccountMapping>& account_mappings,
287 const base::Time& last_token_fetch_time) override;
288 void OnActivityRecorded() override {}
289 void OnConnected(const net::IPEndPoint& ip_endpoint) override {}
290 void OnDisconnected() override {}
292 GCMClientImpl* gcm_client() const { return gcm_client_.get(); }
293 GCMClientImpl::State gcm_client_state() const {
294 return gcm_client_->state_;
296 FakeMCSClient* mcs_client() const {
297 return reinterpret_cast<FakeMCSClient*>(gcm_client_->mcs_client_.get());
299 ConnectionFactory* connection_factory() const {
300 return gcm_client_->connection_factory_.get();
303 const GCMClientImpl::CheckinInfo& device_checkin_info() const {
304 return gcm_client_->device_checkin_info_;
307 void reset_last_event() {
308 last_event_ = NONE;
309 last_app_id_.clear();
310 last_registration_id_.clear();
311 last_message_id_.clear();
312 last_result_ = GCMClient::UNKNOWN_ERROR;
313 last_account_mappings_.clear();
314 last_token_fetch_time_ = base::Time();
317 LastEvent last_event() const { return last_event_; }
318 const std::string& last_app_id() const { return last_app_id_; }
319 const std::string& last_registration_id() const {
320 return last_registration_id_;
322 const std::string& last_message_id() const { return last_message_id_; }
323 GCMClient::Result last_result() const { return last_result_; }
324 const GCMClient::IncomingMessage& last_message() const {
325 return last_message_;
327 const GCMClient::SendErrorDetails& last_error_details() const {
328 return last_error_details_;
330 const base::Time& last_token_fetch_time() const {
331 return last_token_fetch_time_;
333 const std::vector<AccountMapping>& last_account_mappings() {
334 return last_account_mappings_;
337 const GServicesSettings& gservices_settings() const {
338 return gcm_client_->gservices_settings_;
341 const base::FilePath& temp_directory_path() const {
342 return temp_directory_.path();
345 int64 CurrentTime();
347 // Tooling.
348 void PumpLoop();
349 void PumpLoopUntilIdle();
350 void QuitLoop();
351 void InitializeLoop();
352 bool CreateUniqueTempDir();
353 AutoAdvancingTestClock* clock() const {
354 return reinterpret_cast<AutoAdvancingTestClock*>(gcm_client_->clock_.get());
357 private:
358 // Variables used for verification.
359 LastEvent last_event_;
360 std::string last_app_id_;
361 std::string last_registration_id_;
362 std::string last_message_id_;
363 GCMClient::Result last_result_;
364 GCMClient::IncomingMessage last_message_;
365 GCMClient::SendErrorDetails last_error_details_;
366 base::Time last_token_fetch_time_;
367 std::vector<AccountMapping> last_account_mappings_;
369 scoped_ptr<GCMClientImpl> gcm_client_;
371 base::MessageLoop message_loop_;
372 scoped_ptr<base::RunLoop> run_loop_;
373 net::TestURLFetcherFactory url_fetcher_factory_;
375 // Injected to GCM client:
376 base::ScopedTempDir temp_directory_;
377 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_;
380 GCMClientImplTest::GCMClientImplTest()
381 : last_event_(NONE),
382 last_result_(GCMClient::UNKNOWN_ERROR),
383 url_request_context_getter_(new net::TestURLRequestContextGetter(
384 message_loop_.message_loop_proxy())) {
387 GCMClientImplTest::~GCMClientImplTest() {}
389 void GCMClientImplTest::SetUp() {
390 testing::Test::SetUp();
391 ASSERT_TRUE(CreateUniqueTempDir());
392 InitializeLoop();
393 BuildGCMClient(base::TimeDelta());
394 InitializeGCMClient();
395 StartGCMClient();
396 SetUpUrlFetcherFactory();
397 CompleteCheckin(kDeviceAndroidId,
398 kDeviceSecurityToken,
399 std::string(),
400 std::map<std::string, std::string>());
403 void GCMClientImplTest::SetUpUrlFetcherFactory() {
404 url_fetcher_factory_.set_remove_fetcher_on_delete(true);
407 void GCMClientImplTest::PumpLoop() {
408 run_loop_->Run();
409 run_loop_.reset(new base::RunLoop());
412 void GCMClientImplTest::PumpLoopUntilIdle() {
413 run_loop_->RunUntilIdle();
414 run_loop_.reset(new base::RunLoop());
417 void GCMClientImplTest::QuitLoop() {
418 if (run_loop_ && run_loop_->running())
419 run_loop_->Quit();
422 void GCMClientImplTest::InitializeLoop() {
423 run_loop_.reset(new base::RunLoop);
426 bool GCMClientImplTest::CreateUniqueTempDir() {
427 return temp_directory_.CreateUniqueTempDir();
430 void GCMClientImplTest::BuildGCMClient(base::TimeDelta clock_step) {
431 gcm_client_.reset(new GCMClientImpl(make_scoped_ptr<GCMInternalsBuilder>(
432 new FakeGCMInternalsBuilder(clock_step))));
435 void GCMClientImplTest::CompleteCheckin(
436 uint64 android_id,
437 uint64 security_token,
438 const std::string& digest,
439 const std::map<std::string, std::string>& settings) {
440 checkin_proto::AndroidCheckinResponse response;
441 response.set_stats_ok(true);
442 response.set_android_id(android_id);
443 response.set_security_token(security_token);
445 // For testing G-services settings.
446 if (!digest.empty()) {
447 response.set_digest(digest);
448 for (std::map<std::string, std::string>::const_iterator it =
449 settings.begin();
450 it != settings.end();
451 ++it) {
452 checkin_proto::GservicesSetting* setting = response.add_setting();
453 setting->set_name(it->first);
454 setting->set_value(it->second);
456 response.set_settings_diff(false);
459 std::string response_string;
460 response.SerializeToString(&response_string);
462 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
463 ASSERT_TRUE(fetcher);
464 fetcher->set_response_code(net::HTTP_OK);
465 fetcher->SetResponseString(response_string);
466 fetcher->delegate()->OnURLFetchComplete(fetcher);
469 void GCMClientImplTest::CompleteRegistration(
470 const std::string& registration_id) {
471 std::string response(kRegistrationResponsePrefix);
472 response.append(registration_id);
473 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
474 ASSERT_TRUE(fetcher);
475 fetcher->set_response_code(net::HTTP_OK);
476 fetcher->SetResponseString(response);
477 fetcher->delegate()->OnURLFetchComplete(fetcher);
480 void GCMClientImplTest::CompleteUnregistration(
481 const std::string& app_id) {
482 std::string response(kUnregistrationResponsePrefix);
483 response.append(app_id);
484 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
485 ASSERT_TRUE(fetcher);
486 fetcher->set_response_code(net::HTTP_OK);
487 fetcher->SetResponseString(response);
488 fetcher->delegate()->OnURLFetchComplete(fetcher);
491 void GCMClientImplTest::VerifyPendingRequestFetcherDeleted() {
492 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
493 EXPECT_FALSE(fetcher);
496 bool GCMClientImplTest::ExistsRegistration(const std::string& app_id) const {
497 return gcm_client_->registrations_.count(app_id) > 0;
500 void GCMClientImplTest::AddRegistration(
501 const std::string& app_id,
502 const std::vector<std::string>& sender_ids,
503 const std::string& registration_id) {
504 linked_ptr<RegistrationInfo> registration(new RegistrationInfo);
505 registration->sender_ids = sender_ids;
506 registration->registration_id = registration_id;
507 gcm_client_->registrations_[app_id] = registration;
510 void GCMClientImplTest::InitializeGCMClient() {
511 clock()->Advance(base::TimeDelta::FromMilliseconds(1));
513 // Actual initialization.
514 GCMClient::ChromeBuildInfo chrome_build_info;
515 gcm_client_->Initialize(chrome_build_info,
516 temp_directory_.path(),
517 message_loop_.message_loop_proxy(),
518 url_request_context_getter_,
519 make_scoped_ptr<Encryptor>(new FakeEncryptor),
520 this);
523 void GCMClientImplTest::StartGCMClient() {
524 // Start loading and check-in.
525 gcm_client_->Start(GCMClient::IMMEDIATE_START);
527 PumpLoopUntilIdle();
530 void GCMClientImplTest::ReceiveMessageFromMCS(const MCSMessage& message) {
531 gcm_client_->recorder_.RecordConnectionInitiated(std::string());
532 gcm_client_->recorder_.RecordConnectionSuccess();
533 gcm_client_->OnMessageReceivedFromMCS(message);
536 void GCMClientImplTest::ReceiveOnMessageSentToMCS(
537 const std::string& app_id,
538 const std::string& message_id,
539 const MCSClient::MessageSendStatus status) {
540 gcm_client_->OnMessageSentToMCS(0LL, app_id, message_id, status);
543 void GCMClientImplTest::OnGCMReady(
544 const std::vector<AccountMapping>& account_mappings,
545 const base::Time& last_token_fetch_time) {
546 last_event_ = LOADING_COMPLETED;
547 last_account_mappings_ = account_mappings;
548 last_token_fetch_time_ = last_token_fetch_time;
549 QuitLoop();
552 void GCMClientImplTest::OnMessageReceived(
553 const std::string& registration_id,
554 const GCMClient::IncomingMessage& message) {
555 last_event_ = MESSAGE_RECEIVED;
556 last_app_id_ = registration_id;
557 last_message_ = message;
558 QuitLoop();
561 void GCMClientImplTest::OnRegisterFinished(const std::string& app_id,
562 const std::string& registration_id,
563 GCMClient::Result result) {
564 last_event_ = REGISTRATION_COMPLETED;
565 last_app_id_ = app_id;
566 last_registration_id_ = registration_id;
567 last_result_ = result;
570 void GCMClientImplTest::OnUnregisterFinished(const std::string& app_id,
571 GCMClient::Result result) {
572 last_event_ = UNREGISTRATION_COMPLETED;
573 last_app_id_ = app_id;
574 last_result_ = result;
577 void GCMClientImplTest::OnMessagesDeleted(const std::string& app_id) {
578 last_event_ = MESSAGES_DELETED;
579 last_app_id_ = app_id;
582 void GCMClientImplTest::OnMessageSendError(
583 const std::string& app_id,
584 const gcm::GCMClient::SendErrorDetails& send_error_details) {
585 last_event_ = MESSAGE_SEND_ERROR;
586 last_app_id_ = app_id;
587 last_error_details_ = send_error_details;
590 void GCMClientImplTest::OnSendAcknowledged(const std::string& app_id,
591 const std::string& message_id) {
592 last_event_ = MESSAGE_SEND_ACK;
593 last_app_id_ = app_id;
594 last_message_id_ = message_id;
597 int64 GCMClientImplTest::CurrentTime() {
598 return clock()->Now().ToInternalValue() / base::Time::kMicrosecondsPerSecond;
601 TEST_F(GCMClientImplTest, LoadingCompleted) {
602 EXPECT_EQ(LOADING_COMPLETED, last_event());
603 EXPECT_EQ(kDeviceAndroidId, mcs_client()->last_android_id());
604 EXPECT_EQ(kDeviceSecurityToken, mcs_client()->last_security_token());
606 // Checking freshly loaded CheckinInfo.
607 EXPECT_EQ(kDeviceAndroidId, device_checkin_info().android_id);
608 EXPECT_EQ(kDeviceSecurityToken, device_checkin_info().secret);
609 EXPECT_TRUE(device_checkin_info().last_checkin_accounts.empty());
610 EXPECT_TRUE(device_checkin_info().accounts_set);
611 EXPECT_TRUE(device_checkin_info().account_tokens.empty());
614 TEST_F(GCMClientImplTest, LoadingBusted) {
615 // Close the GCM store.
616 gcm_client()->Stop();
617 PumpLoopUntilIdle();
619 // Mess up the store.
620 base::FilePath store_file_path =
621 temp_directory_path().Append(FILE_PATH_LITERAL("CURRENT"));
622 ASSERT_TRUE(base::AppendToFile(store_file_path, "A", 1));
624 // Restart GCM client. The store should be reset and the loading should
625 // complete successfully.
626 reset_last_event();
627 BuildGCMClient(base::TimeDelta());
628 InitializeGCMClient();
629 StartGCMClient();
630 CompleteCheckin(kDeviceAndroidId2,
631 kDeviceSecurityToken2,
632 std::string(),
633 std::map<std::string, std::string>());
635 EXPECT_EQ(LOADING_COMPLETED, last_event());
636 EXPECT_EQ(kDeviceAndroidId2, mcs_client()->last_android_id());
637 EXPECT_EQ(kDeviceSecurityToken2, mcs_client()->last_security_token());
640 TEST_F(GCMClientImplTest, RegisterApp) {
641 EXPECT_FALSE(ExistsRegistration(kAppId));
643 std::vector<std::string> senders;
644 senders.push_back("sender");
645 gcm_client()->Register(kAppId, senders);
646 CompleteRegistration("reg_id");
648 EXPECT_EQ(REGISTRATION_COMPLETED, last_event());
649 EXPECT_EQ(kAppId, last_app_id());
650 EXPECT_EQ("reg_id", last_registration_id());
651 EXPECT_EQ(GCMClient::SUCCESS, last_result());
652 EXPECT_TRUE(ExistsRegistration(kAppId));
655 TEST_F(GCMClientImplTest, DISABLED_RegisterAppFromCache) {
656 EXPECT_FALSE(ExistsRegistration(kAppId));
658 std::vector<std::string> senders;
659 senders.push_back("sender");
660 gcm_client()->Register(kAppId, senders);
661 CompleteRegistration("reg_id");
662 EXPECT_TRUE(ExistsRegistration(kAppId));
664 EXPECT_EQ(kAppId, last_app_id());
665 EXPECT_EQ("reg_id", last_registration_id());
666 EXPECT_EQ(GCMClient::SUCCESS, last_result());
667 EXPECT_EQ(REGISTRATION_COMPLETED, last_event());
669 // Recreate GCMClient in order to load from the persistent store.
670 BuildGCMClient(base::TimeDelta());
671 InitializeGCMClient();
672 StartGCMClient();
674 EXPECT_TRUE(ExistsRegistration(kAppId));
677 TEST_F(GCMClientImplTest, UnregisterApp) {
678 EXPECT_FALSE(ExistsRegistration(kAppId));
680 std::vector<std::string> senders;
681 senders.push_back("sender");
682 gcm_client()->Register(kAppId, senders);
683 CompleteRegistration("reg_id");
684 EXPECT_TRUE(ExistsRegistration(kAppId));
686 gcm_client()->Unregister(kAppId);
687 CompleteUnregistration(kAppId);
689 EXPECT_EQ(UNREGISTRATION_COMPLETED, last_event());
690 EXPECT_EQ(kAppId, last_app_id());
691 EXPECT_EQ(GCMClient::SUCCESS, last_result());
692 EXPECT_FALSE(ExistsRegistration(kAppId));
695 // Tests that stopping the GCMClient also deletes pending registration requests.
696 // This is tested by checking that url fetcher contained in the request was
697 // deleted.
698 TEST_F(GCMClientImplTest, DeletePendingRequestsWhenStopping) {
699 std::vector<std::string> senders;
700 senders.push_back("sender");
701 gcm_client()->Register(kAppId, senders);
703 gcm_client()->Stop();
704 VerifyPendingRequestFetcherDeleted();
707 TEST_F(GCMClientImplTest, DispatchDownstreamMessage) {
708 // Register to receive messages from kSender and kSender2 only.
709 std::vector<std::string> senders;
710 senders.push_back(kSender);
711 senders.push_back(kSender2);
712 AddRegistration(kAppId, senders, "reg_id");
714 std::map<std::string, std::string> expected_data;
715 expected_data["message_type"] = "gcm";
716 expected_data["key"] = "value";
717 expected_data["key2"] = "value2";
719 // Message for kSender will be received.
720 MCSMessage message(BuildDownstreamMessage(kSender, kAppId, expected_data));
721 EXPECT_TRUE(message.IsValid());
722 ReceiveMessageFromMCS(message);
724 expected_data.erase(expected_data.find("message_type"));
725 EXPECT_EQ(MESSAGE_RECEIVED, last_event());
726 EXPECT_EQ(kAppId, last_app_id());
727 EXPECT_EQ(expected_data.size(), last_message().data.size());
728 EXPECT_EQ(expected_data, last_message().data);
729 EXPECT_EQ(kSender, last_message().sender_id);
731 reset_last_event();
733 // Message for kSender2 will be received.
734 MCSMessage message2(BuildDownstreamMessage(kSender2, kAppId, expected_data));
735 EXPECT_TRUE(message2.IsValid());
736 ReceiveMessageFromMCS(message2);
738 EXPECT_EQ(MESSAGE_RECEIVED, last_event());
739 EXPECT_EQ(kAppId, last_app_id());
740 EXPECT_EQ(expected_data.size(), last_message().data.size());
741 EXPECT_EQ(expected_data, last_message().data);
742 EXPECT_EQ(kSender2, last_message().sender_id);
744 reset_last_event();
746 // Message from kSender3 will be dropped.
747 MCSMessage message3(BuildDownstreamMessage(kSender3, kAppId, expected_data));
748 EXPECT_TRUE(message3.IsValid());
749 ReceiveMessageFromMCS(message3);
751 EXPECT_NE(MESSAGE_RECEIVED, last_event());
752 EXPECT_NE(kAppId, last_app_id());
755 TEST_F(GCMClientImplTest, DispatchDownstreamMessageSendError) {
756 std::map<std::string, std::string> expected_data;
757 expected_data["message_type"] = "send_error";
758 expected_data["google.message_id"] = "007";
759 expected_data["error_details"] = "some details";
760 MCSMessage message(BuildDownstreamMessage(
761 kSender, kAppId, expected_data));
762 EXPECT_TRUE(message.IsValid());
763 ReceiveMessageFromMCS(message);
765 EXPECT_EQ(MESSAGE_SEND_ERROR, last_event());
766 EXPECT_EQ(kAppId, last_app_id());
767 EXPECT_EQ("007", last_error_details().message_id);
768 EXPECT_EQ(1UL, last_error_details().additional_data.size());
769 GCMClient::MessageData::const_iterator iter =
770 last_error_details().additional_data.find("error_details");
771 EXPECT_TRUE(iter != last_error_details().additional_data.end());
772 EXPECT_EQ("some details", iter->second);
775 TEST_F(GCMClientImplTest, DispatchDownstreamMessgaesDeleted) {
776 std::map<std::string, std::string> expected_data;
777 expected_data["message_type"] = "deleted_messages";
778 MCSMessage message(BuildDownstreamMessage(
779 kSender, kAppId, expected_data));
780 EXPECT_TRUE(message.IsValid());
781 ReceiveMessageFromMCS(message);
783 EXPECT_EQ(MESSAGES_DELETED, last_event());
784 EXPECT_EQ(kAppId, last_app_id());
787 TEST_F(GCMClientImplTest, SendMessage) {
788 GCMClient::OutgoingMessage message;
789 message.id = "007";
790 message.time_to_live = 500;
791 message.data["key"] = "value";
792 gcm_client()->Send(kAppId, kSender, message);
794 EXPECT_EQ(kDataMessageStanzaTag, mcs_client()->last_message_tag());
795 EXPECT_EQ(kAppId, mcs_client()->last_data_message_stanza().category());
796 EXPECT_EQ(kSender, mcs_client()->last_data_message_stanza().to());
797 EXPECT_EQ(500, mcs_client()->last_data_message_stanza().ttl());
798 EXPECT_EQ(CurrentTime(), mcs_client()->last_data_message_stanza().sent());
799 EXPECT_EQ("007", mcs_client()->last_data_message_stanza().id());
800 EXPECT_EQ("gcm@chrome.com", mcs_client()->last_data_message_stanza().from());
801 EXPECT_EQ(kSender, mcs_client()->last_data_message_stanza().to());
802 EXPECT_EQ("key", mcs_client()->last_data_message_stanza().app_data(0).key());
803 EXPECT_EQ("value",
804 mcs_client()->last_data_message_stanza().app_data(0).value());
807 TEST_F(GCMClientImplTest, SendMessageAcknowledged) {
808 ReceiveOnMessageSentToMCS(kAppId, "007", MCSClient::SENT);
809 EXPECT_EQ(MESSAGE_SEND_ACK, last_event());
810 EXPECT_EQ(kAppId, last_app_id());
811 EXPECT_EQ("007", last_message_id());
814 class GCMClientImplCheckinTest : public GCMClientImplTest {
815 public:
816 GCMClientImplCheckinTest();
817 ~GCMClientImplCheckinTest() override;
819 void SetUp() override;
822 GCMClientImplCheckinTest::GCMClientImplCheckinTest() {
825 GCMClientImplCheckinTest::~GCMClientImplCheckinTest() {
828 void GCMClientImplCheckinTest::SetUp() {
829 testing::Test::SetUp();
830 // Creating unique temp directory that will be used by GCMStore shared between
831 // GCM Client and G-services settings.
832 ASSERT_TRUE(CreateUniqueTempDir());
833 InitializeLoop();
834 // Time will be advancing one hour every time it is checked.
835 BuildGCMClient(base::TimeDelta::FromSeconds(kSettingsCheckinInterval));
836 InitializeGCMClient();
837 StartGCMClient();
840 TEST_F(GCMClientImplCheckinTest, GServicesSettingsAfterInitialCheckin) {
841 std::map<std::string, std::string> settings;
842 settings["checkin_interval"] = base::Int64ToString(kSettingsCheckinInterval);
843 settings["checkin_url"] = "http://alternative.url/checkin";
844 settings["gcm_hostname"] = "alternative.gcm.host";
845 settings["gcm_secure_port"] = "7777";
846 settings["gcm_registration_url"] = "http://alternative.url/registration";
847 CompleteCheckin(kDeviceAndroidId,
848 kDeviceSecurityToken,
849 GServicesSettings::CalculateDigest(settings),
850 settings);
851 EXPECT_EQ(base::TimeDelta::FromSeconds(kSettingsCheckinInterval),
852 gservices_settings().GetCheckinInterval());
853 EXPECT_EQ(GURL("http://alternative.url/checkin"),
854 gservices_settings().GetCheckinURL());
855 EXPECT_EQ(GURL("http://alternative.url/registration"),
856 gservices_settings().GetRegistrationURL());
857 EXPECT_EQ(GURL("https://alternative.gcm.host:7777"),
858 gservices_settings().GetMCSMainEndpoint());
859 EXPECT_EQ(GURL("https://alternative.gcm.host:443"),
860 gservices_settings().GetMCSFallbackEndpoint());
863 // This test only checks that periodic checkin happens.
864 TEST_F(GCMClientImplCheckinTest, PeriodicCheckin) {
865 std::map<std::string, std::string> settings;
866 settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval);
867 settings["checkin_url"] = "http://alternative.url/checkin";
868 settings["gcm_hostname"] = "alternative.gcm.host";
869 settings["gcm_secure_port"] = "7777";
870 settings["gcm_registration_url"] = "http://alternative.url/registration";
871 CompleteCheckin(kDeviceAndroidId,
872 kDeviceSecurityToken,
873 GServicesSettings::CalculateDigest(settings),
874 settings);
876 EXPECT_EQ(2, clock()->call_count());
878 PumpLoopUntilIdle();
879 CompleteCheckin(kDeviceAndroidId,
880 kDeviceSecurityToken,
881 GServicesSettings::CalculateDigest(settings),
882 settings);
885 TEST_F(GCMClientImplCheckinTest, LoadGSettingsFromStore) {
886 std::map<std::string, std::string> settings;
887 settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval);
888 settings["checkin_url"] = "http://alternative.url/checkin";
889 settings["gcm_hostname"] = "alternative.gcm.host";
890 settings["gcm_secure_port"] = "7777";
891 settings["gcm_registration_url"] = "http://alternative.url/registration";
892 CompleteCheckin(kDeviceAndroidId,
893 kDeviceSecurityToken,
894 GServicesSettings::CalculateDigest(settings),
895 settings);
897 BuildGCMClient(base::TimeDelta());
898 InitializeGCMClient();
899 StartGCMClient();
901 EXPECT_EQ(base::TimeDelta::FromSeconds(kSettingsCheckinInterval),
902 gservices_settings().GetCheckinInterval());
903 EXPECT_EQ(GURL("http://alternative.url/checkin"),
904 gservices_settings().GetCheckinURL());
905 EXPECT_EQ(GURL("http://alternative.url/registration"),
906 gservices_settings().GetRegistrationURL());
907 EXPECT_EQ(GURL("https://alternative.gcm.host:7777"),
908 gservices_settings().GetMCSMainEndpoint());
909 EXPECT_EQ(GURL("https://alternative.gcm.host:443"),
910 gservices_settings().GetMCSFallbackEndpoint());
913 // This test only checks that periodic checkin happens.
914 TEST_F(GCMClientImplCheckinTest, CheckinWithAccounts) {
915 std::map<std::string, std::string> settings;
916 settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval);
917 settings["checkin_url"] = "http://alternative.url/checkin";
918 settings["gcm_hostname"] = "alternative.gcm.host";
919 settings["gcm_secure_port"] = "7777";
920 settings["gcm_registration_url"] = "http://alternative.url/registration";
921 CompleteCheckin(kDeviceAndroidId,
922 kDeviceSecurityToken,
923 GServicesSettings::CalculateDigest(settings),
924 settings);
926 std::vector<GCMClient::AccountTokenInfo> account_tokens;
927 account_tokens.push_back(MakeAccountToken("test_user1@gmail.com", "token1"));
928 account_tokens.push_back(MakeAccountToken("test_user2@gmail.com", "token2"));
929 gcm_client()->SetAccountTokens(account_tokens);
931 EXPECT_TRUE(device_checkin_info().last_checkin_accounts.empty());
932 EXPECT_TRUE(device_checkin_info().accounts_set);
933 EXPECT_EQ(MakeEmailToTokenMap(account_tokens),
934 device_checkin_info().account_tokens);
936 PumpLoopUntilIdle();
937 CompleteCheckin(kDeviceAndroidId,
938 kDeviceSecurityToken,
939 GServicesSettings::CalculateDigest(settings),
940 settings);
942 std::set<std::string> accounts;
943 accounts.insert("test_user1@gmail.com");
944 accounts.insert("test_user2@gmail.com");
945 EXPECT_EQ(accounts, device_checkin_info().last_checkin_accounts);
946 EXPECT_TRUE(device_checkin_info().accounts_set);
947 EXPECT_EQ(MakeEmailToTokenMap(account_tokens),
948 device_checkin_info().account_tokens);
951 // This test only checks that periodic checkin happens.
952 TEST_F(GCMClientImplCheckinTest, CheckinWhenAccountRemoved) {
953 std::map<std::string, std::string> settings;
954 settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval);
955 settings["checkin_url"] = "http://alternative.url/checkin";
956 settings["gcm_hostname"] = "alternative.gcm.host";
957 settings["gcm_secure_port"] = "7777";
958 settings["gcm_registration_url"] = "http://alternative.url/registration";
959 CompleteCheckin(kDeviceAndroidId,
960 kDeviceSecurityToken,
961 GServicesSettings::CalculateDigest(settings),
962 settings);
964 std::vector<GCMClient::AccountTokenInfo> account_tokens;
965 account_tokens.push_back(MakeAccountToken("test_user1@gmail.com", "token1"));
966 account_tokens.push_back(MakeAccountToken("test_user2@gmail.com", "token2"));
967 gcm_client()->SetAccountTokens(account_tokens);
968 PumpLoopUntilIdle();
969 CompleteCheckin(kDeviceAndroidId,
970 kDeviceSecurityToken,
971 GServicesSettings::CalculateDigest(settings),
972 settings);
974 EXPECT_EQ(2UL, device_checkin_info().last_checkin_accounts.size());
975 EXPECT_TRUE(device_checkin_info().accounts_set);
976 EXPECT_EQ(MakeEmailToTokenMap(account_tokens),
977 device_checkin_info().account_tokens);
979 account_tokens.erase(account_tokens.begin() + 1);
980 gcm_client()->SetAccountTokens(account_tokens);
982 PumpLoopUntilIdle();
983 CompleteCheckin(kDeviceAndroidId,
984 kDeviceSecurityToken,
985 GServicesSettings::CalculateDigest(settings),
986 settings);
988 std::set<std::string> accounts;
989 accounts.insert("test_user1@gmail.com");
990 EXPECT_EQ(accounts, device_checkin_info().last_checkin_accounts);
991 EXPECT_TRUE(device_checkin_info().accounts_set);
992 EXPECT_EQ(MakeEmailToTokenMap(account_tokens),
993 device_checkin_info().account_tokens);
996 // This test only checks that periodic checkin happens.
997 TEST_F(GCMClientImplCheckinTest, CheckinWhenAccountReplaced) {
998 std::map<std::string, std::string> settings;
999 settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval);
1000 settings["checkin_url"] = "http://alternative.url/checkin";
1001 settings["gcm_hostname"] = "alternative.gcm.host";
1002 settings["gcm_secure_port"] = "7777";
1003 settings["gcm_registration_url"] = "http://alternative.url/registration";
1004 CompleteCheckin(kDeviceAndroidId,
1005 kDeviceSecurityToken,
1006 GServicesSettings::CalculateDigest(settings),
1007 settings);
1009 std::vector<GCMClient::AccountTokenInfo> account_tokens;
1010 account_tokens.push_back(MakeAccountToken("test_user1@gmail.com", "token1"));
1011 gcm_client()->SetAccountTokens(account_tokens);
1013 PumpLoopUntilIdle();
1014 CompleteCheckin(kDeviceAndroidId,
1015 kDeviceSecurityToken,
1016 GServicesSettings::CalculateDigest(settings),
1017 settings);
1019 std::set<std::string> accounts;
1020 accounts.insert("test_user1@gmail.com");
1021 EXPECT_EQ(accounts, device_checkin_info().last_checkin_accounts);
1023 // This should trigger another checkin, because the list of accounts is
1024 // different.
1025 account_tokens.clear();
1026 account_tokens.push_back(MakeAccountToken("test_user2@gmail.com", "token2"));
1027 gcm_client()->SetAccountTokens(account_tokens);
1029 PumpLoopUntilIdle();
1030 CompleteCheckin(kDeviceAndroidId,
1031 kDeviceSecurityToken,
1032 GServicesSettings::CalculateDigest(settings),
1033 settings);
1035 accounts.clear();
1036 accounts.insert("test_user2@gmail.com");
1037 EXPECT_EQ(accounts, device_checkin_info().last_checkin_accounts);
1038 EXPECT_TRUE(device_checkin_info().accounts_set);
1039 EXPECT_EQ(MakeEmailToTokenMap(account_tokens),
1040 device_checkin_info().account_tokens);
1043 class GCMClientImplStartAndStopTest : public GCMClientImplTest {
1044 public:
1045 GCMClientImplStartAndStopTest();
1046 ~GCMClientImplStartAndStopTest() override;
1048 void SetUp() override;
1050 void DefaultCompleteCheckin();
1053 GCMClientImplStartAndStopTest::GCMClientImplStartAndStopTest() {
1056 GCMClientImplStartAndStopTest::~GCMClientImplStartAndStopTest() {
1059 void GCMClientImplStartAndStopTest::SetUp() {
1060 testing::Test::SetUp();
1061 ASSERT_TRUE(CreateUniqueTempDir());
1062 InitializeLoop();
1063 BuildGCMClient(base::TimeDelta());
1064 InitializeGCMClient();
1067 void GCMClientImplStartAndStopTest::DefaultCompleteCheckin() {
1068 SetUpUrlFetcherFactory();
1069 CompleteCheckin(kDeviceAndroidId,
1070 kDeviceSecurityToken,
1071 std::string(),
1072 std::map<std::string, std::string>());
1073 PumpLoopUntilIdle();
1076 TEST_F(GCMClientImplStartAndStopTest, StartStopAndRestart) {
1077 // GCMClientImpl should be in INITIALIZED state at first.
1078 EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
1080 // Delay start the GCM.
1081 gcm_client()->Start(GCMClient::DELAYED_START);
1082 PumpLoopUntilIdle();
1083 EXPECT_EQ(GCMClientImpl::LOADED, gcm_client_state());
1085 // Stop the GCM.
1086 gcm_client()->Stop();
1087 PumpLoopUntilIdle();
1088 EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
1090 // Restart the GCM without delay.
1091 gcm_client()->Start(GCMClient::IMMEDIATE_START);
1092 PumpLoopUntilIdle();
1093 EXPECT_EQ(GCMClientImpl::INITIAL_DEVICE_CHECKIN, gcm_client_state());
1096 TEST_F(GCMClientImplStartAndStopTest, StartAndStopImmediately) {
1097 // GCMClientImpl should be in INITIALIZED state at first.
1098 EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
1100 // Delay start the GCM and then stop it immediately.
1101 gcm_client()->Start(GCMClient::DELAYED_START);
1102 gcm_client()->Stop();
1103 PumpLoopUntilIdle();
1104 EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
1106 // Start the GCM and then stop it immediately.
1107 gcm_client()->Start(GCMClient::IMMEDIATE_START);
1108 gcm_client()->Stop();
1109 PumpLoopUntilIdle();
1110 EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
1113 TEST_F(GCMClientImplStartAndStopTest, StartStopAndRestartImmediately) {
1114 // GCMClientImpl should be in INITIALIZED state at first.
1115 EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
1117 // Delay start the GCM and then stop and restart it immediately.
1118 gcm_client()->Start(GCMClient::DELAYED_START);
1119 gcm_client()->Stop();
1120 gcm_client()->Start(GCMClient::DELAYED_START);
1121 PumpLoopUntilIdle();
1122 EXPECT_EQ(GCMClientImpl::LOADED, gcm_client_state());
1124 // Start the GCM and then stop and restart it immediately.
1125 gcm_client()->Start(GCMClient::IMMEDIATE_START);
1126 gcm_client()->Stop();
1127 gcm_client()->Start(GCMClient::IMMEDIATE_START);
1128 PumpLoopUntilIdle();
1129 EXPECT_EQ(GCMClientImpl::INITIAL_DEVICE_CHECKIN, gcm_client_state());
1132 TEST_F(GCMClientImplStartAndStopTest, DelayStart) {
1133 // GCMClientImpl should be in INITIALIZED state at first.
1134 EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
1136 // Delay start the GCM.
1137 gcm_client()->Start(GCMClient::DELAYED_START);
1138 PumpLoopUntilIdle();
1139 EXPECT_EQ(GCMClientImpl::LOADED, gcm_client_state());
1141 // Start the GCM immediately and complete the checkin.
1142 gcm_client()->Start(GCMClient::IMMEDIATE_START);
1143 PumpLoopUntilIdle();
1144 EXPECT_EQ(GCMClientImpl::INITIAL_DEVICE_CHECKIN, gcm_client_state());
1145 DefaultCompleteCheckin();
1146 EXPECT_EQ(GCMClientImpl::READY, gcm_client_state());
1148 // Registration.
1149 std::vector<std::string> senders;
1150 senders.push_back("sender");
1151 gcm_client()->Register(kAppId, senders);
1152 CompleteRegistration("reg_id");
1153 EXPECT_EQ(GCMClientImpl::READY, gcm_client_state());
1155 // Stop the GCM.
1156 gcm_client()->Stop();
1157 PumpLoopUntilIdle();
1158 EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
1160 // Delay start the GCM. GCM is indeed started without delay because the
1161 // registration record has been found.
1162 gcm_client()->Start(GCMClient::DELAYED_START);
1163 PumpLoopUntilIdle();
1164 EXPECT_EQ(GCMClientImpl::READY, gcm_client_state());
1167 // Test for known account mappings and last token fetching time being passed
1168 // to OnGCMReady.
1169 TEST_F(GCMClientImplStartAndStopTest, OnGCMReadyAccountsAndTokenFetchingTime) {
1170 // Start the GCM and wait until it is ready.
1171 gcm_client()->Start(GCMClient::IMMEDIATE_START);
1172 PumpLoopUntilIdle();
1173 DefaultCompleteCheckin();
1175 base::Time expected_time = base::Time::Now();
1176 gcm_client()->SetLastTokenFetchTime(expected_time);
1177 AccountMapping expected_mapping;
1178 expected_mapping.account_id = "accId";
1179 expected_mapping.email = "email@gmail.com";
1180 expected_mapping.status = AccountMapping::MAPPED;
1181 expected_mapping.status_change_timestamp = expected_time;
1182 gcm_client()->UpdateAccountMapping(expected_mapping);
1183 PumpLoopUntilIdle();
1185 // Stop the GCM.
1186 gcm_client()->Stop();
1187 PumpLoopUntilIdle();
1189 // Restart the GCM.
1190 gcm_client()->Start(GCMClient::IMMEDIATE_START);
1191 PumpLoopUntilIdle();
1193 EXPECT_EQ(LOADING_COMPLETED, last_event());
1194 EXPECT_EQ(expected_time, last_token_fetch_time());
1195 ASSERT_EQ(1UL, last_account_mappings().size());
1196 const AccountMapping& actual_mapping = last_account_mappings()[0];
1197 EXPECT_EQ(expected_mapping.account_id, actual_mapping.account_id);
1198 EXPECT_EQ(expected_mapping.email, actual_mapping.email);
1199 EXPECT_EQ(expected_mapping.status, actual_mapping.status);
1200 EXPECT_EQ(expected_mapping.status_change_timestamp,
1201 actual_mapping.status_change_timestamp);
1204 } // namespace gcm