| OLD | NEW |
| 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 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/browser/media_galleries/fileapi/picasa_data_provider.h" | 22 #include "chrome/browser/media_galleries/fileapi/picasa_data_provider.h" |
| 23 #include "chrome/browser/media_galleries/fileapi/picasa_file_util.h" | 23 #include "chrome/browser/media_galleries/fileapi/picasa_file_util.h" |
| 24 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" | 24 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" |
| 25 #include "chrome/common/media_galleries/picasa_types.h" | 25 #include "chrome/common/media_galleries/picasa_types.h" |
| 26 #include "chrome/common/media_galleries/pmp_constants.h" | 26 #include "chrome/common/media_galleries/pmp_constants.h" |
| 27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/test/mock_special_storage_policy.h" | 28 #include "content/public/test/mock_special_storage_policy.h" |
| 29 #include "content/public/test/test_browser_thread.h" | 29 #include "content/public/test/test_browser_thread.h" |
| 30 #include "content/public/test/test_file_system_options.h" | 30 #include "content/public/test/test_file_system_options.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 32 #include "webkit/browser/fileapi/async_file_util.h" | 32 #include "storage/browser/fileapi/async_file_util.h" |
| 33 #include "webkit/browser/fileapi/external_mount_points.h" | 33 #include "storage/browser/fileapi/external_mount_points.h" |
| 34 #include "webkit/browser/fileapi/file_system_context.h" | 34 #include "storage/browser/fileapi/file_system_context.h" |
| 35 #include "webkit/browser/fileapi/file_system_operation_context.h" | 35 #include "storage/browser/fileapi/file_system_operation_context.h" |
| 36 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 36 #include "storage/browser/fileapi/file_system_operation_runner.h" |
| 37 #include "webkit/browser/fileapi/isolated_context.h" | 37 #include "storage/browser/fileapi/isolated_context.h" |
| 38 #include "webkit/common/blob/shareable_file_reference.h" | 38 #include "storage/common/blob/shareable_file_reference.h" |
| 39 | 39 |
| 40 using fileapi::FileSystemOperationContext; | 40 using storage::FileSystemOperationContext; |
| 41 using fileapi::FileSystemOperation; | 41 using storage::FileSystemOperation; |
| 42 using fileapi::FileSystemURL; | 42 using storage::FileSystemURL; |
| 43 | 43 |
| 44 namespace picasa { | 44 namespace picasa { |
| 45 | 45 |
| 46 namespace { | 46 namespace { |
| 47 | 47 |
| 48 base::Time::Exploded test_date_exploded = { 2013, 4, 0, 16, 0, 0, 0, 0 }; | 48 base::Time::Exploded test_date_exploded = { 2013, 4, 0, 16, 0, 0, 0, 0 }; |
| 49 | 49 |
| 50 bool WriteJPEGHeader(const base::FilePath& path) { | 50 bool WriteJPEGHeader(const base::FilePath& path) { |
| 51 const char kJpegHeader[] = "\xFF\xD8\xFF"; // Per HTML5 specification. | 51 const char kJpegHeader[] = "\xFF\xD8\xFF"; // Per HTML5 specification. |
| 52 return base::WriteFile(path, kJpegHeader, arraysize(kJpegHeader)) != -1; | 52 return base::WriteFile(path, kJpegHeader, arraysize(kJpegHeader)) != -1; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 FileSystemOperation::FileEntryList* contents, | 135 FileSystemOperation::FileEntryList* contents, |
| 136 bool* completed, base::File::Error error, | 136 bool* completed, base::File::Error error, |
| 137 const FileSystemOperation::FileEntryList& file_list, | 137 const FileSystemOperation::FileEntryList& file_list, |
| 138 bool has_more) { | 138 bool has_more) { |
| 139 DCHECK(!*completed); | 139 DCHECK(!*completed); |
| 140 *completed = !has_more && error == base::File::FILE_OK; | 140 *completed = !has_more && error == base::File::FILE_OK; |
| 141 *contents = file_list; | 141 *contents = file_list; |
| 142 run_loop->Quit(); | 142 run_loop->Quit(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void ReadDirectoryTestHelper(fileapi::FileSystemOperationRunner* runner, | 145 void ReadDirectoryTestHelper(storage::FileSystemOperationRunner* runner, |
| 146 const FileSystemURL& url, | 146 const FileSystemURL& url, |
| 147 FileSystemOperation::FileEntryList* contents, | 147 FileSystemOperation::FileEntryList* contents, |
| 148 bool* completed) { | 148 bool* completed) { |
| 149 DCHECK(contents); | 149 DCHECK(contents); |
| 150 DCHECK(completed); | 150 DCHECK(completed); |
| 151 base::RunLoop run_loop; | 151 base::RunLoop run_loop; |
| 152 runner->ReadDirectory( | 152 runner->ReadDirectory( |
| 153 url, base::Bind(&ReadDirectoryTestHelperCallback, &run_loop, contents, | 153 url, base::Bind(&ReadDirectoryTestHelperCallback, &run_loop, contents, |
| 154 completed)); | 154 completed)); |
| 155 run_loop.Run(); | 155 run_loop.Run(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 void SynchronouslyRunOnMediaTaskRunner(const base::Closure& closure) { | 158 void SynchronouslyRunOnMediaTaskRunner(const base::Closure& closure) { |
| 159 base::RunLoop loop; | 159 base::RunLoop loop; |
| 160 MediaFileSystemBackend::MediaTaskRunner()->PostTaskAndReply( | 160 MediaFileSystemBackend::MediaTaskRunner()->PostTaskAndReply( |
| 161 FROM_HERE, | 161 FROM_HERE, |
| 162 closure, | 162 closure, |
| 163 loop.QuitClosure()); | 163 loop.QuitClosure()); |
| 164 loop.Run(); | 164 loop.Run(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void CreateSnapshotFileTestHelperCallback( | 167 void CreateSnapshotFileTestHelperCallback( |
| 168 base::RunLoop* run_loop, | 168 base::RunLoop* run_loop, |
| 169 base::File::Error* error, | 169 base::File::Error* error, |
| 170 base::FilePath* platform_path_result, | 170 base::FilePath* platform_path_result, |
| 171 base::File::Error result, | 171 base::File::Error result, |
| 172 const base::File::Info& file_info, | 172 const base::File::Info& file_info, |
| 173 const base::FilePath& platform_path, | 173 const base::FilePath& platform_path, |
| 174 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 174 const scoped_refptr<storage::ShareableFileReference>& file_ref) { |
| 175 DCHECK(run_loop); | 175 DCHECK(run_loop); |
| 176 DCHECK(error); | 176 DCHECK(error); |
| 177 DCHECK(platform_path_result); | 177 DCHECK(platform_path_result); |
| 178 | 178 |
| 179 *error = result; | 179 *error = result; |
| 180 *platform_path_result = platform_path; | 180 *platform_path_result = platform_path; |
| 181 run_loop->Quit(); | 181 run_loop->Quit(); |
| 182 } | 182 } |
| 183 | 183 |
| 184 } // namespace | 184 } // namespace |
| (...skipping 15 matching lines...) Expand all Loading... |
| 200 }; | 200 }; |
| 201 | 201 |
| 202 class TestMediaFileSystemBackend : public MediaFileSystemBackend { | 202 class TestMediaFileSystemBackend : public MediaFileSystemBackend { |
| 203 public: | 203 public: |
| 204 TestMediaFileSystemBackend(const base::FilePath& profile_path, | 204 TestMediaFileSystemBackend(const base::FilePath& profile_path, |
| 205 PicasaFileUtil* picasa_file_util) | 205 PicasaFileUtil* picasa_file_util) |
| 206 : MediaFileSystemBackend(profile_path, | 206 : MediaFileSystemBackend(profile_path, |
| 207 MediaFileSystemBackend::MediaTaskRunner().get()), | 207 MediaFileSystemBackend::MediaTaskRunner().get()), |
| 208 test_file_util_(picasa_file_util) {} | 208 test_file_util_(picasa_file_util) {} |
| 209 | 209 |
| 210 virtual fileapi::AsyncFileUtil* | 210 virtual storage::AsyncFileUtil* GetAsyncFileUtil( |
| 211 GetAsyncFileUtil(fileapi::FileSystemType type) OVERRIDE { | 211 storage::FileSystemType type) OVERRIDE { |
| 212 if (type != fileapi::kFileSystemTypePicasa) | 212 if (type != storage::kFileSystemTypePicasa) |
| 213 return NULL; | 213 return NULL; |
| 214 | 214 |
| 215 return test_file_util_.get(); | 215 return test_file_util_.get(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 private: | 218 private: |
| 219 scoped_ptr<fileapi::AsyncFileUtil> test_file_util_; | 219 scoped_ptr<storage::AsyncFileUtil> test_file_util_; |
| 220 }; | 220 }; |
| 221 | 221 |
| 222 class PicasaFileUtilTest : public testing::Test { | 222 class PicasaFileUtilTest : public testing::Test { |
| 223 public: | 223 public: |
| 224 PicasaFileUtilTest() | 224 PicasaFileUtilTest() |
| 225 : io_thread_(content::BrowserThread::IO, &message_loop_) { | 225 : io_thread_(content::BrowserThread::IO, &message_loop_) { |
| 226 } | 226 } |
| 227 virtual ~PicasaFileUtilTest() {} | 227 virtual ~PicasaFileUtilTest() {} |
| 228 | 228 |
| 229 virtual void SetUp() OVERRIDE { | 229 virtual void SetUp() OVERRIDE { |
| 230 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); | 230 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); |
| 231 ImportedMediaGalleryRegistry::GetInstance()->Initialize(); | 231 ImportedMediaGalleryRegistry::GetInstance()->Initialize(); |
| 232 | 232 |
| 233 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = | 233 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = |
| 234 new content::MockSpecialStoragePolicy(); | 234 new content::MockSpecialStoragePolicy(); |
| 235 | 235 |
| 236 SynchronouslyRunOnMediaTaskRunner(base::Bind( | 236 SynchronouslyRunOnMediaTaskRunner(base::Bind( |
| 237 &PicasaFileUtilTest::SetUpOnMediaTaskRunner, base::Unretained(this))); | 237 &PicasaFileUtilTest::SetUpOnMediaTaskRunner, base::Unretained(this))); |
| 238 | 238 |
| 239 media_path_filter_.reset(new MediaPathFilter()); | 239 media_path_filter_.reset(new MediaPathFilter()); |
| 240 | 240 |
| 241 ScopedVector<fileapi::FileSystemBackend> additional_providers; | 241 ScopedVector<storage::FileSystemBackend> additional_providers; |
| 242 additional_providers.push_back(new TestMediaFileSystemBackend( | 242 additional_providers.push_back(new TestMediaFileSystemBackend( |
| 243 profile_dir_.path(), | 243 profile_dir_.path(), |
| 244 new TestPicasaFileUtil(media_path_filter_.get(), | 244 new TestPicasaFileUtil(media_path_filter_.get(), |
| 245 picasa_data_provider_.get()))); | 245 picasa_data_provider_.get()))); |
| 246 | 246 |
| 247 file_system_context_ = new fileapi::FileSystemContext( | 247 file_system_context_ = new storage::FileSystemContext( |
| 248 base::MessageLoopProxy::current().get(), | 248 base::MessageLoopProxy::current().get(), |
| 249 base::MessageLoopProxy::current().get(), | 249 base::MessageLoopProxy::current().get(), |
| 250 fileapi::ExternalMountPoints::CreateRefCounted().get(), | 250 storage::ExternalMountPoints::CreateRefCounted().get(), |
| 251 storage_policy.get(), | 251 storage_policy.get(), |
| 252 NULL, | 252 NULL, |
| 253 additional_providers.Pass(), | 253 additional_providers.Pass(), |
| 254 std::vector<fileapi::URLRequestAutoMountHandler>(), | 254 std::vector<storage::URLRequestAutoMountHandler>(), |
| 255 profile_dir_.path(), | 255 profile_dir_.path(), |
| 256 content::CreateAllowFileAccessOptions()); | 256 content::CreateAllowFileAccessOptions()); |
| 257 } | 257 } |
| 258 | 258 |
| 259 virtual void TearDown() OVERRIDE { | 259 virtual void TearDown() OVERRIDE { |
| 260 SynchronouslyRunOnMediaTaskRunner( | 260 SynchronouslyRunOnMediaTaskRunner( |
| 261 base::Bind(&PicasaFileUtilTest::TearDownOnMediaTaskRunner, | 261 base::Bind(&PicasaFileUtilTest::TearDownOnMediaTaskRunner, |
| 262 base::Unretained(this))); | 262 base::Unretained(this))); |
| 263 } | 263 } |
| 264 | 264 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 ASSERT_TRUE(completed); | 356 ASSERT_TRUE(completed); |
| 357 EXPECT_EQ(0u, contents.size()); | 357 EXPECT_EQ(0u, contents.size()); |
| 358 } | 358 } |
| 359 | 359 |
| 360 FileSystemURL CreateURL(const std::string& path) const { | 360 FileSystemURL CreateURL(const std::string& path) const { |
| 361 base::FilePath virtual_path = | 361 base::FilePath virtual_path = |
| 362 ImportedMediaGalleryRegistry::GetInstance()->ImportedRoot(); | 362 ImportedMediaGalleryRegistry::GetInstance()->ImportedRoot(); |
| 363 virtual_path = virtual_path.AppendASCII("picasa"); | 363 virtual_path = virtual_path.AppendASCII("picasa"); |
| 364 virtual_path = virtual_path.AppendASCII(path); | 364 virtual_path = virtual_path.AppendASCII(path); |
| 365 return file_system_context_->CreateCrackedFileSystemURL( | 365 return file_system_context_->CreateCrackedFileSystemURL( |
| 366 GURL("http://www.example.com"), fileapi::kFileSystemTypePicasa, | 366 GURL("http://www.example.com"), |
| 367 storage::kFileSystemTypePicasa, |
| 367 virtual_path); | 368 virtual_path); |
| 368 } | 369 } |
| 369 | 370 |
| 370 fileapi::FileSystemOperationRunner* operation_runner() const { | 371 storage::FileSystemOperationRunner* operation_runner() const { |
| 371 return file_system_context_->operation_runner(); | 372 return file_system_context_->operation_runner(); |
| 372 } | 373 } |
| 373 | 374 |
| 374 scoped_refptr<fileapi::FileSystemContext> file_system_context() const { | 375 scoped_refptr<storage::FileSystemContext> file_system_context() const { |
| 375 return file_system_context_; | 376 return file_system_context_; |
| 376 } | 377 } |
| 377 | 378 |
| 378 private: | 379 private: |
| 379 base::MessageLoop message_loop_; | 380 base::MessageLoop message_loop_; |
| 380 content::TestBrowserThread io_thread_; | 381 content::TestBrowserThread io_thread_; |
| 381 | 382 |
| 382 base::ScopedTempDir profile_dir_; | 383 base::ScopedTempDir profile_dir_; |
| 383 | 384 |
| 384 scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 385 scoped_refptr<storage::FileSystemContext> file_system_context_; |
| 385 scoped_ptr<PicasaDataProvider> picasa_data_provider_; | 386 scoped_ptr<PicasaDataProvider> picasa_data_provider_; |
| 386 scoped_ptr<MediaPathFilter> media_path_filter_; | 387 scoped_ptr<MediaPathFilter> media_path_filter_; |
| 387 | 388 |
| 388 DISALLOW_COPY_AND_ASSIGN(PicasaFileUtilTest); | 389 DISALLOW_COPY_AND_ASSIGN(PicasaFileUtilTest); |
| 389 }; | 390 }; |
| 390 | 391 |
| 391 TEST_F(PicasaFileUtilTest, DateFormat) { | 392 TEST_F(PicasaFileUtilTest, DateFormat) { |
| 392 base::Time::Exploded exploded_shortmonth = { 2013, 4, 0, 16, 0, 0, 0, 0 }; | 393 base::Time::Exploded exploded_shortmonth = { 2013, 4, 0, 16, 0, 0, 0, 0 }; |
| 393 base::Time shortmonth = base::Time::FromLocalExploded(exploded_shortmonth); | 394 base::Time shortmonth = base::Time::FromLocalExploded(exploded_shortmonth); |
| 394 | 395 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 ASSERT_TRUE(completed); | 577 ASSERT_TRUE(completed); |
| 577 EXPECT_EQ(1u, contents.size()); | 578 EXPECT_EQ(1u, contents.size()); |
| 578 EXPECT_EQ("mapped_name.jpg", | 579 EXPECT_EQ("mapped_name.jpg", |
| 579 base::FilePath(contents.begin()->name).AsUTF8Unsafe()); | 580 base::FilePath(contents.begin()->name).AsUTF8Unsafe()); |
| 580 EXPECT_FALSE(contents.begin()->is_directory); | 581 EXPECT_FALSE(contents.begin()->is_directory); |
| 581 | 582 |
| 582 // Create a snapshot file to verify the file path. | 583 // Create a snapshot file to verify the file path. |
| 583 base::RunLoop loop; | 584 base::RunLoop loop; |
| 584 base::File::Error error; | 585 base::File::Error error; |
| 585 base::FilePath platform_path_result; | 586 base::FilePath platform_path_result; |
| 586 fileapi::FileSystemOperationRunner::SnapshotFileCallback snapshot_callback = | 587 storage::FileSystemOperationRunner::SnapshotFileCallback snapshot_callback = |
| 587 base::Bind(&CreateSnapshotFileTestHelperCallback, | 588 base::Bind(&CreateSnapshotFileTestHelperCallback, |
| 588 &loop, | 589 &loop, |
| 589 &error, | 590 &error, |
| 590 &platform_path_result); | 591 &platform_path_result); |
| 591 operation_runner()->CreateSnapshotFile( | 592 operation_runner()->CreateSnapshotFile( |
| 592 CreateURL(std::string(kPicasaDirAlbums) + | 593 CreateURL(std::string(kPicasaDirAlbums) + |
| 593 "/albumname 2013-04-16/mapped_name.jpg"), | 594 "/albumname 2013-04-16/mapped_name.jpg"), |
| 594 snapshot_callback); | 595 snapshot_callback); |
| 595 loop.Run(); | 596 loop.Run(); |
| 596 EXPECT_EQ(base::File::FILE_OK, error); | 597 EXPECT_EQ(base::File::FILE_OK, error); |
| 597 EXPECT_EQ(image_path, platform_path_result); | 598 EXPECT_EQ(image_path, platform_path_result); |
| 598 } | 599 } |
| 599 | 600 |
| 600 } // namespace picasa | 601 } // namespace picasa |
| OLD | NEW |