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

Side by Side Diff: content/common/power_monitor_broadcast_source_unittest.cc

Issue 17074009: Created multi-process-friendly PowerMonitor interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Expanding units tests Created 7 years, 5 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
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/message_loop.h"
6 #include "base/power_monitor/power_monitor_test_base.h"
7 #include "content/common/power_monitor_broadcast_source.h"
8 #include "content/common/power_monitor_messages.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace content {
12
13 class PowerMonitorBroadcastSourceTest : public testing::Test {
14 protected:
15 PowerMonitorBroadcastSourceTest() {
16 power_monitor_source_ = new PowerMonitorBroadcastSource();
17 power_monitor_.reset(new base::PowerMonitor(power_monitor_source_));
18 }
19 virtual ~PowerMonitorBroadcastSourceTest() {}
20
21 PowerMonitorBroadcastSource* source() { return power_monitor_source_; }
22 base::PowerMonitor* monitor() { return power_monitor_.get(); }
23
24 base::MessageLoop message_loop_;
25
26 private:
27 PowerMonitorBroadcastSource* power_monitor_source_;
28 scoped_ptr<base::PowerMonitor> power_monitor_;
29
30 DISALLOW_COPY_AND_ASSIGN(PowerMonitorBroadcastSourceTest);
31 };
32
33 TEST_F(PowerMonitorBroadcastSourceTest, PowerMessageReceiveBroadcast) {
34 IPC::ChannelProxy::MessageFilter* message_filter = source()->MessageFilter();
35
36 base::PowerMonitorTestObserver observer;
37 monitor()->AddObserver(&observer);
38
39 PowerMonitorMsg_Suspend suspend_msg;
40 PowerMonitorMsg_Resume resume_msg;
41
42 // Sending resume when not suspended should have no effect.
43 message_filter->OnMessageReceived(resume_msg);
44 message_loop_.RunUntilIdle();
45 EXPECT_EQ(observer.resumes(), 0);
46
47 // Pretend we suspended.
48 message_filter->OnMessageReceived(suspend_msg);
49 message_loop_.RunUntilIdle();
50 EXPECT_EQ(observer.suspends(), 1);
51
52 // Send a second suspend notification. This should be suppressed.
53 message_filter->OnMessageReceived(suspend_msg);
54 message_loop_.RunUntilIdle();
55 EXPECT_EQ(observer.suspends(), 1);
56
57 // Pretend we were awakened.
58 message_filter->OnMessageReceived(resume_msg);
59 message_loop_.RunUntilIdle();
60 EXPECT_EQ(observer.resumes(), 1);
61
62 // Send a duplicate resume notification. This should be suppressed.
63 message_filter->OnMessageReceived(resume_msg);
64 message_loop_.RunUntilIdle();
65 EXPECT_EQ(observer.resumes(), 1);
66
67 /*PowerMonitorMsg_PowerStateChange on_battery_msg(true);
bajones 2013/07/12 18:55:08 Testing these messages currently has me stumped. P
68 PowerMonitorMsg_PowerStateChange off_battery_msg(false);
69
70 // Pretend the device has gone on battery power
71 message_filter->OnMessageReceived(on_battery_msg);
72 message_loop_.RunUntilIdle();
73 EXPECT_EQ(observer.power_state_changes(), 1);
74 EXPECT_EQ(observer.last_power_state(), true);
75
76 // Repeated indications the device is on battery power should be suppressed.
77 message_filter->OnMessageReceived(on_battery_msg);
78 message_loop_.RunUntilIdle();
79 EXPECT_EQ(observer.power_state_changes(), 1);
80
81 // Pretend the device has gone off battery power
82 message_filter->OnMessageReceived(off_battery_msg);
83 message_loop_.RunUntilIdle();
84 EXPECT_EQ(observer.power_state_changes(), 2);
85 EXPECT_EQ(observer.last_power_state(), false);
86
87 // Repeated indications the device is off battery power should be suppressed.
88 message_filter->OnMessageReceived(off_battery_msg);
89 message_loop_.RunUntilIdle();
90 EXPECT_EQ(observer.power_state_changes(), 2);*/
91 }
92
93 } // namespace base
OLDNEW
« no previous file with comments | « content/common/power_monitor_broadcast_source.cc ('k') | content/common/power_monitor_message_broadcaster.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698