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

Side by Side Diff: google_apis/gcm/engine/gcm_store_impl_unittest.cc

Issue 1121003003: [GCM] Adding handling of heartbeat intervals to the GCM store. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@heartbeat-gcm
Patch Set: Adding histrograms Created 5 years, 7 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 unified diff | Download patch
OLDNEW
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 "google_apis/gcm/engine/gcm_store_impl.h" 5 #include "google_apis/gcm/engine/gcm_store_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 iter = load_result->account_mappings.begin(); 603 iter = load_result->account_mappings.begin();
604 EXPECT_EQ(account_mapping2.account_id, iter->account_id); 604 EXPECT_EQ(account_mapping2.account_id, iter->account_id);
605 EXPECT_EQ(account_mapping2.email, iter->email); 605 EXPECT_EQ(account_mapping2.email, iter->email);
606 EXPECT_TRUE(iter->access_token.empty()); 606 EXPECT_TRUE(iter->access_token.empty());
607 EXPECT_EQ(AccountMapping::REMOVING, iter->status); 607 EXPECT_EQ(AccountMapping::REMOVING, iter->status);
608 EXPECT_EQ(account_mapping2.status_change_timestamp, 608 EXPECT_EQ(account_mapping2.status_change_timestamp,
609 iter->status_change_timestamp); 609 iter->status_change_timestamp);
610 EXPECT_EQ(account_mapping2.last_message_id, iter->last_message_id); 610 EXPECT_EQ(account_mapping2.last_message_id, iter->last_message_id);
611 } 611 }
612 612
613 TEST_F(GCMStoreImplTest, HeartbeatInterval) {
614 scoped_ptr<GCMStore> gcm_store(BuildGCMStore());
615 scoped_ptr<GCMStore::LoadResult> load_result;
616 gcm_store->Load(base::Bind(
617 &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
618
619 std::string scope1 = "scope1";
620 std::string scope2 = "scope2";
621 int heartbeat1 = 120 * 1000;
622 int heartbeat2 = 360 * 1000;
623
624 gcm_store->AddHeartbeatInterval(
625 scope1,
626 heartbeat1,
627 base::Bind(&GCMStoreImplTest::UpdateCallback, base::Unretained(this)));
628 PumpLoop();
629 gcm_store->AddHeartbeatInterval(
630 scope2,
631 heartbeat2,
632 base::Bind(&GCMStoreImplTest::UpdateCallback, base::Unretained(this)));
633 PumpLoop();
634
635 gcm_store = BuildGCMStore().Pass();
636 gcm_store->Load(base::Bind(
637 &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
638 PumpLoop();
639
640 EXPECT_EQ(2UL, load_result->heartbeat_intervals.size());
641 ASSERT_TRUE(load_result->heartbeat_intervals.find(scope1) !=
642 load_result->heartbeat_intervals.end());
643 EXPECT_EQ(heartbeat1, load_result->heartbeat_intervals[scope1]);
644 ASSERT_TRUE(load_result->heartbeat_intervals.find(scope2) !=
645 load_result->heartbeat_intervals.end());
646 EXPECT_EQ(heartbeat2, load_result->heartbeat_intervals[scope2]);
647
648 gcm_store->RemoveHeartbeatInterval(
649 scope2,
650 base::Bind(&GCMStoreImplTest::UpdateCallback, base::Unretained(this)));
651 PumpLoop();
652
653 gcm_store = BuildGCMStore().Pass();
654 gcm_store->Load(base::Bind(
655 &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
656 PumpLoop();
657
658 EXPECT_EQ(1UL, load_result->heartbeat_intervals.size());
659 ASSERT_TRUE(load_result->heartbeat_intervals.find(scope1) !=
660 load_result->heartbeat_intervals.end());
661 EXPECT_EQ(heartbeat1, load_result->heartbeat_intervals[scope1]);
662 }
663
613 // When the database is destroyed, all database updates should fail. At the 664 // When the database is destroyed, all database updates should fail. At the
614 // same time, they per-app message counts should not go up, as failures should 665 // same time, they per-app message counts should not go up, as failures should
615 // result in decrementing the counts. 666 // result in decrementing the counts.
616 TEST_F(GCMStoreImplTest, AddMessageAfterDestroy) { 667 TEST_F(GCMStoreImplTest, AddMessageAfterDestroy) {
617 scoped_ptr<GCMStore> gcm_store(BuildGCMStore()); 668 scoped_ptr<GCMStore> gcm_store(BuildGCMStore());
618 scoped_ptr<GCMStore::LoadResult> load_result; 669 scoped_ptr<GCMStore::LoadResult> load_result;
619 gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback, 670 gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback,
620 base::Unretained(this), 671 base::Unretained(this),
621 &load_result)); 672 &load_result));
622 PumpLoop(); 673 PumpLoop();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 gcm_store = BuildGCMStore().Pass(); 737 gcm_store = BuildGCMStore().Pass();
687 gcm_store->Load(base::Bind( 738 gcm_store->Load(base::Bind(
688 &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result)); 739 &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
689 PumpLoop(); 740 PumpLoop();
690 EXPECT_EQ(base::Time(), load_result->last_token_fetch_time); 741 EXPECT_EQ(base::Time(), load_result->last_token_fetch_time);
691 } 742 }
692 743
693 } // namespace 744 } // namespace
694 745
695 } // namespace gcm 746 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698