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

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: Make singleton pointer live in base class. 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
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"
32 #include "chrome/common/extensions/extension.h" 33 #include "chrome/common/extensions/extension.h"
33 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 34 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
34 #include "chrome/test/base/testing_browser_process.h" 35 #include "chrome/test/base/testing_browser_process.h"
35 #include "chrome/test/base/testing_profile.h" 36 #include "chrome/test/base/testing_profile.h"
36 #include "content/public/browser/render_process_host_factory.h" 37 #include "content/public/browser/render_process_host_factory.h"
37 #include "content/public/browser/render_process_host.h" 38 #include "content/public/browser/render_process_host.h"
38 #include "content/public/browser/render_view_host.h" 39 #include "content/public/browser/render_view_host.h"
39 #include "content/public/browser/web_contents.h" 40 #include "content/public/browser/web_contents.h"
40 #include "content/public/test/mock_render_process_host.h" 41 #include "content/public/test/mock_render_process_host.h"
41 #include "content/public/test/test_browser_thread.h" 42 #include "content/public/test/test_browser_thread.h"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 scoped_ptr<content::WebContents> shared_web_contents2_; 294 scoped_ptr<content::WebContents> shared_web_contents2_;
294 295
295 // The RenderProcessHosts are freed when their respective WebContents / 296 // The RenderProcessHosts are freed when their respective WebContents /
296 // RenderViewHosts go away. 297 // RenderViewHosts go away.
297 content::MockRenderProcessHost* single_rph_; 298 content::MockRenderProcessHost* single_rph_;
298 content::MockRenderProcessHost* shared_rph_; 299 content::MockRenderProcessHost* shared_rph_;
299 300
300 DISALLOW_COPY_AND_ASSIGN(ProfileState); 301 DISALLOW_COPY_AND_ASSIGN(ProfileState);
301 }; 302 };
302 303
304 class FakeRemovableStorageNotifications
vandebo (ex-Chrome) 2013/01/18 18:42:58 I don't see what this class does here?
Greg Billock 2013/01/22 20:00:39 Needed to set up the singleton (done in the base c
vandebo (ex-Chrome) 2013/01/22 23:37:24 Ahh, I see. There's a second copy (and a third) o
Greg Billock 2013/01/23 00:28:01 Used "test_*" since that seems the moniker in the
305 : public chrome::RemovableStorageNotifications {
306 public:
307 FakeRemovableStorageNotifications() : RemovableStorageNotifications() {}
308 virtual ~FakeRemovableStorageNotifications() {}
309
310 virtual bool GetDeviceInfoForPath(
311 const FilePath& path,
312 StorageInfo* device_info) const {
313 return false;
314 }
315
316 virtual uint64 GetStorageSize(const std::string& location) const {
317 return 0;
318 }
319 };
320
321 } // namespace
322
303 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness { 323 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness {
304 public: 324 public:
305 MediaFileSystemRegistryTest(); 325 MediaFileSystemRegistryTest();
306 virtual ~MediaFileSystemRegistryTest() {} 326 virtual ~MediaFileSystemRegistryTest() {}
307 327
308 void CreateProfileState(size_t profile_count); 328 void CreateProfileState(size_t profile_count);
309 329
310 ProfileState* GetProfileState(size_t i); 330 ProfileState* GetProfileState(size_t i);
311 331
312 FilePath empty_dir() { 332 FilePath empty_dir() {
(...skipping 28 matching lines...) Expand all
341 361
342 void CheckNewGalleryInfo(ProfileState* profile_state, 362 void CheckNewGalleryInfo(ProfileState* profile_state,
343 const FSInfoMap& galleries_info, 363 const FSInfoMap& galleries_info,
344 const FilePath& location, 364 const FilePath& location,
345 bool removable, 365 bool removable,
346 bool media_device); 366 bool media_device);
347 367
348 std::vector<MediaFileSystemInfo> GetAutoAddedGalleries( 368 std::vector<MediaFileSystemInfo> GetAutoAddedGalleries(
349 ProfileState* profile_state); 369 ProfileState* profile_state);
350 370
371 void ProcessAttach(const std::string& id,
372 const string16& name,
373 const FilePath::StringType& location) {
374 chrome::RemovableStorageNotifications::GetInstance()->ProcessAttach(
375 id, name, location);
376 }
377
378 void ProcessDetach(const std::string& id) {
379 chrome::RemovableStorageNotifications::GetInstance()->ProcessDetach(id);
380 }
381
351 protected: 382 protected:
352 void SetUp(); 383 void SetUp();
353 void TearDown(); 384 void TearDown();
354 385
355 private: 386 private:
356 // This makes sure that at least one default gallery exists on the file 387 // This makes sure that at least one default gallery exists on the file
357 // system. 388 // system.
358 EnsureMediaDirectoriesExists media_directories_; 389 EnsureMediaDirectoriesExists media_directories_;
359 390
360 // Some test gallery directories. 391 // Some test gallery directories.
361 base::ScopedTempDir galleries_dir_; 392 base::ScopedTempDir galleries_dir_;
362 // An empty directory in |galleries_dir_| 393 // An empty directory in |galleries_dir_|
363 FilePath empty_dir_; 394 FilePath empty_dir_;
364 // A directory in |galleries_dir_| with a DCIM directory in it. 395 // A directory in |galleries_dir_| with a DCIM directory in it.
365 FilePath dcim_dir_; 396 FilePath dcim_dir_;
366 397
367 // MediaFileSystemRegistry owns this. 398 // MediaFileSystemRegistry owns this.
368 TestMediaFileSystemContext* test_file_system_context_; 399 TestMediaFileSystemContext* test_file_system_context_;
369 400
370 // Needed for extension service & friends to work. 401 // Needed for extension service & friends to work.
371 content::TestBrowserThread ui_thread_; 402 content::TestBrowserThread ui_thread_;
372 content::TestBrowserThread file_thread_; 403 content::TestBrowserThread file_thread_;
373 404
374 // For AttachDevice() and DetachDevice().
375 scoped_ptr<base::SystemMonitor> system_monitor_;
376
377 MockProfileSharedRenderProcessHostFactory rph_factory_; 405 MockProfileSharedRenderProcessHostFactory rph_factory_;
378 406
379 ScopedVector<ProfileState> profile_states_; 407 ScopedVector<ProfileState> profile_states_;
380 408
409 FakeRemovableStorageNotifications notifications_;
vandebo (ex-Chrome) 2013/01/18 18:42:58 Not used
Greg Billock 2013/01/22 20:00:39 see above On 2013/01/18 18:42:58, vandebo wrote:
410
381 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest); 411 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest);
382 }; 412 };
383 413
414 namespace {
415
384 bool MediaFileSystemInfoComparator(const MediaFileSystemInfo& a, 416 bool MediaFileSystemInfoComparator(const MediaFileSystemInfo& a,
385 const MediaFileSystemInfo& b) { 417 const MediaFileSystemInfo& b) {
386 CHECK_NE(a.name, b.name); // Name must be unique. 418 CHECK_NE(a.name, b.name); // Name must be unique.
387 return a.name < b.name; 419 return a.name < b.name;
388 } 420 }
389 421
390 ////////////////////////// 422 //////////////////////////
391 // TestMediaStorageUtil // 423 // TestMediaStorageUtil //
392 ////////////////////////// 424 //////////////////////////
393 425
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 EXPECT_EQ(expected[i].fsid, actual[i].fsid) << test; 602 EXPECT_EQ(expected[i].fsid, actual[i].fsid) << test;
571 } 603 }
572 } 604 }
573 605
574 int ProfileState::GetAndClearComparisonCount() { 606 int ProfileState::GetAndClearComparisonCount() {
575 int result = num_comparisons_; 607 int result = num_comparisons_;
576 num_comparisons_ = 0; 608 num_comparisons_ = 0;
577 return result; 609 return result;
578 } 610 }
579 611
612 } // namespace
613
580 ///////////////////////////////// 614 /////////////////////////////////
581 // MediaFileSystemRegistryTest // 615 // MediaFileSystemRegistryTest //
582 ///////////////////////////////// 616 /////////////////////////////////
583 617
584 MediaFileSystemRegistryTest::MediaFileSystemRegistryTest() 618 MediaFileSystemRegistryTest::MediaFileSystemRegistryTest()
585 : ui_thread_(content::BrowserThread::UI, MessageLoop::current()), 619 : ui_thread_(content::BrowserThread::UI, MessageLoop::current()),
586 file_thread_(content::BrowserThread::FILE, MessageLoop::current()) { 620 file_thread_(content::BrowserThread::FILE, MessageLoop::current()) {
587 } 621 }
588 622
589 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) { 623 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) {
(...skipping 22 matching lines...) Expand all
612 return device_id; 646 return device_id;
613 } 647 }
614 648
615 std::string MediaFileSystemRegistryTest::AttachDevice( 649 std::string MediaFileSystemRegistryTest::AttachDevice(
616 MediaStorageUtil::Type type, 650 MediaStorageUtil::Type type,
617 const std::string& unique_id, 651 const std::string& unique_id,
618 const FilePath& location) { 652 const FilePath& location) {
619 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); 653 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id);
620 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); 654 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id));
621 string16 name = location.LossyDisplayName(); 655 string16 name = location.LossyDisplayName();
622 base::SystemMonitor::Get()->ProcessRemovableStorageAttached(device_id, name, 656 ProcessAttach(device_id, name, location.value());
623 location.value());
624 bool user_added = (type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM); 657 bool user_added = (type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM);
625 for (size_t i = 0; i < profile_states_.size(); ++i) { 658 for (size_t i = 0; i < profile_states_.size(); ++i) {
626 profile_states_[i]->GetMediaGalleriesPrefs()->AddGallery( 659 profile_states_[i]->GetMediaGalleriesPrefs()->AddGallery(
627 device_id, name, FilePath(), user_added); 660 device_id, name, FilePath(), user_added);
628 } 661 }
629 MessageLoop::current()->RunUntilIdle(); 662 MessageLoop::current()->RunUntilIdle();
630 return device_id; 663 return device_id;
631 } 664 }
632 665
633 void MediaFileSystemRegistryTest::DetachDevice(const std::string& device_id) { 666 void MediaFileSystemRegistryTest::DetachDevice(const std::string& device_id) {
634 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); 667 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id));
635 base::SystemMonitor::Get()->ProcessRemovableStorageDetached(device_id); 668 ProcessDetach(device_id);
636 MessageLoop::current()->RunUntilIdle(); 669 MessageLoop::current()->RunUntilIdle();
637 } 670 }
638 671
639 void MediaFileSystemRegistryTest::SetGalleryPermission( 672 void MediaFileSystemRegistryTest::SetGalleryPermission(
640 ProfileState* profile_state, extensions::Extension* extension, 673 ProfileState* profile_state, extensions::Extension* extension,
641 const std::string& device_id, bool has_access) { 674 const std::string& device_id, bool has_access) {
642 MediaGalleriesPreferences* preferences = 675 MediaGalleriesPreferences* preferences =
643 profile_state->GetMediaGalleriesPrefs(); 676 profile_state->GetMediaGalleriesPrefs();
644 MediaGalleryPrefIdSet pref_id = 677 MediaGalleryPrefIdSet pref_id =
645 preferences->LookUpGalleriesByDeviceId(device_id); 678 preferences->LookUpGalleriesByDeviceId(device_id);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 MediaFileSystemInfo info(path.AsUTF8Unsafe(), path, std::string(), 757 MediaFileSystemInfo info(path.AsUTF8Unsafe(), path, std::string(),
725 0, 0, false, false); 758 0, 0, false, false);
726 result.push_back(info); 759 result.push_back(info);
727 } 760 }
728 } 761 }
729 std::sort(result.begin(), result.end(), MediaFileSystemInfoComparator); 762 std::sort(result.begin(), result.end(), MediaFileSystemInfoComparator);
730 return result; 763 return result;
731 } 764 }
732 765
733 void MediaFileSystemRegistryTest::SetUp() { 766 void MediaFileSystemRegistryTest::SetUp() {
734 #if defined(OS_MACOSX) 767 // Need to create BrowserMainParts here? Or does one of these harnesses do it?
vandebo (ex-Chrome) 2013/01/18 18:42:58 I don't think a BrowserMainParts is created... not
Greg Billock 2013/01/22 20:00:39 Yeah, I looked into that, and got nowhere. Used th
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(); 768 ChromeRenderViewHostTestHarness::SetUp();
741 DeleteContents(); 769 DeleteContents();
742 SetRenderProcessHostFactory(&rph_factory_); 770 SetRenderProcessHostFactory(&rph_factory_);
743 771
744 TestMediaStorageUtil::SetTestingMode(); 772 TestMediaStorageUtil::SetTestingMode();
745 test_file_system_context_ = new TestMediaFileSystemContext( 773 test_file_system_context_ = new TestMediaFileSystemContext(
746 g_browser_process->media_file_system_registry()); 774 g_browser_process->media_file_system_registry());
747 775
748 ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir()); 776 ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir());
749 empty_dir_ = galleries_dir_.path().AppendASCII("empty"); 777 empty_dir_ = galleries_dir_.path().AppendASCII("empty");
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 // Add permission for new non-default gallery. 908 // Add permission for new non-default gallery.
881 ProfileState* profile_state = GetProfileState(0U); 909 ProfileState* profile_state = GetProfileState(0U);
882 SetGalleryPermission(profile_state, 910 SetGalleryPermission(profile_state,
883 profile_state->all_permission_extension(), 911 profile_state->all_permission_extension(),
884 device_id, 912 device_id,
885 true /*has access*/); 913 true /*has access*/);
886 CheckNewGalleryInfo(profile_state, galleries_info, empty_dir(), 914 CheckNewGalleryInfo(profile_state, galleries_info, empty_dir(),
887 false /*removable*/, false /* media device */); 915 false /*removable*/, false /* media device */);
888 } 916 }
889 917
890 } // namespace
891
892 } // namespace chrome 918 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698