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

Side by Side Diff: chrome/browser/media_gallery/media_file_system_registry_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698