Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/basictypes.h" | |
| 6 #include "base/logging.h" | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "base/run_loop.h" | |
| 10 #include "media/base/keyboard_event_counter.h" | |
| 11 #include "media/base/user_input_monitor.h" | |
| 12 #include "testing/gmock/include/gmock/gmock.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 #include "third_party/skia/include/core/SkPoint.h" | |
| 15 | |
| 16 namespace media { | |
| 17 | |
| 18 class MockMouseListener : public UserInputMonitor::MouseEventListener { | |
| 19 public: | |
| 20 MOCK_METHOD1(OnMouseMoved, void(const SkIPoint& position)); | |
| 21 | |
| 22 virtual ~MockMouseListener() {} | |
| 23 }; | |
| 24 | |
| 25 TEST(UserInputMonitorTest, KeyPressCounter) { | |
| 26 KeyboardEventCounter counter; | |
| 27 | |
| 28 EXPECT_EQ(0u, counter.GetKeyPressCount()); | |
| 29 | |
| 30 counter.OnKeyboardEvent(ui::ET_KEY_PRESSED, ui::VKEY_0); | |
| 31 EXPECT_EQ(1u, counter.GetKeyPressCount()); | |
| 32 | |
| 33 // Holding the same key without releasing it does not increase the count. | |
| 34 counter.OnKeyboardEvent(ui::ET_KEY_PRESSED, ui::VKEY_0); | |
| 35 EXPECT_EQ(1u, counter.GetKeyPressCount()); | |
| 36 | |
| 37 // Releasing the key does not affect the total count. | |
| 38 counter.OnKeyboardEvent(ui::ET_KEY_RELEASED, ui::VKEY_0); | |
| 39 EXPECT_EQ(1u, counter.GetKeyPressCount()); | |
| 40 | |
| 41 counter.OnKeyboardEvent(ui::ET_KEY_PRESSED, ui::VKEY_0); | |
| 42 counter.OnKeyboardEvent(ui::ET_KEY_RELEASED, ui::VKEY_0); | |
| 43 EXPECT_EQ(2u, counter.GetKeyPressCount()); | |
| 44 } | |
| 45 | |
| 46 #ifndef DISABLE_USER_INPUT_MONITOR | |
|
DaleCurtis
2013/09/06 21:51:08
!defined()
jiayl
2013/09/06 22:43:30
Done.
| |
| 47 TEST(UserInputMonitorTest, CreatePlatformSpecific) { | |
| 48 #if defined(OS_LINUX) | |
| 49 base::MessageLoop message_loop(base::MessageLoop::TYPE_IO); | |
| 50 #else | |
| 51 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); | |
| 52 #endif // defined(OS_LINUX) | |
| 53 | |
| 54 base::RunLoop run_loop; | |
| 55 scoped_ptr<UserInputMonitor> monitor = UserInputMonitor::Create( | |
|
DaleCurtis
2013/09/06 21:51:08
Just stack allocate?
jiayl
2013/09/06 22:43:30
But UserInputMonitor::Create returns scoped_ptr.
| |
| 56 message_loop.message_loop_proxy(), message_loop.message_loop_proxy()); | |
| 57 | |
| 58 MockMouseListener listener; | |
| 59 // Ignore any callbacks. | |
| 60 EXPECT_CALL(listener, OnMouseMoved(testing::_)).Times(testing::AnyNumber()); | |
| 61 | |
| 62 #if !defined(OS_MACOSX) | |
| 63 monitor->AddMouseListener(&listener); | |
| 64 monitor->RemoveMouseListener(&listener); | |
| 65 #endif // !define(OS_MACOSX) | |
| 66 | |
| 67 monitor->EnableKeyPressMonitoring(); | |
| 68 monitor->DisableKeyPressMonitoring(); | |
| 69 } | |
| 70 #endif // DISABLE_USER_INPUT_MONITOR | |
| 71 | |
| 72 } // namespace media | |
| OLD | NEW |