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

Side by Side Diff: base/system_monitor/system_monitor_unittest.cc

Issue 10781014: Isolated FS for media devices. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review 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 "base/system_monitor/system_monitor.h" 5 #include "base/system_monitor/system_monitor.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/test/mock_devices_changed_observer.h" 9 #include "base/test/mock_devices_changed_observer.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 103
104 // Send a duplicate resume notification. This should be suppressed. 104 // Send a duplicate resume notification. This should be suppressed.
105 system_monitor_->ProcessPowerMessage(SystemMonitor::RESUME_EVENT); 105 system_monitor_->ProcessPowerMessage(SystemMonitor::RESUME_EVENT);
106 message_loop_.RunAllPending(); 106 message_loop_.RunAllPending();
107 EXPECT_EQ(test[0].resumes(), 1); 107 EXPECT_EQ(test[0].resumes(), 1);
108 } 108 }
109 109
110 TEST_F(SystemMonitorTest, DeviceChangeNotifications) { 110 TEST_F(SystemMonitorTest, DeviceChangeNotifications) {
111 const int kObservers = 5; 111 const int kObservers = 5;
112 const string16 kDeviceName = ASCIIToUTF16("media device"); 112 const string16 kDeviceName = ASCIIToUTF16("media device");
113 const FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo"));
113 const std::string kDeviceId1 = "1"; 114 const std::string kDeviceId1 = "1";
114 const std::string kDeviceId2 = "2"; 115 const std::string kDeviceId2 = "2";
115 116
116 testing::Sequence mock_sequencer[kObservers]; 117 testing::Sequence mock_sequencer[kObservers];
117 MockDevicesChangedObserver observers[kObservers]; 118 MockDevicesChangedObserver observers[kObservers];
118 for (int index = 0; index < kObservers; ++index) { 119 for (int index = 0; index < kObservers; ++index) {
119 system_monitor_->AddDevicesChangedObserver(&observers[index]); 120 system_monitor_->AddDevicesChangedObserver(&observers[index]);
120 121
121 EXPECT_CALL(observers[index], 122 EXPECT_CALL(observers[index],
122 OnDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN)) 123 OnDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN))
123 .Times(3) 124 .Times(3)
124 .InSequence(mock_sequencer[index]); 125 .InSequence(mock_sequencer[index]);
125 EXPECT_CALL(observers[index], 126 EXPECT_CALL(observers[index],
126 OnMediaDeviceAttached(kDeviceId1, 127 OnMediaDeviceAttached(kDeviceId1,
127 kDeviceName, 128 kDeviceName,
128 base::SystemMonitor::TYPE_PATH, 129 base::SystemMonitor::TYPE_PATH,
129 testing::_)) 130 kDevicePath1.value()))
130 .InSequence(mock_sequencer[index]); 131 .InSequence(mock_sequencer[index]);
131 EXPECT_CALL(observers[index], OnMediaDeviceDetached(kDeviceId1)) 132 EXPECT_CALL(observers[index], OnMediaDeviceDetached(
132 .InSequence(mock_sequencer[index]); 133 kDeviceId1, kDevicePath1.value())).InSequence(mock_sequencer[index]);
133 EXPECT_CALL(observers[index], OnMediaDeviceDetached(kDeviceId2)) 134 EXPECT_CALL(observers[index], OnMediaDeviceDetached(
134 .InSequence(mock_sequencer[index]); 135 kDeviceId2, testing::_)).Times(0);
135 } 136 }
136 137
137 system_monitor_->ProcessDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN); 138 system_monitor_->ProcessDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN);
138 message_loop_.RunAllPending(); 139 message_loop_.RunAllPending();
139 140
140 system_monitor_->ProcessDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN); 141 system_monitor_->ProcessDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN);
141 system_monitor_->ProcessDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN); 142 system_monitor_->ProcessDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN);
142 message_loop_.RunAllPending(); 143 message_loop_.RunAllPending();
143 144
144 system_monitor_->ProcessMediaDeviceAttached( 145 system_monitor_->ProcessMediaDeviceAttached(
145 kDeviceId1, 146 kDeviceId1,
146 kDeviceName, 147 kDeviceName,
147 base::SystemMonitor::TYPE_PATH, 148 base::SystemMonitor::TYPE_PATH,
148 FILE_PATH_LITERAL("path")); 149 kDevicePath1.value());
149 message_loop_.RunAllPending(); 150 message_loop_.RunAllPending();
150 151
151 system_monitor_->ProcessMediaDeviceDetached(kDeviceId1); 152 system_monitor_->ProcessMediaDeviceDetached(kDeviceId1);
152 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2); 153 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2);
153 message_loop_.RunAllPending(); 154 message_loop_.RunAllPending();
154 } 155 }
155 156
156 TEST_F(SystemMonitorTest, GetAttachedMediaDevicesEmpty) { 157 TEST_F(SystemMonitorTest, GetAttachedMediaDevicesEmpty) {
157 std::vector<SystemMonitor::MediaDeviceInfo> devices = 158 std::vector<SystemMonitor::MediaDeviceInfo> devices =
158 system_monitor_->GetAttachedMediaDevices(); 159 system_monitor_->GetAttachedMediaDevices();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 207
207 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2); 208 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2);
208 message_loop_.RunAllPending(); 209 message_loop_.RunAllPending();
209 devices = system_monitor_->GetAttachedMediaDevices(); 210 devices = system_monitor_->GetAttachedMediaDevices();
210 EXPECT_EQ(0U, devices.size()); 211 EXPECT_EQ(0U, devices.size());
211 } 212 }
212 213
213 } // namespace 214 } // namespace
214 215
215 } // namespace base 216 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698