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

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

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

Powered by Google App Engine
This is Rietveld 408576698