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

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

Issue 23727009: Cleanup: Remove chrome namespace for storage monitor and media galleries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nit Created 7 years, 3 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 | Annotate | Revision Log
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/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/storage_monitor/test_storage_monitor.h" 21 #include "chrome/browser/storage_monitor/test_storage_monitor.h"
22 #include "chrome/browser/storage_monitor/test_storage_monitor_win.h" 22 #include "chrome/browser/storage_monitor/test_storage_monitor_win.h"
23 #include "chrome/browser/storage_monitor/test_volume_mount_watcher_win.h" 23 #include "chrome/browser/storage_monitor/test_volume_mount_watcher_win.h"
24 #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" 25 #include "chrome/test/base/testing_browser_process.h"
26 #include "chrome/test/base/testing_profile.h" 26 #include "chrome/test/base/testing_profile.h"
27 #include "content/public/browser/render_view_host.h" 27 #include "content/public/browser/render_view_host.h"
28 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
29 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
30 30
31 namespace chrome {
32
33 namespace { 31 namespace {
34 32
35 typedef std::map<MediaGalleryPrefId, MediaFileSystemInfo> FSInfoMap; 33 typedef std::map<MediaGalleryPrefId, MediaFileSystemInfo> FSInfoMap;
36 34
37 void GetGalleryInfoCallback( 35 void GetGalleryInfoCallback(
38 FSInfoMap* results, 36 FSInfoMap* results,
39 const std::vector<MediaFileSystemInfo>& file_systems) { 37 const std::vector<MediaFileSystemInfo>& file_systems) {
40 for (size_t i = 0; i < file_systems.size(); ++i) { 38 for (size_t i = 0; i < file_systems.size(); ++i) {
41 ASSERT_FALSE(ContainsKey(*results, file_systems[i].pref_id)); 39 ASSERT_FALSE(ContainsKey(*results, file_systems[i].pref_id));
42 (*results)[file_systems[i].pref_id] = file_systems[i]; 40 (*results)[file_systems[i].pref_id] = file_systems[i];
(...skipping 13 matching lines...) Expand all
56 std::string AttachDevice(StorageInfo::Type type, 54 std::string AttachDevice(StorageInfo::Type type,
57 const std::string& unique_id, 55 const std::string& unique_id,
58 const base::FilePath& location); 56 const base::FilePath& location);
59 void CheckGalleryInfo(const MediaFileSystemInfo& info, 57 void CheckGalleryInfo(const MediaFileSystemInfo& info,
60 const string16& name, 58 const string16& name,
61 const base::FilePath& path, 59 const base::FilePath& path,
62 bool removable, 60 bool removable,
63 bool media_device); 61 bool media_device);
64 62
65 // Pointer to the storage monitor. Owned by TestingBrowserProcess. 63 // Pointer to the storage monitor. Owned by TestingBrowserProcess.
66 test::TestStorageMonitorWin* monitor_; 64 TestStorageMonitorWin* monitor_;
67 scoped_refptr<extensions::Extension> extension_; 65 scoped_refptr<extensions::Extension> extension_;
68 66
69 EnsureMediaDirectoriesExists media_directories_; 67 EnsureMediaDirectoriesExists media_directories_;
70 }; 68 };
71 69
72 void MTPDeviceDelegateImplWinTest::SetUp() { 70 void MTPDeviceDelegateImplWinTest::SetUp() {
73 ChromeRenderViewHostTestHarness::SetUp(); 71 ChromeRenderViewHostTestHarness::SetUp();
74 72
75 test::TestStorageMonitor::RemoveSingleton(); 73 TestStorageMonitor::RemoveSingleton();
76 test::TestPortableDeviceWatcherWin* portable_device_watcher = 74 TestPortableDeviceWatcherWin* portable_device_watcher =
77 new test::TestPortableDeviceWatcherWin; 75 new TestPortableDeviceWatcherWin;
78 test::TestVolumeMountWatcherWin* mount_watcher = 76 TestVolumeMountWatcherWin* mount_watcher = new TestVolumeMountWatcherWin;
79 new test::TestVolumeMountWatcherWin;
80 portable_device_watcher->set_use_dummy_mtp_storage_info(true); 77 portable_device_watcher->set_use_dummy_mtp_storage_info(true);
81 scoped_ptr<test::TestStorageMonitorWin> monitor( 78 scoped_ptr<TestStorageMonitorWin> monitor(
82 new test::TestStorageMonitorWin( 79 new TestStorageMonitorWin(mount_watcher, portable_device_watcher));
83 mount_watcher, portable_device_watcher));
84 TestingBrowserProcess* browser_process = TestingBrowserProcess::GetGlobal(); 80 TestingBrowserProcess* browser_process = TestingBrowserProcess::GetGlobal();
85 DCHECK(browser_process); 81 DCHECK(browser_process);
86 monitor_ = monitor.get(); 82 monitor_ = monitor.get();
87 browser_process->SetStorageMonitor(monitor.Pass()); 83 browser_process->SetStorageMonitor(monitor.Pass());
88 84
89 base::RunLoop runloop; 85 base::RunLoop runloop;
90 monitor_->EnsureInitialized(runloop.QuitClosure()); 86 monitor_->EnsureInitialized(runloop.QuitClosure());
91 runloop.Run(); 87 runloop.Run();
92 88
93 extensions::TestExtensionSystem* extension_system( 89 extensions::TestExtensionSystem* extension_system(
94 static_cast<extensions::TestExtensionSystem*>( 90 static_cast<extensions::TestExtensionSystem*>(
95 extensions::ExtensionSystem::Get(profile()))); 91 extensions::ExtensionSystem::Get(profile())));
96 extension_system->CreateExtensionService( 92 extension_system->CreateExtensionService(
97 CommandLine::ForCurrentProcess(), base::FilePath(), false); 93 CommandLine::ForCurrentProcess(), base::FilePath(), false);
98 94
99 std::vector<std::string> all_permissions; 95 std::vector<std::string> all_permissions;
100 all_permissions.push_back("allAutoDetected"); 96 all_permissions.push_back("allAutoDetected");
101 all_permissions.push_back("read"); 97 all_permissions.push_back("read");
102 extension_ = AddMediaGalleriesApp("all", all_permissions, profile()); 98 extension_ = AddMediaGalleriesApp("all", all_permissions, profile());
103 } 99 }
104 100
105 void MTPDeviceDelegateImplWinTest::TearDown() { 101 void MTPDeviceDelegateImplWinTest::TearDown() {
106 // Windows storage monitor must be destroyed on the same thread 102 // Windows storage monitor must be destroyed on the same thread
107 // as construction. 103 // as construction.
108 test::TestStorageMonitor::RemoveSingleton(); 104 TestStorageMonitor::RemoveSingleton();
109 105
110 ChromeRenderViewHostTestHarness::TearDown(); 106 ChromeRenderViewHostTestHarness::TearDown();
111 } 107 }
112 108
113 void MTPDeviceDelegateImplWinTest::ProcessAttach( 109 void MTPDeviceDelegateImplWinTest::ProcessAttach(
114 const std::string& id, 110 const std::string& id,
115 const string16& label, 111 const string16& label,
116 const base::FilePath::StringType& location) { 112 const base::FilePath::StringType& location) {
117 StorageInfo info(id, string16(), location, label, string16(), string16(), 0); 113 StorageInfo info(id, string16(), location, label, string16(), string16(), 0);
118 monitor_->receiver()->ProcessAttach(info); 114 monitor_->receiver()->ProcessAttach(info);
(...skipping 25 matching lines...) Expand all
144 140
145 if (removable) 141 if (removable)
146 EXPECT_NE(0UL, info.transient_device_id.size()); 142 EXPECT_NE(0UL, info.transient_device_id.size());
147 else 143 else
148 EXPECT_EQ(0UL, info.transient_device_id.size()); 144 EXPECT_EQ(0UL, info.transient_device_id.size());
149 } 145 }
150 146
151 TEST_F(MTPDeviceDelegateImplWinTest, GalleryNameMTP) { 147 TEST_F(MTPDeviceDelegateImplWinTest, GalleryNameMTP) {
152 base::FilePath location( 148 base::FilePath location(
153 PortableDeviceWatcherWin::GetStoragePathFromStorageId( 149 PortableDeviceWatcherWin::GetStoragePathFromStorageId(
154 test::TestPortableDeviceWatcherWin::kStorageUniqueIdA)); 150 TestPortableDeviceWatcherWin::kStorageUniqueIdA));
155 AttachDevice(StorageInfo::MTP_OR_PTP, "mtp_fake_id", location); 151 AttachDevice(StorageInfo::MTP_OR_PTP, "mtp_fake_id", location);
156 152
157 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); 153 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost();
158 FSInfoMap results; 154 FSInfoMap results;
159 MediaFileSystemRegistry* registry = 155 MediaFileSystemRegistry* registry =
160 g_browser_process->media_file_system_registry(); 156 g_browser_process->media_file_system_registry();
161 registry->GetMediaFileSystemsForExtension( 157 registry->GetMediaFileSystemsForExtension(
162 rvh, extension_.get(), 158 rvh, extension_.get(),
163 base::Bind(&GetGalleryInfoCallback, base::Unretained(&results))); 159 base::Bind(&GetGalleryInfoCallback, base::Unretained(&results)));
164 base::RunLoop().RunUntilIdle(); 160 base::RunLoop().RunUntilIdle();
165 161
166 ASSERT_EQ(media_directories_.num_galleries() + 1, results.size()); 162 ASSERT_EQ(media_directories_.num_galleries() + 1, results.size());
167 bool checked = false; 163 bool checked = false;
168 for (FSInfoMap::iterator i = results.begin(); i != results.end(); ++i) { 164 for (FSInfoMap::iterator i = results.begin(); i != results.end(); ++i) {
169 MediaFileSystemInfo info = i->second; 165 MediaFileSystemInfo info = i->second;
170 if (info.path == location) { 166 if (info.path == location) {
171 CheckGalleryInfo(info, location.LossyDisplayName(), location, true, true); 167 CheckGalleryInfo(info, location.LossyDisplayName(), location, true, true);
172 checked = true; 168 checked = true;
173 break; 169 break;
174 } 170 }
175 } 171 }
176 EXPECT_TRUE(checked); 172 EXPECT_TRUE(checked);
177 } 173 }
178
179 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698