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

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: rebase 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 {
28 29
29 // See drive.proto for the difference between the two URLs. 30 // See drive.proto for the difference between the two URLs.
30 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/"; 31 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/";
31 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/"; 32 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/";
32 33
33 const char kTestRootResourceId[] = "test_root";
34
35 // The changestamp of the resource metadata used in 34 // The changestamp of the resource metadata used in
36 // DriveResourceMetadataTest. 35 // DriveResourceMetadataTest.
37 const int64 kTestChangestamp = 100; 36 const int64 kTestChangestamp = 100;
38 37
39 // Returns the sorted base names from |entries|. 38 // Returns the sorted base names from |entries|.
40 std::vector<std::string> GetSortedBaseNames( 39 std::vector<std::string> GetSortedBaseNames(
41 const DriveEntryProtoVector& entries) { 40 const DriveEntryProtoVector& entries) {
42 std::vector<std::string> base_names; 41 std::vector<std::string> base_names;
43 for (size_t i = 0; i < entries.size(); ++i) 42 for (size_t i = 0; i < entries.size(); ++i)
44 base_names.push_back(entries[i].base_name()); 43 base_names.push_back(entries[i].base_name());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 const std::string& parent_resource_id); 80 const std::string& parent_resource_id);
82 81
83 virtual void SetUp() OVERRIDE { 82 virtual void SetUp() OVERRIDE {
84 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 83 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
85 84
86 base::ThreadRestrictions::SetIOAllowed(false); // For strict thread check. 85 base::ThreadRestrictions::SetIOAllowed(false); // For strict thread check.
87 scoped_refptr<base::SequencedWorkerPool> pool = 86 scoped_refptr<base::SequencedWorkerPool> pool =
88 content::BrowserThread::GetBlockingPool(); 87 content::BrowserThread::GetBlockingPool();
89 blocking_task_runner_ = 88 blocking_task_runner_ =
90 pool->GetSequencedTaskRunner(pool->GetSequenceToken()); 89 pool->GetSequencedTaskRunner(pool->GetSequenceToken());
91 resource_metadata_.reset(new DriveResourceMetadata(kTestRootResourceId, 90 resource_metadata_.reset(new DriveResourceMetadata(
92 temp_dir_.path(), 91 util::kDriveGrandRootSpecialResourceId,
93 blocking_task_runner_)); 92 temp_dir_.path(),
93 blocking_task_runner_));
94 Init(resource_metadata_.get()); 94 Init(resource_metadata_.get());
95 } 95 }
96 96
97 virtual void TearDown() OVERRIDE { 97 virtual void TearDown() OVERRIDE {
98 resource_metadata_.reset(); 98 resource_metadata_.reset();
99 base::ThreadRestrictions::SetIOAllowed(true); 99 base::ThreadRestrictions::SetIOAllowed(true);
100 } 100 }
101 101
102 // Gets the entry info by path synchronously. Returns NULL on failure. 102 // Gets the entry info by path synchronously. Returns NULL on failure.
103 scoped_ptr<DriveEntryProto> GetEntryInfoByPathSync( 103 scoped_ptr<DriveEntryProto> GetEntryInfoByPathSync(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 // static 167 // static
168 void DriveResourceMetadataTest::Init(DriveResourceMetadata* resource_metadata) { 168 void DriveResourceMetadataTest::Init(DriveResourceMetadata* resource_metadata) {
169 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 169 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
170 resource_metadata->Initialize( 170 resource_metadata->Initialize(
171 google_apis::test_util::CreateCopyResultCallback(&error)); 171 google_apis::test_util::CreateCopyResultCallback(&error));
172 google_apis::test_util::RunBlockingPoolTask(); 172 google_apis::test_util::RunBlockingPoolTask();
173 ASSERT_EQ(DRIVE_FILE_OK, error); 173 ASSERT_EQ(DRIVE_FILE_OK, error);
174 174
175 int sequence_id = 1; 175 int sequence_id = 1;
176 ASSERT_TRUE(AddDriveEntryProto( 176 ASSERT_TRUE(AddDriveEntryProto(
177 resource_metadata, sequence_id++, true, kTestRootResourceId)); 177 resource_metadata, sequence_id++, true,
178 util::kDriveGrandRootSpecialResourceId));
178 ASSERT_TRUE(AddDriveEntryProto( 179 ASSERT_TRUE(AddDriveEntryProto(
179 resource_metadata, sequence_id++, true, kTestRootResourceId)); 180 resource_metadata, sequence_id++, true,
181 util::kDriveGrandRootSpecialResourceId));
180 ASSERT_TRUE(AddDriveEntryProto( 182 ASSERT_TRUE(AddDriveEntryProto(
181 resource_metadata, sequence_id++, true, "resource_id:dir1")); 183 resource_metadata, sequence_id++, true, "resource_id:dir1"));
182 184
183 ASSERT_TRUE(AddDriveEntryProto( 185 ASSERT_TRUE(AddDriveEntryProto(
184 resource_metadata, sequence_id++, false, "resource_id:dir1")); 186 resource_metadata, sequence_id++, false, "resource_id:dir1"));
185 ASSERT_TRUE(AddDriveEntryProto( 187 ASSERT_TRUE(AddDriveEntryProto(
186 resource_metadata, sequence_id++, false, "resource_id:dir1")); 188 resource_metadata, sequence_id++, false, "resource_id:dir1"));
187 189
188 ASSERT_TRUE(AddDriveEntryProto( 190 ASSERT_TRUE(AddDriveEntryProto(
189 resource_metadata, sequence_id++, false, "resource_id:dir2")); 191 resource_metadata, sequence_id++, false, "resource_id:dir2"));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 google_apis::test_util::RunBlockingPoolTask(); 252 google_apis::test_util::RunBlockingPoolTask();
251 return DRIVE_FILE_OK == error; 253 return DRIVE_FILE_OK == error;
252 } 254 }
253 255
254 TEST_F(DriveResourceMetadataTest, VersionCheck) { 256 TEST_F(DriveResourceMetadataTest, VersionCheck) {
255 // Set up the root directory. 257 // Set up the root directory.
256 DriveRootDirectoryProto proto; 258 DriveRootDirectoryProto proto;
257 DriveEntryProto* mutable_entry = 259 DriveEntryProto* mutable_entry =
258 proto.mutable_drive_directory()->mutable_drive_entry(); 260 proto.mutable_drive_directory()->mutable_drive_entry();
259 mutable_entry->mutable_file_info()->set_is_directory(true); 261 mutable_entry->mutable_file_info()->set_is_directory(true);
260 mutable_entry->set_resource_id(kTestRootResourceId); 262 mutable_entry->set_resource_id(util::kDriveGrandRootSpecialResourceId);
261 mutable_entry->set_upload_url(kResumableCreateMediaUrl); 263 mutable_entry->set_upload_url(kResumableCreateMediaUrl);
262 mutable_entry->set_title("drive"); 264 mutable_entry->set_title("drive");
263 265
264 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests> 266 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests>
265 resource_metadata(new DriveResourceMetadata(kTestRootResourceId, 267 resource_metadata(new DriveResourceMetadata(
266 temp_dir_.path(), 268 util::kDriveGrandRootSpecialResourceId,
267 blocking_task_runner_)); 269 temp_dir_.path(),
270 blocking_task_runner_));
268 ForceUsingMemoryStorage(resource_metadata.get()); 271 ForceUsingMemoryStorage(resource_metadata.get());
269 272
270 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 273 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
271 resource_metadata->Initialize( 274 resource_metadata->Initialize(
272 google_apis::test_util::CreateCopyResultCallback(&error)); 275 google_apis::test_util::CreateCopyResultCallback(&error));
273 google_apis::test_util::RunBlockingPoolTask(); 276 google_apis::test_util::RunBlockingPoolTask();
274 ASSERT_EQ(DRIVE_FILE_OK, error); 277 ASSERT_EQ(DRIVE_FILE_OK, error);
275 278
276 std::string serialized_proto; 279 std::string serialized_proto;
277 EXPECT_TRUE(proto.SerializeToString(&serialized_proto)); 280 EXPECT_TRUE(proto.SerializeToString(&serialized_proto));
(...skipping 18 matching lines...) Expand all
296 // Set a newer version, and serialize. 299 // Set a newer version, and serialize.
297 proto.set_version(kProtoVersion + 1); 300 proto.set_version(kProtoVersion + 1);
298 EXPECT_TRUE(proto.SerializeToString(&serialized_proto)); 301 EXPECT_TRUE(proto.SerializeToString(&serialized_proto));
299 // This should fail as the version is newer. 302 // This should fail as the version is newer.
300 EXPECT_FALSE(ParseMetadataFromString(resource_metadata.get(), 303 EXPECT_FALSE(ParseMetadataFromString(resource_metadata.get(),
301 serialized_proto)); 304 serialized_proto));
302 } 305 }
303 306
304 TEST_F(DriveResourceMetadataTest, LargestChangestamp) { 307 TEST_F(DriveResourceMetadataTest, LargestChangestamp) {
305 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests> 308 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests>
306 resource_metadata(new DriveResourceMetadata(kTestRootResourceId, 309 resource_metadata(new DriveResourceMetadata(
307 temp_dir_.path(), 310 util::kDriveGrandRootSpecialResourceId,
308 blocking_task_runner_)); 311 temp_dir_.path(),
312 blocking_task_runner_));
309 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 313 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
310 resource_metadata->Initialize( 314 resource_metadata->Initialize(
311 google_apis::test_util::CreateCopyResultCallback(&error)); 315 google_apis::test_util::CreateCopyResultCallback(&error));
312 google_apis::test_util::RunBlockingPoolTask(); 316 google_apis::test_util::RunBlockingPoolTask();
313 ASSERT_EQ(DRIVE_FILE_OK, error); 317 ASSERT_EQ(DRIVE_FILE_OK, error);
314 318
315 int64 in_changestamp = 123456; 319 int64 in_changestamp = 123456;
316 resource_metadata->SetLargestChangestamp( 320 resource_metadata->SetLargestChangestamp(
317 in_changestamp, 321 in_changestamp,
318 google_apis::test_util::CreateCopyResultCallback(&error)); 322 google_apis::test_util::CreateCopyResultCallback(&error));
319 google_apis::test_util::RunBlockingPoolTask(); 323 google_apis::test_util::RunBlockingPoolTask();
320 EXPECT_EQ(DRIVE_FILE_OK, error); 324 EXPECT_EQ(DRIVE_FILE_OK, error);
321 325
322 int64 out_changestamp = 0; 326 int64 out_changestamp = 0;
323 resource_metadata->GetLargestChangestamp( 327 resource_metadata->GetLargestChangestamp(
324 google_apis::test_util::CreateCopyResultCallback(&out_changestamp)); 328 google_apis::test_util::CreateCopyResultCallback(&out_changestamp));
325 google_apis::test_util::RunBlockingPoolTask(); 329 google_apis::test_util::RunBlockingPoolTask();
326 DCHECK_EQ(in_changestamp, out_changestamp); 330 DCHECK_EQ(in_changestamp, out_changestamp);
327 } 331 }
328 332
329 TEST_F(DriveResourceMetadataTest, GetEntryInfoByResourceId_RootDirectory) { 333 TEST_F(DriveResourceMetadataTest, GetEntryInfoByResourceId_RootDirectory) {
330 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests> 334 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests>
331 resource_metadata(new DriveResourceMetadata(kTestRootResourceId, 335 resource_metadata(new DriveResourceMetadata(
332 temp_dir_.path(), 336 util::kDriveGrandRootSpecialResourceId,
333 blocking_task_runner_)); 337 temp_dir_.path(),
338 blocking_task_runner_));
334 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 339 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
335 resource_metadata->Initialize( 340 resource_metadata->Initialize(
336 google_apis::test_util::CreateCopyResultCallback(&error)); 341 google_apis::test_util::CreateCopyResultCallback(&error));
337 google_apis::test_util::RunBlockingPoolTask(); 342 google_apis::test_util::RunBlockingPoolTask();
338 ASSERT_EQ(DRIVE_FILE_OK, error); 343 ASSERT_EQ(DRIVE_FILE_OK, error);
339 344
340 base::FilePath drive_file_path; 345 base::FilePath drive_file_path;
341 scoped_ptr<DriveEntryProto> entry_proto; 346 scoped_ptr<DriveEntryProto> entry_proto;
342 347
343 // Look up the root directory by its resource ID. 348 // Look up the root directory by its resource ID.
344 resource_metadata->GetEntryInfoByResourceId( 349 resource_metadata->GetEntryInfoByResourceId(
345 kTestRootResourceId, 350 util::kDriveGrandRootSpecialResourceId,
346 google_apis::test_util::CreateCopyResultCallback( 351 google_apis::test_util::CreateCopyResultCallback(
347 &error, &drive_file_path, &entry_proto)); 352 &error, &drive_file_path, &entry_proto));
348 google_apis::test_util::RunBlockingPoolTask(); 353 google_apis::test_util::RunBlockingPoolTask();
349 EXPECT_EQ(DRIVE_FILE_OK, error); 354 EXPECT_EQ(DRIVE_FILE_OK, error);
350 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive"), drive_file_path); 355 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive"), drive_file_path);
351 ASSERT_TRUE(entry_proto.get()); 356 ASSERT_TRUE(entry_proto.get());
352 EXPECT_EQ("drive", entry_proto->base_name()); 357 EXPECT_EQ("drive", entry_proto->base_name());
353 } 358 }
354 359
355 TEST_F(DriveResourceMetadataTest, GetEntryInfoByResourceId) { 360 TEST_F(DriveResourceMetadataTest, GetEntryInfoByResourceId) {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 // Remove unknown resource_id using RemoveEntry. 572 // Remove unknown resource_id using RemoveEntry.
568 resource_metadata_->RemoveEntry( 573 resource_metadata_->RemoveEntry(
569 "foo", 574 "foo",
570 google_apis::test_util::CreateCopyResultCallback( 575 google_apis::test_util::CreateCopyResultCallback(
571 &error, &drive_file_path)); 576 &error, &drive_file_path));
572 google_apis::test_util::RunBlockingPoolTask(); 577 google_apis::test_util::RunBlockingPoolTask();
573 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); 578 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
574 579
575 // Try removing root. This should fail. 580 // Try removing root. This should fail.
576 resource_metadata_->RemoveEntry( 581 resource_metadata_->RemoveEntry(
577 kTestRootResourceId, 582 util::kDriveGrandRootSpecialResourceId,
578 google_apis::test_util::CreateCopyResultCallback( 583 google_apis::test_util::CreateCopyResultCallback(
579 &error, &drive_file_path)); 584 &error, &drive_file_path));
580 google_apis::test_util::RunBlockingPoolTask(); 585 google_apis::test_util::RunBlockingPoolTask();
581 EXPECT_EQ(DRIVE_FILE_ERROR_ACCESS_DENIED, error); 586 EXPECT_EQ(DRIVE_FILE_ERROR_ACCESS_DENIED, error);
582 } 587 }
583 588
584 TEST_F(DriveResourceMetadataTest, MoveEntryToDirectory) { 589 TEST_F(DriveResourceMetadataTest, MoveEntryToDirectory) {
585 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 590 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
586 base::FilePath drive_file_path; 591 base::FilePath drive_file_path;
587 scoped_ptr<DriveEntryProto> entry_proto; 592 scoped_ptr<DriveEntryProto> entry_proto;
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 814 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
810 base::FilePath drive_file_path; 815 base::FilePath drive_file_path;
811 scoped_ptr<DriveEntryProto> entry_proto; 816 scoped_ptr<DriveEntryProto> entry_proto;
812 817
813 // Get root. 818 // Get root.
814 entry_proto = GetEntryInfoByPathSync( 819 entry_proto = GetEntryInfoByPathSync(
815 base::FilePath::FromUTF8Unsafe("drive")); 820 base::FilePath::FromUTF8Unsafe("drive"));
816 ASSERT_TRUE(entry_proto.get()); 821 ASSERT_TRUE(entry_proto.get());
817 EXPECT_EQ("drive", entry_proto->base_name()); 822 EXPECT_EQ("drive", entry_proto->base_name());
818 ASSERT_TRUE(entry_proto->file_info().is_directory()); 823 ASSERT_TRUE(entry_proto->file_info().is_directory());
819 EXPECT_EQ(kTestRootResourceId, entry_proto->resource_id()); 824 EXPECT_EQ(util::kDriveGrandRootSpecialResourceId, entry_proto->resource_id());
820 EXPECT_TRUE(entry_proto->upload_url().empty()); 825 EXPECT_TRUE(entry_proto->upload_url().empty());
821 826
822 // Set upload url and call RefreshEntry on root. 827 // Set upload url and call RefreshEntry on root.
823 DriveEntryProto dir_entry_proto(*entry_proto); 828 DriveEntryProto dir_entry_proto(*entry_proto);
824 dir_entry_proto.set_upload_url("http://root.upload.url/"); 829 dir_entry_proto.set_upload_url("http://root.upload.url/");
825 entry_proto.reset(); 830 entry_proto.reset();
826 resource_metadata_->RefreshEntry( 831 resource_metadata_->RefreshEntry(
827 dir_entry_proto, 832 dir_entry_proto,
828 google_apis::test_util::CreateCopyResultCallback( 833 google_apis::test_util::CreateCopyResultCallback(
829 &error, &drive_file_path, &entry_proto)); 834 &error, &drive_file_path, &entry_proto));
830 google_apis::test_util::RunBlockingPoolTask(); 835 google_apis::test_util::RunBlockingPoolTask();
831 EXPECT_EQ(DRIVE_FILE_OK, error); 836 EXPECT_EQ(DRIVE_FILE_OK, error);
832 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive"), drive_file_path); 837 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive"), drive_file_path);
833 ASSERT_TRUE(entry_proto.get()); 838 ASSERT_TRUE(entry_proto.get());
834 EXPECT_EQ("drive", entry_proto->base_name()); 839 EXPECT_EQ("drive", entry_proto->base_name());
835 EXPECT_TRUE(entry_proto->file_info().is_directory()); 840 EXPECT_TRUE(entry_proto->file_info().is_directory());
836 EXPECT_EQ(kTestRootResourceId, entry_proto->resource_id()); 841 EXPECT_EQ(util::kDriveGrandRootSpecialResourceId, entry_proto->resource_id());
837 EXPECT_EQ("http://root.upload.url/", entry_proto->upload_url()); 842 EXPECT_EQ("http://root.upload.url/", entry_proto->upload_url());
838 843
839 // Make sure the children have moved over. Test file9. 844 // Make sure the children have moved over. Test file9.
840 entry_proto.reset(); 845 entry_proto.reset();
841 entry_proto = GetEntryInfoByPathSync( 846 entry_proto = GetEntryInfoByPathSync(
842 base::FilePath::FromUTF8Unsafe("drive/dir1/dir3/file9")); 847 base::FilePath::FromUTF8Unsafe("drive/dir1/dir3/file9"));
843 ASSERT_TRUE(entry_proto.get()); 848 ASSERT_TRUE(entry_proto.get());
844 EXPECT_EQ("file9", entry_proto->base_name()); 849 EXPECT_EQ("file9", entry_proto->base_name());
845 850
846 // Refreshing root with a proto which has parent_resource_id should fail. 851 // Refreshing root with a proto which has parent_resource_id should fail.
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 google_apis::test_util::RunBlockingPoolTask(); 1224 google_apis::test_util::RunBlockingPoolTask();
1220 1225
1221 base::FilePath drive_file_path; 1226 base::FilePath drive_file_path;
1222 scoped_ptr<DriveEntryProto> entry_proto; 1227 scoped_ptr<DriveEntryProto> entry_proto;
1223 1228
1224 // root should continue to exist. 1229 // root should continue to exist.
1225 entry_proto = GetEntryInfoByPathSync(base::FilePath::FromUTF8Unsafe("drive")); 1230 entry_proto = GetEntryInfoByPathSync(base::FilePath::FromUTF8Unsafe("drive"));
1226 ASSERT_TRUE(entry_proto.get()); 1231 ASSERT_TRUE(entry_proto.get());
1227 EXPECT_EQ("drive", entry_proto->base_name()); 1232 EXPECT_EQ("drive", entry_proto->base_name());
1228 ASSERT_TRUE(entry_proto->file_info().is_directory()); 1233 ASSERT_TRUE(entry_proto->file_info().is_directory());
1229 EXPECT_EQ(kTestRootResourceId, entry_proto->resource_id()); 1234 EXPECT_EQ(util::kDriveGrandRootSpecialResourceId, entry_proto->resource_id());
1230 1235
1231 // root should have no children. 1236 // There is only "other", which is empty.
satorux1 2013/04/05 01:55:30 Why was "drive/root" removed here?
Haruki Sato 2013/04/05 04:35:25 Thank you for the comment. This was from the orig
1232 entries = ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive")); 1237 entries = ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive"));
1233 ASSERT_TRUE(entries.get()); 1238 ASSERT_TRUE(entries.get());
1234 EXPECT_TRUE(entries->empty()); 1239 EXPECT_EQ(1U, entries->size());
1240
1241 scoped_ptr<DriveEntryProtoVector> entries_in_other =
1242 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive/other"));
1243 ASSERT_TRUE(entries_in_other.get());
1244 EXPECT_TRUE(entries_in_other->empty());
1245
1235 } 1246 }
1236 1247
1237 TEST_F(DriveResourceMetadataTest, PerDirectoryChangestamp) { 1248 TEST_F(DriveResourceMetadataTest, PerDirectoryChangestamp) {
1238 const int kNewChangestamp = kTestChangestamp + 1; 1249 const int kNewChangestamp = kTestChangestamp + 1;
1239 const char kSubDirectoryResourceId[] = "sub-directory-id"; 1250 const char kSubDirectoryResourceId[] = "sub-directory-id";
1240 1251
1241 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests> 1252 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests>
1242 resource_metadata_original(new DriveResourceMetadata( 1253 resource_metadata_original(new DriveResourceMetadata(
1243 kTestRootResourceId, temp_dir_.path(), blocking_task_runner_)); 1254 util::kDriveGrandRootSpecialResourceId, temp_dir_.path(),
1255 blocking_task_runner_));
1244 ForceUsingMemoryStorage(resource_metadata_original.get()); 1256 ForceUsingMemoryStorage(resource_metadata_original.get());
1245 1257
1246 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 1258 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1247 resource_metadata_original->Initialize( 1259 resource_metadata_original->Initialize(
1248 google_apis::test_util::CreateCopyResultCallback(&error)); 1260 google_apis::test_util::CreateCopyResultCallback(&error));
1249 google_apis::test_util::RunBlockingPoolTask(); 1261 google_apis::test_util::RunBlockingPoolTask();
1250 ASSERT_EQ(DRIVE_FILE_OK, error); 1262 ASSERT_EQ(DRIVE_FILE_OK, error);
1251 1263
1252 resource_metadata_original->SetLargestChangestamp( 1264 resource_metadata_original->SetLargestChangestamp(
1253 kNewChangestamp, 1265 kNewChangestamp,
1254 google_apis::test_util::CreateCopyResultCallback(&error)); 1266 google_apis::test_util::CreateCopyResultCallback(&error));
1255 google_apis::test_util::RunBlockingPoolTask(); 1267 google_apis::test_util::RunBlockingPoolTask();
1256 EXPECT_EQ(DRIVE_FILE_OK, error); 1268 EXPECT_EQ(DRIVE_FILE_OK, error);
1257 1269
1258 // Add a sub directory. 1270 // Add a sub directory.
1259 DriveEntryProto directory_entry; 1271 DriveEntryProto directory_entry;
1260 directory_entry.mutable_file_info()->set_is_directory(true); 1272 directory_entry.mutable_file_info()->set_is_directory(true);
1261 directory_entry.set_resource_id(kSubDirectoryResourceId); 1273 directory_entry.set_resource_id(kSubDirectoryResourceId);
1262 directory_entry.set_parent_resource_id(kTestRootResourceId); 1274 directory_entry.set_parent_resource_id(
1275 util::kDriveGrandRootSpecialResourceId);
1263 directory_entry.set_title("directory"); 1276 directory_entry.set_title("directory");
1264 base::FilePath file_path; 1277 base::FilePath file_path;
1265 resource_metadata_original->AddEntry( 1278 resource_metadata_original->AddEntry(
1266 directory_entry, 1279 directory_entry,
1267 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); 1280 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
1268 // At this point, both the root and the sub directory do not contain the 1281 // At this point, both the root and the sub directory do not contain the
1269 // per-directory changestamp. 1282 // per-directory changestamp.
1270 resource_metadata_original->MaybeSave(); 1283 resource_metadata_original->MaybeSave();
1271 google_apis::test_util::RunBlockingPoolTask(); 1284 google_apis::test_util::RunBlockingPoolTask();
1272 1285
1273 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests> 1286 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests>
1274 resource_metadata(new DriveResourceMetadata(kTestRootResourceId, 1287 resource_metadata(new DriveResourceMetadata(
1275 temp_dir_.path(), 1288 util::kDriveGrandRootSpecialResourceId,
1276 blocking_task_runner_)); 1289 temp_dir_.path(),
1290 blocking_task_runner_));
1277 ForceUsingMemoryStorage(resource_metadata.get()); 1291 ForceUsingMemoryStorage(resource_metadata.get());
1278 1292
1279 resource_metadata->Initialize( 1293 resource_metadata->Initialize(
1280 google_apis::test_util::CreateCopyResultCallback(&error)); 1294 google_apis::test_util::CreateCopyResultCallback(&error));
1281 google_apis::test_util::RunBlockingPoolTask(); 1295 google_apis::test_util::RunBlockingPoolTask();
1282 ASSERT_EQ(DRIVE_FILE_OK, error); 1296 ASSERT_EQ(DRIVE_FILE_OK, error);
1283 1297
1284 // Load. This should propagate the largest changestamp to every directory. 1298 // Load. This should propagate the largest changestamp to every directory.
1285 resource_metadata->Load( 1299 resource_metadata->Load(
1286 google_apis::test_util::CreateCopyResultCallback(&error)); 1300 google_apis::test_util::CreateCopyResultCallback(&error));
(...skipping 17 matching lines...) Expand all
1304 google_apis::test_util::RunBlockingPoolTask(); 1318 google_apis::test_util::RunBlockingPoolTask();
1305 ASSERT_EQ(DRIVE_FILE_OK, error); 1319 ASSERT_EQ(DRIVE_FILE_OK, error);
1306 EXPECT_EQ(kNewChangestamp, 1320 EXPECT_EQ(kNewChangestamp,
1307 entry_proto->directory_specific_info().changestamp()); 1321 entry_proto->directory_specific_info().changestamp());
1308 } 1322 }
1309 1323
1310 TEST_F(DriveResourceMetadataTest, SaveAndLoad) { 1324 TEST_F(DriveResourceMetadataTest, SaveAndLoad) {
1311 // Save metadata and reset. 1325 // Save metadata and reset.
1312 resource_metadata_->MaybeSave(); 1326 resource_metadata_->MaybeSave();
1313 1327
1314 resource_metadata_.reset(new DriveResourceMetadata(kTestRootResourceId, 1328 resource_metadata_.reset(new DriveResourceMetadata(
1315 temp_dir_.path(), 1329 util::kDriveGrandRootSpecialResourceId,
1316 blocking_task_runner_)); 1330 temp_dir_.path(),
1331 blocking_task_runner_));
1317 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 1332 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1318 resource_metadata_->Initialize( 1333 resource_metadata_->Initialize(
1319 google_apis::test_util::CreateCopyResultCallback(&error)); 1334 google_apis::test_util::CreateCopyResultCallback(&error));
1320 google_apis::test_util::RunBlockingPoolTask(); 1335 google_apis::test_util::RunBlockingPoolTask();
1321 ASSERT_EQ(DRIVE_FILE_OK, error); 1336 ASSERT_EQ(DRIVE_FILE_OK, error);
1322 1337
1323 // Load metadata. 1338 // Load metadata.
1324 resource_metadata_->Load( 1339 resource_metadata_->Load(
1325 google_apis::test_util::CreateCopyResultCallback(&error)); 1340 google_apis::test_util::CreateCopyResultCallback(&error));
1326 google_apis::test_util::RunBlockingPoolTask(); 1341 google_apis::test_util::RunBlockingPoolTask();
1327 EXPECT_EQ(DRIVE_FILE_OK, error); 1342 EXPECT_EQ(DRIVE_FILE_OK, error);
1328 1343
1329 // Try to get some data. 1344 // Try to get some data.
1330 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync( 1345 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(
1331 base::FilePath::FromUTF8Unsafe("drive/dir1/dir3/file9")); 1346 base::FilePath::FromUTF8Unsafe("drive/dir1/dir3/file9"));
1332 ASSERT_TRUE(entry.get()); 1347 ASSERT_TRUE(entry.get());
1333 EXPECT_EQ("file9", entry->base_name()); 1348 EXPECT_EQ("file9", entry->base_name());
1334 ASSERT_TRUE(!entry->file_info().is_directory()); 1349 ASSERT_TRUE(!entry->file_info().is_directory());
1335 EXPECT_EQ("md5:file9", entry->file_specific_info().file_md5()); 1350 EXPECT_EQ("md5:file9", entry->file_specific_info().file_md5());
1336 } 1351 }
1337 1352
1338 } // namespace drive 1353 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698