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

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

Issue 185393012: Change media galleries to external file system type to add toURL support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 8 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
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/callback.h" 6 #include "base/callback.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/numerics/safe_conversions.h" 10 #include "base/numerics/safe_conversions.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 preferences->known_galleries(); 188 preferences->known_galleries();
189 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); 189 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin();
190 it != galleries.end(); ++it) { 190 it != galleries.end(); ++it) {
191 preferences->ForgetGalleryById(it->first); 191 preferences->ForgetGalleryById(it->first);
192 } 192 }
193 } 193 }
194 194
195 // This function makes a single fake gallery. This is needed to test platforms 195 // This function makes a single fake gallery. This is needed to test platforms
196 // with no default media galleries, such as CHROMEOS. This fake gallery is 196 // with no default media galleries, such as CHROMEOS. This fake gallery is
197 // pre-populated with a test.jpg and test.txt. 197 // pre-populated with a test.jpg and test.txt.
198 void MakeSingleFakeGallery() { 198 void MakeSingleFakeGallery(MediaGalleryPrefId* pref_id) {
199 ASSERT_FALSE(fake_gallery_temp_dir_.IsValid()); 199 ASSERT_FALSE(fake_gallery_temp_dir_.IsValid());
200 ASSERT_TRUE(fake_gallery_temp_dir_.CreateUniqueTempDir()); 200 ASSERT_TRUE(fake_gallery_temp_dir_.CreateUniqueTempDir());
201 201
202 MediaGalleriesPreferences* preferences = GetAndInitializePreferences(); 202 MediaGalleriesPreferences* preferences = GetAndInitializePreferences();
203 203
204 MediaGalleryPrefInfo gallery_info; 204 MediaGalleryPrefInfo gallery_info;
205 ASSERT_FALSE(preferences->LookUpGalleryByPath(fake_gallery_temp_dir_.path(), 205 ASSERT_FALSE(preferences->LookUpGalleryByPath(fake_gallery_temp_dir_.path(),
206 &gallery_info)); 206 &gallery_info));
207 preferences->AddGallery(gallery_info.device_id, 207 MediaGalleryPrefId id = preferences->AddGallery(
208 gallery_info.path, 208 gallery_info.device_id,
209 MediaGalleryPrefInfo::kAutoDetected, 209 gallery_info.path,
210 gallery_info.volume_label, 210 MediaGalleryPrefInfo::kAutoDetected,
211 gallery_info.vendor_name, 211 gallery_info.volume_label,
212 gallery_info.model_name, 212 gallery_info.vendor_name,
213 gallery_info.total_size_in_bytes, 213 gallery_info.model_name,
214 gallery_info.last_attach_time, 214 gallery_info.total_size_in_bytes,
215 0, 0, 0); 215 gallery_info.last_attach_time,
216 0, 0, 0);
217 if (pref_id)
218 *pref_id = id;
216 219
217 content::RunAllPendingInMessageLoop(); 220 content::RunAllPendingInMessageLoop();
218 221
219 // Valid file, should show up in JS as a FileEntry. 222 // Valid file, should show up in JS as a FileEntry.
220 AddFileToSingleFakeGallery(GetCommonDataDir().AppendASCII("test.jpg")); 223 AddFileToSingleFakeGallery(GetCommonDataDir().AppendASCII("test.jpg"));
221 224
222 // Invalid file, should not show up as a FileEntry in JS at all. 225 // Invalid file, should not show up as a FileEntry in JS at all.
223 AddFileToSingleFakeGallery(GetCommonDataDir().AppendASCII("test.txt")); 226 AddFileToSingleFakeGallery(GetCommonDataDir().AppendASCII("test.txt"));
224 } 227 }
225 228
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 }; 423 };
421 424
422 // Flaky on WinXP Tests(1): http://crbug.com/354425 425 // Flaky on WinXP Tests(1): http://crbug.com/354425
423 #if defined(OS_WIN) && defined(ARCH_CPU_X86) 426 #if defined(OS_WIN) && defined(ARCH_CPU_X86)
424 #define MAYBE_MediaGalleriesNoAccess DISABLED_MediaGalleriesNoAccess 427 #define MAYBE_MediaGalleriesNoAccess DISABLED_MediaGalleriesNoAccess
425 #else 428 #else
426 #define MAYBE_MediaGalleriesNoAccess MediaGalleriesNoAccess 429 #define MAYBE_MediaGalleriesNoAccess MediaGalleriesNoAccess
427 #endif 430 #endif
428 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, 431 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
429 MAYBE_MediaGalleriesNoAccess) { 432 MAYBE_MediaGalleriesNoAccess) {
430 MakeSingleFakeGallery(); 433 MakeSingleFakeGallery(NULL);
431 434
432 base::ListValue custom_args; 435 base::ListValue custom_args;
433 custom_args.AppendInteger(num_galleries() + 1); 436 custom_args.AppendInteger(num_galleries() + 1);
434 437
435 ASSERT_TRUE(RunMediaGalleriesTestWithArg("no_access", custom_args)) 438 ASSERT_TRUE(RunMediaGalleriesTestWithArg("no_access", custom_args))
436 << message_; 439 << message_;
437 } 440 }
438 441
439 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, NoGalleriesRead) { 442 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, NoGalleriesRead) {
440 ASSERT_TRUE(RunMediaGalleriesTest("no_galleries")) << message_; 443 ASSERT_TRUE(RunMediaGalleriesTest("no_galleries")) << message_;
441 } 444 }
442 445
443 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, 446 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
444 NoGalleriesCopyTo) { 447 NoGalleriesCopyTo) {
445 ASSERT_TRUE(RunMediaGalleriesTest("no_galleries_copy_to")) << message_; 448 ASSERT_TRUE(RunMediaGalleriesTest("no_galleries_copy_to")) << message_;
446 } 449 }
447 450
448 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, 451 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
449 MediaGalleriesRead) { 452 MediaGalleriesRead) {
450 RemoveAllGalleries(); 453 RemoveAllGalleries();
451 MakeSingleFakeGallery(); 454 MakeSingleFakeGallery(NULL);
452 base::ListValue custom_args; 455 base::ListValue custom_args;
453 custom_args.AppendInteger(test_jpg_size()); 456 custom_args.AppendInteger(test_jpg_size());
454 457
455 ASSERT_TRUE(RunMediaGalleriesTestWithArg("read_access", custom_args)) 458 ASSERT_TRUE(RunMediaGalleriesTestWithArg("read_access", custom_args))
456 << message_; 459 << message_;
457 } 460 }
458 461
459 // Test is flaky, it fails only on a certain bot, namely WinXP Tests(1). 462 // Test is flaky, it fails only on a certain bot, namely WinXP Tests(1).
460 // See crbug.com/354425 . 463 // See crbug.com/354425 .
461 #if defined(OS_WIN) && defined(ARCH_CPU_X86) 464 #if defined(OS_WIN) && defined(ARCH_CPU_X86)
462 #define MAYBE_MediaGalleriesCopyTo DISABLED_MediaGalleriesCopyTo 465 #define MAYBE_MediaGalleriesCopyTo DISABLED_MediaGalleriesCopyTo
463 #else 466 #else
464 #define MAYBE_MediaGalleriesCopyTo MediaGalleriesCopyTo 467 #define MAYBE_MediaGalleriesCopyTo MediaGalleriesCopyTo
465 #endif 468 #endif
466 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, 469 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
467 MAYBE_MediaGalleriesCopyTo) { 470 MAYBE_MediaGalleriesCopyTo) {
468 RemoveAllGalleries(); 471 RemoveAllGalleries();
469 MakeSingleFakeGallery(); 472 MakeSingleFakeGallery(NULL);
470 ASSERT_TRUE(RunMediaGalleriesTest("copy_to_access")) << message_; 473 ASSERT_TRUE(RunMediaGalleriesTest("copy_to_access")) << message_;
471 } 474 }
472 475
473 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, 476 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
474 MediaGalleriesDelete) { 477 MediaGalleriesDelete) {
475 MakeSingleFakeGallery(); 478 MakeSingleFakeGallery(NULL);
476 base::ListValue custom_args; 479 base::ListValue custom_args;
477 custom_args.AppendInteger(num_galleries() + 1); 480 custom_args.AppendInteger(num_galleries() + 1);
478 ASSERT_TRUE(RunMediaGalleriesTestWithArg("delete_access", custom_args)) 481 ASSERT_TRUE(RunMediaGalleriesTestWithArg("delete_access", custom_args))
479 << message_; 482 << message_;
480 } 483 }
481 484
482 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, 485 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
483 MediaGalleriesAccessAttached) { 486 MediaGalleriesAccessAttached) {
484 AttachFakeDevice(); 487 AttachFakeDevice();
485 488
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 base::WriteFile(scan_root.path().AppendASCII("a/d/e.txt"), 580 base::WriteFile(scan_root.path().AppendASCII("a/d/e.txt"),
578 dummy_data.c_str(), dummy_data.size())); 581 dummy_data.c_str(), dummy_data.size()));
579 ASSERT_TRUE(base::CreateDirectory(scan_root.path().AppendASCII("f"))); 582 ASSERT_TRUE(base::CreateDirectory(scan_root.path().AppendASCII("f")));
580 ASSERT_EQ(static_cast<int>(dummy_data.size()), 583 ASSERT_EQ(static_cast<int>(dummy_data.size()),
581 base::WriteFile(scan_root.path().AppendASCII("f/g.jpg"), 584 base::WriteFile(scan_root.path().AppendASCII("f/g.jpg"),
582 dummy_data.c_str(), dummy_data.size())); 585 dummy_data.c_str(), dummy_data.size()));
583 586
584 ASSERT_TRUE(RunMediaGalleriesTest("scan")) << message_; 587 ASSERT_TRUE(RunMediaGalleriesTest("scan")) << message_;
585 } 588 }
586 589
590 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, ToURL) {
591 RemoveAllGalleries();
592 MediaGalleryPrefId pref_id;
593 MakeSingleFakeGallery(&pref_id);
594
595 base::ListValue custom_args;
596 custom_args.AppendInteger(base::checked_cast<int>(pref_id));
597 custom_args.AppendString(
598 browser()->profile()->GetPath().BaseName().MaybeAsASCII());
599
600 ASSERT_TRUE(RunMediaGalleriesTestWithArg("tourl", custom_args)) << message_;
601 }
602
587 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, GetMetadata) { 603 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, GetMetadata) {
588 RemoveAllGalleries(); 604 RemoveAllGalleries();
589 MakeSingleFakeGallery(); 605 MakeSingleFakeGallery(NULL);
590 606
591 AddFileToSingleFakeGallery(media::GetTestDataFilePath("90rotation.mp4")); 607 AddFileToSingleFakeGallery(media::GetTestDataFilePath("90rotation.mp4"));
592 AddFileToSingleFakeGallery(media::GetTestDataFilePath("id3_png_test.mp3")); 608 AddFileToSingleFakeGallery(media::GetTestDataFilePath("id3_png_test.mp3"));
593 609
594 base::ListValue custom_args; 610 base::ListValue custom_args;
595 #if defined(USE_PROPRIETARY_CODECS) 611 #if defined(USE_PROPRIETARY_CODECS)
596 custom_args.AppendBoolean(true); 612 custom_args.AppendBoolean(true);
597 #else 613 #else
598 custom_args.AppendBoolean(false); 614 custom_args.AppendBoolean(false);
599 #endif 615 #endif
600 ASSERT_TRUE(RunMediaGalleriesTestWithArg("media_metadata", custom_args)) 616 ASSERT_TRUE(RunMediaGalleriesTestWithArg("media_metadata", custom_args))
601 << message_; 617 << message_;
602 } 618 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698