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

Side by Side 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, 2 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
« no previous file with comments | « no previous file | google_apis/gcm/engine/gcm_store_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/gcm_driver/gcm_client_impl.h" 5 #include "components/gcm_driver/gcm_client_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <initializer_list> 9 #include <initializer_list>
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/files/scoped_temp_dir.h" 15 #include "base/files/scoped_temp_dir.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/test/histogram_tester.h"
19 #include "base/test/test_mock_time_task_runner.h" 20 #include "base/test/test_mock_time_task_runner.h"
20 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
21 #include "base/time/clock.h" 22 #include "base/time/clock.h"
22 #include "base/timer/timer.h" 23 #include "base/timer/timer.h"
23 #include "google_apis/gcm/base/fake_encryptor.h" 24 #include "google_apis/gcm/base/fake_encryptor.h"
24 #include "google_apis/gcm/base/mcs_message.h" 25 #include "google_apis/gcm/base/mcs_message.h"
25 #include "google_apis/gcm/base/mcs_util.h" 26 #include "google_apis/gcm/base/mcs_util.h"
26 #include "google_apis/gcm/engine/fake_connection_factory.h" 27 #include "google_apis/gcm/engine/fake_connection_factory.h"
27 #include "google_apis/gcm/engine/fake_connection_handler.h" 28 #include "google_apis/gcm/engine/fake_connection_handler.h"
28 #include "google_apis/gcm/engine/gservices_settings.h" 29 #include "google_apis/gcm/engine/gservices_settings.h"
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 StartGCMClient(); 673 StartGCMClient();
673 ASSERT_NO_FATAL_FAILURE( 674 ASSERT_NO_FATAL_FAILURE(
674 CompleteCheckin(kDeviceAndroidId2, kDeviceSecurityToken2, std::string(), 675 CompleteCheckin(kDeviceAndroidId2, kDeviceSecurityToken2, std::string(),
675 std::map<std::string, std::string>())); 676 std::map<std::string, std::string>()));
676 677
677 EXPECT_EQ(LOADING_COMPLETED, last_event()); 678 EXPECT_EQ(LOADING_COMPLETED, last_event());
678 EXPECT_EQ(kDeviceAndroidId2, mcs_client()->last_android_id()); 679 EXPECT_EQ(kDeviceAndroidId2, mcs_client()->last_android_id());
679 EXPECT_EQ(kDeviceSecurityToken2, mcs_client()->last_security_token()); 680 EXPECT_EQ(kDeviceSecurityToken2, mcs_client()->last_security_token());
680 } 681 }
681 682
683 TEST_F(GCMClientImplTest, LoadingWithEmptyDirectory) {
684 // Close the GCM store.
685 gcm_client()->Stop();
686 PumpLoopUntilIdle();
687
688 // Make the store directory empty, to simulate a previous destroy store
689 // operation failing to delete the store directory.
690 ASSERT_TRUE(base::DeleteFile(gcm_store_path(), true /* recursive */));
691 ASSERT_TRUE(base::CreateDirectory(gcm_store_path()));
692
693 base::HistogramTester histogram_tester;
694
695 // Restart GCM client. The store should be considered to not exist.
696 BuildGCMClient(base::TimeDelta());
697 InitializeGCMClient();
698 gcm_client()->Start(GCMClient::DELAYED_START);
699 PumpLoopUntilIdle();
700 histogram_tester.ExpectUniqueSample("GCM.LoadStatus",
701 13 /* STORE_DOES_NOT_EXIST */, 1);
702 // Since the store does not exist, the database should not have been opened.
703 histogram_tester.ExpectTotalCount("GCM.Database.Open", 0);
704 // Without a store, DELAYED_START loading should only reach INITIALIZED state.
705 EXPECT_EQ(GCMClientImpl::INITIALIZED, gcm_client_state());
706
707 // The store directory should still exist (and be empty). If not, then the
708 // DELAYED_START load has probably reset the store, rather than leaving that
709 // to the next IMMEDIATE_START load as expected.
710 ASSERT_TRUE(base::DirectoryExists(gcm_store_path()));
711 ASSERT_FALSE(
712 base::PathExists(gcm_store_path().Append(FILE_PATH_LITERAL("CURRENT"))));
713
714 // IMMEDIATE_START loading should successfully create a new store despite the
715 // empty directory.
716 reset_last_event();
717 StartGCMClient();
718 ASSERT_NO_FATAL_FAILURE(
719 CompleteCheckin(kDeviceAndroidId2, kDeviceSecurityToken2, std::string(),
720 std::map<std::string, std::string>()));
721 EXPECT_EQ(LOADING_COMPLETED, last_event());
722 EXPECT_EQ(GCMClientImpl::READY, gcm_client_state());
723 EXPECT_EQ(kDeviceAndroidId2, mcs_client()->last_android_id());
724 EXPECT_EQ(kDeviceSecurityToken2, mcs_client()->last_security_token());
725 }
726
682 TEST_F(GCMClientImplTest, DestroyStoreWhenNotNeeded) { 727 TEST_F(GCMClientImplTest, DestroyStoreWhenNotNeeded) {
683 // Close the GCM store. 728 // Close the GCM store.
684 gcm_client()->Stop(); 729 gcm_client()->Stop();
685 PumpLoopUntilIdle(); 730 PumpLoopUntilIdle();
686 731
687 // Restart GCM client. The store is loaded successfully. 732 // Restart GCM client. The store is loaded successfully.
688 reset_last_event(); 733 reset_last_event();
689 BuildGCMClient(base::TimeDelta()); 734 BuildGCMClient(base::TimeDelta());
690 InitializeGCMClient(); 735 InitializeGCMClient();
691 gcm_client()->Start(GCMClient::DELAYED_START); 736 gcm_client()->Start(GCMClient::DELAYED_START);
(...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 ReceiveMessageFromMCS(message); 1873 ReceiveMessageFromMCS(message);
1829 1874
1830 EXPECT_EQ(MESSAGE_RECEIVED, last_event()); 1875 EXPECT_EQ(MESSAGE_RECEIVED, last_event());
1831 EXPECT_EQ(kExtensionAppId, last_app_id()); 1876 EXPECT_EQ(kExtensionAppId, last_app_id());
1832 EXPECT_EQ(expected_data.size(), last_message().data.size()); 1877 EXPECT_EQ(expected_data.size(), last_message().data.size());
1833 EXPECT_EQ(expected_data, last_message().data); 1878 EXPECT_EQ(expected_data, last_message().data);
1834 EXPECT_EQ(kSender, last_message().sender_id); 1879 EXPECT_EQ(kSender, last_message().sender_id);
1835 } 1880 }
1836 1881
1837 } // namespace gcm 1882 } // namespace gcm
OLDNEW
« 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