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" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 base::TimeTicks now_; | 82 base::TimeTicks now_; |
83 | 83 |
84 private: | 84 private: |
85 DISALLOW_COPY_AND_ASSIGN(UserActivityDetectorTest); | 85 DISALLOW_COPY_AND_ASSIGN(UserActivityDetectorTest); |
86 }; | 86 }; |
87 | 87 |
88 // Checks that the observer is notified in response to different types of input | 88 // Checks that the observer is notified in response to different types of input |
89 // events. | 89 // events. |
90 TEST_F(UserActivityDetectorTest, Basic) { | 90 TEST_F(UserActivityDetectorTest, Basic) { |
91 scoped_ptr<aura::Window> window( | 91 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(12345)); |
92 aura::test::CreateTestWindowWithId(12345, NULL)); | |
93 | 92 |
94 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE, false); | 93 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE, false); |
95 SetEventTarget(window.get(), &key_event); | 94 SetEventTarget(window.get(), &key_event); |
96 EXPECT_EQ(ui::ER_UNHANDLED, detector_->OnKeyEvent(&key_event)); | 95 EXPECT_EQ(ui::ER_UNHANDLED, detector_->OnKeyEvent(&key_event)); |
97 EXPECT_EQ(1, observer_->num_invocations()); | 96 EXPECT_EQ(1, observer_->num_invocations()); |
98 observer_->reset_stats(); | 97 observer_->reset_stats(); |
99 | 98 |
100 base::TimeDelta advance_delta = | 99 base::TimeDelta advance_delta = |
101 base::TimeDelta::FromSeconds(UserActivityDetector::kNotifyIntervalMs); | 100 base::TimeDelta::FromSeconds(UserActivityDetector::kNotifyIntervalMs); |
102 AdvanceTime(advance_delta); | 101 AdvanceTime(advance_delta); |
(...skipping 25 matching lines...) Expand all Loading... |
128 base::TimeDelta::FromMilliseconds(base::Time::Now().ToDoubleT() * 1000), | 127 base::TimeDelta::FromMilliseconds(base::Time::Now().ToDoubleT() * 1000), |
129 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 0, 0), 0U); | 128 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 0, 0), 0U); |
130 SetEventTarget(window.get(), &gesture_event); | 129 SetEventTarget(window.get(), &gesture_event); |
131 EXPECT_FALSE(detector_->OnGestureEvent(&gesture_event)); | 130 EXPECT_FALSE(detector_->OnGestureEvent(&gesture_event)); |
132 EXPECT_EQ(1, observer_->num_invocations()); | 131 EXPECT_EQ(1, observer_->num_invocations()); |
133 observer_->reset_stats(); | 132 observer_->reset_stats(); |
134 } | 133 } |
135 | 134 |
136 // Checks that observers aren't notified too frequently. | 135 // Checks that observers aren't notified too frequently. |
137 TEST_F(UserActivityDetectorTest, RateLimitNotifications) { | 136 TEST_F(UserActivityDetectorTest, RateLimitNotifications) { |
138 scoped_ptr<aura::Window> window( | 137 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(12345)); |
139 aura::test::CreateTestWindowWithId(12345, NULL)); | |
140 | 138 |
141 // The observer should be notified about a key event. | 139 // The observer should be notified about a key event. |
142 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE, false); | 140 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE, false); |
143 SetEventTarget(window.get(), &event); | 141 SetEventTarget(window.get(), &event); |
144 EXPECT_FALSE(detector_->OnKeyEvent(&event)); | 142 EXPECT_FALSE(detector_->OnKeyEvent(&event)); |
145 EXPECT_EQ(1, observer_->num_invocations()); | 143 EXPECT_EQ(1, observer_->num_invocations()); |
146 observer_->reset_stats(); | 144 observer_->reset_stats(); |
147 | 145 |
148 // It shouldn't be notified if a second event occurs | 146 // It shouldn't be notified if a second event occurs |
149 // in the same instant in time. | 147 // in the same instant in time. |
(...skipping 13 matching lines...) Expand all Loading... |
163 // rate limit. This should let us trigger another notification. | 161 // rate limit. This should let us trigger another notification. |
164 AdvanceTime(base::TimeDelta::FromMilliseconds( | 162 AdvanceTime(base::TimeDelta::FromMilliseconds( |
165 UserActivityDetector::kNotifyIntervalMs)); | 163 UserActivityDetector::kNotifyIntervalMs)); |
166 | 164 |
167 EXPECT_EQ(ui::ER_UNHANDLED, detector_->OnKeyEvent(&event)); | 165 EXPECT_EQ(ui::ER_UNHANDLED, detector_->OnKeyEvent(&event)); |
168 EXPECT_EQ(1, observer_->num_invocations()); | 166 EXPECT_EQ(1, observer_->num_invocations()); |
169 } | 167 } |
170 | 168 |
171 // Checks that the detector ignores synthetic mouse events. | 169 // Checks that the detector ignores synthetic mouse events. |
172 TEST_F(UserActivityDetectorTest, IgnoreSyntheticMouseEvents) { | 170 TEST_F(UserActivityDetectorTest, IgnoreSyntheticMouseEvents) { |
173 scoped_ptr<aura::Window> window( | 171 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(12345)); |
174 aura::test::CreateTestWindowWithId(12345, NULL)); | |
175 ui::MouseEvent mouse_event( | 172 ui::MouseEvent mouse_event( |
176 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), ui::EF_IS_SYNTHESIZED); | 173 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), ui::EF_IS_SYNTHESIZED); |
177 SetEventTarget(window.get(), &mouse_event); | 174 SetEventTarget(window.get(), &mouse_event); |
178 EXPECT_EQ(ui::ER_UNHANDLED, detector_->OnMouseEvent(&mouse_event)); | 175 EXPECT_EQ(ui::ER_UNHANDLED, detector_->OnMouseEvent(&mouse_event)); |
179 EXPECT_EQ(0, observer_->num_invocations()); | 176 EXPECT_EQ(0, observer_->num_invocations()); |
180 } | 177 } |
181 | 178 |
182 } // namespace test | 179 } // namespace test |
183 } // namespace ash | 180 } // namespace ash |
OLD | NEW |