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

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

Issue 9555014: Revert 124288 (made mac browser and ui_tests flaky) - Add Media device notification to SystemMonito… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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) 2012 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/file_path.h"
6 #include "base/test/mock_devices_changed_observer.h"
7 #include "base/system_monitor/system_monitor.h" 5 #include "base/system_monitor/system_monitor.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
10 7
11 namespace base { 8 namespace base {
12 9
13 class PowerTest : public SystemMonitor::PowerObserver { 10 class PowerTest : public SystemMonitor::PowerObserver {
14 public: 11 public:
15 PowerTest() 12 PowerTest()
16 : battery_(false), 13 : battery_(false),
17 power_state_changes_(0), 14 power_state_changes_(0),
18 suspends_(0), 15 suspends_(0),
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT); 83 system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT);
87 loop.RunAllPending(); 84 loop.RunAllPending();
88 EXPECT_EQ(test[0].resumes(), 1); 85 EXPECT_EQ(test[0].resumes(), 1);
89 86
90 // Send a duplicate resume notification. This should be suppressed. 87 // Send a duplicate resume notification. This should be suppressed.
91 system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT); 88 system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT);
92 loop.RunAllPending(); 89 loop.RunAllPending();
93 EXPECT_EQ(test[0].resumes(), 1); 90 EXPECT_EQ(test[0].resumes(), 1);
94 } 91 }
95 92
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
96 TEST(SystemMonitor, DeviceChangeNotifications) { 113 TEST(SystemMonitor, DeviceChangeNotifications) {
97 const int kObservers = 5; 114 const int kObservers = 5;
98 115
99 // Initialize a message loop for this to run on. 116 // Initialize a message loop for this to run on.
100 MessageLoop loop; 117 MessageLoop loop;
101 118
102 #if defined(OS_MACOSX) 119 #if defined(OS_MACOSX)
103 SystemMonitor::AllocateSystemIOPorts(); 120 SystemMonitor::AllocateSystemIOPorts();
104 #endif 121 #endif
105 122
106 testing::Sequence mock_sequencer[kObservers];
107 SystemMonitor system_monitor; 123 SystemMonitor system_monitor;
108 MockDevicesChangedObserver observers[kObservers]; 124 DevicesChangedTest test[kObservers];
109 for (int index = 0; index < kObservers; ++index) { 125 for (int index = 0; index < kObservers; ++index)
110 system_monitor.AddDevicesChangedObserver(&observers[index]); 126 system_monitor.AddDevicesChangedObserver(&test[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 }
123 127
124 system_monitor.ProcessDevicesChanged(); 128 system_monitor.ProcessDevicesChanged();
125 loop.RunAllPending(); 129 loop.RunAllPending();
130 EXPECT_EQ(1, test[0].changes());
126 131
127 system_monitor.ProcessDevicesChanged(); 132 system_monitor.ProcessDevicesChanged();
128 system_monitor.ProcessDevicesChanged(); 133 system_monitor.ProcessDevicesChanged();
129 loop.RunAllPending(); 134 loop.RunAllPending();
130 135 EXPECT_EQ(3, test[0].changes());
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();
138 } 136 }
139 137
140 } // namespace base 138 } // 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