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; | 51 base::RunLoop runloop; |
47 StorageMonitor::GetInstance()->EnsureInitialized(runloop.QuitClosure()); | 52 StorageMonitor::GetInstance()->EnsureInitialized(runloop.QuitClosure()); |
48 runloop.Run(); | 53 runloop.Run(); |
49 | 54 |
50 MediaGalleriesPreferences* preferences = | 55 MediaGalleriesPreferences* preferences = |
51 g_browser_process->media_file_system_registry()->GetPreferences(profile); | 56 g_browser_process->media_file_system_registry()->GetPreferences(profile); |
52 | 57 |
53 MediaGalleryPrefInfo gallery_info; | 58 MediaGalleryPrefInfo gallery_info; |
54 ASSERT_FALSE(preferences->LookUpGalleryByPath(path, &gallery_info)); | 59 ASSERT_FALSE(preferences->LookUpGalleryByPath(path, &gallery_info)); |
55 preferences->AddGallery(gallery_info.device_id, | 60 preferences->AddGallery(gallery_info.device_id, |
56 gallery_info.path, | 61 gallery_info.path, |
57 false /* user_added */, | 62 false /* user_added */, |
58 gallery_info.volume_label, | 63 gallery_info.volume_label, |
59 gallery_info.vendor_name, | 64 gallery_info.vendor_name, |
60 gallery_info.model_name, | 65 gallery_info.model_name, |
61 gallery_info.total_size_in_bytes, | 66 gallery_info.total_size_in_bytes, |
62 gallery_info.last_attach_time); | 67 gallery_info.last_attach_time); |
63 | 68 |
64 content::RunAllPendingInMessageLoop(); | 69 content::RunAllPendingInMessageLoop(); |
65 } | 70 } |
66 | 71 |
72 } // namespace | |
73 | |
67 class MediaGalleriesPlatformAppBrowserTest : public PlatformAppBrowserTest { | 74 class MediaGalleriesPlatformAppBrowserTest : public PlatformAppBrowserTest { |
68 protected: | 75 protected: |
69 // Since ExtensionTestMessageListener does not work with RunPlatformAppTest(), | 76 // Since ExtensionTestMessageListener does not work with RunPlatformAppTest(), |
70 // This helper method can be used to run additional media gallery tests. | 77 // This helper method can be used to run additional media gallery tests. |
71 void RunSecondTestPhase(const string16& command) { | 78 void RunSecondTestPhase(const string16& command) { |
72 const extensions::Extension* extension = GetSingleLoadedExtension(); | 79 const extensions::Extension* extension = GetSingleLoadedExtension(); |
73 extensions::ExtensionHost* host = | 80 extensions::ExtensionHost* host = |
74 extensions::ExtensionSystem::Get(browser()->profile())-> | 81 extensions::ExtensionSystem::Get(browser()->profile())-> |
75 process_manager()->GetBackgroundHostForExtension(extension->id()); | 82 process_manager()->GetBackgroundHostForExtension(extension->id()); |
76 ASSERT_TRUE(host); | 83 ASSERT_TRUE(host); |
(...skipping 11 matching lines...) Expand all Loading... | |
88 StorageInfo(device_id_, string16(), kDevicePath, | 95 StorageInfo(device_id_, string16(), kDevicePath, |
89 ASCIIToUTF16(kDeviceName), string16(), string16(), 0)); | 96 ASCIIToUTF16(kDeviceName), string16(), string16(), 0)); |
90 content::RunAllPendingInMessageLoop(); | 97 content::RunAllPendingInMessageLoop(); |
91 } | 98 } |
92 | 99 |
93 void DetachFakeDevice() { | 100 void DetachFakeDevice() { |
94 StorageMonitor::GetInstance()->receiver()->ProcessDetach(device_id_); | 101 StorageMonitor::GetInstance()->receiver()->ProcessDetach(device_id_); |
95 content::RunAllPendingInMessageLoop(); | 102 content::RunAllPendingInMessageLoop(); |
96 } | 103 } |
97 | 104 |
105 #if defined(OS_WIN) || defined(OS_MACOSX) | |
106 // This initializes the storage monitor, MediaGalleriesPreferences, and | |
107 // removes all non-Picasa media galleries for a test. | |
108 void SetMediaGalleriesPreferencesForPicasaTest(Profile* profile) { | |
vandebo (ex-Chrome)
2013/09/17 21:18:06
I think the js equivalent (picking out the picasa
tommycli
2013/09/18 15:25:37
Done.
| |
109 base::RunLoop runloop; | |
110 StorageMonitor::GetInstance()->EnsureInitialized(runloop.QuitClosure()); | |
111 runloop.Run(); | |
112 | |
113 MediaGalleriesPreferences* preferences = | |
114 g_browser_process->media_file_system_registry()->GetPreferences( | |
115 profile); | |
116 | |
117 content::RunAllPendingInMessageLoop(); | |
118 | |
119 // Remove all non-Picasa galleries for ease of testing. | |
120 MediaGalleriesPrefInfoMap known_galleries = preferences->known_galleries(); | |
121 for (MediaGalleriesPrefInfoMap::const_iterator it = known_galleries.begin(); | |
122 it != known_galleries.end(); | |
123 ++it) { | |
124 if (!StorageInfo::IsPicasaDevice(it->second.device_id)) | |
125 preferences->ForgetGalleryById(it->first); | |
126 } | |
127 | |
128 content::RunAllPendingInMessageLoop(); | |
129 } | |
130 #endif | |
131 | |
98 private: | 132 private: |
99 std::string device_id_; | 133 std::string device_id_; |
100 }; | 134 }; |
101 | 135 |
102 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, | 136 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, |
103 MediaGalleriesNoAccess) { | 137 MediaGalleriesNoAccess) { |
104 EnsureMediaDirectoriesExists media_directories; | 138 EnsureMediaDirectoriesExists media_directories; |
105 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/no_access")) | 139 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/no_access")) |
106 << message_; | 140 << message_; |
107 RunSecondTestPhase(base::UTF8ToUTF16(base::StringPrintf( | 141 RunSecondTestPhase(base::UTF8ToUTF16(base::StringPrintf( |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 | 200 |
167 DetachFakeDevice(); | 201 DetachFakeDevice(); |
168 } | 202 } |
169 | 203 |
170 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, | 204 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, |
171 GetFilesystemMetadata) { | 205 GetFilesystemMetadata) { |
172 EnsureMediaDirectoriesExists media_directories; | 206 EnsureMediaDirectoriesExists media_directories; |
173 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/metadata")) | 207 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/metadata")) |
174 << message_; | 208 << message_; |
175 } | 209 } |
210 | |
211 #if defined(OS_WIN) || defined(OS_MACOSX) | |
212 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, Picasa) { | |
213 EnsureMediaDirectoriesExists media_directories; | |
214 | |
215 // Create Picasa metadata database directories. | |
216 base::FilePath picasa_database_path = | |
217 picasa::PicasaFinder::GetPicasaDatabasePath(); | |
vandebo (ex-Chrome)
2013/09/17 21:18:06
Would it make sense to just call the regular Picas
tommycli
2013/09/18 15:25:37
Changed some stuff here.
| |
218 base::FilePath picasa_temp_dir_path = | |
219 picasa_database_path.DirName().AppendASCII(picasa::kPicasaTempDirName); | |
220 ASSERT_TRUE(file_util::CreateDirectory(picasa_database_path)); | |
221 ASSERT_TRUE(file_util::CreateDirectory(picasa_temp_dir_path)); | |
222 | |
223 // Create fake folder directories. | |
224 base::ScopedTempDir folders_root; | |
225 ASSERT_TRUE(folders_root.CreateUniqueTempDir()); | |
226 base::FilePath fake_folder_1 = folders_root.path().AppendASCII("folder1"); | |
227 base::FilePath fake_folder_2 = folders_root.path().AppendASCII("folder2"); | |
228 ASSERT_TRUE(file_util::CreateDirectory(fake_folder_1)); | |
229 ASSERT_TRUE(file_util::CreateDirectory(fake_folder_2)); | |
230 | |
231 // Write folder and album contents. | |
232 picasa::WriteTestAlbumTable( | |
233 picasa_database_path, fake_folder_1, fake_folder_2); | |
234 picasa::WriteTestAlbumsImagesIndex(fake_folder_1, fake_folder_2); | |
235 picasa::WriteJPEGHeader(fake_folder_1.AppendASCII("InBoth.jpg")); | |
236 picasa::WriteJPEGHeader(fake_folder_1.AppendASCII("InSecondAlbumOnly.jpg")); | |
237 picasa::WriteJPEGHeader(fake_folder_2.AppendASCII("InFirstAlbumOnly.jpg")); | |
238 | |
239 SetMediaGalleriesPreferencesForPicasaTest(browser()->profile()); | |
240 | |
241 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/picasa")) | |
242 << message_; | |
243 } | |
244 #endif // defined(OS_WIN) || defined(OS_MACOSX) | |
OLD | NEW |