Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "chrome/browser/chromeos/gdata/gdata.pb.h" | 15 #include "chrome/browser/chromeos/gdata/gdata.pb.h" |
| 16 #include "chrome/browser/chromeos/gdata/gdata_cache.h" | 16 #include "chrome/browser/chromeos/gdata/gdata_cache.h" |
| 17 #include "chrome/browser/chromeos/gdata/gdata_test_util.h" | 17 #include "chrome/browser/chromeos/gdata/gdata_test_util.h" |
| 18 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 19 #include "content/public/test/test_browser_thread.h" | 19 #include "content/public/test/test_browser_thread.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 21 |
| 22 namespace gdata { | 22 namespace gdata { |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // See gdata.proto for the difference between the two URLs. | 25 // See gdata.proto for the difference between the two URLs. |
| 26 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/"; | 26 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/"; |
| 27 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/"; | 27 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/"; |
| 28 | 28 |
| 29 void OnAddEntryToDirectory(GDataFileError expected_error, | |
| 30 GDataFileError actual_error, | |
| 31 const FilePath& updated_file_path) { | |
| 32 EXPECT_EQ(expected_error, actual_error); | |
| 33 } | |
| 34 | |
| 29 // Add a directory to |parent| and return that directory. The name and | 35 // Add a directory to |parent| and return that directory. The name and |
| 30 // resource_id are determined by the incrementing counter |sequence_id|. | 36 // resource_id are determined by the incrementing counter |sequence_id|. |
| 31 GDataDirectory* AddDirectory(GDataDirectory* parent, | 37 GDataDirectory* AddDirectory(GDataDirectory* parent, |
| 32 GDataDirectoryService* directory_service, | 38 GDataDirectoryService* directory_service, |
| 33 int sequence_id) { | 39 int sequence_id) { |
| 34 GDataDirectory* dir = new GDataDirectory(parent, directory_service); | 40 GDataDirectory* dir = new GDataDirectory(NULL, directory_service); |
|
satorux1
2012/08/08 14:09:06
can you remove the first parameter?
achuithb
2012/08/08 22:08:41
In the next CL?
| |
| 35 const std::string dir_name = "dir" + base::IntToString(sequence_id); | 41 const std::string dir_name = "dir" + base::IntToString(sequence_id); |
| 36 const std::string resource_id = std::string("dir_resource_id:") + | 42 const std::string resource_id = std::string("dir_resource_id:") + |
| 37 dir_name; | 43 dir_name; |
| 38 dir->set_title(dir_name); | 44 dir->set_title(dir_name); |
| 39 dir->set_resource_id(resource_id); | 45 dir->set_resource_id(resource_id); |
| 40 GDataFileError error = GDATA_FILE_ERROR_FAILED; | |
| 41 directory_service->AddEntryToDirectory( | 46 directory_service->AddEntryToDirectory( |
| 42 parent->GetFilePath(), | 47 parent->GetFilePath(), |
| 43 dir, | 48 dir, |
| 44 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); | 49 base::Bind(&OnAddEntryToDirectory, GDATA_FILE_OK)); |
|
satorux1
2012/08/08 14:09:06
Hmm, this looks trickier than the original code. c
achuithb
2012/08/08 22:08:41
Good point. I can't use CopyErrorCodeFromFileOpera
achuithb
2012/08/08 22:38:00
I did this since I'm guessing you prefer this solu
| |
| 45 test_util::RunBlockingPoolTask(); | 50 test_util::RunBlockingPoolTask(); |
| 46 EXPECT_EQ(GDATA_FILE_OK, error); | |
| 47 return dir; | 51 return dir; |
| 48 } | 52 } |
| 49 | 53 |
| 50 // Add a file to |parent| and return that file. The name and | 54 // Add a file to |parent| and return that file. The name and |
| 51 // resource_id are determined by the incrementing counter |sequence_id|. | 55 // resource_id are determined by the incrementing counter |sequence_id|. |
| 52 GDataFile* AddFile(GDataDirectory* parent, | 56 GDataFile* AddFile(GDataDirectory* parent, |
| 53 GDataDirectoryService* directory_service, | 57 GDataDirectoryService* directory_service, |
| 54 int sequence_id) { | 58 int sequence_id) { |
| 55 GDataFile* file = new GDataFile(parent, directory_service); | 59 GDataFile* file = new GDataFile(NULL, directory_service); |
| 56 const std::string title = "file" + base::IntToString(sequence_id); | 60 const std::string title = "file" + base::IntToString(sequence_id); |
| 57 const std::string resource_id = std::string("file_resource_id:") + | 61 const std::string resource_id = std::string("file_resource_id:") + |
| 58 title; | 62 title; |
| 59 file->set_title(title); | 63 file->set_title(title); |
| 60 file->set_resource_id(resource_id); | 64 file->set_resource_id(resource_id); |
| 61 file->set_file_md5(std::string("file_md5:") + title); | 65 file->set_file_md5(std::string("file_md5:") + title); |
| 62 GDataFileError error = GDATA_FILE_ERROR_FAILED; | |
| 63 directory_service->AddEntryToDirectory( | 66 directory_service->AddEntryToDirectory( |
| 64 parent->GetFilePath(), | 67 parent->GetFilePath(), |
| 65 file, | 68 file, |
| 66 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); | 69 base::Bind(&OnAddEntryToDirectory, GDATA_FILE_OK)); |
| 67 test_util::RunBlockingPoolTask(); | 70 test_util::RunBlockingPoolTask(); |
| 68 EXPECT_EQ(GDATA_FILE_OK, error); | |
| 69 return file; | 71 return file; |
| 70 } | 72 } |
| 71 | 73 |
| 72 // Creates the following files/directories | 74 // Creates the following files/directories |
| 73 // drive/dir1/ | 75 // drive/dir1/ |
| 74 // drive/dir2/ | 76 // drive/dir2/ |
| 75 // drive/dir1/dir3/ | 77 // drive/dir1/dir3/ |
| 76 // drive/dir1/file4 | 78 // drive/dir1/file4 |
| 77 // drive/dir1/file5 | 79 // drive/dir1/file5 |
| 78 // drive/dir2/file6 | 80 // drive/dir2/file6 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 // No file should be added to the root directory. | 368 // No file should be added to the root directory. |
| 367 ASSERT_TRUE(root->child_files().empty()); | 369 ASSERT_TRUE(root->child_files().empty()); |
| 368 // Two directories ("empty", "dir") should be added to the root directory. | 370 // Two directories ("empty", "dir") should be added to the root directory. |
| 369 ASSERT_EQ(2U, root->child_directories().size()); | 371 ASSERT_EQ(2U, root->child_directories().size()); |
| 370 // The origin should change to FROM_CACHE because we loaded from the cache. | 372 // The origin should change to FROM_CACHE because we loaded from the cache. |
| 371 ASSERT_EQ(FROM_CACHE, directory_service.origin()); | 373 ASSERT_EQ(FROM_CACHE, directory_service.origin()); |
| 372 } | 374 } |
| 373 | 375 |
| 374 TEST(GDataRootDirectoryTest, RefreshFile) { | 376 TEST(GDataRootDirectoryTest, RefreshFile) { |
| 375 MessageLoopForUI message_loop; | 377 MessageLoopForUI message_loop; |
| 378 content::TestBrowserThread ui_thread(content::BrowserThread::UI, | |
| 379 &message_loop); | |
| 380 | |
| 376 GDataDirectoryService directory_service; | 381 GDataDirectoryService directory_service; |
| 377 GDataDirectory* root(directory_service.root()); | |
| 378 // Add a directory to the file system. | 382 // Add a directory to the file system. |
| 379 GDataDirectory* directory_entry = new GDataDirectory(root, | 383 GDataDirectory* directory_entry = new GDataDirectory(NULL, |
| 380 &directory_service); | 384 &directory_service); |
| 381 directory_entry->set_resource_id("folder:directory_resource_id"); | 385 directory_entry->set_resource_id("folder:directory_resource_id"); |
| 382 directory_entry->set_title("directory"); | 386 directory_entry->set_title("directory"); |
| 383 directory_entry->SetBaseNameFromTitle(); | 387 directory_entry->SetBaseNameFromTitle(); |
| 384 GDataFileError error = GDATA_FILE_ERROR_FAILED; | |
| 385 directory_service.AddEntryToDirectory( | 388 directory_service.AddEntryToDirectory( |
| 386 FilePath(kGDataRootDirectory), | 389 FilePath(kGDataRootDirectory), |
| 387 directory_entry, | 390 directory_entry, |
| 388 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); | 391 base::Bind(&OnAddEntryToDirectory, GDATA_FILE_OK)); |
| 389 test_util::RunBlockingPoolTask(); | 392 test_util::RunBlockingPoolTask(); |
| 390 ASSERT_EQ(GDATA_FILE_OK, error); | |
| 391 | 393 |
| 392 // Add a new file to the directory. | 394 // Add a new file to the directory. |
| 393 GDataFile* initial_file_entry = new GDataFile(NULL, &directory_service); | 395 GDataFile* initial_file_entry = new GDataFile(NULL, &directory_service); |
| 394 initial_file_entry->set_resource_id("file:file_resource_id"); | 396 initial_file_entry->set_resource_id("file:file_resource_id"); |
| 395 initial_file_entry->set_title("file"); | 397 initial_file_entry->set_title("file"); |
| 396 initial_file_entry->SetBaseNameFromTitle(); | 398 initial_file_entry->SetBaseNameFromTitle(); |
| 397 directory_service.AddEntryToDirectory( | 399 directory_service.AddEntryToDirectory( |
| 398 directory_entry->GetFilePath(), | 400 directory_entry->GetFilePath(), |
| 399 initial_file_entry, | 401 initial_file_entry, |
| 400 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); | 402 base::Bind(&OnAddEntryToDirectory, GDATA_FILE_OK)); |
| 401 test_util::RunBlockingPoolTask(); | 403 test_util::RunBlockingPoolTask(); |
| 402 ASSERT_EQ(GDATA_FILE_OK, error); | |
| 403 | 404 |
| 404 ASSERT_EQ(directory_entry, initial_file_entry->parent()); | 405 ASSERT_EQ(directory_entry, initial_file_entry->parent()); |
| 405 | 406 |
| 406 // Initial file system state set, let's try refreshing entries. | 407 // Initial file system state set, let's try refreshing entries. |
| 407 | 408 |
| 408 // New value for the entry with resource id "file:file_resource_id". | 409 // New value for the entry with resource id "file:file_resource_id". |
| 409 GDataFile* new_file_entry = new GDataFile(NULL, &directory_service); | 410 GDataFile* new_file_entry = new GDataFile(NULL, &directory_service); |
| 410 new_file_entry->set_resource_id("file:file_resource_id"); | 411 new_file_entry->set_resource_id("file:file_resource_id"); |
| 411 directory_service.RefreshFile(scoped_ptr<GDataFile>(new_file_entry).Pass()); | 412 directory_service.RefreshFile(scoped_ptr<GDataFile>(new_file_entry).Pass()); |
| 412 // Root should have |new_file_entry|, not |initial_file_entry|. | 413 // Root should have |new_file_entry|, not |initial_file_entry|. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 GDataDirectoryService directory_service2; | 465 GDataDirectoryService directory_service2; |
| 465 // InitFromDB should succeed with GDATA_FILE_OK as the db now exists. | 466 // InitFromDB should succeed with GDATA_FILE_OK as the db now exists. |
| 466 directory_service2.InitFromDB(db_path, blocking_task_runner, | 467 directory_service2.InitFromDB(db_path, blocking_task_runner, |
| 467 base::Bind(&InitFromDBCallback, GDATA_FILE_OK)); | 468 base::Bind(&InitFromDBCallback, GDATA_FILE_OK)); |
| 468 test_util::RunBlockingPoolTask(); | 469 test_util::RunBlockingPoolTask(); |
| 469 | 470 |
| 470 VerifyDirectoryService(&directory_service2); | 471 VerifyDirectoryService(&directory_service2); |
| 471 } | 472 } |
| 472 | 473 |
| 473 } // namespace gdata | 474 } // namespace gdata |
| OLD | NEW |