| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 "remoting/protocol/key_event_tracker.h" | |
| 6 | |
| 7 #include "remoting/proto/event.pb.h" | |
| 8 #include "testing/gmock/include/gmock/gmock.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 using ::testing::_; | |
| 12 using ::testing::ExpectationSet; | |
| 13 using ::testing::InSequence; | |
| 14 | |
| 15 namespace remoting { | |
| 16 | |
| 17 MATCHER_P2(EqualsKeyEvent, keycode, pressed, "") { | |
| 18 return arg.keycode() == keycode && arg.pressed() == pressed; | |
| 19 } | |
| 20 | |
| 21 class MockInputStub : public protocol::InputStub { | |
| 22 public: | |
| 23 MockInputStub() {} | |
| 24 | |
| 25 MOCK_METHOD1(InjectKeyEvent, void(const protocol::KeyEvent&)); | |
| 26 MOCK_METHOD1(InjectMouseEvent, void(const protocol::MouseEvent&)); | |
| 27 private: | |
| 28 DISALLOW_COPY_AND_ASSIGN(MockInputStub); | |
| 29 }; | |
| 30 | |
| 31 static protocol::KeyEvent KeyEvent(int keycode, bool pressed) { | |
| 32 protocol::KeyEvent event; | |
| 33 event.set_keycode(keycode); | |
| 34 event.set_pressed(pressed); | |
| 35 return event; | |
| 36 } | |
| 37 | |
| 38 static void PressAndRelease(protocol::InputStub* input_stub, int keycode) { | |
| 39 input_stub->InjectKeyEvent(KeyEvent(keycode, true)); | |
| 40 input_stub->InjectKeyEvent(KeyEvent(keycode, false)); | |
| 41 } | |
| 42 | |
| 43 // Verify that keys that were pressed and released aren't re-released. | |
| 44 TEST(KeyEventTrackerTest, NothingToRelease) { | |
| 45 MockInputStub mock_stub; | |
| 46 protocol::KeyEventTracker key_tracker(&mock_stub); | |
| 47 { | |
| 48 InSequence s; | |
| 49 | |
| 50 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(1, true))); | |
| 51 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(1, false))); | |
| 52 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(2, true))); | |
| 53 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(2, false))); | |
| 54 } | |
| 55 PressAndRelease(&key_tracker, 1); | |
| 56 PressAndRelease(&key_tracker, 2); | |
| 57 } | |
| 58 | |
| 59 // Verify that keys that were left pressed get released. | |
| 60 TEST(KeyEventTrackerTest, ReleaseAllKeys) { | |
| 61 MockInputStub mock_stub; | |
| 62 protocol::KeyEventTracker key_tracker(&mock_stub); | |
| 63 ExpectationSet injects; | |
| 64 | |
| 65 { | |
| 66 InSequence s; | |
| 67 | |
| 68 injects += EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(3, true))); | |
| 69 injects += EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(1, true))); | |
| 70 injects += EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(1, false))); | |
| 71 injects += EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(2, true))); | |
| 72 injects += EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(2, false))); | |
| 73 } | |
| 74 | |
| 75 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(3, false))) | |
| 76 .After(injects); | |
| 77 | |
| 78 key_tracker.InjectKeyEvent(KeyEvent(3, true)); | |
| 79 PressAndRelease(&key_tracker, 1); | |
| 80 PressAndRelease(&key_tracker, 2); | |
| 81 key_tracker.ReleaseAllKeys(); | |
| 82 } | |
| 83 | |
| 84 } // namespace remoting | |
| OLD | NEW |