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

Side by Side Diff: chrome/browser/media_galleries/win/mtp_device_delegate_impl_win_unittest.cc

Issue 16703025: [StorageMonitor] Move StorageMonitor ownership to BrowserProcessImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 7 years, 5 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
OLDNEW
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
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 monitor_ = new test::TestStorageMonitorWin(
78 mount_watcher, portable_device_watcher)); 82 mount_watcher, portable_device_watcher);
83 TestingBrowserProcess* browser_process = TestingBrowserProcess::GetGlobal();
84 if (browser_process)
vandebo (ex-Chrome) 2013/07/10 16:57:45 When will this be false? If it is false, monitor_
Greg Billock 2013/07/10 21:11:16 I think this was for platforms where there are sti
vandebo (ex-Chrome) 2013/07/11 15:53:00 The quickest way to make sure you have it all figu
Greg Billock 2013/07/11 20:53:35 Yes. Where I'm confident we're fine I just switche
85 browser_process->SetStorageMonitor(monitor_);
86
79 base::RunLoop runloop; 87 base::RunLoop runloop;
80 monitor_->EnsureInitialized(runloop.QuitClosure()); 88 monitor_->EnsureInitialized(runloop.QuitClosure());
81 runloop.Run(); 89 runloop.Run();
82 90
83 extensions::TestExtensionSystem* extension_system( 91 extensions::TestExtensionSystem* extension_system(
84 static_cast<extensions::TestExtensionSystem*>( 92 static_cast<extensions::TestExtensionSystem*>(
85 extensions::ExtensionSystem::Get(profile()))); 93 extensions::ExtensionSystem::Get(profile())));
86 extension_system->CreateExtensionService( 94 extension_system->CreateExtensionService(
87 CommandLine::ForCurrentProcess(), base::FilePath(), false); 95 CommandLine::ForCurrentProcess(), base::FilePath(), false);
88 96
89 std::vector<std::string> all_permissions; 97 std::vector<std::string> all_permissions;
90 all_permissions.push_back("allAutoDetected"); 98 all_permissions.push_back("allAutoDetected");
91 all_permissions.push_back("read"); 99 all_permissions.push_back("read");
92 extension_ = AddMediaGalleriesApp("all", all_permissions, profile()); 100 extension_ = AddMediaGalleriesApp("all", all_permissions, profile());
93 } 101 }
94 102
95 void MTPDeviceDelegateImplWinTest::TearDown() { 103 void MTPDeviceDelegateImplWinTest::TearDown() {
96 monitor_.reset(); 104 // Windows storage monitor must be destroyed on the same thread
105 // as construction.
106 test::TestStorageMonitor::RemoveSingleton();
97 107
98 ChromeRenderViewHostTestHarness::TearDown(); 108 ChromeRenderViewHostTestHarness::TearDown();
99 } 109 }
100 110
101 void MTPDeviceDelegateImplWinTest::ProcessAttach( 111 void MTPDeviceDelegateImplWinTest::ProcessAttach(
102 const std::string& id, 112 const std::string& id,
103 const string16& label, 113 const string16& label,
104 const base::FilePath::StringType& location) { 114 const base::FilePath::StringType& location) {
105 StorageInfo info(id, string16(), location, label, string16(), string16(), 0); 115 StorageInfo info(id, string16(), location, label, string16(), string16(), 0);
106 monitor_->receiver()->ProcessAttach(info); 116 monitor_->receiver()->ProcessAttach(info);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 if (info.path == location) { 168 if (info.path == location) {
159 CheckGalleryInfo(info, location.LossyDisplayName(), location, true, true); 169 CheckGalleryInfo(info, location.LossyDisplayName(), location, true, true);
160 checked = true; 170 checked = true;
161 break; 171 break;
162 } 172 }
163 } 173 }
164 EXPECT_TRUE(checked); 174 EXPECT_TRUE(checked);
165 } 175 }
166 176
167 } // namespace chrome 177 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698