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 // MediaFileSystemRegistry unit tests. | 5 // MediaFileSystemRegistry unit tests. |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> |
8 | 9 |
9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
10 #include "base/file_util.h" | 11 #include "base/file_util.h" |
11 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/json/json_reader.h" |
12 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
15 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
16 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
17 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
18 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
19 #include "base/values.h" | 21 #include "base/values.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/extensions/extension_system.h" | 23 #include "chrome/browser/extensions/extension_system.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 DCHECK(!path.ReferencesParent()); | 146 DCHECK(!path.ReferencesParent()); |
145 | 147 |
146 std::string fsid = base::StringPrintf("FSID:%d", ++fsid_); | 148 std::string fsid = base::StringPrintf("FSID:%d", ++fsid_); |
147 FSInfo info(device_id, path, fsid); | 149 FSInfo info(device_id, path, fsid); |
148 file_systems_by_id_[fsid] = info; | 150 file_systems_by_id_[fsid] = info; |
149 return fsid; | 151 return fsid; |
150 } | 152 } |
151 | 153 |
152 namespace { | 154 namespace { |
153 | 155 |
| 156 void GetGalleryNamesCallback( |
| 157 std::set<std::string>* results, |
| 158 const std::vector<MediaFileSystemInfo>& file_systems) { |
| 159 for (size_t i = 0; i < file_systems.size(); ++i) { |
| 160 ASSERT_FALSE(ContainsKey(*results, file_systems[i].name)); |
| 161 results->insert(file_systems[i].name); |
| 162 } |
| 163 } |
| 164 |
| 165 void CheckGalleryJSONName(const std::string& name, bool removable) { |
| 166 scoped_ptr<DictionaryValue> dict(static_cast<DictionaryValue*>( |
| 167 base::JSONReader::Read(name))); |
| 168 ASSERT_TRUE(dict); |
| 169 |
| 170 // Check deviceId. |
| 171 EXPECT_EQ(removable, |
| 172 dict->HasKey(MediaFileSystemRegistry::kDeviceIdKey)) << name; |
| 173 if (removable) { |
| 174 std::string device_id; |
| 175 EXPECT_TRUE(dict->GetString(MediaFileSystemRegistry::kDeviceIdKey, |
| 176 &device_id)) << name; |
| 177 EXPECT_FALSE(device_id.empty()) << name; |
| 178 } |
| 179 |
| 180 // Check galleryId. |
| 181 EXPECT_TRUE(dict->HasKey(MediaFileSystemRegistry::kGalleryIdKey)) << name; |
| 182 |
| 183 // Check name. |
| 184 EXPECT_TRUE(dict->HasKey(MediaFileSystemRegistry::kNameKey)) << name; |
| 185 std::string gallery_name; |
| 186 EXPECT_TRUE(dict->GetString(MediaFileSystemRegistry::kNameKey, |
| 187 &gallery_name)) << name; |
| 188 EXPECT_FALSE(gallery_name.empty()) << name; |
| 189 } |
| 190 |
154 class TestMediaStorageUtil : public MediaStorageUtil { | 191 class TestMediaStorageUtil : public MediaStorageUtil { |
155 public: | 192 public: |
156 static void SetTestingMode(); | 193 static void SetTestingMode(); |
157 | 194 |
158 static bool GetDeviceInfoFromPathTestFunction(const FilePath& path, | 195 static bool GetDeviceInfoFromPathTestFunction(const FilePath& path, |
159 std::string* device_id, | 196 std::string* device_id, |
160 string16* device_name, | 197 string16* device_name, |
161 FilePath* relative_path); | 198 FilePath* relative_path); |
162 }; | 199 }; |
163 | 200 |
(...skipping 25 matching lines...) Expand all Loading... |
189 MockProfileSharedRenderProcessHostFactory* rph_factory); | 226 MockProfileSharedRenderProcessHostFactory* rph_factory); |
190 ~ProfileState(); | 227 ~ProfileState(); |
191 | 228 |
192 MediaGalleriesPreferences* GetMediaGalleriesPrefs(); | 229 MediaGalleriesPreferences* GetMediaGalleriesPrefs(); |
193 | 230 |
194 void CheckGalleries( | 231 void CheckGalleries( |
195 const std::string& test, | 232 const std::string& test, |
196 const std::vector<MediaFileSystemInfo>& regular_extension_galleries, | 233 const std::vector<MediaFileSystemInfo>& regular_extension_galleries, |
197 const std::vector<MediaFileSystemInfo>& all_extension_galleries); | 234 const std::vector<MediaFileSystemInfo>& all_extension_galleries); |
198 | 235 |
| 236 std::set<std::string> GetGalleryNames(extensions::Extension* extension); |
| 237 |
199 extensions::Extension* all_permission_extension(); | 238 extensions::Extension* all_permission_extension(); |
200 extensions::Extension* regular_permission_extension(); | 239 extensions::Extension* regular_permission_extension(); |
201 | 240 |
202 private: | 241 private: |
203 void CompareResults(const std::string& test, | 242 void CompareResults(const std::string& test, |
204 const std::vector<MediaFileSystemInfo>& expected, | 243 const std::vector<MediaFileSystemInfo>& expected, |
205 const std::vector<MediaFileSystemInfo>& actual); | 244 const std::vector<MediaFileSystemInfo>& actual); |
206 | 245 |
207 int GetAndClearComparisonCount(); | 246 int GetAndClearComparisonCount(); |
208 | 247 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 295 |
257 void DetachDevice(const std::string& device_id); | 296 void DetachDevice(const std::string& device_id); |
258 | 297 |
259 void SetGalleryPermission(ProfileState* profile_state, | 298 void SetGalleryPermission(ProfileState* profile_state, |
260 extensions::Extension* extension, | 299 extensions::Extension* extension, |
261 const std::string& device_id, | 300 const std::string& device_id, |
262 bool has_access); | 301 bool has_access); |
263 | 302 |
264 void AssertAllAutoAddedGalleries(); | 303 void AssertAllAutoAddedGalleries(); |
265 | 304 |
| 305 void InitForGalleryNamesTest(std::set<std::string>* gallery_names); |
| 306 |
| 307 void CheckNewGallery(ProfileState* profile_state, |
| 308 const std::set<std::string>& gallery_names, |
| 309 bool removable); |
| 310 |
266 std::vector<MediaFileSystemInfo> GetAutoAddedGalleries( | 311 std::vector<MediaFileSystemInfo> GetAutoAddedGalleries( |
267 ProfileState* profile_state); | 312 ProfileState* profile_state); |
268 | 313 |
269 protected: | 314 protected: |
270 void SetUp(); | 315 void SetUp(); |
271 void TearDown(); | 316 void TearDown(); |
272 | 317 |
273 private: | 318 private: |
274 // This makes sure that at least one default gallery exists on the file | 319 // This makes sure that at least one default gallery exists on the file |
275 // system. | 320 // system. |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 // All galleries permission. | 491 // All galleries permission. |
447 registry->GetMediaFileSystemsForExtension( | 492 registry->GetMediaFileSystemsForExtension( |
448 rvh, all_permission_extension_.get(), | 493 rvh, all_permission_extension_.get(), |
449 base::Bind(&ProfileState::CompareResults, base::Unretained(this), | 494 base::Bind(&ProfileState::CompareResults, base::Unretained(this), |
450 StringPrintf("%s (all permission)", test.c_str()), | 495 StringPrintf("%s (all permission)", test.c_str()), |
451 base::ConstRef(all_extension_galleries))); | 496 base::ConstRef(all_extension_galleries))); |
452 MessageLoop::current()->RunUntilIdle(); | 497 MessageLoop::current()->RunUntilIdle(); |
453 EXPECT_EQ(1, GetAndClearComparisonCount()); | 498 EXPECT_EQ(1, GetAndClearComparisonCount()); |
454 } | 499 } |
455 | 500 |
| 501 std::set<std::string> ProfileState::GetGalleryNames( |
| 502 extensions::Extension* extension) { |
| 503 content::RenderViewHost* rvh = single_web_contents_->GetRenderViewHost(); |
| 504 std::set<std::string> results; |
| 505 MediaFileSystemRegistry* registry = |
| 506 g_browser_process->media_file_system_registry(); |
| 507 registry->GetMediaFileSystemsForExtension( |
| 508 rvh, extension, |
| 509 base::Bind(&GetGalleryNamesCallback, base::Unretained(&results))); |
| 510 MessageLoop::current()->RunUntilIdle(); |
| 511 return results; |
| 512 } |
| 513 |
456 extensions::Extension* ProfileState::all_permission_extension() { | 514 extensions::Extension* ProfileState::all_permission_extension() { |
457 return all_permission_extension_.get(); | 515 return all_permission_extension_.get(); |
458 } | 516 } |
459 | 517 |
460 extensions::Extension* ProfileState::regular_permission_extension() { | 518 extensions::Extension* ProfileState::regular_permission_extension() { |
461 return regular_permission_extension_.get(); | 519 return regular_permission_extension_.get(); |
462 } | 520 } |
463 | 521 |
464 void ProfileState::CompareResults( | 522 void ProfileState::CompareResults( |
465 const std::string& test, | 523 const std::string& test, |
466 const std::vector<MediaFileSystemInfo>& expected, | 524 const std::vector<MediaFileSystemInfo>& expected, |
467 const std::vector<MediaFileSystemInfo>& actual) { | 525 const std::vector<MediaFileSystemInfo>& actual) { |
468 // Order isn't important, so sort the results. Assume that expected | 526 // Order isn't important, so sort the results. Assume that expected |
469 // is already sorted. | 527 // is already sorted. |
470 std::vector<MediaFileSystemInfo> sorted(actual); | 528 std::vector<MediaFileSystemInfo> sorted(actual); |
471 std::sort(sorted.begin(), sorted.end(), MediaFileSystemInfoComparator); | 529 std::sort(sorted.begin(), sorted.end(), MediaFileSystemInfoComparator); |
472 | 530 |
473 num_comparisons_++; | 531 num_comparisons_++; |
474 ASSERT_EQ(expected.size(), actual.size()) << test; | 532 ASSERT_EQ(expected.size(), actual.size()) << test; |
475 for (size_t i = 0; i < expected.size() && i < actual.size(); i++) { | 533 for (size_t i = 0; i < expected.size() && i < actual.size(); ++i) { |
476 EXPECT_EQ(expected[i].path.value(), actual[i].path.value()) << test; | 534 EXPECT_EQ(expected[i].path.value(), actual[i].path.value()) << test; |
477 EXPECT_FALSE(actual[i].fsid.empty()) << test; | 535 EXPECT_FALSE(actual[i].fsid.empty()) << test; |
478 if (!expected[i].fsid.empty()) | 536 if (!expected[i].fsid.empty()) |
479 EXPECT_EQ(expected[i].fsid, actual[i].fsid) << test; | 537 EXPECT_EQ(expected[i].fsid, actual[i].fsid) << test; |
480 } | 538 } |
481 } | 539 } |
482 | 540 |
483 int ProfileState::GetAndClearComparisonCount() { | 541 int ProfileState::GetAndClearComparisonCount() { |
484 int result = num_comparisons_; | 542 int result = num_comparisons_; |
485 num_comparisons_ = 0; | 543 num_comparisons_ = 0; |
486 return result; | 544 return result; |
487 } | 545 } |
488 | 546 |
489 ///////////////////////////////// | 547 ///////////////////////////////// |
490 // MediaFileSystemRegistryTest // | 548 // MediaFileSystemRegistryTest // |
491 ///////////////////////////////// | 549 ///////////////////////////////// |
492 | 550 |
493 MediaFileSystemRegistryTest::MediaFileSystemRegistryTest() | 551 MediaFileSystemRegistryTest::MediaFileSystemRegistryTest() |
494 : ui_thread_(content::BrowserThread::UI, MessageLoop::current()), | 552 : ui_thread_(content::BrowserThread::UI, MessageLoop::current()), |
495 file_thread_(content::BrowserThread::FILE, MessageLoop::current()) { | 553 file_thread_(content::BrowserThread::FILE, MessageLoop::current()) { |
496 } | 554 } |
497 | 555 |
498 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) { | 556 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) { |
499 for (size_t i = 0; i < profile_count; i++) { | 557 for (size_t i = 0; i < profile_count; ++i) { |
500 ProfileState* state = new ProfileState(&rph_factory_); | 558 ProfileState* state = new ProfileState(&rph_factory_); |
501 profile_states_.push_back(state); | 559 profile_states_.push_back(state); |
502 } | 560 } |
503 } | 561 } |
504 | 562 |
505 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) { | 563 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) { |
506 return profile_states_[i]; | 564 return profile_states_[i]; |
507 } | 565 } |
508 | 566 |
509 std::string MediaFileSystemRegistryTest::AddUserGallery( | 567 std::string MediaFileSystemRegistryTest::AddUserGallery( |
510 MediaStorageUtil::Type type, | 568 MediaStorageUtil::Type type, |
511 const std::string& unique_id, | 569 const std::string& unique_id, |
512 const FilePath& path) { | 570 const FilePath& path) { |
513 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); | 571 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); |
514 string16 name = path.LossyDisplayName(); | 572 string16 name = path.LossyDisplayName(); |
515 DCHECK(!MediaStorageUtil::IsMediaDevice(device_id)); | 573 DCHECK(!MediaStorageUtil::IsMediaDevice(device_id)); |
516 | 574 |
517 for (size_t i = 0; i < profile_states_.size(); i++) { | 575 for (size_t i = 0; i < profile_states_.size(); ++i) { |
518 profile_states_[i]->GetMediaGalleriesPrefs()->AddGallery( | 576 profile_states_[i]->GetMediaGalleriesPrefs()->AddGallery( |
519 device_id, name, FilePath(), true /*user_added*/); | 577 device_id, name, FilePath(), true /*user_added*/); |
520 } | 578 } |
521 return device_id; | 579 return device_id; |
522 } | 580 } |
523 | 581 |
524 std::string MediaFileSystemRegistryTest::AttachDevice( | 582 std::string MediaFileSystemRegistryTest::AttachDevice( |
525 MediaStorageUtil::Type type, | 583 MediaStorageUtil::Type type, |
526 const std::string& unique_id, | 584 const std::string& unique_id, |
527 const FilePath& location) { | 585 const FilePath& location) { |
528 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); | 586 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); |
529 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); | 587 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); |
530 string16 name = location.LossyDisplayName(); | 588 string16 name = location.LossyDisplayName(); |
531 base::SystemMonitor::Get()->ProcessRemovableStorageAttached(device_id, name, | 589 base::SystemMonitor::Get()->ProcessRemovableStorageAttached(device_id, name, |
532 location.value()); | 590 location.value()); |
| 591 bool user_added = (type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM); |
| 592 for (size_t i = 0; i < profile_states_.size(); ++i) { |
| 593 profile_states_[i]->GetMediaGalleriesPrefs()->AddGallery( |
| 594 device_id, name, FilePath(), user_added); |
| 595 } |
533 MessageLoop::current()->RunUntilIdle(); | 596 MessageLoop::current()->RunUntilIdle(); |
534 return device_id; | 597 return device_id; |
535 } | 598 } |
536 | 599 |
537 void MediaFileSystemRegistryTest::DetachDevice(const std::string& device_id) { | 600 void MediaFileSystemRegistryTest::DetachDevice(const std::string& device_id) { |
538 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); | 601 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); |
539 base::SystemMonitor::Get()->ProcessRemovableStorageDetached(device_id); | 602 base::SystemMonitor::Get()->ProcessRemovableStorageDetached(device_id); |
540 MessageLoop::current()->RunUntilIdle(); | 603 MessageLoop::current()->RunUntilIdle(); |
541 } | 604 } |
542 | 605 |
543 void MediaFileSystemRegistryTest::SetGalleryPermission( | 606 void MediaFileSystemRegistryTest::SetGalleryPermission( |
544 ProfileState* profile_state, extensions::Extension* extension, | 607 ProfileState* profile_state, extensions::Extension* extension, |
545 const std::string& device_id, bool has_access) { | 608 const std::string& device_id, bool has_access) { |
546 MediaGalleriesPreferences* preferences = | 609 MediaGalleriesPreferences* preferences = |
547 profile_state->GetMediaGalleriesPrefs(); | 610 profile_state->GetMediaGalleriesPrefs(); |
548 MediaGalleryPrefIdSet pref_id = | 611 MediaGalleryPrefIdSet pref_id = |
549 preferences->LookUpGalleriesByDeviceId(device_id); | 612 preferences->LookUpGalleriesByDeviceId(device_id); |
550 DCHECK_EQ(1U, pref_id.size()); | 613 ASSERT_EQ(1U, pref_id.size()); |
551 preferences->SetGalleryPermissionForExtension(*extension, *pref_id.begin(), | 614 preferences->SetGalleryPermissionForExtension(*extension, *pref_id.begin(), |
552 has_access); | 615 has_access); |
553 } | 616 } |
554 | 617 |
555 void MediaFileSystemRegistryTest::AssertAllAutoAddedGalleries() { | 618 void MediaFileSystemRegistryTest::AssertAllAutoAddedGalleries() { |
556 for (size_t i = 0; i < profile_states_.size(); i++) { | 619 for (size_t i = 0; i < profile_states_.size(); ++i) { |
557 MediaGalleriesPreferences* prefs = | 620 MediaGalleriesPreferences* prefs = |
558 profile_states_[0]->GetMediaGalleriesPrefs(); | 621 profile_states_[0]->GetMediaGalleriesPrefs(); |
559 | 622 |
560 // Make sure that we have at least one gallery and that they are all | 623 // Make sure that we have at least one gallery and that they are all |
561 // auto added galleries. | 624 // auto added galleries. |
562 const MediaGalleriesPrefInfoMap& galleries = prefs->known_galleries(); | 625 const MediaGalleriesPrefInfoMap& galleries = prefs->known_galleries(); |
563 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 626 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
564 ASSERT_GT(galleries.size(), 0U); | 627 ASSERT_GT(galleries.size(), 0U); |
565 #endif | 628 #endif |
566 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); | 629 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); |
567 it != galleries.end(); | 630 it != galleries.end(); |
568 ++it) { | 631 ++it) { |
569 ASSERT_EQ(MediaGalleryPrefInfo::kAutoDetected, it->second.type); | 632 ASSERT_EQ(MediaGalleryPrefInfo::kAutoDetected, it->second.type); |
570 } | 633 } |
571 } | 634 } |
572 } | 635 } |
573 | 636 |
| 637 void MediaFileSystemRegistryTest::InitForGalleryNamesTest( |
| 638 std::set<std::string>* gallery_names) { |
| 639 CreateProfileState(1); |
| 640 AssertAllAutoAddedGalleries(); |
| 641 |
| 642 // Get all existing gallery names. |
| 643 ProfileState* profile_state = GetProfileState(0U); |
| 644 *gallery_names = |
| 645 profile_state->GetGalleryNames(profile_state->all_permission_extension()); |
| 646 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 647 ASSERT_EQ(3U, gallery_names->size()); |
| 648 #else |
| 649 ASSERT_EQ(0U, gallery_names->size()); |
| 650 #endif |
| 651 } |
| 652 |
| 653 void MediaFileSystemRegistryTest::CheckNewGallery( |
| 654 ProfileState* profile_state, |
| 655 const std::set<std::string>& gallery_names, |
| 656 bool removable) { |
| 657 // Get new galleries. |
| 658 std::set<std::string> new_gallery_names = |
| 659 profile_state->GetGalleryNames(profile_state->all_permission_extension()); |
| 660 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 661 ASSERT_EQ(4U, new_gallery_names.size()); |
| 662 #else |
| 663 ASSERT_EQ(1U, new_gallery_names.size()); |
| 664 #endif |
| 665 |
| 666 // Find the new one and check it. |
| 667 std::vector<std::string> difference; |
| 668 std::set_symmetric_difference( |
| 669 gallery_names.begin(), gallery_names.end(), |
| 670 new_gallery_names.begin(), new_gallery_names.end(), |
| 671 std::back_inserter(difference)); |
| 672 ASSERT_EQ(1U, difference.size()); |
| 673 CheckGalleryJSONName(difference[0], removable); |
| 674 } |
| 675 |
574 std::vector<MediaFileSystemInfo> | 676 std::vector<MediaFileSystemInfo> |
575 MediaFileSystemRegistryTest::GetAutoAddedGalleries( | 677 MediaFileSystemRegistryTest::GetAutoAddedGalleries( |
576 ProfileState* profile_state) { | 678 ProfileState* profile_state) { |
577 const MediaGalleriesPrefInfoMap& galleries = | 679 const MediaGalleriesPrefInfoMap& galleries = |
578 profile_state->GetMediaGalleriesPrefs()->known_galleries(); | 680 profile_state->GetMediaGalleriesPrefs()->known_galleries(); |
579 std::vector<MediaFileSystemInfo> result; | 681 std::vector<MediaFileSystemInfo> result; |
580 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); | 682 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); |
581 it != galleries.end(); | 683 it != galleries.end(); |
582 ++it) { | 684 ++it) { |
583 if (it->second.type == MediaGalleryPrefInfo::kAutoDetected) { | 685 if (it->second.type == MediaGalleryPrefInfo::kAutoDetected) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 // Add it to the all galleries extension. | 765 // Add it to the all galleries extension. |
664 SetGalleryPermission(profile_state, | 766 SetGalleryPermission(profile_state, |
665 profile_state->all_permission_extension(), | 767 profile_state->all_permission_extension(), |
666 device_id, | 768 device_id, |
667 true /*has access*/); | 769 true /*has access*/); |
668 auto_galleries.push_back(added_info); | 770 auto_galleries.push_back(added_info); |
669 profile_state->CheckGalleries("user added all", added_galleries, | 771 profile_state->CheckGalleries("user added all", added_galleries, |
670 auto_galleries); | 772 auto_galleries); |
671 } | 773 } |
672 | 774 |
| 775 TEST_F(MediaFileSystemRegistryTest, GalleryNameDefault) { |
| 776 std::set<std::string> gallery_names; |
| 777 InitForGalleryNamesTest(&gallery_names); |
| 778 |
| 779 for (std::set<std::string>::const_iterator it = gallery_names.begin(); |
| 780 it != gallery_names.end(); |
| 781 ++it) { |
| 782 CheckGalleryJSONName(*it, false /*not removable*/); |
| 783 } |
| 784 } |
| 785 |
| 786 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
| 787 TEST_F(MediaFileSystemRegistryTest, GalleryNameMTP) { |
| 788 std::set<std::string> gallery_names; |
| 789 InitForGalleryNamesTest(&gallery_names); |
| 790 |
| 791 // TODO(port) On Windows, this is not an absolute path. |
| 792 FilePath location(FILE_PATH_LITERAL("/mtp_bogus")); |
| 793 AttachDevice(MediaStorageUtil::MTP_OR_PTP, "mtp_fake_id", location); |
| 794 CheckNewGallery(GetProfileState(0U), gallery_names, true /*removable*/); |
| 795 } |
| 796 #endif |
| 797 |
| 798 TEST_F(MediaFileSystemRegistryTest, GalleryNameDCIM) { |
| 799 std::set<std::string> gallery_names; |
| 800 InitForGalleryNamesTest(&gallery_names); |
| 801 |
| 802 AttachDevice(MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM, |
| 803 "removable_dcim_fake_id", |
| 804 dcim_dir()); |
| 805 CheckNewGallery(GetProfileState(0U), gallery_names, true /*removable*/); |
| 806 } |
| 807 |
| 808 TEST_F(MediaFileSystemRegistryTest, GalleryNameNoDCIM) { |
| 809 std::set<std::string> gallery_names; |
| 810 InitForGalleryNamesTest(&gallery_names); |
| 811 |
| 812 std::string device_id = |
| 813 AttachDevice(MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, |
| 814 empty_dir().AsUTF8Unsafe(), |
| 815 empty_dir()); |
| 816 std::string device_id2 = |
| 817 AddUserGallery(MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, |
| 818 empty_dir().AsUTF8Unsafe(), |
| 819 empty_dir()); |
| 820 ASSERT_EQ(device_id, device_id2); |
| 821 // Add permission for new non-default gallery. |
| 822 ProfileState* profile_state = GetProfileState(0U); |
| 823 SetGalleryPermission(profile_state, |
| 824 profile_state->all_permission_extension(), |
| 825 device_id, |
| 826 true /*has access*/); |
| 827 CheckNewGallery(profile_state, gallery_names, true /*removable*/); |
| 828 } |
| 829 |
| 830 TEST_F(MediaFileSystemRegistryTest, GalleryNameUserAddedPath) { |
| 831 std::set<std::string> gallery_names; |
| 832 InitForGalleryNamesTest(&gallery_names); |
| 833 |
| 834 std::string device_id = AddUserGallery(MediaStorageUtil::FIXED_MASS_STORAGE, |
| 835 empty_dir().AsUTF8Unsafe(), |
| 836 empty_dir()); |
| 837 // Add permission for new non-default gallery. |
| 838 ProfileState* profile_state = GetProfileState(0U); |
| 839 SetGalleryPermission(profile_state, |
| 840 profile_state->all_permission_extension(), |
| 841 device_id, |
| 842 true /*has access*/); |
| 843 CheckNewGallery(profile_state, gallery_names, false /*not removable*/); |
| 844 } |
| 845 |
673 } // namespace | 846 } // namespace |
674 | 847 |
675 } // namespace chrome | 848 } // namespace chrome |
OLD | NEW |