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

Side by Side Diff: remoting/protocol/mouse_input_filter_unittest.cc

Issue 23440046: Remove dependency on Skia from chromoting client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/protocol/mouse_input_filter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/mouse_input_filter.h" 5 #include "remoting/protocol/mouse_input_filter.h"
6 6
7 #include "remoting/proto/event.pb.h" 7 #include "remoting/proto/event.pb.h"
8 #include "remoting/protocol/protocol_mock_objects.h" 8 #include "remoting/protocol/protocol_mock_objects.h"
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/skia/include/core/SkPoint.h" 11 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
12 12
13 using ::testing::_; 13 using ::testing::_;
14 using ::testing::InSequence; 14 using ::testing::InSequence;
15 15
16 namespace remoting { 16 namespace remoting {
17 namespace protocol { 17 namespace protocol {
18 18
19 MATCHER_P2(EqualsMouseMoveEvent, x, y, "") { 19 MATCHER_P2(EqualsMouseMoveEvent, x, y, "") {
20 return arg.x() == x && arg.y() == y; 20 return arg.x() == x && arg.y() == y;
21 } 21 }
22 22
23 static MouseEvent MouseMoveEvent(int x, int y) { 23 static MouseEvent MouseMoveEvent(int x, int y) {
24 MouseEvent event; 24 MouseEvent event;
25 event.set_x(x); 25 event.set_x(x);
26 event.set_y(y); 26 event.set_y(y);
27 return event; 27 return event;
28 } 28 }
29 29
30 static void InjectTestSequence(InputStub* input_stub) { 30 static void InjectTestSequence(InputStub* input_stub) {
31 static const SkIPoint input_sequence[] = { 31 struct Point {
32 int x;
33 int y;
34 };
35 static const Point input_sequence[] = {
32 {-5, 10}, {0, 10}, {-1, 10}, {15, 40}, {15, 45}, {15, 39}, {15, 25} 36 {-5, 10}, {0, 10}, {-1, 10}, {15, 40}, {15, 45}, {15, 39}, {15, 25}
33 }; 37 };
34 for (unsigned int i=0; i<arraysize(input_sequence); ++i) { 38 // arraysize() cannot be used here, becase Point is declared inside of a
35 const SkIPoint& point = input_sequence[i]; 39 // function.
36 input_stub->InjectMouseEvent(MouseMoveEvent(point.x(), point.y())); 40 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(input_sequence); ++i) {
41 const Point& point = input_sequence[i];
42 input_stub->InjectMouseEvent(MouseMoveEvent(point.x, point.y));
37 } 43 }
38 for (unsigned int i=0; i<arraysize(input_sequence); ++i) { 44 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(input_sequence); ++i) {
39 const SkIPoint& point = input_sequence[i]; 45 const Point& point = input_sequence[i];
40 input_stub->InjectMouseEvent(MouseMoveEvent(point.y(), point.x())); 46 input_stub->InjectMouseEvent(MouseMoveEvent(point.y, point.x));
41 } 47 }
42 } 48 }
43 49
44 // Verify that no events get through if we don't set either dimensions. 50 // Verify that no events get through if we don't set either dimensions.
45 TEST(MouseInputFilterTest, BothDimensionsZero) { 51 TEST(MouseInputFilterTest, BothDimensionsZero) {
46 MockInputStub mock_stub; 52 MockInputStub mock_stub;
47 MouseInputFilter mouse_filter(&mock_stub); 53 MouseInputFilter mouse_filter(&mock_stub);
48 54
49 EXPECT_CALL(mock_stub, InjectMouseEvent(_)) 55 EXPECT_CALL(mock_stub, InjectMouseEvent(_))
50 .Times(0); 56 .Times(0);
51 57
52 InjectTestSequence(&mouse_filter); 58 InjectTestSequence(&mouse_filter);
53 } 59 }
54 60
55 // Verify that no events get through if there's no input size. 61 // Verify that no events get through if there's no input size.
56 TEST(MouseInputFilterTest, InputDimensionsZero) { 62 TEST(MouseInputFilterTest, InputDimensionsZero) {
57 MockInputStub mock_stub; 63 MockInputStub mock_stub;
58 MouseInputFilter mouse_filter(&mock_stub); 64 MouseInputFilter mouse_filter(&mock_stub);
59 mouse_filter.set_output_size(SkISize::Make(50,50)); 65 mouse_filter.set_output_size(webrtc::DesktopSize(50, 50));
60 66
61 EXPECT_CALL(mock_stub, InjectMouseEvent(_)) 67 EXPECT_CALL(mock_stub, InjectMouseEvent(_))
62 .Times(0); 68 .Times(0);
63 69
64 InjectTestSequence(&mouse_filter); 70 InjectTestSequence(&mouse_filter);
65 } 71 }
66 72
67 // Verify that no events get through if there's no output size. 73 // Verify that no events get through if there's no output size.
68 TEST(MouseInputFilterTest, OutputDimensionsZero) { 74 TEST(MouseInputFilterTest, OutputDimensionsZero) {
69 MockInputStub mock_stub; 75 MockInputStub mock_stub;
70 MouseInputFilter mouse_filter(&mock_stub); 76 MouseInputFilter mouse_filter(&mock_stub);
71 mouse_filter.set_input_size(SkISize::Make(50,50)); 77 mouse_filter.set_input_size(webrtc::DesktopSize(50, 50));
72 78
73 EXPECT_CALL(mock_stub, InjectMouseEvent(_)) 79 EXPECT_CALL(mock_stub, InjectMouseEvent(_))
74 .Times(0); 80 .Times(0);
75 81
76 InjectTestSequence(&mouse_filter); 82 InjectTestSequence(&mouse_filter);
77 } 83 }
78 84
79 // Verify that all events get through, clamped to the output. 85 // Verify that all events get through, clamped to the output.
80 TEST(MouseInputFilterTest, NoScalingOrClipping) { 86 TEST(MouseInputFilterTest, NoScalingOrClipping) {
81 MockInputStub mock_stub; 87 MockInputStub mock_stub;
82 MouseInputFilter mouse_filter(&mock_stub); 88 MouseInputFilter mouse_filter(&mock_stub);
83 mouse_filter.set_output_size(SkISize::Make(40,40)); 89 mouse_filter.set_output_size(webrtc::DesktopSize(40,40));
84 mouse_filter.set_input_size(SkISize::Make(40,40)); 90 mouse_filter.set_input_size(webrtc::DesktopSize(40,40));
85 91
86 { 92 {
87 InSequence s; 93 InSequence s;
88 94
89 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(0, 10))). 95 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(0, 10))).
90 Times(3); 96 Times(3);
91 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(15, 39))). 97 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(15, 39))).
92 Times(3); 98 Times(3);
93 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(15, 25))). 99 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(15, 25))).
94 Times(1); 100 Times(1);
95 101
96 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(10, 0))). 102 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(10, 0))).
97 Times(3); 103 Times(3);
98 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(39, 15))). 104 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(39, 15))).
99 Times(3); 105 Times(3);
100 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(25, 15))). 106 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(25, 15))).
101 Times(1); 107 Times(1);
102 } 108 }
103 109
104 InjectTestSequence(&mouse_filter); 110 InjectTestSequence(&mouse_filter);
105 } 111 }
106 112
107 // Verify that we can up-scale with clamping. 113 // Verify that we can up-scale with clamping.
108 TEST(MouseInputFilterTest, UpScalingAndClamping) { 114 TEST(MouseInputFilterTest, UpScalingAndClamping) {
109 MockInputStub mock_stub; 115 MockInputStub mock_stub;
110 MouseInputFilter mouse_filter(&mock_stub); 116 MouseInputFilter mouse_filter(&mock_stub);
111 mouse_filter.set_output_size(SkISize::Make(80,80)); 117 mouse_filter.set_output_size(webrtc::DesktopSize(80, 80));
112 mouse_filter.set_input_size(SkISize::Make(40,40)); 118 mouse_filter.set_input_size(webrtc::DesktopSize(40, 40));
113 119
114 { 120 {
115 InSequence s; 121 InSequence s;
116 122
117 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(0, 20))). 123 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(0, 20))).
118 Times(3); 124 Times(3);
119 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(30, 79))). 125 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(30, 79))).
120 Times(3); 126 Times(3);
121 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(30, 51))). 127 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(30, 51))).
122 Times(1); 128 Times(1);
123 129
124 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(20, 0))). 130 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(20, 0))).
125 Times(3); 131 Times(3);
126 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(79, 30))). 132 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(79, 30))).
127 Times(3); 133 Times(3);
128 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(51, 30))). 134 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(51, 30))).
129 Times(1); 135 Times(1);
130 } 136 }
131 137
132 InjectTestSequence(&mouse_filter); 138 InjectTestSequence(&mouse_filter);
133 } 139 }
134 140
135 // Verify that we can down-scale with clamping. 141 // Verify that we can down-scale with clamping.
136 TEST(MouseInputFilterTest, DownScalingAndClamping) { 142 TEST(MouseInputFilterTest, DownScalingAndClamping) {
137 MockInputStub mock_stub; 143 MockInputStub mock_stub;
138 MouseInputFilter mouse_filter(&mock_stub); 144 MouseInputFilter mouse_filter(&mock_stub);
139 mouse_filter.set_output_size(SkISize::Make(30,30)); 145 mouse_filter.set_output_size(webrtc::DesktopSize(30, 30));
140 mouse_filter.set_input_size(SkISize::Make(40,40)); 146 mouse_filter.set_input_size(webrtc::DesktopSize(40, 40));
141 147
142 { 148 {
143 InSequence s; 149 InSequence s;
144 150
145 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(0, 7))). 151 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(0, 7))).
146 Times(3); 152 Times(3);
147 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(11, 29))). 153 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(11, 29))).
148 Times(3); 154 Times(3);
149 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(11, 19))). 155 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(11, 19))).
150 Times(1); 156 Times(1);
151 157
152 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(7, 0))). 158 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(7, 0))).
153 Times(3); 159 Times(3);
154 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(29, 11))). 160 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(29, 11))).
155 Times(3); 161 Times(3);
156 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(19, 11))). 162 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(19, 11))).
157 Times(1); 163 Times(1);
158 164
159 } 165 }
160 166
161 InjectTestSequence(&mouse_filter); 167 InjectTestSequence(&mouse_filter);
162 } 168 }
163 169
164 } // namespace protocol 170 } // namespace protocol
165 } // namespace remoting 171 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/mouse_input_filter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698