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

Side by Side Diff: chrome/browser/chromeos/drive/drive_resource_metadata_unittest.cc

Issue 12706012: chromeos: Destruct DriveResourceMetadata on the blocking pool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add note Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/drive/drive_resource_metadata.h" 5 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 96
97 scoped_refptr<base::SequencedWorkerPool> pool = 97 scoped_refptr<base::SequencedWorkerPool> pool =
98 content::BrowserThread::GetBlockingPool(); 98 content::BrowserThread::GetBlockingPool();
99 blocking_task_runner_ = 99 blocking_task_runner_ =
100 pool->GetSequencedTaskRunner(pool->GetSequenceToken()); 100 pool->GetSequencedTaskRunner(pool->GetSequenceToken());
101 resource_metadata_.reset(new DriveResourceMetadata(kTestRootResourceId, 101 resource_metadata_.reset(new DriveResourceMetadata(kTestRootResourceId,
102 blocking_task_runner_)); 102 blocking_task_runner_));
103 Init(resource_metadata_.get()); 103 Init(resource_metadata_.get());
104 } 104 }
105 105
106 virtual void TearDown() OVERRIDE {
107 resource_metadata_.reset();
108 }
109
106 // Gets the entry info by path synchronously. Returns NULL on failure. 110 // Gets the entry info by path synchronously. Returns NULL on failure.
107 scoped_ptr<DriveEntryProto> GetEntryInfoByPathSync( 111 scoped_ptr<DriveEntryProto> GetEntryInfoByPathSync(
108 const base::FilePath& file_path) { 112 const base::FilePath& file_path) {
109 DriveFileError error = DRIVE_FILE_OK; 113 DriveFileError error = DRIVE_FILE_OK;
110 scoped_ptr<DriveEntryProto> entry_proto; 114 scoped_ptr<DriveEntryProto> entry_proto;
111 resource_metadata_->GetEntryInfoByPath( 115 resource_metadata_->GetEntryInfoByPath(
112 file_path, 116 file_path,
113 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, 117 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback,
114 &error, &entry_proto)); 118 &error, &entry_proto));
115 google_apis::test_util::RunBlockingPoolTask(); 119 google_apis::test_util::RunBlockingPoolTask();
(...skipping 16 matching lines...) Expand all
132 return entries.Pass(); 136 return entries.Pass();
133 } 137 }
134 138
135 bool ParseMetadataFromString(DriveResourceMetadata* resource_metadata, 139 bool ParseMetadataFromString(DriveResourceMetadata* resource_metadata,
136 const std::string& serialized_proto) { 140 const std::string& serialized_proto) {
137 return resource_metadata->ParseFromString(serialized_proto); 141 return resource_metadata->ParseFromString(serialized_proto);
138 } 142 }
139 143
140 base::ScopedTempDir temp_dir_; 144 base::ScopedTempDir temp_dir_;
141 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 145 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
142 scoped_ptr<DriveResourceMetadata> resource_metadata_; 146 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests>
147 resource_metadata_;
143 148
144 private: 149 private:
145 MessageLoopForUI message_loop_; 150 MessageLoopForUI message_loop_;
146 content::TestBrowserThread ui_thread_; 151 content::TestBrowserThread ui_thread_;
147 }; 152 };
148 153
149 // static 154 // static
150 void DriveResourceMetadataTest::Init(DriveResourceMetadata* resource_metadata) { 155 void DriveResourceMetadataTest::Init(DriveResourceMetadata* resource_metadata) {
151 int sequence_id = 1; 156 int sequence_id = 1;
152 ASSERT_TRUE(AddDriveEntryProto( 157 ASSERT_TRUE(AddDriveEntryProto(
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 TEST_F(DriveResourceMetadataTest, VersionCheck) { 238 TEST_F(DriveResourceMetadataTest, VersionCheck) {
234 // Set up the root directory. 239 // Set up the root directory.
235 DriveRootDirectoryProto proto; 240 DriveRootDirectoryProto proto;
236 DriveEntryProto* mutable_entry = 241 DriveEntryProto* mutable_entry =
237 proto.mutable_drive_directory()->mutable_drive_entry(); 242 proto.mutable_drive_directory()->mutable_drive_entry();
238 mutable_entry->mutable_file_info()->set_is_directory(true); 243 mutable_entry->mutable_file_info()->set_is_directory(true);
239 mutable_entry->set_resource_id(kTestRootResourceId); 244 mutable_entry->set_resource_id(kTestRootResourceId);
240 mutable_entry->set_upload_url(kResumableCreateMediaUrl); 245 mutable_entry->set_upload_url(kResumableCreateMediaUrl);
241 mutable_entry->set_title("drive"); 246 mutable_entry->set_title("drive");
242 247
243 DriveResourceMetadata resource_metadata(kTestRootResourceId, 248 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests>
244 blocking_task_runner_); 249 resource_metadata(new DriveResourceMetadata(kTestRootResourceId,
250 blocking_task_runner_));
245 251
246 std::string serialized_proto; 252 std::string serialized_proto;
247 EXPECT_TRUE(proto.SerializeToString(&serialized_proto)); 253 EXPECT_TRUE(proto.SerializeToString(&serialized_proto));
248 // This should fail as the version is empty. 254 // This should fail as the version is empty.
249 EXPECT_FALSE(ParseMetadataFromString(&resource_metadata, serialized_proto)); 255 EXPECT_FALSE(ParseMetadataFromString(resource_metadata.get(),
256 serialized_proto));
250 257
251 // Set an older version, and serialize. 258 // Set an older version, and serialize.
252 proto.set_version(kProtoVersion - 1); 259 proto.set_version(kProtoVersion - 1);
253 EXPECT_TRUE(proto.SerializeToString(&serialized_proto)); 260 EXPECT_TRUE(proto.SerializeToString(&serialized_proto));
254 // This should fail as the version is older. 261 // This should fail as the version is older.
255 EXPECT_FALSE(ParseMetadataFromString(&resource_metadata, serialized_proto)); 262 EXPECT_FALSE(ParseMetadataFromString(resource_metadata.get(),
263 serialized_proto));
256 264
257 // Set the current version, and serialize. 265 // Set the current version, and serialize.
258 proto.set_version(kProtoVersion); 266 proto.set_version(kProtoVersion);
259 EXPECT_TRUE(proto.SerializeToString(&serialized_proto)); 267 EXPECT_TRUE(proto.SerializeToString(&serialized_proto));
260 // This should succeed as the version matches the current number. 268 // This should succeed as the version matches the current number.
261 EXPECT_TRUE(ParseMetadataFromString(&resource_metadata, serialized_proto)); 269 EXPECT_TRUE(ParseMetadataFromString(resource_metadata.get(),
270 serialized_proto));
262 271
263 // Set a newer version, and serialize. 272 // Set a newer version, and serialize.
264 proto.set_version(kProtoVersion + 1); 273 proto.set_version(kProtoVersion + 1);
265 EXPECT_TRUE(proto.SerializeToString(&serialized_proto)); 274 EXPECT_TRUE(proto.SerializeToString(&serialized_proto));
266 // This should fail as the version is newer. 275 // This should fail as the version is newer.
267 EXPECT_FALSE(ParseMetadataFromString(&resource_metadata, serialized_proto)); 276 EXPECT_FALSE(ParseMetadataFromString(resource_metadata.get(),
277 serialized_proto));
268 } 278 }
269 279
270 TEST_F(DriveResourceMetadataTest, LargestChangestamp) { 280 TEST_F(DriveResourceMetadataTest, LargestChangestamp) {
271 DriveResourceMetadata resource_metadata(kTestRootResourceId, 281 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests>
272 blocking_task_runner_); 282 resource_metadata(new DriveResourceMetadata(kTestRootResourceId,
283 blocking_task_runner_));
273 284
274 int64 in_changestamp = 123456; 285 int64 in_changestamp = 123456;
275 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 286 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
276 resource_metadata.SetLargestChangestamp( 287 resource_metadata->SetLargestChangestamp(
277 in_changestamp, 288 in_changestamp,
278 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, 289 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback,
279 &error)); 290 &error));
280 google_apis::test_util::RunBlockingPoolTask(); 291 google_apis::test_util::RunBlockingPoolTask();
281 EXPECT_EQ(DRIVE_FILE_OK, error); 292 EXPECT_EQ(DRIVE_FILE_OK, error);
282 293
283 int64 out_changestamp = 0; 294 int64 out_changestamp = 0;
284 resource_metadata.GetLargestChangestamp( 295 resource_metadata->GetLargestChangestamp(
285 base::Bind(&CopyResultFromGetChangestampCallback, 296 base::Bind(&CopyResultFromGetChangestampCallback,
286 &out_changestamp)); 297 &out_changestamp));
287 google_apis::test_util::RunBlockingPoolTask(); 298 google_apis::test_util::RunBlockingPoolTask();
288 DCHECK_EQ(in_changestamp, out_changestamp); 299 DCHECK_EQ(in_changestamp, out_changestamp);
289 } 300 }
290 301
291 TEST_F(DriveResourceMetadataTest, GetEntryInfoByResourceId_RootDirectory) { 302 TEST_F(DriveResourceMetadataTest, GetEntryInfoByResourceId_RootDirectory) {
292 DriveResourceMetadata resource_metadata(kTestRootResourceId, 303 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests>
293 blocking_task_runner_); 304 resource_metadata(new DriveResourceMetadata(kTestRootResourceId,
305 blocking_task_runner_));
294 306
295 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 307 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
296 base::FilePath drive_file_path; 308 base::FilePath drive_file_path;
297 scoped_ptr<DriveEntryProto> entry_proto; 309 scoped_ptr<DriveEntryProto> entry_proto;
298 310
299 // Look up the root directory by its resource ID. 311 // Look up the root directory by its resource ID.
300 resource_metadata.GetEntryInfoByResourceId( 312 resource_metadata->GetEntryInfoByResourceId(
301 kTestRootResourceId, 313 kTestRootResourceId,
302 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, 314 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback,
303 &error, &drive_file_path, &entry_proto)); 315 &error, &drive_file_path, &entry_proto));
304 google_apis::test_util::RunBlockingPoolTask(); 316 google_apis::test_util::RunBlockingPoolTask();
305 EXPECT_EQ(DRIVE_FILE_OK, error); 317 EXPECT_EQ(DRIVE_FILE_OK, error);
306 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive"), drive_file_path); 318 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive"), drive_file_path);
307 ASSERT_TRUE(entry_proto.get()); 319 ASSERT_TRUE(entry_proto.get());
308 EXPECT_EQ("drive", entry_proto->base_name()); 320 EXPECT_EQ("drive", entry_proto->base_name());
309 } 321 }
310 322
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 // root should have no children. 1195 // root should have no children.
1184 entries = ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive")); 1196 entries = ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive"));
1185 ASSERT_TRUE(entries.get()); 1197 ASSERT_TRUE(entries.get());
1186 EXPECT_TRUE(entries->empty()); 1198 EXPECT_TRUE(entries->empty());
1187 } 1199 }
1188 1200
1189 TEST_F(DriveResourceMetadataTest, PerDirectoryChangestamp) { 1201 TEST_F(DriveResourceMetadataTest, PerDirectoryChangestamp) {
1190 const int kNewChangestamp = kTestChangestamp + 1; 1202 const int kNewChangestamp = kTestChangestamp + 1;
1191 const char kSubDirectoryResourceId[] = "sub-directory-id"; 1203 const char kSubDirectoryResourceId[] = "sub-directory-id";
1192 1204
1193 DriveResourceMetadata resource_metadata_original(kTestRootResourceId, 1205 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests>
1194 blocking_task_runner_); 1206 resource_metadata_original(new DriveResourceMetadata(
1207 kTestRootResourceId, blocking_task_runner_));
1208
1195 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 1209 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1196 resource_metadata_original.SetLargestChangestamp( 1210 resource_metadata_original->SetLargestChangestamp(
1197 kNewChangestamp, 1211 kNewChangestamp,
1198 google_apis::test_util::CreateCopyResultCallback(&error)); 1212 google_apis::test_util::CreateCopyResultCallback(&error));
1199 google_apis::test_util::RunBlockingPoolTask(); 1213 google_apis::test_util::RunBlockingPoolTask();
1200 EXPECT_EQ(DRIVE_FILE_OK, error); 1214 EXPECT_EQ(DRIVE_FILE_OK, error);
1201 1215
1202 // Add a sub directory. 1216 // Add a sub directory.
1203 DriveEntryProto directory_entry; 1217 DriveEntryProto directory_entry;
1204 directory_entry.mutable_file_info()->set_is_directory(true); 1218 directory_entry.mutable_file_info()->set_is_directory(true);
1205 directory_entry.set_resource_id(kSubDirectoryResourceId); 1219 directory_entry.set_resource_id(kSubDirectoryResourceId);
1206 directory_entry.set_parent_resource_id(kTestRootResourceId); 1220 directory_entry.set_parent_resource_id(kTestRootResourceId);
1207 directory_entry.set_title("directory"); 1221 directory_entry.set_title("directory");
1208 base::FilePath file_path; 1222 base::FilePath file_path;
1209 resource_metadata_original.AddEntry( 1223 resource_metadata_original->AddEntry(
1210 directory_entry, 1224 directory_entry,
1211 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); 1225 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
1212 // At this point, both the root and the sub directory do not contain the 1226 // At this point, both the root and the sub directory do not contain the
1213 // per-directory changestamp. 1227 // per-directory changestamp.
1214 resource_metadata_original.MaybeSave(temp_dir_.path()); 1228 resource_metadata_original->MaybeSave(temp_dir_.path());
1215 google_apis::test_util::RunBlockingPoolTask(); 1229 google_apis::test_util::RunBlockingPoolTask();
1216 1230
1217 DriveResourceMetadata resource_metadata(kTestRootResourceId, 1231 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests>
1218 blocking_task_runner_); 1232 resource_metadata(new DriveResourceMetadata(kTestRootResourceId,
1233 blocking_task_runner_));
1219 1234
1220 // Load. This should propagate the largest changestamp to every directory. 1235 // Load. This should propagate the largest changestamp to every directory.
1221 resource_metadata.Load( 1236 resource_metadata->Load(
1222 temp_dir_.path(), 1237 temp_dir_.path(),
1223 google_apis::test_util::CreateCopyResultCallback(&error)); 1238 google_apis::test_util::CreateCopyResultCallback(&error));
1224 google_apis::test_util::RunBlockingPoolTask(); 1239 google_apis::test_util::RunBlockingPoolTask();
1225 EXPECT_EQ(DRIVE_FILE_OK, error); 1240 EXPECT_EQ(DRIVE_FILE_OK, error);
1226 1241
1227 // Confirm that the root directory contains the changestamp. 1242 // Confirm that the root directory contains the changestamp.
1228 scoped_ptr<DriveEntryProto> entry_proto; 1243 scoped_ptr<DriveEntryProto> entry_proto;
1229 resource_metadata.GetEntryInfoByPath( 1244 resource_metadata->GetEntryInfoByPath(
1230 base::FilePath::FromUTF8Unsafe("drive"), 1245 base::FilePath::FromUTF8Unsafe("drive"),
1231 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, 1246 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback,
1232 &error, &entry_proto)); 1247 &error, &entry_proto));
1233 google_apis::test_util::RunBlockingPoolTask(); 1248 google_apis::test_util::RunBlockingPoolTask();
1234 ASSERT_EQ(DRIVE_FILE_OK, error); 1249 ASSERT_EQ(DRIVE_FILE_OK, error);
1235 EXPECT_EQ(kNewChangestamp, 1250 EXPECT_EQ(kNewChangestamp,
1236 entry_proto->directory_specific_info().changestamp()); 1251 entry_proto->directory_specific_info().changestamp());
1237 1252
1238 // Confirm that the sub directory contains the changestamp. 1253 // Confirm that the sub directory contains the changestamp.
1239 resource_metadata.GetEntryInfoByPath( 1254 resource_metadata->GetEntryInfoByPath(
1240 base::FilePath::FromUTF8Unsafe("drive/directory"), 1255 base::FilePath::FromUTF8Unsafe("drive/directory"),
1241 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, 1256 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback,
1242 &error, &entry_proto)); 1257 &error, &entry_proto));
1243 google_apis::test_util::RunBlockingPoolTask(); 1258 google_apis::test_util::RunBlockingPoolTask();
1244 ASSERT_EQ(DRIVE_FILE_OK, error); 1259 ASSERT_EQ(DRIVE_FILE_OK, error);
1245 EXPECT_EQ(kNewChangestamp, 1260 EXPECT_EQ(kNewChangestamp,
1246 entry_proto->directory_specific_info().changestamp()); 1261 entry_proto->directory_specific_info().changestamp());
1247 } 1262 }
1248 1263
1249 TEST_F(DriveResourceMetadataTest, SaveAndLoad) { 1264 TEST_F(DriveResourceMetadataTest, SaveAndLoad) {
(...skipping 14 matching lines...) Expand all
1264 // Try to get some data. 1279 // Try to get some data.
1265 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync( 1280 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(
1266 base::FilePath::FromUTF8Unsafe("drive/dir1/dir3/file9")); 1281 base::FilePath::FromUTF8Unsafe("drive/dir1/dir3/file9"));
1267 ASSERT_TRUE(entry.get()); 1282 ASSERT_TRUE(entry.get());
1268 EXPECT_EQ("file9", entry->base_name()); 1283 EXPECT_EQ("file9", entry->base_name());
1269 ASSERT_TRUE(!entry->file_info().is_directory()); 1284 ASSERT_TRUE(!entry->file_info().is_directory());
1270 EXPECT_EQ("md5:file9", entry->file_specific_info().file_md5()); 1285 EXPECT_EQ("md5:file9", entry->file_specific_info().file_md5());
1271 } 1286 }
1272 1287
1273 } // namespace drive 1288 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_resource_metadata.cc ('k') | chrome/browser/chromeos/drive/drive_sync_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698