| 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 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "content/public/browser/render_process_host_factory.h" | 45 #include "content/public/browser/render_process_host_factory.h" |
| 46 #include "content/public/browser/web_contents.h" | 46 #include "content/public/browser/web_contents.h" |
| 47 #include "content/public/test/mock_render_process_host.h" | 47 #include "content/public/test/mock_render_process_host.h" |
| 48 #include "content/public/test/test_browser_thread.h" | 48 #include "content/public/test/test_browser_thread.h" |
| 49 #include "content/public/test/web_contents_tester.h" | 49 #include "content/public/test/web_contents_tester.h" |
| 50 #include "extensions/browser/extension_system.h" | 50 #include "extensions/browser/extension_system.h" |
| 51 #include "extensions/common/extension.h" | 51 #include "extensions/common/extension.h" |
| 52 #include "testing/gtest/include/gtest/gtest.h" | 52 #include "testing/gtest/include/gtest/gtest.h" |
| 53 | 53 |
| 54 #if defined(OS_CHROMEOS) | 54 #if defined(OS_CHROMEOS) |
| 55 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" | |
| 56 #include "chrome/browser/chromeos/settings/cros_settings.h" | 55 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 57 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 56 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 58 #endif | 57 #endif |
| 59 | 58 |
| 60 using content::BrowserThread; | 59 using content::BrowserThread; |
| 61 using storage_monitor::StorageInfo; | 60 using storage_monitor::StorageInfo; |
| 62 using storage_monitor::StorageMonitor; | 61 using storage_monitor::StorageMonitor; |
| 63 using storage_monitor::TestStorageMonitor; | 62 using storage_monitor::TestStorageMonitor; |
| 64 | 63 |
| 65 // Not anonymous so it can be friends with MediaFileSystemRegistry. | 64 // Not anonymous so it can be friends with MediaFileSystemRegistry. |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 base::FilePath dcim_dir_; | 371 base::FilePath dcim_dir_; |
| 373 | 372 |
| 374 // MediaFileSystemRegistry owns this. | 373 // MediaFileSystemRegistry owns this. |
| 375 TestMediaFileSystemContext* test_file_system_context_; | 374 TestMediaFileSystemContext* test_file_system_context_; |
| 376 | 375 |
| 377 // Needed for extension service & friends to work. | 376 // Needed for extension service & friends to work. |
| 378 | 377 |
| 379 #if defined(OS_CHROMEOS) | 378 #if defined(OS_CHROMEOS) |
| 380 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 379 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 381 chromeos::ScopedTestCrosSettings test_cros_settings_; | 380 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 382 std::unique_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | |
| 383 #endif | 381 #endif |
| 384 | 382 |
| 385 MockProfileSharedRenderProcessHostFactory rph_factory_; | 383 MockProfileSharedRenderProcessHostFactory rph_factory_; |
| 386 | 384 |
| 387 std::vector<std::unique_ptr<ProfileState>> profile_states_; | 385 std::vector<std::unique_ptr<ProfileState>> profile_states_; |
| 388 | 386 |
| 389 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest); | 387 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest); |
| 390 }; | 388 }; |
| 391 | 389 |
| 392 namespace { | 390 namespace { |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 void MediaFileSystemRegistryTest::SetUp() { | 768 void MediaFileSystemRegistryTest::SetUp() { |
| 771 ChromeRenderViewHostTestHarness::SetUp(); | 769 ChromeRenderViewHostTestHarness::SetUp(); |
| 772 ASSERT_TRUE(TestStorageMonitor::CreateAndInstall()); | 770 ASSERT_TRUE(TestStorageMonitor::CreateAndInstall()); |
| 773 | 771 |
| 774 DeleteContents(); | 772 DeleteContents(); |
| 775 SetRenderProcessHostFactory(&rph_factory_); | 773 SetRenderProcessHostFactory(&rph_factory_); |
| 776 | 774 |
| 777 test_file_system_context_ = new TestMediaFileSystemContext( | 775 test_file_system_context_ = new TestMediaFileSystemContext( |
| 778 g_browser_process->media_file_system_registry()); | 776 g_browser_process->media_file_system_registry()); |
| 779 | 777 |
| 780 #if defined(OS_CHROMEOS) | |
| 781 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); | |
| 782 #endif | |
| 783 | |
| 784 ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir()); | 778 ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir()); |
| 785 empty_dir_ = galleries_dir_.GetPath().AppendASCII("empty"); | 779 empty_dir_ = galleries_dir_.GetPath().AppendASCII("empty"); |
| 786 ASSERT_TRUE(base::CreateDirectory(empty_dir_)); | 780 ASSERT_TRUE(base::CreateDirectory(empty_dir_)); |
| 787 dcim_dir_ = galleries_dir_.GetPath().AppendASCII("with_dcim"); | 781 dcim_dir_ = galleries_dir_.GetPath().AppendASCII("with_dcim"); |
| 788 ASSERT_TRUE(base::CreateDirectory(dcim_dir_)); | 782 ASSERT_TRUE(base::CreateDirectory(dcim_dir_)); |
| 789 ASSERT_TRUE(base::CreateDirectory( | 783 ASSERT_TRUE(base::CreateDirectory( |
| 790 dcim_dir_.Append(storage_monitor::kDCIMDirectoryName))); | 784 dcim_dir_.Append(storage_monitor::kDCIMDirectoryName))); |
| 791 } | 785 } |
| 792 | 786 |
| 793 void MediaFileSystemRegistryTest::TearDown() { | 787 void MediaFileSystemRegistryTest::TearDown() { |
| 794 profile_states_.clear(); | 788 profile_states_.clear(); |
| 795 MediaFileSystemRegistry* registry = | 789 MediaFileSystemRegistry* registry = |
| 796 g_browser_process->media_file_system_registry(); | 790 g_browser_process->media_file_system_registry(); |
| 797 EXPECT_EQ(0U, GetExtensionGalleriesHostCount(registry)); | 791 EXPECT_EQ(0U, GetExtensionGalleriesHostCount(registry)); |
| 798 | 792 |
| 799 #if defined(OS_CHROMEOS) | |
| 800 test_user_manager_.reset(); | |
| 801 #endif | |
| 802 | |
| 803 // The TestingProfile must be destroyed before the TestingBrowserProcess | 793 // The TestingProfile must be destroyed before the TestingBrowserProcess |
| 804 // because it uses it in its destructor. | 794 // because it uses it in its destructor. |
| 805 ChromeRenderViewHostTestHarness::TearDown(); | 795 ChromeRenderViewHostTestHarness::TearDown(); |
| 806 | 796 |
| 807 // The MediaFileSystemRegistry owned by the TestingBrowserProcess must be | 797 // The MediaFileSystemRegistry owned by the TestingBrowserProcess must be |
| 808 // destroyed before the StorageMonitor because it calls | 798 // destroyed before the StorageMonitor because it calls |
| 809 // StorageMonitor::RemoveObserver() in its destructor. | 799 // StorageMonitor::RemoveObserver() in its destructor. |
| 810 TestingBrowserProcess::DeleteInstance(); | 800 TestingBrowserProcess::DeleteInstance(); |
| 811 | 801 |
| 812 TestStorageMonitor::Destroy(); | 802 TestStorageMonitor::Destroy(); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 fs_info.begin()->second.fsid).empty()); | 1075 fs_info.begin()->second.fsid).empty()); |
| 1086 | 1076 |
| 1087 // Revoke permission and ensure that the file system is revoked. | 1077 // Revoke permission and ensure that the file system is revoked. |
| 1088 SetGalleryPermission(profile_state, | 1078 SetGalleryPermission(profile_state, |
| 1089 profile_state->regular_permission_extension(), | 1079 profile_state->regular_permission_extension(), |
| 1090 device_id, | 1080 device_id, |
| 1091 false /*has access*/); | 1081 false /*has access*/); |
| 1092 EXPECT_TRUE(test_file_system_context()->GetRegisteredPath( | 1082 EXPECT_TRUE(test_file_system_context()->GetRegisteredPath( |
| 1093 fs_info.begin()->second.fsid).empty()); | 1083 fs_info.begin()->second.fsid).empty()); |
| 1094 } | 1084 } |
| OLD | NEW |