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

Side by Side Diff: chrome/browser/media_gallery/media_device_notifications_window_win_unittest.cc

Issue 10829384: SystemMonitor: Pull device type into the device id (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 4 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/media_gallery/media_device_notifications_window_win.h" 5 #include "chrome/browser/media_gallery/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>
11 11
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "base/scoped_temp_dir.h" 15 #include "base/scoped_temp_dir.h"
16 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
17 #include "base/system_monitor/system_monitor.h" 17 #include "base/system_monitor/system_monitor.h"
18 #include "base/test/mock_devices_changed_observer.h" 18 #include "base/test/mock_devices_changed_observer.h"
19 #include "chrome/browser/media_gallery/media_storage_util.h"
19 #include "content/public/test/test_browser_thread.h" 20 #include "content/public/test/test_browser_thread.h"
20 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 namespace { 24 namespace {
24 25
25 using content::BrowserThread; 26 using content::BrowserThread;
26 27
27 LRESULT GetVolumeName(LPCWSTR drive, 28 LRESULT GetVolumeName(LPCWSTR drive,
28 LPWSTR volume_name, 29 LPWSTR volume_name,
29 unsigned int volume_name_length) { 30 unsigned int volume_name_length) {
30 DCHECK(volume_name_length > wcslen(drive) + 2); 31 DCHECK(volume_name_length > wcslen(drive) + 2);
31 *volume_name = 'V'; 32 *volume_name = 'V';
32 wcscpy(volume_name + 1, drive); 33 wcscpy(volume_name + 1, drive);
33 return TRUE; 34 return TRUE;
34 } 35 }
35 36
36 } // namespace 37 } // namespace
37 38
39 namespace chrome {
40
38 using chrome::MediaDeviceNotificationsWindowWin; 41 using chrome::MediaDeviceNotificationsWindowWin;
39 using testing::_; 42 using testing::_;
40 43
41 class MediaDeviceNotificationsWindowWinTest : public testing::Test { 44 class MediaDeviceNotificationsWindowWinTest : public testing::Test {
42 public: 45 public:
43 MediaDeviceNotificationsWindowWinTest() 46 MediaDeviceNotificationsWindowWinTest()
44 : ui_thread_(BrowserThread::UI, &message_loop_), 47 : ui_thread_(BrowserThread::UI, &message_loop_),
45 file_thread_(BrowserThread::FILE) { } 48 file_thread_(BrowserThread::FILE) { }
46 virtual ~MediaDeviceNotificationsWindowWinTest() { } 49 virtual ~MediaDeviceNotificationsWindowWinTest() { }
47 50
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 volume_broadcast.dbcv_flags = 0x0; 95 volume_broadcast.dbcv_flags = 0x0;
93 { 96 {
94 testing::InSequence sequence; 97 testing::InSequence sequence;
95 for (std::vector<int>::const_iterator it = device_indices.begin(); 98 for (std::vector<int>::const_iterator it = device_indices.begin();
96 it != device_indices.end(); 99 it != device_indices.end();
97 ++it) { 100 ++it) {
98 volume_broadcast.dbcv_unitmask |= 0x1 << *it; 101 volume_broadcast.dbcv_unitmask |= 0x1 << *it;
99 std::wstring drive(L"_:\\"); 102 std::wstring drive(L"_:\\");
100 drive[0] = 'A' + *it; 103 drive[0] = 'A' + *it;
101 FilePath::StringType name = L"V" + drive; 104 FilePath::StringType name = L"V" + drive;
102 EXPECT_CALL(observer_, 105 std::string device_id = MediaStorageUtil::MakeDeviceId(
103 OnMediaDeviceAttached(base::IntToString(*it), 106 MediaStorageUtil::USB_MASS_STORAGE_WITH_DCIM, base::IntToString(*it));
104 name, 107 EXPECT_CALL(observer_, OnMediaDeviceAttached(device_id, name, drive))
105 base::SystemMonitor::TYPE_PATH,
106 drive))
107 .Times(0); 108 .Times(0);
108 } 109 }
109 } 110 }
110 window_->OnDeviceChange(DBT_DEVICEARRIVAL, 111 window_->OnDeviceChange(DBT_DEVICEARRIVAL,
111 reinterpret_cast<DWORD>(&volume_broadcast)); 112 reinterpret_cast<DWORD>(&volume_broadcast));
112 message_loop_.RunAllPending(); 113 message_loop_.RunAllPending();
113 } 114 }
114 115
115 void MediaDeviceNotificationsWindowWinTest::DoDevicesDetachedTest( 116 void MediaDeviceNotificationsWindowWinTest::DoDevicesDetachedTest(
116 const std::vector<int>& device_indices) { 117 const std::vector<int>& device_indices) {
117 DEV_BROADCAST_VOLUME volume_broadcast; 118 DEV_BROADCAST_VOLUME volume_broadcast;
118 volume_broadcast.dbcv_size = sizeof(volume_broadcast); 119 volume_broadcast.dbcv_size = sizeof(volume_broadcast);
119 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; 120 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME;
120 volume_broadcast.dbcv_unitmask = 0x0; 121 volume_broadcast.dbcv_unitmask = 0x0;
121 volume_broadcast.dbcv_flags = 0x0; 122 volume_broadcast.dbcv_flags = 0x0;
122 { 123 {
123 testing::InSequence sequence; 124 testing::InSequence sequence;
124 for (std::vector<int>::const_iterator it = device_indices.begin(); 125 for (std::vector<int>::const_iterator it = device_indices.begin();
125 it != device_indices.end(); 126 it != device_indices.end();
126 ++it) { 127 ++it) {
127 volume_broadcast.dbcv_unitmask |= 0x1 << *it; 128 volume_broadcast.dbcv_unitmask |= 0x1 << *it;
128 EXPECT_CALL(observer_, OnMediaDeviceDetached(base::IntToString(*it))) 129 std::string device_id = MediaStorageUtil::MakeDeviceId(
129 .Times(0); 130 MediaStorageUtil::USB_MASS_STORAGE_WITH_DCIM, base::IntToString(*it));
131 EXPECT_CALL(observer_, OnMediaDeviceDetached(device_id)).Times(0);
130 } 132 }
131 } 133 }
132 window_->OnDeviceChange(DBT_DEVICEREMOVECOMPLETE, 134 window_->OnDeviceChange(DBT_DEVICEREMOVECOMPLETE,
133 reinterpret_cast<DWORD>(&volume_broadcast)); 135 reinterpret_cast<DWORD>(&volume_broadcast));
134 message_loop_.RunAllPending(); 136 message_loop_.RunAllPending();
135 } 137 }
136 138
137 TEST_F(MediaDeviceNotificationsWindowWinTest, RandomMessage) { 139 TEST_F(MediaDeviceNotificationsWindowWinTest, RandomMessage) {
138 window_->OnDeviceChange(DBT_DEVICEQUERYREMOVE, NULL); 140 window_->OnDeviceChange(DBT_DEVICEQUERYREMOVE, NULL);
139 message_loop_.RunAllPending(); 141 message_loop_.RunAllPending();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 199
198 TEST_F(MediaDeviceNotificationsWindowWinTest, DevicesDetachedAdjacentBits) { 200 TEST_F(MediaDeviceNotificationsWindowWinTest, DevicesDetachedAdjacentBits) {
199 std::vector<int> device_indices; 201 std::vector<int> device_indices;
200 device_indices.push_back(0); 202 device_indices.push_back(0);
201 device_indices.push_back(1); 203 device_indices.push_back(1);
202 device_indices.push_back(2); 204 device_indices.push_back(2);
203 device_indices.push_back(3); 205 device_indices.push_back(3);
204 206
205 DoDevicesDetachedTest(device_indices); 207 DoDevicesDetachedTest(device_indices);
206 } 208 }
209
210 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698