Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / api / media_galleries / media_galleries_apitest.cc
blobe7ff754a722cfd6ce44855c457ac63f7912baf39
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
3 // found in the LICENSE file.
5 #include "base/auto_reset.h"
6 #include "base/callback.h"
7 #include "base/files/file_util.h"
8 #include "base/files/scoped_temp_dir.h"
9 #include "base/json/json_writer.h"
10 #include "base/numerics/safe_conversions.h"
11 #include "base/path_service.h"
12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "base/values.h"
15 #include "chrome/browser/apps/app_browsertest_util.h"
16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h"
18 #include "chrome/browser/media_galleries/media_file_system_registry.h"
19 #include "chrome/browser/media_galleries/media_folder_finder.h"
20 #include "chrome/browser/media_galleries/media_galleries_preferences.h"
21 #include "chrome/browser/media_galleries/media_galleries_scan_result_controller.h"
22 #include "chrome/browser/media_galleries/media_galleries_test_util.h"
23 #include "chrome/browser/media_galleries/media_scan_manager.h"
24 #include "chrome/browser/ui/extensions/app_launch_params.h"
25 #include "chrome/browser/ui/extensions/application_launch.h"
26 #include "chrome/common/chrome_paths.h"
27 #include "components/storage_monitor/storage_info.h"
28 #include "components/storage_monitor/storage_monitor.h"
29 #include "content/public/browser/web_contents.h"
30 #include "content/public/test/test_utils.h"
31 #include "extensions/browser/extension_system.h"
32 #include "extensions/common/constants.h"
33 #include "extensions/common/extension.h"
34 #include "extensions/test/result_catcher.h"
35 #include "media/base/test_data_util.h"
37 #if defined(OS_WIN) || defined(OS_MACOSX)
38 #include "chrome/browser/media_galleries/fileapi/picasa_finder.h"
39 #include "chrome/common/media_galleries/picasa_test_util.h"
40 #include "chrome/common/media_galleries/picasa_types.h"
41 #include "chrome/common/media_galleries/pmp_test_util.h"
42 #endif
44 #if defined(OS_MACOSX)
45 #include "base/mac/foundation_util.h"
46 #include "base/strings/sys_string_conversions.h"
47 #include "chrome/browser/media_galleries/fileapi/iapps_finder_impl.h"
48 #endif // OS_MACOSX
50 #if !defined(DISABLE_NACL)
51 #include "base/command_line.h"
52 #include "chrome/browser/ui/extensions/application_launch.h"
53 #include "ppapi/shared_impl/ppapi_switches.h"
54 #endif
56 using extensions::PlatformAppBrowserTest;
57 using storage_monitor::StorageInfo;
58 using storage_monitor::StorageMonitor;
60 namespace {
62 // Dummy device properties.
63 const char kDeviceId[] = "testDeviceId";
64 const char kDeviceName[] = "foobar";
65 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
66 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("C:\\qux");
67 #else
68 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("/qux");
69 #endif
71 class DoNothingMediaFolderFinder : public MediaFolderFinder {
72 public:
73 explicit DoNothingMediaFolderFinder(
74 const MediaFolderFinderResultsCallback& callback)
75 : MediaFolderFinder(callback) {
77 ~DoNothingMediaFolderFinder() override {}
79 static MediaFolderFinder* CreateDoNothingMediaFolderFinder(
80 const MediaFolderFinderResultsCallback& callback) {
81 return new DoNothingMediaFolderFinder(callback);
84 void StartScan() override {}
86 private:
89 } // namespace
91 class TestMediaGalleriesAddScanResultsFunction
92 : public extensions::MediaGalleriesAddScanResultsFunction {
93 public:
94 static ExtensionFunction* Factory() {
95 return new TestMediaGalleriesAddScanResultsFunction;
98 protected:
99 ~TestMediaGalleriesAddScanResultsFunction() override {}
101 // Accepts the dialog as soon as it is created.
102 MediaGalleriesScanResultController* MakeDialog(
103 content::WebContents* web_contents,
104 const extensions::Extension& extension,
105 const base::Closure& on_finish) override {
106 MediaGalleriesScanResultController* controller =
107 extensions::MediaGalleriesAddScanResultsFunction::MakeDialog(
108 web_contents, extension, on_finish);
109 controller->dialog_->AcceptDialogForTesting();
110 // The dialog is closing or closed so don't return it.
111 return NULL;
115 class MediaGalleriesPlatformAppBrowserTest : public PlatformAppBrowserTest {
116 protected:
117 MediaGalleriesPlatformAppBrowserTest() : test_jpg_size_(0) {}
118 ~MediaGalleriesPlatformAppBrowserTest() override {}
120 void SetUpOnMainThread() override {
121 PlatformAppBrowserTest::SetUpOnMainThread();
122 ensure_media_directories_exists_.reset(new EnsureMediaDirectoriesExists);
124 int64 file_size;
125 ASSERT_TRUE(base::GetFileSize(GetCommonDataDir().AppendASCII("test.jpg"),
126 &file_size));
127 test_jpg_size_ = base::checked_cast<int>(file_size);
130 void TearDownOnMainThread() override {
131 ensure_media_directories_exists_.reset();
132 PlatformAppBrowserTest::TearDownOnMainThread();
135 bool RunMediaGalleriesTest(const std::string& extension_name) {
136 base::ListValue empty_list_value;
137 return RunMediaGalleriesTestWithArg(extension_name, empty_list_value);
140 bool RunMediaGalleriesTestWithArg(const std::string& extension_name,
141 const base::ListValue& custom_arg_value) {
142 // Copy the test data for this test into a temporary directory. Then add
143 // a common_injected.js to the temporary copy and run it.
144 const char kTestDir[] = "api_test/media_galleries/";
145 base::FilePath from_dir =
146 test_data_dir_.AppendASCII(kTestDir + extension_name);
147 from_dir = from_dir.NormalizePathSeparators();
149 base::ScopedTempDir temp_dir;
150 if (!temp_dir.CreateUniqueTempDir())
151 return false;
153 if (!base::CopyDirectory(from_dir, temp_dir.path(), true))
154 return false;
156 base::FilePath common_js_path(
157 GetCommonDataDir().AppendASCII("common_injected.js"));
158 base::FilePath inject_js_path(
159 temp_dir.path().AppendASCII(extension_name)
160 .AppendASCII("common_injected.js"));
161 if (!base::CopyFile(common_js_path, inject_js_path))
162 return false;
164 const char* custom_arg = NULL;
165 std::string json_string;
166 if (!custom_arg_value.empty()) {
167 base::JSONWriter::Write(custom_arg_value, &json_string);
168 custom_arg = json_string.c_str();
171 base::AutoReset<base::FilePath> reset(&test_data_dir_, temp_dir.path());
172 bool result = RunPlatformAppTestWithArg(extension_name, custom_arg);
173 content::RunAllPendingInMessageLoop(); // avoid race on exit in registry.
174 return result;
177 void AttachFakeDevice() {
178 device_id_ = StorageInfo::MakeDeviceId(
179 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId);
181 StorageMonitor::GetInstance()->receiver()->ProcessAttach(
182 StorageInfo(device_id_, kDevicePath, base::ASCIIToUTF16(kDeviceName),
183 base::string16(), base::string16(), 0));
184 content::RunAllPendingInMessageLoop();
187 void DetachFakeDevice() {
188 StorageMonitor::GetInstance()->receiver()->ProcessDetach(device_id_);
189 content::RunAllPendingInMessageLoop();
192 // Called if test only wants a single gallery it creates.
193 void RemoveAllGalleries() {
194 MediaGalleriesPreferences* preferences = GetAndInitializePreferences();
196 // Make a copy, as the iterator would be invalidated otherwise.
197 const MediaGalleriesPrefInfoMap galleries =
198 preferences->known_galleries();
199 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin();
200 it != galleries.end(); ++it) {
201 preferences->ForgetGalleryById(it->first);
205 // This function makes a single fake gallery. This is needed to test platforms
206 // with no default media galleries, such as CHROMEOS. This fake gallery is
207 // pre-populated with a test.jpg and test.txt.
208 void MakeSingleFakeGallery(MediaGalleryPrefId* pref_id) {
209 ASSERT_FALSE(fake_gallery_temp_dir_.IsValid());
210 ASSERT_TRUE(fake_gallery_temp_dir_.CreateUniqueTempDir());
212 MediaGalleriesPreferences* preferences = GetAndInitializePreferences();
214 MediaGalleryPrefInfo gallery_info;
215 ASSERT_FALSE(preferences->LookUpGalleryByPath(fake_gallery_temp_dir_.path(),
216 &gallery_info));
217 MediaGalleryPrefId id = preferences->AddGallery(
218 gallery_info.device_id,
219 gallery_info.path,
220 MediaGalleryPrefInfo::kAutoDetected,
221 gallery_info.volume_label,
222 gallery_info.vendor_name,
223 gallery_info.model_name,
224 gallery_info.total_size_in_bytes,
225 gallery_info.last_attach_time,
226 0, 0, 0);
227 if (pref_id)
228 *pref_id = id;
230 content::RunAllPendingInMessageLoop();
232 // Valid file, should show up in JS as a FileEntry.
233 AddFileToSingleFakeGallery(GetCommonDataDir().AppendASCII("test.jpg"));
235 // Invalid file, should not show up as a FileEntry in JS at all.
236 AddFileToSingleFakeGallery(GetCommonDataDir().AppendASCII("test.txt"));
239 void AddFileToSingleFakeGallery(const base::FilePath& source_path) {
240 ASSERT_TRUE(fake_gallery_temp_dir_.IsValid());
242 ASSERT_TRUE(base::CopyFile(
243 source_path,
244 fake_gallery_temp_dir_.path().Append(source_path.BaseName())));
247 #if defined(OS_WIN) || defined(OS_MACOSX)
248 void PopulatePicasaTestData(const base::FilePath& picasa_app_data_root) {
249 base::FilePath picasa_database_path =
250 picasa::MakePicasaDatabasePath(picasa_app_data_root);
251 base::FilePath picasa_temp_dir_path =
252 picasa_database_path.DirName().AppendASCII(picasa::kPicasaTempDirName);
253 ASSERT_TRUE(base::CreateDirectory(picasa_database_path));
254 ASSERT_TRUE(base::CreateDirectory(picasa_temp_dir_path));
256 // Create fake folder directories.
257 base::FilePath folders_root =
258 ensure_media_directories_exists_->GetFakePicasaFoldersRootPath();
259 base::FilePath fake_folder_1 = folders_root.AppendASCII("folder1");
260 base::FilePath fake_folder_2 = folders_root.AppendASCII("folder2");
261 ASSERT_TRUE(base::CreateDirectory(fake_folder_1));
262 ASSERT_TRUE(base::CreateDirectory(fake_folder_2));
264 // Write folder and album contents.
265 picasa::WriteTestAlbumTable(
266 picasa_database_path, fake_folder_1, fake_folder_2);
267 picasa::WriteTestAlbumsImagesIndex(fake_folder_1, fake_folder_2);
269 base::FilePath test_jpg_path = GetCommonDataDir().AppendASCII("test.jpg");
270 ASSERT_TRUE(base::CopyFile(
271 test_jpg_path, fake_folder_1.AppendASCII("InBoth.jpg")));
272 ASSERT_TRUE(base::CopyFile(
273 test_jpg_path, fake_folder_1.AppendASCII("InSecondAlbumOnly.jpg")));
274 ASSERT_TRUE(base::CopyFile(
275 test_jpg_path, fake_folder_2.AppendASCII("InFirstAlbumOnly.jpg")));
277 #endif // defined(OS_WIN) || defined(OS_MACOSX)
279 #if defined(OS_MACOSX)
280 void PopulateIPhotoTestData(const base::FilePath& iphoto_data_root) {
281 std::string xml_contents = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
282 "<plist version=\"1.0\">"
283 "<dict>\n"
285 " <key>List of Albums</key>"
286 " <array>\n"
288 " <dict>\n"
289 " <key>AlbumId</key>"
290 " <integer>1</integer>"
291 " <key>AlbumName</key>"
292 " <string>Album1</string>"
293 " <key>KeyList</key>\n"
294 " <array>"
295 " <string>1</string>"
296 " <string>2</string>"
297 " </array>\n"
298 " </dict>\n"
300 " <dict>\n"
301 " <key>AlbumId</key>"
302 " <integer>2</integer>"
303 " <key>AlbumName</key>"
304 " <string>Album2</string>"
305 " <key>KeyList</key>\n"
306 " <array>"
307 " <string>2</string>"
308 " </array>\n"
309 " </dict>\n"
311 " </array>\n"
313 " <key>Master Image List</key>\n"
314 " <dict>\n"
316 " <key>1</key>"
317 " <dict>\n"
318 " <key>MediaType</key>"
319 " <string>Image</string>"
320 " <key>Caption</key>"
321 " <string>caption 1</string>"
322 " <key>GUID</key>"
323 " <string>1</string>"
324 " <key>ModDateAsTimerInterval</key>"
325 " <string>386221543.0000</string>"
326 " <key>DateAsTimerInterval</key>"
327 " <string>386221543.0000</string>"
328 " <key>DateAsTimerIntervalGMT</key>"
329 " <string>385123456.00</string>"
330 " <key>ImagePath</key>"
331 " <string>$path1</string>"
332 " <key>ThumbPath</key>"
333 " <string>/thumb/path</string>\n"
334 " </dict>\n"
336 " <key>2</key>\n"
337 " <dict>\n"
338 " <key>MediaType</key>"
339 " <string>Image</string>"
340 " <key>Caption</key>"
341 " <string>caption 2</string>"
342 " <key>GUID</key>"
343 " <string>2</string>"
344 " <key>ModDateAsTimerInterval</key>"
345 " <string>386221543.0000</string>"
346 " <key>DateAsTimerInterval</key>"
347 " <string>386221543.0000</string>"
348 " <key>DateAsTimerIntervalGMT</key>"
349 " <string>385123456.00</string>"
350 " <key>ImagePath</key>"
351 " <string>$path2</string>"
352 " <key>ThumbPath</key>"
353 " <string>/thumb/path2</string>\n"
354 " </dict>\n"
356 " </dict>\n" // Master Image List
358 "</dict>\n"
359 "</plist>";
361 base::FilePath test_jpg_path = GetCommonDataDir().AppendASCII("test.jpg");
362 ASSERT_TRUE(base::CreateDirectory(iphoto_data_root));
363 base::FilePath first_only_jpg =
364 iphoto_data_root.AppendASCII("InFirstAlbumOnly.jpg");
365 base::FilePath in_both_jpg = iphoto_data_root.AppendASCII("InBoth.jpg");
366 ASSERT_TRUE(base::CopyFile(test_jpg_path, first_only_jpg));
367 ASSERT_TRUE(base::CopyFile(test_jpg_path, in_both_jpg));
368 base::ReplaceFirstSubstringAfterOffset(
369 &xml_contents, 0, "$path1", first_only_jpg.value());
370 base::ReplaceFirstSubstringAfterOffset(
371 &xml_contents, 0, "$path2", in_both_jpg.value());
373 base::FilePath album_xml = iphoto_data_root.AppendASCII("AlbumData.xml");
374 ASSERT_NE(-1, base::WriteFile(album_xml,
375 xml_contents.c_str(), xml_contents.size()));
377 #endif // defined(OS_MACOSX)
379 base::FilePath GetCommonDataDir() const {
380 return test_data_dir_.AppendASCII("api_test")
381 .AppendASCII("media_galleries")
382 .AppendASCII("common");
385 base::FilePath GetWallpaperTestDataDir() const {
386 return test_data_dir_.AppendASCII("api_test")
387 .AppendASCII("wallpaper");
390 int num_galleries() const {
391 return ensure_media_directories_exists_->num_galleries();
394 int test_jpg_size() const { return test_jpg_size_; }
396 EnsureMediaDirectoriesExists* ensure_media_directories_exists() const {
397 return ensure_media_directories_exists_.get();
400 void InstallDoNothingFolderFinder() {
401 MediaScanManager * scan_manager =
402 g_browser_process->media_file_system_registry()->media_scan_manager();
403 scan_manager->SetMediaFolderFinderFactory(base::Bind(
404 &DoNothingMediaFolderFinder::CreateDoNothingMediaFolderFinder));
407 void SetRootsForFolderFinder(const std::vector<base::FilePath>& roots) {
408 MediaScanManager* scan_manager =
409 g_browser_process->media_file_system_registry()->media_scan_manager();
410 scan_manager->SetMediaFolderFinderFactory(base::Bind(
411 &MediaGalleriesPlatformAppBrowserTest::CreateMediaFolderFinderWithRoots,
412 roots));
415 private:
416 static MediaFolderFinder* CreateMediaFolderFinderWithRoots(
417 const std::vector<base::FilePath>& roots,
418 const MediaFolderFinder::MediaFolderFinderResultsCallback& callback) {
419 MediaFolderFinder* finder = new MediaFolderFinder(callback);
420 finder->SetRootsForTesting(roots);
421 return finder;
424 MediaGalleriesPreferences* GetAndInitializePreferences() {
425 MediaGalleriesPreferences* preferences =
426 g_browser_process->media_file_system_registry()->GetPreferences(
427 browser()->profile());
428 base::RunLoop runloop;
429 preferences->EnsureInitialized(runloop.QuitClosure());
430 runloop.Run();
431 return preferences;
434 std::string device_id_;
435 base::ScopedTempDir fake_gallery_temp_dir_;
436 int test_jpg_size_;
437 scoped_ptr<EnsureMediaDirectoriesExists> ensure_media_directories_exists_;
440 #if !defined(DISABLE_NACL)
441 class MediaGalleriesPlatformAppPpapiTest
442 : public MediaGalleriesPlatformAppBrowserTest {
443 protected:
444 void SetUpCommandLine(base::CommandLine* command_line) override {
445 MediaGalleriesPlatformAppBrowserTest::SetUpCommandLine(command_line);
446 command_line->AppendSwitch(switches::kEnablePepperTesting);
449 void SetUpOnMainThread() override {
450 MediaGalleriesPlatformAppBrowserTest::SetUpOnMainThread();
452 ASSERT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, &app_dir_));
453 app_dir_ = app_dir_.AppendASCII("ppapi")
454 .AppendASCII("tests")
455 .AppendASCII("extensions")
456 .AppendASCII("media_galleries")
457 .AppendASCII("newlib");
460 const base::FilePath& app_dir() const {
461 return app_dir_;
464 private:
465 base::FilePath app_dir_;
468 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppPpapiTest, SendFilesystem) {
469 RemoveAllGalleries();
470 MakeSingleFakeGallery(NULL);
472 const extensions::Extension* extension = LoadExtension(app_dir());
473 ASSERT_TRUE(extension);
475 extensions::ResultCatcher catcher;
476 AppLaunchParams params(browser()->profile(), extension,
477 extensions::LAUNCH_CONTAINER_NONE, NEW_WINDOW,
478 extensions::SOURCE_TEST);
479 params.command_line = *base::CommandLine::ForCurrentProcess();
480 OpenApplication(params);
482 bool result = true;
483 if (!catcher.GetNextResult()) {
484 message_ = catcher.message();
485 result = false;
487 content::RunAllPendingInMessageLoop(); // avoid race on exit in registry.
488 ASSERT_TRUE(result) << message_;
491 #endif // !defined(DISABLE_NACL)
493 // Test is flaky, it fails on certain bots, namely WinXP Tests(1) and Linux
494 // (dbg)(1)(32). See crbug.com/354425.
495 #if defined(OS_WIN) || defined(OS_LINUX)
496 #define MAYBE_MediaGalleriesNoAccess DISABLED_MediaGalleriesNoAccess
497 #else
498 #define MAYBE_MediaGalleriesNoAccess MediaGalleriesNoAccess
499 #endif
500 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
501 MAYBE_MediaGalleriesNoAccess) {
502 MakeSingleFakeGallery(NULL);
504 base::ListValue custom_args;
505 custom_args.AppendInteger(num_galleries() + 1);
507 ASSERT_TRUE(RunMediaGalleriesTestWithArg("no_access", custom_args))
508 << message_;
511 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, NoGalleriesRead) {
512 ASSERT_TRUE(RunMediaGalleriesTest("no_galleries")) << message_;
515 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
516 NoGalleriesCopyTo) {
517 ASSERT_TRUE(RunMediaGalleriesTest("no_galleries_copy_to")) << message_;
520 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
521 MediaGalleriesRead) {
522 RemoveAllGalleries();
523 MakeSingleFakeGallery(NULL);
524 base::ListValue custom_args;
525 custom_args.AppendInteger(test_jpg_size());
527 ASSERT_TRUE(RunMediaGalleriesTestWithArg("read_access", custom_args))
528 << message_;
531 // Test is flaky, it fails on certain bots, namely WinXP Tests(1) and Linux
532 // (dbg)(1)(32). See crbug.com/354425.
533 #if defined(OS_WIN) || defined(OS_LINUX)
534 #define MAYBE_MediaGalleriesCopyTo DISABLED_MediaGalleriesCopyTo
535 #else
536 #define MAYBE_MediaGalleriesCopyTo MediaGalleriesCopyTo
537 #endif
538 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
539 MAYBE_MediaGalleriesCopyTo) {
540 RemoveAllGalleries();
541 MakeSingleFakeGallery(NULL);
542 ASSERT_TRUE(RunMediaGalleriesTest("copy_to_access")) << message_;
545 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
546 MediaGalleriesDelete) {
547 MakeSingleFakeGallery(NULL);
548 base::ListValue custom_args;
549 custom_args.AppendInteger(num_galleries() + 1);
550 ASSERT_TRUE(RunMediaGalleriesTestWithArg("delete_access", custom_args))
551 << message_;
554 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
555 MediaGalleriesAccessAttached) {
556 AttachFakeDevice();
558 base::ListValue custom_args;
559 custom_args.AppendInteger(num_galleries() + 1);
560 custom_args.AppendString(kDeviceName);
562 ASSERT_TRUE(RunMediaGalleriesTestWithArg("access_attached", custom_args))
563 << message_;
565 DetachFakeDevice();
568 #if defined(OS_WIN)|| defined(OS_MACOSX)
569 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
570 PicasaDefaultLocation) {
571 #if defined(OS_WIN)
572 PopulatePicasaTestData(
573 ensure_media_directories_exists()->GetFakeLocalAppDataPath());
574 #elif defined(OS_MACOSX)
575 PopulatePicasaTestData(
576 ensure_media_directories_exists()->GetFakeAppDataPath());
577 #endif
579 base::ListValue custom_args;
580 custom_args.AppendInteger(test_jpg_size());
581 ASSERT_TRUE(RunMediaGalleriesTestWithArg("picasa", custom_args)) << message_;
584 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
585 PicasaCustomLocation) {
586 base::ScopedTempDir custom_picasa_app_data_root;
587 ASSERT_TRUE(custom_picasa_app_data_root.CreateUniqueTempDir());
588 ensure_media_directories_exists()->SetCustomPicasaAppDataPath(
589 custom_picasa_app_data_root.path());
590 PopulatePicasaTestData(custom_picasa_app_data_root.path());
592 base::ListValue custom_args;
593 custom_args.AppendInteger(test_jpg_size());
594 ASSERT_TRUE(RunMediaGalleriesTestWithArg("picasa", custom_args)) << message_;
596 #endif // defined(OS_WIN) || defined(OS_MACOSX)
598 #if defined(OS_MACOSX)
599 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
600 IPhotoTest) {
601 PopulateIPhotoTestData(
602 ensure_media_directories_exists()->GetFakeIPhotoRootPath());
604 base::ListValue custom_args;
605 custom_args.AppendInteger(test_jpg_size());
606 ASSERT_TRUE(RunMediaGalleriesTestWithArg("iphoto", custom_args)) << message_;
608 iapps::SetMacPreferencesForTesting(NULL);
610 #endif // defined(OS_MACOSX)
612 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, CancelScan) {
613 InstallDoNothingFolderFinder();
614 ASSERT_TRUE(RunMediaGalleriesTest("cancel_scan")) << message_;
617 // Flaky time outs on MSAN. https://crbug.com/503329
618 #if defined(MEMORY_SANITIZER)
619 #define MAYBE_Scan DISABLED_Scan
620 #else
621 #define MAYBE_Scan Scan
622 #endif
623 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, MAYBE_Scan) {
624 base::ScopedTempDir scan_root;
625 ASSERT_TRUE(scan_root.CreateUniqueTempDir());
626 std::vector<base::FilePath> roots;
627 roots.push_back(scan_root.path());
628 SetRootsForFolderFinder(roots);
630 // Override addScanResults so that the dialog is accepted as soon as it is
631 // created.
632 ASSERT_TRUE(extensions::ExtensionFunctionDispatcher::OverrideFunction(
633 "mediaGalleries.addScanResults",
634 &TestMediaGalleriesAddScanResultsFunction::Factory));
636 // Add some files and directories to the scan root for testing. Only the
637 // "f" directory should be found.
638 std::string dummy_data;
639 dummy_data.resize(1);
640 ASSERT_TRUE(base::CreateDirectory(scan_root.path().AppendASCII("a/b")));
641 ASSERT_EQ(static_cast<int>(dummy_data.size()),
642 base::WriteFile(scan_root.path().AppendASCII("a/b/c.jpg"),
643 dummy_data.c_str(), dummy_data.size()));
644 ASSERT_TRUE(base::CreateDirectory(scan_root.path().AppendASCII("a/d")));
645 dummy_data.resize(201 * 1024); // 200k is the min size for the folder finder.
646 ASSERT_EQ(static_cast<int>(dummy_data.size()),
647 base::WriteFile(scan_root.path().AppendASCII("a/d/e.txt"),
648 dummy_data.c_str(), dummy_data.size()));
649 ASSERT_TRUE(base::CreateDirectory(scan_root.path().AppendASCII("f")));
650 ASSERT_EQ(static_cast<int>(dummy_data.size()),
651 base::WriteFile(scan_root.path().AppendASCII("f/g.jpg"),
652 dummy_data.c_str(), dummy_data.size()));
654 ASSERT_TRUE(RunMediaGalleriesTest("scan")) << message_;
657 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, ToURL) {
658 RemoveAllGalleries();
659 MediaGalleryPrefId pref_id;
660 MakeSingleFakeGallery(&pref_id);
662 base::ListValue custom_args;
663 custom_args.AppendInteger(base::checked_cast<int>(pref_id));
664 custom_args.AppendString(
665 browser()->profile()->GetPath().BaseName().MaybeAsASCII());
667 ASSERT_TRUE(RunMediaGalleriesTestWithArg("tourl", custom_args)) << message_;
670 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, GetMetadata) {
671 RemoveAllGalleries();
672 MakeSingleFakeGallery(NULL);
674 AddFileToSingleFakeGallery(media::GetTestDataFilePath("90rotation.mp4"));
675 AddFileToSingleFakeGallery(media::GetTestDataFilePath("id3_png_test.mp3"));
676 AddFileToSingleFakeGallery(GetWallpaperTestDataDir().AppendASCII("test.jpg"));
678 base::ListValue custom_args;
679 #if defined(USE_PROPRIETARY_CODECS)
680 custom_args.AppendBoolean(true);
681 #else
682 custom_args.AppendBoolean(false);
683 #endif
684 ASSERT_TRUE(RunMediaGalleriesTestWithArg("media_metadata", custom_args))
685 << message_;