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

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

Issue 11573048: [Media Galleries] Move RemovableStorageInfo notifications to chrome namespace (part 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Working on windows Created 7 years, 10 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
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 #include <set>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 11 matching lines...) Expand all
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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 scoped_ptr<content::WebContents> shared_web_contents2_; 302 scoped_ptr<content::WebContents> shared_web_contents2_;
301 303
302 // The RenderProcessHosts are freed when their respective WebContents / 304 // The RenderProcessHosts are freed when their respective WebContents /
303 // RenderViewHosts go away. 305 // RenderViewHosts go away.
304 content::MockRenderProcessHost* single_rph_; 306 content::MockRenderProcessHost* single_rph_;
305 content::MockRenderProcessHost* shared_rph_; 307 content::MockRenderProcessHost* shared_rph_;
306 308
307 DISALLOW_COPY_AND_ASSIGN(ProfileState); 309 DISALLOW_COPY_AND_ASSIGN(ProfileState);
308 }; 310 };
309 311
312 } // namespace
313
310 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness { 314 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness {
311 public: 315 public:
312 MediaFileSystemRegistryTest(); 316 MediaFileSystemRegistryTest();
313 virtual ~MediaFileSystemRegistryTest() {} 317 virtual ~MediaFileSystemRegistryTest() {}
314 318
315 void CreateProfileState(size_t profile_count); 319 void CreateProfileState(size_t profile_count);
316 320
317 ProfileState* GetProfileState(size_t i); 321 ProfileState* GetProfileState(size_t i);
318 322
319 FilePath empty_dir() { 323 FilePath empty_dir() {
(...skipping 28 matching lines...) Expand all
348 352
349 void CheckNewGalleryInfo(ProfileState* profile_state, 353 void CheckNewGalleryInfo(ProfileState* profile_state,
350 const FSInfoMap& galleries_info, 354 const FSInfoMap& galleries_info,
351 const FilePath& location, 355 const FilePath& location,
352 bool removable, 356 bool removable,
353 bool media_device); 357 bool media_device);
354 358
355 std::vector<MediaFileSystemInfo> GetAutoAddedGalleries( 359 std::vector<MediaFileSystemInfo> GetAutoAddedGalleries(
356 ProfileState* profile_state); 360 ProfileState* profile_state);
357 361
362 void ProcessAttach(const std::string& id,
363 const string16& name,
364 const FilePath::StringType& location) {
365 RemovableStorageNotifications::GetInstance()->ProcessAttach(
366 id, name, location);
367 }
368
369 void ProcessDetach(const std::string& id) {
370 RemovableStorageNotifications::GetInstance()->ProcessDetach(id);
371 }
372
358 protected: 373 protected:
359 void SetUp(); 374 virtual void SetUp() OVERRIDE;
360 void TearDown(); 375 virtual void TearDown() OVERRIDE;
361 376
362 private: 377 private:
363 // This makes sure that at least one default gallery exists on the file 378 // This makes sure that at least one default gallery exists on the file
364 // system. 379 // system.
365 EnsureMediaDirectoriesExists media_directories_; 380 EnsureMediaDirectoriesExists media_directories_;
366 381
367 // Some test gallery directories. 382 // Some test gallery directories.
368 base::ScopedTempDir galleries_dir_; 383 base::ScopedTempDir galleries_dir_;
369 // An empty directory in |galleries_dir_| 384 // An empty directory in |galleries_dir_|
370 FilePath empty_dir_; 385 FilePath empty_dir_;
371 // A directory in |galleries_dir_| with a DCIM directory in it. 386 // A directory in |galleries_dir_| with a DCIM directory in it.
372 FilePath dcim_dir_; 387 FilePath dcim_dir_;
373 388
374 // MediaFileSystemRegistry owns this. 389 // MediaFileSystemRegistry owns this.
375 TestMediaFileSystemContext* test_file_system_context_; 390 TestMediaFileSystemContext* test_file_system_context_;
376 391
377 // Needed for extension service & friends to work. 392 // Needed for extension service & friends to work.
378 content::TestBrowserThread ui_thread_; 393 content::TestBrowserThread ui_thread_;
379 content::TestBrowserThread file_thread_; 394 content::TestBrowserThread file_thread_;
380 395
381 #if defined(OS_WIN) 396 #if defined(OS_WIN)
382 scoped_ptr<test::TestRemovableDeviceNotificationsWindowWin> window_; 397 scoped_ptr<test::TestRemovableDeviceNotificationsWindowWin> window_;
398 #else
399 chrome::test::TestRemovableStorageNotifications notifications_;
383 #endif 400 #endif
384 401
385 // For AttachDevice() and DetachDevice().
386 scoped_ptr<base::SystemMonitor> system_monitor_;
387
388 MockProfileSharedRenderProcessHostFactory rph_factory_; 402 MockProfileSharedRenderProcessHostFactory rph_factory_;
389 403
390 ScopedVector<ProfileState> profile_states_; 404 ScopedVector<ProfileState> profile_states_;
391 405
392 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest); 406 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest);
393 }; 407 };
394 408
409 namespace {
410
395 bool MediaFileSystemInfoComparator(const MediaFileSystemInfo& a, 411 bool MediaFileSystemInfoComparator(const MediaFileSystemInfo& a,
396 const MediaFileSystemInfo& b) { 412 const MediaFileSystemInfo& b) {
397 CHECK_NE(a.name, b.name); // Name must be unique. 413 CHECK_NE(a.name, b.name); // Name must be unique.
398 return a.name < b.name; 414 return a.name < b.name;
399 } 415 }
400 416
401 ////////////////////////// 417 //////////////////////////
402 // TestMediaStorageUtil // 418 // TestMediaStorageUtil //
403 ////////////////////////// 419 //////////////////////////
404 420
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 EXPECT_EQ(expected[i].fsid, actual[i].fsid) << test; 597 EXPECT_EQ(expected[i].fsid, actual[i].fsid) << test;
582 } 598 }
583 } 599 }
584 600
585 int ProfileState::GetAndClearComparisonCount() { 601 int ProfileState::GetAndClearComparisonCount() {
586 int result = num_comparisons_; 602 int result = num_comparisons_;
587 num_comparisons_ = 0; 603 num_comparisons_ = 0;
588 return result; 604 return result;
589 } 605 }
590 606
607 } // namespace
608
591 ///////////////////////////////// 609 /////////////////////////////////
592 // MediaFileSystemRegistryTest // 610 // MediaFileSystemRegistryTest //
593 ///////////////////////////////// 611 /////////////////////////////////
594 612
595 MediaFileSystemRegistryTest::MediaFileSystemRegistryTest() 613 MediaFileSystemRegistryTest::MediaFileSystemRegistryTest()
596 : ui_thread_(content::BrowserThread::UI, MessageLoop::current()), 614 : ui_thread_(content::BrowserThread::UI, MessageLoop::current()),
597 file_thread_(content::BrowserThread::FILE, MessageLoop::current()) { 615 file_thread_(content::BrowserThread::FILE, MessageLoop::current()) {
598 } 616 }
599 617
600 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) { 618 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) {
(...skipping 22 matching lines...) Expand all
623 return device_id; 641 return device_id;
624 } 642 }
625 643
626 std::string MediaFileSystemRegistryTest::AttachDevice( 644 std::string MediaFileSystemRegistryTest::AttachDevice(
627 MediaStorageUtil::Type type, 645 MediaStorageUtil::Type type,
628 const std::string& unique_id, 646 const std::string& unique_id,
629 const FilePath& location) { 647 const FilePath& location) {
630 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); 648 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id);
631 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); 649 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id));
632 string16 name = location.LossyDisplayName(); 650 string16 name = location.LossyDisplayName();
633 base::SystemMonitor::Get()->ProcessRemovableStorageAttached(device_id, name, 651 ProcessAttach(device_id, name, location.value());
634 location.value());
635 bool user_added = (type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM); 652 bool user_added = (type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM);
636 for (size_t i = 0; i < profile_states_.size(); ++i) { 653 for (size_t i = 0; i < profile_states_.size(); ++i) {
637 profile_states_[i]->GetMediaGalleriesPrefs()->AddGallery( 654 profile_states_[i]->GetMediaGalleriesPrefs()->AddGallery(
638 device_id, name, FilePath(), user_added); 655 device_id, name, FilePath(), user_added);
639 } 656 }
640 MessageLoop::current()->RunUntilIdle(); 657 MessageLoop::current()->RunUntilIdle();
641 return device_id; 658 return device_id;
642 } 659 }
643 660
644 void MediaFileSystemRegistryTest::DetachDevice(const std::string& device_id) { 661 void MediaFileSystemRegistryTest::DetachDevice(const std::string& device_id) {
645 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); 662 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id));
646 base::SystemMonitor::Get()->ProcessRemovableStorageDetached(device_id); 663 ProcessDetach(device_id);
647 MessageLoop::current()->RunUntilIdle(); 664 MessageLoop::current()->RunUntilIdle();
648 } 665 }
649 666
650 void MediaFileSystemRegistryTest::SetGalleryPermission( 667 void MediaFileSystemRegistryTest::SetGalleryPermission(
651 ProfileState* profile_state, extensions::Extension* extension, 668 ProfileState* profile_state, extensions::Extension* extension,
652 const std::string& device_id, bool has_access) { 669 const std::string& device_id, bool has_access) {
653 MediaGalleriesPreferences* preferences = 670 MediaGalleriesPreferences* preferences =
654 profile_state->GetMediaGalleriesPrefs(); 671 profile_state->GetMediaGalleriesPrefs();
655 MediaGalleryPrefIdSet pref_id = 672 MediaGalleryPrefIdSet pref_id =
656 preferences->LookUpGalleriesByDeviceId(device_id); 673 preferences->LookUpGalleriesByDeviceId(device_id);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 CommandLine::ForCurrentProcess()->AppendSwitch( 763 CommandLine::ForCurrentProcess()->AppendSwitch(
747 switches::kEnableMediaTransferProtocolDeviceOperations); 764 switches::kEnableMediaTransferProtocolDeviceOperations);
748 test::TestPortableDeviceWatcherWin* portable_device_watcher = 765 test::TestPortableDeviceWatcherWin* portable_device_watcher =
749 new test::TestPortableDeviceWatcherWin; 766 new test::TestPortableDeviceWatcherWin;
750 portable_device_watcher->set_use_dummy_mtp_storage_info(true); 767 portable_device_watcher->set_use_dummy_mtp_storage_info(true);
751 window_.reset(new test::TestRemovableDeviceNotificationsWindowWin( 768 window_.reset(new test::TestRemovableDeviceNotificationsWindowWin(
752 new test::TestVolumeMountWatcherWin, portable_device_watcher)); 769 new test::TestVolumeMountWatcherWin, portable_device_watcher));
753 window_->Init(); 770 window_->Init();
754 #endif 771 #endif
755 772
756 #if defined(OS_MACOSX)
757 // This needs to happen before SystemMonitor's ctor.
758 base::SystemMonitor::AllocateSystemIOPorts();
759 #endif
760 system_monitor_.reset(new base::SystemMonitor);
761
762 ChromeRenderViewHostTestHarness::SetUp(); 773 ChromeRenderViewHostTestHarness::SetUp();
763 DeleteContents(); 774 DeleteContents();
764 SetRenderProcessHostFactory(&rph_factory_); 775 SetRenderProcessHostFactory(&rph_factory_);
765 776
766 TestMediaStorageUtil::SetTestingMode(); 777 TestMediaStorageUtil::SetTestingMode();
767 test_file_system_context_ = new TestMediaFileSystemContext( 778 test_file_system_context_ = new TestMediaFileSystemContext(
768 g_browser_process->media_file_system_registry()); 779 g_browser_process->media_file_system_registry());
769 780
770 ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir()); 781 ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir());
771 empty_dir_ = galleries_dir_.path().AppendASCII("empty"); 782 empty_dir_ = galleries_dir_.path().AppendASCII("empty");
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 // Add permission for new non-default gallery. 918 // Add permission for new non-default gallery.
908 ProfileState* profile_state = GetProfileState(0U); 919 ProfileState* profile_state = GetProfileState(0U);
909 SetGalleryPermission(profile_state, 920 SetGalleryPermission(profile_state,
910 profile_state->all_permission_extension(), 921 profile_state->all_permission_extension(),
911 device_id, 922 device_id,
912 true /*has access*/); 923 true /*has access*/);
913 CheckNewGalleryInfo(profile_state, galleries_info, empty_dir(), 924 CheckNewGalleryInfo(profile_state, galleries_info, empty_dir(),
914 false /*removable*/, false /* media device */); 925 false /*removable*/, false /* media device */);
915 } 926 }
916 927
917 } // namespace
918
919 } // namespace chrome 928 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698