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

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

Issue 179923006: Attempting to resolve a race condition with PowerMonitor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Win64 fixes Created 6 years, 8 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 | « content/child/child_thread.cc ('k') | content/gpu/gpu_watchdog_thread.cc » ('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 2013 The Chromium Authors. All rights reserved. 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 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/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "base/test/power_monitor_test_base.h" 6 #include "base/test/power_monitor_test_base.h"
7 #include "content/child/power_monitor_broadcast_source.h" 7 #include "content/child/power_monitor_broadcast_source.h"
8 #include "content/common/power_monitor_messages.h" 8 #include "content/common/power_monitor_messages.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace content { 11 namespace content {
12 12
13 class PowerMonitorBroadcastSourceTest : public testing::Test { 13 class PowerMonitorBroadcastSourceTest : public testing::Test {
14 protected: 14 protected:
15 PowerMonitorBroadcastSourceTest() { 15 PowerMonitorBroadcastSourceTest() {
16 power_monitor_source_ = new PowerMonitorBroadcastSource(); 16 power_monitor_source_ = new PowerMonitorBroadcastSource();
17 power_monitor_.reset(new base::PowerMonitor( 17 base::PowerMonitor::Initialize(
18 scoped_ptr<base::PowerMonitorSource>(power_monitor_source_))); 18 scoped_ptr<base::PowerMonitorSource>(power_monitor_source_));
19 } 19 }
20 virtual ~PowerMonitorBroadcastSourceTest() {} 20 virtual ~PowerMonitorBroadcastSourceTest() {
21 base::PowerMonitor::ShutdownForTesting();
22 }
21 23
22 PowerMonitorBroadcastSource* source() { return power_monitor_source_; } 24 PowerMonitorBroadcastSource* source() { return power_monitor_source_; }
23 base::PowerMonitor* monitor() { return power_monitor_.get(); }
24 25
25 base::MessageLoop message_loop_; 26 base::MessageLoop message_loop_;
26 27
27 private: 28 private:
28 PowerMonitorBroadcastSource* power_monitor_source_; 29 PowerMonitorBroadcastSource* power_monitor_source_;
29 scoped_ptr<base::PowerMonitor> power_monitor_;
30 30
31 DISALLOW_COPY_AND_ASSIGN(PowerMonitorBroadcastSourceTest); 31 DISALLOW_COPY_AND_ASSIGN(PowerMonitorBroadcastSourceTest);
32 }; 32 };
33 33
34 TEST_F(PowerMonitorBroadcastSourceTest, PowerMessageReceiveBroadcast) { 34 TEST_F(PowerMonitorBroadcastSourceTest, PowerMessageReceiveBroadcast) {
35 IPC::ChannelProxy::MessageFilter* message_filter = 35 IPC::ChannelProxy::MessageFilter* message_filter =
36 source()->GetMessageFilter(); 36 source()->GetMessageFilter();
37 37
38 base::PowerMonitorTestObserver observer; 38 base::PowerMonitorTestObserver observer;
39 monitor()->AddObserver(&observer); 39 base::PowerMonitor::AddObserver(&observer);
40 40
41 PowerMonitorMsg_Suspend suspend_msg; 41 PowerMonitorMsg_Suspend suspend_msg;
42 PowerMonitorMsg_Resume resume_msg; 42 PowerMonitorMsg_Resume resume_msg;
43 43
44 // Sending resume when not suspended should have no effect. 44 // Sending resume when not suspended should have no effect.
45 message_filter->OnMessageReceived(resume_msg); 45 message_filter->OnMessageReceived(resume_msg);
46 message_loop_.RunUntilIdle(); 46 message_loop_.RunUntilIdle();
47 EXPECT_EQ(observer.resumes(), 0); 47 EXPECT_EQ(observer.resumes(), 0);
48 48
49 // Pretend we suspended. 49 // Pretend we suspended.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 EXPECT_EQ(observer.power_state_changes(), 2); 86 EXPECT_EQ(observer.power_state_changes(), 2);
87 EXPECT_EQ(observer.last_power_state(), false); 87 EXPECT_EQ(observer.last_power_state(), false);
88 88
89 // Repeated indications the device is off battery power should be suppressed. 89 // Repeated indications the device is off battery power should be suppressed.
90 message_filter->OnMessageReceived(off_battery_msg); 90 message_filter->OnMessageReceived(off_battery_msg);
91 message_loop_.RunUntilIdle(); 91 message_loop_.RunUntilIdle();
92 EXPECT_EQ(observer.power_state_changes(), 2); 92 EXPECT_EQ(observer.power_state_changes(), 2);
93 } 93 }
94 94
95 } // namespace base 95 } // namespace base
OLDNEW
« no previous file with comments | « content/child/child_thread.cc ('k') | content/gpu/gpu_watchdog_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698