OLD | NEW |
1 // Copyright (c) 2012 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 "ash/wm/user_activity_detector.h" | 5 #include "ash/wm/user_activity_detector.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
9 #include "ash/wm/user_activity_observer.h" | 9 #include "ash/wm/user_activity_observer.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "ui/aura/event.h" | |
14 #include "ui/aura/test/test_windows.h" | 13 #include "ui/aura/test/test_windows.h" |
15 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 #include "ui/base/event.h" |
16 #include "ui/base/events.h" | 16 #include "ui/base/events.h" |
17 #include "ui/base/keycodes/keyboard_codes.h" | 17 #include "ui/base/keycodes/keyboard_codes.h" |
18 #include "ui/gfx/point.h" | 18 #include "ui/gfx/point.h" |
19 | 19 |
20 namespace ash { | 20 namespace ash { |
21 namespace test { | 21 namespace test { |
22 | 22 |
23 // Implementation that just counts the number of times we've been told that the | 23 // Implementation that just counts the number of times we've been told that the |
24 // user is active. | 24 // user is active. |
25 class TestUserActivityObserver : public UserActivityObserver { | 25 class TestUserActivityObserver : public UserActivityObserver { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 private: | 75 private: |
76 DISALLOW_COPY_AND_ASSIGN(UserActivityDetectorTest); | 76 DISALLOW_COPY_AND_ASSIGN(UserActivityDetectorTest); |
77 }; | 77 }; |
78 | 78 |
79 // Checks that the observer is notified in response to different types of input | 79 // Checks that the observer is notified in response to different types of input |
80 // events. | 80 // events. |
81 TEST_F(UserActivityDetectorTest, Basic) { | 81 TEST_F(UserActivityDetectorTest, Basic) { |
82 scoped_ptr<aura::Window> window( | 82 scoped_ptr<aura::Window> window( |
83 aura::test::CreateTestWindowWithId(12345, NULL)); | 83 aura::test::CreateTestWindowWithId(12345, NULL)); |
84 | 84 |
85 aura::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); | 85 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
86 EXPECT_FALSE(detector_->PreHandleKeyEvent(window.get(), &key_event)); | 86 EXPECT_FALSE(detector_->PreHandleKeyEvent(window.get(), &key_event)); |
87 EXPECT_EQ(1, observer_->num_invocations()); | 87 EXPECT_EQ(1, observer_->num_invocations()); |
88 observer_->reset_stats(); | 88 observer_->reset_stats(); |
89 | 89 |
90 base::TimeDelta advance_delta = | 90 base::TimeDelta advance_delta = |
91 base::TimeDelta::FromSeconds(UserActivityDetector::kNotifyIntervalSec); | 91 base::TimeDelta::FromSeconds(UserActivityDetector::kNotifyIntervalSec); |
92 AdvanceTime(advance_delta); | 92 AdvanceTime(advance_delta); |
93 aura::MouseEvent mouse_event( | 93 ui::MouseEvent mouse_event( |
94 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), ui::EF_NONE); | 94 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), ui::EF_NONE); |
95 EXPECT_FALSE(detector_->PreHandleMouseEvent(window.get(), &mouse_event)); | 95 EXPECT_FALSE(detector_->PreHandleMouseEvent(window.get(), &mouse_event)); |
96 EXPECT_EQ(1, observer_->num_invocations()); | 96 EXPECT_EQ(1, observer_->num_invocations()); |
97 observer_->reset_stats(); | 97 observer_->reset_stats(); |
98 | 98 |
99 AdvanceTime(advance_delta); | 99 AdvanceTime(advance_delta); |
100 aura::TouchEvent touch_event( | 100 ui::TouchEventImpl touch_event( |
101 ui::ET_TOUCH_PRESSED, gfx::Point(), 0, base::TimeDelta()); | 101 ui::ET_TOUCH_PRESSED, gfx::Point(), 0, base::TimeDelta()); |
102 EXPECT_FALSE(detector_->PreHandleTouchEvent(window.get(), &touch_event)); | 102 EXPECT_FALSE(detector_->PreHandleTouchEvent(window.get(), &touch_event)); |
103 EXPECT_EQ(1, observer_->num_invocations()); | 103 EXPECT_EQ(1, observer_->num_invocations()); |
104 observer_->reset_stats(); | 104 observer_->reset_stats(); |
105 | 105 |
106 AdvanceTime(advance_delta); | 106 AdvanceTime(advance_delta); |
107 aura::GestureEvent gesture_event( | 107 ui::GestureEventImpl gesture_event( |
108 ui::ET_GESTURE_TAP, 0, 0, ui::EF_NONE, base::Time(), | 108 ui::ET_GESTURE_TAP, 0, 0, ui::EF_NONE, base::Time(), |
109 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 0, 0), 0U); | 109 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 0, 0), 0U); |
110 EXPECT_FALSE(detector_->PreHandleGestureEvent(window.get(), &gesture_event)); | 110 EXPECT_FALSE(detector_->PreHandleGestureEvent(window.get(), &gesture_event)); |
111 EXPECT_EQ(1, observer_->num_invocations()); | 111 EXPECT_EQ(1, observer_->num_invocations()); |
112 observer_->reset_stats(); | 112 observer_->reset_stats(); |
113 } | 113 } |
114 | 114 |
115 // Checks that observers aren't notified too frequently. | 115 // Checks that observers aren't notified too frequently. |
116 TEST_F(UserActivityDetectorTest, RateLimitNotifications) { | 116 TEST_F(UserActivityDetectorTest, RateLimitNotifications) { |
117 scoped_ptr<aura::Window> window( | 117 scoped_ptr<aura::Window> window( |
118 aura::test::CreateTestWindowWithId(12345, NULL)); | 118 aura::test::CreateTestWindowWithId(12345, NULL)); |
119 | 119 |
120 // The observer should be notified about a key event. | 120 // The observer should be notified about a key event. |
121 aura::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); | 121 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
122 EXPECT_FALSE(detector_->PreHandleKeyEvent(window.get(), &event)); | 122 EXPECT_FALSE(detector_->PreHandleKeyEvent(window.get(), &event)); |
123 EXPECT_EQ(1, observer_->num_invocations()); | 123 EXPECT_EQ(1, observer_->num_invocations()); |
124 observer_->reset_stats(); | 124 observer_->reset_stats(); |
125 | 125 |
126 // It shouldn't be notified if a second event occurs in the same second, | 126 // It shouldn't be notified if a second event occurs in the same second, |
127 // though. | 127 // though. |
128 EXPECT_FALSE(detector_->PreHandleKeyEvent(window.get(), &event)); | 128 EXPECT_FALSE(detector_->PreHandleKeyEvent(window.get(), &event)); |
129 EXPECT_EQ(0, observer_->num_invocations()); | 129 EXPECT_EQ(0, observer_->num_invocations()); |
130 observer_->reset_stats(); | 130 observer_->reset_stats(); |
131 | 131 |
132 // Advance the time, but not quite enough for another notification to be sent. | 132 // Advance the time, but not quite enough for another notification to be sent. |
133 AdvanceTime( | 133 AdvanceTime( |
134 base::TimeDelta::FromSeconds( | 134 base::TimeDelta::FromSeconds( |
135 UserActivityDetector::kNotifyIntervalSec - 1)); | 135 UserActivityDetector::kNotifyIntervalSec - 1)); |
136 EXPECT_FALSE(detector_->PreHandleKeyEvent(window.get(), &event)); | 136 EXPECT_FALSE(detector_->PreHandleKeyEvent(window.get(), &event)); |
137 EXPECT_EQ(0, observer_->num_invocations()); | 137 EXPECT_EQ(0, observer_->num_invocations()); |
138 observer_->reset_stats(); | 138 observer_->reset_stats(); |
139 | 139 |
140 // One second later, we should send a notification again. | 140 // One second later, we should send a notification again. |
141 AdvanceTime(base::TimeDelta::FromSeconds(1)); | 141 AdvanceTime(base::TimeDelta::FromSeconds(1)); |
142 EXPECT_FALSE(detector_->PreHandleKeyEvent(window.get(), &event)); | 142 EXPECT_FALSE(detector_->PreHandleKeyEvent(window.get(), &event)); |
143 EXPECT_EQ(1, observer_->num_invocations()); | 143 EXPECT_EQ(1, observer_->num_invocations()); |
144 } | 144 } |
145 | 145 |
146 // Checks that the detector ignores synthetic mouse events. | 146 // Checks that the detector ignores synthetic mouse events. |
147 TEST_F(UserActivityDetectorTest, IgnoreSyntheticMouseEvents) { | 147 TEST_F(UserActivityDetectorTest, IgnoreSyntheticMouseEvents) { |
148 scoped_ptr<aura::Window> window( | 148 scoped_ptr<aura::Window> window( |
149 aura::test::CreateTestWindowWithId(12345, NULL)); | 149 aura::test::CreateTestWindowWithId(12345, NULL)); |
150 aura::MouseEvent mouse_event( | 150 ui::MouseEvent mouse_event( |
151 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), ui::EF_IS_SYNTHESIZED); | 151 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), ui::EF_IS_SYNTHESIZED); |
152 EXPECT_FALSE(detector_->PreHandleMouseEvent(window.get(), &mouse_event)); | 152 EXPECT_FALSE(detector_->PreHandleMouseEvent(window.get(), &mouse_event)); |
153 EXPECT_EQ(0, observer_->num_invocations()); | 153 EXPECT_EQ(0, observer_->num_invocations()); |
154 } | 154 } |
155 | 155 |
156 } // namespace test | 156 } // namespace test |
157 } // namespace ash | 157 } // namespace ash |
OLD | NEW |