| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/wm/core/user_activity_detector.h" | 5 #include "ui/wm/core/user_activity_detector.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "ui/aura/test/aura_test_base.h" | 10 #include "ui/aura/test/aura_test_base.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 base::TimeTicks now_; | 70 base::TimeTicks now_; |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 DISALLOW_COPY_AND_ASSIGN(UserActivityDetectorTest); | 73 DISALLOW_COPY_AND_ASSIGN(UserActivityDetectorTest); |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 // Checks that the observer is notified in response to different types of input | 76 // Checks that the observer is notified in response to different types of input |
| 77 // events. | 77 // events. |
| 78 TEST_F(UserActivityDetectorTest, Basic) { | 78 TEST_F(UserActivityDetectorTest, Basic) { |
| 79 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE, false); | 79 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
| 80 detector_->OnKeyEvent(&key_event); | 80 detector_->OnKeyEvent(&key_event); |
| 81 EXPECT_FALSE(key_event.handled()); | 81 EXPECT_FALSE(key_event.handled()); |
| 82 EXPECT_EQ(now_.ToInternalValue(), | 82 EXPECT_EQ(now_.ToInternalValue(), |
| 83 detector_->last_activity_time().ToInternalValue()); | 83 detector_->last_activity_time().ToInternalValue()); |
| 84 EXPECT_EQ(1, observer_->num_invocations()); | 84 EXPECT_EQ(1, observer_->num_invocations()); |
| 85 observer_->reset_stats(); | 85 observer_->reset_stats(); |
| 86 | 86 |
| 87 base::TimeDelta advance_delta = base::TimeDelta::FromMilliseconds( | 87 base::TimeDelta advance_delta = base::TimeDelta::FromMilliseconds( |
| 88 UserActivityDetector::kNotifyIntervalMs); | 88 UserActivityDetector::kNotifyIntervalMs); |
| 89 AdvanceTime(advance_delta); | 89 AdvanceTime(advance_delta); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 EXPECT_FALSE(gesture_event.handled()); | 146 EXPECT_FALSE(gesture_event.handled()); |
| 147 EXPECT_EQ(now_.ToInternalValue(), | 147 EXPECT_EQ(now_.ToInternalValue(), |
| 148 detector_->last_activity_time().ToInternalValue()); | 148 detector_->last_activity_time().ToInternalValue()); |
| 149 EXPECT_EQ(1, observer_->num_invocations()); | 149 EXPECT_EQ(1, observer_->num_invocations()); |
| 150 observer_->reset_stats(); | 150 observer_->reset_stats(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 // Checks that observers aren't notified too frequently. | 153 // Checks that observers aren't notified too frequently. |
| 154 TEST_F(UserActivityDetectorTest, RateLimitNotifications) { | 154 TEST_F(UserActivityDetectorTest, RateLimitNotifications) { |
| 155 // The observer should be notified about a key event. | 155 // The observer should be notified about a key event. |
| 156 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE, false); | 156 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
| 157 detector_->OnKeyEvent(&event); | 157 detector_->OnKeyEvent(&event); |
| 158 EXPECT_FALSE(event.handled()); | 158 EXPECT_FALSE(event.handled()); |
| 159 EXPECT_EQ(1, observer_->num_invocations()); | 159 EXPECT_EQ(1, observer_->num_invocations()); |
| 160 observer_->reset_stats(); | 160 observer_->reset_stats(); |
| 161 | 161 |
| 162 // It shouldn't be notified if a second event occurs in the same instant in | 162 // It shouldn't be notified if a second event occurs in the same instant in |
| 163 // time. | 163 // time. |
| 164 detector_->OnKeyEvent(&event); | 164 detector_->OnKeyEvent(&event); |
| 165 EXPECT_FALSE(event.handled()); | 165 EXPECT_FALSE(event.handled()); |
| 166 EXPECT_EQ(0, observer_->num_invocations()); | 166 EXPECT_EQ(0, observer_->num_invocations()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 191 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), ui::EF_IS_SYNTHESIZED, | 191 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), ui::EF_IS_SYNTHESIZED, |
| 192 ui::EF_NONE); | 192 ui::EF_NONE); |
| 193 detector_->OnMouseEvent(&mouse_event); | 193 detector_->OnMouseEvent(&mouse_event); |
| 194 EXPECT_FALSE(mouse_event.handled()); | 194 EXPECT_FALSE(mouse_event.handled()); |
| 195 EXPECT_EQ(base::TimeTicks().ToInternalValue(), | 195 EXPECT_EQ(base::TimeTicks().ToInternalValue(), |
| 196 detector_->last_activity_time().ToInternalValue()); | 196 detector_->last_activity_time().ToInternalValue()); |
| 197 EXPECT_EQ(0, observer_->num_invocations()); | 197 EXPECT_EQ(0, observer_->num_invocations()); |
| 198 } | 198 } |
| 199 | 199 |
| 200 } // namespace wm | 200 } // namespace wm |
| OLD | NEW |