OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/protocol/key_event_tracker.h" | 5 #include "remoting/protocol/key_event_tracker.h" |
6 | 6 |
7 #include "remoting/proto/event.pb.h" | 7 #include "remoting/proto/event.pb.h" |
8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... | |
34 event.set_pressed(pressed); | 34 event.set_pressed(pressed); |
35 return event; | 35 return event; |
36 } | 36 } |
37 | 37 |
38 static void PressAndRelease(protocol::InputStub* input_stub, int keycode) { | 38 static void PressAndRelease(protocol::InputStub* input_stub, int keycode) { |
39 input_stub->InjectKeyEvent(KeyEvent(keycode, true)); | 39 input_stub->InjectKeyEvent(KeyEvent(keycode, true)); |
40 input_stub->InjectKeyEvent(KeyEvent(keycode, false)); | 40 input_stub->InjectKeyEvent(KeyEvent(keycode, false)); |
41 } | 41 } |
42 | 42 |
43 // Verify that keys that were pressed and released aren't re-released. | 43 // Verify that keys that were pressed and released aren't re-released. |
44 TEST(KeyEventTrackerTest, NothingToRelease) { | 44 TEST(InputEventTrackerTest, NothingToRelease) { |
Jamie
2012/03/15 18:38:56
Since this is now testing a class that deals with
Wez
2012/03/15 22:25:29
Done.
| |
45 MockInputStub mock_stub; | 45 MockInputStub mock_stub; |
46 protocol::KeyEventTracker key_tracker(&mock_stub); | 46 protocol::InputEventTracker key_tracker(&mock_stub); |
47 { | 47 { |
48 InSequence s; | 48 InSequence s; |
49 | 49 |
50 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(1, true))); | 50 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(1, true))); |
51 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(1, false))); | 51 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(1, false))); |
52 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(2, true))); | 52 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(2, true))); |
53 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(2, false))); | 53 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(2, false))); |
54 } | 54 } |
55 PressAndRelease(&key_tracker, 1); | 55 PressAndRelease(&key_tracker, 1); |
56 PressAndRelease(&key_tracker, 2); | 56 PressAndRelease(&key_tracker, 2); |
57 key_tracker.ReleaseAll(); | |
57 } | 58 } |
58 | 59 |
59 // Verify that keys that were left pressed get released. | 60 // Verify that keys that were left pressed get released. |
60 TEST(KeyEventTrackerTest, ReleaseAllKeys) { | 61 TEST(InputEventTrackerTest, ReleaseAllKeys) { |
61 MockInputStub mock_stub; | 62 MockInputStub mock_stub; |
62 protocol::KeyEventTracker key_tracker(&mock_stub); | 63 protocol::InputEventTracker key_tracker(&mock_stub); |
63 ExpectationSet injects; | 64 ExpectationSet injects; |
64 | 65 |
65 { | 66 { |
66 InSequence s; | 67 InSequence s; |
67 | 68 |
68 injects += EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(3, true))); | 69 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, true))); |
70 injects += EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(1, false))); | 71 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, true))); |
72 injects += EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(2, false))); | 73 injects += EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(2, false))); |
73 } | 74 } |
74 | 75 |
75 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(3, false))) | 76 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(3, false))) |
76 .After(injects); | 77 .After(injects); |
77 | 78 |
78 key_tracker.InjectKeyEvent(KeyEvent(3, true)); | 79 key_tracker.InjectKeyEvent(KeyEvent(3, true)); |
79 PressAndRelease(&key_tracker, 1); | 80 PressAndRelease(&key_tracker, 1); |
80 PressAndRelease(&key_tracker, 2); | 81 PressAndRelease(&key_tracker, 2); |
81 key_tracker.ReleaseAllKeys(); | 82 key_tracker.ReleaseAll(); |
82 } | 83 } |
83 | 84 |
84 } // namespace remoting | 85 } // namespace remoting |
OLD | NEW |