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