Chromium Code Reviews| 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 "base/auto_reset.h" | 5 #include "base/auto_reset.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/mac/scoped_cftyperef.h" | |
|
vandebo (ex-Chrome)
2014/01/06 18:45:03
Should all/most of the new includes be in a MAC_OS
Greg Billock
2014/01/07 16:50:55
Yeah, the trybots squealed about this.
| |
| 9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 10 #include "base/safe_numerics.h" | 11 #include "base/safe_numerics.h" |
| 12 #include "base/strings/string_util.h" | |
| 13 #include "base/strings/sys_string_conversions.h" | |
| 11 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/values.h" | 15 #include "base/values.h" |
| 13 #include "chrome/browser/apps/app_browsertest_util.h" | 16 #include "chrome/browser/apps/app_browsertest_util.h" |
| 14 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
| 19 #include "chrome/browser/media_galleries/fileapi/iapps_finder_impl.h" | |
| 16 #include "chrome/browser/media_galleries/media_file_system_registry.h" | 20 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
| 17 #include "chrome/browser/media_galleries/media_galleries_preferences.h" | 21 #include "chrome/browser/media_galleries/media_galleries_preferences.h" |
| 18 #include "chrome/browser/media_galleries/media_galleries_test_util.h" | 22 #include "chrome/browser/media_galleries/media_galleries_test_util.h" |
| 19 #include "chrome/browser/storage_monitor/storage_info.h" | 23 #include "chrome/browser/storage_monitor/storage_info.h" |
| 20 #include "chrome/browser/storage_monitor/storage_monitor.h" | 24 #include "chrome/browser/storage_monitor/storage_monitor.h" |
| 21 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
| 26 #include "components/policy/core/common/preferences_mock_mac.h" | |
| 22 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
| 23 | 28 |
| 24 #if defined(OS_WIN) || defined(OS_MACOSX) | 29 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 25 #include "chrome/browser/media_galleries/fileapi/picasa_finder.h" | 30 #include "chrome/browser/media_galleries/fileapi/picasa_finder.h" |
| 26 #include "chrome/common/media_galleries/picasa_test_util.h" | 31 #include "chrome/common/media_galleries/picasa_test_util.h" |
| 27 #include "chrome/common/media_galleries/picasa_types.h" | 32 #include "chrome/common/media_galleries/picasa_types.h" |
| 28 #include "chrome/common/media_galleries/pmp_test_util.h" | 33 #include "chrome/common/media_galleries/pmp_test_util.h" |
| 29 #endif | 34 #endif |
| 30 | 35 |
| 36 #if defined(OS_MACOSX) | |
| 37 #include "base/mac/foundation_util.h" | |
| 38 #include "base/strings/sys_string_conversions.h" | |
| 39 #endif // OS_MACOSX | |
| 40 | |
| 31 using extensions::PlatformAppBrowserTest; | 41 using extensions::PlatformAppBrowserTest; |
| 32 | 42 |
| 33 namespace { | 43 namespace { |
| 34 | 44 |
| 35 // Dummy device properties. | 45 // Dummy device properties. |
| 36 const char kDeviceId[] = "testDeviceId"; | 46 const char kDeviceId[] = "testDeviceId"; |
| 37 const char kDeviceName[] = "foobar"; | 47 const char kDeviceName[] = "foobar"; |
| 38 #if defined(FILE_PATH_USES_DRIVE_LETTERS) | 48 #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
| 39 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("C:\\qux"); | 49 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("C:\\qux"); |
| 40 #else | 50 #else |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 return false; | 103 return false; |
| 94 | 104 |
| 95 const char* custom_arg = NULL; | 105 const char* custom_arg = NULL; |
| 96 std::string json_string; | 106 std::string json_string; |
| 97 if (!custom_arg_value.empty()) { | 107 if (!custom_arg_value.empty()) { |
| 98 base::JSONWriter::Write(&custom_arg_value, &json_string); | 108 base::JSONWriter::Write(&custom_arg_value, &json_string); |
| 99 custom_arg = json_string.c_str(); | 109 custom_arg = json_string.c_str(); |
| 100 } | 110 } |
| 101 | 111 |
| 102 base::AutoReset<base::FilePath> reset(&test_data_dir_, temp_dir.path()); | 112 base::AutoReset<base::FilePath> reset(&test_data_dir_, temp_dir.path()); |
| 103 return RunPlatformAppTestWithArg(extension_name, custom_arg); | 113 bool result = RunPlatformAppTestWithArg(extension_name, custom_arg); |
| 114 content::RunAllPendingInMessageLoop(); // avoid race on exit in registry. | |
| 115 return result; | |
| 104 } | 116 } |
| 105 | 117 |
| 106 void AttachFakeDevice() { | 118 void AttachFakeDevice() { |
| 107 device_id_ = StorageInfo::MakeDeviceId( | 119 device_id_ = StorageInfo::MakeDeviceId( |
| 108 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId); | 120 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId); |
| 109 | 121 |
| 110 StorageMonitor::GetInstance()->receiver()->ProcessAttach( | 122 StorageMonitor::GetInstance()->receiver()->ProcessAttach( |
| 111 StorageInfo(device_id_, base::string16(), kDevicePath, | 123 StorageInfo(device_id_, base::string16(), kDevicePath, |
| 112 base::ASCIIToUTF16(kDeviceName), base::string16(), | 124 base::ASCIIToUTF16(kDeviceName), base::string16(), |
| 113 base::string16(), 0)); | 125 base::string16(), 0)); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 picasa::WriteTestAlbumsImagesIndex(fake_folder_1, fake_folder_2); | 201 picasa::WriteTestAlbumsImagesIndex(fake_folder_1, fake_folder_2); |
| 190 | 202 |
| 191 base::FilePath test_jpg_path = GetCommonDataDir().AppendASCII("test.jpg"); | 203 base::FilePath test_jpg_path = GetCommonDataDir().AppendASCII("test.jpg"); |
| 192 ASSERT_TRUE(base::CopyFile( | 204 ASSERT_TRUE(base::CopyFile( |
| 193 test_jpg_path, fake_folder_1.AppendASCII("InBoth.jpg"))); | 205 test_jpg_path, fake_folder_1.AppendASCII("InBoth.jpg"))); |
| 194 ASSERT_TRUE(base::CopyFile( | 206 ASSERT_TRUE(base::CopyFile( |
| 195 test_jpg_path, fake_folder_1.AppendASCII("InSecondAlbumOnly.jpg"))); | 207 test_jpg_path, fake_folder_1.AppendASCII("InSecondAlbumOnly.jpg"))); |
| 196 ASSERT_TRUE(base::CopyFile( | 208 ASSERT_TRUE(base::CopyFile( |
| 197 test_jpg_path, fake_folder_2.AppendASCII("InFirstAlbumOnly.jpg"))); | 209 test_jpg_path, fake_folder_2.AppendASCII("InFirstAlbumOnly.jpg"))); |
| 198 } | 210 } |
| 199 #endif | 211 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| 212 | |
| 213 #if defined(OS_MACOSX) | |
| 214 void PopulateIPhotoTestData(const base::FilePath& iphoto_data_root) { | |
| 215 std::string xml_contents = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | |
| 216 "<plist version=\"1.0\">" | |
| 217 "<dict>\n" | |
| 218 | |
| 219 " <key>List of Albums</key>" | |
| 220 " <array>\n" | |
| 221 | |
| 222 " <dict>\n" | |
| 223 " <key>AlbumId</key>" | |
| 224 " <integer>1</integer>" | |
| 225 " <key>AlbumName</key>" | |
| 226 " <string>Album1</string>" | |
| 227 " <key>KeyList</key>\n" | |
| 228 " <array>" | |
| 229 " <string>1</string>" | |
| 230 " <string>2</string>" | |
| 231 " </array>\n" | |
| 232 " </dict>\n" | |
| 233 | |
| 234 " <dict>\n" | |
| 235 " <key>AlbumId</key>" | |
| 236 " <integer>2</integer>" | |
| 237 " <key>AlbumName</key>" | |
| 238 " <string>Album2</string>" | |
| 239 " <key>KeyList</key>\n" | |
| 240 " <array>" | |
| 241 " <string>2</string>" | |
| 242 " </array>\n" | |
| 243 " </dict>\n" | |
| 244 | |
| 245 " </array>\n" | |
| 246 | |
| 247 " <key>Master Image List</key>\n" | |
| 248 " <dict>\n" | |
| 249 | |
| 250 " <key>1</key>" | |
| 251 " <dict>\n" | |
| 252 " <key>MediaType</key>" | |
| 253 " <string>Image</string>" | |
| 254 " <key>Caption</key>" | |
| 255 " <string>caption 1</string>" | |
| 256 " <key>GUID</key>" | |
| 257 " <string>1</string>" | |
| 258 " <key>ModDateAsTimerInterval</key>" | |
| 259 " <string>386221543.0000</string>" | |
| 260 " <key>DateAsTimerInterval</key>" | |
| 261 " <string>386221543.0000</string>" | |
| 262 " <key>DateAsTimerIntervalGMT</key>" | |
| 263 " <string>385123456.00</string>" | |
| 264 " <key>ImagePath</key>" | |
| 265 " <string>$path1</string>" | |
| 266 " <key>ThumbPath</key>" | |
| 267 " <string>/thumb/path</string>\n" | |
| 268 " </dict>\n" | |
| 269 | |
| 270 " <key>2</key>\n" | |
| 271 " <dict>\n" | |
| 272 " <key>MediaType</key>" | |
| 273 " <string>Image</string>" | |
| 274 " <key>Caption</key>" | |
| 275 " <string>caption 2</string>" | |
| 276 " <key>GUID</key>" | |
| 277 " <string>2</string>" | |
| 278 " <key>ModDateAsTimerInterval</key>" | |
| 279 " <string>386221543.0000</string>" | |
| 280 " <key>DateAsTimerInterval</key>" | |
| 281 " <string>386221543.0000</string>" | |
| 282 " <key>DateAsTimerIntervalGMT</key>" | |
| 283 " <string>385123456.00</string>" | |
| 284 " <key>ImagePath</key>" | |
| 285 " <string>$path2</string>" | |
| 286 " <key>ThumbPath</key>" | |
| 287 " <string>/thumb/path2</string>\n" | |
| 288 " </dict>\n" | |
| 289 | |
| 290 " </dict>\n" // Master Image List | |
| 291 | |
| 292 "</dict>\n" | |
| 293 "</plist>"; | |
| 294 | |
| 295 base::FilePath test_jpg_path = GetCommonDataDir().AppendASCII("test.jpg"); | |
| 296 ASSERT_TRUE(base::CreateDirectory(iphoto_data_root)); | |
| 297 base::FilePath first_only_jpg = | |
| 298 iphoto_data_root.AppendASCII("InFirstAlbumOnly.jpg"); | |
| 299 base::FilePath in_both_jpg = iphoto_data_root.AppendASCII("InBoth.jpg"); | |
| 300 ASSERT_TRUE(base::CopyFile(test_jpg_path, first_only_jpg)); | |
| 301 ASSERT_TRUE(base::CopyFile(test_jpg_path, in_both_jpg)); | |
| 302 ReplaceFirstSubstringAfterOffset( | |
| 303 &xml_contents, 0, std::string("$path1"), first_only_jpg.value()); | |
| 304 ReplaceFirstSubstringAfterOffset( | |
| 305 &xml_contents, 0, std::string("$path2"), in_both_jpg.value()); | |
| 306 | |
| 307 base::FilePath album_xml = iphoto_data_root.AppendASCII("AlbumData.xml"); | |
| 308 ASSERT_NE(-1, file_util::WriteFile(album_xml, | |
| 309 xml_contents.c_str(), | |
| 310 xml_contents.size())); | |
| 311 } | |
| 312 #endif // defined(OS_MACOSX) | |
| 200 | 313 |
| 201 base::FilePath GetCommonDataDir() const { | 314 base::FilePath GetCommonDataDir() const { |
| 202 return test_data_dir_.AppendASCII("api_test") | 315 return test_data_dir_.AppendASCII("api_test") |
| 203 .AppendASCII("media_galleries") | 316 .AppendASCII("media_galleries") |
| 204 .AppendASCII("common"); | 317 .AppendASCII("common"); |
| 205 } | 318 } |
| 206 | 319 |
| 207 int num_galleries() const { | 320 int num_galleries() const { |
| 208 return ensure_media_directories_exists_->num_galleries(); | 321 return ensure_media_directories_exists_->num_galleries(); |
| 209 } | 322 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 ASSERT_TRUE(custom_picasa_app_data_root.CreateUniqueTempDir()); | 427 ASSERT_TRUE(custom_picasa_app_data_root.CreateUniqueTempDir()); |
| 315 ensure_media_directories_exists()->SetCustomPicasaAppDataPath( | 428 ensure_media_directories_exists()->SetCustomPicasaAppDataPath( |
| 316 custom_picasa_app_data_root.path()); | 429 custom_picasa_app_data_root.path()); |
| 317 PopulatePicasaTestData(custom_picasa_app_data_root.path()); | 430 PopulatePicasaTestData(custom_picasa_app_data_root.path()); |
| 318 | 431 |
| 319 base::ListValue custom_args; | 432 base::ListValue custom_args; |
| 320 custom_args.AppendInteger(test_jpg_size()); | 433 custom_args.AppendInteger(test_jpg_size()); |
| 321 ASSERT_TRUE(RunMediaGalleriesTestWithArg("picasa", custom_args)) << message_; | 434 ASSERT_TRUE(RunMediaGalleriesTestWithArg("picasa", custom_args)) << message_; |
| 322 } | 435 } |
| 323 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 436 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| 437 | |
| 438 #if defined(OS_MACOSX) | |
| 439 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, | |
| 440 IPhotoTest) { | |
| 441 MockPreferences prefs; | |
| 442 base::FilePath iphoto_xml = | |
| 443 ensure_media_directories_exists()->GetFakeIPhotoRootPath(). | |
| 444 AppendASCII("AlbumData.xml"); | |
| 445 prefs.AddTestItem( | |
| 446 base::mac::NSToCFCast(iapps::kIPhotoRecentDatabasesKey), | |
| 447 base::mac::NSToCFCast(iapps::NSArrayFromFilePath(iphoto_xml)), | |
| 448 false); | |
| 449 iapps::SetMacPreferencesForTesting(&prefs); | |
| 450 | |
| 451 PopulateIPhotoTestData( | |
| 452 ensure_media_directories_exists()->GetFakeIPhotoRootPath()); | |
| 453 | |
| 454 base::ListValue custom_args; | |
| 455 custom_args.AppendInteger(test_jpg_size()); | |
| 456 ASSERT_TRUE(RunMediaGalleriesTestWithArg("iphoto", custom_args)) << message_; | |
| 457 | |
| 458 iapps::SetMacPreferencesForTesting(NULL); | |
| 459 } | |
| 460 #endif // defined(OS_MACOSX) | |
| OLD | NEW |