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

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

Issue 10877006: Rename GDataErrorCode to DriveErrorCode, GDataFileError to DriveFileError (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor local variable name fix. Created 8 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 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/gdata/drive_resource_metadata.h" 5 #include "chrome/browser/chromeos/gdata/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 21 matching lines...) Expand all
32 // resource_id are determined by the incrementing counter |sequence_id|. 32 // resource_id are determined by the incrementing counter |sequence_id|.
33 DriveDirectory* AddDirectory(DriveDirectory* parent, 33 DriveDirectory* AddDirectory(DriveDirectory* parent,
34 DriveResourceMetadata* resource_metadata, 34 DriveResourceMetadata* resource_metadata,
35 int sequence_id) { 35 int sequence_id) {
36 DriveDirectory* dir = resource_metadata->CreateDriveDirectory(); 36 DriveDirectory* dir = resource_metadata->CreateDriveDirectory();
37 const std::string dir_name = "dir" + base::IntToString(sequence_id); 37 const std::string dir_name = "dir" + base::IntToString(sequence_id);
38 const std::string resource_id = std::string("dir_resource_id:") + 38 const std::string resource_id = std::string("dir_resource_id:") +
39 dir_name; 39 dir_name;
40 dir->set_title(dir_name); 40 dir->set_title(dir_name);
41 dir->set_resource_id(resource_id); 41 dir->set_resource_id(resource_id);
42 GDataFileError error = GDATA_FILE_ERROR_FAILED; 42 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
43 FilePath moved_file_path; 43 FilePath moved_file_path;
44 resource_metadata->MoveEntryToDirectory( 44 resource_metadata->MoveEntryToDirectory(
45 parent->GetFilePath(), 45 parent->GetFilePath(),
46 dir, 46 dir,
47 base::Bind(&test_util::CopyResultsFromFileMoveCallback, 47 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
48 &error, 48 &error,
49 &moved_file_path)); 49 &moved_file_path));
50 test_util::RunBlockingPoolTask(); 50 test_util::RunBlockingPoolTask();
51 EXPECT_EQ(GDATA_FILE_OK, error); 51 EXPECT_EQ(DRIVE_FILE_OK, error);
52 EXPECT_EQ(parent->GetFilePath().AppendASCII(dir_name), moved_file_path); 52 EXPECT_EQ(parent->GetFilePath().AppendASCII(dir_name), moved_file_path);
53 return dir; 53 return dir;
54 } 54 }
55 55
56 // Add a file to |parent| and return that file. The name and 56 // Add a file to |parent| and return that file. The name and
57 // resource_id are determined by the incrementing counter |sequence_id|. 57 // resource_id are determined by the incrementing counter |sequence_id|.
58 DriveFile* AddFile(DriveDirectory* parent, 58 DriveFile* AddFile(DriveDirectory* parent,
59 DriveResourceMetadata* resource_metadata, 59 DriveResourceMetadata* resource_metadata,
60 int sequence_id) { 60 int sequence_id) {
61 DriveFile* file = resource_metadata->CreateDriveFile(); 61 DriveFile* file = resource_metadata->CreateDriveFile();
62 const std::string title = "file" + base::IntToString(sequence_id); 62 const std::string title = "file" + base::IntToString(sequence_id);
63 const std::string resource_id = std::string("file_resource_id:") + 63 const std::string resource_id = std::string("file_resource_id:") +
64 title; 64 title;
65 file->set_title(title); 65 file->set_title(title);
66 file->set_resource_id(resource_id); 66 file->set_resource_id(resource_id);
67 file->set_file_md5(std::string("file_md5:") + title); 67 file->set_file_md5(std::string("file_md5:") + title);
68 GDataFileError error = GDATA_FILE_ERROR_FAILED; 68 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
69 FilePath moved_file_path; 69 FilePath moved_file_path;
70 resource_metadata->MoveEntryToDirectory( 70 resource_metadata->MoveEntryToDirectory(
71 parent->GetFilePath(), 71 parent->GetFilePath(),
72 file, 72 file,
73 base::Bind(&test_util::CopyResultsFromFileMoveCallback, 73 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
74 &error, 74 &error,
75 &moved_file_path)); 75 &moved_file_path));
76 test_util::RunBlockingPoolTask(); 76 test_util::RunBlockingPoolTask();
77 EXPECT_EQ(GDATA_FILE_OK, error); 77 EXPECT_EQ(DRIVE_FILE_OK, error);
78 EXPECT_EQ(parent->GetFilePath().AppendASCII(title), moved_file_path); 78 EXPECT_EQ(parent->GetFilePath().AppendASCII(title), moved_file_path);
79 return file; 79 return file;
80 } 80 }
81 81
82 // Creates the following files/directories 82 // Creates the following files/directories
83 // drive/dir1/ 83 // drive/dir1/
84 // drive/dir2/ 84 // drive/dir2/
85 // drive/dir1/dir3/ 85 // drive/dir1/dir3/
86 // drive/dir1/file4 86 // drive/dir1/file4
87 // drive/dir1/file5 87 // drive/dir1/file5
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 "file_resource_id:file7")); 178 "file_resource_id:file7"));
179 EXPECT_EQ(file8, resource_metadata->GetEntryByResourceId( 179 EXPECT_EQ(file8, resource_metadata->GetEntryByResourceId(
180 "file_resource_id:file8")); 180 "file_resource_id:file8"));
181 EXPECT_EQ(file9, resource_metadata->GetEntryByResourceId( 181 EXPECT_EQ(file9, resource_metadata->GetEntryByResourceId(
182 "file_resource_id:file9")); 182 "file_resource_id:file9"));
183 EXPECT_EQ(file10, resource_metadata->GetEntryByResourceId( 183 EXPECT_EQ(file10, resource_metadata->GetEntryByResourceId(
184 "file_resource_id:file10")); 184 "file_resource_id:file10"));
185 } 185 }
186 186
187 // Callback for DriveResourceMetadata::InitFromDB. 187 // Callback for DriveResourceMetadata::InitFromDB.
188 void InitFromDBCallback(GDataFileError expected_error, 188 void InitFromDBCallback(DriveFileError expected_error,
189 GDataFileError actual_error) { 189 DriveFileError actual_error) {
190 EXPECT_EQ(expected_error, actual_error); 190 EXPECT_EQ(expected_error, actual_error);
191 } 191 }
192 192
193 // Callback for DriveResourceMetadata::ReadDirectoryByPath. 193 // Callback for DriveResourceMetadata::ReadDirectoryByPath.
194 void ReadDirectoryByPathCallback( 194 void ReadDirectoryByPathCallback(
195 scoped_ptr<DriveEntryProtoVector>* result, 195 scoped_ptr<DriveEntryProtoVector>* result,
196 GDataFileError error, 196 DriveFileError error,
197 scoped_ptr<DriveEntryProtoVector> entries) { 197 scoped_ptr<DriveEntryProtoVector> entries) {
198 EXPECT_EQ(GDATA_FILE_OK, error); 198 EXPECT_EQ(DRIVE_FILE_OK, error);
199 *result = entries.Pass(); 199 *result = entries.Pass();
200 } 200 }
201 201
202 } // namespace 202 } // namespace
203 203
204 TEST(DriveResourceMetadataTest, VersionCheck) { 204 TEST(DriveResourceMetadataTest, VersionCheck) {
205 // Set up the root directory. 205 // Set up the root directory.
206 DriveRootDirectoryProto proto; 206 DriveRootDirectoryProto proto;
207 DriveEntryProto* mutable_entry = 207 DriveEntryProto* mutable_entry =
208 proto.mutable_gdata_directory()->mutable_gdata_entry(); 208 proto.mutable_gdata_directory()->mutable_gdata_entry();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 MessageLoopForUI message_loop; 241 MessageLoopForUI message_loop;
242 content::TestBrowserThread ui_thread(content::BrowserThread::UI, 242 content::TestBrowserThread ui_thread(content::BrowserThread::UI,
243 &message_loop); 243 &message_loop);
244 244
245 DriveResourceMetadata resource_metadata; 245 DriveResourceMetadata resource_metadata;
246 // Add a directory to the file system. 246 // Add a directory to the file system.
247 DriveDirectory* directory_entry = resource_metadata.CreateDriveDirectory(); 247 DriveDirectory* directory_entry = resource_metadata.CreateDriveDirectory();
248 directory_entry->set_resource_id("folder:directory_resource_id"); 248 directory_entry->set_resource_id("folder:directory_resource_id");
249 directory_entry->set_title("directory"); 249 directory_entry->set_title("directory");
250 directory_entry->SetBaseNameFromTitle(); 250 directory_entry->SetBaseNameFromTitle();
251 GDataFileError error = GDATA_FILE_ERROR_FAILED; 251 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
252 FilePath moved_file_path; 252 FilePath moved_file_path;
253 FilePath root_path(kDriveRootDirectory); 253 FilePath root_path(kDriveRootDirectory);
254 resource_metadata.MoveEntryToDirectory( 254 resource_metadata.MoveEntryToDirectory(
255 root_path, 255 root_path,
256 directory_entry, 256 directory_entry,
257 base::Bind(&test_util::CopyResultsFromFileMoveCallback, 257 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
258 &error, 258 &error,
259 &moved_file_path)); 259 &moved_file_path));
260 test_util::RunBlockingPoolTask(); 260 test_util::RunBlockingPoolTask();
261 ASSERT_EQ(GDATA_FILE_OK, error); 261 ASSERT_EQ(DRIVE_FILE_OK, error);
262 EXPECT_EQ(root_path.AppendASCII(directory_entry->base_name()), 262 EXPECT_EQ(root_path.AppendASCII(directory_entry->base_name()),
263 moved_file_path); 263 moved_file_path);
264 264
265 // Add a new file to the directory. 265 // Add a new file to the directory.
266 DriveFile* initial_file_entry = resource_metadata.CreateDriveFile(); 266 DriveFile* initial_file_entry = resource_metadata.CreateDriveFile();
267 initial_file_entry->set_resource_id("file:file_resource_id"); 267 initial_file_entry->set_resource_id("file:file_resource_id");
268 initial_file_entry->set_title("file"); 268 initial_file_entry->set_title("file");
269 initial_file_entry->SetBaseNameFromTitle(); 269 initial_file_entry->SetBaseNameFromTitle();
270 error = GDATA_FILE_ERROR_FAILED; 270 error = DRIVE_FILE_ERROR_FAILED;
271 moved_file_path.clear(); 271 moved_file_path.clear();
272 resource_metadata.MoveEntryToDirectory( 272 resource_metadata.MoveEntryToDirectory(
273 directory_entry->GetFilePath(), 273 directory_entry->GetFilePath(),
274 initial_file_entry, 274 initial_file_entry,
275 base::Bind(&test_util::CopyResultsFromFileMoveCallback, 275 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
276 &error, 276 &error,
277 &moved_file_path)); 277 &moved_file_path));
278 test_util::RunBlockingPoolTask(); 278 test_util::RunBlockingPoolTask();
279 ASSERT_EQ(GDATA_FILE_OK, error); 279 ASSERT_EQ(DRIVE_FILE_OK, error);
280 EXPECT_EQ(directory_entry->GetFilePath().AppendASCII( 280 EXPECT_EQ(directory_entry->GetFilePath().AppendASCII(
281 initial_file_entry->base_name()), moved_file_path); 281 initial_file_entry->base_name()), moved_file_path);
282 282
283 ASSERT_EQ(directory_entry, initial_file_entry->parent()); 283 ASSERT_EQ(directory_entry, initial_file_entry->parent());
284 284
285 // Initial file system state set, let's try refreshing entries. 285 // Initial file system state set, let's try refreshing entries.
286 286
287 // New value for the entry with resource id "file:file_resource_id". 287 // New value for the entry with resource id "file:file_resource_id".
288 DriveFile* new_file_entry = resource_metadata.CreateDriveFile(); 288 DriveFile* new_file_entry = resource_metadata.CreateDriveFile();
289 new_file_entry->set_resource_id("file:file_resource_id"); 289 new_file_entry->set_resource_id("file:file_resource_id");
(...skipping 26 matching lines...) Expand all
316 } 316 }
317 317
318 TEST(DriveResourceMetadataTest, GetEntryInfoByResourceId) { 318 TEST(DriveResourceMetadataTest, GetEntryInfoByResourceId) {
319 MessageLoopForUI message_loop; 319 MessageLoopForUI message_loop;
320 content::TestBrowserThread ui_thread(content::BrowserThread::UI, 320 content::TestBrowserThread ui_thread(content::BrowserThread::UI,
321 &message_loop); 321 &message_loop);
322 DriveResourceMetadata resource_metadata; 322 DriveResourceMetadata resource_metadata;
323 InitDirectoryService(&resource_metadata); 323 InitDirectoryService(&resource_metadata);
324 324
325 // Confirm that an existing file is found. 325 // Confirm that an existing file is found.
326 GDataFileError error = GDATA_FILE_ERROR_FAILED; 326 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
327 FilePath drive_file_path; 327 FilePath drive_file_path;
328 scoped_ptr<DriveEntryProto> entry_proto; 328 scoped_ptr<DriveEntryProto> entry_proto;
329 resource_metadata.GetEntryInfoByResourceId( 329 resource_metadata.GetEntryInfoByResourceId(
330 "file_resource_id:file4", 330 "file_resource_id:file4",
331 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, 331 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback,
332 &error, &drive_file_path, &entry_proto)); 332 &error, &drive_file_path, &entry_proto));
333 test_util::RunBlockingPoolTask(); 333 test_util::RunBlockingPoolTask();
334 EXPECT_EQ(GDATA_FILE_OK, error); 334 EXPECT_EQ(DRIVE_FILE_OK, error);
335 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file4"), drive_file_path); 335 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file4"), drive_file_path);
336 ASSERT_TRUE(entry_proto.get()); 336 ASSERT_TRUE(entry_proto.get());
337 EXPECT_EQ("file4", entry_proto->base_name()); 337 EXPECT_EQ("file4", entry_proto->base_name());
338 338
339 // Confirm that a non existing file is not found. 339 // Confirm that a non existing file is not found.
340 error = GDATA_FILE_ERROR_FAILED; 340 error = DRIVE_FILE_ERROR_FAILED;
341 entry_proto.reset(); 341 entry_proto.reset();
342 resource_metadata.GetEntryInfoByResourceId( 342 resource_metadata.GetEntryInfoByResourceId(
343 "file:non_existing", 343 "file:non_existing",
344 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, 344 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback,
345 &error, &drive_file_path, &entry_proto)); 345 &error, &drive_file_path, &entry_proto));
346 test_util::RunBlockingPoolTask(); 346 test_util::RunBlockingPoolTask();
347 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, error); 347 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
348 EXPECT_FALSE(entry_proto.get()); 348 EXPECT_FALSE(entry_proto.get());
349 } 349 }
350 350
351 TEST(DriveResourceMetadataTest, GetEntryInfoByPath) { 351 TEST(DriveResourceMetadataTest, GetEntryInfoByPath) {
352 MessageLoopForUI message_loop; 352 MessageLoopForUI message_loop;
353 content::TestBrowserThread ui_thread(content::BrowserThread::UI, 353 content::TestBrowserThread ui_thread(content::BrowserThread::UI,
354 &message_loop); 354 &message_loop);
355 DriveResourceMetadata resource_metadata; 355 DriveResourceMetadata resource_metadata;
356 InitDirectoryService(&resource_metadata); 356 InitDirectoryService(&resource_metadata);
357 357
358 // Confirm that an existing file is found. 358 // Confirm that an existing file is found.
359 GDataFileError error = GDATA_FILE_ERROR_FAILED; 359 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
360 scoped_ptr<DriveEntryProto> entry_proto; 360 scoped_ptr<DriveEntryProto> entry_proto;
361 resource_metadata.GetEntryInfoByPath( 361 resource_metadata.GetEntryInfoByPath(
362 FilePath::FromUTF8Unsafe("drive/dir1/file4"), 362 FilePath::FromUTF8Unsafe("drive/dir1/file4"),
363 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, 363 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback,
364 &error, &entry_proto)); 364 &error, &entry_proto));
365 test_util::RunBlockingPoolTask(); 365 test_util::RunBlockingPoolTask();
366 EXPECT_EQ(GDATA_FILE_OK, error); 366 EXPECT_EQ(DRIVE_FILE_OK, error);
367 ASSERT_TRUE(entry_proto.get()); 367 ASSERT_TRUE(entry_proto.get());
368 EXPECT_EQ("file4", entry_proto->base_name()); 368 EXPECT_EQ("file4", entry_proto->base_name());
369 369
370 // Confirm that a non existing file is not found. 370 // Confirm that a non existing file is not found.
371 error = GDATA_FILE_ERROR_FAILED; 371 error = DRIVE_FILE_ERROR_FAILED;
372 entry_proto.reset(); 372 entry_proto.reset();
373 resource_metadata.GetEntryInfoByPath( 373 resource_metadata.GetEntryInfoByPath(
374 FilePath::FromUTF8Unsafe("drive/dir1/non_existing"), 374 FilePath::FromUTF8Unsafe("drive/dir1/non_existing"),
375 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, 375 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback,
376 &error, &entry_proto)); 376 &error, &entry_proto));
377 test_util::RunBlockingPoolTask(); 377 test_util::RunBlockingPoolTask();
378 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, error); 378 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
379 EXPECT_FALSE(entry_proto.get()); 379 EXPECT_FALSE(entry_proto.get());
380 } 380 }
381 381
382 TEST(DriveResourceMetadataTest, ReadDirectoryByPath) { 382 TEST(DriveResourceMetadataTest, ReadDirectoryByPath) {
383 MessageLoopForUI message_loop; 383 MessageLoopForUI message_loop;
384 content::TestBrowserThread ui_thread(content::BrowserThread::UI, 384 content::TestBrowserThread ui_thread(content::BrowserThread::UI,
385 &message_loop); 385 &message_loop);
386 DriveResourceMetadata resource_metadata; 386 DriveResourceMetadata resource_metadata;
387 InitDirectoryService(&resource_metadata); 387 InitDirectoryService(&resource_metadata);
388 388
389 // Confirm that an existing directory is found. 389 // Confirm that an existing directory is found.
390 GDataFileError error = GDATA_FILE_ERROR_FAILED; 390 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
391 scoped_ptr<DriveEntryProtoVector> entries; 391 scoped_ptr<DriveEntryProtoVector> entries;
392 resource_metadata.ReadDirectoryByPath( 392 resource_metadata.ReadDirectoryByPath(
393 FilePath::FromUTF8Unsafe("drive/dir1"), 393 FilePath::FromUTF8Unsafe("drive/dir1"),
394 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, 394 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback,
395 &error, &entries)); 395 &error, &entries));
396 test_util::RunBlockingPoolTask(); 396 test_util::RunBlockingPoolTask();
397 EXPECT_EQ(GDATA_FILE_OK, error); 397 EXPECT_EQ(DRIVE_FILE_OK, error);
398 ASSERT_TRUE(entries.get()); 398 ASSERT_TRUE(entries.get());
399 ASSERT_EQ(3U, entries->size()); 399 ASSERT_EQ(3U, entries->size());
400 400
401 // The order is not guaranteed so we should sort the base names. 401 // The order is not guaranteed so we should sort the base names.
402 std::vector<std::string> base_names; 402 std::vector<std::string> base_names;
403 for (size_t i = 0; i < 3; ++i) 403 for (size_t i = 0; i < 3; ++i)
404 base_names.push_back(entries->at(i).base_name()); 404 base_names.push_back(entries->at(i).base_name());
405 std::sort(base_names.begin(), base_names.end()); 405 std::sort(base_names.begin(), base_names.end());
406 406
407 EXPECT_EQ("dir3", base_names[0]); 407 EXPECT_EQ("dir3", base_names[0]);
408 EXPECT_EQ("file4", base_names[1]); 408 EXPECT_EQ("file4", base_names[1]);
409 EXPECT_EQ("file5", base_names[2]); 409 EXPECT_EQ("file5", base_names[2]);
410 410
411 // Confirm that a non existing directory is not found. 411 // Confirm that a non existing directory is not found.
412 error = GDATA_FILE_ERROR_FAILED; 412 error = DRIVE_FILE_ERROR_FAILED;
413 entries.reset(); 413 entries.reset();
414 resource_metadata.ReadDirectoryByPath( 414 resource_metadata.ReadDirectoryByPath(
415 FilePath::FromUTF8Unsafe("drive/non_existing"), 415 FilePath::FromUTF8Unsafe("drive/non_existing"),
416 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, 416 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback,
417 &error, &entries)); 417 &error, &entries));
418 test_util::RunBlockingPoolTask(); 418 test_util::RunBlockingPoolTask();
419 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, error); 419 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
420 EXPECT_FALSE(entries.get()); 420 EXPECT_FALSE(entries.get());
421 421
422 // Confirm that reading a file results in GDATA_FILE_ERROR_NOT_A_DIRECTORY. 422 // Confirm that reading a file results in DRIVE_FILE_ERROR_NOT_A_DIRECTORY.
423 error = GDATA_FILE_ERROR_FAILED; 423 error = DRIVE_FILE_ERROR_FAILED;
424 entries.reset(); 424 entries.reset();
425 resource_metadata.ReadDirectoryByPath( 425 resource_metadata.ReadDirectoryByPath(
426 FilePath::FromUTF8Unsafe("drive/dir1/file4"), 426 FilePath::FromUTF8Unsafe("drive/dir1/file4"),
427 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, 427 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback,
428 &error, &entries)); 428 &error, &entries));
429 test_util::RunBlockingPoolTask(); 429 test_util::RunBlockingPoolTask();
430 EXPECT_EQ(GDATA_FILE_ERROR_NOT_A_DIRECTORY, error); 430 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, error);
431 EXPECT_FALSE(entries.get()); 431 EXPECT_FALSE(entries.get());
432 } 432 }
433 433
434 TEST(DriveResourceMetadataTest, GetEntryInfoPairByPaths) { 434 TEST(DriveResourceMetadataTest, GetEntryInfoPairByPaths) {
435 MessageLoopForUI message_loop; 435 MessageLoopForUI message_loop;
436 content::TestBrowserThread ui_thread(content::BrowserThread::UI, 436 content::TestBrowserThread ui_thread(content::BrowserThread::UI,
437 &message_loop); 437 &message_loop);
438 DriveResourceMetadata resource_metadata; 438 DriveResourceMetadata resource_metadata;
439 InitDirectoryService(&resource_metadata); 439 InitDirectoryService(&resource_metadata);
440 440
441 // Confirm that existing two files are found. 441 // Confirm that existing two files are found.
442 scoped_ptr<EntryInfoPairResult> pair_result; 442 scoped_ptr<EntryInfoPairResult> pair_result;
443 resource_metadata.GetEntryInfoPairByPaths( 443 resource_metadata.GetEntryInfoPairByPaths(
444 FilePath::FromUTF8Unsafe("drive/dir1/file4"), 444 FilePath::FromUTF8Unsafe("drive/dir1/file4"),
445 FilePath::FromUTF8Unsafe("drive/dir1/file5"), 445 FilePath::FromUTF8Unsafe("drive/dir1/file5"),
446 base::Bind(&test_util::CopyResultsFromGetEntryInfoPairCallback, 446 base::Bind(&test_util::CopyResultsFromGetEntryInfoPairCallback,
447 &pair_result)); 447 &pair_result));
448 test_util::RunBlockingPoolTask(); 448 test_util::RunBlockingPoolTask();
449 // The first entry should be found. 449 // The first entry should be found.
450 EXPECT_EQ(GDATA_FILE_OK, pair_result->first.error); 450 EXPECT_EQ(DRIVE_FILE_OK, pair_result->first.error);
451 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file4"), 451 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file4"),
452 pair_result->first.path); 452 pair_result->first.path);
453 ASSERT_TRUE(pair_result->first.proto.get()); 453 ASSERT_TRUE(pair_result->first.proto.get());
454 EXPECT_EQ("file4", pair_result->first.proto->base_name()); 454 EXPECT_EQ("file4", pair_result->first.proto->base_name());
455 // The second entry should be found. 455 // The second entry should be found.
456 EXPECT_EQ(GDATA_FILE_OK, pair_result->second.error); 456 EXPECT_EQ(DRIVE_FILE_OK, pair_result->second.error);
457 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file5"), 457 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file5"),
458 pair_result->second.path); 458 pair_result->second.path);
459 ASSERT_TRUE(pair_result->second.proto.get()); 459 ASSERT_TRUE(pair_result->second.proto.get());
460 EXPECT_EQ("file5", pair_result->second.proto->base_name()); 460 EXPECT_EQ("file5", pair_result->second.proto->base_name());
461 461
462 // Confirm that the first non existent file is not found. 462 // Confirm that the first non existent file is not found.
463 pair_result.reset(); 463 pair_result.reset();
464 resource_metadata.GetEntryInfoPairByPaths( 464 resource_metadata.GetEntryInfoPairByPaths(
465 FilePath::FromUTF8Unsafe("drive/dir1/non_existent"), 465 FilePath::FromUTF8Unsafe("drive/dir1/non_existent"),
466 FilePath::FromUTF8Unsafe("drive/dir1/file5"), 466 FilePath::FromUTF8Unsafe("drive/dir1/file5"),
467 base::Bind(&test_util::CopyResultsFromGetEntryInfoPairCallback, 467 base::Bind(&test_util::CopyResultsFromGetEntryInfoPairCallback,
468 &pair_result)); 468 &pair_result));
469 test_util::RunBlockingPoolTask(); 469 test_util::RunBlockingPoolTask();
470 // The first entry should not be found. 470 // The first entry should not be found.
471 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, pair_result->first.error); 471 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, pair_result->first.error);
472 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/non_existent"), 472 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/non_existent"),
473 pair_result->first.path); 473 pair_result->first.path);
474 ASSERT_FALSE(pair_result->first.proto.get()); 474 ASSERT_FALSE(pair_result->first.proto.get());
475 // The second entry should not be found, because the first one failed. 475 // The second entry should not be found, because the first one failed.
476 EXPECT_EQ(GDATA_FILE_ERROR_FAILED, pair_result->second.error); 476 EXPECT_EQ(DRIVE_FILE_ERROR_FAILED, pair_result->second.error);
477 EXPECT_EQ(FilePath(), pair_result->second.path); 477 EXPECT_EQ(FilePath(), pair_result->second.path);
478 ASSERT_FALSE(pair_result->second.proto.get()); 478 ASSERT_FALSE(pair_result->second.proto.get());
479 479
480 // Confirm that the second non existent file is not found. 480 // Confirm that the second non existent file is not found.
481 pair_result.reset(); 481 pair_result.reset();
482 resource_metadata.GetEntryInfoPairByPaths( 482 resource_metadata.GetEntryInfoPairByPaths(
483 FilePath::FromUTF8Unsafe("drive/dir1/file4"), 483 FilePath::FromUTF8Unsafe("drive/dir1/file4"),
484 FilePath::FromUTF8Unsafe("drive/dir1/non_existent"), 484 FilePath::FromUTF8Unsafe("drive/dir1/non_existent"),
485 base::Bind(&test_util::CopyResultsFromGetEntryInfoPairCallback, 485 base::Bind(&test_util::CopyResultsFromGetEntryInfoPairCallback,
486 &pair_result)); 486 &pair_result));
487 test_util::RunBlockingPoolTask(); 487 test_util::RunBlockingPoolTask();
488 // The first entry should be found. 488 // The first entry should be found.
489 EXPECT_EQ(GDATA_FILE_OK, pair_result->first.error); 489 EXPECT_EQ(DRIVE_FILE_OK, pair_result->first.error);
490 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file4"), 490 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file4"),
491 pair_result->first.path); 491 pair_result->first.path);
492 ASSERT_TRUE(pair_result->first.proto.get()); 492 ASSERT_TRUE(pair_result->first.proto.get());
493 EXPECT_EQ("file4", pair_result->first.proto->base_name()); 493 EXPECT_EQ("file4", pair_result->first.proto->base_name());
494 // The second entry should not be found. 494 // The second entry should not be found.
495 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, pair_result->second.error); 495 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, pair_result->second.error);
496 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/non_existent"), 496 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/non_existent"),
497 pair_result->second.path); 497 pair_result->second.path);
498 ASSERT_FALSE(pair_result->second.proto.get()); 498 ASSERT_FALSE(pair_result->second.proto.get());
499 } 499 }
500 500
501 TEST(DriveResourceMetadataTest, DBTest) { 501 TEST(DriveResourceMetadataTest, DBTest) {
502 MessageLoopForUI message_loop; 502 MessageLoopForUI message_loop;
503 content::TestBrowserThread ui_thread(content::BrowserThread::UI, 503 content::TestBrowserThread ui_thread(content::BrowserThread::UI,
504 &message_loop); 504 &message_loop);
505 505
506 scoped_ptr<TestingProfile> profile(new TestingProfile); 506 scoped_ptr<TestingProfile> profile(new TestingProfile);
507 scoped_refptr<base::SequencedWorkerPool> pool = 507 scoped_refptr<base::SequencedWorkerPool> pool =
508 content::BrowserThread::GetBlockingPool(); 508 content::BrowserThread::GetBlockingPool();
509 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner = 509 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner =
510 pool->GetSequencedTaskRunner(pool->GetSequenceToken()); 510 pool->GetSequencedTaskRunner(pool->GetSequenceToken());
511 511
512 DriveResourceMetadata resource_metadata; 512 DriveResourceMetadata resource_metadata;
513 FilePath db_path(DriveCache::GetCacheRootPath(profile.get()). 513 FilePath db_path(DriveCache::GetCacheRootPath(profile.get()).
514 AppendASCII("meta").AppendASCII("resource_metadata.db")); 514 AppendASCII("meta").AppendASCII("resource_metadata.db"));
515 // InitFromDB should fail with GDATA_FILE_ERROR_NOT_FOUND since the db 515 // InitFromDB should fail with DRIVE_FILE_ERROR_NOT_FOUND since the db
516 // doesn't exist. 516 // doesn't exist.
517 resource_metadata.InitFromDB(db_path, blocking_task_runner, 517 resource_metadata.InitFromDB(db_path, blocking_task_runner,
518 base::Bind(&InitFromDBCallback, GDATA_FILE_ERROR_NOT_FOUND)); 518 base::Bind(&InitFromDBCallback, DRIVE_FILE_ERROR_NOT_FOUND));
519 test_util::RunBlockingPoolTask(); 519 test_util::RunBlockingPoolTask();
520 InitDirectoryService(&resource_metadata); 520 InitDirectoryService(&resource_metadata);
521 521
522 // Write the filesystem to db. 522 // Write the filesystem to db.
523 resource_metadata.SaveToDB(); 523 resource_metadata.SaveToDB();
524 test_util::RunBlockingPoolTask(); 524 test_util::RunBlockingPoolTask();
525 525
526 DriveResourceMetadata resource_metadata2; 526 DriveResourceMetadata resource_metadata2;
527 // InitFromDB should succeed with GDATA_FILE_OK as the db now exists. 527 // InitFromDB should succeed with DRIVE_FILE_OK as the db now exists.
528 resource_metadata2.InitFromDB(db_path, blocking_task_runner, 528 resource_metadata2.InitFromDB(db_path, blocking_task_runner,
529 base::Bind(&InitFromDBCallback, GDATA_FILE_OK)); 529 base::Bind(&InitFromDBCallback, DRIVE_FILE_OK));
530 test_util::RunBlockingPoolTask(); 530 test_util::RunBlockingPoolTask();
531 531
532 VerifyDirectoryService(&resource_metadata2); 532 VerifyDirectoryService(&resource_metadata2);
533 } 533 }
534 534
535 } // namespace gdata 535 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/drive_resource_metadata.cc ('k') | chrome/browser/chromeos/gdata/drive_task_executor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698