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

Side by Side Diff: src/platform/power_manager/xidle_unittest.cc

Issue 1035001: Fix off-by-one bug for the negative transition in XIdle::AddIdleTimeout, which (Closed)
Patch Set: Update to address Dan's comments Created 10 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
OLDNEW
1 // Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2009-2010 The Chromium OS 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 <gtest/gtest.h> 5 #include <gtest/gtest.h>
6 #include <unistd.h> 6 #include <unistd.h>
7 #include <X11/extensions/XTest.h>
8 #include <cstdio>
7 9
8 #include <base/command_line.h> 10 #include "base/command_line.h"
9 #include <base/logging.h> 11 #include "base/logging.h"
10
11 #include "power_manager/xidle.h" 12 #include "power_manager/xidle.h"
12 13
13 namespace power_manager { 14 namespace power_manager {
14 15
15 class XIdleTest : public ::testing::Test { }; 16 class XIdleTest : public ::testing::Test {
17 protected:
18 virtual void SetUp() {
19 display_ = XOpenDisplay(NULL);
20 ASSERT_TRUE(idle_.Init(display_));
21 }
22 virtual void TearDown() {
23 idle_.ClearTimeouts();
24 XCloseDisplay(display_);
25 }
26 Display *display_;
27 power_manager::XIdle idle_;
28 };
16 29
17 TEST(XIdleTest, GetIdleTimeTest) { 30 static void FakeMotionEvent(Display* display) {
31 XTestFakeMotionEvent(display, 0, 0, 0, 0);
Daniel Erat 2010/03/16 21:40:01 i think that this will warp the user's pointer to
davidjames 2010/03/16 22:27:09 Aha, good catch. I didn't notice the warping becau
32 XSync(display, false);
33 }
34
35 TEST_F(XIdleTest, GetIdleTimeTest) {
18 int64 idle_time = kint64max; 36 int64 idle_time = kint64max;
19 power_manager::XIdle idle; 37 ASSERT_TRUE(idle_.GetIdleTime(&idle_time));
20 if (idle.Init()) { 38 ASSERT_NE(idle_time, kint64max);
21 ASSERT_TRUE(idle.GetIdleTime(&idle_time)); 39 }
22 ASSERT_NE(kint64max, idle_time); 40
41 TEST_F(XIdleTest, GetIdleTimeWhenNonIdleTest) {
42 int64 idle_time = kint64max;
43 FakeMotionEvent(display_);
44 ASSERT_TRUE(idle_.GetIdleTime(&idle_time));
45 ASSERT_LT(idle_time, 50);
46 }
47
48 TEST_F(XIdleTest, MonitorTest) {
49 int64 idle_time = kint64max;
50 bool is_idle;
51 FakeMotionEvent(display_);
52 idle_.AddIdleTimeout(50);
53 idle_.AddIdleTimeout(100);
54 for (int i = 0; i < 10; i++) {
55 ASSERT_TRUE(idle_.GetIdleTime(&idle_time));
56 ASSERT_LT(idle_time, 50);
57 ASSERT_TRUE(idle_.Monitor(&is_idle, &idle_time));
58 ASSERT_GT(idle_time, 49);
59 ASSERT_LT(idle_time, 100);
60 ASSERT_TRUE(is_idle);
61 FakeMotionEvent(display_);
62 ASSERT_TRUE(idle_.Monitor(&is_idle, &idle_time));
63 ASSERT_LT(idle_time, 50);
64 ASSERT_FALSE(is_idle);
23 } 65 }
24 } 66 }
25 67
26 } // namespace power_manager 68 } // namespace power_manager
OLDNEW
« src/platform/power_manager/xidle-example.cc ('K') | « src/platform/power_manager/xidle-example.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698