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

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

Issue 13445002: Remove fake uploader from Drive 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/drive_scheduler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_file_system.h" 5 #include "chrome/browser/chromeos/drive/drive_file_system.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // Counts the number of files (not directories) in |entries|. 85 // Counts the number of files (not directories) in |entries|.
86 int CountFiles(const DriveEntryProtoVector& entries) { 86 int CountFiles(const DriveEntryProtoVector& entries) {
87 int num_files = 0; 87 int num_files = 0;
88 for (size_t i = 0; i < entries.size(); ++i) { 88 for (size_t i = 0; i < entries.size(); ++i) {
89 if (!entries[i].file_info().is_directory()) 89 if (!entries[i].file_info().is_directory())
90 ++num_files; 90 ++num_files;
91 } 91 }
92 return num_files; 92 return num_files;
93 } 93 }
94 94
95 // A fake implementation of DriveUploaderInterface, which provides fake
96 // behaviors for file uploading.
97 class FakeDriveUploader : public google_apis::DriveUploaderInterface {
98 public:
99 FakeDriveUploader() {}
100 virtual ~FakeDriveUploader() {}
101
102 // DriveUploaderInterface overrides.
103
104 // Pretends that a new file was uploaded successfully, and returns the
105 // contents of "chromeos/gdata/uploaded_file.json" to the caller.
106 virtual void UploadNewFile(
107 const std::string& parent_resource_id,
108 const base::FilePath& drive_file_path,
109 const base::FilePath& local_file_path,
110 const std::string& title,
111 const std::string& content_type,
112 const google_apis::UploadCompletionCallback& callback) OVERRIDE {
113 DCHECK(!callback.is_null());
114
115 scoped_ptr<base::Value> value =
116 google_apis::test_util::LoadJSONFile(
117 "chromeos/gdata/uploaded_file.json");
118 scoped_ptr<google_apis::ResourceEntry> resource_entry(
119 google_apis::ResourceEntry::ExtractAndParse(*value));
120
121 base::MessageLoopProxy::current()->PostTask(
122 FROM_HERE,
123 base::Bind(callback,
124 google_apis::DRIVE_UPLOAD_OK,
125 drive_file_path,
126 local_file_path,
127 base::Passed(&resource_entry)));
128 }
129
130 // Pretends that an existing file ("drive/File 1.txt") was uploaded
131 // successfully, and returns an entry for the file in
132 // "chromeos/gdata/root_feed.json" to the caller.
133 virtual void UploadExistingFile(
134 const std::string& resource_id,
135 const base::FilePath& drive_file_path,
136 const base::FilePath& local_file_path,
137 const std::string& content_type,
138 const std::string& etag,
139 const google_apis::UploadCompletionCallback& callback) OVERRIDE {
140 DCHECK(!callback.is_null());
141
142 // This function can only handle "drive/File 1.txt" whose resource ID is
143 // "file:2_file_resource_id".
144 DCHECK_EQ("drive/File 1.txt", drive_file_path.value());
145 const std::string kResourceId = "file:2_file_resource_id";
146 EXPECT_EQ(kResourceId, resource_id);
147
148 // Create a google_apis::ResourceEntry, which is needed to return a value
149 // from this function. TODO(satorux): This should be cleaned
150 // up. crbug.com/134240.
151 scoped_ptr<google_apis::ResourceEntry> resource_entry;
152 scoped_ptr<base::Value> value =
153 google_apis::test_util::LoadJSONFile("chromeos/gdata/root_feed.json");
154 if (!value.get())
155 return;
156
157 base::DictionaryValue* as_dict = NULL;
158 base::ListValue* entry_list = NULL;
159 if (value->GetAsDictionary(&as_dict) &&
160 as_dict->GetList("feed.entry", &entry_list)) {
161 for (size_t i = 0; i < entry_list->GetSize(); ++i) {
162 base::DictionaryValue* entry = NULL;
163 std::string entry_resource_id;
164 if (entry_list->GetDictionary(i, &entry) &&
165 entry->GetString("gd$resourceId.$t", &entry_resource_id) &&
166 entry_resource_id == kResourceId) {
167 resource_entry = google_apis::ResourceEntry::CreateFrom(*entry);
168 }
169 }
170 }
171 if (!resource_entry)
172 return;
173
174 base::MessageLoopProxy::current()->PostTask(
175 FROM_HERE,
176 base::Bind(callback,
177 google_apis::DRIVE_UPLOAD_OK,
178 drive_file_path,
179 local_file_path,
180 base::Passed(&resource_entry)));
181 }
182 };
183
184 } // namespace 95 } // namespace
185 96
186 class DriveFileSystemTest : public testing::Test { 97 class DriveFileSystemTest : public testing::Test {
187 protected: 98 protected:
188 DriveFileSystemTest() 99 DriveFileSystemTest()
189 : ui_thread_(content::BrowserThread::UI, &message_loop_), 100 : ui_thread_(content::BrowserThread::UI, &message_loop_),
190 expected_success_(true), 101 expected_success_(true),
191 // |root_feed_changestamp_| should be set to the largest changestamp in 102 // |root_feed_changestamp_| should be set to the largest changestamp in
192 // account metadata feed. But we fake it by some non-zero positive 103 // account metadata feed. But we fake it by some non-zero positive
193 // increasing value. See |LoadFeed()|. 104 // increasing value. See |LoadFeed()|.
(...skipping 15 matching lines...) Expand all
209 120
210 scoped_refptr<base::SequencedWorkerPool> pool = 121 scoped_refptr<base::SequencedWorkerPool> pool =
211 content::BrowserThread::GetBlockingPool(); 122 content::BrowserThread::GetBlockingPool();
212 blocking_task_runner_ = 123 blocking_task_runner_ =
213 pool->GetSequencedTaskRunner(pool->GetSequenceToken()); 124 pool->GetSequencedTaskRunner(pool->GetSequenceToken());
214 125
215 cache_.reset(new DriveCache(DriveCache::GetCacheRootPath(profile_.get()), 126 cache_.reset(new DriveCache(DriveCache::GetCacheRootPath(profile_.get()),
216 blocking_task_runner_, 127 blocking_task_runner_,
217 fake_free_disk_space_getter_.get())); 128 fake_free_disk_space_getter_.get()));
218 129
219 fake_uploader_.reset(new FakeDriveUploader); 130 uploader_.reset(new google_apis::DriveUploader(fake_drive_service_.get()));
220 drive_webapps_registry_.reset(new DriveWebAppsRegistry); 131 drive_webapps_registry_.reset(new DriveWebAppsRegistry);
221 132
222 133
223 mock_cache_observer_.reset(new StrictMock<MockDriveCacheObserver>); 134 mock_cache_observer_.reset(new StrictMock<MockDriveCacheObserver>);
224 cache_->AddObserver(mock_cache_observer_.get()); 135 cache_->AddObserver(mock_cache_observer_.get());
225 136
226 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>); 137 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>);
227 138
228 cache_->RequestInitializeForTesting(); 139 cache_->RequestInitializeForTesting();
229 google_apis::test_util::RunBlockingPoolTask(); 140 google_apis::test_util::RunBlockingPoolTask();
230 141
231 SetUpResourceMetadataAndFileSystem(); 142 SetUpResourceMetadataAndFileSystem();
232 } 143 }
233 144
234 void SetUpResourceMetadataAndFileSystem() { 145 void SetUpResourceMetadataAndFileSystem() {
235 resource_metadata_.reset(new DriveResourceMetadata( 146 resource_metadata_.reset(new DriveResourceMetadata(
236 fake_drive_service_->GetRootResourceId(), 147 fake_drive_service_->GetRootResourceId(),
237 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_META), 148 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_META),
238 blocking_task_runner_)); 149 blocking_task_runner_));
239 150
240 file_system_.reset(new DriveFileSystem(profile_.get(), 151 file_system_.reset(new DriveFileSystem(profile_.get(),
241 cache_.get(), 152 cache_.get(),
242 fake_drive_service_.get(), 153 fake_drive_service_.get(),
243 fake_uploader_.get(), 154 uploader_.get(),
244 drive_webapps_registry_.get(), 155 drive_webapps_registry_.get(),
245 resource_metadata_.get(), 156 resource_metadata_.get(),
246 blocking_task_runner_)); 157 blocking_task_runner_));
247 file_system_->AddObserver(mock_directory_observer_.get()); 158 file_system_->AddObserver(mock_directory_observer_.get());
248 file_system_->Initialize(); 159 file_system_->Initialize();
249 160
250 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 161 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
251 resource_metadata_->Initialize( 162 resource_metadata_->Initialize(
252 google_apis::test_util::CreateCopyResultCallback(&error)); 163 google_apis::test_util::CreateCopyResultCallback(&error));
253 google_apis::test_util::RunBlockingPoolTask(); 164 google_apis::test_util::RunBlockingPoolTask();
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 EXPECT_EQ(entry_proto.resource_id(), resource_id); 448 EXPECT_EQ(entry_proto.resource_id(), resource_id);
538 } 449 }
539 450
540 MessageLoopForUI message_loop_; 451 MessageLoopForUI message_loop_;
541 // The order of the test threads is important, do not change the order. 452 // The order of the test threads is important, do not change the order.
542 // See also content/browser/browser_thread_impl.cc. 453 // See also content/browser/browser_thread_impl.cc.
543 content::TestBrowserThread ui_thread_; 454 content::TestBrowserThread ui_thread_;
544 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 455 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
545 scoped_ptr<TestingProfile> profile_; 456 scoped_ptr<TestingProfile> profile_;
546 scoped_ptr<DriveCache, test_util::DestroyHelperForTests> cache_; 457 scoped_ptr<DriveCache, test_util::DestroyHelperForTests> cache_;
547 scoped_ptr<FakeDriveUploader> fake_uploader_; 458 scoped_ptr<google_apis::DriveUploaderInterface> uploader_;
548 scoped_ptr<DriveFileSystem> file_system_; 459 scoped_ptr<DriveFileSystem> file_system_;
549 scoped_ptr<google_apis::FakeDriveService> fake_drive_service_; 460 scoped_ptr<google_apis::FakeDriveService> fake_drive_service_;
550 scoped_ptr<DriveWebAppsRegistry> drive_webapps_registry_; 461 scoped_ptr<DriveWebAppsRegistry> drive_webapps_registry_;
551 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests> 462 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests>
552 resource_metadata_; 463 resource_metadata_;
553 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; 464 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_;
554 scoped_ptr<StrictMock<MockDriveCacheObserver> > mock_cache_observer_; 465 scoped_ptr<StrictMock<MockDriveCacheObserver> > mock_cache_observer_;
555 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_; 466 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_;
556 467
557 bool expected_success_; 468 bool expected_success_;
(...skipping 1657 matching lines...) Expand 10 before | Expand all | Expand 10 after
2215 2126
2216 // An app for foo.exe should now be found, as the registry was loaded. 2127 // An app for foo.exe should now be found, as the registry was loaded.
2217 drive_webapps_registry_->GetWebAppsForFile( 2128 drive_webapps_registry_->GetWebAppsForFile(
2218 base::FilePath(FILE_PATH_LITERAL("foo.exe")), 2129 base::FilePath(FILE_PATH_LITERAL("foo.exe")),
2219 "" /* mime_type */, 2130 "" /* mime_type */,
2220 &apps); 2131 &apps);
2221 EXPECT_EQ(1U, apps.size()); 2132 EXPECT_EQ(1U, apps.size());
2222 } 2133 }
2223 2134
2224 } // namespace drive 2135 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/drive_scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698