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

Side by Side Diff: chrome/browser/media_galleries/fileapi/picasa/picasa_file_util_unittest.cc

Issue 15653004: Picasa import: Make NativeMediaFileUtil an AsyncFileUtil (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address vandebo comments. Created 7 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 7
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/run_loop.h"
12 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
13 #include "base/time.h" 14 #include "base/time.h"
14 #include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_p rovider.h" 15 #include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_p rovider.h"
15 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" 16 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h"
16 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_album_table_reade r.h" 17 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_album_table_reade r.h"
17 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h" 18 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h"
18 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_file_util.h" 19 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_file_util.h"
19 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_constants.h" 20 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_constants.h"
20 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_test_helper.h" 21 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_test_helper.h"
22 #include "content/public/test/test_browser_thread.h"
21 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
22 #include "webkit/browser/fileapi/async_file_util_adapter.h" 24 #include "webkit/browser/fileapi/async_file_util_adapter.h"
23 #include "webkit/browser/fileapi/external_mount_points.h" 25 #include "webkit/browser/fileapi/external_mount_points.h"
24 #include "webkit/browser/fileapi/file_system_context.h" 26 #include "webkit/browser/fileapi/file_system_context.h"
25 #include "webkit/browser/fileapi/file_system_file_util.h" 27 #include "webkit/browser/fileapi/file_system_file_util.h"
26 #include "webkit/browser/fileapi/file_system_operation.h" 28 #include "webkit/browser/fileapi/file_system_operation.h"
27 #include "webkit/browser/fileapi/file_system_operation_context.h" 29 #include "webkit/browser/fileapi/file_system_operation_context.h"
28 #include "webkit/browser/fileapi/file_system_task_runners.h" 30 #include "webkit/browser/fileapi/file_system_task_runners.h"
29 #include "webkit/browser/fileapi/isolated_context.h" 31 #include "webkit/browser/fileapi/isolated_context.h"
30 #include "webkit/browser/fileapi/local_file_system_operation.h" 32 #include "webkit/browser/fileapi/local_file_system_operation.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 141 }
140 142
141 scoped_ptr<PicasaDataProvider> data_provider_; 143 scoped_ptr<PicasaDataProvider> data_provider_;
142 }; 144 };
143 145
144 class TestMediaFileSystemMountPointProvider 146 class TestMediaFileSystemMountPointProvider
145 : public chrome::MediaFileSystemMountPointProvider { 147 : public chrome::MediaFileSystemMountPointProvider {
146 public: 148 public:
147 TestMediaFileSystemMountPointProvider( 149 TestMediaFileSystemMountPointProvider(
148 const base::FilePath& profile_path, 150 const base::FilePath& profile_path,
149 scoped_ptr<PicasaFileUtil> picasa_file_util) 151 PicasaFileUtil* picasa_file_util)
150 : chrome::MediaFileSystemMountPointProvider(profile_path), 152 : chrome::MediaFileSystemMountPointProvider(profile_path),
151 test_file_util_(new fileapi::AsyncFileUtilAdapter( 153 test_file_util_(picasa_file_util) {
152 picasa_file_util.release())) {
153 } 154 }
154 155
155 virtual fileapi::AsyncFileUtil* 156 virtual fileapi::AsyncFileUtil*
156 GetAsyncFileUtil(fileapi::FileSystemType type) OVERRIDE { 157 GetAsyncFileUtil(fileapi::FileSystemType type) OVERRIDE {
157 if (type != fileapi::kFileSystemTypePicasa) 158 if (type != fileapi::kFileSystemTypePicasa)
158 return NULL; 159 return NULL;
159 160
160 return test_file_util_.get(); 161 return test_file_util_.get();
161 } 162 }
162 163
163 private: 164 private:
164 scoped_ptr<fileapi::AsyncFileUtil> test_file_util_; 165 scoped_ptr<fileapi::AsyncFileUtil> test_file_util_;
165 }; 166 };
166 167
167 void DidReadDirectory(FileSystemOperation::FileEntryList* contents, 168 void DidReadDirectory(FileSystemOperation::FileEntryList* contents,
168 bool* completed, base::PlatformFileError error, 169 bool* completed, base::PlatformFileError error,
169 const FileSystemOperation::FileEntryList& file_list, 170 const FileSystemOperation::FileEntryList& file_list,
170 bool has_more) { 171 bool has_more) {
171 DCHECK(!*completed); 172 DCHECK(!*completed);
172 *completed = !has_more && error == base::PLATFORM_FILE_OK; 173 *completed = !has_more && error == base::PLATFORM_FILE_OK;
173 *contents = file_list; 174 *contents = file_list;
174 } 175 }
175 176
177 void ReadDirectoryTestCallback(
178 base::RunLoop* run_loop,
179 base::PlatformFileError* error_result,
180 fileapi::AsyncFileUtil::EntryList* file_list_result,
181 bool* has_more_result,
182 base::PlatformFileError error,
183 const fileapi::AsyncFileUtil::EntryList& file_list,
184 bool has_more) {
185 DCHECK(error_result);
186 DCHECK(file_list_result);
187 DCHECK(has_more_result);
188 *error_result = error;
189 *file_list_result = file_list;
190 *has_more_result = has_more;
191 run_loop->Quit();
192 }
193
176 } // namespace 194 } // namespace
177 195
178 class PicasaFileUtilTest : public testing::Test { 196 class PicasaFileUtilTest : public testing::Test {
179 public: 197 public:
180 PicasaFileUtilTest() {} 198 PicasaFileUtilTest()
199 : io_thread_(content::BrowserThread::IO, &message_loop_) {
200 }
181 virtual ~PicasaFileUtilTest() {} 201 virtual ~PicasaFileUtilTest() {}
182 202
183 virtual void SetUp() OVERRIDE { 203 virtual void SetUp() OVERRIDE {
184 test_helper_.reset(new PmpTestHelper(kPicasaAlbumTableName)); 204 test_helper_.reset(new PmpTestHelper(kPicasaAlbumTableName));
185 ASSERT_TRUE(test_helper_->Init()); 205 ASSERT_TRUE(test_helper_->Init());
186 206
187 scoped_ptr<PicasaDataProvider> data_provider( 207 scoped_ptr<PicasaDataProvider> data_provider(
188 new PicasaDataProvider(test_helper_->GetTempDirPath())); 208 new PicasaDataProvider(test_helper_->GetTempDirPath()));
189 scoped_ptr<PicasaFileUtil> file_util(new TestPicasaFileUtil(
190 data_provider.Pass()));
191 209
192 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); 210 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir());
193 211
194 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = 212 scoped_refptr<quota::SpecialStoragePolicy> storage_policy =
195 new quota::MockSpecialStoragePolicy(); 213 new quota::MockSpecialStoragePolicy();
196 214
197 ScopedVector<fileapi::FileSystemMountPointProvider> additional_providers; 215 ScopedVector<fileapi::FileSystemMountPointProvider> additional_providers;
198 additional_providers.push_back( 216 additional_providers.push_back(new TestMediaFileSystemMountPointProvider(
199 new TestMediaFileSystemMountPointProvider(profile_dir_.path(), 217 profile_dir_.path(),
200 file_util.Pass())); 218 new TestPicasaFileUtil(data_provider.Pass())));
201 219
202 file_system_context_ = new fileapi::FileSystemContext( 220 file_system_context_ = new fileapi::FileSystemContext(
203 fileapi::FileSystemTaskRunners::CreateMockTaskRunners(), 221 fileapi::FileSystemTaskRunners::CreateMockTaskRunners(),
204 fileapi::ExternalMountPoints::CreateRefCounted().get(), 222 fileapi::ExternalMountPoints::CreateRefCounted().get(),
205 storage_policy, 223 storage_policy,
206 NULL, 224 NULL,
207 additional_providers.Pass(), 225 additional_providers.Pass(),
208 profile_dir_.path(), 226 profile_dir_.path(),
209 fileapi::CreateAllowFileAccessOptions()); 227 fileapi::CreateAllowFileAccessOptions());
210 } 228 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 FileSystemOperation* NewOperation(const FileSystemURL& url) { 336 FileSystemOperation* NewOperation(const FileSystemURL& url) {
319 return file_system_context_->CreateFileSystemOperation(url, NULL); 337 return file_system_context_->CreateFileSystemOperation(url, NULL);
320 } 338 }
321 339
322 scoped_refptr<fileapi::FileSystemContext> file_system_context() { 340 scoped_refptr<fileapi::FileSystemContext> file_system_context() {
323 return file_system_context_; 341 return file_system_context_;
324 } 342 }
325 343
326 private: 344 private:
327 base::MessageLoop message_loop_; 345 base::MessageLoop message_loop_;
346 content::TestBrowserThread io_thread_;
328 347
329 base::ScopedTempDir profile_dir_; 348 base::ScopedTempDir profile_dir_;
330 349
331 scoped_refptr<fileapi::FileSystemContext> file_system_context_; 350 scoped_refptr<fileapi::FileSystemContext> file_system_context_;
332 scoped_ptr<PmpTestHelper> test_helper_; 351 scoped_ptr<PmpTestHelper> test_helper_;
333 352
334 DISALLOW_COPY_AND_ASSIGN(PicasaFileUtilTest); 353 DISALLOW_COPY_AND_ASSIGN(PicasaFileUtilTest);
335 }; 354 };
336 355
337 TEST_F(PicasaFileUtilTest, DateFormat) { 356 TEST_F(PicasaFileUtilTest, DateFormat) {
(...skipping 30 matching lines...) Expand all
368 expected_names.push_back("duplicate " + test_date_string + " (1)"); 387 expected_names.push_back("duplicate " + test_date_string + " (1)");
369 388
370 folders.push_back( 389 folders.push_back(
371 AlbumInfo("duplicate", test_date, "uuid5", base::FilePath())); 390 AlbumInfo("duplicate", test_date, "uuid5", base::FilePath()));
372 expected_names.push_back("duplicate " + test_date_string + " (2)"); 391 expected_names.push_back("duplicate " + test_date_string + " (2)");
373 392
374 folders.push_back( 393 folders.push_back(
375 AlbumInfo("unique_name", test_date, "uuid1", base::FilePath())); 394 AlbumInfo("unique_name", test_date, "uuid1", base::FilePath()));
376 expected_names.push_back("unique_name " + test_date_string); 395 expected_names.push_back("unique_name " + test_date_string);
377 396
378 scoped_ptr<FileSystemOperationContext> operation_context( 397 FileSystemOperationContext operation_context(file_system_context().get());
379 new FileSystemOperationContext(file_system_context().get()));
380 398
381 scoped_ptr<chrome::MediaPathFilter> media_path_filter( 399 scoped_ptr<chrome::MediaPathFilter> media_path_filter(
382 new chrome::MediaPathFilter()); 400 new chrome::MediaPathFilter());
383 401
384 operation_context->SetUserValue( 402 operation_context.SetUserValue(
385 chrome::MediaFileSystemMountPointProvider::kMediaPathFilterKey, 403 chrome::MediaFileSystemMountPointProvider::kMediaPathFilterKey,
386 media_path_filter.get()); 404 media_path_filter.get());
387 405
388 scoped_ptr<PicasaDataProvider> data_provider( 406 scoped_ptr<PicasaDataProvider> data_provider(
389 new TestPicasaDataProvider(std::vector<AlbumInfo>(), folders)); 407 new TestPicasaDataProvider(std::vector<AlbumInfo>(), folders));
390 TestPicasaFileUtil file_util(data_provider.Pass()); 408 TestPicasaFileUtil test_file_util(data_provider.Pass());
391 409
392 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enumerator = 410 base::RunLoop run_loop;
vandebo (ex-Chrome) 2013/06/02 04:30:24 Probably should pull this into a helper function,
393 file_util.CreateFileEnumerator(operation_context.get(), 411 base::PlatformFileError result;
394 CreateURL("folders")); 412 fileapi::AsyncFileUtil::EntryList file_list;
413 bool has_more = false;
414 bool callback_made = test_file_util.ReadDirectory(
415 &operation_context,
416 CreateURL(kPicasaDirFolders),
417 base::Bind(&ReadDirectoryTestCallback, &run_loop, &result, &file_list,
418 &has_more));
419 ASSERT_TRUE(callback_made);
420 run_loop.Run();
421 ASSERT_EQ(result, base::PLATFORM_FILE_OK);
395 422
396 for (unsigned int i = 0; i < expected_names.size(); ++i) { 423 for (size_t i = 0; i < file_list.size(); ++i) {
397 base::FilePath path = file_enumerator->Next(); 424 ASSERT_FALSE(file_list[i].name.empty());
398 425 EXPECT_EQ(expected_names[i],
399 ASSERT_TRUE(!path.empty()); 426 base::FilePath(file_list[i].name).AsUTF8Unsafe());
400 EXPECT_EQ(expected_names[i], path.BaseName().AsUTF8Unsafe()); 427 EXPECT_EQ(folders[i].timestamp, file_list[i].last_modified_time);
401 EXPECT_EQ(folders[i].timestamp, file_enumerator->LastModifiedTime()); 428 EXPECT_TRUE(file_list[i].is_directory);
402 EXPECT_TRUE(file_enumerator->IsDirectory());
403 } 429 }
404 } 430 }
405 431
406 TEST_F(PicasaFileUtilTest, RootFolders) { 432 TEST_F(PicasaFileUtilTest, RootFolders) {
407 FileSystemOperation::FileEntryList contents; 433 FileSystemOperation::FileEntryList contents;
408 FileSystemURL url = CreateURL(""); 434 FileSystemURL url = CreateURL("");
409 bool completed = false; 435 bool completed = false;
410 NewOperation(url)->ReadDirectory( 436 NewOperation(url)->ReadDirectory(
411 url, base::Bind(&DidReadDirectory, &contents, &completed)); 437 url, base::Bind(&DidReadDirectory, &contents, &completed));
412 base::MessageLoop::current()->RunUntilIdle(); 438 base::MessageLoop::current()->RunUntilIdle();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 new TestFolder(base::StringPrintf("folder-%05d", i), 500 new TestFolder(base::StringPrintf("folder-%05d", i),
475 date, 501 date,
476 base::StringPrintf("uid%05d", i), i % 5, i % 3)); 502 base::StringPrintf("uid%05d", i), i % 5, i % 3));
477 } 503 }
478 504
479 SetupFolders(&test_folders); 505 SetupFolders(&test_folders);
480 VerifyFolderDirectoryList(test_folders); 506 VerifyFolderDirectoryList(test_folders);
481 } 507 }
482 508
483 } // namespace chrome 509 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698