| 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/base/user_activity/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 "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/base/user_activity/user_activity_observer.h" |
| 11 #include "ui/events/event.h" | 12 #include "ui/events/event.h" |
| 12 #include "ui/events/event_constants.h" | 13 #include "ui/events/event_constants.h" |
| 13 #include "ui/events/keycodes/keyboard_codes.h" | 14 #include "ui/events/keycodes/keyboard_codes.h" |
| 14 #include "ui/gfx/geometry/point.h" | 15 #include "ui/gfx/geometry/point.h" |
| 15 #include "ui/wm/core/user_activity_observer.h" | |
| 16 | 16 |
| 17 namespace wm { | 17 namespace ui { |
| 18 | 18 |
| 19 // Implementation that just counts the number of times we've been told that the | 19 // Implementation that just counts the number of times we've been told that the |
| 20 // user is active. | 20 // user is active. |
| 21 class TestUserActivityObserver : public UserActivityObserver { | 21 class TestUserActivityObserver : public UserActivityObserver { |
| 22 public: | 22 public: |
| 23 TestUserActivityObserver() : num_invocations_(0) {} | 23 TestUserActivityObserver() : num_invocations_(0) {} |
| 24 | 24 |
| 25 int num_invocations() const { return num_invocations_; } | 25 int num_invocations() const { return num_invocations_; } |
| 26 void reset_stats() { num_invocations_ = 0; } | 26 void reset_stats() { num_invocations_ = 0; } |
| 27 | 27 |
| 28 // UserActivityObserver implementation. | 28 // UserActivityObserver implementation. |
| 29 void OnUserActivity(const ui::Event* event) override { num_invocations_++; } | 29 void OnUserActivity(const ui::Event* event) override { num_invocations_++; } |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 // Number of times that OnUserActivity() has been called. | 32 // Number of times that OnUserActivity() has been called. |
| 33 int num_invocations_; | 33 int num_invocations_; |
| 34 | 34 |
| 35 DISALLOW_COPY_AND_ASSIGN(TestUserActivityObserver); | 35 DISALLOW_COPY_AND_ASSIGN(TestUserActivityObserver); |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 class UserActivityDetectorTest : public aura::test::AuraTestBase { | 38 class UserActivityDetectorTest : public testing::Test { |
| 39 public: | 39 public: |
| 40 UserActivityDetectorTest() {} | 40 UserActivityDetectorTest() |
| 41 ~UserActivityDetectorTest() override {} | 41 : detector_(new UserActivityDetector), |
| 42 | 42 observer_(new TestUserActivityObserver) { |
| 43 void SetUp() override { | |
| 44 AuraTestBase::SetUp(); | |
| 45 observer_.reset(new TestUserActivityObserver); | |
| 46 detector_.reset(new UserActivityDetector); | |
| 47 detector_->AddObserver(observer_.get()); | 43 detector_->AddObserver(observer_.get()); |
| 48 | |
| 49 now_ = base::TimeTicks::Now(); | 44 now_ = base::TimeTicks::Now(); |
| 50 detector_->set_now_for_test(now_); | 45 detector_->set_now_for_test(now_); |
| 51 } | 46 } |
| 52 | 47 |
| 53 void TearDown() override { | 48 ~UserActivityDetectorTest() override { |
| 54 detector_->RemoveObserver(observer_.get()); | 49 detector_->RemoveObserver(observer_.get()); |
| 55 AuraTestBase::TearDown(); | |
| 56 } | 50 } |
| 57 | 51 |
| 58 protected: | 52 protected: |
| 59 // Move |detector_|'s idea of the current time forward by |delta|. | 53 // Move |detector_|'s idea of the current time forward by |delta|. |
| 60 void AdvanceTime(base::TimeDelta delta) { | 54 void AdvanceTime(base::TimeDelta delta) { |
| 61 now_ += delta; | 55 now_ += delta; |
| 62 detector_->set_now_for_test(now_); | 56 detector_->set_now_for_test(now_); |
| 63 } | 57 } |
| 64 | 58 |
| 65 scoped_ptr<UserActivityDetector> detector_; | 59 scoped_ptr<UserActivityDetector> detector_; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 ui::MouseEvent mouse_event( | 184 ui::MouseEvent mouse_event( |
| 191 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), ui::EF_IS_SYNTHESIZED, | 185 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), ui::EF_IS_SYNTHESIZED, |
| 192 ui::EF_NONE); | 186 ui::EF_NONE); |
| 193 detector_->OnMouseEvent(&mouse_event); | 187 detector_->OnMouseEvent(&mouse_event); |
| 194 EXPECT_FALSE(mouse_event.handled()); | 188 EXPECT_FALSE(mouse_event.handled()); |
| 195 EXPECT_EQ(base::TimeTicks().ToInternalValue(), | 189 EXPECT_EQ(base::TimeTicks().ToInternalValue(), |
| 196 detector_->last_activity_time().ToInternalValue()); | 190 detector_->last_activity_time().ToInternalValue()); |
| 197 EXPECT_EQ(0, observer_->num_invocations()); | 191 EXPECT_EQ(0, observer_->num_invocations()); |
| 198 } | 192 } |
| 199 | 193 |
| 200 } // namespace wm | 194 } // namespace ui |
| OLD | NEW |