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

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: Type Created 8 years, 9 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
« no previous file with comments | « base/system_monitor/system_monitor.cc ('k') | base/test/mock_devices_changed_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 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/file_path.h"
6 #include "base/test/mock_devices_changed_observer.h"
5 #include "base/system_monitor/system_monitor.h" 7 #include "base/system_monitor/system_monitor.h"
8 #include "testing/gmock/include/gmock/gmock.h"
6 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
7 10
8 namespace base { 11 namespace base {
9 12
10 class PowerTest : public SystemMonitor::PowerObserver { 13 class PowerTest : public SystemMonitor::PowerObserver {
11 public: 14 public:
12 PowerTest() 15 PowerTest()
13 : battery_(false), 16 : battery_(false),
14 power_state_changes_(0), 17 power_state_changes_(0),
15 suspends_(0), 18 suspends_(0),
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT); 86 system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT);
84 loop.RunAllPending(); 87 loop.RunAllPending();
85 EXPECT_EQ(test[0].resumes(), 1); 88 EXPECT_EQ(test[0].resumes(), 1);
86 89
87 // Send a duplicate resume notification. This should be suppressed. 90 // Send a duplicate resume notification. This should be suppressed.
88 system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT); 91 system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT);
89 loop.RunAllPending(); 92 loop.RunAllPending();
90 EXPECT_EQ(test[0].resumes(), 1); 93 EXPECT_EQ(test[0].resumes(), 1);
91 } 94 }
92 95
93 class DevicesChangedTest : public SystemMonitor::DevicesChangedObserver {
94 public:
95 DevicesChangedTest()
96 : changes_(0) {
97 }
98
99 // DevicesChangedObserver callbacks.
100 virtual void OnDevicesChanged() OVERRIDE {
101 changes_++;
102 }
103
104 // Test status counts.
105 int changes() const { return changes_; }
106
107 private:
108 int changes_; // Count of OnDevicesChanged notifications.
109
110 DISALLOW_COPY_AND_ASSIGN(DevicesChangedTest);
111 };
112
113 TEST(SystemMonitor, DeviceChangeNotifications) { 96 TEST(SystemMonitor, DeviceChangeNotifications) {
114 const int kObservers = 5; 97 const int kObservers = 5;
115 98
116 // Initialize a message loop for this to run on. 99 // Initialize a message loop for this to run on.
117 MessageLoop loop; 100 MessageLoop loop;
118 101
119 #if defined(OS_MACOSX) 102 #if defined(OS_MACOSX)
120 SystemMonitor::AllocateSystemIOPorts(); 103 SystemMonitor::AllocateSystemIOPorts();
121 #endif 104 #endif
122 105
106 testing::Sequence mock_sequencer[kObservers];
123 SystemMonitor system_monitor; 107 SystemMonitor system_monitor;
124 DevicesChangedTest test[kObservers]; 108 MockDevicesChangedObserver observers[kObservers];
125 for (int index = 0; index < kObservers; ++index) 109 for (int index = 0; index < kObservers; ++index) {
126 system_monitor.AddDevicesChangedObserver(&test[index]); 110 system_monitor.AddDevicesChangedObserver(&observers[index]);
111
112 EXPECT_CALL(observers[index], OnDevicesChanged())
113 .Times(3)
114 .InSequence(mock_sequencer[index]);
115 EXPECT_CALL(observers[index], OnMediaDeviceAttached(1, "media device",
116 testing::_))
117 .InSequence(mock_sequencer[index]);
118 EXPECT_CALL(observers[index], OnMediaDeviceDetached(1))
119 .InSequence(mock_sequencer[index]);
120 EXPECT_CALL(observers[index], OnMediaDeviceDetached(2))
121 .InSequence(mock_sequencer[index]);
122 }
127 123
128 system_monitor.ProcessDevicesChanged(); 124 system_monitor.ProcessDevicesChanged();
129 loop.RunAllPending(); 125 loop.RunAllPending();
130 EXPECT_EQ(1, test[0].changes());
131 126
132 system_monitor.ProcessDevicesChanged(); 127 system_monitor.ProcessDevicesChanged();
133 system_monitor.ProcessDevicesChanged(); 128 system_monitor.ProcessDevicesChanged();
134 loop.RunAllPending(); 129 loop.RunAllPending();
135 EXPECT_EQ(3, test[0].changes()); 130
131 system_monitor.ProcessMediaDeviceAttached(
132 1, "media device", FilePath(FILE_PATH_LITERAL("path")));
133 loop.RunAllPending();
134
135 system_monitor.ProcessMediaDeviceDetached(1);
136 system_monitor.ProcessMediaDeviceDetached(2);
137 loop.RunAllPending();
136 } 138 }
137 139
138 } // namespace base 140 } // namespace base
OLDNEW
« no previous file with comments | « base/system_monitor/system_monitor.cc ('k') | base/test/mock_devices_changed_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698