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

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

Issue 10854083: Remove parent* arg from GDataEntry ctor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/gdata/gdata_files.h" 5 #include "chrome/browser/chromeos/gdata/gdata_files.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 14 matching lines...) Expand all
25 25
26 // See gdata.proto for the difference between the two URLs. 26 // See gdata.proto for the difference between the two URLs.
27 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/"; 27 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/";
28 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/"; 28 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/";
29 29
30 // Add a directory to |parent| and return that directory. The name and 30 // Add a directory to |parent| and return that directory. The name and
31 // resource_id are determined by the incrementing counter |sequence_id|. 31 // resource_id are determined by the incrementing counter |sequence_id|.
32 GDataDirectory* AddDirectory(GDataDirectory* parent, 32 GDataDirectory* AddDirectory(GDataDirectory* parent,
33 GDataDirectoryService* directory_service, 33 GDataDirectoryService* directory_service,
34 int sequence_id) { 34 int sequence_id) {
35 GDataDirectory* dir = new GDataDirectory(NULL, directory_service); 35 GDataDirectory* dir = directory_service->CreateGDataDirectory();
36 const std::string dir_name = "dir" + base::IntToString(sequence_id); 36 const std::string dir_name = "dir" + base::IntToString(sequence_id);
37 const std::string resource_id = std::string("dir_resource_id:") + 37 const std::string resource_id = std::string("dir_resource_id:") +
38 dir_name; 38 dir_name;
39 dir->set_title(dir_name); 39 dir->set_title(dir_name);
40 dir->set_resource_id(resource_id); 40 dir->set_resource_id(resource_id);
41 GDataFileError error = GDATA_FILE_ERROR_FAILED; 41 GDataFileError error = GDATA_FILE_ERROR_FAILED;
42 FilePath moved_file_path; 42 FilePath moved_file_path;
43 directory_service->MoveEntryToDirectory( 43 directory_service->MoveEntryToDirectory(
44 parent->GetFilePath(), 44 parent->GetFilePath(),
45 dir, 45 dir,
46 base::Bind(&test_util::CopyResultsFromFileMoveCallback, 46 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
47 &error, 47 &error,
48 &moved_file_path)); 48 &moved_file_path));
49 test_util::RunBlockingPoolTask(); 49 test_util::RunBlockingPoolTask();
50 EXPECT_EQ(GDATA_FILE_OK, error); 50 EXPECT_EQ(GDATA_FILE_OK, error);
51 EXPECT_EQ(parent->GetFilePath().AppendASCII(dir_name), moved_file_path); 51 EXPECT_EQ(parent->GetFilePath().AppendASCII(dir_name), moved_file_path);
52 return dir; 52 return dir;
53 } 53 }
54 54
55 // Add a file to |parent| and return that file. The name and 55 // Add a file to |parent| and return that file. The name and
56 // resource_id are determined by the incrementing counter |sequence_id|. 56 // resource_id are determined by the incrementing counter |sequence_id|.
57 GDataFile* AddFile(GDataDirectory* parent, 57 GDataFile* AddFile(GDataDirectory* parent,
58 GDataDirectoryService* directory_service, 58 GDataDirectoryService* directory_service,
59 int sequence_id) { 59 int sequence_id) {
60 GDataFile* file = new GDataFile(NULL, directory_service); 60 GDataFile* file = directory_service->CreateGDataFile();
61 const std::string title = "file" + base::IntToString(sequence_id); 61 const std::string title = "file" + base::IntToString(sequence_id);
62 const std::string resource_id = std::string("file_resource_id:") + 62 const std::string resource_id = std::string("file_resource_id:") +
63 title; 63 title;
64 file->set_title(title); 64 file->set_title(title);
65 file->set_resource_id(resource_id); 65 file->set_resource_id(resource_id);
66 file->set_file_md5(std::string("file_md5:") + title); 66 file->set_file_md5(std::string("file_md5:") + title);
67 GDataFileError error = GDATA_FILE_ERROR_FAILED; 67 GDataFileError error = GDATA_FILE_ERROR_FAILED;
68 FilePath moved_file_path; 68 FilePath moved_file_path;
69 directory_service->MoveEntryToDirectory( 69 directory_service->MoveEntryToDirectory(
70 parent->GetFilePath(), 70 parent->GetFilePath(),
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 GDataFileError actual_error) { 188 GDataFileError actual_error) {
189 EXPECT_EQ(expected_error, actual_error); 189 EXPECT_EQ(expected_error, actual_error);
190 } 190 }
191 191
192 } // namespace 192 } // namespace
193 193
194 TEST(GDataEntryTest, FromProto_DetectBadUploadUrl) { 194 TEST(GDataEntryTest, FromProto_DetectBadUploadUrl) {
195 GDataEntryProto proto; 195 GDataEntryProto proto;
196 proto.set_title("test.txt"); 196 proto.set_title("test.txt");
197 197
198 GDataEntry entry(NULL, NULL); 198 GDataDirectoryService directory_service;
199
200 scoped_ptr<GDataEntry> entry(directory_service.CreateGDataFile());
199 // This should fail as the upload URL is empty. 201 // This should fail as the upload URL is empty.
200 ASSERT_FALSE(entry.FromProto(proto)); 202 ASSERT_FALSE(entry->FromProto(proto));
201 203
202 // Set a upload URL. 204 // Set a upload URL.
203 proto.set_upload_url(kResumableEditMediaUrl); 205 proto.set_upload_url(kResumableEditMediaUrl);
204 206
205 // This should succeed as the upload URL is set. 207 // This should succeed as the upload URL is set.
206 ASSERT_TRUE(entry.FromProto(proto)); 208 ASSERT_TRUE(entry->FromProto(proto));
207 EXPECT_EQ(kResumableEditMediaUrl, entry.upload_url().spec()); 209 EXPECT_EQ(kResumableEditMediaUrl, entry->upload_url().spec());
208 } 210 }
209 211
210 TEST(GDataDirectoryServiceTest, VersionCheck) { 212 TEST(GDataDirectoryServiceTest, VersionCheck) {
211 // Set up the root directory. 213 // Set up the root directory.
212 GDataRootDirectoryProto proto; 214 GDataRootDirectoryProto proto;
213 GDataEntryProto* mutable_entry = 215 GDataEntryProto* mutable_entry =
214 proto.mutable_gdata_directory()->mutable_gdata_entry(); 216 proto.mutable_gdata_directory()->mutable_gdata_entry();
215 mutable_entry->mutable_file_info()->set_is_directory(true); 217 mutable_entry->mutable_file_info()->set_is_directory(true);
216 mutable_entry->set_resource_id(kGDataRootDirectoryResourceId); 218 mutable_entry->set_resource_id(kGDataRootDirectoryResourceId);
217 mutable_entry->set_upload_url(kResumableCreateMediaUrl); 219 mutable_entry->set_upload_url(kResumableCreateMediaUrl);
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 ASSERT_EQ(FROM_CACHE, directory_service.origin()); 382 ASSERT_EQ(FROM_CACHE, directory_service.origin());
381 } 383 }
382 384
383 TEST(GDataDirectoryServiceTest, RefreshFile) { 385 TEST(GDataDirectoryServiceTest, RefreshFile) {
384 MessageLoopForUI message_loop; 386 MessageLoopForUI message_loop;
385 content::TestBrowserThread ui_thread(content::BrowserThread::UI, 387 content::TestBrowserThread ui_thread(content::BrowserThread::UI,
386 &message_loop); 388 &message_loop);
387 389
388 GDataDirectoryService directory_service; 390 GDataDirectoryService directory_service;
389 // Add a directory to the file system. 391 // Add a directory to the file system.
390 GDataDirectory* directory_entry = new GDataDirectory(NULL, 392 GDataDirectory* directory_entry = directory_service.CreateGDataDirectory();
391 &directory_service);
392 directory_entry->set_resource_id("folder:directory_resource_id"); 393 directory_entry->set_resource_id("folder:directory_resource_id");
393 directory_entry->set_title("directory"); 394 directory_entry->set_title("directory");
394 directory_entry->SetBaseNameFromTitle(); 395 directory_entry->SetBaseNameFromTitle();
395 GDataFileError error = GDATA_FILE_ERROR_FAILED; 396 GDataFileError error = GDATA_FILE_ERROR_FAILED;
396 FilePath moved_file_path; 397 FilePath moved_file_path;
397 FilePath root_path(kGDataRootDirectory); 398 FilePath root_path(kGDataRootDirectory);
398 directory_service.MoveEntryToDirectory( 399 directory_service.MoveEntryToDirectory(
399 root_path, 400 root_path,
400 directory_entry, 401 directory_entry,
401 base::Bind(&test_util::CopyResultsFromFileMoveCallback, 402 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
402 &error, 403 &error,
403 &moved_file_path)); 404 &moved_file_path));
404 test_util::RunBlockingPoolTask(); 405 test_util::RunBlockingPoolTask();
405 ASSERT_EQ(GDATA_FILE_OK, error); 406 ASSERT_EQ(GDATA_FILE_OK, error);
406 EXPECT_EQ(root_path.AppendASCII(directory_entry->base_name()), 407 EXPECT_EQ(root_path.AppendASCII(directory_entry->base_name()),
407 moved_file_path); 408 moved_file_path);
408 409
409 // Add a new file to the directory. 410 // Add a new file to the directory.
410 GDataFile* initial_file_entry = new GDataFile(NULL, &directory_service); 411 GDataFile* initial_file_entry = directory_service.CreateGDataFile();
411 initial_file_entry->set_resource_id("file:file_resource_id"); 412 initial_file_entry->set_resource_id("file:file_resource_id");
412 initial_file_entry->set_title("file"); 413 initial_file_entry->set_title("file");
413 initial_file_entry->SetBaseNameFromTitle(); 414 initial_file_entry->SetBaseNameFromTitle();
414 error = GDATA_FILE_ERROR_FAILED; 415 error = GDATA_FILE_ERROR_FAILED;
415 moved_file_path.clear(); 416 moved_file_path.clear();
416 directory_service.MoveEntryToDirectory( 417 directory_service.MoveEntryToDirectory(
417 directory_entry->GetFilePath(), 418 directory_entry->GetFilePath(),
418 initial_file_entry, 419 initial_file_entry,
419 base::Bind(&test_util::CopyResultsFromFileMoveCallback, 420 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
420 &error, 421 &error,
421 &moved_file_path)); 422 &moved_file_path));
422 test_util::RunBlockingPoolTask(); 423 test_util::RunBlockingPoolTask();
423 ASSERT_EQ(GDATA_FILE_OK, error); 424 ASSERT_EQ(GDATA_FILE_OK, error);
424 EXPECT_EQ(directory_entry->GetFilePath().AppendASCII( 425 EXPECT_EQ(directory_entry->GetFilePath().AppendASCII(
425 initial_file_entry->base_name()), moved_file_path); 426 initial_file_entry->base_name()), moved_file_path);
426 427
427 ASSERT_EQ(directory_entry, initial_file_entry->parent()); 428 ASSERT_EQ(directory_entry, initial_file_entry->parent());
428 429
429 // Initial file system state set, let's try refreshing entries. 430 // Initial file system state set, let's try refreshing entries.
430 431
431 // New value for the entry with resource id "file:file_resource_id". 432 // New value for the entry with resource id "file:file_resource_id".
432 GDataFile* new_file_entry = new GDataFile(NULL, &directory_service); 433 GDataFile* new_file_entry = directory_service.CreateGDataFile();
433 new_file_entry->set_resource_id("file:file_resource_id"); 434 new_file_entry->set_resource_id("file:file_resource_id");
434 directory_service.RefreshFile(scoped_ptr<GDataFile>(new_file_entry).Pass()); 435 directory_service.RefreshFile(scoped_ptr<GDataFile>(new_file_entry).Pass());
435 // Root should have |new_file_entry|, not |initial_file_entry|. 436 // Root should have |new_file_entry|, not |initial_file_entry|.
436 // If this is not true, |new_file_entry| has probably been destroyed, hence 437 // If this is not true, |new_file_entry| has probably been destroyed, hence
437 // ASSERT (we're trying to access |new_file_entry| later on). 438 // ASSERT (we're trying to access |new_file_entry| later on).
438 ASSERT_EQ(new_file_entry, 439 ASSERT_EQ(new_file_entry,
439 directory_service.GetEntryByResourceId("file:file_resource_id")); 440 directory_service.GetEntryByResourceId("file:file_resource_id"));
440 // We have just verified new_file_entry exists inside root, so accessing 441 // We have just verified new_file_entry exists inside root, so accessing
441 // |new_file_entry->parent()| should be safe. 442 // |new_file_entry->parent()| should be safe.
442 EXPECT_EQ(directory_entry, new_file_entry->parent()); 443 EXPECT_EQ(directory_entry, new_file_entry->parent());
443 444
444 // Let's try refreshing file that didn't prviously exist. 445 // Let's try refreshing file that didn't prviously exist.
445 GDataFile* non_existent_entry = new GDataFile(NULL, &directory_service); 446 GDataFile* non_existent_entry = directory_service.CreateGDataFile();
446 non_existent_entry->set_resource_id("file:does_not_exist"); 447 non_existent_entry->set_resource_id("file:does_not_exist");
447 directory_service.RefreshFile( 448 directory_service.RefreshFile(
448 scoped_ptr<GDataFile>(non_existent_entry).Pass()); 449 scoped_ptr<GDataFile>(non_existent_entry).Pass());
449 // File with non existent resource id should not be added. 450 // File with non existent resource id should not be added.
450 EXPECT_FALSE(directory_service.GetEntryByResourceId("file:does_not_exist")); 451 EXPECT_FALSE(directory_service.GetEntryByResourceId("file:does_not_exist"));
451 } 452 }
452 453
453 TEST(GDataDirectoryServiceTest, GetEntryByResourceId_RootDirectory) { 454 TEST(GDataDirectoryServiceTest, GetEntryByResourceId_RootDirectory) {
454 GDataDirectoryService directory_service; 455 GDataDirectoryService directory_service;
455 // Look up the root directory by its resource ID. 456 // Look up the root directory by its resource ID.
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 GDataDirectoryService directory_service2; 638 GDataDirectoryService directory_service2;
638 // InitFromDB should succeed with GDATA_FILE_OK as the db now exists. 639 // InitFromDB should succeed with GDATA_FILE_OK as the db now exists.
639 directory_service2.InitFromDB(db_path, blocking_task_runner, 640 directory_service2.InitFromDB(db_path, blocking_task_runner,
640 base::Bind(&InitFromDBCallback, GDATA_FILE_OK)); 641 base::Bind(&InitFromDBCallback, GDATA_FILE_OK));
641 test_util::RunBlockingPoolTask(); 642 test_util::RunBlockingPoolTask();
642 643
643 VerifyDirectoryService(&directory_service2); 644 VerifyDirectoryService(&directory_service2);
644 } 645 }
645 646
646 } // namespace gdata 647 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698