Chromium Code Reviews| Index: media/base/user_input_monitor_unittest.cc |
| diff --git a/media/base/user_input_monitor_unittest.cc b/media/base/user_input_monitor_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..407c730a677d0ee6491fd489318aaa1dffaa69fa |
| --- /dev/null |
| +++ b/media/base/user_input_monitor_unittest.cc |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/basictypes.h" |
| +#include "base/logging.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/run_loop.h" |
| +#include "media/base/keyboard_event_counter.h" |
| +#include "media/base/user_input_monitor.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "third_party/skia/include/core/SkPoint.h" |
| + |
| +namespace media { |
| + |
| +class MockMouseListener : public UserInputMonitor::MouseEventListener { |
| + public: |
| + MOCK_METHOD1(OnMouseMoved, void(const SkIPoint& position)); |
| + |
| + virtual ~MockMouseListener() {} |
| +}; |
| + |
| +TEST(UserInputMonitorTest, KeyPressCounter) { |
| + KeyboardEventCounter counter; |
| + |
| + EXPECT_EQ(0u, counter.GetKeyPressCount()); |
| + |
| + counter.OnKeyboardEvent(ui::ET_KEY_PRESSED, ui::VKEY_0); |
| + EXPECT_EQ(1u, counter.GetKeyPressCount()); |
| + |
| + // Holding the same key without releasing it does not increase the count. |
| + counter.OnKeyboardEvent(ui::ET_KEY_PRESSED, ui::VKEY_0); |
| + EXPECT_EQ(1u, counter.GetKeyPressCount()); |
| + |
| + // Releasing the key does not affect the total count. |
| + counter.OnKeyboardEvent(ui::ET_KEY_RELEASED, ui::VKEY_0); |
| + EXPECT_EQ(1u, counter.GetKeyPressCount()); |
| + |
| + counter.OnKeyboardEvent(ui::ET_KEY_PRESSED, ui::VKEY_0); |
| + counter.OnKeyboardEvent(ui::ET_KEY_RELEASED, ui::VKEY_0); |
| + EXPECT_EQ(2u, counter.GetKeyPressCount()); |
| +} |
| + |
| +#ifndef DISABLE_USER_INPUT_MONITOR |
|
DaleCurtis
2013/09/06 21:51:08
!defined()
jiayl
2013/09/06 22:43:30
Done.
|
| +TEST(UserInputMonitorTest, CreatePlatformSpecific) { |
| +#if defined(OS_LINUX) |
| + base::MessageLoop message_loop(base::MessageLoop::TYPE_IO); |
| +#else |
| + base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); |
| +#endif // defined(OS_LINUX) |
| + |
| + base::RunLoop run_loop; |
| + 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.
|
| + message_loop.message_loop_proxy(), message_loop.message_loop_proxy()); |
| + |
| + MockMouseListener listener; |
| + // Ignore any callbacks. |
| + EXPECT_CALL(listener, OnMouseMoved(testing::_)).Times(testing::AnyNumber()); |
| + |
| +#if !defined(OS_MACOSX) |
| + monitor->AddMouseListener(&listener); |
| + monitor->RemoveMouseListener(&listener); |
| +#endif // !define(OS_MACOSX) |
| + |
| + monitor->EnableKeyPressMonitoring(); |
| + monitor->DisableKeyPressMonitoring(); |
| +} |
| +#endif // DISABLE_USER_INPUT_MONITOR |
| + |
| +} // namespace media |