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

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

Issue 9363008: Add Media device notification to SystemMonitor and Mac impl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 namespace base { 8 namespace base {
9 9
10 class PowerTest : public SystemMonitor::PowerObserver { 10 class PowerTest : public SystemMonitor::PowerObserver {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 EXPECT_EQ(test[0].resumes(), 1); 85 EXPECT_EQ(test[0].resumes(), 1);
86 86
87 // Send a duplicate resume notification. This should be suppressed. 87 // Send a duplicate resume notification. This should be suppressed.
88 system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT); 88 system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT);
89 loop.RunAllPending(); 89 loop.RunAllPending();
90 EXPECT_EQ(test[0].resumes(), 1); 90 EXPECT_EQ(test[0].resumes(), 1);
91 } 91 }
92 92
93 class DevicesChangedTest : public SystemMonitor::DevicesChangedObserver { 93 class DevicesChangedTest : public SystemMonitor::DevicesChangedObserver {
94 public: 94 public:
95 DevicesChangedTest() 95 DevicesChangedTest() : changes_(0), media_attaches_(0), media_detaches_(0) {
96 : changes_(0) {
97 } 96 }
98 97
99 // DevicesChangedObserver callbacks. 98 // DevicesChangedObserver callbacks.
100 virtual void OnDevicesChanged() OVERRIDE { 99 virtual void OnDevicesChanged() OVERRIDE {
101 changes_++; 100 changes_++;
102 } 101 }
103 102
103 virtual void OnMediaDeviceAttached(const std::string& name,
104 const FilePath& path) OVERRIDE {
105 media_attaches_++;
106 }
107 virtual void OnMediaDeviceDetached(const std::string& name) OVERRIDE {
108 media_detaches_++;
109 }
110
104 // Test status counts. 111 // Test status counts.
105 int changes() const { return changes_; } 112 int changes() const { return changes_; }
113 int media_attaches() const { return media_attaches_; }
114 int media_detaches() const { return media_detaches_; }
106 115
107 private: 116 private:
108 int changes_; // Count of OnDevicesChanged notifications. 117 int changes_; // Count of OnDevicesChanged notifications.
118 int media_attaches_; // Count of OnMediaDeviceAttached notifications.
119 int media_detaches_; // Count of OnMediaDeviceDetached notifications.
109 120
110 DISALLOW_COPY_AND_ASSIGN(DevicesChangedTest); 121 DISALLOW_COPY_AND_ASSIGN(DevicesChangedTest);
111 }; 122 };
112 123
113 TEST(SystemMonitor, DeviceChangeNotifications) { 124 TEST(SystemMonitor, DeviceChangeNotifications) {
114 const int kObservers = 5; 125 const int kObservers = 5;
115 126
116 // Initialize a message loop for this to run on. 127 // Initialize a message loop for this to run on.
117 MessageLoop loop; 128 MessageLoop loop;
118 129
119 #if defined(OS_MACOSX) 130 #if defined(OS_MACOSX)
120 SystemMonitor::AllocateSystemIOPorts(); 131 SystemMonitor::AllocateSystemIOPorts();
121 #endif 132 #endif
122 133
123 SystemMonitor system_monitor; 134 SystemMonitor system_monitor;
124 DevicesChangedTest test[kObservers]; 135 DevicesChangedTest test[kObservers];
125 for (int index = 0; index < kObservers; ++index) 136 for (int index = 0; index < kObservers; ++index)
126 system_monitor.AddDevicesChangedObserver(&test[index]); 137 system_monitor.AddDevicesChangedObserver(&test[index]);
127 138
128 system_monitor.ProcessDevicesChanged(); 139 system_monitor.ProcessDevicesChanged();
129 loop.RunAllPending(); 140 loop.RunAllPending();
130 EXPECT_EQ(1, test[0].changes()); 141 EXPECT_EQ(1, test[0].changes());
142 EXPECT_EQ(0, test[0].media_attaches());
143 EXPECT_EQ(0, test[0].media_detaches());
131 144
132 system_monitor.ProcessDevicesChanged(); 145 system_monitor.ProcessDevicesChanged();
133 system_monitor.ProcessDevicesChanged(); 146 system_monitor.ProcessDevicesChanged();
134 loop.RunAllPending(); 147 loop.RunAllPending();
135 EXPECT_EQ(3, test[0].changes()); 148 EXPECT_EQ(3, test[0].changes());
149 EXPECT_EQ(0, test[0].media_attaches());
150 EXPECT_EQ(0, test[0].media_detaches());
151
152 system_monitor.ProcessMediaDeviceAttached("media device", FilePath("path"));
tpayne 2012/02/08 20:46:44 FilePath("path") does not compile on Windows, whic
Lei Zhang 2012/02/08 23:34:14 You need FILE_PATH_LITERAL here.
153 loop.RunAllPending();
154 EXPECT_EQ(4, test[0].changes());
155 EXPECT_EQ(1, test[0].media_attaches());
156 EXPECT_EQ(0, test[0].media_detaches());
157
158 system_monitor.ProcessMediaDeviceDetached("media device");
159 system_monitor.ProcessMediaDeviceDetached("other media device");
160 loop.RunAllPending();
161 EXPECT_EQ(6, test[0].changes());
162 EXPECT_EQ(1, test[0].media_attaches());
163 EXPECT_EQ(2, test[0].media_detaches());
136 } 164 }
137 165
138 } // namespace base 166 } // namespace base
OLDNEW
« base/system_monitor/system_monitor.cc ('K') | « base/system_monitor/system_monitor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698