Index: remoting/host/remote_input_filter_unittest.cc |
diff --git a/remoting/host/remote_input_filter_unittest.cc b/remoting/host/remote_input_filter_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2cebb2200e7c886a78bda8ad277785d2336159f9 |
--- /dev/null |
+++ b/remoting/host/remote_input_filter_unittest.cc |
@@ -0,0 +1,91 @@ |
+// Copyright (c) 2012 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 "remoting/host/remote_input_filter.h" |
+ |
+#include "remoting/proto/event.pb.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+using ::testing::_; |
+using ::testing::ExpectationSet; |
+using ::testing::InSequence; |
+ |
+namespace remoting { |
+ |
+class MockInputStub : public protocol::InputStub { |
+ public: |
+ MockInputStub() {} |
+ |
+ MOCK_METHOD1(InjectKeyEvent, void(const protocol::KeyEvent&)); |
+ MOCK_METHOD1(InjectMouseEvent, void(const protocol::MouseEvent&)); |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(MockInputStub); |
+}; |
+ |
+static protocol::MouseEvent MouseMoveEvent(int x, int y) { |
+ protocol::MouseEvent event; |
+ event.set_x(x); |
+ event.set_y(y); |
+ return event; |
+} |
+ |
+// Verify that events get through if there is no local activity. |
+TEST(RemoteInputFilterTest, NoLocalActivity) { |
+ MockInputStub mock_stub; |
+ RemoteInputFilter input_filter(&mock_stub); |
+ |
+ EXPECT_CALL(mock_stub, InjectMouseEvent(_)) |
+ .Times(10); |
+ |
+ for (int i=0; i<10; ++1) |
+ input_filter.InjectMouseEvent(MouseMoveEvent(0, 0)); |
+} |
+ |
+// Verify that events get through until there is local activity. |
+TEST(MouseInputFilterTest, MismatchedLocalActivity) { |
+ MockInputStub mock_stub; |
+ RemoteInputFilter input_filter(&mock_stub); |
+ |
+ EXPECT_CALL(mock_stub, InjectMouseEvent(_)) |
+ .Times(5); |
+ |
+ for (int i=0; i<5; ++1) |
+ input_filter.InjectMouseEvent(MouseMoveEvent(0, 0)); |
+ input_filter.LocalMouseMoved(SkIPoint::Make(1, 1)); |
+ for (int i=0; i<5; ++1) |
+ input_filter.InjectMouseEvent(MouseMoveEvent(0, 0)); |
+} |
+ |
+// Verify that echos of injected events don't block activity. |
+TEST(MouseInputFilterTest, LocalEchosOfRemoteActivity) { |
Jamie
2012/03/15 18:38:56
s/Echos/Echoes/g :)
Wez
2012/03/15 22:25:29
Done.
|
+ MockInputStub mock_stub; |
+ RemoteInputFilter input_filter(&mock_stub); |
+ |
+ EXPECT_CALL(mock_stub, InjectMouseEvent(_)) |
+ .Times(10); |
+ |
+ for (int i=0; i<5; ++1) { |
+ input_filter.InjectMouseEvent(MouseMoveEvent(0, 0)); |
+ input_filter.LocalMouseMoved(SkIPoint::Make(0, 0)); |
+ } |
+} |
+ |
+// Verify that echos followed by a mismatch blocks activity. |
+TEST(MouseInputFilterTest, LocalEchosOfRemoteActivity) { |
+ MockInputStub mock_stub; |
+ RemoteInputFilter input_filter(&mock_stub); |
+ |
+ EXPECT_CALL(mock_stub, InjectMouseEvent(_)) |
+ .Times(5); |
+ |
+ for (int i=0; i<5; ++1) { |
+ input_filter.InjectMouseEvent(MouseMoveEvent(0, 0)); |
+ input_filter.LocalMouseMoved(SkIPoint::Make(0, 0)); |
+ if (i == 4) |
+ input_filter.LocalMouseMoved(SkIPoint::Make(1, 1)); |
+ } |
Jamie
2012/03/15 18:38:56
I think you need another InjectMouseEvent here.
Wez
2012/03/15 22:25:29
Nope; the number of events being injected was inte
|
+} |
+ |
+} // namespace remoting |