Chromium Code Reviews| 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/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 Loading... | |
| 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) { |
|
Lei Zhang
2014/03/20 21:37:53
Why not just return the 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 414 } | 417 } |
| 415 | 418 |
| 416 std::string device_id_; | 419 std::string device_id_; |
| 417 base::ScopedTempDir fake_gallery_temp_dir_; | 420 base::ScopedTempDir fake_gallery_temp_dir_; |
| 418 int test_jpg_size_; | 421 int test_jpg_size_; |
| 419 scoped_ptr<EnsureMediaDirectoriesExists> ensure_media_directories_exists_; | 422 scoped_ptr<EnsureMediaDirectoriesExists> ensure_media_directories_exists_; |
| 420 }; | 423 }; |
| 421 | 424 |
| 422 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, | 425 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, |
| 423 MediaGalleriesNoAccess) { | 426 MediaGalleriesNoAccess) { |
| 424 MakeSingleFakeGallery(); | 427 MakeSingleFakeGallery(NULL); |
| 425 | 428 |
| 426 base::ListValue custom_args; | 429 base::ListValue custom_args; |
| 427 custom_args.AppendInteger(num_galleries() + 1); | 430 custom_args.AppendInteger(num_galleries() + 1); |
| 428 | 431 |
| 429 ASSERT_TRUE(RunMediaGalleriesTestWithArg("no_access", custom_args)) | 432 ASSERT_TRUE(RunMediaGalleriesTestWithArg("no_access", custom_args)) |
| 430 << message_; | 433 << message_; |
| 431 } | 434 } |
| 432 | 435 |
| 433 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, NoGalleriesRead) { | 436 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, NoGalleriesRead) { |
| 434 ASSERT_TRUE(RunMediaGalleriesTest("no_galleries")) << message_; | 437 ASSERT_TRUE(RunMediaGalleriesTest("no_galleries")) << message_; |
| 435 } | 438 } |
| 436 | 439 |
| 437 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, | 440 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, |
| 438 NoGalleriesCopyTo) { | 441 NoGalleriesCopyTo) { |
| 439 ASSERT_TRUE(RunMediaGalleriesTest("no_galleries_copy_to")) << message_; | 442 ASSERT_TRUE(RunMediaGalleriesTest("no_galleries_copy_to")) << message_; |
| 440 } | 443 } |
| 441 | 444 |
| 442 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, | 445 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, |
| 443 MediaGalleriesRead) { | 446 MediaGalleriesRead) { |
| 444 RemoveAllGalleries(); | 447 RemoveAllGalleries(); |
| 445 MakeSingleFakeGallery(); | 448 MakeSingleFakeGallery(NULL); |
| 446 base::ListValue custom_args; | 449 base::ListValue custom_args; |
| 447 custom_args.AppendInteger(test_jpg_size()); | 450 custom_args.AppendInteger(test_jpg_size()); |
| 448 | 451 |
| 449 ASSERT_TRUE(RunMediaGalleriesTestWithArg("read_access", custom_args)) | 452 ASSERT_TRUE(RunMediaGalleriesTestWithArg("read_access", custom_args)) |
| 450 << message_; | 453 << message_; |
| 451 } | 454 } |
| 452 | 455 |
| 453 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, | 456 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, |
| 454 MediaGalleriesCopyTo) { | 457 MediaGalleriesCopyTo) { |
| 455 RemoveAllGalleries(); | 458 RemoveAllGalleries(); |
| 456 MakeSingleFakeGallery(); | 459 MakeSingleFakeGallery(NULL); |
| 457 ASSERT_TRUE(RunMediaGalleriesTest("copy_to_access")) << message_; | 460 ASSERT_TRUE(RunMediaGalleriesTest("copy_to_access")) << message_; |
| 458 } | 461 } |
| 459 | 462 |
| 460 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, | 463 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, |
| 461 MediaGalleriesDelete) { | 464 MediaGalleriesDelete) { |
| 462 MakeSingleFakeGallery(); | 465 MakeSingleFakeGallery(NULL); |
| 463 base::ListValue custom_args; | 466 base::ListValue custom_args; |
| 464 custom_args.AppendInteger(num_galleries() + 1); | 467 custom_args.AppendInteger(num_galleries() + 1); |
| 465 ASSERT_TRUE(RunMediaGalleriesTestWithArg("delete_access", custom_args)) | 468 ASSERT_TRUE(RunMediaGalleriesTestWithArg("delete_access", custom_args)) |
| 466 << message_; | 469 << message_; |
| 467 } | 470 } |
| 468 | 471 |
| 469 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, | 472 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, |
| 470 MediaGalleriesAccessAttached) { | 473 MediaGalleriesAccessAttached) { |
| 471 AttachFakeDevice(); | 474 AttachFakeDevice(); |
| 472 | 475 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 564 base::WriteFile(scan_root.path().AppendASCII("a/d/e.txt"), | 567 base::WriteFile(scan_root.path().AppendASCII("a/d/e.txt"), |
| 565 dummy_data.c_str(), dummy_data.size())); | 568 dummy_data.c_str(), dummy_data.size())); |
| 566 ASSERT_TRUE(base::CreateDirectory(scan_root.path().AppendASCII("f"))); | 569 ASSERT_TRUE(base::CreateDirectory(scan_root.path().AppendASCII("f"))); |
| 567 ASSERT_EQ(static_cast<int>(dummy_data.size()), | 570 ASSERT_EQ(static_cast<int>(dummy_data.size()), |
| 568 base::WriteFile(scan_root.path().AppendASCII("f/g.jpg"), | 571 base::WriteFile(scan_root.path().AppendASCII("f/g.jpg"), |
| 569 dummy_data.c_str(), dummy_data.size())); | 572 dummy_data.c_str(), dummy_data.size())); |
| 570 | 573 |
| 571 ASSERT_TRUE(RunMediaGalleriesTest("scan")) << message_; | 574 ASSERT_TRUE(RunMediaGalleriesTest("scan")) << message_; |
| 572 } | 575 } |
| 573 | 576 |
| 577 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, ToURL) { | |
| 578 RemoveAllGalleries(); | |
| 579 MediaGalleryPrefId pref_id; | |
| 580 MakeSingleFakeGallery(&pref_id); | |
|
Lei Zhang
2014/03/20 21:37:53
assert |pref_id| is not kInvalidMediaGalleryPrefId
| |
| 581 | |
| 582 base::ListValue custom_args; | |
| 583 custom_args.AppendInteger(base::checked_cast<int>(pref_id)); | |
| 584 | |
| 585 ASSERT_TRUE(RunMediaGalleriesTestWithArg("tourl", custom_args)) << message_; | |
| 586 } | |
| 587 | |
| 574 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, GetMetadata) { | 588 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, GetMetadata) { |
| 575 RemoveAllGalleries(); | 589 RemoveAllGalleries(); |
| 576 MakeSingleFakeGallery(); | 590 MakeSingleFakeGallery(NULL); |
| 577 | 591 |
| 578 AddFileToSingleFakeGallery(media::GetTestDataFilePath("90rotation.mp4")); | 592 AddFileToSingleFakeGallery(media::GetTestDataFilePath("90rotation.mp4")); |
| 579 AddFileToSingleFakeGallery(media::GetTestDataFilePath("id3_png_test.mp3")); | 593 AddFileToSingleFakeGallery(media::GetTestDataFilePath("id3_png_test.mp3")); |
| 580 | 594 |
| 581 base::ListValue custom_args; | 595 base::ListValue custom_args; |
| 582 #if defined(USE_PROPRIETARY_CODECS) | 596 #if defined(USE_PROPRIETARY_CODECS) |
| 583 custom_args.AppendBoolean(true); | 597 custom_args.AppendBoolean(true); |
| 584 #else | 598 #else |
| 585 custom_args.AppendBoolean(false); | 599 custom_args.AppendBoolean(false); |
| 586 #endif | 600 #endif |
| 587 ASSERT_TRUE(RunMediaGalleriesTestWithArg("media_metadata", custom_args)) | 601 ASSERT_TRUE(RunMediaGalleriesTestWithArg("media_metadata", custom_args)) |
| 588 << message_; | 602 << message_; |
| 589 } | 603 } |
| OLD | NEW |