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

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: Fix shared_build compile error. 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], OnDevicesChanged()) 122 EXPECT_CALL(observers[index], OnDevicesChanged())
122 .Times(3) 123 .Times(3)
123 .InSequence(mock_sequencer[index]); 124 .InSequence(mock_sequencer[index]);
124 EXPECT_CALL(observers[index], 125 EXPECT_CALL(observers[index],
125 OnMediaDeviceAttached(kDeviceId1, 126 OnMediaDeviceAttached(kDeviceId1,
126 kDeviceName, 127 kDeviceName,
127 base::SystemMonitor::TYPE_PATH, 128 base::SystemMonitor::TYPE_PATH,
128 testing::_)) 129 kDevicePath1.value()))
129 .InSequence(mock_sequencer[index]); 130 .InSequence(mock_sequencer[index]);
130 EXPECT_CALL(observers[index], OnMediaDeviceDetached(kDeviceId1)) 131 EXPECT_CALL(observers[index], OnMediaDeviceDetached(
131 .InSequence(mock_sequencer[index]); 132 kDeviceId1, kDevicePath1.value())).InSequence(mock_sequencer[index]);
132 EXPECT_CALL(observers[index], OnMediaDeviceDetached(kDeviceId2)) 133 EXPECT_CALL(observers[index], OnMediaDeviceDetached(
133 .InSequence(mock_sequencer[index]); 134 kDeviceId2, testing::_)).Times(0);
134 } 135 }
135 136
136 system_monitor_->ProcessDevicesChanged(); 137 system_monitor_->ProcessDevicesChanged();
137 message_loop_.RunAllPending(); 138 message_loop_.RunAllPending();
138 139
139 system_monitor_->ProcessDevicesChanged(); 140 system_monitor_->ProcessDevicesChanged();
140 system_monitor_->ProcessDevicesChanged(); 141 system_monitor_->ProcessDevicesChanged();
141 message_loop_.RunAllPending(); 142 message_loop_.RunAllPending();
142 143
143 system_monitor_->ProcessMediaDeviceAttached( 144 system_monitor_->ProcessMediaDeviceAttached(
144 kDeviceId1, 145 kDeviceId1,
145 kDeviceName, 146 kDeviceName,
146 base::SystemMonitor::TYPE_PATH, 147 base::SystemMonitor::TYPE_PATH,
147 FILE_PATH_LITERAL("path")); 148 kDevicePath1.value());
148 message_loop_.RunAllPending(); 149 message_loop_.RunAllPending();
149 150
150 system_monitor_->ProcessMediaDeviceDetached(kDeviceId1); 151 system_monitor_->ProcessMediaDeviceDetached(kDeviceId1);
151 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2); 152 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2);
152 message_loop_.RunAllPending(); 153 message_loop_.RunAllPending();
153 } 154 }
154 155
155 TEST_F(SystemMonitorTest, GetAttachedMediaDevicesEmpty) { 156 TEST_F(SystemMonitorTest, GetAttachedMediaDevicesEmpty) {
156 std::vector<SystemMonitor::MediaDeviceInfo> devices = 157 std::vector<SystemMonitor::MediaDeviceInfo> devices =
157 system_monitor_->GetAttachedMediaDevices(); 158 system_monitor_->GetAttachedMediaDevices();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 206
206 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2); 207 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2);
207 message_loop_.RunAllPending(); 208 message_loop_.RunAllPending();
208 devices = system_monitor_->GetAttachedMediaDevices(); 209 devices = system_monitor_->GetAttachedMediaDevices();
209 EXPECT_EQ(0U, devices.size()); 210 EXPECT_EQ(0U, devices.size());
210 } 211 }
211 212
212 } // namespace 213 } // namespace
213 214
214 } // namespace base 215 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698