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

Side by Side Diff: google_apis/gcm/engine/gcm_store_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 | « google_apis/gcm/engine/gcm_store_impl.cc ('k') | no next file » | 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 "google_apis/gcm/engine/gcm_store_impl.h" 5 #include "google_apis/gcm/engine/gcm_store_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
17 #include "base/files/file_util.h"
17 #include "base/files/scoped_temp_dir.h" 18 #include "base/files/scoped_temp_dir.h"
18 #include "base/memory/ptr_util.h" 19 #include "base/memory/ptr_util.h"
19 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
20 #include "base/test/test_simple_task_runner.h" 21 #include "base/test/test_simple_task_runner.h"
21 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
22 #include "google_apis/gcm/base/fake_encryptor.h" 23 #include "google_apis/gcm/base/fake_encryptor.h"
23 #include "google_apis/gcm/base/mcs_message.h" 24 #include "google_apis/gcm/base/mcs_message.h"
24 #include "google_apis/gcm/base/mcs_util.h" 25 #include "google_apis/gcm/base/mcs_util.h"
25 #include "google_apis/gcm/protocol/mcs.pb.h" 26 #include "google_apis/gcm/protocol/mcs.pb.h"
26 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 std::unique_ptr<GCMStore::LoadResult> result); 63 std::unique_ptr<GCMStore::LoadResult> result);
63 void LoadWithoutCheckCallback( 64 void LoadWithoutCheckCallback(
64 std::unique_ptr<GCMStore::LoadResult>* result_dst, 65 std::unique_ptr<GCMStore::LoadResult>* result_dst,
65 std::unique_ptr<GCMStore::LoadResult> result); 66 std::unique_ptr<GCMStore::LoadResult> result);
66 void UpdateCallback(bool success); 67 void UpdateCallback(bool success);
67 68
68 protected: 69 protected:
69 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 70 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
70 base::ThreadTaskRunnerHandle task_runner_handle_; 71 base::ThreadTaskRunnerHandle task_runner_handle_;
71 base::ScopedTempDir temp_directory_; 72 base::ScopedTempDir temp_directory_;
73 base::FilePath store_path_;
72 bool expected_success_; 74 bool expected_success_;
73 uint64_t next_persistent_id_; 75 uint64_t next_persistent_id_;
74 }; 76 };
75 77
76 GCMStoreImplTest::GCMStoreImplTest() 78 GCMStoreImplTest::GCMStoreImplTest()
77 : task_runner_(new base::TestSimpleTaskRunner()), 79 : task_runner_(new base::TestSimpleTaskRunner()),
78 task_runner_handle_(task_runner_), 80 task_runner_handle_(task_runner_),
79 expected_success_(true), 81 expected_success_(true),
80 next_persistent_id_(base::Time::Now().ToInternalValue()) { 82 next_persistent_id_(base::Time::Now().ToInternalValue()) {
81 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir()); 83 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir());
82 } 84 }
83 85
84 GCMStoreImplTest::~GCMStoreImplTest() {} 86 GCMStoreImplTest::~GCMStoreImplTest() {}
85 87
86 std::unique_ptr<GCMStoreImpl> GCMStoreImplTest::BuildGCMStore() { 88 std::unique_ptr<GCMStoreImpl> GCMStoreImplTest::BuildGCMStore() {
87 return std::unique_ptr<GCMStoreImpl>(new GCMStoreImpl( 89 // Pass an non-existent directory as store path to match the exact behavior in
88 // Pass an non-existent directory as store path to match the exact 90 // the production code. Currently GCMStoreImpl checks if the directory exists
89 // behavior in the production code. Currently GCMStoreImpl checks if 91 // and contains a CURRENT file to determine the store existence.
90 // the directory exist or not to determine the store existence. 92 store_path_ =
91 temp_directory_.GetPath().Append(FILE_PATH_LITERAL("GCM Store")), 93 temp_directory_.GetPath().Append(FILE_PATH_LITERAL("GCM Store"));
92 task_runner_, base::WrapUnique<Encryptor>(new FakeEncryptor))); 94 return std::unique_ptr<GCMStoreImpl>(
95 new GCMStoreImpl(store_path_, task_runner_,
96 base::WrapUnique<Encryptor>(new FakeEncryptor)));
93 } 97 }
94 98
95 void GCMStoreImplTest::LoadGCMStore( 99 void GCMStoreImplTest::LoadGCMStore(
96 GCMStoreImpl* gcm_store, 100 GCMStoreImpl* gcm_store,
97 std::unique_ptr<GCMStore::LoadResult>* result_dst) { 101 std::unique_ptr<GCMStore::LoadResult>* result_dst) {
98 gcm_store->Load( 102 gcm_store->Load(
99 GCMStore::CREATE_IF_MISSING, 103 GCMStore::CREATE_IF_MISSING,
100 base::Bind(&GCMStoreImplTest::LoadCallback, 104 base::Bind(&GCMStoreImplTest::LoadCallback,
101 base::Unretained(this), 105 base::Unretained(this),
102 result_dst)); 106 result_dst));
(...skipping 30 matching lines...) Expand all
133 LoadGCMStore(gcm_store.get(), &load_result); 137 LoadGCMStore(gcm_store.get(), &load_result);
134 138
135 EXPECT_EQ(0U, load_result->device_android_id); 139 EXPECT_EQ(0U, load_result->device_android_id);
136 EXPECT_EQ(0U, load_result->device_security_token); 140 EXPECT_EQ(0U, load_result->device_security_token);
137 EXPECT_TRUE(load_result->incoming_messages.empty()); 141 EXPECT_TRUE(load_result->incoming_messages.empty());
138 EXPECT_TRUE(load_result->outgoing_messages.empty()); 142 EXPECT_TRUE(load_result->outgoing_messages.empty());
139 EXPECT_TRUE(load_result->gservices_settings.empty()); 143 EXPECT_TRUE(load_result->gservices_settings.empty());
140 EXPECT_EQ(base::Time::FromInternalValue(0LL), load_result->last_checkin_time); 144 EXPECT_EQ(base::Time::FromInternalValue(0LL), load_result->last_checkin_time);
141 } 145 }
142 146
143 // Verify new database is not created when DO_NOT_CREATE_NEW_STORE is passed. 147 // Verify new database is not created when DO_NOT_CREATE is passed.
144 TEST_F(GCMStoreImplTest, LoadWithoutCreatingNewStore) { 148 TEST_F(GCMStoreImplTest, LoadWithoutCreatingNewStore) {
145 std::unique_ptr<GCMStoreImpl> gcm_store(BuildGCMStore()); 149 std::unique_ptr<GCMStoreImpl> gcm_store(BuildGCMStore());
146 std::unique_ptr<GCMStore::LoadResult> load_result; 150 std::unique_ptr<GCMStore::LoadResult> load_result;
147 gcm_store->Load( 151 gcm_store->Load(GCMStore::DO_NOT_CREATE,
148 GCMStore::DO_NOT_CREATE, 152 base::Bind(&GCMStoreImplTest::LoadWithoutCheckCallback,
149 base::Bind(&GCMStoreImplTest::LoadWithoutCheckCallback, 153 base::Unretained(this), &load_result));
150 base::Unretained(this),
151 &load_result));
152 PumpLoop(); 154 PumpLoop();
153 155
154 EXPECT_FALSE(load_result->success); 156 EXPECT_FALSE(load_result->success);
157 EXPECT_TRUE(load_result->store_does_not_exist);
158 }
159
160 // Verifies that loads with DO_NOT_CREATE set store_does_not_exist to true when
161 // an empty directory was left behind after destroying the database.
162 TEST_F(GCMStoreImplTest, LoadWithEmptyDirectory) {
163 std::unique_ptr<GCMStoreImpl> gcm_store(BuildGCMStore());
164
165 // Create an empty directory at the store path, to simulate an empty directory
166 // being left behind after destroying a previous store.
167 ASSERT_TRUE(base::CreateDirectory(store_path_));
168
169 std::unique_ptr<GCMStore::LoadResult> load_result;
170 gcm_store->Load(GCMStore::DO_NOT_CREATE,
171 base::Bind(&GCMStoreImplTest::LoadWithoutCheckCallback,
172 base::Unretained(this), &load_result));
173 PumpLoop();
174
175 EXPECT_FALSE(load_result->success);
155 EXPECT_TRUE(load_result->store_does_not_exist); 176 EXPECT_TRUE(load_result->store_does_not_exist);
156 } 177 }
157 178
158 TEST_F(GCMStoreImplTest, DeviceCredentials) { 179 TEST_F(GCMStoreImplTest, DeviceCredentials) {
159 std::unique_ptr<GCMStoreImpl> gcm_store(BuildGCMStore()); 180 std::unique_ptr<GCMStoreImpl> gcm_store(BuildGCMStore());
160 std::unique_ptr<GCMStore::LoadResult> load_result; 181 std::unique_ptr<GCMStore::LoadResult> load_result;
161 LoadGCMStore(gcm_store.get(), &load_result); 182 LoadGCMStore(gcm_store.get(), &load_result);
162 183
163 gcm_store->SetDeviceCredentials( 184 gcm_store->SetDeviceCredentials(
164 kDeviceId, 185 kDeviceId,
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 754
734 ASSERT_EQ(1u, load_result->instance_id_data.size()); 755 ASSERT_EQ(1u, load_result->instance_id_data.size());
735 ASSERT_TRUE(load_result->instance_id_data.find(kAppName2) != 756 ASSERT_TRUE(load_result->instance_id_data.find(kAppName2) !=
736 load_result->instance_id_data.end()); 757 load_result->instance_id_data.end());
737 EXPECT_EQ(instance_id_data2, load_result->instance_id_data[kAppName2]); 758 EXPECT_EQ(instance_id_data2, load_result->instance_id_data[kAppName2]);
738 } 759 }
739 760
740 } // namespace 761 } // namespace
741 762
742 } // namespace gcm 763 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/engine/gcm_store_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698