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

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

Issue 10389161: Cleanup: Misc fixes to MediaDeviceNotifications. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 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
« no previous file with comments | « chrome/browser/media_gallery/media_device_notifications_window_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <windows.h>
6 #include <dbt.h>
6 7
7 #include <dbt.h>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/sys_string_conversions.h" 12 #include "base/sys_string_conversions.h"
14 #include "base/system_monitor/system_monitor.h" 13 #include "base/system_monitor/system_monitor.h"
15 #include "base/test/mock_devices_changed_observer.h" 14 #include "base/test/mock_devices_changed_observer.h"
15 #include "chrome/browser/media_gallery/media_device_notifications_window_win.h"
vandebo (ex-Chrome) 2012/05/16 17:00:16 nit: it looks like most files in base have this fi
Lei Zhang 2012/05/16 19:02:55 I remembered wrong. Reverted.
16 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace { 19 namespace {
20 20
21 LRESULT GetVolumeName(LPCWSTR drive, 21 LRESULT GetVolumeName(LPCWSTR drive,
22 LPWSTR volume_name, 22 LPWSTR volume_name,
23 unsigned int volume_name_length) { 23 unsigned int volume_name_length) {
24 DCHECK(volume_name_length > wcslen(drive) + 2); 24 DCHECK(volume_name_length > wcslen(drive) + 2);
25 *volume_name = 'V'; 25 *volume_name = 'V';
26 wcscpy(volume_name + 1, drive); 26 wcscpy(volume_name + 1, drive);
27 return TRUE; 27 return TRUE;
28 } 28 }
29 29
30 } // namespace 30 } // namespace
31 31
32 class MediaDeviceNotificationsWindowWinTest : public testing::Test { 32 class MediaDeviceNotificationsWindowWinTest : public testing::Test {
33 public: 33 public:
34 MediaDeviceNotificationsWindowWinTest() : window_(&GetVolumeName) { } 34 MediaDeviceNotificationsWindowWinTest() : window_(&GetVolumeName) { }
35 virtual ~MediaDeviceNotificationsWindowWinTest() { } 35 virtual ~MediaDeviceNotificationsWindowWinTest() { }
36 36
37 protected: 37 protected:
38 virtual void SetUp() OVERRIDE { 38 virtual void SetUp() OVERRIDE {
39 system_monitor_.AddDevicesChangedObserver(&observer_); 39 system_monitor_.AddDevicesChangedObserver(&observer_);
40 } 40 }
41 41
42 void DoDevicesAttachedTest(const std::vector<int>& deviceIndices); 42 void DoDevicesAttachedTest(const std::vector<int>& device_indices);
43 void DoDevicesDetachedTest(const std::vector<int>& deviceIndices); 43 void DoDevicesDetachedTest(const std::vector<int>& device_indices);
44 44
45 MessageLoop message_loop_; 45 MessageLoop message_loop_;
46 base::SystemMonitor system_monitor_; 46 base::SystemMonitor system_monitor_;
47 base::MockDevicesChangedObserver observer_; 47 base::MockDevicesChangedObserver observer_;
48 chrome::MediaDeviceNotificationsWindowWin window_; 48 chrome::MediaDeviceNotificationsWindowWin window_;
49 }; 49 };
50 50
51 void MediaDeviceNotificationsWindowWinTest::DoDevicesAttachedTest( 51 void MediaDeviceNotificationsWindowWinTest::DoDevicesAttachedTest(
52 const std::vector<int>& device_indices) { 52 const std::vector<int>& device_indices) {
53 DEV_BROADCAST_VOLUME volume_broadcast; 53 DEV_BROADCAST_VOLUME volume_broadcast;
54 volume_broadcast.dbcv_size = sizeof(volume_broadcast); 54 volume_broadcast.dbcv_size = sizeof(volume_broadcast);
55 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; 55 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME;
56 volume_broadcast.dbcv_unitmask = 0x0; 56 volume_broadcast.dbcv_unitmask = 0x0;
57 volume_broadcast.dbcv_flags = 0x0; 57 volume_broadcast.dbcv_flags = 0x0;
58 { 58 {
59 testing::InSequence sequnce; 59 testing::InSequence sequence;
60 for (std::vector<int>::const_iterator it = device_indices.begin(); 60 for (std::vector<int>::const_iterator it = device_indices.begin();
61 it != device_indices.end(); 61 it != device_indices.end();
62 ++it) { 62 ++it) {
63 volume_broadcast.dbcv_unitmask |= 0x1 << *it; 63 volume_broadcast.dbcv_unitmask |= 0x1 << *it;
64 std::wstring drive(L"_:\\"); 64 std::wstring drive(L"_:\\");
65 drive[0] = 'A' + *it; 65 drive[0] = 'A' + *it;
66 std::string name("V"); 66 std::string name("V");
67 name.append(base::SysWideToUTF8(drive)); 67 name.append(base::SysWideToUTF8(drive));
68 EXPECT_CALL(observer_, OnMediaDeviceAttached(*it, name, FilePath(drive))); 68 EXPECT_CALL(observer_, OnMediaDeviceAttached(*it, name, FilePath(drive)));
69 } 69 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 157
158 TEST_F(MediaDeviceNotificationsWindowWinTest, DevicesDetachedAdjacentBits) { 158 TEST_F(MediaDeviceNotificationsWindowWinTest, DevicesDetachedAdjacentBits) {
159 std::vector<int> device_indices; 159 std::vector<int> device_indices;
160 device_indices.push_back(0); 160 device_indices.push_back(0);
161 device_indices.push_back(1); 161 device_indices.push_back(1);
162 device_indices.push_back(2); 162 device_indices.push_back(2);
163 device_indices.push_back(3); 163 device_indices.push_back(3);
164 164
165 DoDevicesDetachedTest(device_indices); 165 DoDevicesDetachedTest(device_indices);
166 } 166 }
OLDNEW
« no previous file with comments | « chrome/browser/media_gallery/media_device_notifications_window_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698