| 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 "chrome/browser/media_galleries/media_file_system_registry.h" | 7 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
| 8 | 8 |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <set> | 13 #include <set> |
| 14 #include <vector> |
| 14 | 15 |
| 15 #include "base/bind_helpers.h" | 16 #include "base/bind_helpers.h" |
| 16 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 17 #include "base/files/file_util.h" | 18 #include "base/files/file_util.h" |
| 18 #include "base/files/scoped_temp_dir.h" | 19 #include "base/files/scoped_temp_dir.h" |
| 19 #include "base/macros.h" | 20 #include "base/macros.h" |
| 20 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
| 21 #include "base/memory/ref_counted.h" | 22 #include "base/memory/ref_counted.h" |
| 22 #include "base/memory/scoped_vector.h" | |
| 23 #include "base/path_service.h" | 23 #include "base/path_service.h" |
| 24 #include "base/run_loop.h" | 24 #include "base/run_loop.h" |
| 25 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 27 #include "base/threading/sequenced_worker_pool.h" | 27 #include "base/threading/sequenced_worker_pool.h" |
| 28 #include "base/values.h" | 28 #include "base/values.h" |
| 29 #include "build/build_config.h" | 29 #include "build/build_config.h" |
| 30 #include "chrome/browser/extensions/extension_service.h" | 30 #include "chrome/browser/extensions/extension_service.h" |
| 31 #include "chrome/browser/extensions/test_extension_system.h" | 31 #include "chrome/browser/extensions/test_extension_system.h" |
| 32 #include "chrome/browser/media_galleries/media_file_system_context.h" | 32 #include "chrome/browser/media_galleries/media_file_system_context.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 return path.BaseName().LossyDisplayName(); | 273 return path.BaseName().LossyDisplayName(); |
| 274 #else | 274 #else |
| 275 return path.LossyDisplayName(); | 275 return path.LossyDisplayName(); |
| 276 #endif | 276 #endif |
| 277 } | 277 } |
| 278 | 278 |
| 279 } // namespace | 279 } // namespace |
| 280 | 280 |
| 281 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness { | 281 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness { |
| 282 public: | 282 public: |
| 283 MediaFileSystemRegistryTest() = default; |
| 284 |
| 285 ~MediaFileSystemRegistryTest() override = default; |
| 286 |
| 283 void CreateProfileState(size_t profile_count); | 287 void CreateProfileState(size_t profile_count); |
| 284 | 288 |
| 285 ProfileState* GetProfileState(size_t i); | 289 ProfileState* GetProfileState(size_t i); |
| 286 | 290 |
| 287 MediaGalleriesPreferences* GetPreferences(Profile* profile); | 291 MediaGalleriesPreferences* GetPreferences(Profile* profile); |
| 288 | 292 |
| 289 base::FilePath empty_dir() { | 293 base::FilePath empty_dir() { |
| 290 return empty_dir_; | 294 return empty_dir_; |
| 291 } | 295 } |
| 292 | 296 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 // Needed for extension service & friends to work. | 377 // Needed for extension service & friends to work. |
| 374 | 378 |
| 375 #if defined(OS_CHROMEOS) | 379 #if defined(OS_CHROMEOS) |
| 376 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 380 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 377 chromeos::ScopedTestCrosSettings test_cros_settings_; | 381 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 378 std::unique_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | 382 std::unique_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
| 379 #endif | 383 #endif |
| 380 | 384 |
| 381 MockProfileSharedRenderProcessHostFactory rph_factory_; | 385 MockProfileSharedRenderProcessHostFactory rph_factory_; |
| 382 | 386 |
| 383 ScopedVector<ProfileState> profile_states_; | 387 std::vector<std::unique_ptr<ProfileState>> profile_states_; |
| 388 |
| 389 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest); |
| 384 }; | 390 }; |
| 385 | 391 |
| 386 namespace { | 392 namespace { |
| 387 | 393 |
| 388 bool MediaFileSystemInfoComparator(const MediaFileSystemInfo& a, | 394 bool MediaFileSystemInfoComparator(const MediaFileSystemInfo& a, |
| 389 const MediaFileSystemInfo& b) { | 395 const MediaFileSystemInfo& b) { |
| 390 CHECK_NE(a.name, b.name); // Name must be unique. | 396 CHECK_NE(a.name, b.name); // Name must be unique. |
| 391 return a.name < b.name; | 397 return a.name < b.name; |
| 392 } | 398 } |
| 393 | 399 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 } | 603 } |
| 598 | 604 |
| 599 } // namespace | 605 } // namespace |
| 600 | 606 |
| 601 ///////////////////////////////// | 607 ///////////////////////////////// |
| 602 // MediaFileSystemRegistryTest // | 608 // MediaFileSystemRegistryTest // |
| 603 ///////////////////////////////// | 609 ///////////////////////////////// |
| 604 | 610 |
| 605 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) { | 611 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) { |
| 606 for (size_t i = 0; i < profile_count; ++i) { | 612 for (size_t i = 0; i < profile_count; ++i) { |
| 607 ProfileState* state = new ProfileState(&rph_factory_); | 613 profile_states_.push_back(base::MakeUnique<ProfileState>(&rph_factory_)); |
| 608 profile_states_.push_back(state); | |
| 609 } | 614 } |
| 610 } | 615 } |
| 611 | 616 |
| 612 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) { | 617 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) { |
| 613 return profile_states_[i]; | 618 return profile_states_[i].get(); |
| 614 } | 619 } |
| 615 | 620 |
| 616 MediaGalleriesPreferences* MediaFileSystemRegistryTest::GetPreferences( | 621 MediaGalleriesPreferences* MediaFileSystemRegistryTest::GetPreferences( |
| 617 Profile* profile) { | 622 Profile* profile) { |
| 618 MediaGalleriesPreferences* prefs = registry()->GetPreferences(profile); | 623 MediaGalleriesPreferences* prefs = registry()->GetPreferences(profile); |
| 619 base::RunLoop loop; | 624 base::RunLoop loop; |
| 620 prefs->EnsureInitialized(loop.QuitClosure()); | 625 prefs->EnsureInitialized(loop.QuitClosure()); |
| 621 loop.Run(); | 626 loop.Run(); |
| 622 return prefs; | 627 return prefs; |
| 623 } | 628 } |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 fs_info.begin()->second.fsid).empty()); | 1085 fs_info.begin()->second.fsid).empty()); |
| 1081 | 1086 |
| 1082 // Revoke permission and ensure that the file system is revoked. | 1087 // Revoke permission and ensure that the file system is revoked. |
| 1083 SetGalleryPermission(profile_state, | 1088 SetGalleryPermission(profile_state, |
| 1084 profile_state->regular_permission_extension(), | 1089 profile_state->regular_permission_extension(), |
| 1085 device_id, | 1090 device_id, |
| 1086 false /*has access*/); | 1091 false /*has access*/); |
| 1087 EXPECT_TRUE(test_file_system_context()->GetRegisteredPath( | 1092 EXPECT_TRUE(test_file_system_context()->GetRegisteredPath( |
| 1088 fs_info.begin()->second.fsid).empty()); | 1093 fs_info.begin()->second.fsid).empty()); |
| 1089 } | 1094 } |
| OLD | NEW |