| OLD | NEW |
| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/numerics/safe_conversions.h" | 12 #include "base/numerics/safe_conversions.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/test/test_timeouts.h" | 16 #include "base/test/test_timeouts.h" |
| 17 #include "base/threading/thread_restrictions.h" |
| 17 #include "base/values.h" | 18 #include "base/values.h" |
| 18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 19 #include "chrome/browser/apps/app_browsertest_util.h" | 20 #include "chrome/browser/apps/app_browsertest_util.h" |
| 20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h" | 22 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h" |
| 22 #include "chrome/browser/media_galleries/media_file_system_registry.h" | 23 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
| 23 #include "chrome/browser/media_galleries/media_galleries_preferences.h" | 24 #include "chrome/browser/media_galleries/media_galleries_preferences.h" |
| 24 #include "chrome/browser/media_galleries/media_galleries_test_util.h" | 25 #include "chrome/browser/media_galleries/media_galleries_test_util.h" |
| 25 #include "chrome/browser/ui/extensions/app_launch_params.h" | 26 #include "chrome/browser/ui/extensions/app_launch_params.h" |
| 26 #include "chrome/browser/ui/extensions/application_launch.h" | 27 #include "chrome/browser/ui/extensions/application_launch.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 106 |
| 106 bool RunMediaGalleriesTestWithArg(const std::string& extension_name, | 107 bool RunMediaGalleriesTestWithArg(const std::string& extension_name, |
| 107 const base::ListValue& custom_arg_value) { | 108 const base::ListValue& custom_arg_value) { |
| 108 // Copy the test data for this test into a temporary directory. Then add | 109 // Copy the test data for this test into a temporary directory. Then add |
| 109 // a common_injected.js to the temporary copy and run it. | 110 // a common_injected.js to the temporary copy and run it. |
| 110 const char kTestDir[] = "api_test/media_galleries/"; | 111 const char kTestDir[] = "api_test/media_galleries/"; |
| 111 base::FilePath from_dir = | 112 base::FilePath from_dir = |
| 112 test_data_dir_.AppendASCII(kTestDir + extension_name); | 113 test_data_dir_.AppendASCII(kTestDir + extension_name); |
| 113 from_dir = from_dir.NormalizePathSeparators(); | 114 from_dir = from_dir.NormalizePathSeparators(); |
| 114 | 115 |
| 116 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 115 base::ScopedTempDir temp_dir; | 117 base::ScopedTempDir temp_dir; |
| 116 if (!temp_dir.CreateUniqueTempDir()) | 118 if (!temp_dir.CreateUniqueTempDir()) |
| 117 return false; | 119 return false; |
| 118 | 120 |
| 119 if (!base::CopyDirectory(from_dir, temp_dir.GetPath(), true)) | 121 if (!base::CopyDirectory(from_dir, temp_dir.GetPath(), true)) |
| 120 return false; | 122 return false; |
| 121 | 123 |
| 122 base::FilePath common_js_path( | 124 base::FilePath common_js_path( |
| 123 GetCommonDataDir().AppendASCII("common_injected.js")); | 125 GetCommonDataDir().AppendASCII("common_injected.js")); |
| 124 base::FilePath inject_js_path(temp_dir.GetPath() | 126 base::FilePath inject_js_path(temp_dir.GetPath() |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); | 167 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); |
| 166 it != galleries.end(); ++it) { | 168 it != galleries.end(); ++it) { |
| 167 preferences->ForgetGalleryById(it->first); | 169 preferences->ForgetGalleryById(it->first); |
| 168 } | 170 } |
| 169 } | 171 } |
| 170 | 172 |
| 171 // This function makes a single fake gallery. This is needed to test platforms | 173 // This function makes a single fake gallery. This is needed to test platforms |
| 172 // with no default media galleries, such as CHROMEOS. This fake gallery is | 174 // with no default media galleries, such as CHROMEOS. This fake gallery is |
| 173 // pre-populated with a test.jpg and test.txt. | 175 // pre-populated with a test.jpg and test.txt. |
| 174 void MakeSingleFakeGallery(MediaGalleryPrefId* pref_id) { | 176 void MakeSingleFakeGallery(MediaGalleryPrefId* pref_id) { |
| 177 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 175 ASSERT_FALSE(fake_gallery_temp_dir_.IsValid()); | 178 ASSERT_FALSE(fake_gallery_temp_dir_.IsValid()); |
| 176 ASSERT_TRUE(fake_gallery_temp_dir_.CreateUniqueTempDir()); | 179 ASSERT_TRUE(fake_gallery_temp_dir_.CreateUniqueTempDir()); |
| 177 | 180 |
| 178 MediaGalleriesPreferences* preferences = GetAndInitializePreferences(); | 181 MediaGalleriesPreferences* preferences = GetAndInitializePreferences(); |
| 179 | 182 |
| 180 MediaGalleryPrefInfo gallery_info; | 183 MediaGalleryPrefInfo gallery_info; |
| 181 ASSERT_FALSE(preferences->LookUpGalleryByPath( | 184 ASSERT_FALSE(preferences->LookUpGalleryByPath( |
| 182 fake_gallery_temp_dir_.GetPath(), &gallery_info)); | 185 fake_gallery_temp_dir_.GetPath(), &gallery_info)); |
| 183 MediaGalleryPrefId id = preferences->AddGallery( | 186 MediaGalleryPrefId id = preferences->AddGallery( |
| 184 gallery_info.device_id, | 187 gallery_info.device_id, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 196 content::RunAllPendingInMessageLoop(); | 199 content::RunAllPendingInMessageLoop(); |
| 197 | 200 |
| 198 // Valid file, should show up in JS as a FileEntry. | 201 // Valid file, should show up in JS as a FileEntry. |
| 199 AddFileToSingleFakeGallery(GetCommonDataDir().AppendASCII("test.jpg")); | 202 AddFileToSingleFakeGallery(GetCommonDataDir().AppendASCII("test.jpg")); |
| 200 | 203 |
| 201 // Invalid file, should not show up as a FileEntry in JS at all. | 204 // Invalid file, should not show up as a FileEntry in JS at all. |
| 202 AddFileToSingleFakeGallery(GetCommonDataDir().AppendASCII("test.txt")); | 205 AddFileToSingleFakeGallery(GetCommonDataDir().AppendASCII("test.txt")); |
| 203 } | 206 } |
| 204 | 207 |
| 205 void AddFileToSingleFakeGallery(const base::FilePath& source_path) { | 208 void AddFileToSingleFakeGallery(const base::FilePath& source_path) { |
| 209 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 206 ASSERT_TRUE(fake_gallery_temp_dir_.IsValid()); | 210 ASSERT_TRUE(fake_gallery_temp_dir_.IsValid()); |
| 207 | 211 |
| 208 ASSERT_TRUE(base::CopyFile( | 212 ASSERT_TRUE(base::CopyFile( |
| 209 source_path, | 213 source_path, |
| 210 fake_gallery_temp_dir_.GetPath().Append(source_path.BaseName()))); | 214 fake_gallery_temp_dir_.GetPath().Append(source_path.BaseName()))); |
| 211 } | 215 } |
| 212 | 216 |
| 213 #if defined(OS_WIN) || defined(OS_MACOSX) | 217 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 214 void PopulatePicasaTestData(const base::FilePath& picasa_app_data_root) { | 218 void PopulatePicasaTestData(const base::FilePath& picasa_app_data_root) { |
| 219 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 215 base::FilePath picasa_database_path = | 220 base::FilePath picasa_database_path = |
| 216 picasa::MakePicasaDatabasePath(picasa_app_data_root); | 221 picasa::MakePicasaDatabasePath(picasa_app_data_root); |
| 217 base::FilePath picasa_temp_dir_path = | 222 base::FilePath picasa_temp_dir_path = |
| 218 picasa_database_path.DirName().AppendASCII(picasa::kPicasaTempDirName); | 223 picasa_database_path.DirName().AppendASCII(picasa::kPicasaTempDirName); |
| 219 ASSERT_TRUE(base::CreateDirectory(picasa_database_path)); | 224 ASSERT_TRUE(base::CreateDirectory(picasa_database_path)); |
| 220 ASSERT_TRUE(base::CreateDirectory(picasa_temp_dir_path)); | 225 ASSERT_TRUE(base::CreateDirectory(picasa_temp_dir_path)); |
| 221 | 226 |
| 222 // Create fake folder directories. | 227 // Create fake folder directories. |
| 223 base::FilePath folders_root = | 228 base::FilePath folders_root = |
| 224 ensure_media_directories_exists_->GetFakePicasaFoldersRootPath(); | 229 ensure_media_directories_exists_->GetFakePicasaFoldersRootPath(); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 ensure_media_directories_exists()->GetFakeAppDataPath()); | 429 ensure_media_directories_exists()->GetFakeAppDataPath()); |
| 425 #endif | 430 #endif |
| 426 | 431 |
| 427 base::ListValue custom_args; | 432 base::ListValue custom_args; |
| 428 custom_args.AppendInteger(test_jpg_size()); | 433 custom_args.AppendInteger(test_jpg_size()); |
| 429 ASSERT_TRUE(RunMediaGalleriesTestWithArg("picasa", custom_args)) << message_; | 434 ASSERT_TRUE(RunMediaGalleriesTestWithArg("picasa", custom_args)) << message_; |
| 430 } | 435 } |
| 431 | 436 |
| 432 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, | 437 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, |
| 433 MAYBE_PicasaCustomLocation) { | 438 MAYBE_PicasaCustomLocation) { |
| 439 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 434 base::ScopedTempDir custom_picasa_app_data_root; | 440 base::ScopedTempDir custom_picasa_app_data_root; |
| 435 ASSERT_TRUE(custom_picasa_app_data_root.CreateUniqueTempDir()); | 441 ASSERT_TRUE(custom_picasa_app_data_root.CreateUniqueTempDir()); |
| 436 ensure_media_directories_exists()->SetCustomPicasaAppDataPath( | 442 ensure_media_directories_exists()->SetCustomPicasaAppDataPath( |
| 437 custom_picasa_app_data_root.GetPath()); | 443 custom_picasa_app_data_root.GetPath()); |
| 438 PopulatePicasaTestData(custom_picasa_app_data_root.GetPath()); | 444 PopulatePicasaTestData(custom_picasa_app_data_root.GetPath()); |
| 439 | 445 |
| 440 base::ListValue custom_args; | 446 base::ListValue custom_args; |
| 441 custom_args.AppendInteger(test_jpg_size()); | 447 custom_args.AppendInteger(test_jpg_size()); |
| 442 ASSERT_TRUE(RunMediaGalleriesTestWithArg("picasa", custom_args)) << message_; | 448 ASSERT_TRUE(RunMediaGalleriesTestWithArg("picasa", custom_args)) << message_; |
| 443 } | 449 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 465 | 471 |
| 466 base::ListValue custom_args; | 472 base::ListValue custom_args; |
| 467 #if BUILDFLAG(USE_PROPRIETARY_CODECS) | 473 #if BUILDFLAG(USE_PROPRIETARY_CODECS) |
| 468 custom_args.AppendBoolean(true); | 474 custom_args.AppendBoolean(true); |
| 469 #else | 475 #else |
| 470 custom_args.AppendBoolean(false); | 476 custom_args.AppendBoolean(false); |
| 471 #endif | 477 #endif |
| 472 ASSERT_TRUE(RunMediaGalleriesTestWithArg("media_metadata", custom_args)) | 478 ASSERT_TRUE(RunMediaGalleriesTestWithArg("media_metadata", custom_args)) |
| 473 << message_; | 479 << message_; |
| 474 } | 480 } |
| OLD | NEW |