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

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

Issue 8523021: Send WM_DEVICECHANGE message through SystemMonitor (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 9 years, 1 month 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
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT); 83 system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT);
84 loop.RunAllPending(); 84 loop.RunAllPending();
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 DeviceChangeTest : public SystemMonitor::DeviceChangeObserver {
94 public:
95 DeviceChangeTest()
96 : changes_(0) {
97 }
98
99 // DeviceChangeObserver callbacks.
100 void OnDeviceChange() {
sky 2011/11/11 02:32:59 virtual and OVERRIDE
scottmg 2011/11/11 05:06:09 Done.
101 changes_++;
102 }
103
104 // Test status counts.
105 int changes() { return changes_; }
sky 2011/11/11 02:32:59 const
scottmg 2011/11/11 05:06:09 Done.
106
107 private:
108 int changes_; // Count of OnDeviceChange notifications.
sky 2011/11/11 02:32:59 DISALLOW_...
scottmg 2011/11/11 05:06:09 Done.
109 };
110
111 TEST(SystemMonitor, DeviceChangeNotifications) {
112 const int kObservers = 5;
113
114 // Initialize a message loop for this to run on.
115 MessageLoop loop;
116
117 #if defined(OS_MACOSX)
118 SystemMonitor::AllocateSystemIOPorts();
119 #endif
120
121 SystemMonitor system_monitor;
122 DeviceChangeTest test[kObservers];
123 for (int index = 0; index < kObservers; ++index)
124 system_monitor.AddObserver(&test[index]);
125
126 system_monitor.ProcessDeviceChange();
127 loop.RunAllPending();
128 EXPECT_EQ(test[0].changes(), 1);
sky 2011/11/11 02:32:59 assertions should have expected first, then actual
scottmg 2011/11/11 05:06:09 Done.
129
130 system_monitor.ProcessDeviceChange();
131 system_monitor.ProcessDeviceChange();
132 loop.RunAllPending();
133 EXPECT_EQ(test[0].changes(), 3);
134 }
135
93 } // namespace base 136 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698