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

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: Turns out, we want a number id on Windows too 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 SystemMonitor::DeviceIdType& id,
104 const std::string& name,
105 const FilePath& path) OVERRIDE {
106 media_attaches_++;
107 }
108 virtual void OnMediaDeviceDetached(
109 const SystemMonitor::DeviceIdType& name) OVERRIDE {
110 media_detaches_++;
111 }
112
104 // Test status counts. 113 // Test status counts.
105 int changes() const { return changes_; } 114 int changes() const { return changes_; }
115 int media_attaches() const { return media_attaches_; }
116 int media_detaches() const { return media_detaches_; }
106 117
107 private: 118 private:
108 int changes_; // Count of OnDevicesChanged notifications. 119 int changes_; // Count of OnDevicesChanged notifications.
120 int media_attaches_; // Count of OnMediaDeviceAttached notifications.
121 int media_detaches_; // Count of OnMediaDeviceDetached notifications.
109 122
110 DISALLOW_COPY_AND_ASSIGN(DevicesChangedTest); 123 DISALLOW_COPY_AND_ASSIGN(DevicesChangedTest);
111 }; 124 };
112 125
113 TEST(SystemMonitor, DeviceChangeNotifications) { 126 TEST(SystemMonitor, DeviceChangeNotifications) {
114 const int kObservers = 5; 127 const int kObservers = 5;
115 128
116 // Initialize a message loop for this to run on. 129 // Initialize a message loop for this to run on.
117 MessageLoop loop; 130 MessageLoop loop;
118 131
119 #if defined(OS_MACOSX) 132 #if defined(OS_MACOSX)
120 SystemMonitor::AllocateSystemIOPorts(); 133 SystemMonitor::AllocateSystemIOPorts();
121 #endif 134 #endif
122 135
123 SystemMonitor system_monitor; 136 SystemMonitor system_monitor;
124 DevicesChangedTest test[kObservers]; 137 DevicesChangedTest test[kObservers];
125 for (int index = 0; index < kObservers; ++index) 138 for (int index = 0; index < kObservers; ++index)
126 system_monitor.AddDevicesChangedObserver(&test[index]); 139 system_monitor.AddDevicesChangedObserver(&test[index]);
127 140
128 system_monitor.ProcessDevicesChanged(); 141 system_monitor.ProcessDevicesChanged();
129 loop.RunAllPending(); 142 loop.RunAllPending();
130 EXPECT_EQ(1, test[0].changes()); 143 EXPECT_EQ(1, test[0].changes());
144 EXPECT_EQ(0, test[0].media_attaches());
145 EXPECT_EQ(0, test[0].media_detaches());
131 146
132 system_monitor.ProcessDevicesChanged(); 147 system_monitor.ProcessDevicesChanged();
133 system_monitor.ProcessDevicesChanged(); 148 system_monitor.ProcessDevicesChanged();
134 loop.RunAllPending(); 149 loop.RunAllPending();
135 EXPECT_EQ(3, test[0].changes()); 150 EXPECT_EQ(3, test[0].changes());
151 EXPECT_EQ(0, test[0].media_attaches());
152 EXPECT_EQ(0, test[0].media_detaches());
153
154 system_monitor.ProcessMediaDeviceAttached(
155 1, "media device", FilePath(FILE_PATH_LITERAL("path")));
156 loop.RunAllPending();
157 EXPECT_EQ(3, test[0].changes());
158 EXPECT_EQ(1, test[0].media_attaches());
159 EXPECT_EQ(0, test[0].media_detaches());
160
161 system_monitor.ProcessMediaDeviceDetached(1);
162 system_monitor.ProcessMediaDeviceDetached(2);
163 loop.RunAllPending();
164 EXPECT_EQ(3, test[0].changes());
165 EXPECT_EQ(1, test[0].media_attaches());
166 EXPECT_EQ(2, test[0].media_detaches());
136 } 167 }
137 168
138 } // namespace base 169 } // namespace base
OLDNEW
« base/system_monitor/system_monitor_mac.mm ('K') | « base/system_monitor/system_monitor_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698