| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/extension_system.h" | 14 #include "chrome/browser/extensions/extension_system.h" |
| 15 #include "chrome/browser/extensions/test_extension_system.h" | 15 #include "chrome/browser/extensions/test_extension_system.h" |
| 16 #include "chrome/browser/media_galleries/media_file_system_registry.h" | 16 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
| 17 #include "chrome/browser/media_galleries/media_galleries_test_util.h" | 17 #include "chrome/browser/media_galleries/media_galleries_test_util.h" |
| 18 #include "chrome/browser/storage_monitor/storage_info.h" | 18 #include "chrome/browser/storage_monitor/storage_info.h" |
| 19 #include "chrome/browser/storage_monitor/storage_monitor.h" | 19 #include "chrome/browser/storage_monitor/storage_monitor.h" |
| 20 #include "chrome/browser/storage_monitor/test_portable_device_watcher_win.h" | 20 #include "chrome/browser/storage_monitor/test_portable_device_watcher_win.h" |
| 21 #include "chrome/browser/storage_monitor/test_storage_monitor.h" |
| 21 #include "chrome/browser/storage_monitor/test_storage_monitor_win.h" | 22 #include "chrome/browser/storage_monitor/test_storage_monitor_win.h" |
| 22 #include "chrome/browser/storage_monitor/test_volume_mount_watcher_win.h" | 23 #include "chrome/browser/storage_monitor/test_volume_mount_watcher_win.h" |
| 23 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 24 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 25 #include "chrome/test/base/testing_browser_process.h" |
| 24 #include "chrome/test/base/testing_profile.h" | 26 #include "chrome/test/base/testing_profile.h" |
| 25 #include "content/public/browser/render_view_host.h" | 27 #include "content/public/browser/render_view_host.h" |
| 26 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 30 |
| 29 namespace chrome { | 31 namespace chrome { |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| 32 | 34 |
| 33 typedef std::map<MediaGalleryPrefId, MediaFileSystemInfo> FSInfoMap; | 35 typedef std::map<MediaGalleryPrefId, MediaFileSystemInfo> FSInfoMap; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 53 const base::FilePath::StringType& location); | 55 const base::FilePath::StringType& location); |
| 54 std::string AttachDevice(StorageInfo::Type type, | 56 std::string AttachDevice(StorageInfo::Type type, |
| 55 const std::string& unique_id, | 57 const std::string& unique_id, |
| 56 const base::FilePath& location); | 58 const base::FilePath& location); |
| 57 void CheckGalleryInfo(const MediaFileSystemInfo& info, | 59 void CheckGalleryInfo(const MediaFileSystemInfo& info, |
| 58 const string16& name, | 60 const string16& name, |
| 59 const base::FilePath& path, | 61 const base::FilePath& path, |
| 60 bool removable, | 62 bool removable, |
| 61 bool media_device); | 63 bool media_device); |
| 62 | 64 |
| 63 // Note: need to make this weak ptr once ownership moves to g_browser_process | 65 // Pointer to the storage monitor. Owned by TestingBrowserProcess. |
| 64 scoped_ptr<test::TestStorageMonitorWin> monitor_; | 66 test::TestStorageMonitorWin* monitor_; |
| 65 scoped_refptr<extensions::Extension> extension_; | 67 scoped_refptr<extensions::Extension> extension_; |
| 66 | 68 |
| 67 EnsureMediaDirectoriesExists media_directories_; | 69 EnsureMediaDirectoriesExists media_directories_; |
| 68 }; | 70 }; |
| 69 | 71 |
| 70 void MTPDeviceDelegateImplWinTest::SetUp() { | 72 void MTPDeviceDelegateImplWinTest::SetUp() { |
| 71 ChromeRenderViewHostTestHarness::SetUp(); | 73 ChromeRenderViewHostTestHarness::SetUp(); |
| 74 |
| 75 test::TestStorageMonitor::RemoveSingleton(); |
| 72 test::TestPortableDeviceWatcherWin* portable_device_watcher = | 76 test::TestPortableDeviceWatcherWin* portable_device_watcher = |
| 73 new test::TestPortableDeviceWatcherWin; | 77 new test::TestPortableDeviceWatcherWin; |
| 74 test::TestVolumeMountWatcherWin* mount_watcher = | 78 test::TestVolumeMountWatcherWin* mount_watcher = |
| 75 new test::TestVolumeMountWatcherWin; | 79 new test::TestVolumeMountWatcherWin; |
| 76 portable_device_watcher->set_use_dummy_mtp_storage_info(true); | 80 portable_device_watcher->set_use_dummy_mtp_storage_info(true); |
| 77 monitor_.reset(new test::TestStorageMonitorWin( | 81 scoped_ptr<test::TestStorageMonitorWin> monitor( |
| 78 mount_watcher, portable_device_watcher)); | 82 new test::TestStorageMonitorWin( |
| 83 mount_watcher, portable_device_watcher)); |
| 84 TestingBrowserProcess* browser_process = TestingBrowserProcess::GetGlobal(); |
| 85 DCHECK(browser_process); |
| 86 monitor_ = monitor.get(); |
| 87 browser_process->SetStorageMonitor(monitor.Pass()); |
| 88 |
| 79 base::RunLoop runloop; | 89 base::RunLoop runloop; |
| 80 monitor_->EnsureInitialized(runloop.QuitClosure()); | 90 monitor_->EnsureInitialized(runloop.QuitClosure()); |
| 81 runloop.Run(); | 91 runloop.Run(); |
| 82 | 92 |
| 83 extensions::TestExtensionSystem* extension_system( | 93 extensions::TestExtensionSystem* extension_system( |
| 84 static_cast<extensions::TestExtensionSystem*>( | 94 static_cast<extensions::TestExtensionSystem*>( |
| 85 extensions::ExtensionSystem::Get(profile()))); | 95 extensions::ExtensionSystem::Get(profile()))); |
| 86 extension_system->CreateExtensionService( | 96 extension_system->CreateExtensionService( |
| 87 CommandLine::ForCurrentProcess(), base::FilePath(), false); | 97 CommandLine::ForCurrentProcess(), base::FilePath(), false); |
| 88 | 98 |
| 89 std::vector<std::string> all_permissions; | 99 std::vector<std::string> all_permissions; |
| 90 all_permissions.push_back("allAutoDetected"); | 100 all_permissions.push_back("allAutoDetected"); |
| 91 all_permissions.push_back("read"); | 101 all_permissions.push_back("read"); |
| 92 extension_ = AddMediaGalleriesApp("all", all_permissions, profile()); | 102 extension_ = AddMediaGalleriesApp("all", all_permissions, profile()); |
| 93 } | 103 } |
| 94 | 104 |
| 95 void MTPDeviceDelegateImplWinTest::TearDown() { | 105 void MTPDeviceDelegateImplWinTest::TearDown() { |
| 96 monitor_.reset(); | 106 // Windows storage monitor must be destroyed on the same thread |
| 107 // as construction. |
| 108 test::TestStorageMonitor::RemoveSingleton(); |
| 97 | 109 |
| 98 ChromeRenderViewHostTestHarness::TearDown(); | 110 ChromeRenderViewHostTestHarness::TearDown(); |
| 99 } | 111 } |
| 100 | 112 |
| 101 void MTPDeviceDelegateImplWinTest::ProcessAttach( | 113 void MTPDeviceDelegateImplWinTest::ProcessAttach( |
| 102 const std::string& id, | 114 const std::string& id, |
| 103 const string16& label, | 115 const string16& label, |
| 104 const base::FilePath::StringType& location) { | 116 const base::FilePath::StringType& location) { |
| 105 StorageInfo info(id, string16(), location, label, string16(), string16(), 0); | 117 StorageInfo info(id, string16(), location, label, string16(), string16(), 0); |
| 106 monitor_->receiver()->ProcessAttach(info); | 118 monitor_->receiver()->ProcessAttach(info); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 if (info.path == location) { | 170 if (info.path == location) { |
| 159 CheckGalleryInfo(info, location.LossyDisplayName(), location, true, true); | 171 CheckGalleryInfo(info, location.LossyDisplayName(), location, true, true); |
| 160 checked = true; | 172 checked = true; |
| 161 break; | 173 break; |
| 162 } | 174 } |
| 163 } | 175 } |
| 164 EXPECT_TRUE(checked); | 176 EXPECT_TRUE(checked); |
| 165 } | 177 } |
| 166 | 178 |
| 167 } // namespace chrome | 179 } // namespace chrome |
| OLD | NEW |