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

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

Issue 10919093: Rename GDataUplaoder to DriveUploader (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix after rebase Created 8 years, 3 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/json/json_file_value_serializer.h" 11 #include "base/json/json_file_value_serializer.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/scoped_temp_dir.h" 15 #include "base/scoped_temp_dir.h"
16 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
17 #include "base/threading/sequenced_worker_pool.h" 17 #include "base/threading/sequenced_worker_pool.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/chromeos/cros/cros_library.h" 19 #include "chrome/browser/chromeos/cros/cros_library.h"
20 #include "chrome/browser/chromeos/gdata/drive.pb.h" 20 #include "chrome/browser/chromeos/gdata/drive.pb.h"
21 #include "chrome/browser/chromeos/gdata/drive_api_parser.h" 21 #include "chrome/browser/chromeos/gdata/drive_api_parser.h"
22 #include "chrome/browser/chromeos/gdata/drive_file_system.h" 22 #include "chrome/browser/chromeos/gdata/drive_file_system.h"
23 #include "chrome/browser/chromeos/gdata/drive_file_system_util.h" 23 #include "chrome/browser/chromeos/gdata/drive_file_system_util.h"
24 #include "chrome/browser/chromeos/gdata/drive_function_remove.h" 24 #include "chrome/browser/chromeos/gdata/drive_function_remove.h"
25 #include "chrome/browser/chromeos/gdata/drive_uploader.h"
25 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" 26 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h"
26 #include "chrome/browser/chromeos/gdata/gdata_test_util.h" 27 #include "chrome/browser/chromeos/gdata/gdata_test_util.h"
27 #include "chrome/browser/chromeos/gdata/gdata_uploader.h"
28 #include "chrome/browser/chromeos/gdata/mock_directory_change_observer.h" 28 #include "chrome/browser/chromeos/gdata/mock_directory_change_observer.h"
29 #include "chrome/browser/chromeos/gdata/mock_drive_cache_observer.h" 29 #include "chrome/browser/chromeos/gdata/mock_drive_cache_observer.h"
30 #include "chrome/browser/chromeos/gdata/mock_drive_service.h" 30 #include "chrome/browser/chromeos/gdata/mock_drive_service.h"
31 #include "chrome/browser/chromeos/gdata/mock_drive_web_apps_registry.h" 31 #include "chrome/browser/chromeos/gdata/mock_drive_web_apps_registry.h"
32 #include "chrome/browser/chromeos/gdata/mock_free_disk_space_getter.h" 32 #include "chrome/browser/chromeos/gdata/mock_free_disk_space_getter.h"
33 #include "chrome/common/chrome_paths.h" 33 #include "chrome/common/chrome_paths.h"
34 #include "chrome/test/base/testing_profile.h" 34 #include "chrome/test/base/testing_profile.h"
35 #include "content/public/browser/browser_thread.h" 35 #include "content/public/browser/browser_thread.h"
36 #include "content/public/test/test_browser_thread.h" 36 #include "content/public/test/test_browser_thread.h"
37 #include "testing/gmock/include/gmock/gmock.h" 37 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 80 }
81 81
82 // Action used to set mock expectations for 82 // Action used to set mock expectations for
83 // DriveServiceInterface::GetDocumentEntry(). 83 // DriveServiceInterface::GetDocumentEntry().
84 ACTION_P2(MockGetDocumentEntry, status, value) { 84 ACTION_P2(MockGetDocumentEntry, status, value) {
85 base::MessageLoopProxy::current()->PostTask(FROM_HERE, 85 base::MessageLoopProxy::current()->PostTask(FROM_HERE,
86 base::Bind(arg1, status, base::Passed(value))); 86 base::Bind(arg1, status, base::Passed(value)));
87 } 87 }
88 88
89 // Action used to set mock expectations for 89 // Action used to set mock expectations for
90 // GDataUploaderInterface::UploadExistingFile(). 90 // DriveUploaderInterface::UploadExistingFile().
91 ACTION_P4(MockUploadExistingFile, 91 ACTION_P4(MockUploadExistingFile,
92 error, gdata_path, local_file_path, document_entry) { 92 error, drive_path, local_file_path, document_entry) {
93 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo); 93 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo);
94 upload_file_info->gdata_path = gdata_path; 94 upload_file_info->drive_path = drive_path;
95 upload_file_info->file_path = local_file_path; 95 upload_file_info->file_path = local_file_path;
96 upload_file_info->entry.reset(document_entry); 96 upload_file_info->entry.reset(document_entry);
97 base::MessageLoopProxy::current()->PostTask(FROM_HERE, 97 base::MessageLoopProxy::current()->PostTask(FROM_HERE,
98 base::Bind(arg5, error, base::Passed(&upload_file_info))); 98 base::Bind(arg5, error, base::Passed(&upload_file_info)));
99 99
100 const int kUploadId = 123; 100 const int kUploadId = 123;
101 return kUploadId; 101 return kUploadId;
102 } 102 }
103 103
104 // Action used to set mock expectations for 104 // Action used to set mock expectations for
105 // DriveFileSystem::CopyDocument(). 105 // DriveFileSystem::CopyDocument().
106 ACTION_P2(MockCopyDocument, status, value) { 106 ACTION_P2(MockCopyDocument, status, value) {
107 base::MessageLoopProxy::current()->PostTask( 107 base::MessageLoopProxy::current()->PostTask(
108 FROM_HERE, 108 FROM_HERE,
109 base::Bind(arg2, status, base::Passed(value))); 109 base::Bind(arg2, status, base::Passed(value)));
110 } 110 }
111 111
112 // Counts the number of files (not directories) in |entries|. 112 // Counts the number of files (not directories) in |entries|.
113 int CountFiles(const DriveEntryProtoVector& entries) { 113 int CountFiles(const DriveEntryProtoVector& entries) {
114 int num_files = 0; 114 int num_files = 0;
115 for (size_t i = 0; i < entries.size(); ++i) { 115 for (size_t i = 0; i < entries.size(); ++i) {
116 if (!entries[i].file_info().is_directory()) 116 if (!entries[i].file_info().is_directory())
117 ++num_files; 117 ++num_files;
118 } 118 }
119 return num_files; 119 return num_files;
120 } 120 }
121 121
122 } // namespace 122 } // namespace
123 123
124 class MockGDataUploader : public GDataUploaderInterface { 124 class MockDriveUploader : public DriveUploaderInterface {
125 public: 125 public:
126 virtual ~MockGDataUploader() {} 126 virtual ~MockDriveUploader() {}
127 // This function is not mockable by gmock. 127 // This function is not mockable by gmock.
128 virtual int UploadNewFile( 128 virtual int UploadNewFile(
129 scoped_ptr<UploadFileInfo> upload_file_info) OVERRIDE { 129 scoped_ptr<UploadFileInfo> upload_file_info) OVERRIDE {
130 // Set a document entry for an uploaded file. 130 // Set a document entry for an uploaded file.
131 // Used for TransferFileFromLocalToRemote_RegularFile test. 131 // Used for TransferFileFromLocalToRemote_RegularFile test.
132 scoped_ptr<base::Value> value( 132 scoped_ptr<base::Value> value(
133 test_util::LoadJSONFile("uploaded_file.json")); 133 test_util::LoadJSONFile("uploaded_file.json"));
134 scoped_ptr<DocumentEntry> document_entry( 134 scoped_ptr<DocumentEntry> document_entry(
135 DocumentEntry::ExtractAndParse(*value)); 135 DocumentEntry::ExtractAndParse(*value));
136 upload_file_info->entry = document_entry.Pass(); 136 upload_file_info->entry = document_entry.Pass();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 SetFreeDiskSpaceGetterForTesting(mock_free_disk_space_checker_); 199 SetFreeDiskSpaceGetterForTesting(mock_free_disk_space_checker_);
200 200
201 scoped_refptr<base::SequencedWorkerPool> pool = 201 scoped_refptr<base::SequencedWorkerPool> pool =
202 content::BrowserThread::GetBlockingPool(); 202 content::BrowserThread::GetBlockingPool();
203 blocking_task_runner_ = 203 blocking_task_runner_ =
204 pool->GetSequencedTaskRunner(pool->GetSequenceToken()); 204 pool->GetSequencedTaskRunner(pool->GetSequenceToken());
205 205
206 cache_ = DriveCache::CreateDriveCacheOnUIThread( 206 cache_ = DriveCache::CreateDriveCacheOnUIThread(
207 DriveCache::GetCacheRootPath(profile_.get()), blocking_task_runner_); 207 DriveCache::GetCacheRootPath(profile_.get()), blocking_task_runner_);
208 208
209 mock_uploader_.reset(new StrictMock<MockGDataUploader>); 209 mock_uploader_.reset(new StrictMock<MockDriveUploader>);
210 mock_webapps_registry_.reset(new StrictMock<MockDriveWebAppsRegistry>); 210 mock_webapps_registry_.reset(new StrictMock<MockDriveWebAppsRegistry>);
211 211
212 ASSERT_FALSE(file_system_); 212 ASSERT_FALSE(file_system_);
213 file_system_ = new DriveFileSystem(profile_.get(), 213 file_system_ = new DriveFileSystem(profile_.get(),
214 cache_, 214 cache_,
215 mock_drive_service_, 215 mock_drive_service_,
216 mock_uploader_.get(), 216 mock_uploader_.get(),
217 mock_webapps_registry_.get(), 217 mock_webapps_registry_.get(),
218 blocking_task_runner_); 218 blocking_task_runner_);
219 219
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 801
802 MessageLoopForUI message_loop_; 802 MessageLoopForUI message_loop_;
803 // The order of the test threads is important, do not change the order. 803 // The order of the test threads is important, do not change the order.
804 // See also content/browser/browser_thread_impl.cc. 804 // See also content/browser/browser_thread_impl.cc.
805 content::TestBrowserThread ui_thread_; 805 content::TestBrowserThread ui_thread_;
806 content::TestBrowserThread io_thread_; 806 content::TestBrowserThread io_thread_;
807 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 807 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
808 scoped_ptr<TestingProfile> profile_; 808 scoped_ptr<TestingProfile> profile_;
809 scoped_refptr<CallbackHelper> callback_helper_; 809 scoped_refptr<CallbackHelper> callback_helper_;
810 DriveCache* cache_; 810 DriveCache* cache_;
811 scoped_ptr<StrictMock<MockGDataUploader> > mock_uploader_; 811 scoped_ptr<StrictMock<MockDriveUploader> > mock_uploader_;
812 DriveFileSystem* file_system_; 812 DriveFileSystem* file_system_;
813 StrictMock<MockDriveService>* mock_drive_service_; 813 StrictMock<MockDriveService>* mock_drive_service_;
814 scoped_ptr<StrictMock<MockDriveWebAppsRegistry> > mock_webapps_registry_; 814 scoped_ptr<StrictMock<MockDriveWebAppsRegistry> > mock_webapps_registry_;
815 StrictMock<MockFreeDiskSpaceGetter>* mock_free_disk_space_checker_; 815 StrictMock<MockFreeDiskSpaceGetter>* mock_free_disk_space_checker_;
816 scoped_ptr<StrictMock<MockDriveCacheObserver> > mock_cache_observer_; 816 scoped_ptr<StrictMock<MockDriveCacheObserver> > mock_cache_observer_;
817 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_; 817 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_;
818 818
819 int num_callback_invocations_; 819 int num_callback_invocations_;
820 DriveFileError expected_error_; 820 DriveFileError expected_error_;
821 int expected_cache_state_; 821 int expected_cache_state_;
(...skipping 1516 matching lines...) Expand 10 before | Expand all | Expand 10 after
2338 test_util::TEST_CACHE_STATE_PERSISTENT, 2338 test_util::TEST_CACHE_STATE_PERSISTENT,
2339 DriveCache::CACHE_TYPE_PERSISTENT); 2339 DriveCache::CACHE_TYPE_PERSISTENT);
2340 const FilePath outgoing_symlink_path = 2340 const FilePath outgoing_symlink_path =
2341 DriveCache::GetCacheRootPath(profile_.get()) 2341 DriveCache::GetCacheRootPath(profile_.get())
2342 .AppendASCII("outgoing") 2342 .AppendASCII("outgoing")
2343 .AppendASCII(kResourceId); 2343 .AppendASCII(kResourceId);
2344 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path)); 2344 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path));
2345 ASSERT_TRUE(file_util::PathExists(outgoing_symlink_path)); 2345 ASSERT_TRUE(file_util::PathExists(outgoing_symlink_path));
2346 2346
2347 // Create a DocumentEntry, which is needed to mock 2347 // Create a DocumentEntry, which is needed to mock
2348 // GDataUploaderInterface::UploadExistingFile(). 2348 // DriveUploaderInterface::UploadExistingFile().
2349 // TODO(satorux): This should be cleaned up. crbug.com/134240. 2349 // TODO(satorux): This should be cleaned up. crbug.com/134240.
2350 DocumentEntry* document_entry = NULL; 2350 DocumentEntry* document_entry = NULL;
2351 scoped_ptr<base::Value> value(test_util::LoadJSONFile("root_feed.json")); 2351 scoped_ptr<base::Value> value(test_util::LoadJSONFile("root_feed.json"));
2352 ASSERT_TRUE(value.get()); 2352 ASSERT_TRUE(value.get());
2353 base::DictionaryValue* as_dict = NULL; 2353 base::DictionaryValue* as_dict = NULL;
2354 base::ListValue* entry_list = NULL; 2354 base::ListValue* entry_list = NULL;
2355 if (value->GetAsDictionary(&as_dict) && 2355 if (value->GetAsDictionary(&as_dict) &&
2356 as_dict->GetList("feed.entry", &entry_list)) { 2356 as_dict->GetList("feed.entry", &entry_list)) {
2357 for (size_t i = 0; i < entry_list->GetSize(); ++i) { 2357 for (size_t i = 0; i < entry_list->GetSize(); ++i) {
2358 base::DictionaryValue* entry = NULL; 2358 base::DictionaryValue* entry = NULL;
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
2613 2613
2614 // Try to close the same file twice. 2614 // Try to close the same file twice.
2615 file_system_->CloseFile(kFileInRoot, close_file_callback); 2615 file_system_->CloseFile(kFileInRoot, close_file_callback);
2616 message_loop_.Run(); 2616 message_loop_.Run();
2617 2617
2618 // It must fail. 2618 // It must fail.
2619 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); 2619 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_);
2620 } 2620 }
2621 2621
2622 } // namespace gdata 2622 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/drive_file_system_interface.h ('k') | chrome/browser/chromeos/gdata/drive_system_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698