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

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

Issue 13149003: drive: Use "/drive/root" namespace and fix Files app and tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge glitches. Created 7 years, 8 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>
11 11
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/threading/sequenced_worker_pool.h" 15 #include "base/threading/sequenced_worker_pool.h"
16 #include "chrome/browser/chromeos/drive/drive.pb.h" 16 #include "chrome/browser/chromeos/drive/drive.pb.h"
17 #include "chrome/browser/chromeos/drive/drive_cache.h" 17 #include "chrome/browser/chromeos/drive/drive_cache.h"
18 #include "chrome/browser/chromeos/drive/drive_file_system_util.h"
18 #include "chrome/browser/chromeos/drive/drive_resource_metadata_storage.h" 19 #include "chrome/browser/chromeos/drive/drive_resource_metadata_storage.h"
19 #include "chrome/browser/chromeos/drive/drive_test_util.h" 20 #include "chrome/browser/chromeos/drive/drive_test_util.h"
20 #include "chrome/browser/google_apis/test_util.h" 21 #include "chrome/browser/google_apis/test_util.h"
21 #include "chrome/browser/google_apis/time_util.h" 22 #include "chrome/browser/google_apis/time_util.h"
22 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
23 #include "content/public/test/test_browser_thread.h" 24 #include "content/public/test/test_browser_thread.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 26
26 namespace drive { 27 namespace drive {
27 namespace { 28 namespace {
(...skipping 20 matching lines...) Expand all
48 49
49 } // namespace 50 } // namespace
50 51
51 class DriveResourceMetadataTest : public testing::Test { 52 class DriveResourceMetadataTest : public testing::Test {
52 protected: 53 protected:
53 DriveResourceMetadataTest() 54 DriveResourceMetadataTest()
54 : ui_thread_(content::BrowserThread::UI, &message_loop_) { 55 : ui_thread_(content::BrowserThread::UI, &message_loop_) {
55 } 56 }
56 57
57 // Creates the following files/directories 58 // Creates the following files/directories
58 // drive/dir1/ 59 // drive/root/dir1/
59 // drive/dir2/ 60 // drive/root/dir2/
60 // drive/dir1/dir3/ 61 // drive/root/dir1/dir3/
61 // drive/dir1/file4 62 // drive/root/dir1/file4
62 // drive/dir1/file5 63 // drive/root/dir1/file5
63 // drive/dir2/file6 64 // drive/root/dir2/file6
64 // drive/dir2/file7 65 // drive/root/dir2/file7
65 // drive/dir2/file8 66 // drive/root/dir2/file8
66 // drive/dir1/dir3/file9 67 // drive/root/dir1/dir3/file9
67 // drive/dir1/dir3/file10 68 // drive/root/dir1/dir3/file10
68 static void Init(DriveResourceMetadata* resource_metadata); 69 static void Init(DriveResourceMetadata* resource_metadata);
69 70
70 // Creates a DriveEntryProto. 71 // Creates a DriveEntryProto.
71 static DriveEntryProto CreateDriveEntryProto( 72 static DriveEntryProto CreateDriveEntryProto(
72 int sequence_id, 73 int sequence_id,
73 bool is_directory, 74 bool is_directory,
74 const std::string& parent_resource_id); 75 const std::string& parent_resource_id);
75 76
76 // Adds a DriveEntryProto to the metadata tree. Returns true on success. 77 // Adds a DriveEntryProto to the metadata tree. Returns true on success.
77 static bool AddDriveEntryProto(DriveResourceMetadata* resource_metadata, 78 static bool AddDriveEntryProto(DriveResourceMetadata* resource_metadata,
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 google_apis::test_util::RunBlockingPoolTask(); 250 google_apis::test_util::RunBlockingPoolTask();
250 return DRIVE_FILE_OK == error; 251 return DRIVE_FILE_OK == error;
251 } 252 }
252 253
253 TEST_F(DriveResourceMetadataTest, VersionCheck) { 254 TEST_F(DriveResourceMetadataTest, VersionCheck) {
254 // Set up the root directory. 255 // Set up the root directory.
255 DriveRootDirectoryProto proto; 256 DriveRootDirectoryProto proto;
256 DriveEntryProto* mutable_entry = 257 DriveEntryProto* mutable_entry =
257 proto.mutable_drive_directory()->mutable_drive_entry(); 258 proto.mutable_drive_directory()->mutable_drive_entry();
258 mutable_entry->mutable_file_info()->set_is_directory(true); 259 mutable_entry->mutable_file_info()->set_is_directory(true);
259 mutable_entry->set_resource_id(kTestRootResourceId); 260 mutable_entry->set_resource_id(util::kDriveGrandRootSpecialResourceId);
260 mutable_entry->set_title("drive"); 261 mutable_entry->set_title("drive");
261 262
262 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests> 263 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests>
263 resource_metadata(new DriveResourceMetadata(kTestRootResourceId, 264 resource_metadata(new DriveResourceMetadata(kTestRootResourceId,
264 temp_dir_.path(), 265 temp_dir_.path(),
265 blocking_task_runner_)); 266 blocking_task_runner_));
266 ForceUsingMemoryStorage(resource_metadata.get()); 267 ForceUsingMemoryStorage(resource_metadata.get());
267 268
268 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 269 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
269 resource_metadata->Initialize( 270 resource_metadata->Initialize(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 resource_metadata->Initialize( 334 resource_metadata->Initialize(
334 google_apis::test_util::CreateCopyResultCallback(&error)); 335 google_apis::test_util::CreateCopyResultCallback(&error));
335 google_apis::test_util::RunBlockingPoolTask(); 336 google_apis::test_util::RunBlockingPoolTask();
336 ASSERT_EQ(DRIVE_FILE_OK, error); 337 ASSERT_EQ(DRIVE_FILE_OK, error);
337 338
338 base::FilePath drive_file_path; 339 base::FilePath drive_file_path;
339 scoped_ptr<DriveEntryProto> entry_proto; 340 scoped_ptr<DriveEntryProto> entry_proto;
340 341
341 // Look up the root directory by its resource ID. 342 // Look up the root directory by its resource ID.
342 resource_metadata->GetEntryInfoByResourceId( 343 resource_metadata->GetEntryInfoByResourceId(
343 kTestRootResourceId, 344 util::kDriveGrandRootSpecialResourceId,
344 google_apis::test_util::CreateCopyResultCallback( 345 google_apis::test_util::CreateCopyResultCallback(
345 &error, &drive_file_path, &entry_proto)); 346 &error, &drive_file_path, &entry_proto));
346 google_apis::test_util::RunBlockingPoolTask(); 347 google_apis::test_util::RunBlockingPoolTask();
347 EXPECT_EQ(DRIVE_FILE_OK, error); 348 EXPECT_EQ(DRIVE_FILE_OK, error);
348 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive"), drive_file_path); 349 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive"), drive_file_path);
349 ASSERT_TRUE(entry_proto.get()); 350 ASSERT_TRUE(entry_proto.get());
350 EXPECT_EQ("drive", entry_proto->base_name()); 351 EXPECT_EQ("drive", entry_proto->base_name());
351 } 352 }
352 353
353 TEST_F(DriveResourceMetadataTest, GetEntryInfoByResourceId) { 354 TEST_F(DriveResourceMetadataTest, GetEntryInfoByResourceId) {
354 // Confirm that an existing file is found. 355 // Confirm that an existing file is found.
355 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 356 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
356 base::FilePath drive_file_path; 357 base::FilePath drive_file_path;
357 scoped_ptr<DriveEntryProto> entry_proto; 358 scoped_ptr<DriveEntryProto> entry_proto;
358 resource_metadata_->GetEntryInfoByResourceId( 359 resource_metadata_->GetEntryInfoByResourceId(
359 "resource_id:file4", 360 "resource_id:file4",
360 google_apis::test_util::CreateCopyResultCallback( 361 google_apis::test_util::CreateCopyResultCallback(
361 &error, &drive_file_path, &entry_proto)); 362 &error, &drive_file_path, &entry_proto));
362 google_apis::test_util::RunBlockingPoolTask(); 363 google_apis::test_util::RunBlockingPoolTask();
363 EXPECT_EQ(DRIVE_FILE_OK, error); 364 EXPECT_EQ(DRIVE_FILE_OK, error);
364 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir1/file4"), 365 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/file4"),
365 drive_file_path); 366 drive_file_path);
366 ASSERT_TRUE(entry_proto.get()); 367 ASSERT_TRUE(entry_proto.get());
367 EXPECT_EQ("file4", entry_proto->base_name()); 368 EXPECT_EQ("file4", entry_proto->base_name());
368 369
369 // Confirm that a non existing file is not found. 370 // Confirm that a non existing file is not found.
370 error = DRIVE_FILE_ERROR_FAILED; 371 error = DRIVE_FILE_ERROR_FAILED;
371 entry_proto.reset(); 372 entry_proto.reset();
372 resource_metadata_->GetEntryInfoByResourceId( 373 resource_metadata_->GetEntryInfoByResourceId(
373 "file:non_existing", 374 "file:non_existing",
374 google_apis::test_util::CreateCopyResultCallback( 375 google_apis::test_util::CreateCopyResultCallback(
375 &error, &drive_file_path, &entry_proto)); 376 &error, &drive_file_path, &entry_proto));
376 google_apis::test_util::RunBlockingPoolTask(); 377 google_apis::test_util::RunBlockingPoolTask();
377 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); 378 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
378 EXPECT_FALSE(entry_proto.get()); 379 EXPECT_FALSE(entry_proto.get());
379 } 380 }
380 381
381 TEST_F(DriveResourceMetadataTest, GetEntryInfoByPath) { 382 TEST_F(DriveResourceMetadataTest, GetEntryInfoByPath) {
382 // Confirm that an existing file is found. 383 // Confirm that an existing file is found.
383 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 384 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
384 scoped_ptr<DriveEntryProto> entry_proto; 385 scoped_ptr<DriveEntryProto> entry_proto;
385 resource_metadata_->GetEntryInfoByPath( 386 resource_metadata_->GetEntryInfoByPath(
386 base::FilePath::FromUTF8Unsafe("drive/dir1/file4"), 387 base::FilePath::FromUTF8Unsafe("drive/root/dir1/file4"),
387 google_apis::test_util::CreateCopyResultCallback(&error, &entry_proto)); 388 google_apis::test_util::CreateCopyResultCallback(&error, &entry_proto));
388 google_apis::test_util::RunBlockingPoolTask(); 389 google_apis::test_util::RunBlockingPoolTask();
389 EXPECT_EQ(DRIVE_FILE_OK, error); 390 EXPECT_EQ(DRIVE_FILE_OK, error);
390 ASSERT_TRUE(entry_proto.get()); 391 ASSERT_TRUE(entry_proto.get());
391 EXPECT_EQ("file4", entry_proto->base_name()); 392 EXPECT_EQ("file4", entry_proto->base_name());
392 393
393 // Confirm that a non existing file is not found. 394 // Confirm that a non existing file is not found.
394 error = DRIVE_FILE_ERROR_FAILED; 395 error = DRIVE_FILE_ERROR_FAILED;
395 entry_proto.reset(); 396 entry_proto.reset();
396 resource_metadata_->GetEntryInfoByPath( 397 resource_metadata_->GetEntryInfoByPath(
397 base::FilePath::FromUTF8Unsafe("drive/dir1/non_existing"), 398 base::FilePath::FromUTF8Unsafe("drive/root/dir1/non_existing"),
398 google_apis::test_util::CreateCopyResultCallback(&error, &entry_proto)); 399 google_apis::test_util::CreateCopyResultCallback(&error, &entry_proto));
399 google_apis::test_util::RunBlockingPoolTask(); 400 google_apis::test_util::RunBlockingPoolTask();
400 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); 401 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
401 EXPECT_FALSE(entry_proto.get()); 402 EXPECT_FALSE(entry_proto.get());
402 } 403 }
403 404
404 TEST_F(DriveResourceMetadataTest, ReadDirectoryByPath) { 405 TEST_F(DriveResourceMetadataTest, ReadDirectoryByPath) {
405 // Confirm that an existing directory is found. 406 // Confirm that an existing directory is found.
406 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 407 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
407 scoped_ptr<DriveEntryProtoVector> entries; 408 scoped_ptr<DriveEntryProtoVector> entries;
408 resource_metadata_->ReadDirectoryByPath( 409 resource_metadata_->ReadDirectoryByPath(
409 base::FilePath::FromUTF8Unsafe("drive/dir1"), 410 base::FilePath::FromUTF8Unsafe("drive/root/dir1"),
410 google_apis::test_util::CreateCopyResultCallback(&error, &entries)); 411 google_apis::test_util::CreateCopyResultCallback(&error, &entries));
411 google_apis::test_util::RunBlockingPoolTask(); 412 google_apis::test_util::RunBlockingPoolTask();
412 EXPECT_EQ(DRIVE_FILE_OK, error); 413 EXPECT_EQ(DRIVE_FILE_OK, error);
413 ASSERT_TRUE(entries.get()); 414 ASSERT_TRUE(entries.get());
414 ASSERT_EQ(3U, entries->size()); 415 ASSERT_EQ(3U, entries->size());
415 // The order is not guaranteed so we should sort the base names. 416 // The order is not guaranteed so we should sort the base names.
416 std::vector<std::string> base_names = GetSortedBaseNames(*entries); 417 std::vector<std::string> base_names = GetSortedBaseNames(*entries);
417 EXPECT_EQ("dir3", base_names[0]); 418 EXPECT_EQ("dir3", base_names[0]);
418 EXPECT_EQ("file4", base_names[1]); 419 EXPECT_EQ("file4", base_names[1]);
419 EXPECT_EQ("file5", base_names[2]); 420 EXPECT_EQ("file5", base_names[2]);
420 421
421 // Confirm that a non existing directory is not found. 422 // Confirm that a non existing directory is not found.
422 error = DRIVE_FILE_ERROR_FAILED; 423 error = DRIVE_FILE_ERROR_FAILED;
423 entries.reset(); 424 entries.reset();
424 resource_metadata_->ReadDirectoryByPath( 425 resource_metadata_->ReadDirectoryByPath(
425 base::FilePath::FromUTF8Unsafe("drive/non_existing"), 426 base::FilePath::FromUTF8Unsafe("drive/root/non_existing"),
426 google_apis::test_util::CreateCopyResultCallback(&error, &entries)); 427 google_apis::test_util::CreateCopyResultCallback(&error, &entries));
427 google_apis::test_util::RunBlockingPoolTask(); 428 google_apis::test_util::RunBlockingPoolTask();
428 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); 429 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
429 EXPECT_FALSE(entries.get()); 430 EXPECT_FALSE(entries.get());
430 431
431 // Confirm that reading a file results in DRIVE_FILE_ERROR_NOT_A_DIRECTORY. 432 // Confirm that reading a file results in DRIVE_FILE_ERROR_NOT_A_DIRECTORY.
432 error = DRIVE_FILE_ERROR_FAILED; 433 error = DRIVE_FILE_ERROR_FAILED;
433 entries.reset(); 434 entries.reset();
434 resource_metadata_->ReadDirectoryByPath( 435 resource_metadata_->ReadDirectoryByPath(
435 base::FilePath::FromUTF8Unsafe("drive/dir1/file4"), 436 base::FilePath::FromUTF8Unsafe("drive/root/dir1/file4"),
436 google_apis::test_util::CreateCopyResultCallback(&error, &entries)); 437 google_apis::test_util::CreateCopyResultCallback(&error, &entries));
437 google_apis::test_util::RunBlockingPoolTask(); 438 google_apis::test_util::RunBlockingPoolTask();
438 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, error); 439 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, error);
439 EXPECT_FALSE(entries.get()); 440 EXPECT_FALSE(entries.get());
440 } 441 }
441 442
442 TEST_F(DriveResourceMetadataTest, GetEntryInfoPairByPaths) { 443 TEST_F(DriveResourceMetadataTest, GetEntryInfoPairByPaths) {
443 // Confirm that existing two files are found. 444 // Confirm that existing two files are found.
444 scoped_ptr<EntryInfoPairResult> pair_result; 445 scoped_ptr<EntryInfoPairResult> pair_result;
445 resource_metadata_->GetEntryInfoPairByPaths( 446 resource_metadata_->GetEntryInfoPairByPaths(
446 base::FilePath::FromUTF8Unsafe("drive/dir1/file4"), 447 base::FilePath::FromUTF8Unsafe("drive/root/dir1/file4"),
447 base::FilePath::FromUTF8Unsafe("drive/dir1/file5"), 448 base::FilePath::FromUTF8Unsafe("drive/root/dir1/file5"),
448 google_apis::test_util::CreateCopyResultCallback(&pair_result)); 449 google_apis::test_util::CreateCopyResultCallback(&pair_result));
449 google_apis::test_util::RunBlockingPoolTask(); 450 google_apis::test_util::RunBlockingPoolTask();
450 // The first entry should be found. 451 // The first entry should be found.
451 EXPECT_EQ(DRIVE_FILE_OK, pair_result->first.error); 452 EXPECT_EQ(DRIVE_FILE_OK, pair_result->first.error);
452 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir1/file4"), 453 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/file4"),
453 pair_result->first.path); 454 pair_result->first.path);
454 ASSERT_TRUE(pair_result->first.proto.get()); 455 ASSERT_TRUE(pair_result->first.proto.get());
455 EXPECT_EQ("file4", pair_result->first.proto->base_name()); 456 EXPECT_EQ("file4", pair_result->first.proto->base_name());
456 // The second entry should be found. 457 // The second entry should be found.
457 EXPECT_EQ(DRIVE_FILE_OK, pair_result->second.error); 458 EXPECT_EQ(DRIVE_FILE_OK, pair_result->second.error);
458 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir1/file5"), 459 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/file5"),
459 pair_result->second.path); 460 pair_result->second.path);
460 ASSERT_TRUE(pair_result->second.proto.get()); 461 ASSERT_TRUE(pair_result->second.proto.get());
461 EXPECT_EQ("file5", pair_result->second.proto->base_name()); 462 EXPECT_EQ("file5", pair_result->second.proto->base_name());
462 463
463 // Confirm that the first non existent file is not found. 464 // Confirm that the first non existent file is not found.
464 pair_result.reset(); 465 pair_result.reset();
465 resource_metadata_->GetEntryInfoPairByPaths( 466 resource_metadata_->GetEntryInfoPairByPaths(
466 base::FilePath::FromUTF8Unsafe("drive/dir1/non_existent"), 467 base::FilePath::FromUTF8Unsafe("drive/root/dir1/non_existent"),
467 base::FilePath::FromUTF8Unsafe("drive/dir1/file5"), 468 base::FilePath::FromUTF8Unsafe("drive/root/dir1/file5"),
468 google_apis::test_util::CreateCopyResultCallback(&pair_result)); 469 google_apis::test_util::CreateCopyResultCallback(&pair_result));
469 google_apis::test_util::RunBlockingPoolTask(); 470 google_apis::test_util::RunBlockingPoolTask();
470 // The first entry should not be found. 471 // The first entry should not be found.
471 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, pair_result->first.error); 472 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, pair_result->first.error);
472 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir1/non_existent"), 473 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/non_existent"),
473 pair_result->first.path); 474 pair_result->first.path);
474 ASSERT_FALSE(pair_result->first.proto.get()); 475 ASSERT_FALSE(pair_result->first.proto.get());
475 // The second entry should not be found, because the first one failed. 476 // The second entry should not be found, because the first one failed.
476 EXPECT_EQ(DRIVE_FILE_ERROR_FAILED, pair_result->second.error); 477 EXPECT_EQ(DRIVE_FILE_ERROR_FAILED, pair_result->second.error);
477 EXPECT_EQ(base::FilePath(), pair_result->second.path); 478 EXPECT_EQ(base::FilePath(), pair_result->second.path);
478 ASSERT_FALSE(pair_result->second.proto.get()); 479 ASSERT_FALSE(pair_result->second.proto.get());
479 480
480 // Confirm that the second non existent file is not found. 481 // Confirm that the second non existent file is not found.
481 pair_result.reset(); 482 pair_result.reset();
482 resource_metadata_->GetEntryInfoPairByPaths( 483 resource_metadata_->GetEntryInfoPairByPaths(
483 base::FilePath::FromUTF8Unsafe("drive/dir1/file4"), 484 base::FilePath::FromUTF8Unsafe("drive/root/dir1/file4"),
484 base::FilePath::FromUTF8Unsafe("drive/dir1/non_existent"), 485 base::FilePath::FromUTF8Unsafe("drive/root/dir1/non_existent"),
485 google_apis::test_util::CreateCopyResultCallback(&pair_result)); 486 google_apis::test_util::CreateCopyResultCallback(&pair_result));
486 google_apis::test_util::RunBlockingPoolTask(); 487 google_apis::test_util::RunBlockingPoolTask();
487 // The first entry should be found. 488 // The first entry should be found.
488 EXPECT_EQ(DRIVE_FILE_OK, pair_result->first.error); 489 EXPECT_EQ(DRIVE_FILE_OK, pair_result->first.error);
489 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir1/file4"), 490 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/file4"),
490 pair_result->first.path); 491 pair_result->first.path);
491 ASSERT_TRUE(pair_result->first.proto.get()); 492 ASSERT_TRUE(pair_result->first.proto.get());
492 EXPECT_EQ("file4", pair_result->first.proto->base_name()); 493 EXPECT_EQ("file4", pair_result->first.proto->base_name());
493 // The second entry should not be found. 494 // The second entry should not be found.
494 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, pair_result->second.error); 495 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, pair_result->second.error);
495 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir1/non_existent"), 496 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/non_existent"),
496 pair_result->second.path); 497 pair_result->second.path);
497 ASSERT_FALSE(pair_result->second.proto.get()); 498 ASSERT_FALSE(pair_result->second.proto.get());
498 } 499 }
499 500
500 TEST_F(DriveResourceMetadataTest, RemoveEntry) { 501 TEST_F(DriveResourceMetadataTest, RemoveEntry) {
501 // Make sure file9 is found. 502 // Make sure file9 is found.
502 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 503 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
503 base::FilePath drive_file_path; 504 base::FilePath drive_file_path;
504 const std::string file9_resource_id = "resource_id:file9"; 505 const std::string file9_resource_id = "resource_id:file9";
505 scoped_ptr<DriveEntryProto> entry_proto; 506 scoped_ptr<DriveEntryProto> entry_proto;
506 resource_metadata_->GetEntryInfoByResourceId( 507 resource_metadata_->GetEntryInfoByResourceId(
507 file9_resource_id, 508 file9_resource_id,
508 google_apis::test_util::CreateCopyResultCallback( 509 google_apis::test_util::CreateCopyResultCallback(
509 &error, &drive_file_path, &entry_proto)); 510 &error, &drive_file_path, &entry_proto));
510 google_apis::test_util::RunBlockingPoolTask(); 511 google_apis::test_util::RunBlockingPoolTask();
511 EXPECT_EQ(DRIVE_FILE_OK, error); 512 EXPECT_EQ(DRIVE_FILE_OK, error);
512 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir1/dir3/file9"), 513 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3/file9"),
513 drive_file_path); 514 drive_file_path);
514 ASSERT_TRUE(entry_proto.get()); 515 ASSERT_TRUE(entry_proto.get());
515 EXPECT_EQ("file9", entry_proto->base_name()); 516 EXPECT_EQ("file9", entry_proto->base_name());
516 517
517 // Remove file9 using RemoveEntry. 518 // Remove file9 using RemoveEntry.
518 resource_metadata_->RemoveEntry( 519 resource_metadata_->RemoveEntry(
519 file9_resource_id, 520 file9_resource_id,
520 google_apis::test_util::CreateCopyResultCallback( 521 google_apis::test_util::CreateCopyResultCallback(
521 &error, &drive_file_path)); 522 &error, &drive_file_path));
522 google_apis::test_util::RunBlockingPoolTask(); 523 google_apis::test_util::RunBlockingPoolTask();
523 EXPECT_EQ(DRIVE_FILE_OK, error); 524 EXPECT_EQ(DRIVE_FILE_OK, error);
524 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir1/dir3"), drive_file_path); 525 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3"),
526 drive_file_path);
525 527
526 // file9 should no longer exist. 528 // file9 should no longer exist.
527 resource_metadata_->GetEntryInfoByResourceId( 529 resource_metadata_->GetEntryInfoByResourceId(
528 file9_resource_id, 530 file9_resource_id,
529 google_apis::test_util::CreateCopyResultCallback( 531 google_apis::test_util::CreateCopyResultCallback(
530 &error, &drive_file_path, &entry_proto)); 532 &error, &drive_file_path, &entry_proto));
531 google_apis::test_util::RunBlockingPoolTask(); 533 google_apis::test_util::RunBlockingPoolTask();
532 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); 534 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
533 EXPECT_FALSE(entry_proto.get()); 535 EXPECT_FALSE(entry_proto.get());
534 536
535 // Look for dir3. 537 // Look for dir3.
536 const std::string dir3_resource_id = "resource_id:dir3"; 538 const std::string dir3_resource_id = "resource_id:dir3";
537 resource_metadata_->GetEntryInfoByResourceId( 539 resource_metadata_->GetEntryInfoByResourceId(
538 dir3_resource_id, 540 dir3_resource_id,
539 google_apis::test_util::CreateCopyResultCallback( 541 google_apis::test_util::CreateCopyResultCallback(
540 &error, &drive_file_path, &entry_proto)); 542 &error, &drive_file_path, &entry_proto));
541 google_apis::test_util::RunBlockingPoolTask(); 543 google_apis::test_util::RunBlockingPoolTask();
542 EXPECT_EQ(DRIVE_FILE_OK, error); 544 EXPECT_EQ(DRIVE_FILE_OK, error);
543 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir1/dir3"), drive_file_path); 545 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3"),
546 drive_file_path);
544 ASSERT_TRUE(entry_proto.get()); 547 ASSERT_TRUE(entry_proto.get());
545 EXPECT_EQ("dir3", entry_proto->base_name()); 548 EXPECT_EQ("dir3", entry_proto->base_name());
546 549
547 // Remove dir3 using RemoveEntry. 550 // Remove dir3 using RemoveEntry.
548 resource_metadata_->RemoveEntry( 551 resource_metadata_->RemoveEntry(
549 dir3_resource_id, 552 dir3_resource_id,
550 google_apis::test_util::CreateCopyResultCallback( 553 google_apis::test_util::CreateCopyResultCallback(
551 &error, &drive_file_path)); 554 &error, &drive_file_path));
552 google_apis::test_util::RunBlockingPoolTask(); 555 google_apis::test_util::RunBlockingPoolTask();
553 EXPECT_EQ(DRIVE_FILE_OK, error); 556 EXPECT_EQ(DRIVE_FILE_OK, error);
554 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir1"), drive_file_path); 557 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1"), drive_file_path);
555 558
556 // dir3 should no longer exist. 559 // dir3 should no longer exist.
557 resource_metadata_->GetEntryInfoByResourceId( 560 resource_metadata_->GetEntryInfoByResourceId(
558 dir3_resource_id, 561 dir3_resource_id,
559 google_apis::test_util::CreateCopyResultCallback( 562 google_apis::test_util::CreateCopyResultCallback(
560 &error, &drive_file_path, &entry_proto)); 563 &error, &drive_file_path, &entry_proto));
561 google_apis::test_util::RunBlockingPoolTask(); 564 google_apis::test_util::RunBlockingPoolTask();
562 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); 565 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
563 EXPECT_FALSE(entry_proto.get()); 566 EXPECT_FALSE(entry_proto.get());
564 567
565 // Remove unknown resource_id using RemoveEntry. 568 // Remove unknown resource_id using RemoveEntry.
566 resource_metadata_->RemoveEntry( 569 resource_metadata_->RemoveEntry(
567 "foo", 570 "foo",
568 google_apis::test_util::CreateCopyResultCallback( 571 google_apis::test_util::CreateCopyResultCallback(
569 &error, &drive_file_path)); 572 &error, &drive_file_path));
570 google_apis::test_util::RunBlockingPoolTask(); 573 google_apis::test_util::RunBlockingPoolTask();
571 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); 574 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
572 575
573 // Try removing root. This should fail. 576 // Try removing root. This should fail.
574 resource_metadata_->RemoveEntry( 577 resource_metadata_->RemoveEntry(
575 kTestRootResourceId, 578 util::kDriveGrandRootSpecialResourceId,
576 google_apis::test_util::CreateCopyResultCallback( 579 google_apis::test_util::CreateCopyResultCallback(
577 &error, &drive_file_path)); 580 &error, &drive_file_path));
578 google_apis::test_util::RunBlockingPoolTask(); 581 google_apis::test_util::RunBlockingPoolTask();
579 EXPECT_EQ(DRIVE_FILE_ERROR_ACCESS_DENIED, error); 582 EXPECT_EQ(DRIVE_FILE_ERROR_ACCESS_DENIED, error);
580 } 583 }
581 584
582 TEST_F(DriveResourceMetadataTest, MoveEntryToDirectory) { 585 TEST_F(DriveResourceMetadataTest, MoveEntryToDirectory) {
583 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 586 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
584 base::FilePath drive_file_path; 587 base::FilePath drive_file_path;
585 scoped_ptr<DriveEntryProto> entry_proto; 588 scoped_ptr<DriveEntryProto> entry_proto;
586 589
587 // Move file8 to drive/dir1. 590 // Move file8 to drive/dir1.
588 resource_metadata_->MoveEntryToDirectory( 591 resource_metadata_->MoveEntryToDirectory(
589 base::FilePath::FromUTF8Unsafe("drive/dir2/file8"), 592 base::FilePath::FromUTF8Unsafe("drive/root/dir2/file8"),
590 base::FilePath::FromUTF8Unsafe("drive/dir1"), 593 base::FilePath::FromUTF8Unsafe("drive/root/dir1"),
591 google_apis::test_util::CreateCopyResultCallback( 594 google_apis::test_util::CreateCopyResultCallback(
592 &error, &drive_file_path)); 595 &error, &drive_file_path));
593 google_apis::test_util::RunBlockingPoolTask(); 596 google_apis::test_util::RunBlockingPoolTask();
594 EXPECT_EQ(DRIVE_FILE_OK, error); 597 EXPECT_EQ(DRIVE_FILE_OK, error);
595 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir1/file8"), 598 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/file8"),
596 drive_file_path); 599 drive_file_path);
597 600
598 // Look up the entry by its resource id and make sure it really moved. 601 // Look up the entry by its resource id and make sure it really moved.
599 resource_metadata_->GetEntryInfoByResourceId( 602 resource_metadata_->GetEntryInfoByResourceId(
600 "resource_id:file8", 603 "resource_id:file8",
601 google_apis::test_util::CreateCopyResultCallback( 604 google_apis::test_util::CreateCopyResultCallback(
602 &error, &drive_file_path, &entry_proto)); 605 &error, &drive_file_path, &entry_proto));
603 google_apis::test_util::RunBlockingPoolTask(); 606 google_apis::test_util::RunBlockingPoolTask();
604 EXPECT_EQ(DRIVE_FILE_OK, error); 607 EXPECT_EQ(DRIVE_FILE_OK, error);
605 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir1/file8"), 608 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/file8"),
606 drive_file_path); 609 drive_file_path);
607 610
608 // Move non-existent file to drive/dir1. This should fail. 611 // Move non-existent file to drive/dir1. This should fail.
609 resource_metadata_->MoveEntryToDirectory( 612 resource_metadata_->MoveEntryToDirectory(
610 base::FilePath::FromUTF8Unsafe("drive/dir2/file8"), 613 base::FilePath::FromUTF8Unsafe("drive/root/dir2/file8"),
611 base::FilePath::FromUTF8Unsafe("drive/dir1"), 614 base::FilePath::FromUTF8Unsafe("drive/root/dir1"),
612 google_apis::test_util::CreateCopyResultCallback( 615 google_apis::test_util::CreateCopyResultCallback(
613 &error, &drive_file_path)); 616 &error, &drive_file_path));
614 google_apis::test_util::RunBlockingPoolTask(); 617 google_apis::test_util::RunBlockingPoolTask();
615 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); 618 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
616 EXPECT_EQ(base::FilePath(), drive_file_path); 619 EXPECT_EQ(base::FilePath(), drive_file_path);
617 620
618 // Move existing file to non-existent directory. This should fail. 621 // Move existing file to non-existent directory. This should fail.
619 resource_metadata_->MoveEntryToDirectory( 622 resource_metadata_->MoveEntryToDirectory(
620 base::FilePath::FromUTF8Unsafe("drive/dir1/file8"), 623 base::FilePath::FromUTF8Unsafe("drive/root/dir1/file8"),
621 base::FilePath::FromUTF8Unsafe("drive/dir4"), 624 base::FilePath::FromUTF8Unsafe("drive/root/dir4"),
622 google_apis::test_util::CreateCopyResultCallback( 625 google_apis::test_util::CreateCopyResultCallback(
623 &error, &drive_file_path)); 626 &error, &drive_file_path));
624 google_apis::test_util::RunBlockingPoolTask(); 627 google_apis::test_util::RunBlockingPoolTask();
625 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); 628 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
626 EXPECT_EQ(base::FilePath(), drive_file_path); 629 EXPECT_EQ(base::FilePath(), drive_file_path);
627 630
628 // Move existing file to existing file (non-directory). This should fail. 631 // Move existing file to existing file (non-directory). This should fail.
629 resource_metadata_->MoveEntryToDirectory( 632 resource_metadata_->MoveEntryToDirectory(
630 base::FilePath::FromUTF8Unsafe("drive/dir1/file8"), 633 base::FilePath::FromUTF8Unsafe("drive/root/dir1/file8"),
631 base::FilePath::FromUTF8Unsafe("drive/dir1/file4"), 634 base::FilePath::FromUTF8Unsafe("drive/root/dir1/file4"),
632 google_apis::test_util::CreateCopyResultCallback( 635 google_apis::test_util::CreateCopyResultCallback(
633 &error, &drive_file_path)); 636 &error, &drive_file_path));
634 google_apis::test_util::RunBlockingPoolTask(); 637 google_apis::test_util::RunBlockingPoolTask();
635 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, error); 638 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, error);
636 EXPECT_EQ(base::FilePath(), drive_file_path); 639 EXPECT_EQ(base::FilePath(), drive_file_path);
637 640
638 // Move the file to root. 641 // Move the file to root.
639 resource_metadata_->MoveEntryToDirectory( 642 resource_metadata_->MoveEntryToDirectory(
640 base::FilePath::FromUTF8Unsafe("drive/dir1/file8"), 643 base::FilePath::FromUTF8Unsafe("drive/root/dir1/file8"),
641 base::FilePath::FromUTF8Unsafe("drive"), 644 base::FilePath::FromUTF8Unsafe("drive/root"),
642 google_apis::test_util::CreateCopyResultCallback( 645 google_apis::test_util::CreateCopyResultCallback(
643 &error, &drive_file_path)); 646 &error, &drive_file_path));
644 google_apis::test_util::RunBlockingPoolTask(); 647 google_apis::test_util::RunBlockingPoolTask();
645 EXPECT_EQ(DRIVE_FILE_OK, error); 648 EXPECT_EQ(DRIVE_FILE_OK, error);
646 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/file8"), drive_file_path); 649 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/file8"),
650 drive_file_path);
647 651
648 // Move the file from root. 652 // Move the file from root.
649 resource_metadata_->MoveEntryToDirectory( 653 resource_metadata_->MoveEntryToDirectory(
650 base::FilePath::FromUTF8Unsafe("drive/file8"), 654 base::FilePath::FromUTF8Unsafe("drive/root/file8"),
651 base::FilePath::FromUTF8Unsafe("drive/dir2"), 655 base::FilePath::FromUTF8Unsafe("drive/root/dir2"),
652 google_apis::test_util::CreateCopyResultCallback( 656 google_apis::test_util::CreateCopyResultCallback(
653 &error, &drive_file_path)); 657 &error, &drive_file_path));
654 google_apis::test_util::RunBlockingPoolTask(); 658 google_apis::test_util::RunBlockingPoolTask();
655 EXPECT_EQ(DRIVE_FILE_OK, error); 659 EXPECT_EQ(DRIVE_FILE_OK, error);
656 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir2/file8"), 660 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir2/file8"),
657 drive_file_path); 661 drive_file_path);
658 662
659 // Make sure file is still ok. 663 // Make sure file is still ok.
660 resource_metadata_->GetEntryInfoByResourceId( 664 resource_metadata_->GetEntryInfoByResourceId(
661 "resource_id:file8", 665 "resource_id:file8",
662 google_apis::test_util::CreateCopyResultCallback( 666 google_apis::test_util::CreateCopyResultCallback(
663 &error, &drive_file_path, &entry_proto)); 667 &error, &drive_file_path, &entry_proto));
664 google_apis::test_util::RunBlockingPoolTask(); 668 google_apis::test_util::RunBlockingPoolTask();
665 EXPECT_EQ(DRIVE_FILE_OK, error); 669 EXPECT_EQ(DRIVE_FILE_OK, error);
666 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir2/file8"), 670 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir2/file8"),
667 drive_file_path); 671 drive_file_path);
668 } 672 }
669 673
670 TEST_F(DriveResourceMetadataTest, RenameEntry) { 674 TEST_F(DriveResourceMetadataTest, RenameEntry) {
671 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 675 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
672 base::FilePath drive_file_path; 676 base::FilePath drive_file_path;
673 scoped_ptr<DriveEntryProto> entry_proto; 677 scoped_ptr<DriveEntryProto> entry_proto;
674 678
675 // Rename file8 to file11. 679 // Rename file8 to file11.
676 resource_metadata_->RenameEntry( 680 resource_metadata_->RenameEntry(
677 base::FilePath::FromUTF8Unsafe("drive/dir2/file8"), 681 base::FilePath::FromUTF8Unsafe("drive/root/dir2/file8"),
678 "file11", 682 "file11",
679 google_apis::test_util::CreateCopyResultCallback( 683 google_apis::test_util::CreateCopyResultCallback(
680 &error, &drive_file_path)); 684 &error, &drive_file_path));
681 google_apis::test_util::RunBlockingPoolTask(); 685 google_apis::test_util::RunBlockingPoolTask();
682 EXPECT_EQ(DRIVE_FILE_OK, error); 686 EXPECT_EQ(DRIVE_FILE_OK, error);
683 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir2/file11"), 687 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir2/file11"),
684 drive_file_path); 688 drive_file_path);
685 689
686 // Lookup the file by resource id to make sure the file actually got renamed. 690 // Lookup the file by resource id to make sure the file actually got renamed.
687 resource_metadata_->GetEntryInfoByResourceId( 691 resource_metadata_->GetEntryInfoByResourceId(
688 "resource_id:file8", 692 "resource_id:file8",
689 google_apis::test_util::CreateCopyResultCallback( 693 google_apis::test_util::CreateCopyResultCallback(
690 &error, &drive_file_path, &entry_proto)); 694 &error, &drive_file_path, &entry_proto));
691 google_apis::test_util::RunBlockingPoolTask(); 695 google_apis::test_util::RunBlockingPoolTask();
692 EXPECT_EQ(DRIVE_FILE_OK, error); 696 EXPECT_EQ(DRIVE_FILE_OK, error);
693 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir2/file11"), 697 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir2/file11"),
694 drive_file_path); 698 drive_file_path);
695 699
696 // Rename to file7 to force a duplicate name. 700 // Rename to file7 to force a duplicate name.
697 resource_metadata_->RenameEntry( 701 resource_metadata_->RenameEntry(
698 base::FilePath::FromUTF8Unsafe("drive/dir2/file11"), 702 base::FilePath::FromUTF8Unsafe("drive/root/dir2/file11"),
699 "file7", 703 "file7",
700 google_apis::test_util::CreateCopyResultCallback( 704 google_apis::test_util::CreateCopyResultCallback(
701 &error, &drive_file_path)); 705 &error, &drive_file_path));
702 google_apis::test_util::RunBlockingPoolTask(); 706 google_apis::test_util::RunBlockingPoolTask();
703 EXPECT_EQ(DRIVE_FILE_OK, error); 707 EXPECT_EQ(DRIVE_FILE_OK, error);
704 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir2/file7 (2)"), 708 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir2/file7 (2)"),
705 drive_file_path); 709 drive_file_path);
706 710
707 // Rename to same name. This should fail. 711 // Rename to same name. This should fail.
708 resource_metadata_->RenameEntry( 712 resource_metadata_->RenameEntry(
709 base::FilePath::FromUTF8Unsafe("drive/dir2/file7 (2)"), 713 base::FilePath::FromUTF8Unsafe("drive/root/dir2/file7 (2)"),
710 "file7 (2)", 714 "file7 (2)",
711 google_apis::test_util::CreateCopyResultCallback( 715 google_apis::test_util::CreateCopyResultCallback(
712 &error, &drive_file_path)); 716 &error, &drive_file_path));
713 google_apis::test_util::RunBlockingPoolTask(); 717 google_apis::test_util::RunBlockingPoolTask();
714 EXPECT_EQ(DRIVE_FILE_ERROR_EXISTS, error); 718 EXPECT_EQ(DRIVE_FILE_ERROR_EXISTS, error);
715 EXPECT_EQ(base::FilePath(), drive_file_path); 719 EXPECT_EQ(base::FilePath(), drive_file_path);
716 720
717 // Rename non-existent. 721 // Rename non-existent.
718 resource_metadata_->RenameEntry( 722 resource_metadata_->RenameEntry(
719 base::FilePath::FromUTF8Unsafe("drive/dir2/file11"), 723 base::FilePath::FromUTF8Unsafe("drive/root/dir2/file11"),
720 "file11", 724 "file11",
721 google_apis::test_util::CreateCopyResultCallback( 725 google_apis::test_util::CreateCopyResultCallback(
722 &error, &drive_file_path)); 726 &error, &drive_file_path));
723 google_apis::test_util::RunBlockingPoolTask(); 727 google_apis::test_util::RunBlockingPoolTask();
724 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); 728 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
725 EXPECT_EQ(base::FilePath(), drive_file_path); 729 EXPECT_EQ(base::FilePath(), drive_file_path);
726 } 730 }
727 731
728 TEST_F(DriveResourceMetadataTest, RefreshEntry) { 732 TEST_F(DriveResourceMetadataTest, RefreshEntry) {
729 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 733 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
730 base::FilePath drive_file_path; 734 base::FilePath drive_file_path;
731 scoped_ptr<DriveEntryProto> entry_proto; 735 scoped_ptr<DriveEntryProto> entry_proto;
732 736
733 // Get file9. 737 // Get file9.
734 entry_proto = GetEntryInfoByPathSync( 738 entry_proto = GetEntryInfoByPathSync(
735 base::FilePath::FromUTF8Unsafe("drive/dir1/dir3/file9")); 739 base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3/file9"));
736 ASSERT_TRUE(entry_proto.get()); 740 ASSERT_TRUE(entry_proto.get());
737 EXPECT_EQ("file9", entry_proto->base_name()); 741 EXPECT_EQ("file9", entry_proto->base_name());
738 ASSERT_TRUE(!entry_proto->file_info().is_directory()); 742 ASSERT_TRUE(!entry_proto->file_info().is_directory());
739 EXPECT_EQ("md5:file9", entry_proto->file_specific_info().file_md5()); 743 EXPECT_EQ("md5:file9", entry_proto->file_specific_info().file_md5());
740 744
741 // Rename it and change the file size. 745 // Rename it and change the file size.
742 DriveEntryProto file_entry_proto(*entry_proto); 746 DriveEntryProto file_entry_proto(*entry_proto);
743 const std::string updated_md5("md5:updated"); 747 const std::string updated_md5("md5:updated");
744 file_entry_proto.mutable_file_specific_info()->set_file_md5(updated_md5); 748 file_entry_proto.mutable_file_specific_info()->set_file_md5(updated_md5);
745 file_entry_proto.set_title("file100"); 749 file_entry_proto.set_title("file100");
746 entry_proto.reset(); 750 entry_proto.reset();
747 resource_metadata_->RefreshEntry( 751 resource_metadata_->RefreshEntry(
748 file_entry_proto, 752 file_entry_proto,
749 google_apis::test_util::CreateCopyResultCallback( 753 google_apis::test_util::CreateCopyResultCallback(
750 &error, &drive_file_path, &entry_proto)); 754 &error, &drive_file_path, &entry_proto));
751 google_apis::test_util::RunBlockingPoolTask(); 755 google_apis::test_util::RunBlockingPoolTask();
752 EXPECT_EQ(DRIVE_FILE_OK, error); 756 EXPECT_EQ(DRIVE_FILE_OK, error);
753 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir1/dir3/file100"), 757 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3/file100"),
754 drive_file_path); 758 drive_file_path);
755 ASSERT_TRUE(entry_proto.get()); 759 ASSERT_TRUE(entry_proto.get());
756 EXPECT_EQ("file100", entry_proto->base_name()); 760 EXPECT_EQ("file100", entry_proto->base_name());
757 ASSERT_TRUE(!entry_proto->file_info().is_directory()); 761 ASSERT_TRUE(!entry_proto->file_info().is_directory());
758 EXPECT_EQ(updated_md5, entry_proto->file_specific_info().file_md5()); 762 EXPECT_EQ(updated_md5, entry_proto->file_specific_info().file_md5());
759 763
760 // Make sure we get the same thing from GetEntryInfoByPath. 764 // Make sure we get the same thing from GetEntryInfoByPath.
761 entry_proto = GetEntryInfoByPathSync( 765 entry_proto = GetEntryInfoByPathSync(
762 base::FilePath::FromUTF8Unsafe("drive/dir1/dir3/file100")); 766 base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3/file100"));
763 ASSERT_TRUE(entry_proto.get()); 767 ASSERT_TRUE(entry_proto.get());
764 EXPECT_EQ("file100", entry_proto->base_name()); 768 EXPECT_EQ("file100", entry_proto->base_name());
765 ASSERT_TRUE(!entry_proto->file_info().is_directory()); 769 ASSERT_TRUE(!entry_proto->file_info().is_directory());
766 EXPECT_EQ(updated_md5, entry_proto->file_specific_info().file_md5()); 770 EXPECT_EQ(updated_md5, entry_proto->file_specific_info().file_md5());
767 771
768 // Get dir2. 772 // Get dir2.
769 entry_proto = GetEntryInfoByPathSync( 773 entry_proto = GetEntryInfoByPathSync(
770 base::FilePath::FromUTF8Unsafe("drive/dir2")); 774 base::FilePath::FromUTF8Unsafe("drive/root/dir2"));
771 ASSERT_TRUE(entry_proto.get()); 775 ASSERT_TRUE(entry_proto.get());
772 EXPECT_EQ("dir2", entry_proto->base_name()); 776 EXPECT_EQ("dir2", entry_proto->base_name());
773 ASSERT_TRUE(entry_proto->file_info().is_directory()); 777 ASSERT_TRUE(entry_proto->file_info().is_directory());
774 778
775 // Change the name to dir100 and change the parent to drive/dir1/dir3. 779 // Change the name to dir100 and change the parent to drive/dir1/dir3.
776 DriveEntryProto dir_entry_proto(*entry_proto); 780 DriveEntryProto dir_entry_proto(*entry_proto);
777 dir_entry_proto.set_title("dir100"); 781 dir_entry_proto.set_title("dir100");
778 dir_entry_proto.set_parent_resource_id("resource_id:dir3"); 782 dir_entry_proto.set_parent_resource_id("resource_id:dir3");
779 entry_proto.reset(); 783 entry_proto.reset();
780 resource_metadata_->RefreshEntry( 784 resource_metadata_->RefreshEntry(
781 dir_entry_proto, 785 dir_entry_proto,
782 google_apis::test_util::CreateCopyResultCallback( 786 google_apis::test_util::CreateCopyResultCallback(
783 &error, &drive_file_path, &entry_proto)); 787 &error, &drive_file_path, &entry_proto));
784 google_apis::test_util::RunBlockingPoolTask(); 788 google_apis::test_util::RunBlockingPoolTask();
785 EXPECT_EQ(DRIVE_FILE_OK, error); 789 EXPECT_EQ(DRIVE_FILE_OK, error);
786 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir1/dir3/dir100"), 790 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3/dir100"),
787 drive_file_path); 791 drive_file_path);
788 ASSERT_TRUE(entry_proto.get()); 792 ASSERT_TRUE(entry_proto.get());
789 EXPECT_EQ("dir100", entry_proto->base_name()); 793 EXPECT_EQ("dir100", entry_proto->base_name());
790 EXPECT_TRUE(entry_proto->file_info().is_directory()); 794 EXPECT_TRUE(entry_proto->file_info().is_directory());
791 EXPECT_EQ("resource_id:dir2", entry_proto->resource_id()); 795 EXPECT_EQ("resource_id:dir2", entry_proto->resource_id());
792 796
793 // Make sure the children have moved over. Test file6. 797 // Make sure the children have moved over. Test file6.
794 entry_proto = GetEntryInfoByPathSync( 798 entry_proto = GetEntryInfoByPathSync(
795 base::FilePath::FromUTF8Unsafe("drive/dir1/dir3/dir100/file6")); 799 base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3/dir100/file6"));
796 ASSERT_TRUE(entry_proto.get()); 800 ASSERT_TRUE(entry_proto.get());
797 EXPECT_EQ("file6", entry_proto->base_name()); 801 EXPECT_EQ("file6", entry_proto->base_name());
798 802
799 // Make sure dir2 no longer exists. 803 // Make sure dir2 no longer exists.
800 entry_proto = GetEntryInfoByPathSync( 804 entry_proto = GetEntryInfoByPathSync(
801 base::FilePath::FromUTF8Unsafe("drive/dir2")); 805 base::FilePath::FromUTF8Unsafe("drive/root/dir2"));
802 EXPECT_FALSE(entry_proto.get()); 806 EXPECT_FALSE(entry_proto.get());
803 } 807 }
804 808
805 // Test the special logic for RefreshEntry of root. 809 // Test the special logic for RefreshEntry of root.
806 TEST_F(DriveResourceMetadataTest, RefreshEntry_Root) { 810 TEST_F(DriveResourceMetadataTest, RefreshEntry_Root) {
807 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 811 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
808 base::FilePath drive_file_path; 812 base::FilePath drive_file_path;
809 scoped_ptr<DriveEntryProto> entry_proto; 813 scoped_ptr<DriveEntryProto> entry_proto;
810 814
811 // Get root. 815 // Get root.
812 entry_proto = GetEntryInfoByPathSync( 816 entry_proto = GetEntryInfoByPathSync(
813 base::FilePath::FromUTF8Unsafe("drive")); 817 base::FilePath::FromUTF8Unsafe("drive"));
814 ASSERT_TRUE(entry_proto.get()); 818 ASSERT_TRUE(entry_proto.get());
815 EXPECT_EQ("drive", entry_proto->base_name()); 819 EXPECT_EQ("drive", entry_proto->base_name());
816 ASSERT_TRUE(entry_proto->file_info().is_directory()); 820 ASSERT_TRUE(entry_proto->file_info().is_directory());
817 EXPECT_EQ(kTestRootResourceId, entry_proto->resource_id()); 821 EXPECT_EQ(util::kDriveGrandRootSpecialResourceId, entry_proto->resource_id());
818 822
819 // Set upload url and call RefreshEntry on root. 823 // Set upload url and call RefreshEntry on root.
820 DriveEntryProto dir_entry_proto(*entry_proto); 824 DriveEntryProto dir_entry_proto(*entry_proto);
821 entry_proto.reset(); 825 entry_proto.reset();
822 resource_metadata_->RefreshEntry( 826 resource_metadata_->RefreshEntry(
823 dir_entry_proto, 827 dir_entry_proto,
824 google_apis::test_util::CreateCopyResultCallback( 828 google_apis::test_util::CreateCopyResultCallback(
825 &error, &drive_file_path, &entry_proto)); 829 &error, &drive_file_path, &entry_proto));
826 google_apis::test_util::RunBlockingPoolTask(); 830 google_apis::test_util::RunBlockingPoolTask();
827 EXPECT_EQ(DRIVE_FILE_OK, error); 831 EXPECT_EQ(DRIVE_FILE_OK, error);
828 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive"), drive_file_path); 832 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive"), drive_file_path);
829 ASSERT_TRUE(entry_proto.get()); 833 ASSERT_TRUE(entry_proto.get());
830 EXPECT_EQ("drive", entry_proto->base_name()); 834 EXPECT_EQ("drive", entry_proto->base_name());
831 EXPECT_TRUE(entry_proto->file_info().is_directory()); 835 EXPECT_TRUE(entry_proto->file_info().is_directory());
832 EXPECT_EQ(kTestRootResourceId, entry_proto->resource_id()); 836 EXPECT_EQ(util::kDriveGrandRootSpecialResourceId, entry_proto->resource_id());
833 837
834 // Make sure the children have moved over. Test file9. 838 // Make sure the children have moved over. Test file9.
835 entry_proto.reset(); 839 entry_proto.reset();
836 entry_proto = GetEntryInfoByPathSync( 840 entry_proto = GetEntryInfoByPathSync(
837 base::FilePath::FromUTF8Unsafe("drive/dir1/dir3/file9")); 841 base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3/file9"));
838 ASSERT_TRUE(entry_proto.get()); 842 ASSERT_TRUE(entry_proto.get());
839 EXPECT_EQ("file9", entry_proto->base_name()); 843 EXPECT_EQ("file9", entry_proto->base_name());
840 844
841 // Refreshing root with a proto which has parent_resource_id should fail. 845 // Refreshing root with a proto which has parent_resource_id should fail.
842 entry_proto = GetEntryInfoByPathSync( 846 entry_proto = GetEntryInfoByPathSync(
843 base::FilePath::FromUTF8Unsafe("drive")); 847 base::FilePath::FromUTF8Unsafe("drive"));
844 ASSERT_TRUE(entry_proto.get()); 848 ASSERT_TRUE(entry_proto.get());
845 entry_proto->set_parent_resource_id("foo"); 849 entry_proto->set_parent_resource_id("foo");
846 resource_metadata_->RefreshEntry( 850 resource_metadata_->RefreshEntry(
847 *entry_proto, 851 *entry_proto,
848 google_apis::test_util::CreateCopyResultCallback( 852 google_apis::test_util::CreateCopyResultCallback(
849 &error, &drive_file_path, &entry_proto)); 853 &error, &drive_file_path, &entry_proto));
850 google_apis::test_util::RunBlockingPoolTask(); 854 google_apis::test_util::RunBlockingPoolTask();
851 EXPECT_EQ(DRIVE_FILE_ERROR_INVALID_OPERATION, error); 855 EXPECT_EQ(DRIVE_FILE_ERROR_INVALID_OPERATION, error);
852 } 856 }
853 857
854 TEST_F(DriveResourceMetadataTest, RefreshDirectory_EmtpyMap) { 858 TEST_F(DriveResourceMetadataTest, RefreshDirectory_EmtpyMap) {
855 base::FilePath kDirectoryPath(FILE_PATH_LITERAL("drive/dir1")); 859 base::FilePath kDirectoryPath(FILE_PATH_LITERAL("drive/root/dir1"));
856 const int64 kNewChangestamp = kTestChangestamp + 1; 860 const int64 kNewChangestamp = kTestChangestamp + 1;
857 861
858 // Read the directory. 862 // Read the directory.
859 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 863 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
860 scoped_ptr<DriveEntryProtoVector> entries; 864 scoped_ptr<DriveEntryProtoVector> entries;
861 entries = ReadDirectoryByPathSync(base::FilePath(kDirectoryPath)); 865 entries = ReadDirectoryByPathSync(base::FilePath(kDirectoryPath));
862 ASSERT_TRUE(entries.get()); 866 ASSERT_TRUE(entries.get());
863 // "file4", "file5", "dir3" should exist in drive/dir1. 867 // "file4", "file5", "dir3" should exist in drive/dir1.
864 ASSERT_EQ(3U, entries->size()); 868 ASSERT_EQ(3U, entries->size());
865 std::vector<std::string> base_names = GetSortedBaseNames(*entries); 869 std::vector<std::string> base_names = GetSortedBaseNames(*entries);
(...skipping 29 matching lines...) Expand all
895 899
896 // Read the directory again. 900 // Read the directory again.
897 entries = ReadDirectoryByPathSync(base::FilePath(kDirectoryPath)); 901 entries = ReadDirectoryByPathSync(base::FilePath(kDirectoryPath));
898 ASSERT_TRUE(entries.get()); 902 ASSERT_TRUE(entries.get());
899 // All entries ("file4", "file5", "dir3") should be gone now, as 903 // All entries ("file4", "file5", "dir3") should be gone now, as
900 // RefreshDirectory() was called with an empty map. 904 // RefreshDirectory() was called with an empty map.
901 ASSERT_TRUE(entries->empty()); 905 ASSERT_TRUE(entries->empty());
902 } 906 }
903 907
904 TEST_F(DriveResourceMetadataTest, RefreshDirectory_NonEmptyMap) { 908 TEST_F(DriveResourceMetadataTest, RefreshDirectory_NonEmptyMap) {
905 base::FilePath kDirectoryPath(FILE_PATH_LITERAL("drive/dir1")); 909 base::FilePath kDirectoryPath(FILE_PATH_LITERAL("drive/root/dir1"));
906 const int64 kNewChangestamp = kTestChangestamp + 1; 910 const int64 kNewChangestamp = kTestChangestamp + 1;
907 911
908 // Read the directory. 912 // Read the directory.
909 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 913 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
910 scoped_ptr<DriveEntryProtoVector> entries; 914 scoped_ptr<DriveEntryProtoVector> entries;
911 entries = ReadDirectoryByPathSync(kDirectoryPath); 915 entries = ReadDirectoryByPathSync(kDirectoryPath);
912 ASSERT_TRUE(entries.get()); 916 ASSERT_TRUE(entries.get());
913 // "file4", "file5", "dir3" should exist in drive/dir1. 917 // "file4", "file5", "dir3" should exist in drive/dir1.
914 ASSERT_EQ(3U, entries->size()); 918 ASSERT_EQ(3U, entries->size());
915 std::vector<std::string> base_names = GetSortedBaseNames(*entries); 919 std::vector<std::string> base_names = GetSortedBaseNames(*entries);
916 EXPECT_EQ("dir3", base_names[0]); 920 EXPECT_EQ("dir3", base_names[0]);
917 EXPECT_EQ("file4", base_names[1]); 921 EXPECT_EQ("file4", base_names[1]);
918 EXPECT_EQ("file5", base_names[2]); 922 EXPECT_EQ("file5", base_names[2]);
919 923
920 // Get the directory dir1. 924 // Get the directory dir1.
921 scoped_ptr<DriveEntryProto> dir1_proto; 925 scoped_ptr<DriveEntryProto> dir1_proto;
922 dir1_proto = GetEntryInfoByPathSync(kDirectoryPath); 926 dir1_proto = GetEntryInfoByPathSync(kDirectoryPath);
923 ASSERT_TRUE(dir1_proto.get()); 927 ASSERT_TRUE(dir1_proto.get());
924 // The changestamp should be initially kTestChangestamp. 928 // The changestamp should be initially kTestChangestamp.
925 EXPECT_EQ(kTestChangestamp, 929 EXPECT_EQ(kTestChangestamp,
926 dir1_proto->directory_specific_info().changestamp()); 930 dir1_proto->directory_specific_info().changestamp());
927 931
928 // Get the directory dir2 (existing non-child directory). 932 // Get the directory dir2 (existing non-child directory).
929 // This directory will be moved to "drive/dir1/dir2". 933 // This directory will be moved to "drive/dir1/dir2".
930 scoped_ptr<DriveEntryProto> dir2_proto; 934 scoped_ptr<DriveEntryProto> dir2_proto;
931 dir2_proto = GetEntryInfoByPathSync( 935 dir2_proto = GetEntryInfoByPathSync(
932 base::FilePath::FromUTF8Unsafe("drive/dir2")); 936 base::FilePath::FromUTF8Unsafe("drive/root/dir2"));
933 ASSERT_TRUE(dir2_proto.get()); 937 ASSERT_TRUE(dir2_proto.get());
934 EXPECT_EQ(kTestChangestamp, 938 EXPECT_EQ(kTestChangestamp,
935 dir2_proto->directory_specific_info().changestamp()); 939 dir2_proto->directory_specific_info().changestamp());
936 // Change the parent resource ID, as dir2 will be moved to "drive/dir1/dir2". 940 // Change the parent resource ID, as dir2 will be moved to "drive/dir1/dir2".
937 dir2_proto->set_parent_resource_id(dir1_proto->resource_id()); 941 dir2_proto->set_parent_resource_id(dir1_proto->resource_id());
938 942
939 // Get the directory dir3 (existing child directory). 943 // Get the directory dir3 (existing child directory).
940 // This directory will remain as "drive/dir1/dir3". 944 // This directory will remain as "drive/dir1/dir3".
941 scoped_ptr<DriveEntryProto> dir3_proto; 945 scoped_ptr<DriveEntryProto> dir3_proto;
942 dir3_proto = GetEntryInfoByPathSync( 946 dir3_proto = GetEntryInfoByPathSync(
943 base::FilePath::FromUTF8Unsafe("drive/dir1/dir3")); 947 base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3"));
944 ASSERT_TRUE(dir3_proto.get()); 948 ASSERT_TRUE(dir3_proto.get());
945 EXPECT_EQ(kTestChangestamp, 949 EXPECT_EQ(kTestChangestamp,
946 dir3_proto->directory_specific_info().changestamp()); 950 dir3_proto->directory_specific_info().changestamp());
947 951
948 // Create a map. 952 // Create a map.
949 DriveEntryProtoMap entry_map; 953 DriveEntryProtoMap entry_map;
950 954
951 // Add a new file to the map. 955 // Add a new file to the map.
952 DriveEntryProto new_file; 956 DriveEntryProto new_file;
953 new_file.set_title("new_file"); 957 new_file.set_title("new_file");
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 ASSERT_EQ(4U, entries->size()); 996 ASSERT_EQ(4U, entries->size());
993 base_names = GetSortedBaseNames(*entries); 997 base_names = GetSortedBaseNames(*entries);
994 EXPECT_EQ("dir2", base_names[0]); 998 EXPECT_EQ("dir2", base_names[0]);
995 EXPECT_EQ("dir3", base_names[1]); 999 EXPECT_EQ("dir3", base_names[1]);
996 EXPECT_EQ("new_directory", base_names[2]); 1000 EXPECT_EQ("new_directory", base_names[2]);
997 EXPECT_EQ("new_file", base_names[3]); 1001 EXPECT_EQ("new_file", base_names[3]);
998 1002
999 // Get the new directory. 1003 // Get the new directory.
1000 scoped_ptr<DriveEntryProto> new_directory_proto; 1004 scoped_ptr<DriveEntryProto> new_directory_proto;
1001 new_directory_proto = GetEntryInfoByPathSync( 1005 new_directory_proto = GetEntryInfoByPathSync(
1002 base::FilePath::FromUTF8Unsafe("drive/dir1/new_directory")); 1006 base::FilePath::FromUTF8Unsafe("drive/root/dir1/new_directory"));
1003 ASSERT_TRUE(new_directory_proto.get()); 1007 ASSERT_TRUE(new_directory_proto.get());
1004 // The changestamp should be 0 for a new directory. 1008 // The changestamp should be 0 for a new directory.
1005 EXPECT_EQ(0, new_directory_proto->directory_specific_info().changestamp()); 1009 EXPECT_EQ(0, new_directory_proto->directory_specific_info().changestamp());
1006 1010
1007 // Get the directory dir3 (existing child directory) again. 1011 // Get the directory dir3 (existing child directory) again.
1008 dir3_proto = GetEntryInfoByPathSync( 1012 dir3_proto = GetEntryInfoByPathSync(
1009 base::FilePath::FromUTF8Unsafe("drive/dir1/dir3")); 1013 base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3"));
1010 ASSERT_TRUE(dir3_proto.get()); 1014 ASSERT_TRUE(dir3_proto.get());
1011 // The changestamp should not be changed. 1015 // The changestamp should not be changed.
1012 EXPECT_EQ(kTestChangestamp, 1016 EXPECT_EQ(kTestChangestamp,
1013 dir3_proto->directory_specific_info().changestamp()); 1017 dir3_proto->directory_specific_info().changestamp());
1014 1018
1015 // Read the directory dir3. The contents should remain. 1019 // Read the directory dir3. The contents should remain.
1016 // See the comment at Init() for the contents of the dir3. 1020 // See the comment at Init() for the contents of the dir3.
1017 entries = ReadDirectoryByPathSync( 1021 entries = ReadDirectoryByPathSync(
1018 base::FilePath::FromUTF8Unsafe("drive/dir1/dir3")); 1022 base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3"));
1019 ASSERT_TRUE(entries.get()); 1023 ASSERT_TRUE(entries.get());
1020 ASSERT_EQ(2U, entries->size()); 1024 ASSERT_EQ(2U, entries->size());
1021 1025
1022 // Get the directory dir2 (existing non-child directory) again using the 1026 // Get the directory dir2 (existing non-child directory) again using the
1023 // old path. This should fail, as dir2 is now moved to drive/dir1/dir2. 1027 // old path. This should fail, as dir2 is now moved to drive/dir1/dir2.
1024 dir2_proto = GetEntryInfoByPathSync( 1028 dir2_proto = GetEntryInfoByPathSync(
1025 base::FilePath::FromUTF8Unsafe("drive/dir2")); 1029 base::FilePath::FromUTF8Unsafe("drive/root/dir2"));
1026 ASSERT_FALSE(dir2_proto.get()); 1030 ASSERT_FALSE(dir2_proto.get());
1027 1031
1028 // Get the directory dir2 (existing non-child directory) again using the 1032 // Get the directory dir2 (existing non-child directory) again using the
1029 // new path. This should succeed. 1033 // new path. This should succeed.
1030 dir2_proto = GetEntryInfoByPathSync( 1034 dir2_proto = GetEntryInfoByPathSync(
1031 base::FilePath::FromUTF8Unsafe("drive/dir1/dir2")); 1035 base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir2"));
1032 ASSERT_TRUE(dir2_proto.get()); 1036 ASSERT_TRUE(dir2_proto.get());
1033 // The changestamp should not be changed. 1037 // The changestamp should not be changed.
1034 EXPECT_EQ(kTestChangestamp, 1038 EXPECT_EQ(kTestChangestamp,
1035 dir2_proto->directory_specific_info().changestamp()); 1039 dir2_proto->directory_specific_info().changestamp());
1036 1040
1037 // Read the directory dir2. The contents should remain. 1041 // Read the directory dir2. The contents should remain.
1038 // See the comment at Init() for the contents of the dir2. 1042 // See the comment at Init() for the contents of the dir2.
1039 entries = ReadDirectoryByPathSync( 1043 entries = ReadDirectoryByPathSync(
1040 base::FilePath::FromUTF8Unsafe("drive/dir1/dir2")); 1044 base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir2"));
1041 ASSERT_TRUE(entries.get()); 1045 ASSERT_TRUE(entries.get());
1042 ASSERT_EQ(3U, entries->size()); 1046 ASSERT_EQ(3U, entries->size());
1043 } 1047 }
1044 1048
1045 TEST_F(DriveResourceMetadataTest, RefreshDirectory_WrongParentResourceId) { 1049 TEST_F(DriveResourceMetadataTest, RefreshDirectory_WrongParentResourceId) {
1046 base::FilePath kDirectoryPath(FILE_PATH_LITERAL("drive/dir1")); 1050 base::FilePath kDirectoryPath(FILE_PATH_LITERAL("drive/root/dir1"));
1047 const int64 kNewChangestamp = kTestChangestamp + 1; 1051 const int64 kNewChangestamp = kTestChangestamp + 1;
1048 1052
1049 // Get the directory dir1. 1053 // Get the directory dir1.
1050 scoped_ptr<DriveEntryProto> dir1_proto; 1054 scoped_ptr<DriveEntryProto> dir1_proto;
1051 dir1_proto = GetEntryInfoByPathSync(kDirectoryPath); 1055 dir1_proto = GetEntryInfoByPathSync(kDirectoryPath);
1052 ASSERT_TRUE(dir1_proto.get()); 1056 ASSERT_TRUE(dir1_proto.get());
1053 1057
1054 // Create a map and add a new file to it. 1058 // Create a map and add a new file to it.
1055 DriveEntryProtoMap entry_map; 1059 DriveEntryProtoMap entry_map;
1056 DriveEntryProto new_file; 1060 DriveEntryProto new_file;
(...skipping 30 matching lines...) Expand all
1087 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 1091 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1088 base::FilePath drive_file_path; 1092 base::FilePath drive_file_path;
1089 1093
1090 // Add to dir3. 1094 // Add to dir3.
1091 resource_metadata_->AddEntry( 1095 resource_metadata_->AddEntry(
1092 file_entry_proto, 1096 file_entry_proto,
1093 google_apis::test_util::CreateCopyResultCallback( 1097 google_apis::test_util::CreateCopyResultCallback(
1094 &error, &drive_file_path)); 1098 &error, &drive_file_path));
1095 google_apis::test_util::RunBlockingPoolTask(); 1099 google_apis::test_util::RunBlockingPoolTask();
1096 EXPECT_EQ(DRIVE_FILE_OK, error); 1100 EXPECT_EQ(DRIVE_FILE_OK, error);
1097 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir1/dir3/file100"), 1101 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3/file100"),
1098 drive_file_path); 1102 drive_file_path);
1099 1103
1100 // Add a directory. 1104 // Add a directory.
1101 DriveEntryProto dir_entry_proto = CreateDriveEntryProto( 1105 DriveEntryProto dir_entry_proto = CreateDriveEntryProto(
1102 sequence_id++, true, "resource_id:dir1"); 1106 sequence_id++, true, "resource_id:dir1");
1103 1107
1104 resource_metadata_->AddEntry( 1108 resource_metadata_->AddEntry(
1105 dir_entry_proto, 1109 dir_entry_proto,
1106 google_apis::test_util::CreateCopyResultCallback( 1110 google_apis::test_util::CreateCopyResultCallback(
1107 &error, &drive_file_path)); 1111 &error, &drive_file_path));
1108 google_apis::test_util::RunBlockingPoolTask(); 1112 google_apis::test_util::RunBlockingPoolTask();
1109 EXPECT_EQ(DRIVE_FILE_OK, error); 1113 EXPECT_EQ(DRIVE_FILE_OK, error);
1110 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir1/dir101"), 1114 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir101"),
1111 drive_file_path); 1115 drive_file_path);
1112 1116
1113 // Add to an invalid parent. 1117 // Add to an invalid parent.
1114 DriveEntryProto file_entry_proto3 = CreateDriveEntryProto( 1118 DriveEntryProto file_entry_proto3 = CreateDriveEntryProto(
1115 sequence_id++, false, "resource_id:invalid"); 1119 sequence_id++, false, "resource_id:invalid");
1116 1120
1117 resource_metadata_->AddEntry( 1121 resource_metadata_->AddEntry(
1118 file_entry_proto3, 1122 file_entry_proto3,
1119 google_apis::test_util::CreateCopyResultCallback( 1123 google_apis::test_util::CreateCopyResultCallback(
1120 &error, &drive_file_path)); 1124 &error, &drive_file_path));
(...skipping 26 matching lines...) Expand all
1147 google_apis::test_util::RunBlockingPoolTask(); 1151 google_apis::test_util::RunBlockingPoolTask();
1148 EXPECT_TRUE(child_directories.empty()); 1152 EXPECT_TRUE(child_directories.empty());
1149 1153
1150 // dir1: dir3 is the only child 1154 // dir1: dir3 is the only child
1151 resource_metadata_->GetChildDirectories( 1155 resource_metadata_->GetChildDirectories(
1152 "resource_id:dir1", 1156 "resource_id:dir1",
1153 google_apis::test_util::CreateCopyResultCallback(&child_directories)); 1157 google_apis::test_util::CreateCopyResultCallback(&child_directories));
1154 google_apis::test_util::RunBlockingPoolTask(); 1158 google_apis::test_util::RunBlockingPoolTask();
1155 EXPECT_EQ(1u, child_directories.size()); 1159 EXPECT_EQ(1u, child_directories.size());
1156 EXPECT_EQ(1u, child_directories.count( 1160 EXPECT_EQ(1u, child_directories.count(
1157 base::FilePath::FromUTF8Unsafe("drive/dir1/dir3"))); 1161 base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3")));
1158 1162
1159 // Add a few more directories to make sure deeper nesting works. 1163 // Add a few more directories to make sure deeper nesting works.
1160 // dir2/dir100 1164 // dir2/dir100
1161 // dir2/dir101 1165 // dir2/dir101
1162 // dir2/dir101/dir102 1166 // dir2/dir101/dir102
1163 // dir2/dir101/dir103 1167 // dir2/dir101/dir103
1164 // dir2/dir101/dir104 1168 // dir2/dir101/dir104
1165 // dir2/dir101/dir102/dir105 1169 // dir2/dir101/dir102/dir105
1166 // dir2/dir101/dir102/dir105/dir106 1170 // dir2/dir101/dir102/dir105/dir106
1167 // dir2/dir101/dir102/dir105/dir106/dir107 1171 // dir2/dir101/dir102/dir105/dir106/dir107
(...skipping 14 matching lines...) Expand all
1182 resource_metadata_.get(), sequence_id++, true, "resource_id:dir105")); 1186 resource_metadata_.get(), sequence_id++, true, "resource_id:dir105"));
1183 ASSERT_TRUE(AddDriveEntryProto( 1187 ASSERT_TRUE(AddDriveEntryProto(
1184 resource_metadata_.get(), sequence_id++, true, "resource_id:dir106")); 1188 resource_metadata_.get(), sequence_id++, true, "resource_id:dir106"));
1185 1189
1186 resource_metadata_->GetChildDirectories( 1190 resource_metadata_->GetChildDirectories(
1187 "resource_id:dir2", 1191 "resource_id:dir2",
1188 google_apis::test_util::CreateCopyResultCallback(&child_directories)); 1192 google_apis::test_util::CreateCopyResultCallback(&child_directories));
1189 google_apis::test_util::RunBlockingPoolTask(); 1193 google_apis::test_util::RunBlockingPoolTask();
1190 EXPECT_EQ(8u, child_directories.size()); 1194 EXPECT_EQ(8u, child_directories.size());
1191 EXPECT_EQ(1u, child_directories.count(base::FilePath::FromUTF8Unsafe( 1195 EXPECT_EQ(1u, child_directories.count(base::FilePath::FromUTF8Unsafe(
1192 "drive/dir2/dir101"))); 1196 "drive/root/dir2/dir101")));
1193 EXPECT_EQ(1u, child_directories.count(base::FilePath::FromUTF8Unsafe( 1197 EXPECT_EQ(1u, child_directories.count(base::FilePath::FromUTF8Unsafe(
1194 "drive/dir2/dir101/dir104"))); 1198 "drive/root/dir2/dir101/dir104")));
1195 EXPECT_EQ(1u, child_directories.count(base::FilePath::FromUTF8Unsafe( 1199 EXPECT_EQ(1u, child_directories.count(base::FilePath::FromUTF8Unsafe(
1196 "drive/dir2/dir101/dir102/dir105/dir106/dir107"))); 1200 "drive/root/dir2/dir101/dir102/dir105/dir106/dir107")));
1197 } 1201 }
1198 1202
1199 TEST_F(DriveResourceMetadataTest, RemoveAll) { 1203 TEST_F(DriveResourceMetadataTest, RemoveAll) {
1200 // root has children. 1204 // The grand root has "root" which is not empty.
1201 scoped_ptr<DriveEntryProtoVector> entries; 1205 scoped_ptr<DriveEntryProtoVector> entries;
1202 entries = ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive")); 1206 entries = ReadDirectoryByPathSync(
1207 base::FilePath::FromUTF8Unsafe("drive/root"));
1203 ASSERT_TRUE(entries.get()); 1208 ASSERT_TRUE(entries.get());
1204 ASSERT_FALSE(entries->empty()); 1209 ASSERT_FALSE(entries->empty());
1205 1210
1206 // remove all children. 1211 // remove all children.
1207 resource_metadata_->RemoveAll(base::Bind(&base::DoNothing)); 1212 resource_metadata_->RemoveAll(base::Bind(&base::DoNothing));
1208 google_apis::test_util::RunBlockingPoolTask(); 1213 google_apis::test_util::RunBlockingPoolTask();
1209 1214
1210 base::FilePath drive_file_path; 1215 base::FilePath drive_file_path;
1211 scoped_ptr<DriveEntryProto> entry_proto; 1216 scoped_ptr<DriveEntryProto> entry_proto;
1212 1217
1213 // root should continue to exist. 1218 // root should continue to exist.
1214 entry_proto = GetEntryInfoByPathSync(base::FilePath::FromUTF8Unsafe("drive")); 1219 entry_proto = GetEntryInfoByPathSync(base::FilePath::FromUTF8Unsafe("drive"));
1215 ASSERT_TRUE(entry_proto.get()); 1220 ASSERT_TRUE(entry_proto.get());
1216 EXPECT_EQ("drive", entry_proto->base_name()); 1221 EXPECT_EQ("drive", entry_proto->base_name());
1217 ASSERT_TRUE(entry_proto->file_info().is_directory()); 1222 ASSERT_TRUE(entry_proto->file_info().is_directory());
1218 EXPECT_EQ(kTestRootResourceId, entry_proto->resource_id()); 1223 EXPECT_EQ(util::kDriveGrandRootSpecialResourceId, entry_proto->resource_id());
1219 1224
1220 // root should have no children. 1225 // There is "root" and "other", which are both empty.
1221 entries = ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive")); 1226 entries = ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive"));
1222 ASSERT_TRUE(entries.get()); 1227 ASSERT_TRUE(entries.get());
1223 EXPECT_TRUE(entries->empty()); 1228 EXPECT_EQ(2U, entries->size());
1229
1230 scoped_ptr<DriveEntryProtoVector> entries_in_mydrive =
1231 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive/root"));
1232 ASSERT_TRUE(entries_in_mydrive.get());
1233 EXPECT_TRUE(entries_in_mydrive->empty());
1234
1235 scoped_ptr<DriveEntryProtoVector> entries_in_other =
1236 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive/other"));
1237 ASSERT_TRUE(entries_in_other.get());
1238 EXPECT_TRUE(entries_in_other->empty());
1239
1224 } 1240 }
1225 1241
1226 TEST_F(DriveResourceMetadataTest, PerDirectoryChangestamp) { 1242 TEST_F(DriveResourceMetadataTest, PerDirectoryChangestamp) {
1227 const int kNewChangestamp = kTestChangestamp + 1; 1243 const int kNewChangestamp = kTestChangestamp + 1;
1228 const char kSubDirectoryResourceId[] = "sub-directory-id"; 1244 const char kSubDirectoryResourceId[] = "sub-directory-id";
1229 1245
1230 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests> 1246 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests>
1231 resource_metadata_original(new DriveResourceMetadata( 1247 resource_metadata_original(new DriveResourceMetadata(
1232 kTestRootResourceId, temp_dir_.path(), blocking_task_runner_)); 1248 kTestRootResourceId, temp_dir_.path(), blocking_task_runner_));
1233 ForceUsingMemoryStorage(resource_metadata_original.get()); 1249 ForceUsingMemoryStorage(resource_metadata_original.get());
(...skipping 19 matching lines...) Expand all
1253 base::FilePath file_path; 1269 base::FilePath file_path;
1254 resource_metadata_original->AddEntry( 1270 resource_metadata_original->AddEntry(
1255 directory_entry, 1271 directory_entry,
1256 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); 1272 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
1257 // At this point, both the root and the sub directory do not contain the 1273 // At this point, both the root and the sub directory do not contain the
1258 // per-directory changestamp. 1274 // per-directory changestamp.
1259 resource_metadata_original->MaybeSave(); 1275 resource_metadata_original->MaybeSave();
1260 google_apis::test_util::RunBlockingPoolTask(); 1276 google_apis::test_util::RunBlockingPoolTask();
1261 1277
1262 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests> 1278 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests>
1263 resource_metadata(new DriveResourceMetadata(kTestRootResourceId, 1279 resource_metadata(new DriveResourceMetadata(
1264 temp_dir_.path(), 1280 util::kDriveGrandRootSpecialResourceId,
1265 blocking_task_runner_)); 1281 temp_dir_.path(),
1282 blocking_task_runner_));
1266 ForceUsingMemoryStorage(resource_metadata.get()); 1283 ForceUsingMemoryStorage(resource_metadata.get());
1267 1284
1268 resource_metadata->Initialize( 1285 resource_metadata->Initialize(
1269 google_apis::test_util::CreateCopyResultCallback(&error)); 1286 google_apis::test_util::CreateCopyResultCallback(&error));
1270 google_apis::test_util::RunBlockingPoolTask(); 1287 google_apis::test_util::RunBlockingPoolTask();
1271 ASSERT_EQ(DRIVE_FILE_OK, error); 1288 ASSERT_EQ(DRIVE_FILE_OK, error);
1272 1289
1273 // Load. This should propagate the largest changestamp to every directory. 1290 // Load. This should propagate the largest changestamp to every directory.
1274 resource_metadata->Load( 1291 resource_metadata->Load(
1275 google_apis::test_util::CreateCopyResultCallback(&error)); 1292 google_apis::test_util::CreateCopyResultCallback(&error));
1276 google_apis::test_util::RunBlockingPoolTask(); 1293 google_apis::test_util::RunBlockingPoolTask();
1277 EXPECT_EQ(DRIVE_FILE_OK, error); 1294 EXPECT_EQ(DRIVE_FILE_OK, error);
1278 1295
1279 // Confirm that the root directory contains the changestamp. 1296 // Confirm that the root directory contains the changestamp.
1280 scoped_ptr<DriveEntryProto> entry_proto; 1297 scoped_ptr<DriveEntryProto> entry_proto;
1281 resource_metadata->GetEntryInfoByPath( 1298 resource_metadata->GetEntryInfoByPath(
1282 base::FilePath::FromUTF8Unsafe("drive"), 1299 base::FilePath::FromUTF8Unsafe("drive"),
1283 google_apis::test_util::CreateCopyResultCallback(&error, &entry_proto)); 1300 google_apis::test_util::CreateCopyResultCallback(&error, &entry_proto));
1284 google_apis::test_util::RunBlockingPoolTask(); 1301 google_apis::test_util::RunBlockingPoolTask();
1285 ASSERT_EQ(DRIVE_FILE_OK, error); 1302 ASSERT_EQ(DRIVE_FILE_OK, error);
1286 EXPECT_EQ(kNewChangestamp, 1303 EXPECT_EQ(kNewChangestamp,
1287 entry_proto->directory_specific_info().changestamp()); 1304 entry_proto->directory_specific_info().changestamp());
1288 1305
1289 // Confirm that the sub directory contains the changestamp. 1306 // Confirm that the sub directory contains the changestamp.
1290 resource_metadata->GetEntryInfoByPath( 1307 resource_metadata->GetEntryInfoByPath(
1291 base::FilePath::FromUTF8Unsafe("drive/directory"), 1308 base::FilePath::FromUTF8Unsafe("drive/root/directory"),
1292 google_apis::test_util::CreateCopyResultCallback(&error, &entry_proto)); 1309 google_apis::test_util::CreateCopyResultCallback(&error, &entry_proto));
1293 google_apis::test_util::RunBlockingPoolTask(); 1310 google_apis::test_util::RunBlockingPoolTask();
1294 ASSERT_EQ(DRIVE_FILE_OK, error); 1311 ASSERT_EQ(DRIVE_FILE_OK, error);
1295 EXPECT_EQ(kNewChangestamp, 1312 EXPECT_EQ(kNewChangestamp,
1296 entry_proto->directory_specific_info().changestamp()); 1313 entry_proto->directory_specific_info().changestamp());
1297 } 1314 }
1298 1315
1299 TEST_F(DriveResourceMetadataTest, SaveAndLoad) { 1316 TEST_F(DriveResourceMetadataTest, SaveAndLoad) {
1300 // Save metadata and reset. 1317 // Save metadata and reset.
1301 resource_metadata_->MaybeSave(); 1318 resource_metadata_->MaybeSave();
1302 1319
1303 resource_metadata_.reset(new DriveResourceMetadata(kTestRootResourceId, 1320 resource_metadata_.reset(new DriveResourceMetadata(
1304 temp_dir_.path(), 1321 util::kDriveGrandRootSpecialResourceId,
1305 blocking_task_runner_)); 1322 temp_dir_.path(),
1323 blocking_task_runner_));
1306 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 1324 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1307 resource_metadata_->Initialize( 1325 resource_metadata_->Initialize(
1308 google_apis::test_util::CreateCopyResultCallback(&error)); 1326 google_apis::test_util::CreateCopyResultCallback(&error));
1309 google_apis::test_util::RunBlockingPoolTask(); 1327 google_apis::test_util::RunBlockingPoolTask();
1310 ASSERT_EQ(DRIVE_FILE_OK, error); 1328 ASSERT_EQ(DRIVE_FILE_OK, error);
1311 1329
1312 // Load metadata. 1330 // Load metadata.
1313 resource_metadata_->Load( 1331 resource_metadata_->Load(
1314 google_apis::test_util::CreateCopyResultCallback(&error)); 1332 google_apis::test_util::CreateCopyResultCallback(&error));
1315 google_apis::test_util::RunBlockingPoolTask(); 1333 google_apis::test_util::RunBlockingPoolTask();
1316 EXPECT_EQ(DRIVE_FILE_OK, error); 1334 EXPECT_EQ(DRIVE_FILE_OK, error);
1317 1335
1318 // Try to get some data. 1336 // Try to get some data.
1319 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync( 1337 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(
1320 base::FilePath::FromUTF8Unsafe("drive/dir1/dir3/file9")); 1338 base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3/file9"));
1321 ASSERT_TRUE(entry.get()); 1339 ASSERT_TRUE(entry.get());
1322 EXPECT_EQ("file9", entry->base_name()); 1340 EXPECT_EQ("file9", entry->base_name());
1323 ASSERT_TRUE(!entry->file_info().is_directory()); 1341 ASSERT_TRUE(!entry->file_info().is_directory());
1324 EXPECT_EQ("md5:file9", entry->file_specific_info().file_md5()); 1342 EXPECT_EQ("md5:file9", entry->file_specific_info().file_md5());
1325 } 1343 }
1326 1344
1327 } // namespace drive 1345 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698