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 // MediaFileSystemRegistry unit tests. | 5 // MediaFileSystemRegistry unit tests. |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "base/values.h" | 22 #include "base/values.h" |
| 23 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
| 24 #include "chrome/browser/extensions/extension_system.h" | 24 #include "chrome/browser/extensions/extension_system.h" |
| 25 #include "chrome/browser/extensions/test_extension_system.h" | 25 #include "chrome/browser/extensions/test_extension_system.h" |
| 26 #include "chrome/browser/media_gallery/media_file_system_context.h" | 26 #include "chrome/browser/media_gallery/media_file_system_context.h" |
| 27 #include "chrome/browser/media_gallery/media_file_system_registry.h" | 27 #include "chrome/browser/media_gallery/media_file_system_registry.h" |
| 28 #include "chrome/browser/media_gallery/media_galleries_preferences_factory.h" | 28 #include "chrome/browser/media_gallery/media_galleries_preferences_factory.h" |
| 29 #include "chrome/browser/media_gallery/media_galleries_test_util.h" | 29 #include "chrome/browser/media_gallery/media_galleries_test_util.h" |
| 30 #include "chrome/browser/system_monitor/media_storage_util.h" | 30 #include "chrome/browser/system_monitor/media_storage_util.h" |
| 31 #include "chrome/browser/system_monitor/removable_device_constants.h" | 31 #include "chrome/browser/system_monitor/removable_device_constants.h" |
| 32 #include "chrome/browser/system_monitor/removable_storage_notifications.h" | |
| 33 #include "chrome/browser/system_monitor/test_removable_storage_notifications.h" | |
| 32 #include "chrome/common/extensions/extension.h" | 34 #include "chrome/common/extensions/extension.h" |
| 33 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 35 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 34 #include "chrome/test/base/testing_browser_process.h" | 36 #include "chrome/test/base/testing_browser_process.h" |
| 35 #include "chrome/test/base/testing_profile.h" | 37 #include "chrome/test/base/testing_profile.h" |
| 36 #include "content/public/browser/render_process_host_factory.h" | 38 #include "content/public/browser/render_process_host_factory.h" |
| 37 #include "content/public/browser/render_process_host.h" | 39 #include "content/public/browser/render_process_host.h" |
| 38 #include "content/public/browser/render_view_host.h" | 40 #include "content/public/browser/render_view_host.h" |
| 39 #include "content/public/browser/web_contents.h" | 41 #include "content/public/browser/web_contents.h" |
| 40 #include "content/public/test/mock_render_process_host.h" | 42 #include "content/public/test/mock_render_process_host.h" |
| 41 #include "content/public/test/test_browser_thread.h" | 43 #include "content/public/test/test_browser_thread.h" |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 scoped_ptr<content::WebContents> shared_web_contents2_; | 295 scoped_ptr<content::WebContents> shared_web_contents2_; |
| 294 | 296 |
| 295 // The RenderProcessHosts are freed when their respective WebContents / | 297 // The RenderProcessHosts are freed when their respective WebContents / |
| 296 // RenderViewHosts go away. | 298 // RenderViewHosts go away. |
| 297 content::MockRenderProcessHost* single_rph_; | 299 content::MockRenderProcessHost* single_rph_; |
| 298 content::MockRenderProcessHost* shared_rph_; | 300 content::MockRenderProcessHost* shared_rph_; |
| 299 | 301 |
| 300 DISALLOW_COPY_AND_ASSIGN(ProfileState); | 302 DISALLOW_COPY_AND_ASSIGN(ProfileState); |
| 301 }; | 303 }; |
| 302 | 304 |
| 305 } // namespace | |
| 306 | |
| 303 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness { | 307 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness { |
| 304 public: | 308 public: |
| 305 MediaFileSystemRegistryTest(); | 309 MediaFileSystemRegistryTest(); |
| 306 virtual ~MediaFileSystemRegistryTest() {} | 310 virtual ~MediaFileSystemRegistryTest() {} |
| 307 | 311 |
| 308 void CreateProfileState(size_t profile_count); | 312 void CreateProfileState(size_t profile_count); |
| 309 | 313 |
| 310 ProfileState* GetProfileState(size_t i); | 314 ProfileState* GetProfileState(size_t i); |
| 311 | 315 |
| 312 FilePath empty_dir() { | 316 FilePath empty_dir() { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 341 | 345 |
| 342 void CheckNewGalleryInfo(ProfileState* profile_state, | 346 void CheckNewGalleryInfo(ProfileState* profile_state, |
| 343 const FSInfoMap& galleries_info, | 347 const FSInfoMap& galleries_info, |
| 344 const FilePath& location, | 348 const FilePath& location, |
| 345 bool removable, | 349 bool removable, |
| 346 bool media_device); | 350 bool media_device); |
| 347 | 351 |
| 348 std::vector<MediaFileSystemInfo> GetAutoAddedGalleries( | 352 std::vector<MediaFileSystemInfo> GetAutoAddedGalleries( |
| 349 ProfileState* profile_state); | 353 ProfileState* profile_state); |
| 350 | 354 |
| 355 void ProcessAttach(const std::string& id, | |
| 356 const string16& name, | |
| 357 const FilePath::StringType& location) { | |
| 358 chrome::RemovableStorageNotifications::GetInstance()->ProcessAttach( | |
|
Lei Zhang
2013/01/26 01:27:49
nit: no need for chrome:: Since we're already insi
Greg Billock
2013/01/26 01:42:07
Done.
| |
| 359 id, name, location); | |
| 360 } | |
| 361 | |
| 362 void ProcessDetach(const std::string& id) { | |
| 363 chrome::RemovableStorageNotifications::GetInstance()->ProcessDetach(id); | |
| 364 } | |
| 365 | |
| 351 protected: | 366 protected: |
| 352 void SetUp(); | 367 void SetUp(); |
| 353 void TearDown(); | 368 void TearDown(); |
| 354 | 369 |
| 355 private: | 370 private: |
| 356 // This makes sure that at least one default gallery exists on the file | 371 // This makes sure that at least one default gallery exists on the file |
| 357 // system. | 372 // system. |
| 358 EnsureMediaDirectoriesExists media_directories_; | 373 EnsureMediaDirectoriesExists media_directories_; |
| 359 | 374 |
| 360 // Some test gallery directories. | 375 // Some test gallery directories. |
| 361 base::ScopedTempDir galleries_dir_; | 376 base::ScopedTempDir galleries_dir_; |
| 362 // An empty directory in |galleries_dir_| | 377 // An empty directory in |galleries_dir_| |
| 363 FilePath empty_dir_; | 378 FilePath empty_dir_; |
| 364 // A directory in |galleries_dir_| with a DCIM directory in it. | 379 // A directory in |galleries_dir_| with a DCIM directory in it. |
| 365 FilePath dcim_dir_; | 380 FilePath dcim_dir_; |
| 366 | 381 |
| 367 // MediaFileSystemRegistry owns this. | 382 // MediaFileSystemRegistry owns this. |
| 368 TestMediaFileSystemContext* test_file_system_context_; | 383 TestMediaFileSystemContext* test_file_system_context_; |
| 369 | 384 |
| 370 // Needed for extension service & friends to work. | 385 // Needed for extension service & friends to work. |
| 371 content::TestBrowserThread ui_thread_; | 386 content::TestBrowserThread ui_thread_; |
| 372 content::TestBrowserThread file_thread_; | 387 content::TestBrowserThread file_thread_; |
| 373 | 388 |
| 374 // For AttachDevice() and DetachDevice(). | |
| 375 scoped_ptr<base::SystemMonitor> system_monitor_; | |
| 376 | |
| 377 MockProfileSharedRenderProcessHostFactory rph_factory_; | 389 MockProfileSharedRenderProcessHostFactory rph_factory_; |
| 378 | 390 |
| 379 ScopedVector<ProfileState> profile_states_; | 391 ScopedVector<ProfileState> profile_states_; |
| 380 | 392 |
| 393 chrome::test::TestRemovableStorageNotifications notifications_; | |
| 394 | |
| 381 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest); | 395 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest); |
| 382 }; | 396 }; |
| 383 | 397 |
| 398 namespace { | |
| 399 | |
| 384 bool MediaFileSystemInfoComparator(const MediaFileSystemInfo& a, | 400 bool MediaFileSystemInfoComparator(const MediaFileSystemInfo& a, |
| 385 const MediaFileSystemInfo& b) { | 401 const MediaFileSystemInfo& b) { |
| 386 CHECK_NE(a.name, b.name); // Name must be unique. | 402 CHECK_NE(a.name, b.name); // Name must be unique. |
| 387 return a.name < b.name; | 403 return a.name < b.name; |
| 388 } | 404 } |
| 389 | 405 |
| 390 ////////////////////////// | 406 ////////////////////////// |
| 391 // TestMediaStorageUtil // | 407 // TestMediaStorageUtil // |
| 392 ////////////////////////// | 408 ////////////////////////// |
| 393 | 409 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 EXPECT_EQ(expected[i].fsid, actual[i].fsid) << test; | 586 EXPECT_EQ(expected[i].fsid, actual[i].fsid) << test; |
| 571 } | 587 } |
| 572 } | 588 } |
| 573 | 589 |
| 574 int ProfileState::GetAndClearComparisonCount() { | 590 int ProfileState::GetAndClearComparisonCount() { |
| 575 int result = num_comparisons_; | 591 int result = num_comparisons_; |
| 576 num_comparisons_ = 0; | 592 num_comparisons_ = 0; |
| 577 return result; | 593 return result; |
| 578 } | 594 } |
| 579 | 595 |
| 596 } // namespace | |
| 597 | |
| 580 ///////////////////////////////// | 598 ///////////////////////////////// |
| 581 // MediaFileSystemRegistryTest // | 599 // MediaFileSystemRegistryTest // |
| 582 ///////////////////////////////// | 600 ///////////////////////////////// |
| 583 | 601 |
| 584 MediaFileSystemRegistryTest::MediaFileSystemRegistryTest() | 602 MediaFileSystemRegistryTest::MediaFileSystemRegistryTest() |
| 585 : ui_thread_(content::BrowserThread::UI, MessageLoop::current()), | 603 : ui_thread_(content::BrowserThread::UI, MessageLoop::current()), |
| 586 file_thread_(content::BrowserThread::FILE, MessageLoop::current()) { | 604 file_thread_(content::BrowserThread::FILE, MessageLoop::current()) { |
| 587 } | 605 } |
| 588 | 606 |
| 589 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) { | 607 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 612 return device_id; | 630 return device_id; |
| 613 } | 631 } |
| 614 | 632 |
| 615 std::string MediaFileSystemRegistryTest::AttachDevice( | 633 std::string MediaFileSystemRegistryTest::AttachDevice( |
| 616 MediaStorageUtil::Type type, | 634 MediaStorageUtil::Type type, |
| 617 const std::string& unique_id, | 635 const std::string& unique_id, |
| 618 const FilePath& location) { | 636 const FilePath& location) { |
| 619 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); | 637 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); |
| 620 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); | 638 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); |
| 621 string16 name = location.LossyDisplayName(); | 639 string16 name = location.LossyDisplayName(); |
| 622 base::SystemMonitor::Get()->ProcessRemovableStorageAttached(device_id, name, | 640 ProcessAttach(device_id, name, location.value()); |
| 623 location.value()); | |
| 624 bool user_added = (type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM); | 641 bool user_added = (type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM); |
| 625 for (size_t i = 0; i < profile_states_.size(); ++i) { | 642 for (size_t i = 0; i < profile_states_.size(); ++i) { |
| 626 profile_states_[i]->GetMediaGalleriesPrefs()->AddGallery( | 643 profile_states_[i]->GetMediaGalleriesPrefs()->AddGallery( |
| 627 device_id, name, FilePath(), user_added); | 644 device_id, name, FilePath(), user_added); |
| 628 } | 645 } |
| 629 MessageLoop::current()->RunUntilIdle(); | 646 MessageLoop::current()->RunUntilIdle(); |
| 630 return device_id; | 647 return device_id; |
| 631 } | 648 } |
| 632 | 649 |
| 633 void MediaFileSystemRegistryTest::DetachDevice(const std::string& device_id) { | 650 void MediaFileSystemRegistryTest::DetachDevice(const std::string& device_id) { |
| 634 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); | 651 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); |
| 635 base::SystemMonitor::Get()->ProcessRemovableStorageDetached(device_id); | 652 ProcessDetach(device_id); |
| 636 MessageLoop::current()->RunUntilIdle(); | 653 MessageLoop::current()->RunUntilIdle(); |
| 637 } | 654 } |
| 638 | 655 |
| 639 void MediaFileSystemRegistryTest::SetGalleryPermission( | 656 void MediaFileSystemRegistryTest::SetGalleryPermission( |
| 640 ProfileState* profile_state, extensions::Extension* extension, | 657 ProfileState* profile_state, extensions::Extension* extension, |
| 641 const std::string& device_id, bool has_access) { | 658 const std::string& device_id, bool has_access) { |
| 642 MediaGalleriesPreferences* preferences = | 659 MediaGalleriesPreferences* preferences = |
| 643 profile_state->GetMediaGalleriesPrefs(); | 660 profile_state->GetMediaGalleriesPrefs(); |
| 644 MediaGalleryPrefIdSet pref_id = | 661 MediaGalleryPrefIdSet pref_id = |
| 645 preferences->LookUpGalleriesByDeviceId(device_id); | 662 preferences->LookUpGalleriesByDeviceId(device_id); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 724 MediaFileSystemInfo info(path.AsUTF8Unsafe(), path, std::string(), | 741 MediaFileSystemInfo info(path.AsUTF8Unsafe(), path, std::string(), |
| 725 0, 0, false, false); | 742 0, 0, false, false); |
| 726 result.push_back(info); | 743 result.push_back(info); |
| 727 } | 744 } |
| 728 } | 745 } |
| 729 std::sort(result.begin(), result.end(), MediaFileSystemInfoComparator); | 746 std::sort(result.begin(), result.end(), MediaFileSystemInfoComparator); |
| 730 return result; | 747 return result; |
| 731 } | 748 } |
| 732 | 749 |
| 733 void MediaFileSystemRegistryTest::SetUp() { | 750 void MediaFileSystemRegistryTest::SetUp() { |
| 734 #if defined(OS_MACOSX) | |
| 735 // This needs to happen before SystemMonitor's ctor. | |
| 736 base::SystemMonitor::AllocateSystemIOPorts(); | |
| 737 #endif | |
| 738 system_monitor_.reset(new base::SystemMonitor); | |
| 739 | |
| 740 ChromeRenderViewHostTestHarness::SetUp(); | 751 ChromeRenderViewHostTestHarness::SetUp(); |
| 741 DeleteContents(); | 752 DeleteContents(); |
| 742 SetRenderProcessHostFactory(&rph_factory_); | 753 SetRenderProcessHostFactory(&rph_factory_); |
| 743 | 754 |
| 744 TestMediaStorageUtil::SetTestingMode(); | 755 TestMediaStorageUtil::SetTestingMode(); |
| 745 test_file_system_context_ = new TestMediaFileSystemContext( | 756 test_file_system_context_ = new TestMediaFileSystemContext( |
| 746 g_browser_process->media_file_system_registry()); | 757 g_browser_process->media_file_system_registry()); |
| 747 | 758 |
| 748 ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir()); | 759 ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir()); |
| 749 empty_dir_ = galleries_dir_.path().AppendASCII("empty"); | 760 empty_dir_ = galleries_dir_.path().AppendASCII("empty"); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 886 // Add permission for new non-default gallery. | 897 // Add permission for new non-default gallery. |
| 887 ProfileState* profile_state = GetProfileState(0U); | 898 ProfileState* profile_state = GetProfileState(0U); |
| 888 SetGalleryPermission(profile_state, | 899 SetGalleryPermission(profile_state, |
| 889 profile_state->all_permission_extension(), | 900 profile_state->all_permission_extension(), |
| 890 device_id, | 901 device_id, |
| 891 true /*has access*/); | 902 true /*has access*/); |
| 892 CheckNewGalleryInfo(profile_state, galleries_info, empty_dir(), | 903 CheckNewGalleryInfo(profile_state, galleries_info, empty_dir(), |
| 893 false /*removable*/, false /* media device */); | 904 false /*removable*/, false /* media device */); |
| 894 } | 905 } |
| 895 | 906 |
| 896 } // namespace | |
| 897 | |
| 898 } // namespace chrome | 907 } // namespace chrome |
| OLD | NEW |