Chromium Code Reviews| 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" |
| 11 #include "base/files/file_path.h" | |
| 11 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "base/message_loop/message_loop_proxy.h" | 15 #include "base/message_loop/message_loop_proxy.h" |
| 15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/synchronization/waitable_event.h" | |
| 17 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 18 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | 20 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
| 19 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" | 21 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" |
| 20 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h" | 22 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h" |
| 21 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_file_util.h" | 23 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_file_util.h" |
| 22 #include "chrome/common/media_galleries/picasa_types.h" | 24 #include "chrome/common/media_galleries/picasa_types.h" |
| 23 #include "chrome/common/media_galleries/pmp_constants.h" | 25 #include "chrome/common/media_galleries/pmp_constants.h" |
| 24 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/test/test_browser_thread.h" | 27 #include "content/public/test/test_browser_thread.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 bool* completed) { | 144 bool* completed) { |
| 143 DCHECK(contents); | 145 DCHECK(contents); |
| 144 DCHECK(completed); | 146 DCHECK(completed); |
| 145 base::RunLoop run_loop; | 147 base::RunLoop run_loop; |
| 146 runner->ReadDirectory( | 148 runner->ReadDirectory( |
| 147 url, base::Bind(&ReadDirectoryTestHelperCallback, &run_loop, contents, | 149 url, base::Bind(&ReadDirectoryTestHelperCallback, &run_loop, contents, |
| 148 completed)); | 150 completed)); |
| 149 run_loop.Run(); | 151 run_loop.Run(); |
| 150 } | 152 } |
| 151 | 153 |
| 154 void SynchronouslyRunOnMediaTaskRunner(const base::Closure& closure) { | |
| 155 base::WaitableEvent event(true, false); | |
| 156 chrome::MediaFileSystemBackend::MediaTaskRunner()->PostTask(FROM_HERE, | |
| 157 closure); | |
| 158 chrome::MediaFileSystemBackend::MediaTaskRunner()->PostTask( | |
| 159 FROM_HERE, | |
| 160 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); | |
| 161 event.Wait(); | |
| 162 } | |
| 163 | |
| 152 } // namespace | 164 } // namespace |
| 153 | 165 |
| 154 class TestPicasaDataProvider : public PicasaDataProvider { | |
| 155 public: | |
| 156 TestPicasaDataProvider() | |
| 157 : PicasaDataProvider(base::FilePath(FILE_PATH_LITERAL("Fake"))), | |
| 158 initialized_(false) { | |
| 159 } | |
| 160 | |
| 161 virtual ~TestPicasaDataProvider() {} | |
| 162 | |
| 163 virtual void RefreshData(const base::Closure& ready_callback) OVERRIDE { | |
| 164 DCHECK(initialized_); | |
| 165 ready_callback.Run(); | |
| 166 } | |
| 167 | |
| 168 void Init(const std::vector<AlbumInfo>& albums, | |
| 169 const std::vector<AlbumInfo>& folders) { | |
| 170 UniquifyNames(albums, &album_map_); | |
| 171 UniquifyNames(folders, &folder_map_); | |
| 172 initialized_ = true; | |
| 173 } | |
| 174 | |
| 175 private: | |
| 176 bool initialized_; | |
| 177 }; | |
| 178 | |
| 179 class TestPicasaFileUtil : public PicasaFileUtil { | 166 class TestPicasaFileUtil : public PicasaFileUtil { |
| 180 public: | 167 public: |
| 181 TestPicasaFileUtil(chrome::MediaPathFilter* media_path_filter, | 168 TestPicasaFileUtil(chrome::MediaPathFilter* media_path_filter, |
| 182 PicasaDataProvider* data_provider) | 169 PicasaDataProvider* data_provider) |
| 183 : PicasaFileUtil(media_path_filter), | 170 : PicasaFileUtil(media_path_filter), |
| 184 data_provider_(data_provider) { | 171 data_provider_(data_provider) { |
| 185 } | 172 } |
| 186 virtual ~TestPicasaFileUtil() {} | 173 virtual ~TestPicasaFileUtil() {} |
| 187 private: | 174 private: |
| 188 virtual PicasaDataProvider* GetDataProvider() OVERRIDE { | 175 virtual PicasaDataProvider* GetDataProvider() OVERRIDE { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 : io_thread_(content::BrowserThread::IO, &message_loop_) { | 207 : io_thread_(content::BrowserThread::IO, &message_loop_) { |
| 221 } | 208 } |
| 222 virtual ~PicasaFileUtilTest() {} | 209 virtual ~PicasaFileUtilTest() {} |
| 223 | 210 |
| 224 virtual void SetUp() OVERRIDE { | 211 virtual void SetUp() OVERRIDE { |
| 225 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); | 212 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); |
| 226 | 213 |
| 227 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = | 214 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = |
| 228 new quota::MockSpecialStoragePolicy(); | 215 new quota::MockSpecialStoragePolicy(); |
| 229 | 216 |
| 217 SynchronouslyRunOnMediaTaskRunner(base::Bind( | |
| 218 &PicasaFileUtilTest::SetUpOnMediaTaskRunner, base::Unretained(this))); | |
| 219 | |
| 230 media_path_filter_.reset(new chrome::MediaPathFilter()); | 220 media_path_filter_.reset(new chrome::MediaPathFilter()); |
| 231 picasa_data_provider_.reset(new TestPicasaDataProvider()); | |
| 232 | 221 |
| 233 ScopedVector<fileapi::FileSystemBackend> additional_providers; | 222 ScopedVector<fileapi::FileSystemBackend> additional_providers; |
| 234 additional_providers.push_back(new TestMediaFileSystemBackend( | 223 additional_providers.push_back(new TestMediaFileSystemBackend( |
| 235 profile_dir_.path(), | 224 profile_dir_.path(), |
| 236 new TestPicasaFileUtil(media_path_filter_.get(), | 225 new TestPicasaFileUtil(media_path_filter_.get(), |
| 237 picasa_data_provider_.get()))); | 226 picasa_data_provider_.get()))); |
| 238 | 227 |
| 239 file_system_context_ = new fileapi::FileSystemContext( | 228 file_system_context_ = new fileapi::FileSystemContext( |
| 240 base::MessageLoopProxy::current().get(), | 229 base::MessageLoopProxy::current().get(), |
| 241 base::MessageLoopProxy::current().get(), | 230 base::MessageLoopProxy::current().get(), |
| 242 fileapi::ExternalMountPoints::CreateRefCounted().get(), | 231 fileapi::ExternalMountPoints::CreateRefCounted().get(), |
| 243 storage_policy.get(), | 232 storage_policy.get(), |
| 244 NULL, | 233 NULL, |
| 245 additional_providers.Pass(), | 234 additional_providers.Pass(), |
| 246 profile_dir_.path(), | 235 profile_dir_.path(), |
| 247 fileapi::CreateAllowFileAccessOptions()); | 236 fileapi::CreateAllowFileAccessOptions()); |
| 248 } | 237 } |
| 249 | 238 |
| 239 virtual void TearDown() OVERRIDE { | |
| 240 SynchronouslyRunOnMediaTaskRunner( | |
| 241 base::Bind(&PicasaFileUtilTest::TearDownOnMediaTaskRunner, | |
| 242 base::Unretained(this))); | |
| 243 } | |
| 244 | |
| 250 protected: | 245 protected: |
| 246 void SetUpOnMediaTaskRunner() { | |
| 247 picasa_data_provider_.reset(new PicasaDataProvider(base::FilePath())); | |
| 248 } | |
| 249 | |
| 250 void TearDownOnMediaTaskRunner() { picasa_data_provider_.reset(); } | |
|
vandebo (ex-Chrome)
2013/08/23 16:42:41
I prefer that this be on multiple lines.
tommycli
2013/08/26 22:06:17
Done. This was a git cl format change though.
| |
| 251 | |
| 252 void SetupDataProvider(PicasaDataProvider* picasa_data_provider, | |
| 253 const std::vector<AlbumInfo>& albums, | |
| 254 const std::vector<AlbumInfo>& folders) { | |
| 255 PicasaDataProvider::UniquifyNames(albums, | |
| 256 &picasa_data_provider->album_map_); | |
| 257 PicasaDataProvider::UniquifyNames(folders, | |
| 258 &picasa_data_provider->folder_map_); | |
| 259 picasa_data_provider->state_ = | |
| 260 PicasaDataProvider::ALBUMS_IMAGES_FRESH_STATE; | |
| 261 } | |
| 262 | |
| 251 // |test_folders| must be in alphabetical order for easy verification | 263 // |test_folders| must be in alphabetical order for easy verification |
| 252 void SetupFolders(ScopedVector<TestFolder>* test_folders) { | 264 void SetupFolders(ScopedVector<TestFolder>* test_folders) { |
| 253 std::vector<AlbumInfo> folders; | 265 std::vector<AlbumInfo> folders; |
| 254 for (ScopedVector<TestFolder>::iterator it = test_folders->begin(); | 266 for (ScopedVector<TestFolder>::iterator it = test_folders->begin(); |
| 255 it != test_folders->end(); ++it) { | 267 it != test_folders->end(); ++it) { |
| 256 TestFolder* test_folder = *it; | 268 TestFolder* test_folder = *it; |
| 257 ASSERT_TRUE(test_folder->Init()); | 269 ASSERT_TRUE(test_folder->Init()); |
| 258 folders.push_back(test_folder->folder_info()); | 270 folders.push_back(test_folder->folder_info()); |
| 259 } | 271 } |
| 260 picasa_data_provider_->Init(std::vector<AlbumInfo>(), folders); | 272 |
| 273 SetupDataProvider( | |
| 274 picasa_data_provider_.get(), std::vector<AlbumInfo>(), folders); | |
| 261 } | 275 } |
| 262 | 276 |
| 263 void VerifyFolderDirectoryList(const ScopedVector<TestFolder>& test_folders) { | 277 void VerifyFolderDirectoryList(const ScopedVector<TestFolder>& test_folders) { |
| 264 FileSystemOperation::FileEntryList contents; | 278 FileSystemOperation::FileEntryList contents; |
| 265 FileSystemURL url = CreateURL(kPicasaDirFolders); | 279 FileSystemURL url = CreateURL(kPicasaDirFolders); |
| 266 bool completed = false; | 280 bool completed = false; |
| 267 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); | 281 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); |
| 268 | 282 |
| 269 ASSERT_TRUE(completed); | 283 ASSERT_TRUE(completed); |
| 270 ASSERT_EQ(test_folders.size(), contents.size()); | 284 ASSERT_EQ(test_folders.size(), contents.size()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 return file_system_context_; | 344 return file_system_context_; |
| 331 } | 345 } |
| 332 | 346 |
| 333 private: | 347 private: |
| 334 base::MessageLoop message_loop_; | 348 base::MessageLoop message_loop_; |
| 335 content::TestBrowserThread io_thread_; | 349 content::TestBrowserThread io_thread_; |
| 336 | 350 |
| 337 base::ScopedTempDir profile_dir_; | 351 base::ScopedTempDir profile_dir_; |
| 338 | 352 |
| 339 scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 353 scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
| 354 scoped_ptr<PicasaDataProvider> picasa_data_provider_; | |
| 340 scoped_ptr<chrome::MediaPathFilter> media_path_filter_; | 355 scoped_ptr<chrome::MediaPathFilter> media_path_filter_; |
| 341 scoped_ptr<TestPicasaDataProvider> picasa_data_provider_; | |
| 342 | 356 |
| 343 DISALLOW_COPY_AND_ASSIGN(PicasaFileUtilTest); | 357 DISALLOW_COPY_AND_ASSIGN(PicasaFileUtilTest); |
| 344 }; | 358 }; |
| 345 | 359 |
| 346 TEST_F(PicasaFileUtilTest, DateFormat) { | 360 TEST_F(PicasaFileUtilTest, DateFormat) { |
| 347 base::Time::Exploded exploded_shortmonth = { 2013, 4, 0, 16, 0, 0, 0, 0 }; | 361 base::Time::Exploded exploded_shortmonth = { 2013, 4, 0, 16, 0, 0, 0, 0 }; |
| 348 base::Time shortmonth = base::Time::FromLocalExploded(exploded_shortmonth); | 362 base::Time shortmonth = base::Time::FromLocalExploded(exploded_shortmonth); |
| 349 | 363 |
| 350 base::Time::Exploded exploded_shortday = { 2013, 11, 0, 3, 0, 0, 0, 0 }; | 364 base::Time::Exploded exploded_shortday = { 2013, 11, 0, 3, 0, 0, 0, 0 }; |
| 351 base::Time shortday = base::Time::FromLocalExploded(exploded_shortday); | 365 base::Time shortday = base::Time::FromLocalExploded(exploded_shortday); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 new TestFolder(base::StringPrintf("folder-%05d", i), | 487 new TestFolder(base::StringPrintf("folder-%05d", i), |
| 474 date, | 488 date, |
| 475 base::StringPrintf("uid%05d", i), i % 5, i % 3)); | 489 base::StringPrintf("uid%05d", i), i % 5, i % 3)); |
| 476 } | 490 } |
| 477 | 491 |
| 478 SetupFolders(&test_folders); | 492 SetupFolders(&test_folders); |
| 479 VerifyFolderDirectoryList(test_folders); | 493 VerifyFolderDirectoryList(test_folders); |
| 480 } | 494 } |
| 481 | 495 |
| 482 } // namespace picasa | 496 } // namespace picasa |
| OLD | NEW |