Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: chrome/browser/extensions/api/media_galleries/media_galleries_apitest.cc

Issue 86743002: [MediaGalleries] Enable iPhoto gallery (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Test setup in util Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/media_galleries/fileapi/iapps_finder_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/path_service.h" 9 #include "base/path_service.h"
10 #include "base/safe_numerics.h" 10 #include "base/safe_numerics.h"
11 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "chrome/browser/apps/app_browsertest_util.h" 14 #include "chrome/browser/apps/app_browsertest_util.h"
14 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/extensions/extension_system.h" 16 #include "chrome/browser/extensions/extension_system.h"
16 #include "chrome/browser/media_galleries/media_file_system_registry.h" 17 #include "chrome/browser/media_galleries/media_file_system_registry.h"
17 #include "chrome/browser/media_galleries/media_galleries_preferences.h" 18 #include "chrome/browser/media_galleries/media_galleries_preferences.h"
18 #include "chrome/browser/media_galleries/media_galleries_test_util.h" 19 #include "chrome/browser/media_galleries/media_galleries_test_util.h"
19 #include "chrome/browser/storage_monitor/storage_info.h" 20 #include "chrome/browser/storage_monitor/storage_info.h"
20 #include "chrome/browser/storage_monitor/storage_monitor.h" 21 #include "chrome/browser/storage_monitor/storage_monitor.h"
21 #include "chrome/common/chrome_paths.h" 22 #include "chrome/common/chrome_paths.h"
22 #include "content/public/test/test_utils.h" 23 #include "content/public/test/test_utils.h"
23 24
24 #if defined(OS_WIN) || defined(OS_MACOSX) 25 #if defined(OS_WIN) || defined(OS_MACOSX)
25 #include "chrome/browser/media_galleries/fileapi/picasa_finder.h" 26 #include "chrome/browser/media_galleries/fileapi/picasa_finder.h"
26 #include "chrome/common/media_galleries/picasa_test_util.h" 27 #include "chrome/common/media_galleries/picasa_test_util.h"
27 #include "chrome/common/media_galleries/picasa_types.h" 28 #include "chrome/common/media_galleries/picasa_types.h"
28 #include "chrome/common/media_galleries/pmp_test_util.h" 29 #include "chrome/common/media_galleries/pmp_test_util.h"
29 #endif 30 #endif
30 31
32 #if defined(OS_MACOSX)
33 #include "base/mac/foundation_util.h"
34 #include "base/strings/sys_string_conversions.h"
35 #include "chrome/browser/media_galleries/fileapi/iapps_finder_impl.h"
36 #endif // OS_MACOSX
37
31 using extensions::PlatformAppBrowserTest; 38 using extensions::PlatformAppBrowserTest;
32 39
33 namespace { 40 namespace {
34 41
35 // Dummy device properties. 42 // Dummy device properties.
36 const char kDeviceId[] = "testDeviceId"; 43 const char kDeviceId[] = "testDeviceId";
37 const char kDeviceName[] = "foobar"; 44 const char kDeviceName[] = "foobar";
38 #if defined(FILE_PATH_USES_DRIVE_LETTERS) 45 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
39 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("C:\\qux"); 46 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("C:\\qux");
40 #else 47 #else
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 return false; 100 return false;
94 101
95 const char* custom_arg = NULL; 102 const char* custom_arg = NULL;
96 std::string json_string; 103 std::string json_string;
97 if (!custom_arg_value.empty()) { 104 if (!custom_arg_value.empty()) {
98 base::JSONWriter::Write(&custom_arg_value, &json_string); 105 base::JSONWriter::Write(&custom_arg_value, &json_string);
99 custom_arg = json_string.c_str(); 106 custom_arg = json_string.c_str();
100 } 107 }
101 108
102 base::AutoReset<base::FilePath> reset(&test_data_dir_, temp_dir.path()); 109 base::AutoReset<base::FilePath> reset(&test_data_dir_, temp_dir.path());
103 return RunPlatformAppTestWithArg(extension_name, custom_arg); 110 bool result = RunPlatformAppTestWithArg(extension_name, custom_arg);
111 content::RunAllPendingInMessageLoop(); // avoid race on exit in registry.
112 return result;
104 } 113 }
105 114
106 void AttachFakeDevice() { 115 void AttachFakeDevice() {
107 device_id_ = StorageInfo::MakeDeviceId( 116 device_id_ = StorageInfo::MakeDeviceId(
108 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId); 117 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId);
109 118
110 StorageMonitor::GetInstance()->receiver()->ProcessAttach( 119 StorageMonitor::GetInstance()->receiver()->ProcessAttach(
111 StorageInfo(device_id_, base::string16(), kDevicePath, 120 StorageInfo(device_id_, base::string16(), kDevicePath,
112 base::ASCIIToUTF16(kDeviceName), base::string16(), 121 base::ASCIIToUTF16(kDeviceName), base::string16(),
113 base::string16(), 0)); 122 base::string16(), 0));
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 picasa::WriteTestAlbumsImagesIndex(fake_folder_1, fake_folder_2); 198 picasa::WriteTestAlbumsImagesIndex(fake_folder_1, fake_folder_2);
190 199
191 base::FilePath test_jpg_path = GetCommonDataDir().AppendASCII("test.jpg"); 200 base::FilePath test_jpg_path = GetCommonDataDir().AppendASCII("test.jpg");
192 ASSERT_TRUE(base::CopyFile( 201 ASSERT_TRUE(base::CopyFile(
193 test_jpg_path, fake_folder_1.AppendASCII("InBoth.jpg"))); 202 test_jpg_path, fake_folder_1.AppendASCII("InBoth.jpg")));
194 ASSERT_TRUE(base::CopyFile( 203 ASSERT_TRUE(base::CopyFile(
195 test_jpg_path, fake_folder_1.AppendASCII("InSecondAlbumOnly.jpg"))); 204 test_jpg_path, fake_folder_1.AppendASCII("InSecondAlbumOnly.jpg")));
196 ASSERT_TRUE(base::CopyFile( 205 ASSERT_TRUE(base::CopyFile(
197 test_jpg_path, fake_folder_2.AppendASCII("InFirstAlbumOnly.jpg"))); 206 test_jpg_path, fake_folder_2.AppendASCII("InFirstAlbumOnly.jpg")));
198 } 207 }
199 #endif 208 #endif // defined(OS_WIN) || defined(OS_MACOSX)
209
210 #if defined(OS_MACOSX)
211 void PopulateIPhotoTestData(const base::FilePath& iphoto_data_root) {
212 std::string xml_contents = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
213 "<plist version=\"1.0\">"
214 "<dict>\n"
215
216 " <key>List of Albums</key>"
217 " <array>\n"
218
219 " <dict>\n"
220 " <key>AlbumId</key>"
221 " <integer>1</integer>"
222 " <key>AlbumName</key>"
223 " <string>Album1</string>"
224 " <key>KeyList</key>\n"
225 " <array>"
226 " <string>1</string>"
227 " <string>2</string>"
228 " </array>\n"
229 " </dict>\n"
230
231 " <dict>\n"
232 " <key>AlbumId</key>"
233 " <integer>2</integer>"
234 " <key>AlbumName</key>"
235 " <string>Album2</string>"
236 " <key>KeyList</key>\n"
237 " <array>"
238 " <string>2</string>"
239 " </array>\n"
240 " </dict>\n"
241
242 " </array>\n"
243
244 " <key>Master Image List</key>\n"
245 " <dict>\n"
246
247 " <key>1</key>"
248 " <dict>\n"
249 " <key>MediaType</key>"
250 " <string>Image</string>"
251 " <key>Caption</key>"
252 " <string>caption 1</string>"
253 " <key>GUID</key>"
254 " <string>1</string>"
255 " <key>ModDateAsTimerInterval</key>"
256 " <string>386221543.0000</string>"
257 " <key>DateAsTimerInterval</key>"
258 " <string>386221543.0000</string>"
259 " <key>DateAsTimerIntervalGMT</key>"
260 " <string>385123456.00</string>"
261 " <key>ImagePath</key>"
262 " <string>$path1</string>"
263 " <key>ThumbPath</key>"
264 " <string>/thumb/path</string>\n"
265 " </dict>\n"
266
267 " <key>2</key>\n"
268 " <dict>\n"
269 " <key>MediaType</key>"
270 " <string>Image</string>"
271 " <key>Caption</key>"
272 " <string>caption 2</string>"
273 " <key>GUID</key>"
274 " <string>2</string>"
275 " <key>ModDateAsTimerInterval</key>"
276 " <string>386221543.0000</string>"
277 " <key>DateAsTimerInterval</key>"
278 " <string>386221543.0000</string>"
279 " <key>DateAsTimerIntervalGMT</key>"
280 " <string>385123456.00</string>"
281 " <key>ImagePath</key>"
282 " <string>$path2</string>"
283 " <key>ThumbPath</key>"
284 " <string>/thumb/path2</string>\n"
285 " </dict>\n"
286
287 " </dict>\n" // Master Image List
288
289 "</dict>\n"
290 "</plist>";
291
292 base::FilePath test_jpg_path = GetCommonDataDir().AppendASCII("test.jpg");
293 ASSERT_TRUE(base::CreateDirectory(iphoto_data_root));
294 base::FilePath first_only_jpg =
295 iphoto_data_root.AppendASCII("InFirstAlbumOnly.jpg");
296 base::FilePath in_both_jpg = iphoto_data_root.AppendASCII("InBoth.jpg");
297 ASSERT_TRUE(base::CopyFile(test_jpg_path, first_only_jpg));
298 ASSERT_TRUE(base::CopyFile(test_jpg_path, in_both_jpg));
299 ReplaceFirstSubstringAfterOffset(
300 &xml_contents, 0, std::string("$path1"), first_only_jpg.value());
301 ReplaceFirstSubstringAfterOffset(
302 &xml_contents, 0, std::string("$path2"), in_both_jpg.value());
303
304 base::FilePath album_xml = iphoto_data_root.AppendASCII("AlbumData.xml");
305 ASSERT_NE(-1, file_util::WriteFile(album_xml,
306 xml_contents.c_str(),
307 xml_contents.size()));
308 }
309 #endif // defined(OS_MACOSX)
200 310
201 base::FilePath GetCommonDataDir() const { 311 base::FilePath GetCommonDataDir() const {
202 return test_data_dir_.AppendASCII("api_test") 312 return test_data_dir_.AppendASCII("api_test")
203 .AppendASCII("media_galleries") 313 .AppendASCII("media_galleries")
204 .AppendASCII("common"); 314 .AppendASCII("common");
205 } 315 }
206 316
207 int num_galleries() const { 317 int num_galleries() const {
208 return ensure_media_directories_exists_->num_galleries(); 318 return ensure_media_directories_exists_->num_galleries();
209 } 319 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 ASSERT_TRUE(custom_picasa_app_data_root.CreateUniqueTempDir()); 424 ASSERT_TRUE(custom_picasa_app_data_root.CreateUniqueTempDir());
315 ensure_media_directories_exists()->SetCustomPicasaAppDataPath( 425 ensure_media_directories_exists()->SetCustomPicasaAppDataPath(
316 custom_picasa_app_data_root.path()); 426 custom_picasa_app_data_root.path());
317 PopulatePicasaTestData(custom_picasa_app_data_root.path()); 427 PopulatePicasaTestData(custom_picasa_app_data_root.path());
318 428
319 base::ListValue custom_args; 429 base::ListValue custom_args;
320 custom_args.AppendInteger(test_jpg_size()); 430 custom_args.AppendInteger(test_jpg_size());
321 ASSERT_TRUE(RunMediaGalleriesTestWithArg("picasa", custom_args)) << message_; 431 ASSERT_TRUE(RunMediaGalleriesTestWithArg("picasa", custom_args)) << message_;
322 } 432 }
323 #endif // defined(OS_WIN) || defined(OS_MACOSX) 433 #endif // defined(OS_WIN) || defined(OS_MACOSX)
434
435 #if defined(OS_MACOSX)
436 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
437 IPhotoTest) {
438 PopulateIPhotoTestData(
439 ensure_media_directories_exists()->GetFakeIPhotoRootPath());
440
441 base::ListValue custom_args;
442 custom_args.AppendInteger(test_jpg_size());
443 ASSERT_TRUE(RunMediaGalleriesTestWithArg("iphoto", custom_args)) << message_;
444
445 iapps::SetMacPreferencesForTesting(NULL);
446 }
447 #endif // defined(OS_MACOSX)
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/media_galleries/fileapi/iapps_finder_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698