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 // injects a custom Picasa database location. | |
108 void SetMediaGalleriesPreferencesForPicasaTest( | |
vandebo (ex-Chrome)
2013/09/18 15:49:35
It's not clear to me that you need this function a
tommycli
2013/09/19 22:58:45
Done. Race fixed in a pending CL:
https://coderevi
vandebo (ex-Chrome)
2013/09/23 16:01:31
Why would you need an IDOverride? Can't you just
tommycli
2013/09/24 00:42:36
Sry, I didn't give you enough info. In the CL afte
vandebo (ex-Chrome)
2013/09/26 21:58:52
Will RegistryOverrideManager do what you need?
tommycli
2013/09/26 22:02:15
It would not work for Mac. I could also override t
vandebo (ex-Chrome)
2013/09/26 22:11:59
I've also been working on this: https://codereview
tommycli
2013/09/26 22:22:39
Yeah if it was just either mac prefs or win regist
vandebo (ex-Chrome)
2013/09/26 22:25:10
But we don't want test to behave differently when
tommycli
2013/09/26 22:52:19
I think the current scheme (injecting in a fake de
| |
109 Profile* profile, | |
110 const base::FilePath& database_path) { | |
111 base::RunLoop runloop; | |
112 StorageMonitor::GetInstance()->EnsureInitialized(runloop.QuitClosure()); | |
113 runloop.Run(); | |
114 | |
115 MediaGalleriesPreferences* preferences = | |
116 g_browser_process->media_file_system_registry()->GetPreferences( | |
117 profile); | |
118 | |
119 content::RunAllPendingInMessageLoop(); | |
120 | |
121 preferences->OnPicasaDeviceID(StorageInfo::MakeDeviceId( | |
122 StorageInfo::PICASA, database_path.AsUTF8Unsafe())); | |
123 } | |
124 #endif | |
125 | |
98 private: | 126 private: |
99 std::string device_id_; | 127 std::string device_id_; |
100 }; | 128 }; |
101 | 129 |
102 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, | 130 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, |
103 MediaGalleriesNoAccess) { | 131 MediaGalleriesNoAccess) { |
104 EnsureMediaDirectoriesExists media_directories; | 132 EnsureMediaDirectoriesExists media_directories; |
105 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/no_access")) | 133 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/no_access")) |
106 << message_; | 134 << message_; |
107 RunSecondTestPhase(base::UTF8ToUTF16(base::StringPrintf( | 135 RunSecondTestPhase(base::UTF8ToUTF16(base::StringPrintf( |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 | 194 |
167 DetachFakeDevice(); | 195 DetachFakeDevice(); |
168 } | 196 } |
169 | 197 |
170 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, | 198 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, |
171 GetFilesystemMetadata) { | 199 GetFilesystemMetadata) { |
172 EnsureMediaDirectoriesExists media_directories; | 200 EnsureMediaDirectoriesExists media_directories; |
173 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/metadata")) | 201 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/metadata")) |
174 << message_; | 202 << message_; |
175 } | 203 } |
204 | |
205 #if defined(OS_WIN) || defined(OS_MACOSX) | |
206 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, Picasa) { | |
207 EnsureMediaDirectoriesExists media_directories; | |
208 | |
209 // Create Picasa metadata database directories. | |
210 base::ScopedTempDir metadata_root; | |
211 ASSERT_TRUE(metadata_root.CreateUniqueTempDir()); | |
212 base::FilePath picasa_database_path = | |
213 metadata_root.path().AppendASCII(picasa::kPicasaDatabaseDirName); | |
214 base::FilePath picasa_temp_dir_path = | |
215 metadata_root.path().AppendASCII(picasa::kPicasaTempDirName); | |
216 ASSERT_TRUE(file_util::CreateDirectory(picasa_database_path)); | |
217 ASSERT_TRUE(file_util::CreateDirectory(picasa_temp_dir_path)); | |
218 | |
219 // Create fake folder directories. | |
220 base::ScopedTempDir folders_root; | |
221 ASSERT_TRUE(folders_root.CreateUniqueTempDir()); | |
222 base::FilePath fake_folder_1 = folders_root.path().AppendASCII("folder1"); | |
223 base::FilePath fake_folder_2 = folders_root.path().AppendASCII("folder2"); | |
224 ASSERT_TRUE(file_util::CreateDirectory(fake_folder_1)); | |
225 ASSERT_TRUE(file_util::CreateDirectory(fake_folder_2)); | |
226 | |
227 // Write folder and album contents. | |
228 picasa::WriteTestAlbumTable( | |
229 picasa_database_path, fake_folder_1, fake_folder_2); | |
230 picasa::WriteTestAlbumsImagesIndex(fake_folder_1, fake_folder_2); | |
231 picasa::WriteJPEGHeader(fake_folder_1.AppendASCII("InBoth.jpg")); | |
232 picasa::WriteJPEGHeader(fake_folder_1.AppendASCII("InSecondAlbumOnly.jpg")); | |
233 picasa::WriteJPEGHeader(fake_folder_2.AppendASCII("InFirstAlbumOnly.jpg")); | |
234 | |
235 SetMediaGalleriesPreferencesForPicasaTest(browser()->profile(), | |
236 picasa_database_path); | |
237 | |
238 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/picasa")) | |
239 << message_; | |
240 } | |
241 #endif // defined(OS_WIN) || defined(OS_MACOSX) | |
OLD | NEW |