| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/apps/app_browsertest_util.h" | 11 #include "chrome/browser/apps/app_browsertest_util.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/extensions/extension_apitest.h" | 13 #include "chrome/browser/extensions/extension_apitest.h" |
| 14 #include "chrome/browser/extensions/extension_process_manager.h" | 14 #include "chrome/browser/extensions/extension_process_manager.h" |
| 15 #include "chrome/browser/extensions/extension_system.h" | 15 #include "chrome/browser/extensions/extension_system.h" |
| 16 #include "chrome/browser/media_galleries/media_file_system_registry.h" | 16 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
| 17 #include "chrome/browser/media_galleries/media_galleries_preferences.h" | 17 #include "chrome/browser/media_galleries/media_galleries_preferences.h" |
| 18 #include "chrome/browser/media_galleries/media_galleries_test_util.h" | 18 #include "chrome/browser/media_galleries/media_galleries_test_util.h" |
| 19 #include "chrome/browser/storage_monitor/storage_info.h" | 19 #include "chrome/browser/storage_monitor/storage_info.h" |
| 20 #include "chrome/browser/storage_monitor/storage_monitor.h" | 20 #include "chrome/browser/storage_monitor/storage_monitor.h" |
| 21 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 22 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
| 23 #include "content/public/test/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
| 24 #include "extensions/common/switches.h" | 24 #include "extensions/common/switches.h" |
| 25 | 25 |
| 26 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 27 #include "chrome/browser/media_galleries/fileapi/picasa_finder.h" |
| 28 #include "chrome/common/media_galleries/picasa_test_util.h" |
| 29 #include "chrome/common/media_galleries/picasa_types.h" |
| 30 #include "chrome/common/media_galleries/pmp_test_util.h" |
| 31 #endif |
| 32 |
| 26 using extensions::PlatformAppBrowserTest; | 33 using extensions::PlatformAppBrowserTest; |
| 27 | 34 |
| 28 namespace { | 35 namespace { |
| 29 | 36 |
| 30 // Dummy device properties. | 37 // Dummy device properties. |
| 31 const char kDeviceId[] = "testDeviceId"; | 38 const char kDeviceId[] = "testDeviceId"; |
| 32 const char kDeviceName[] = "foobar"; | 39 const char kDeviceName[] = "foobar"; |
| 33 #if defined(FILE_PATH_USES_DRIVE_LETTERS) | 40 #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
| 34 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("C:\\qux"); | 41 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("C:\\qux"); |
| 35 #else | 42 #else |
| 36 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("/qux"); | 43 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("/qux"); |
| 37 #endif | 44 #endif |
| 38 | 45 |
| 39 const char kTestGalleries[] = "testGalleries(%d)"; | 46 const char kTestGalleries[] = "testGalleries(%d)"; |
| 40 | 47 |
| 41 } // namespace | |
| 42 | |
| 43 // This function is to ensure at least one (fake) media gallery exists for | 48 // This function is to ensure at least one (fake) media gallery exists for |
| 44 // testing platforms with no default media galleries, such as CHROMEOS. | 49 // testing platforms with no default media galleries, such as CHROMEOS. |
| 45 void MakeFakeMediaGalleryForTest(Profile* profile, const base::FilePath& path) { | 50 void MakeFakeMediaGalleryForTest(Profile* profile, const base::FilePath& path) { |
| 46 base::RunLoop runloop; | |
| 47 MediaGalleriesPreferences* preferences = | 51 MediaGalleriesPreferences* preferences = |
| 48 g_browser_process->media_file_system_registry()->GetPreferences(profile); | 52 g_browser_process->media_file_system_registry()->GetPreferences(profile); |
| 53 base::RunLoop runloop; |
| 49 preferences->EnsureInitialized(runloop.QuitClosure()); | 54 preferences->EnsureInitialized(runloop.QuitClosure()); |
| 50 runloop.Run(); | 55 runloop.Run(); |
| 51 | 56 |
| 52 MediaGalleryPrefInfo gallery_info; | 57 MediaGalleryPrefInfo gallery_info; |
| 53 ASSERT_FALSE(preferences->LookUpGalleryByPath(path, &gallery_info)); | 58 ASSERT_FALSE(preferences->LookUpGalleryByPath(path, &gallery_info)); |
| 54 preferences->AddGallery(gallery_info.device_id, | 59 preferences->AddGallery(gallery_info.device_id, |
| 55 gallery_info.path, | 60 gallery_info.path, |
| 56 false /* user_added */, | 61 false /* user_added */, |
| 57 gallery_info.volume_label, | 62 gallery_info.volume_label, |
| 58 gallery_info.vendor_name, | 63 gallery_info.vendor_name, |
| 59 gallery_info.model_name, | 64 gallery_info.model_name, |
| 60 gallery_info.total_size_in_bytes, | 65 gallery_info.total_size_in_bytes, |
| 61 gallery_info.last_attach_time); | 66 gallery_info.last_attach_time); |
| 62 | 67 |
| 63 content::RunAllPendingInMessageLoop(); | 68 content::RunAllPendingInMessageLoop(); |
| 64 } | 69 } |
| 65 | 70 |
| 71 } // namespace |
| 72 |
| 66 class MediaGalleriesPlatformAppBrowserTest : public PlatformAppBrowserTest { | 73 class MediaGalleriesPlatformAppBrowserTest : public PlatformAppBrowserTest { |
| 67 protected: | 74 protected: |
| 68 // Since ExtensionTestMessageListener does not work with RunPlatformAppTest(), | 75 // Since ExtensionTestMessageListener does not work with RunPlatformAppTest(), |
| 69 // This helper method can be used to run additional media gallery tests. | 76 // This helper method can be used to run additional media gallery tests. |
| 70 void RunSecondTestPhase(const string16& command) { | 77 void RunSecondTestPhase(const string16& command) { |
| 71 const extensions::Extension* extension = GetSingleLoadedExtension(); | 78 const extensions::Extension* extension = GetSingleLoadedExtension(); |
| 72 extensions::ExtensionHost* host = | 79 extensions::ExtensionHost* host = |
| 73 extensions::ExtensionSystem::Get(browser()->profile())-> | 80 extensions::ExtensionSystem::Get(browser()->profile())-> |
| 74 process_manager()->GetBackgroundHostForExtension(extension->id()); | 81 process_manager()->GetBackgroundHostForExtension(extension->id()); |
| 75 ASSERT_TRUE(host); | 82 ASSERT_TRUE(host); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 87 StorageInfo(device_id_, string16(), kDevicePath, | 94 StorageInfo(device_id_, string16(), kDevicePath, |
| 88 ASCIIToUTF16(kDeviceName), string16(), string16(), 0)); | 95 ASCIIToUTF16(kDeviceName), string16(), string16(), 0)); |
| 89 content::RunAllPendingInMessageLoop(); | 96 content::RunAllPendingInMessageLoop(); |
| 90 } | 97 } |
| 91 | 98 |
| 92 void DetachFakeDevice() { | 99 void DetachFakeDevice() { |
| 93 StorageMonitor::GetInstance()->receiver()->ProcessDetach(device_id_); | 100 StorageMonitor::GetInstance()->receiver()->ProcessDetach(device_id_); |
| 94 content::RunAllPendingInMessageLoop(); | 101 content::RunAllPendingInMessageLoop(); |
| 95 } | 102 } |
| 96 | 103 |
| 104 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 105 // This initializes the storage monitor, MediaGalleriesPreferences, and |
| 106 // injects a custom Picasa database location. |
| 107 void SetMediaGalleriesPreferencesForPicasaTest( |
| 108 Profile* profile, |
| 109 const base::FilePath& database_path) { |
| 110 MediaGalleriesPreferences* preferences = |
| 111 g_browser_process->media_file_system_registry()->GetPreferences( |
| 112 profile); |
| 113 base::RunLoop runloop; |
| 114 preferences->EnsureInitialized(runloop.QuitClosure()); |
| 115 runloop.Run(); |
| 116 |
| 117 preferences->OnFinderDeviceID(StorageInfo::MakeDeviceId( |
| 118 StorageInfo::PICASA, database_path.AsUTF8Unsafe())); |
| 119 } |
| 120 #endif |
| 121 |
| 97 private: | 122 private: |
| 98 std::string device_id_; | 123 std::string device_id_; |
| 99 }; | 124 }; |
| 100 | 125 |
| 101 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, | 126 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, |
| 102 MediaGalleriesNoAccess) { | 127 MediaGalleriesNoAccess) { |
| 103 EnsureMediaDirectoriesExists media_directories; | 128 EnsureMediaDirectoriesExists media_directories; |
| 104 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/no_access")) | 129 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/no_access")) |
| 105 << message_; | 130 << message_; |
| 106 RunSecondTestPhase(base::UTF8ToUTF16(base::StringPrintf( | 131 RunSecondTestPhase(base::UTF8ToUTF16(base::StringPrintf( |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 190 |
| 166 DetachFakeDevice(); | 191 DetachFakeDevice(); |
| 167 } | 192 } |
| 168 | 193 |
| 169 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, | 194 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, |
| 170 GetFilesystemMetadata) { | 195 GetFilesystemMetadata) { |
| 171 EnsureMediaDirectoriesExists media_directories; | 196 EnsureMediaDirectoriesExists media_directories; |
| 172 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/metadata")) | 197 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/metadata")) |
| 173 << message_; | 198 << message_; |
| 174 } | 199 } |
| 200 |
| 201 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 202 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, Picasa) { |
| 203 EnsureMediaDirectoriesExists media_directories; |
| 204 |
| 205 // Create Picasa metadata database directories. |
| 206 base::ScopedTempDir metadata_root; |
| 207 ASSERT_TRUE(metadata_root.CreateUniqueTempDir()); |
| 208 base::FilePath picasa_database_path = |
| 209 metadata_root.path().AppendASCII(picasa::kPicasaDatabaseDirName); |
| 210 base::FilePath picasa_temp_dir_path = |
| 211 metadata_root.path().AppendASCII(picasa::kPicasaTempDirName); |
| 212 ASSERT_TRUE(file_util::CreateDirectory(picasa_database_path)); |
| 213 ASSERT_TRUE(file_util::CreateDirectory(picasa_temp_dir_path)); |
| 214 |
| 215 // Create fake folder directories. |
| 216 base::ScopedTempDir folders_root; |
| 217 ASSERT_TRUE(folders_root.CreateUniqueTempDir()); |
| 218 base::FilePath fake_folder_1 = folders_root.path().AppendASCII("folder1"); |
| 219 base::FilePath fake_folder_2 = folders_root.path().AppendASCII("folder2"); |
| 220 ASSERT_TRUE(file_util::CreateDirectory(fake_folder_1)); |
| 221 ASSERT_TRUE(file_util::CreateDirectory(fake_folder_2)); |
| 222 |
| 223 // Write folder and album contents. |
| 224 picasa::WriteTestAlbumTable( |
| 225 picasa_database_path, fake_folder_1, fake_folder_2); |
| 226 picasa::WriteTestAlbumsImagesIndex(fake_folder_1, fake_folder_2); |
| 227 WriteJPEGHeader(fake_folder_1.AppendASCII("InBoth.jpg")); |
| 228 WriteJPEGHeader(fake_folder_1.AppendASCII("InSecondAlbumOnly.jpg")); |
| 229 WriteJPEGHeader(fake_folder_2.AppendASCII("InFirstAlbumOnly.jpg")); |
| 230 |
| 231 SetMediaGalleriesPreferencesForPicasaTest(browser()->profile(), |
| 232 picasa_database_path); |
| 233 |
| 234 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/picasa")) |
| 235 << message_; |
| 236 } |
| 237 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| OLD | NEW |