Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(542)

Unified Diff: media/base/user_input_monitor_unittest.cc

Issue 23702008: Adds the UserInputMonitor implementation for Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..aa8f574ec1b348e9e62de1c091baff16877ad2ef
--- /dev/null
+++ b/media/base/user_input_monitor_unittest.cc
@@ -0,0 +1,117 @@
+// 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() {}
+};
+
+class UserInputMonitorForTest : public UserInputMonitor {
+ public:
+ UserInputMonitorForTest() {}
+
+ virtual size_t GetKeyPressCount() const OVERRIDE {
+ return counter_.GetKeyPressCount();
+ }
+
+ void EmulateMouseEvent(const SkIPoint& position) {
+ UserInputMonitor::OnMouseEvent(position);
+ }
+
+ void EmulateKeyboardEvent(ui::EventType event, ui::KeyboardCode key_code) {
+ counter_.OnKeyboardEvent(event, key_code);
+ }
+
+ private:
+ virtual ~UserInputMonitorForTest() {}
+
+ virtual void StartMouseMonitoring() OVERRIDE {}
+ virtual void StopMouseMonitoring() OVERRIDE {}
+ virtual void StartKeyboardMonitoring() OVERRIDE { counter_.Reset(); }
+ virtual void StopKeyboardMonitoring() OVERRIDE {}
+
+ KeyboardEventCounter counter_;
+};
+
+TEST(UserInputMonitorTest, MouseEvent) {
+ scoped_refptr<UserInputMonitorForTest> monitor(new UserInputMonitorForTest());
+ MockMouseListener listener;
+
+ monitor->AddMouseListener(&listener);
+
+ SkIPoint pos(SkIPoint::Make(100, 100));
+ EXPECT_CALL(listener, OnMouseMoved(pos));
+ monitor->EmulateMouseEvent(pos);
+
+ monitor->RemoveMouseListener(&listener);
+}
+
+TEST(UserInputMonitorTest, KeyPressCounter) {
+ scoped_refptr<UserInputMonitorForTest> monitor(new UserInputMonitorForTest());
+
+ monitor->EnableKeyPressMonitoring();
+ EXPECT_EQ(0u, monitor->GetKeyPressCount());
+
+ monitor->EmulateKeyboardEvent(ui::ET_KEY_PRESSED, ui::VKEY_0);
+ EXPECT_EQ(1u, monitor->GetKeyPressCount());
+
+ // Holding the same key without releasing it does not increase the count.
+ monitor->EmulateKeyboardEvent(ui::ET_KEY_PRESSED, ui::VKEY_0);
+ EXPECT_EQ(1u, monitor->GetKeyPressCount());
+
+ // Releasing the key does not affect the total count.
+ monitor->EmulateKeyboardEvent(ui::ET_KEY_RELEASED, ui::VKEY_0);
+ EXPECT_EQ(1u, monitor->GetKeyPressCount());
+
+ monitor->EmulateKeyboardEvent(ui::ET_KEY_PRESSED, ui::VKEY_0);
+ monitor->EmulateKeyboardEvent(ui::ET_KEY_RELEASED, ui::VKEY_0);
+ EXPECT_EQ(2u, monitor->GetKeyPressCount());
+ monitor->DisableKeyPressMonitoring();
+}
+
+#ifndef DISABLE_USER_INPUT_MONITOR
+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_refptr<UserInputMonitor> monitor = UserInputMonitor::Create(
+ 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();
+
+ // Must wait for all tasks to finish before destroying |monitor|.
+ run_loop_.RunUntilIdle();
+}
+#endif // DISABLE_USER_INPUT_MONITOR
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698