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

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

Issue 11293247: Make DriveFeedProcessor asynchronous. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: merge conflicts + feedback Created 8 years, 1 month 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
« no previous file with comments | « chrome/browser/chromeos/drive/drive_resource_metadata.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (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/string_number_conversions.h" 14 #include "base/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_files.h"
19 #include "chrome/browser/chromeos/drive/drive_test_util.h" 18 #include "chrome/browser/chromeos/drive/drive_test_util.h"
20 #include "chrome/browser/google_apis/time_util.h" 19 #include "chrome/browser/google_apis/time_util.h"
21 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
22 #include "content/public/test/test_browser_thread.h" 21 #include "content/public/test/test_browser_thread.h"
23 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
24 23
25 namespace drive { 24 namespace drive {
26 namespace { 25 namespace {
27 26
28 // See drive.proto for the difference between the two URLs. 27 // See drive.proto for the difference between the two URLs.
29 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/"; 28 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/";
30 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/"; 29 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/";
31 30
32 // Callback for DriveResourceMetadata::InitFromDB. 31 // Callback for DriveResourceMetadata::InitFromDB.
33 void InitFromDBCallback(DriveFileError expected_error, 32 void CopyResultsFromInitFromDBCallback(DriveFileError* expected_error,
34 DriveFileError actual_error) { 33 DriveFileError actual_error) {
35 EXPECT_EQ(expected_error, actual_error); 34 *expected_error = actual_error;
35 }
36
37 void OnGetChildDirectories(std::set<FilePath>* out_changed_directories,
38 const std::set<FilePath>& in_changed_directories) {
39 *out_changed_directories = in_changed_directories;
36 } 40 }
37 41
38 } // namespace 42 } // namespace
39 43
40 class DriveResourceMetadataTest : public testing::Test { 44 class DriveResourceMetadataTest : public testing::Test {
41 public: 45 public:
42 DriveResourceMetadataTest(); 46 DriveResourceMetadataTest();
43 47
44 protected: 48 protected:
49 // Creates a DriveEntryProto.
50 DriveEntryProto CreateDriveEntryProto(int sequence_id,
51 bool is_directory,
52 const std::string& parent_resource_id);
53
54 // Adds a DriveEntryProto to the metadata tree. Returns true on success.
55 bool AddDriveEntryProto(int sequence_id,
56 bool is_directory,
57 const std::string& parent_resource_id);
58
45 DriveResourceMetadata resource_metadata_; 59 DriveResourceMetadata resource_metadata_;
46 60
47 private: 61 private:
48 // Creates the following files/directories 62 // Creates the following files/directories
49 // drive/dir1/ 63 // drive/dir1/
50 // drive/dir2/ 64 // drive/dir2/
51 // drive/dir1/dir3/ 65 // drive/dir1/dir3/
52 // drive/dir1/file4 66 // drive/dir1/file4
53 // drive/dir1/file5 67 // drive/dir1/file5
54 // drive/dir2/file6 68 // drive/dir2/file6
55 // drive/dir2/file7 69 // drive/dir2/file7
56 // drive/dir2/file8 70 // drive/dir2/file8
57 // drive/dir1/dir3/file9 71 // drive/dir1/dir3/file9
58 // drive/dir1/dir3/file10 72 // drive/dir1/dir3/file10
59 void Init(); 73 void Init();
60 74
61 // Add a directory to |parent| and return that directory. The name and
62 // resource_id are determined by the incrementing counter |sequence_id|.
63 DriveDirectory* AddDirectory(DriveDirectory* parent, int sequence_id);
64
65 // Add a file to |parent| and return that file. The name and
66 // resource_id are determined by the incrementing counter |sequence_id|.
67 DriveFile* AddFile(DriveDirectory* parent, int sequence_id);
68
69 MessageLoopForUI message_loop_; 75 MessageLoopForUI message_loop_;
70 content::TestBrowserThread ui_thread_; 76 content::TestBrowserThread ui_thread_;
71 }; 77 };
72 78
73 DriveResourceMetadataTest::DriveResourceMetadataTest() 79 DriveResourceMetadataTest::DriveResourceMetadataTest()
74 : ui_thread_(content::BrowserThread::UI, &message_loop_) { 80 : ui_thread_(content::BrowserThread::UI, &message_loop_) {
75 Init(); 81 Init();
76 } 82 }
77 83
78 void DriveResourceMetadataTest::Init() { 84 void DriveResourceMetadataTest::Init() {
79 resource_metadata_.InitializeRootEntry( 85 resource_metadata_.InitializeRootEntry(
80 kWAPIRootDirectoryResourceIdForTesting); 86 kWAPIRootDirectoryResourceIdForTesting);
81 87
82 int sequence_id = 1; 88 int sequence_id = 1;
83 DriveDirectory* dir1 = AddDirectory(resource_metadata_.root(), sequence_id++); 89 ASSERT_TRUE(AddDriveEntryProto(
84 DriveDirectory* dir2 = AddDirectory(resource_metadata_.root(), sequence_id++); 90 sequence_id++, true, kWAPIRootDirectoryResourceIdForTesting));
85 DriveDirectory* dir3 = AddDirectory(dir1, sequence_id++); 91 ASSERT_TRUE(AddDriveEntryProto(
92 sequence_id++, true, kWAPIRootDirectoryResourceIdForTesting));
93 ASSERT_TRUE(AddDriveEntryProto(sequence_id++, true, "resource_id:dir1"));
86 94
87 AddFile(dir1, sequence_id++); 95 ASSERT_TRUE(AddDriveEntryProto(sequence_id++, false, "resource_id:dir1"));
88 AddFile(dir1, sequence_id++); 96 ASSERT_TRUE(AddDriveEntryProto(sequence_id++, false, "resource_id:dir1"));
89 97
90 AddFile(dir2, sequence_id++); 98 ASSERT_TRUE(AddDriveEntryProto(sequence_id++, false, "resource_id:dir2"));
91 AddFile(dir2, sequence_id++); 99 ASSERT_TRUE(AddDriveEntryProto(sequence_id++, false, "resource_id:dir2"));
92 AddFile(dir2, sequence_id++); 100 ASSERT_TRUE(AddDriveEntryProto(sequence_id++, false, "resource_id:dir2"));
93 101
94 AddFile(dir3, sequence_id++); 102 ASSERT_TRUE(AddDriveEntryProto(sequence_id++, false, "resource_id:dir3"));
95 AddFile(dir3, sequence_id++); 103 ASSERT_TRUE(AddDriveEntryProto(sequence_id++, false, "resource_id:dir3"));
96 } 104 }
97 105
98 DriveDirectory* DriveResourceMetadataTest::AddDirectory(DriveDirectory* parent, 106 DriveEntryProto DriveResourceMetadataTest::CreateDriveEntryProto(
99 int sequence_id) { 107 int sequence_id,
100 scoped_ptr<DriveDirectory> dir = resource_metadata_.CreateDriveDirectory(); 108 bool is_directory,
101 const std::string dir_name = "dir" + base::IntToString(sequence_id); 109 const std::string& parent_resource_id) {
102 const std::string resource_id = std::string("dir_resource_id:") + dir_name; 110 DriveEntryProto entry_proto;
103 dir->set_title(dir_name); 111 const std::string sequence_id_str = base::IntToString(sequence_id);
104 dir->set_resource_id(resource_id); 112 const std::string title = (is_directory ? "dir" : "file") +
113 sequence_id_str;
114 const std::string resource_id = "resource_id:" + title;
115 entry_proto.set_title(title);
116 entry_proto.set_resource_id(resource_id);
117 entry_proto.set_parent_resource_id(parent_resource_id);
105 118
106 parent->AddEntry(dir.get()); 119 PlatformFileInfoProto* file_info = entry_proto.mutable_file_info();
120 file_info->set_is_directory(is_directory);
107 121
108 return dir.release(); 122 if (!is_directory) {
123 DriveFileSpecificInfo* file_specific_info =
124 entry_proto.mutable_file_specific_info();
125 file_info->set_size(sequence_id * 1024);
126 file_specific_info->set_file_md5(std::string("md5:") + title);
127 }
128 return entry_proto;
109 } 129 }
110 130
111 DriveFile* DriveResourceMetadataTest::AddFile(DriveDirectory* parent, 131 bool DriveResourceMetadataTest::AddDriveEntryProto(
112 int sequence_id) { 132 int sequence_id,
113 scoped_ptr<DriveFile> file = resource_metadata_.CreateDriveFile(); 133 bool is_directory,
114 const std::string title = "file" + base::IntToString(sequence_id); 134 const std::string& parent_resource_id) {
115 const std::string resource_id = std::string("file_resource_id:") + title; 135 DriveEntryProto entry_proto = CreateDriveEntryProto(sequence_id,
116 file->set_title(title); 136 is_directory,
117 file->set_resource_id(resource_id); 137 parent_resource_id);
118 file->set_file_md5(std::string("file_md5:") + title); 138 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
139 FilePath drive_file_path;
119 140
120 parent->AddEntry(file.get()); 141 resource_metadata_.AddEntryToParent(
121 142 entry_proto,
122 return file.release(); 143 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
144 &error, &drive_file_path));
145 google_apis::test_util::RunBlockingPoolTask();
146 return DRIVE_FILE_OK == error;
123 } 147 }
124 148
125 TEST_F(DriveResourceMetadataTest, VersionCheck) { 149 TEST_F(DriveResourceMetadataTest, VersionCheck) {
126 // Set up the root directory. 150 // Set up the root directory.
127 DriveRootDirectoryProto proto; 151 DriveRootDirectoryProto proto;
128 DriveEntryProto* mutable_entry = 152 DriveEntryProto* mutable_entry =
129 proto.mutable_drive_directory()->mutable_drive_entry(); 153 proto.mutable_drive_directory()->mutable_drive_entry();
130 mutable_entry->mutable_file_info()->set_is_directory(true); 154 mutable_entry->mutable_file_info()->set_is_directory(true);
131 mutable_entry->set_resource_id(kWAPIRootDirectoryResourceIdForTesting); 155 mutable_entry->set_resource_id(kWAPIRootDirectoryResourceIdForTesting);
132 mutable_entry->set_upload_url(kResumableCreateMediaUrl); 156 mutable_entry->set_upload_url(kResumableCreateMediaUrl);
(...skipping 20 matching lines...) Expand all
153 177
154 // Set a newer version, and serialize. 178 // Set a newer version, and serialize.
155 proto.set_version(kProtoVersion + 1); 179 proto.set_version(kProtoVersion + 1);
156 ASSERT_TRUE(proto.SerializeToString(&serialized_proto)); 180 ASSERT_TRUE(proto.SerializeToString(&serialized_proto));
157 // This should fail as the version is newer. 181 // This should fail as the version is newer.
158 ASSERT_FALSE(resource_metadata.ParseFromString(serialized_proto)); 182 ASSERT_FALSE(resource_metadata.ParseFromString(serialized_proto));
159 } 183 }
160 184
161 TEST_F(DriveResourceMetadataTest, GetEntryByResourceId_RootDirectory) { 185 TEST_F(DriveResourceMetadataTest, GetEntryByResourceId_RootDirectory) {
162 DriveResourceMetadata resource_metadata; 186 DriveResourceMetadata resource_metadata;
187
188 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
189 FilePath drive_file_path;
190 scoped_ptr<DriveEntryProto> entry_proto;
191
163 // Look up the root directory by its resource ID. 192 // Look up the root directory by its resource ID.
164 DriveEntry* entry = resource_metadata.GetEntryByResourceId( 193 resource_metadata.GetEntryInfoByResourceId(
165 kWAPIRootDirectoryResourceId); 194 kWAPIRootDirectoryResourceIdForTesting,
166 ASSERT_FALSE(entry); 195 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback,
196 &error, &drive_file_path, &entry_proto));
197 google_apis::test_util::RunBlockingPoolTask();
198 ASSERT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
199
167 // Initialize root and look it up again. 200 // Initialize root and look it up again.
168 resource_metadata.InitializeRootEntry(kWAPIRootDirectoryResourceIdForTesting); 201 resource_metadata.InitializeRootEntry(kWAPIRootDirectoryResourceIdForTesting);
169 entry = resource_metadata.GetEntryByResourceId(
170 kWAPIRootDirectoryResourceIdForTesting);
171 ASSERT_TRUE(entry);
172 202
173 EXPECT_EQ(kWAPIRootDirectoryResourceIdForTesting, entry->resource_id()); 203 resource_metadata_.GetEntryInfoByResourceId(
204 kWAPIRootDirectoryResourceIdForTesting,
205 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback,
206 &error, &drive_file_path, &entry_proto));
207 google_apis::test_util::RunBlockingPoolTask();
208 EXPECT_EQ(DRIVE_FILE_OK, error);
209 ASSERT_TRUE(entry_proto.get());
210 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive"), drive_file_path);
211 EXPECT_EQ(kWAPIRootDirectoryResourceIdForTesting, entry_proto->resource_id());
174 } 212 }
175 213
176 TEST_F(DriveResourceMetadataTest, GetEntryInfoByResourceId) { 214 TEST_F(DriveResourceMetadataTest, GetEntryInfoByResourceId) {
177 // Confirm that an existing file is found. 215 // Confirm that an existing file is found.
178 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 216 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
179 FilePath drive_file_path; 217 FilePath drive_file_path;
180 scoped_ptr<DriveEntryProto> entry_proto; 218 scoped_ptr<DriveEntryProto> entry_proto;
181 resource_metadata_.GetEntryInfoByResourceId( 219 resource_metadata_.GetEntryInfoByResourceId(
182 "file_resource_id:file4", 220 "resource_id:file4",
183 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, 221 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback,
184 &error, &drive_file_path, &entry_proto)); 222 &error, &drive_file_path, &entry_proto));
185 google_apis::test_util::RunBlockingPoolTask(); 223 google_apis::test_util::RunBlockingPoolTask();
186 EXPECT_EQ(DRIVE_FILE_OK, error); 224 EXPECT_EQ(DRIVE_FILE_OK, error);
187 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file4"), drive_file_path); 225 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file4"), drive_file_path);
188 ASSERT_TRUE(entry_proto.get()); 226 ASSERT_TRUE(entry_proto.get());
189 EXPECT_EQ("file4", entry_proto->base_name()); 227 EXPECT_EQ("file4", entry_proto->base_name());
190 228
191 // Confirm that a non existing file is not found. 229 // Confirm that a non existing file is not found.
192 error = DRIVE_FILE_ERROR_FAILED; 230 error = DRIVE_FILE_ERROR_FAILED;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 TestingProfile profile; 374 TestingProfile profile;
337 scoped_refptr<base::SequencedWorkerPool> pool = 375 scoped_refptr<base::SequencedWorkerPool> pool =
338 content::BrowserThread::GetBlockingPool(); 376 content::BrowserThread::GetBlockingPool();
339 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner = 377 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner =
340 pool->GetSequencedTaskRunner(pool->GetSequenceToken()); 378 pool->GetSequencedTaskRunner(pool->GetSequenceToken());
341 379
342 FilePath db_path(DriveCache::GetCacheRootPath(&profile). 380 FilePath db_path(DriveCache::GetCacheRootPath(&profile).
343 AppendASCII("meta").AppendASCII("resource_metadata.db")); 381 AppendASCII("meta").AppendASCII("resource_metadata.db"));
344 // InitFromDB should fail with DRIVE_FILE_ERROR_NOT_FOUND since the db 382 // InitFromDB should fail with DRIVE_FILE_ERROR_NOT_FOUND since the db
345 // doesn't exist. 383 // doesn't exist.
346 resource_metadata_.InitFromDB(db_path, blocking_task_runner, 384 DriveFileError db_error;
347 base::Bind(&InitFromDBCallback, DRIVE_FILE_ERROR_NOT_FOUND)); 385 resource_metadata_.InitFromDB(
386 db_path,
387 blocking_task_runner,
388 base::Bind(&CopyResultsFromInitFromDBCallback, &db_error));
348 google_apis::test_util::RunBlockingPoolTask(); 389 google_apis::test_util::RunBlockingPoolTask();
390 ASSERT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, db_error);
349 391
350 // Create a file system and write it to disk. 392 // Create a file system and write it to disk.
351 // We cannot call SaveToDB without first having called InitFromDB because 393 // We cannot call SaveToDB without first having called InitFromDB because
352 // InitFrom initializes the db_path and blocking_task_runner needed by 394 // InitFrom initializes the db_path and blocking_task_runner needed by
353 // SaveToDB. 395 // SaveToDB.
354 resource_metadata_.SaveToDB(); 396 resource_metadata_.SaveToDB();
355 google_apis::test_util::RunBlockingPoolTask(); 397 google_apis::test_util::RunBlockingPoolTask();
356 398
357 // InitFromDB should fail with DRIVE_FILE_ERROR_IN_USE. 399 // InitFromDB should fail with DRIVE_FILE_ERROR_IN_USE.
358 resource_metadata_.InitFromDB(db_path, blocking_task_runner, 400 resource_metadata_.InitFromDB(
359 base::Bind(&InitFromDBCallback, DRIVE_FILE_ERROR_IN_USE)); 401 db_path,
402 blocking_task_runner,
403 base::Bind(&CopyResultsFromInitFromDBCallback, &db_error));
360 google_apis::test_util::RunBlockingPoolTask(); 404 google_apis::test_util::RunBlockingPoolTask();
405 ASSERT_EQ(DRIVE_FILE_ERROR_IN_USE, db_error);
361 406
362 // InitFromDB should succeed. 407 // InitFromDB should succeed.
363 DriveResourceMetadata test_resource_metadata; 408 DriveResourceMetadata test_resource_metadata;
364 test_resource_metadata.InitializeRootEntry( 409 test_resource_metadata.InitializeRootEntry(
365 kWAPIRootDirectoryResourceIdForTesting); 410 kWAPIRootDirectoryResourceIdForTesting);
366 test_resource_metadata.InitFromDB(db_path, blocking_task_runner, 411 test_resource_metadata.InitFromDB(
367 base::Bind(&InitFromDBCallback, DRIVE_FILE_OK)); 412 db_path,
413 blocking_task_runner,
414 base::Bind(&CopyResultsFromInitFromDBCallback, &db_error));
368 google_apis::test_util::RunBlockingPoolTask(); 415 google_apis::test_util::RunBlockingPoolTask();
416 ASSERT_EQ(DRIVE_FILE_OK, db_error);
369 417
370 // Verify by checking for drive/dir2, which should have 3 children. 418 // Verify by checking for drive/dir2, which should have 3 children.
371 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 419 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
372 scoped_ptr<DriveEntryProtoVector> entries; 420 scoped_ptr<DriveEntryProtoVector> entries;
373 test_resource_metadata.ReadDirectoryByPath( 421 test_resource_metadata.ReadDirectoryByPath(
374 FilePath::FromUTF8Unsafe("drive/dir2"), 422 FilePath::FromUTF8Unsafe("drive/dir2"),
375 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, 423 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback,
376 &error, &entries)); 424 &error, &entries));
377 google_apis::test_util::RunBlockingPoolTask(); 425 google_apis::test_util::RunBlockingPoolTask();
378 EXPECT_EQ(DRIVE_FILE_OK, error); 426 EXPECT_EQ(DRIVE_FILE_OK, error);
379 ASSERT_TRUE(entries.get()); 427 ASSERT_TRUE(entries.get());
380 ASSERT_EQ(3U, entries->size()); 428 ASSERT_EQ(3U, entries->size());
381 } 429 }
382 430
383 TEST_F(DriveResourceMetadataTest, RemoveEntryFromParent) { 431 TEST_F(DriveResourceMetadataTest, RemoveEntryFromParent) {
384 // Make sure file9 is found. 432 // Make sure file9 is found.
385 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 433 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
386 FilePath drive_file_path; 434 FilePath drive_file_path;
387 const std::string file9_resource_id = "file_resource_id:file9"; 435 const std::string file9_resource_id = "resource_id:file9";
388 scoped_ptr<DriveEntryProto> entry_proto; 436 scoped_ptr<DriveEntryProto> entry_proto;
389 resource_metadata_.GetEntryInfoByResourceId( 437 resource_metadata_.GetEntryInfoByResourceId(
390 file9_resource_id, 438 file9_resource_id,
391 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, 439 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback,
392 &error, &drive_file_path, &entry_proto)); 440 &error, &drive_file_path, &entry_proto));
393 google_apis::test_util::RunBlockingPoolTask(); 441 google_apis::test_util::RunBlockingPoolTask();
394 EXPECT_EQ(DRIVE_FILE_OK, error); 442 EXPECT_EQ(DRIVE_FILE_OK, error);
395 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/dir3/file9"), drive_file_path); 443 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/dir3/file9"), drive_file_path);
396 ASSERT_TRUE(entry_proto.get()); 444 ASSERT_TRUE(entry_proto.get());
397 EXPECT_EQ("file9", entry_proto->base_name()); 445 EXPECT_EQ("file9", entry_proto->base_name());
(...skipping 10 matching lines...) Expand all
408 // file9 should no longer exist. 456 // file9 should no longer exist.
409 resource_metadata_.GetEntryInfoByResourceId( 457 resource_metadata_.GetEntryInfoByResourceId(
410 file9_resource_id, 458 file9_resource_id,
411 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, 459 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback,
412 &error, &drive_file_path, &entry_proto)); 460 &error, &drive_file_path, &entry_proto));
413 google_apis::test_util::RunBlockingPoolTask(); 461 google_apis::test_util::RunBlockingPoolTask();
414 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); 462 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
415 EXPECT_FALSE(entry_proto.get()); 463 EXPECT_FALSE(entry_proto.get());
416 464
417 // Look for dir3. 465 // Look for dir3.
418 const std::string dir3_resource_id = "dir_resource_id:dir3"; 466 const std::string dir3_resource_id = "resource_id:dir3";
419 resource_metadata_.GetEntryInfoByResourceId( 467 resource_metadata_.GetEntryInfoByResourceId(
420 dir3_resource_id, 468 dir3_resource_id,
421 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, 469 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback,
422 &error, &drive_file_path, &entry_proto)); 470 &error, &drive_file_path, &entry_proto));
423 google_apis::test_util::RunBlockingPoolTask(); 471 google_apis::test_util::RunBlockingPoolTask();
424 EXPECT_EQ(DRIVE_FILE_OK, error); 472 EXPECT_EQ(DRIVE_FILE_OK, error);
425 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/dir3"), drive_file_path); 473 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/dir3"), drive_file_path);
426 ASSERT_TRUE(entry_proto.get()); 474 ASSERT_TRUE(entry_proto.get());
427 EXPECT_EQ("dir3", entry_proto->base_name()); 475 EXPECT_EQ("dir3", entry_proto->base_name());
428 476
(...skipping 18 matching lines...) Expand all
447 // Remove unknown resource_id using RemoveEntryFromParent. 495 // Remove unknown resource_id using RemoveEntryFromParent.
448 resource_metadata_.RemoveEntryFromParent( 496 resource_metadata_.RemoveEntryFromParent(
449 "foo", 497 "foo",
450 base::Bind(&test_util::CopyResultsFromFileMoveCallback, 498 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
451 &error, &drive_file_path)); 499 &error, &drive_file_path));
452 google_apis::test_util::RunBlockingPoolTask(); 500 google_apis::test_util::RunBlockingPoolTask();
453 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); 501 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
454 502
455 // Try removing root. This should fail. 503 // Try removing root. This should fail.
456 resource_metadata_.RemoveEntryFromParent( 504 resource_metadata_.RemoveEntryFromParent(
457 resource_metadata_.root()->resource_id(), 505 kWAPIRootDirectoryResourceIdForTesting,
458 base::Bind(&test_util::CopyResultsFromFileMoveCallback, 506 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
459 &error, &drive_file_path)); 507 &error, &drive_file_path));
460 google_apis::test_util::RunBlockingPoolTask(); 508 google_apis::test_util::RunBlockingPoolTask();
461 EXPECT_EQ(DRIVE_FILE_ERROR_ACCESS_DENIED, error); 509 EXPECT_EQ(DRIVE_FILE_ERROR_ACCESS_DENIED, error);
462 } 510 }
463 511
464 TEST_F(DriveResourceMetadataTest, MoveEntryToDirectory) { 512 TEST_F(DriveResourceMetadataTest, MoveEntryToDirectory) {
465 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 513 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
466 FilePath drive_file_path; 514 FilePath drive_file_path;
467 scoped_ptr<DriveEntryProto> entry_proto; 515 scoped_ptr<DriveEntryProto> entry_proto;
468 516
469 // Move file8 to drive/dir1. 517 // Move file8 to drive/dir1.
470 resource_metadata_.MoveEntryToDirectory( 518 resource_metadata_.MoveEntryToDirectory(
471 FilePath::FromUTF8Unsafe("drive/dir2/file8"), 519 FilePath::FromUTF8Unsafe("drive/dir2/file8"),
472 FilePath::FromUTF8Unsafe("drive/dir1"), 520 FilePath::FromUTF8Unsafe("drive/dir1"),
473 base::Bind(&test_util::CopyResultsFromFileMoveCallback, 521 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
474 &error, &drive_file_path)); 522 &error, &drive_file_path));
475 google_apis::test_util::RunBlockingPoolTask(); 523 google_apis::test_util::RunBlockingPoolTask();
476 EXPECT_EQ(DRIVE_FILE_OK, error); 524 EXPECT_EQ(DRIVE_FILE_OK, error);
477 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file8"), drive_file_path); 525 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file8"), drive_file_path);
478 526
479 // Look up the entry by its resource id and make sure it really moved. 527 // Look up the entry by its resource id and make sure it really moved.
480 resource_metadata_.GetEntryInfoByResourceId( 528 resource_metadata_.GetEntryInfoByResourceId(
481 "file_resource_id:file8", 529 "resource_id:file8",
482 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, 530 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback,
483 &error, &drive_file_path, &entry_proto)); 531 &error, &drive_file_path, &entry_proto));
484 google_apis::test_util::RunBlockingPoolTask(); 532 google_apis::test_util::RunBlockingPoolTask();
485 EXPECT_EQ(DRIVE_FILE_OK, error); 533 EXPECT_EQ(DRIVE_FILE_OK, error);
486 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file8"), drive_file_path); 534 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file8"), drive_file_path);
487 535
488 // Move non-existent file to drive/dir1. This should fail. 536 // Move non-existent file to drive/dir1. This should fail.
489 resource_metadata_.MoveEntryToDirectory( 537 resource_metadata_.MoveEntryToDirectory(
490 FilePath::FromUTF8Unsafe("drive/dir2/file8"), 538 FilePath::FromUTF8Unsafe("drive/dir2/file8"),
491 FilePath::FromUTF8Unsafe("drive/dir1"), 539 FilePath::FromUTF8Unsafe("drive/dir1"),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 FilePath::FromUTF8Unsafe("drive/file8"), 578 FilePath::FromUTF8Unsafe("drive/file8"),
531 FilePath::FromUTF8Unsafe("drive/dir2"), 579 FilePath::FromUTF8Unsafe("drive/dir2"),
532 base::Bind(&test_util::CopyResultsFromFileMoveCallback, 580 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
533 &error, &drive_file_path)); 581 &error, &drive_file_path));
534 google_apis::test_util::RunBlockingPoolTask(); 582 google_apis::test_util::RunBlockingPoolTask();
535 EXPECT_EQ(DRIVE_FILE_OK, error); 583 EXPECT_EQ(DRIVE_FILE_OK, error);
536 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2/file8"), drive_file_path); 584 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2/file8"), drive_file_path);
537 585
538 // Make sure file is still ok. 586 // Make sure file is still ok.
539 resource_metadata_.GetEntryInfoByResourceId( 587 resource_metadata_.GetEntryInfoByResourceId(
540 "file_resource_id:file8", 588 "resource_id:file8",
541 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, 589 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback,
542 &error, &drive_file_path, &entry_proto)); 590 &error, &drive_file_path, &entry_proto));
543 google_apis::test_util::RunBlockingPoolTask(); 591 google_apis::test_util::RunBlockingPoolTask();
544 EXPECT_EQ(DRIVE_FILE_OK, error); 592 EXPECT_EQ(DRIVE_FILE_OK, error);
545 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2/file8"), drive_file_path); 593 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2/file8"), drive_file_path);
546 } 594 }
547 595
548 TEST_F(DriveResourceMetadataTest, RenameEntry) { 596 TEST_F(DriveResourceMetadataTest, RenameEntry) {
549 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 597 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
550 FilePath drive_file_path; 598 FilePath drive_file_path;
551 scoped_ptr<DriveEntryProto> entry_proto; 599 scoped_ptr<DriveEntryProto> entry_proto;
552 600
553 // Rename file8 to file11. 601 // Rename file8 to file11.
554 resource_metadata_.RenameEntry( 602 resource_metadata_.RenameEntry(
555 FilePath::FromUTF8Unsafe("drive/dir2/file8"), 603 FilePath::FromUTF8Unsafe("drive/dir2/file8"),
556 "file11", 604 "file11",
557 base::Bind(&test_util::CopyResultsFromFileMoveCallback, 605 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
558 &error, &drive_file_path)); 606 &error, &drive_file_path));
559 google_apis::test_util::RunBlockingPoolTask(); 607 google_apis::test_util::RunBlockingPoolTask();
560 EXPECT_EQ(DRIVE_FILE_OK, error); 608 EXPECT_EQ(DRIVE_FILE_OK, error);
561 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2/file11"), drive_file_path); 609 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2/file11"), drive_file_path);
562 610
563 // Lookup the file by resource id to make sure the file actually got renamed. 611 // Lookup the file by resource id to make sure the file actually got renamed.
564 resource_metadata_.GetEntryInfoByResourceId( 612 resource_metadata_.GetEntryInfoByResourceId(
565 "file_resource_id:file8", 613 "resource_id:file8",
566 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, 614 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback,
567 &error, &drive_file_path, &entry_proto)); 615 &error, &drive_file_path, &entry_proto));
568 google_apis::test_util::RunBlockingPoolTask(); 616 google_apis::test_util::RunBlockingPoolTask();
569 EXPECT_EQ(DRIVE_FILE_OK, error); 617 EXPECT_EQ(DRIVE_FILE_OK, error);
570 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2/file11"), drive_file_path); 618 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2/file11"), drive_file_path);
571 619
572 // Rename to file7 to force a duplicate name. 620 // Rename to file7 to force a duplicate name.
573 resource_metadata_.RenameEntry( 621 resource_metadata_.RenameEntry(
574 FilePath::FromUTF8Unsafe("drive/dir2/file11"), 622 FilePath::FromUTF8Unsafe("drive/dir2/file11"),
575 "file7", 623 "file7",
(...skipping 17 matching lines...) Expand all
593 resource_metadata_.RenameEntry( 641 resource_metadata_.RenameEntry(
594 FilePath::FromUTF8Unsafe("drive/dir2/file11"), 642 FilePath::FromUTF8Unsafe("drive/dir2/file11"),
595 "file11", 643 "file11",
596 base::Bind(&test_util::CopyResultsFromFileMoveCallback, 644 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
597 &error, &drive_file_path)); 645 &error, &drive_file_path));
598 google_apis::test_util::RunBlockingPoolTask(); 646 google_apis::test_util::RunBlockingPoolTask();
599 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); 647 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
600 EXPECT_EQ(FilePath(), drive_file_path); 648 EXPECT_EQ(FilePath(), drive_file_path);
601 } 649 }
602 650
651 TEST_F(DriveResourceMetadataTest, RefreshEntryProto) {
652 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
653 FilePath drive_file_path;
654 scoped_ptr<DriveEntryProto> entry_proto;
655
656 // Get file9.
657 resource_metadata_.GetEntryInfoByPath(
658 FilePath::FromUTF8Unsafe("drive/dir1/dir3/file9"),
659 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback,
660 &error, &entry_proto));
661 google_apis::test_util::RunBlockingPoolTask();
662 EXPECT_EQ(DRIVE_FILE_OK, error);
663 ASSERT_TRUE(entry_proto.get());
664 EXPECT_EQ("file9", entry_proto->base_name());
665 ASSERT_TRUE(!entry_proto->file_info().is_directory());
666 EXPECT_EQ("md5:file9", entry_proto->file_specific_info().file_md5());
667
668 // Rename it and change the file size.
669 DriveEntryProto file_entry_proto(*entry_proto);
670 const std::string updated_md5("md5:updated");
671 file_entry_proto.mutable_file_specific_info()->set_file_md5(updated_md5);
672 file_entry_proto.set_title("file100");
673 entry_proto.reset();
674 resource_metadata_.RefreshEntryProto(
675 file_entry_proto,
676 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback,
677 &error, &drive_file_path, &entry_proto));
678 google_apis::test_util::RunBlockingPoolTask();
679 EXPECT_EQ(DRIVE_FILE_OK, error);
680 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/dir3/file100"),
681 drive_file_path);
682 ASSERT_TRUE(entry_proto.get());
683 EXPECT_EQ("file100", entry_proto->base_name());
684 ASSERT_TRUE(!entry_proto->file_info().is_directory());
685 EXPECT_EQ(updated_md5, entry_proto->file_specific_info().file_md5());
686
687 // Make sure we get the same thing from GetEntryInfoByPath.
688 entry_proto.reset();
689 resource_metadata_.GetEntryInfoByPath(
690 FilePath::FromUTF8Unsafe("drive/dir1/dir3/file100"),
691 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback,
692 &error, &entry_proto));
693 google_apis::test_util::RunBlockingPoolTask();
694 EXPECT_EQ(DRIVE_FILE_OK, error);
695 ASSERT_TRUE(entry_proto.get());
696 EXPECT_EQ("file100", entry_proto->base_name());
697 ASSERT_TRUE(!entry_proto->file_info().is_directory());
698 EXPECT_EQ(updated_md5, entry_proto->file_specific_info().file_md5());
699
700 // Get dir2.
701 entry_proto.reset();
702 resource_metadata_.GetEntryInfoByPath(
703 FilePath::FromUTF8Unsafe("drive/dir2"),
704 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback,
705 &error, &entry_proto));
706 google_apis::test_util::RunBlockingPoolTask();
707 EXPECT_EQ(DRIVE_FILE_OK, error);
708 ASSERT_TRUE(entry_proto.get());
709 EXPECT_EQ("dir2", entry_proto->base_name());
710 ASSERT_TRUE(entry_proto->file_info().is_directory());
711
712 // Change the name to dir100 and change the parent to drive/dir1/dir3.
713 DriveEntryProto dir_entry_proto(*entry_proto);
714 dir_entry_proto.set_title("dir100");
715 dir_entry_proto.set_parent_resource_id("resource_id:dir3");
716 entry_proto.reset();
717 resource_metadata_.RefreshEntryProto(
718 dir_entry_proto,
719 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback,
720 &error, &drive_file_path, &entry_proto));
721 google_apis::test_util::RunBlockingPoolTask();
722 EXPECT_EQ(DRIVE_FILE_OK, error);
723 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/dir3/dir100"),
724 drive_file_path);
725 ASSERT_TRUE(entry_proto.get());
726 EXPECT_EQ("dir100", entry_proto->base_name());
727 EXPECT_TRUE(entry_proto->file_info().is_directory());
728 EXPECT_EQ("resource_id:dir2", entry_proto->resource_id());
729
730 // Make sure the children have moved over. Test file6.
731 entry_proto.reset();
732 resource_metadata_.GetEntryInfoByPath(
733 FilePath::FromUTF8Unsafe("drive/dir1/dir3/dir100/file6"),
734 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback,
735 &error, &entry_proto));
736 google_apis::test_util::RunBlockingPoolTask();
737 EXPECT_EQ(DRIVE_FILE_OK, error);
738 ASSERT_TRUE(entry_proto.get());
739 EXPECT_EQ("file6", entry_proto->base_name());
740
741 // Make sure dir2 no longer exists.
742 resource_metadata_.GetEntryInfoByPath(
743 FilePath::FromUTF8Unsafe("drive/dir2"),
744 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback,
745 &error, &entry_proto));
746 google_apis::test_util::RunBlockingPoolTask();
747 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
748 EXPECT_FALSE(entry_proto.get());
749 }
750
751 TEST_F(DriveResourceMetadataTest, AddEntryToParent) {
752 int sequence_id = 100;
753 DriveEntryProto file_entry_proto = CreateDriveEntryProto(
754 sequence_id++, false, "resource_id:dir3");
755
756 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
757 FilePath drive_file_path;
758
759 // Add to dir3.
760 resource_metadata_.AddEntryToParent(
761 file_entry_proto,
762 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
763 &error, &drive_file_path));
764 google_apis::test_util::RunBlockingPoolTask();
765 EXPECT_EQ(DRIVE_FILE_OK, error);
766 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/dir3/file100"),
767 drive_file_path);
768
769 // Adds to root when parent resource id is not specified.
770 DriveEntryProto file_entry_proto2 = CreateDriveEntryProto(
771 sequence_id++, false, "");
772
773 resource_metadata_.AddEntryToParent(
774 file_entry_proto2,
775 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
776 &error, &drive_file_path));
777 google_apis::test_util::RunBlockingPoolTask();
778 EXPECT_EQ(DRIVE_FILE_OK, error);
779 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/file101"), drive_file_path);
780
781 // Add a directory.
782 DriveEntryProto dir_entry_proto = CreateDriveEntryProto(
783 sequence_id++, true, "resource_id:dir1");
784
785 resource_metadata_.AddEntryToParent(
786 dir_entry_proto,
787 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
788 &error, &drive_file_path));
789 google_apis::test_util::RunBlockingPoolTask();
790 EXPECT_EQ(DRIVE_FILE_OK, error);
791 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/dir102"), drive_file_path);
792
793 // Add to an invalid parent.
794 DriveEntryProto file_entry_proto3 = CreateDriveEntryProto(
795 sequence_id++, false, "resource_id:invalid");
796
797 resource_metadata_.AddEntryToParent(
798 file_entry_proto3,
799 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
800 &error, &drive_file_path));
801 google_apis::test_util::RunBlockingPoolTask();
802 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
803 }
804
805 TEST_F(DriveResourceMetadataTest, GetChildDirectories) {
806 std::set<FilePath> changed_directories;
807
808 // file9: not a directory, so no children.
809 resource_metadata_.GetChildDirectories("resource_id:file9",
810 base::Bind(&OnGetChildDirectories, &changed_directories));
811 google_apis::test_util::RunBlockingPoolTask();
812 EXPECT_TRUE(changed_directories.empty());
813
814 // dir2: no child directories.
815 resource_metadata_.GetChildDirectories("resource_id:dir2",
816 base::Bind(&OnGetChildDirectories, &changed_directories));
817 google_apis::test_util::RunBlockingPoolTask();
818 EXPECT_TRUE(changed_directories.empty());
819
820 // dir1: dir3 is the only child
821 resource_metadata_.GetChildDirectories("resource_id:dir1",
822 base::Bind(&OnGetChildDirectories, &changed_directories));
823 google_apis::test_util::RunBlockingPoolTask();
824 EXPECT_EQ(1u, changed_directories.size());
825 EXPECT_EQ(1u, changed_directories.count(
826 FilePath::FromUTF8Unsafe("drive/dir1/dir3")));
827
828 // Add a few more directories to make sure deeper nesting works.
829 // dir2/dir100
830 // dir2/dir101
831 // dir2/dir101/dir102
832 // dir2/dir101/dir103
833 // dir2/dir101/dir104
834 // dir2/dir101/dir102/dir105
835 // dir2/dir101/dir102/dir105/dir106
836 // dir2/dir101/dir102/dir105/dir106/dir107
837 int sequence_id = 100;
838 ASSERT_TRUE(AddDriveEntryProto(sequence_id++, true, "resource_id:dir2"));
839 ASSERT_TRUE(AddDriveEntryProto(sequence_id++, true, "resource_id:dir2"));
840 ASSERT_TRUE(AddDriveEntryProto(sequence_id++, true, "resource_id:dir101"));
841 ASSERT_TRUE(AddDriveEntryProto(sequence_id++, true, "resource_id:dir101"));
842 ASSERT_TRUE(AddDriveEntryProto(sequence_id++, true, "resource_id:dir101"));
843 ASSERT_TRUE(AddDriveEntryProto(sequence_id++, true, "resource_id:dir102"));
844 ASSERT_TRUE(AddDriveEntryProto(sequence_id++, true, "resource_id:dir105"));
845 ASSERT_TRUE(AddDriveEntryProto(sequence_id++, true, "resource_id:dir106"));
846
847 resource_metadata_.GetChildDirectories("resource_id:dir2",
848 base::Bind(&OnGetChildDirectories, &changed_directories));
849 google_apis::test_util::RunBlockingPoolTask();
850 EXPECT_EQ(8u, changed_directories.size());
851 EXPECT_EQ(1u, changed_directories.count(FilePath::FromUTF8Unsafe(
852 "drive/dir2/dir101")));
853 EXPECT_EQ(1u, changed_directories.count(FilePath::FromUTF8Unsafe(
854 "drive/dir2/dir101/dir104")));
855 EXPECT_EQ(1u, changed_directories.count(FilePath::FromUTF8Unsafe(
856 "drive/dir2/dir101/dir102/dir105/dir106/dir107")));
857 }
858
603 TEST_F(DriveResourceMetadataTest, TakeOverEntries) { 859 TEST_F(DriveResourceMetadataTest, TakeOverEntries) {
604 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 860 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
605 FilePath drive_file_path; 861 FilePath drive_file_path;
606 scoped_ptr<DriveEntryProto> entry_proto; 862 scoped_ptr<DriveEntryProto> entry_proto;
607 863
608 // Move files from dir1 to dir2. 864 // Move files from dir1 to dir2.
609 resource_metadata_.TakeOverEntries( 865 resource_metadata_.TakeOverEntries(
610 "dir_resource_id:dir1", 866 "resource_id:dir1",
611 "dir_resource_id:dir2", 867 "resource_id:dir2",
612 base::Bind(&test_util::CopyResultsFromFileMoveCallback, 868 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
613 &error, &drive_file_path)); 869 &error, &drive_file_path));
614 google_apis::test_util::RunBlockingPoolTask(); 870 google_apis::test_util::RunBlockingPoolTask();
615 EXPECT_EQ(DRIVE_FILE_OK, error); 871 EXPECT_EQ(DRIVE_FILE_OK, error);
616 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2"), drive_file_path); 872 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2"), drive_file_path);
617 873
618 // Check if the file move worked. file6 should now be in drive/dir2. 874 // Check if the file move worked. file6 should now be in drive/dir2.
619 resource_metadata_.GetEntryInfoByPath( 875 resource_metadata_.GetEntryInfoByPath(
620 FilePath::FromUTF8Unsafe("drive/dir2/file6"), 876 FilePath::FromUTF8Unsafe("drive/dir2/file6"),
621 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, 877 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback,
(...skipping 29 matching lines...) Expand all
651 FilePath::FromUTF8Unsafe("drive/dir2"), 907 FilePath::FromUTF8Unsafe("drive/dir2"),
652 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, 908 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback,
653 &error, &entries)); 909 &error, &entries));
654 google_apis::test_util::RunBlockingPoolTask(); 910 google_apis::test_util::RunBlockingPoolTask();
655 EXPECT_EQ(DRIVE_FILE_OK, error); 911 EXPECT_EQ(DRIVE_FILE_OK, error);
656 ASSERT_TRUE(entries.get()); 912 ASSERT_TRUE(entries.get());
657 ASSERT_EQ(6U, entries->size()); 913 ASSERT_EQ(6U, entries->size());
658 } 914 }
659 915
660 } // namespace drive 916 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_resource_metadata.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698