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

Unified Diff: components/gcm_driver/gcm_client_impl_unittest.cc

Issue 1183843002: Do not create GCM store if it is not needed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix trybots Created 5 years, 6 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_client_impl_unittest.cc
diff --git a/components/gcm_driver/gcm_client_impl_unittest.cc b/components/gcm_driver/gcm_client_impl_unittest.cc
index fc578e1d693bb70f4d2705ed55c099f0b67496ea..9fd7f8a16671acd51dbb00fd0c96922ee2c1ab14 100644
--- a/components/gcm_driver/gcm_client_impl_unittest.cc
+++ b/components/gcm_driver/gcm_client_impl_unittest.cc
@@ -524,10 +524,16 @@ void GCMClientImplTest::InitializeGCMClient() {
// Actual initialization.
GCMClient::ChromeBuildInfo chrome_build_info;
chrome_build_info.version = kChromeVersion;
- gcm_client_->Initialize(chrome_build_info, temp_directory_.path(),
- message_loop_.task_runner(),
- url_request_context_getter_,
- make_scoped_ptr<Encryptor>(new FakeEncryptor), this);
+ gcm_client_->Initialize(
+ chrome_build_info,
+ // Pass an non-existent directory as store path to match the exact
+ // behavior in the production code. Currently GCMStoreImpl checks if
+ // the directory exist or not to determine the store existence.
+ temp_directory_.path().Append(FILE_PATH_LITERAL("GCM Store")),
+ message_loop_.task_runner(),
+ url_request_context_getter_,
+ make_scoped_ptr<Encryptor>(new FakeEncryptor),
+ this);
}
void GCMClientImplTest::StartGCMClient() {
@@ -1107,7 +1113,7 @@ TEST_F(GCMClientImplStartAndStopTest, StartStopAndRestart) {
// Delay start the GCM.
gcm_client()->Start(GCMClient::DELAYED_START);
PumpLoopUntilIdle();
- EXPECT_EQ(GCMClientImpl::LOADED, gcm_client_state());
+ EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
// Stop the GCM.
gcm_client()->Stop();
@@ -1120,7 +1126,7 @@ TEST_F(GCMClientImplStartAndStopTest, StartStopAndRestart) {
EXPECT_EQ(GCMClientImpl::INITIAL_DEVICE_CHECKIN, gcm_client_state());
}
-TEST_F(GCMClientImplStartAndStopTest, StartAndStopImmediately) {
+TEST_F(GCMClientImplStartAndStopTest, DelayedStartAndStopImmediately) {
// GCMClientImpl should be in INITIALIZED state at first.
EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
@@ -1129,6 +1135,11 @@ TEST_F(GCMClientImplStartAndStopTest, StartAndStopImmediately) {
gcm_client()->Stop();
PumpLoopUntilIdle();
EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
+}
+
+TEST_F(GCMClientImplStartAndStopTest, ImmediateStartAndStopImmediately) {
+ // GCMClientImpl should be in INITIALIZED state at first.
+ EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
// Start the GCM and then stop it immediately.
gcm_client()->Start(GCMClient::IMMEDIATE_START);
@@ -1137,7 +1148,7 @@ TEST_F(GCMClientImplStartAndStopTest, StartAndStopImmediately) {
EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
}
-TEST_F(GCMClientImplStartAndStopTest, StartStopAndRestartImmediately) {
+TEST_F(GCMClientImplStartAndStopTest, DelayedStartStopAndRestart) {
// GCMClientImpl should be in INITIALIZED state at first.
EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
@@ -1146,7 +1157,12 @@ TEST_F(GCMClientImplStartAndStopTest, StartStopAndRestartImmediately) {
gcm_client()->Stop();
gcm_client()->Start(GCMClient::DELAYED_START);
PumpLoopUntilIdle();
- EXPECT_EQ(GCMClientImpl::LOADED, gcm_client_state());
+ EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
+}
+
+TEST_F(GCMClientImplStartAndStopTest, ImmediateStartStopAndRestart) {
+ // GCMClientImpl should be in INITIALIZED state at first.
+ EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
// Start the GCM and then stop and restart it immediately.
gcm_client()->Start(GCMClient::IMMEDIATE_START);
@@ -1156,14 +1172,63 @@ TEST_F(GCMClientImplStartAndStopTest, StartStopAndRestartImmediately) {
EXPECT_EQ(GCMClientImpl::INITIAL_DEVICE_CHECKIN, gcm_client_state());
}
-TEST_F(GCMClientImplStartAndStopTest, DelayStart) {
+TEST_F(GCMClientImplStartAndStopTest, ImmediateStartAndThenImmediateStart) {
// GCMClientImpl should be in INITIALIZED state at first.
EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
- // Delay start the GCM.
+ // Start the GCM immediately and complete the checkin.
+ gcm_client()->Start(GCMClient::IMMEDIATE_START);
+ PumpLoopUntilIdle();
+ EXPECT_EQ(GCMClientImpl::INITIAL_DEVICE_CHECKIN, gcm_client_state());
+ DefaultCompleteCheckin();
+ EXPECT_EQ(GCMClientImpl::READY, gcm_client_state());
+
+ // Stop the GCM.
+ gcm_client()->Stop();
+ PumpLoopUntilIdle();
+ EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
+
+ // Start the GCM immediately. GCMClientImpl should be in READY state.
+ BuildGCMClient(base::TimeDelta());
+ InitializeGCMClient();
+ gcm_client()->Start(GCMClient::IMMEDIATE_START);
+ PumpLoopUntilIdle();
+ EXPECT_EQ(GCMClientImpl::READY, gcm_client_state());
+}
+
+TEST_F(GCMClientImplStartAndStopTest, ImmediateStartAndThenDelayStart) {
+ // GCMClientImpl should be in INITIALIZED state at first.
+ EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
+
+ // Start the GCM immediately and complete the checkin.
+ gcm_client()->Start(GCMClient::IMMEDIATE_START);
+ PumpLoopUntilIdle();
+ EXPECT_EQ(GCMClientImpl::INITIAL_DEVICE_CHECKIN, gcm_client_state());
+ DefaultCompleteCheckin();
+ EXPECT_EQ(GCMClientImpl::READY, gcm_client_state());
+
+ // Stop the GCM.
+ gcm_client()->Stop();
+ PumpLoopUntilIdle();
+ EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
+
+ // Delay start the GCM. GCMClientImpl should be in LOADED state.
+ BuildGCMClient(base::TimeDelta());
+ InitializeGCMClient();
gcm_client()->Start(GCMClient::DELAYED_START);
PumpLoopUntilIdle();
EXPECT_EQ(GCMClientImpl::LOADED, gcm_client_state());
+}
+
+TEST_F(GCMClientImplStartAndStopTest, DelayedStart) {
+ // GCMClientImpl should be in INITIALIZED state at first.
+ EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
+
+ // Delay start the GCM. The store will not be loaded and GCMClientImpl should
+ // still be in INITIALIZED state.
+ gcm_client()->Start(GCMClient::DELAYED_START);
+ PumpLoopUntilIdle();
+ EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
// Start the GCM immediately and complete the checkin.
gcm_client()->Start(GCMClient::IMMEDIATE_START);
@@ -1175,7 +1240,7 @@ TEST_F(GCMClientImplStartAndStopTest, DelayStart) {
// Registration.
std::vector<std::string> senders;
senders.push_back("sender");
- Register(kAppId, senders);
+ Register(kAppId, senders);
CompleteRegistration("reg_id");
EXPECT_EQ(GCMClientImpl::READY, gcm_client_state());
@@ -1186,6 +1251,8 @@ TEST_F(GCMClientImplStartAndStopTest, DelayStart) {
// Delay start the GCM. GCM is indeed started without delay because the
// registration record has been found.
+ BuildGCMClient(base::TimeDelta());
+ InitializeGCMClient();
gcm_client()->Start(GCMClient::DELAYED_START);
PumpLoopUntilIdle();
EXPECT_EQ(GCMClientImpl::READY, gcm_client_state());

Powered by Google App Engine
This is Rietveld 408576698