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

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

Issue 10827211: Replace GDataDirectory::TakeEntry with GDataDirectoryService::AddEntryToDirectory. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: renames as per feedback 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(parent, directory_service); 35 GDataDirectory* dir = new GDataDirectory(NULL, directory_service);
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 directory_service->AddEntryToDirectory( 42 directory_service->MoveEntryToDirectory(
43 parent->GetFilePath(), 43 parent->GetFilePath(),
44 dir, 44 dir,
45 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 45 base::Bind(&test_util::CopyErrorCodeFromFileMoveCallback, &error));
46 test_util::RunBlockingPoolTask(); 46 test_util::RunBlockingPoolTask();
47 EXPECT_EQ(GDATA_FILE_OK, error); 47 EXPECT_EQ(GDATA_FILE_OK, error);
satorux1 2012/08/09 00:26:24 To test MoveEntryToDirectory better, I think we sh
achuithb 2012/08/09 01:41:32 Done.
48 return dir; 48 return dir;
49 } 49 }
50 50
51 // Add a file to |parent| and return that file. The name and 51 // Add a file to |parent| and return that file. The name and
52 // resource_id are determined by the incrementing counter |sequence_id|. 52 // resource_id are determined by the incrementing counter |sequence_id|.
53 GDataFile* AddFile(GDataDirectory* parent, 53 GDataFile* AddFile(GDataDirectory* parent,
54 GDataDirectoryService* directory_service, 54 GDataDirectoryService* directory_service,
55 int sequence_id) { 55 int sequence_id) {
56 GDataFile* file = new GDataFile(parent, directory_service); 56 GDataFile* file = new GDataFile(NULL, directory_service);
57 const std::string title = "file" + base::IntToString(sequence_id); 57 const std::string title = "file" + base::IntToString(sequence_id);
58 const std::string resource_id = std::string("file_resource_id:") + 58 const std::string resource_id = std::string("file_resource_id:") +
59 title; 59 title;
60 file->set_title(title); 60 file->set_title(title);
61 file->set_resource_id(resource_id); 61 file->set_resource_id(resource_id);
62 file->set_file_md5(std::string("file_md5:") + title); 62 file->set_file_md5(std::string("file_md5:") + title);
63 GDataFileError error = GDATA_FILE_ERROR_FAILED; 63 GDataFileError error = GDATA_FILE_ERROR_FAILED;
64 directory_service->AddEntryToDirectory( 64 directory_service->MoveEntryToDirectory(
65 parent->GetFilePath(), 65 parent->GetFilePath(),
66 file, 66 file,
67 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 67 base::Bind(&test_util::CopyErrorCodeFromFileMoveCallback, &error));
68 test_util::RunBlockingPoolTask(); 68 test_util::RunBlockingPoolTask();
69 EXPECT_EQ(GDATA_FILE_OK, error); 69 EXPECT_EQ(GDATA_FILE_OK, error);
satorux1 2012/08/09 00:26:24 ditto, and elsewhere too.
achuithb 2012/08/09 01:41:32 Done.
70 return file; 70 return file;
71 } 71 }
72 72
73 // Creates the following files/directories 73 // Creates the following files/directories
74 // drive/dir1/ 74 // drive/dir1/
75 // drive/dir2/ 75 // drive/dir2/
76 // drive/dir1/dir3/ 76 // drive/dir1/dir3/
77 // drive/dir1/file4 77 // drive/dir1/file4
78 // drive/dir1/file5 78 // drive/dir1/file5
79 // drive/dir2/file6 79 // drive/dir2/file6
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 // No file should be added to the root directory. 367 // No file should be added to the root directory.
368 ASSERT_TRUE(root->child_files().empty()); 368 ASSERT_TRUE(root->child_files().empty());
369 // Two directories ("empty", "dir") should be added to the root directory. 369 // Two directories ("empty", "dir") should be added to the root directory.
370 ASSERT_EQ(2U, root->child_directories().size()); 370 ASSERT_EQ(2U, root->child_directories().size());
371 // The origin should change to FROM_CACHE because we loaded from the cache. 371 // The origin should change to FROM_CACHE because we loaded from the cache.
372 ASSERT_EQ(FROM_CACHE, directory_service.origin()); 372 ASSERT_EQ(FROM_CACHE, directory_service.origin());
373 } 373 }
374 374
375 TEST(GDataDirectoryServiceTest, RefreshFile) { 375 TEST(GDataDirectoryServiceTest, RefreshFile) {
376 MessageLoopForUI message_loop; 376 MessageLoopForUI message_loop;
377 content::TestBrowserThread ui_thread(content::BrowserThread::UI,
378 &message_loop);
379
377 GDataDirectoryService directory_service; 380 GDataDirectoryService directory_service;
378 GDataDirectory* root(directory_service.root());
379 // Add a directory to the file system. 381 // Add a directory to the file system.
380 GDataDirectory* directory_entry = new GDataDirectory(root, 382 GDataDirectory* directory_entry = new GDataDirectory(NULL,
381 &directory_service); 383 &directory_service);
382 directory_entry->set_resource_id("folder:directory_resource_id"); 384 directory_entry->set_resource_id("folder:directory_resource_id");
383 directory_entry->set_title("directory"); 385 directory_entry->set_title("directory");
384 directory_entry->SetBaseNameFromTitle(); 386 directory_entry->SetBaseNameFromTitle();
385 GDataFileError error = GDATA_FILE_ERROR_FAILED; 387 GDataFileError error = GDATA_FILE_ERROR_FAILED;
386 directory_service.AddEntryToDirectory( 388 directory_service.MoveEntryToDirectory(
387 FilePath(kGDataRootDirectory), 389 FilePath(kGDataRootDirectory),
388 directory_entry, 390 directory_entry,
389 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 391 base::Bind(&test_util::CopyErrorCodeFromFileMoveCallback, &error));
390 test_util::RunBlockingPoolTask(); 392 test_util::RunBlockingPoolTask();
391 ASSERT_EQ(GDATA_FILE_OK, error); 393 ASSERT_EQ(GDATA_FILE_OK, error);
392 394
393 // Add a new file to the directory. 395 // Add a new file to the directory.
394 GDataFile* initial_file_entry = new GDataFile(NULL, &directory_service); 396 GDataFile* initial_file_entry = new GDataFile(NULL, &directory_service);
395 initial_file_entry->set_resource_id("file:file_resource_id"); 397 initial_file_entry->set_resource_id("file:file_resource_id");
396 initial_file_entry->set_title("file"); 398 initial_file_entry->set_title("file");
397 initial_file_entry->SetBaseNameFromTitle(); 399 initial_file_entry->SetBaseNameFromTitle();
398 directory_service.AddEntryToDirectory( 400 error = GDATA_FILE_ERROR_FAILED;
401 directory_service.MoveEntryToDirectory(
399 directory_entry->GetFilePath(), 402 directory_entry->GetFilePath(),
400 initial_file_entry, 403 initial_file_entry,
401 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 404 base::Bind(&test_util::CopyErrorCodeFromFileMoveCallback, &error));
402 test_util::RunBlockingPoolTask(); 405 test_util::RunBlockingPoolTask();
403 ASSERT_EQ(GDATA_FILE_OK, error); 406 ASSERT_EQ(GDATA_FILE_OK, error);
404 407
405 ASSERT_EQ(directory_entry, initial_file_entry->parent()); 408 ASSERT_EQ(directory_entry, initial_file_entry->parent());
406 409
407 // Initial file system state set, let's try refreshing entries. 410 // Initial file system state set, let's try refreshing entries.
408 411
409 // New value for the entry with resource id "file:file_resource_id". 412 // New value for the entry with resource id "file:file_resource_id".
410 GDataFile* new_file_entry = new GDataFile(NULL, &directory_service); 413 GDataFile* new_file_entry = new GDataFile(NULL, &directory_service);
411 new_file_entry->set_resource_id("file:file_resource_id"); 414 new_file_entry->set_resource_id("file:file_resource_id");
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 GDataDirectoryService directory_service2; 618 GDataDirectoryService directory_service2;
616 // InitFromDB should succeed with GDATA_FILE_OK as the db now exists. 619 // InitFromDB should succeed with GDATA_FILE_OK as the db now exists.
617 directory_service2.InitFromDB(db_path, blocking_task_runner, 620 directory_service2.InitFromDB(db_path, blocking_task_runner,
618 base::Bind(&InitFromDBCallback, GDATA_FILE_OK)); 621 base::Bind(&InitFromDBCallback, GDATA_FILE_OK));
619 test_util::RunBlockingPoolTask(); 622 test_util::RunBlockingPoolTask();
620 623
621 VerifyDirectoryService(&directory_service2); 624 VerifyDirectoryService(&directory_service2);
622 } 625 }
623 626
624 } // namespace gdata 627 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698