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" | |
| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 EXPECT_TRUE(dict->HasKey(MediaFileSystemRegistry::kGalleryIdKey)) << name; | 183 EXPECT_TRUE(dict->HasKey(MediaFileSystemRegistry::kGalleryIdKey)) << name; |
| 183 | 184 |
| 184 // Check name. | 185 // Check name. |
| 185 EXPECT_TRUE(dict->HasKey(MediaFileSystemRegistry::kNameKey)) << name; | 186 EXPECT_TRUE(dict->HasKey(MediaFileSystemRegistry::kNameKey)) << name; |
| 186 std::string gallery_name; | 187 std::string gallery_name; |
| 187 EXPECT_TRUE(dict->GetString(MediaFileSystemRegistry::kNameKey, | 188 EXPECT_TRUE(dict->GetString(MediaFileSystemRegistry::kNameKey, |
| 188 &gallery_name)) << name; | 189 &gallery_name)) << name; |
| 189 EXPECT_FALSE(gallery_name.empty()) << name; | 190 EXPECT_FALSE(gallery_name.empty()) << name; |
| 190 } | 191 } |
| 191 | 192 |
| 193 } // namespace | |
| 194 | |
| 192 class TestMediaStorageUtil : public MediaStorageUtil { | 195 class TestMediaStorageUtil : public MediaStorageUtil { |
| 193 public: | 196 public: |
| 194 static void SetTestingMode(); | 197 static void SetTestingMode(); |
| 195 | 198 |
| 196 static bool GetDeviceInfoFromPathTestFunction(const FilePath& path, | 199 static bool GetDeviceInfoFromPathTestFunction(const FilePath& path, |
| 197 std::string* device_id, | 200 std::string* device_id, |
| 198 string16* device_name, | 201 string16* device_name, |
| 199 FilePath* relative_path); | 202 FilePath* relative_path); |
| 200 }; | 203 }; |
| 201 | 204 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 | 308 |
| 306 void InitForGalleryNamesTest(std::set<std::string>* gallery_names); | 309 void InitForGalleryNamesTest(std::set<std::string>* gallery_names); |
| 307 | 310 |
| 308 void CheckNewGallery(ProfileState* profile_state, | 311 void CheckNewGallery(ProfileState* profile_state, |
| 309 const std::set<std::string>& gallery_names, | 312 const std::set<std::string>& gallery_names, |
| 310 bool removable); | 313 bool removable); |
| 311 | 314 |
| 312 std::vector<MediaFileSystemInfo> GetAutoAddedGalleries( | 315 std::vector<MediaFileSystemInfo> GetAutoAddedGalleries( |
| 313 ProfileState* profile_state); | 316 ProfileState* profile_state); |
| 314 | 317 |
| 318 void ProcessAttach(const std::string& id, | |
| 319 const string16& name, | |
| 320 const FilePath::StringType& location) { | |
| 321 RemovableStorageNotifications::GetInstance()->ProcessAttach( | |
|
Hongbo Min
2013/01/17 09:38:03
Is RemovableStorageNotifications instance always c
Greg Billock
2013/01/17 22:10:45
Good question. This test isn't fully converted yet
| |
| 322 id, name, location); | |
| 323 } | |
| 324 | |
| 325 void ProcessDetach(const std::string& id) { | |
| 326 RemovableStorageNotifications::GetInstance()->ProcessDetach(id); | |
| 327 } | |
| 328 | |
| 315 protected: | 329 protected: |
| 316 void SetUp(); | 330 void SetUp(); |
| 317 void TearDown(); | 331 void TearDown(); |
| 318 | 332 |
| 319 private: | 333 private: |
| 320 // This makes sure that at least one default gallery exists on the file | 334 // This makes sure that at least one default gallery exists on the file |
| 321 // system. | 335 // system. |
| 322 EnsureMediaDirectoriesExists media_directories_; | 336 EnsureMediaDirectoriesExists media_directories_; |
| 323 | 337 |
| 324 // Some test gallery directories. | 338 // Some test gallery directories. |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 return device_id; | 594 return device_id; |
| 581 } | 595 } |
| 582 | 596 |
| 583 std::string MediaFileSystemRegistryTest::AttachDevice( | 597 std::string MediaFileSystemRegistryTest::AttachDevice( |
| 584 MediaStorageUtil::Type type, | 598 MediaStorageUtil::Type type, |
| 585 const std::string& unique_id, | 599 const std::string& unique_id, |
| 586 const FilePath& location) { | 600 const FilePath& location) { |
| 587 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); | 601 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); |
| 588 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); | 602 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); |
| 589 string16 name = location.LossyDisplayName(); | 603 string16 name = location.LossyDisplayName(); |
| 590 base::SystemMonitor::Get()->ProcessRemovableStorageAttached(device_id, name, | 604 ProcessAttach(device_id, name, location.value()); |
| 591 location.value()); | |
| 592 bool user_added = (type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM); | 605 bool user_added = (type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM); |
| 593 for (size_t i = 0; i < profile_states_.size(); ++i) { | 606 for (size_t i = 0; i < profile_states_.size(); ++i) { |
| 594 profile_states_[i]->GetMediaGalleriesPrefs()->AddGallery( | 607 profile_states_[i]->GetMediaGalleriesPrefs()->AddGallery( |
| 595 device_id, name, FilePath(), user_added); | 608 device_id, name, FilePath(), user_added); |
| 596 } | 609 } |
| 597 MessageLoop::current()->RunUntilIdle(); | 610 MessageLoop::current()->RunUntilIdle(); |
| 598 return device_id; | 611 return device_id; |
| 599 } | 612 } |
| 600 | 613 |
| 601 void MediaFileSystemRegistryTest::DetachDevice(const std::string& device_id) { | 614 void MediaFileSystemRegistryTest::DetachDevice(const std::string& device_id) { |
| 602 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); | 615 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); |
| 603 base::SystemMonitor::Get()->ProcessRemovableStorageDetached(device_id); | 616 ProcessDetach(device_id); |
| 604 MessageLoop::current()->RunUntilIdle(); | 617 MessageLoop::current()->RunUntilIdle(); |
| 605 } | 618 } |
| 606 | 619 |
| 607 void MediaFileSystemRegistryTest::SetGalleryPermission( | 620 void MediaFileSystemRegistryTest::SetGalleryPermission( |
| 608 ProfileState* profile_state, extensions::Extension* extension, | 621 ProfileState* profile_state, extensions::Extension* extension, |
| 609 const std::string& device_id, bool has_access) { | 622 const std::string& device_id, bool has_access) { |
| 610 MediaGalleriesPreferences* preferences = | 623 MediaGalleriesPreferences* preferences = |
| 611 profile_state->GetMediaGalleriesPrefs(); | 624 profile_state->GetMediaGalleriesPrefs(); |
| 612 MediaGalleryPrefIdSet pref_id = | 625 MediaGalleryPrefIdSet pref_id = |
| 613 preferences->LookUpGalleriesByDeviceId(device_id); | 626 preferences->LookUpGalleriesByDeviceId(device_id); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 839 empty_dir()); | 852 empty_dir()); |
| 840 // Add permission for new non-default gallery. | 853 // Add permission for new non-default gallery. |
| 841 ProfileState* profile_state = GetProfileState(0U); | 854 ProfileState* profile_state = GetProfileState(0U); |
| 842 SetGalleryPermission(profile_state, | 855 SetGalleryPermission(profile_state, |
| 843 profile_state->all_permission_extension(), | 856 profile_state->all_permission_extension(), |
| 844 device_id, | 857 device_id, |
| 845 true /*has access*/); | 858 true /*has access*/); |
| 846 CheckNewGallery(profile_state, gallery_names, false /*not removable*/); | 859 CheckNewGallery(profile_state, gallery_names, false /*not removable*/); |
| 847 } | 860 } |
| 848 | 861 |
| 849 } // namespace | |
| 850 | |
| 851 } // namespace chrome | 862 } // namespace chrome |
| OLD | NEW |