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/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_dialog_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/common/chrome_paths.h"
25 #include "components/storage_monitor/storage_info.h"
26 #include "components/storage_monitor/storage_monitor.h"
27 #include "content/public/browser/web_contents.h"
28 #include "content/public/test/test_utils.h"
29 #include "extensions/browser/extension_system.h"
30 #include "extensions/common/extension.h"
31 #include "media/base/test_data_util.h"
33 #if defined(OS_WIN) || defined(OS_MACOSX)
34 #include "chrome/browser/media_galleries/fileapi/picasa_finder.h"
35 #include "chrome/common/media_galleries/picasa_test_util.h"
36 #include "chrome/common/media_galleries/picasa_types.h"
37 #include "chrome/common/media_galleries/pmp_test_util.h"
40 #if defined(OS_MACOSX)
41 #include "base/mac/foundation_util.h"
42 #include "base/strings/sys_string_conversions.h"
43 #include "chrome/browser/media_galleries/fileapi/iapps_finder_impl.h"
46 #if !defined(DISABLE_NACL)
47 #include "base/command_line.h"
48 #include "chrome/browser/ui/extensions/application_launch.h"
49 #include "ppapi/shared_impl/ppapi_switches.h"
52 using extensions::PlatformAppBrowserTest;
53 using storage_monitor::StorageInfo;
54 using storage_monitor::StorageMonitor;
58 // Dummy device properties.
59 const char kDeviceId[] = "testDeviceId";
60 const char kDeviceName[] = "foobar";
61 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
62 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("C:\\qux");
64 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("/qux");
67 class DoNothingMediaFolderFinder : public MediaFolderFinder {
69 explicit DoNothingMediaFolderFinder(
70 const MediaFolderFinderResultsCallback& callback)
71 : MediaFolderFinder(callback) {
73 virtual ~DoNothingMediaFolderFinder() {}
75 static MediaFolderFinder* CreateDoNothingMediaFolderFinder(
76 const MediaFolderFinderResultsCallback& callback) {
77 return new DoNothingMediaFolderFinder(callback);
80 virtual void StartScan() OVERRIDE {}
87 class TestMediaGalleriesAddScanResultsFunction
88 : public extensions::MediaGalleriesAddScanResultsFunction {
90 static ExtensionFunction* Factory() {
91 return new TestMediaGalleriesAddScanResultsFunction;
95 virtual ~TestMediaGalleriesAddScanResultsFunction() {}
97 // Accepts the dialog as soon as it is created.
98 virtual MediaGalleriesScanResultDialogController* MakeDialog(
99 content::WebContents* web_contents,
100 const extensions::Extension& extension,
101 const base::Closure& on_finish) OVERRIDE {
102 MediaGalleriesScanResultDialogController* controller =
103 extensions::MediaGalleriesAddScanResultsFunction::MakeDialog(
104 web_contents, extension, on_finish);
105 controller->dialog_->AcceptDialogForTesting();
106 // The dialog is closing or closed so don't return it.
111 class MediaGalleriesPlatformAppBrowserTest : public PlatformAppBrowserTest {
113 MediaGalleriesPlatformAppBrowserTest() : test_jpg_size_(0) {}
114 virtual ~MediaGalleriesPlatformAppBrowserTest() {}
116 virtual void SetUpOnMainThread() OVERRIDE {
117 PlatformAppBrowserTest::SetUpOnMainThread();
118 ensure_media_directories_exists_.reset(new EnsureMediaDirectoriesExists);
121 ASSERT_TRUE(base::GetFileSize(GetCommonDataDir().AppendASCII("test.jpg"),
123 test_jpg_size_ = base::checked_cast<int>(file_size);
126 virtual void TearDownOnMainThread() OVERRIDE {
127 ensure_media_directories_exists_.reset();
128 PlatformAppBrowserTest::TearDownOnMainThread();
131 bool RunMediaGalleriesTest(const std::string& extension_name) {
132 base::ListValue empty_list_value;
133 return RunMediaGalleriesTestWithArg(extension_name, empty_list_value);
136 bool RunMediaGalleriesTestWithArg(const std::string& extension_name,
137 const base::ListValue& custom_arg_value) {
138 // Copy the test data for this test into a temporary directory. Then add
139 // a common_injected.js to the temporary copy and run it.
140 const char kTestDir[] = "api_test/media_galleries/";
141 base::FilePath from_dir =
142 test_data_dir_.AppendASCII(kTestDir + extension_name);
143 from_dir = from_dir.NormalizePathSeparators();
145 base::ScopedTempDir temp_dir;
146 if (!temp_dir.CreateUniqueTempDir())
149 if (!base::CopyDirectory(from_dir, temp_dir.path(), true))
152 base::FilePath common_js_path(
153 GetCommonDataDir().AppendASCII("common_injected.js"));
154 base::FilePath inject_js_path(
155 temp_dir.path().AppendASCII(extension_name)
156 .AppendASCII("common_injected.js"));
157 if (!base::CopyFile(common_js_path, inject_js_path))
160 const char* custom_arg = NULL;
161 std::string json_string;
162 if (!custom_arg_value.empty()) {
163 base::JSONWriter::Write(&custom_arg_value, &json_string);
164 custom_arg = json_string.c_str();
167 base::AutoReset<base::FilePath> reset(&test_data_dir_, temp_dir.path());
168 bool result = RunPlatformAppTestWithArg(extension_name, custom_arg);
169 content::RunAllPendingInMessageLoop(); // avoid race on exit in registry.
173 void AttachFakeDevice() {
174 device_id_ = StorageInfo::MakeDeviceId(
175 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId);
177 StorageMonitor::GetInstance()->receiver()->ProcessAttach(
178 StorageInfo(device_id_, kDevicePath, base::ASCIIToUTF16(kDeviceName),
179 base::string16(), base::string16(), 0));
180 content::RunAllPendingInMessageLoop();
183 void DetachFakeDevice() {
184 StorageMonitor::GetInstance()->receiver()->ProcessDetach(device_id_);
185 content::RunAllPendingInMessageLoop();
188 // Called if test only wants a single gallery it creates.
189 void RemoveAllGalleries() {
190 MediaGalleriesPreferences* preferences = GetAndInitializePreferences();
192 // Make a copy, as the iterator would be invalidated otherwise.
193 const MediaGalleriesPrefInfoMap galleries =
194 preferences->known_galleries();
195 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin();
196 it != galleries.end(); ++it) {
197 preferences->ForgetGalleryById(it->first);
201 // This function makes a single fake gallery. This is needed to test platforms
202 // with no default media galleries, such as CHROMEOS. This fake gallery is
203 // pre-populated with a test.jpg and test.txt.
204 void MakeSingleFakeGallery(MediaGalleryPrefId* pref_id) {
205 ASSERT_FALSE(fake_gallery_temp_dir_.IsValid());
206 ASSERT_TRUE(fake_gallery_temp_dir_.CreateUniqueTempDir());
208 MediaGalleriesPreferences* preferences = GetAndInitializePreferences();
210 MediaGalleryPrefInfo gallery_info;
211 ASSERT_FALSE(preferences->LookUpGalleryByPath(fake_gallery_temp_dir_.path(),
213 MediaGalleryPrefId id = preferences->AddGallery(
214 gallery_info.device_id,
216 MediaGalleryPrefInfo::kAutoDetected,
217 gallery_info.volume_label,
218 gallery_info.vendor_name,
219 gallery_info.model_name,
220 gallery_info.total_size_in_bytes,
221 gallery_info.last_attach_time,
226 content::RunAllPendingInMessageLoop();
228 // Valid file, should show up in JS as a FileEntry.
229 AddFileToSingleFakeGallery(GetCommonDataDir().AppendASCII("test.jpg"));
231 // Invalid file, should not show up as a FileEntry in JS at all.
232 AddFileToSingleFakeGallery(GetCommonDataDir().AppendASCII("test.txt"));
235 void AddFileToSingleFakeGallery(const base::FilePath& source_path) {
236 ASSERT_TRUE(fake_gallery_temp_dir_.IsValid());
238 ASSERT_TRUE(base::CopyFile(
240 fake_gallery_temp_dir_.path().Append(source_path.BaseName())));
243 #if defined(OS_WIN) || defined(OS_MACOSX)
244 void PopulatePicasaTestData(const base::FilePath& picasa_app_data_root) {
245 base::FilePath picasa_database_path =
246 picasa::MakePicasaDatabasePath(picasa_app_data_root);
247 base::FilePath picasa_temp_dir_path =
248 picasa_database_path.DirName().AppendASCII(picasa::kPicasaTempDirName);
249 ASSERT_TRUE(base::CreateDirectory(picasa_database_path));
250 ASSERT_TRUE(base::CreateDirectory(picasa_temp_dir_path));
252 // Create fake folder directories.
253 base::FilePath folders_root =
254 ensure_media_directories_exists_->GetFakePicasaFoldersRootPath();
255 base::FilePath fake_folder_1 = folders_root.AppendASCII("folder1");
256 base::FilePath fake_folder_2 = folders_root.AppendASCII("folder2");
257 ASSERT_TRUE(base::CreateDirectory(fake_folder_1));
258 ASSERT_TRUE(base::CreateDirectory(fake_folder_2));
260 // Write folder and album contents.
261 picasa::WriteTestAlbumTable(
262 picasa_database_path, fake_folder_1, fake_folder_2);
263 picasa::WriteTestAlbumsImagesIndex(fake_folder_1, fake_folder_2);
265 base::FilePath test_jpg_path = GetCommonDataDir().AppendASCII("test.jpg");
266 ASSERT_TRUE(base::CopyFile(
267 test_jpg_path, fake_folder_1.AppendASCII("InBoth.jpg")));
268 ASSERT_TRUE(base::CopyFile(
269 test_jpg_path, fake_folder_1.AppendASCII("InSecondAlbumOnly.jpg")));
270 ASSERT_TRUE(base::CopyFile(
271 test_jpg_path, fake_folder_2.AppendASCII("InFirstAlbumOnly.jpg")));
273 #endif // defined(OS_WIN) || defined(OS_MACOSX)
275 #if defined(OS_MACOSX)
276 void PopulateIPhotoTestData(const base::FilePath& iphoto_data_root) {
277 std::string xml_contents = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
278 "<plist version=\"1.0\">"
281 " <key>List of Albums</key>"
285 " <key>AlbumId</key>"
286 " <integer>1</integer>"
287 " <key>AlbumName</key>"
288 " <string>Album1</string>"
289 " <key>KeyList</key>\n"
291 " <string>1</string>"
292 " <string>2</string>"
297 " <key>AlbumId</key>"
298 " <integer>2</integer>"
299 " <key>AlbumName</key>"
300 " <string>Album2</string>"
301 " <key>KeyList</key>\n"
303 " <string>2</string>"
309 " <key>Master Image List</key>\n"
314 " <key>MediaType</key>"
315 " <string>Image</string>"
316 " <key>Caption</key>"
317 " <string>caption 1</string>"
319 " <string>1</string>"
320 " <key>ModDateAsTimerInterval</key>"
321 " <string>386221543.0000</string>"
322 " <key>DateAsTimerInterval</key>"
323 " <string>386221543.0000</string>"
324 " <key>DateAsTimerIntervalGMT</key>"
325 " <string>385123456.00</string>"
326 " <key>ImagePath</key>"
327 " <string>$path1</string>"
328 " <key>ThumbPath</key>"
329 " <string>/thumb/path</string>\n"
334 " <key>MediaType</key>"
335 " <string>Image</string>"
336 " <key>Caption</key>"
337 " <string>caption 2</string>"
339 " <string>2</string>"
340 " <key>ModDateAsTimerInterval</key>"
341 " <string>386221543.0000</string>"
342 " <key>DateAsTimerInterval</key>"
343 " <string>386221543.0000</string>"
344 " <key>DateAsTimerIntervalGMT</key>"
345 " <string>385123456.00</string>"
346 " <key>ImagePath</key>"
347 " <string>$path2</string>"
348 " <key>ThumbPath</key>"
349 " <string>/thumb/path2</string>\n"
352 " </dict>\n" // Master Image List
357 base::FilePath test_jpg_path = GetCommonDataDir().AppendASCII("test.jpg");
358 ASSERT_TRUE(base::CreateDirectory(iphoto_data_root));
359 base::FilePath first_only_jpg =
360 iphoto_data_root.AppendASCII("InFirstAlbumOnly.jpg");
361 base::FilePath in_both_jpg = iphoto_data_root.AppendASCII("InBoth.jpg");
362 ASSERT_TRUE(base::CopyFile(test_jpg_path, first_only_jpg));
363 ASSERT_TRUE(base::CopyFile(test_jpg_path, in_both_jpg));
364 ReplaceFirstSubstringAfterOffset(
365 &xml_contents, 0, std::string("$path1"), first_only_jpg.value());
366 ReplaceFirstSubstringAfterOffset(
367 &xml_contents, 0, std::string("$path2"), in_both_jpg.value());
369 base::FilePath album_xml = iphoto_data_root.AppendASCII("AlbumData.xml");
370 ASSERT_NE(-1, base::WriteFile(album_xml,
371 xml_contents.c_str(), xml_contents.size()));
373 #endif // defined(OS_MACOSX)
375 base::FilePath GetCommonDataDir() const {
376 return test_data_dir_.AppendASCII("api_test")
377 .AppendASCII("media_galleries")
378 .AppendASCII("common");
381 base::FilePath GetWallpaperTestDataDir() const {
382 return test_data_dir_.AppendASCII("api_test")
383 .AppendASCII("wallpaper");
386 int num_galleries() const {
387 return ensure_media_directories_exists_->num_galleries();
390 int test_jpg_size() const { return test_jpg_size_; }
392 EnsureMediaDirectoriesExists* ensure_media_directories_exists() const {
393 return ensure_media_directories_exists_.get();
396 void InstallDoNothingFolderFinder() {
397 MediaScanManager * scan_manager =
398 g_browser_process->media_file_system_registry()->media_scan_manager();
399 scan_manager->SetMediaFolderFinderFactory(base::Bind(
400 &DoNothingMediaFolderFinder::CreateDoNothingMediaFolderFinder));
403 void SetRootsForFolderFinder(const std::vector<base::FilePath>& roots) {
404 MediaScanManager* scan_manager =
405 g_browser_process->media_file_system_registry()->media_scan_manager();
406 scan_manager->SetMediaFolderFinderFactory(base::Bind(
407 &MediaGalleriesPlatformAppBrowserTest::CreateMediaFolderFinderWithRoots,
412 static MediaFolderFinder* CreateMediaFolderFinderWithRoots(
413 const std::vector<base::FilePath>& roots,
414 const MediaFolderFinder::MediaFolderFinderResultsCallback& callback) {
415 MediaFolderFinder* finder = new MediaFolderFinder(callback);
416 finder->SetRootsForTesting(roots);
420 MediaGalleriesPreferences* GetAndInitializePreferences() {
421 MediaGalleriesPreferences* preferences =
422 g_browser_process->media_file_system_registry()->GetPreferences(
423 browser()->profile());
424 base::RunLoop runloop;
425 preferences->EnsureInitialized(runloop.QuitClosure());
430 std::string device_id_;
431 base::ScopedTempDir fake_gallery_temp_dir_;
433 scoped_ptr<EnsureMediaDirectoriesExists> ensure_media_directories_exists_;
436 #if !defined(DISABLE_NACL)
437 class MediaGalleriesPlatformAppPpapiTest
438 : public MediaGalleriesPlatformAppBrowserTest {
440 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
441 MediaGalleriesPlatformAppBrowserTest::SetUpCommandLine(command_line);
442 command_line->AppendSwitch(switches::kEnablePepperTesting);
445 virtual void SetUpOnMainThread() OVERRIDE {
446 MediaGalleriesPlatformAppBrowserTest::SetUpOnMainThread();
448 ASSERT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, &app_dir_));
449 app_dir_ = app_dir_.AppendASCII("ppapi")
450 .AppendASCII("tests")
451 .AppendASCII("extensions")
452 .AppendASCII("media_galleries")
453 .AppendASCII("newlib");
456 const base::FilePath& app_dir() const {
461 base::FilePath app_dir_;
464 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppPpapiTest, SendFilesystem) {
465 RemoveAllGalleries();
466 MakeSingleFakeGallery(NULL);
468 const extensions::Extension* extension = LoadExtension(app_dir());
469 ASSERT_TRUE(extension);
471 ResultCatcher catcher;
472 AppLaunchParams params(browser()->profile(),
474 extensions::LAUNCH_CONTAINER_NONE,
476 params.command_line = *CommandLine::ForCurrentProcess();
477 OpenApplication(params);
480 if (!catcher.GetNextResult()) {
481 message_ = catcher.message();
484 content::RunAllPendingInMessageLoop(); // avoid race on exit in registry.
485 ASSERT_TRUE(result) << message_;
488 #endif // !defined(DISABLE_NACL)
490 // Test is flaky, it fails on certain bots, namely WinXP Tests(1) and Linux
491 // (dbg)(1)(32). See crbug.com/354425.
492 #if (defined(ARCH_CPU_X86)) && (defined(OS_WIN) || defined(OS_LINUX))
493 #define MAYBE_MediaGalleriesNoAccess DISABLED_MediaGalleriesNoAccess
495 #define MAYBE_MediaGalleriesNoAccess MediaGalleriesNoAccess
497 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
498 MAYBE_MediaGalleriesNoAccess) {
499 MakeSingleFakeGallery(NULL);
501 base::ListValue custom_args;
502 custom_args.AppendInteger(num_galleries() + 1);
504 ASSERT_TRUE(RunMediaGalleriesTestWithArg("no_access", custom_args))
508 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, NoGalleriesRead) {
509 ASSERT_TRUE(RunMediaGalleriesTest("no_galleries")) << message_;
512 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
514 ASSERT_TRUE(RunMediaGalleriesTest("no_galleries_copy_to")) << message_;
517 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
518 MediaGalleriesRead) {
519 RemoveAllGalleries();
520 MakeSingleFakeGallery(NULL);
521 base::ListValue custom_args;
522 custom_args.AppendInteger(test_jpg_size());
524 ASSERT_TRUE(RunMediaGalleriesTestWithArg("read_access", custom_args))
528 // Test is flaky, it fails on certain bots, namely WinXP Tests(1) and Linux
529 // (dbg)(1)(32). See crbug.com/354425.
530 #if (defined(ARCH_CPU_X86)) && (defined(OS_WIN) || defined(OS_LINUX))
531 #define MAYBE_MediaGalleriesCopyTo DISABLED_MediaGalleriesCopyTo
533 #define MAYBE_MediaGalleriesCopyTo MediaGalleriesCopyTo
535 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
536 MAYBE_MediaGalleriesCopyTo) {
537 RemoveAllGalleries();
538 MakeSingleFakeGallery(NULL);
539 ASSERT_TRUE(RunMediaGalleriesTest("copy_to_access")) << message_;
542 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
543 MediaGalleriesDelete) {
544 MakeSingleFakeGallery(NULL);
545 base::ListValue custom_args;
546 custom_args.AppendInteger(num_galleries() + 1);
547 ASSERT_TRUE(RunMediaGalleriesTestWithArg("delete_access", custom_args))
551 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
552 MediaGalleriesAccessAttached) {
555 base::ListValue custom_args;
556 custom_args.AppendInteger(num_galleries() + 1);
557 custom_args.AppendString(kDeviceName);
559 ASSERT_TRUE(RunMediaGalleriesTestWithArg("access_attached", custom_args))
565 #if defined(OS_WIN)|| defined(OS_MACOSX)
566 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
567 PicasaDefaultLocation) {
569 PopulatePicasaTestData(
570 ensure_media_directories_exists()->GetFakeLocalAppDataPath());
571 #elif defined(OS_MACOSX)
572 PopulatePicasaTestData(
573 ensure_media_directories_exists()->GetFakeAppDataPath());
576 base::ListValue custom_args;
577 custom_args.AppendInteger(test_jpg_size());
578 ASSERT_TRUE(RunMediaGalleriesTestWithArg("picasa", custom_args)) << message_;
581 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
582 PicasaCustomLocation) {
583 base::ScopedTempDir custom_picasa_app_data_root;
584 ASSERT_TRUE(custom_picasa_app_data_root.CreateUniqueTempDir());
585 ensure_media_directories_exists()->SetCustomPicasaAppDataPath(
586 custom_picasa_app_data_root.path());
587 PopulatePicasaTestData(custom_picasa_app_data_root.path());
589 base::ListValue custom_args;
590 custom_args.AppendInteger(test_jpg_size());
591 ASSERT_TRUE(RunMediaGalleriesTestWithArg("picasa", custom_args)) << message_;
593 #endif // defined(OS_WIN) || defined(OS_MACOSX)
595 #if defined(OS_MACOSX)
596 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
598 PopulateIPhotoTestData(
599 ensure_media_directories_exists()->GetFakeIPhotoRootPath());
601 base::ListValue custom_args;
602 custom_args.AppendInteger(test_jpg_size());
603 ASSERT_TRUE(RunMediaGalleriesTestWithArg("iphoto", custom_args)) << message_;
605 iapps::SetMacPreferencesForTesting(NULL);
607 #endif // defined(OS_MACOSX)
609 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, CancelScan) {
610 InstallDoNothingFolderFinder();
611 ASSERT_TRUE(RunMediaGalleriesTest("cancel_scan")) << message_;
614 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, Scan) {
615 base::ScopedTempDir scan_root;
616 ASSERT_TRUE(scan_root.CreateUniqueTempDir());
617 std::vector<base::FilePath> roots;
618 roots.push_back(scan_root.path());
619 SetRootsForFolderFinder(roots);
621 // Override addScanResults so that the dialog is accepted as soon as it is
623 ASSERT_TRUE(extensions::ExtensionFunctionDispatcher::OverrideFunction(
624 "mediaGalleries.addScanResults",
625 &TestMediaGalleriesAddScanResultsFunction::Factory));
627 // Add some files and directories to the scan root for testing. Only the
628 // "f" directory should be found.
629 std::string dummy_data;
630 dummy_data.resize(1);
631 ASSERT_TRUE(base::CreateDirectory(scan_root.path().AppendASCII("a/b")));
632 ASSERT_EQ(static_cast<int>(dummy_data.size()),
633 base::WriteFile(scan_root.path().AppendASCII("a/b/c.jpg"),
634 dummy_data.c_str(), dummy_data.size()));
635 ASSERT_TRUE(base::CreateDirectory(scan_root.path().AppendASCII("a/d")));
636 dummy_data.resize(201 * 1024); // 200k is the min size for the folder finder.
637 ASSERT_EQ(static_cast<int>(dummy_data.size()),
638 base::WriteFile(scan_root.path().AppendASCII("a/d/e.txt"),
639 dummy_data.c_str(), dummy_data.size()));
640 ASSERT_TRUE(base::CreateDirectory(scan_root.path().AppendASCII("f")));
641 ASSERT_EQ(static_cast<int>(dummy_data.size()),
642 base::WriteFile(scan_root.path().AppendASCII("f/g.jpg"),
643 dummy_data.c_str(), dummy_data.size()));
645 ASSERT_TRUE(RunMediaGalleriesTest("scan")) << message_;
648 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, ToURL) {
649 RemoveAllGalleries();
650 MediaGalleryPrefId pref_id;
651 MakeSingleFakeGallery(&pref_id);
653 base::ListValue custom_args;
654 custom_args.AppendInteger(base::checked_cast<int>(pref_id));
655 custom_args.AppendString(
656 browser()->profile()->GetPath().BaseName().MaybeAsASCII());
658 ASSERT_TRUE(RunMediaGalleriesTestWithArg("tourl", custom_args)) << message_;
661 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, GetMetadata) {
662 RemoveAllGalleries();
663 MakeSingleFakeGallery(NULL);
665 AddFileToSingleFakeGallery(media::GetTestDataFilePath("90rotation.mp4"));
666 AddFileToSingleFakeGallery(media::GetTestDataFilePath("id3_png_test.mp3"));
667 AddFileToSingleFakeGallery(GetWallpaperTestDataDir().AppendASCII("test.jpg"));
669 base::ListValue custom_args;
670 #if defined(USE_PROPRIETARY_CODECS)
671 custom_args.AppendBoolean(true);
673 custom_args.AppendBoolean(false);
675 ASSERT_TRUE(RunMediaGalleriesTestWithArg("media_metadata", custom_args))