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

Unified Diff: components/gcm_driver/gcm_client_impl_unittest.cc

Issue 2380003002: GCM Store: Fix invalid argument errors (Closed)
Patch Set: Fix Win compile with FILE_PATH_LITERAL Created 4 years, 3 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
« no previous file with comments | « no previous file | google_apis/gcm/engine/gcm_store_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4a17c9543e6f3dfb42ae2da234149b928afc168a..f4e040d86f18901c38ba4a898b91f1c08ef6dde0 100644
--- a/components/gcm_driver/gcm_client_impl_unittest.cc
+++ b/components/gcm_driver/gcm_client_impl_unittest.cc
@@ -16,6 +16,7 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
+#include "base/test/histogram_tester.h"
#include "base/test/test_mock_time_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/clock.h"
@@ -679,6 +680,50 @@ TEST_F(GCMClientImplTest, LoadingBusted) {
EXPECT_EQ(kDeviceSecurityToken2, mcs_client()->last_security_token());
}
+TEST_F(GCMClientImplTest, LoadingWithEmptyDirectory) {
+ // Close the GCM store.
+ gcm_client()->Stop();
+ PumpLoopUntilIdle();
+
+ // Make the store directory empty, to simulate a previous destroy store
+ // operation failing to delete the store directory.
+ ASSERT_TRUE(base::DeleteFile(gcm_store_path(), true /* recursive */));
+ ASSERT_TRUE(base::CreateDirectory(gcm_store_path()));
+
+ base::HistogramTester histogram_tester;
+
+ // Restart GCM client. The store should be considered to not exist.
+ BuildGCMClient(base::TimeDelta());
+ InitializeGCMClient();
+ gcm_client()->Start(GCMClient::DELAYED_START);
+ PumpLoopUntilIdle();
+ histogram_tester.ExpectUniqueSample("GCM.LoadStatus",
+ 13 /* STORE_DOES_NOT_EXIST */, 1);
+ // Since the store does not exist, the database should not have been opened.
+ histogram_tester.ExpectTotalCount("GCM.Database.Open", 0);
+ // Without a store, DELAYED_START loading should only reach INITIALIZED state.
+ EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
+
+ // The store directory should still exist (and be empty). If not, then the
+ // DELAYED_START load has probably reset the store, rather than leaving that
+ // to the next IMMEDIATE_START load as expected.
+ ASSERT_TRUE(base::DirectoryExists(gcm_store_path()));
+ ASSERT_FALSE(
+ base::PathExists(gcm_store_path().Append(FILE_PATH_LITERAL("CURRENT"))));
+
+ // IMMEDIATE_START loading should successfully create a new store despite the
+ // empty directory.
+ reset_last_event();
+ StartGCMClient();
+ ASSERT_NO_FATAL_FAILURE(
+ CompleteCheckin(kDeviceAndroidId2, kDeviceSecurityToken2, std::string(),
+ std::map<std::string, std::string>()));
+ EXPECT_EQ(LOADING_COMPLETED, last_event());
+ EXPECT_EQ(GCMClientImpl::READY, gcm_client_state());
+ EXPECT_EQ(kDeviceAndroidId2, mcs_client()->last_android_id());
+ EXPECT_EQ(kDeviceSecurityToken2, mcs_client()->last_security_token());
+}
+
TEST_F(GCMClientImplTest, DestroyStoreWhenNotNeeded) {
// Close the GCM store.
gcm_client()->Stop();
« no previous file with comments | « no previous file | google_apis/gcm/engine/gcm_store_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698