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

Side by Side Diff: chrome/browser/system_monitor/removable_device_notifications_window_win_unittest.cc

Issue 10919173: Rename Windows SystemMonitor implementation files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit Created 8 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 (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 #include "chrome/browser/system_monitor/media_device_notifications_window_win.h" 5 #include "chrome/browser/system_monitor/media_device_notifications_window_win.h"
6 6
7 #include <dbt.h> 7 #include <dbt.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 20 matching lines...) Expand all
31 DCHECK(volume_name_length > wcslen(drive) + 2); 31 DCHECK(volume_name_length > wcslen(drive) + 2);
32 *volume_name = 'V'; 32 *volume_name = 'V';
33 wcscpy(volume_name + 1, drive); 33 wcscpy(volume_name + 1, drive);
34 return TRUE; 34 return TRUE;
35 } 35 }
36 36
37 } // namespace 37 } // namespace
38 38
39 namespace chrome { 39 namespace chrome {
40 40
41 using chrome::MediaDeviceNotificationsWindowWin; 41 using chrome::RemovableDeviceNotificationsWindowWin;
42 using testing::_; 42 using testing::_;
43 43
44 class MediaDeviceNotificationsWindowWinTest : public testing::Test { 44 class RemovableDeviceNotificationsWindowWinTest : public testing::Test {
45 public: 45 public:
46 MediaDeviceNotificationsWindowWinTest() 46 RemovableDeviceNotificationsWindowWinTest()
47 : ui_thread_(BrowserThread::UI, &message_loop_), 47 : ui_thread_(BrowserThread::UI, &message_loop_),
48 file_thread_(BrowserThread::FILE) { } 48 file_thread_(BrowserThread::FILE) { }
49 virtual ~MediaDeviceNotificationsWindowWinTest() { } 49 virtual ~RemovableDeviceNotificationsWindowWinTest() { }
50 50
51 protected: 51 protected:
52 virtual void SetUp() OVERRIDE { 52 virtual void SetUp() OVERRIDE {
53 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); 53 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
54 file_thread_.Start(); 54 file_thread_.Start();
55 window_ = new MediaDeviceNotificationsWindowWin(&GetVolumeName); 55 window_ = new RemovableDeviceNotificationsWindowWin(&GetVolumeName);
56 system_monitor_.AddDevicesChangedObserver(&observer_); 56 system_monitor_.AddDevicesChangedObserver(&observer_);
57 } 57 }
58 58
59 virtual void TearDown() { 59 virtual void TearDown() {
60 system_monitor_.RemoveDevicesChangedObserver(&observer_); 60 system_monitor_.RemoveDevicesChangedObserver(&observer_);
61 WaitForFileThread(); 61 WaitForFileThread();
62 } 62 }
63 63
64 static void PostQuitToUIThread() { 64 static void PostQuitToUIThread() {
65 BrowserThread::PostTask(BrowserThread::UI, 65 BrowserThread::PostTask(BrowserThread::UI,
(...skipping 10 matching lines...) Expand all
76 76
77 void DoDevicesAttachedTest(const std::vector<int>& device_indices); 77 void DoDevicesAttachedTest(const std::vector<int>& device_indices);
78 void DoDevicesDetachedTest(const std::vector<int>& device_indices); 78 void DoDevicesDetachedTest(const std::vector<int>& device_indices);
79 79
80 MessageLoop message_loop_; 80 MessageLoop message_loop_;
81 content::TestBrowserThread ui_thread_; 81 content::TestBrowserThread ui_thread_;
82 content::TestBrowserThread file_thread_; 82 content::TestBrowserThread file_thread_;
83 83
84 base::SystemMonitor system_monitor_; 84 base::SystemMonitor system_monitor_;
85 base::MockDevicesChangedObserver observer_; 85 base::MockDevicesChangedObserver observer_;
86 scoped_refptr<MediaDeviceNotificationsWindowWin> window_; 86 scoped_refptr<RemovableDeviceNotificationsWindowWin> window_;
87 }; 87 };
88 88
89 void MediaDeviceNotificationsWindowWinTest::DoDevicesAttachedTest( 89 void RemovableDeviceNotificationsWindowWinTest::DoDevicesAttachedTest(
90 const std::vector<int>& device_indices) { 90 const std::vector<int>& device_indices) {
91 DEV_BROADCAST_VOLUME volume_broadcast; 91 DEV_BROADCAST_VOLUME volume_broadcast;
92 volume_broadcast.dbcv_size = sizeof(volume_broadcast); 92 volume_broadcast.dbcv_size = sizeof(volume_broadcast);
93 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; 93 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME;
94 volume_broadcast.dbcv_unitmask = 0x0; 94 volume_broadcast.dbcv_unitmask = 0x0;
95 volume_broadcast.dbcv_flags = 0x0; 95 volume_broadcast.dbcv_flags = 0x0;
96 { 96 {
97 testing::InSequence sequence; 97 testing::InSequence sequence;
98 for (std::vector<int>::const_iterator it = device_indices.begin(); 98 for (std::vector<int>::const_iterator it = device_indices.begin();
99 it != device_indices.end(); 99 it != device_indices.end();
100 ++it) { 100 ++it) {
101 volume_broadcast.dbcv_unitmask |= 0x1 << *it; 101 volume_broadcast.dbcv_unitmask |= 0x1 << *it;
102 std::wstring drive(L"_:\\"); 102 std::wstring drive(L"_:\\");
103 drive[0] = 'A' + *it; 103 drive[0] = 'A' + *it;
104 FilePath::StringType name = L"V" + drive; 104 FilePath::StringType name = L"V" + drive;
105 std::string device_id = MediaStorageUtil::MakeDeviceId( 105 std::string device_id = MediaStorageUtil::MakeDeviceId(
106 MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM, 106 MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM,
107 base::IntToString(*it)); 107 base::IntToString(*it));
108 EXPECT_CALL(observer_, OnRemovableStorageAttached(device_id, name, drive)) 108 EXPECT_CALL(observer_, OnRemovableStorageAttached(device_id, name, drive))
109 .Times(0); 109 .Times(0);
110 } 110 }
111 } 111 }
112 window_->OnDeviceChange(DBT_DEVICEARRIVAL, 112 window_->OnDeviceChange(DBT_DEVICEARRIVAL,
113 reinterpret_cast<DWORD>(&volume_broadcast)); 113 reinterpret_cast<DWORD>(&volume_broadcast));
114 message_loop_.RunAllPending(); 114 message_loop_.RunAllPending();
115 } 115 }
116 116
117 void MediaDeviceNotificationsWindowWinTest::DoDevicesDetachedTest( 117 void RemovableDeviceNotificationsWindowWinTest::DoDevicesDetachedTest(
118 const std::vector<int>& device_indices) { 118 const std::vector<int>& device_indices) {
119 DEV_BROADCAST_VOLUME volume_broadcast; 119 DEV_BROADCAST_VOLUME volume_broadcast;
120 volume_broadcast.dbcv_size = sizeof(volume_broadcast); 120 volume_broadcast.dbcv_size = sizeof(volume_broadcast);
121 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; 121 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME;
122 volume_broadcast.dbcv_unitmask = 0x0; 122 volume_broadcast.dbcv_unitmask = 0x0;
123 volume_broadcast.dbcv_flags = 0x0; 123 volume_broadcast.dbcv_flags = 0x0;
124 { 124 {
125 testing::InSequence sequence; 125 testing::InSequence sequence;
126 for (std::vector<int>::const_iterator it = device_indices.begin(); 126 for (std::vector<int>::const_iterator it = device_indices.begin();
127 it != device_indices.end(); 127 it != device_indices.end();
128 ++it) { 128 ++it) {
129 volume_broadcast.dbcv_unitmask |= 0x1 << *it; 129 volume_broadcast.dbcv_unitmask |= 0x1 << *it;
130 std::string device_id = MediaStorageUtil::MakeDeviceId( 130 std::string device_id = MediaStorageUtil::MakeDeviceId(
131 MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM, 131 MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM,
132 base::IntToString(*it)); 132 base::IntToString(*it));
133 EXPECT_CALL(observer_, OnRemovableStorageDetached(device_id)).Times(0); 133 EXPECT_CALL(observer_, OnRemovableStorageDetached(device_id)).Times(0);
134 } 134 }
135 } 135 }
136 window_->OnDeviceChange(DBT_DEVICEREMOVECOMPLETE, 136 window_->OnDeviceChange(DBT_DEVICEREMOVECOMPLETE,
137 reinterpret_cast<DWORD>(&volume_broadcast)); 137 reinterpret_cast<DWORD>(&volume_broadcast));
138 message_loop_.RunAllPending(); 138 message_loop_.RunAllPending();
139 } 139 }
140 140
141 TEST_F(MediaDeviceNotificationsWindowWinTest, RandomMessage) { 141 TEST_F(RemovableDeviceNotificationsWindowWinTest, RandomMessage) {
142 window_->OnDeviceChange(DBT_DEVICEQUERYREMOVE, NULL); 142 window_->OnDeviceChange(DBT_DEVICEQUERYREMOVE, NULL);
143 message_loop_.RunAllPending(); 143 message_loop_.RunAllPending();
144 } 144 }
145 145
146 TEST_F(MediaDeviceNotificationsWindowWinTest, DevicesAttached) { 146 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttached) {
147 std::vector<int> device_indices; 147 std::vector<int> device_indices;
148 device_indices.push_back(1); 148 device_indices.push_back(1);
149 device_indices.push_back(5); 149 device_indices.push_back(5);
150 device_indices.push_back(7); 150 device_indices.push_back(7);
151 151
152 DoDevicesAttachedTest(device_indices); 152 DoDevicesAttachedTest(device_indices);
153 } 153 }
154 154
155 TEST_F(MediaDeviceNotificationsWindowWinTest, DevicesAttachedHighBoundary) { 155 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttachedHighBoundary) {
156 std::vector<int> device_indices; 156 std::vector<int> device_indices;
157 device_indices.push_back(25); 157 device_indices.push_back(25);
158 158
159 DoDevicesAttachedTest(device_indices); 159 DoDevicesAttachedTest(device_indices);
160 } 160 }
161 161
162 TEST_F(MediaDeviceNotificationsWindowWinTest, DevicesAttachedLowBoundary) { 162 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttachedLowBoundary) {
163 std::vector<int> device_indices; 163 std::vector<int> device_indices;
164 device_indices.push_back(0); 164 device_indices.push_back(0);
165 165
166 DoDevicesAttachedTest(device_indices); 166 DoDevicesAttachedTest(device_indices);
167 } 167 }
168 168
169 TEST_F(MediaDeviceNotificationsWindowWinTest, DevicesAttachedAdjacentBits) { 169 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttachedAdjacentBits) {
170 std::vector<int> device_indices; 170 std::vector<int> device_indices;
171 device_indices.push_back(0); 171 device_indices.push_back(0);
172 device_indices.push_back(1); 172 device_indices.push_back(1);
173 device_indices.push_back(2); 173 device_indices.push_back(2);
174 device_indices.push_back(3); 174 device_indices.push_back(3);
175 175
176 DoDevicesAttachedTest(device_indices); 176 DoDevicesAttachedTest(device_indices);
177 } 177 }
178 178
179 TEST_F(MediaDeviceNotificationsWindowWinTest, DevicesDetached) { 179 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesDetached) {
180 std::vector<int> device_indices; 180 std::vector<int> device_indices;
181 device_indices.push_back(1); 181 device_indices.push_back(1);
182 device_indices.push_back(5); 182 device_indices.push_back(5);
183 device_indices.push_back(7); 183 device_indices.push_back(7);
184 184
185 DoDevicesDetachedTest(device_indices); 185 DoDevicesDetachedTest(device_indices);
186 } 186 }
187 187
188 TEST_F(MediaDeviceNotificationsWindowWinTest, DevicesDetachedHighBoundary) { 188 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesDetachedHighBoundary) {
189 std::vector<int> device_indices; 189 std::vector<int> device_indices;
190 device_indices.push_back(25); 190 device_indices.push_back(25);
191 191
192 DoDevicesDetachedTest(device_indices); 192 DoDevicesDetachedTest(device_indices);
193 } 193 }
194 194
195 TEST_F(MediaDeviceNotificationsWindowWinTest, DevicesDetachedLowBoundary) { 195 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesDetachedLowBoundary) {
196 std::vector<int> device_indices; 196 std::vector<int> device_indices;
197 device_indices.push_back(0); 197 device_indices.push_back(0);
198 198
199 DoDevicesDetachedTest(device_indices); 199 DoDevicesDetachedTest(device_indices);
200 } 200 }
201 201
202 TEST_F(MediaDeviceNotificationsWindowWinTest, DevicesDetachedAdjacentBits) { 202 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesDetachedAdjacentBits) {
203 std::vector<int> device_indices; 203 std::vector<int> device_indices;
204 device_indices.push_back(0); 204 device_indices.push_back(0);
205 device_indices.push_back(1); 205 device_indices.push_back(1);
206 device_indices.push_back(2); 206 device_indices.push_back(2);
207 device_indices.push_back(3); 207 device_indices.push_back(3);
208 208
209 DoDevicesDetachedTest(device_indices); 209 DoDevicesDetachedTest(device_indices);
210 } 210 }
211 211
212 } // namespace chrome 212 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698