OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
6 #error "This file requires ARC support." | |
7 #endif | |
8 | |
9 #import "remoting/ios/ui/scene_view.h" | |
10 | |
11 #import "base/compiler_specific.h" | |
12 #import "testing/gtest_mac.h" | |
13 | |
14 namespace remoting { | |
15 | |
16 namespace { | |
17 const int kClientWidth = 200; | |
18 const int kClientHeight = 100; | |
19 const webrtc::DesktopSize kClientSize(kClientWidth, kClientHeight); | |
20 // Smaller then ClientSize | |
21 const webrtc::DesktopSize kSmall(50, 75); | |
22 // Inverted - The vertical is closer to an edge than the horizontal | |
23 const webrtc::DesktopSize kSmallInversed(175, 50); | |
24 // Larger then ClientSize | |
25 const webrtc::DesktopSize kLarge(800, 125); | |
26 const webrtc::DesktopSize kLargeInversed(225, 400); | |
27 } // namespace | |
28 | |
29 class SceneViewTest : public ::testing::Test { | |
30 protected: | |
31 virtual void SetUp() OVERRIDE { | |
32 scene_ = [[SceneView alloc] init]; | |
33 [scene_ | |
34 setContentSize:CGSizeMake(kClientSize.width(), kClientSize.height())]; | |
35 [scene_ setFrameSize:kLarge]; | |
36 } | |
37 | |
38 void MakeLarge() { [scene_ setFrameSize:kLarge]; } | |
39 | |
40 SceneView* scene_; | |
41 }; | |
42 | |
43 TEST(SceneViewTest_Property, ContentSize) { | |
44 SceneView* scene = [[SceneView alloc] init]; | |
45 | |
46 [scene setContentSize:CGSizeMake(0, 0)]; | |
47 EXPECT_EQ(0, scene.contentSize.width()); | |
48 EXPECT_EQ(0, scene.contentSize.height()); | |
49 float zeros[16] = {1.0f / 0.0f, 0, 0, 0, 0, 1.0f / 0.0f, 0, 0, | |
50 0, 0, 1, 0, 0.0f / 0.0f, 0.0f / 0.0f, 0, 1}; | |
51 | |
52 ASSERT_TRUE(memcmp(zeros, scene.projectionMatrix.m, 16 * sizeof(float)) == 0); | |
53 | |
54 [scene setContentSize:CGSizeMake(kClientSize.width(), kClientSize.height())]; | |
55 EXPECT_EQ(kClientSize.width(), scene.contentSize.width()); | |
56 EXPECT_EQ(kClientSize.height(), scene.contentSize.height()); | |
57 | |
58 EXPECT_TRUE(memcmp(GLKMatrix4MakeOrtho( | |
59 0.0, kClientWidth, 0.0, kClientHeight, 1.0, -1.0).m, | |
60 scene.projectionMatrix.m, | |
61 16 * sizeof(float)) == 0); | |
62 } | |
63 | |
64 TEST(SceneViewTest_Property, FrameSizeInit) { | |
65 SceneView* scene = [[SceneView alloc] init]; | |
66 [scene setContentSize:CGSizeMake(kClientSize.width(), kClientSize.height())]; | |
67 | |
68 [scene setFrameSize:webrtc::DesktopSize(1, 1)]; | |
69 EXPECT_EQ(1, scene.frameSize.width()); | |
70 EXPECT_EQ(1, scene.frameSize.height()); | |
71 | |
72 EXPECT_EQ(0, scene.position.x); | |
73 EXPECT_EQ(0, scene.position.y); | |
74 EXPECT_EQ(1, scene.position.z); | |
75 | |
76 EXPECT_FALSE(scene.anchored.left); | |
77 EXPECT_FALSE(scene.anchored.right); | |
78 EXPECT_FALSE(scene.anchored.top); | |
79 EXPECT_FALSE(scene.anchored.bottom); | |
80 | |
81 EXPECT_EQ(0, scene.mousePosition.x()); | |
82 EXPECT_EQ(0, scene.mousePosition.y()); | |
83 } | |
84 | |
85 TEST(SceneViewTest_Property, FrameSizeLarge) { | |
86 SceneView* scene = [[SceneView alloc] init]; | |
87 [scene setContentSize:CGSizeMake(kClientSize.width(), kClientSize.height())]; | |
88 [scene setFrameSize:kLarge]; | |
89 EXPECT_EQ(kLarge.width(), scene.frameSize.width()); | |
90 EXPECT_EQ(kLarge.height(), scene.frameSize.height()); | |
91 | |
92 // Screen is positioned in the lower,left corner, zoomed until the vertical | |
93 // fits exactly, and then centered horizontally | |
94 // HOST | |
95 // CLIENT ------------------------------------------------ | |
96 // ------------ | | | |
97 // | | | | | |
98 // | | | | | |
99 // | | | | | |
100 // ------------ ------------------------------------------------ | |
101 // RESULT - ONSCREEN is completely covered, with some of the HOST off screen | |
102 // (-.-) the mouse cursor | |
103 // ----------------------------------------- | |
104 // | ONSCREEN | OFFSCREEN | | |
105 // | -.- | | | |
106 // | | | | |
107 // ----------------------------------------- | |
108 float scale = static_cast<float>(kClientSize.height()) / | |
109 static_cast<float>(kLarge.height()); | |
110 // vertical fits exactly | |
111 EXPECT_EQ(scale, scene.position.z); | |
112 | |
113 // sitting on both Axis | |
114 EXPECT_EQ(0, scene.position.x); | |
115 EXPECT_EQ(0, scene.position.y); | |
116 | |
117 // bound on 3 sides, not on the right | |
118 EXPECT_TRUE(scene.anchored.left); | |
119 EXPECT_FALSE(scene.anchored.right); | |
120 EXPECT_TRUE(scene.anchored.top); | |
121 EXPECT_TRUE(scene.anchored.bottom); | |
122 | |
123 // mouse is off center on the left horizontal | |
124 EXPECT_EQ(kClientSize.width() / (scale * 2), scene.mousePosition.x()); | |
125 // mouse is centered vertical | |
126 EXPECT_EQ(kLarge.height() / 2, scene.mousePosition.y()); | |
127 } | |
128 | |
129 TEST(SceneViewTest_Property, FrameSizeLargeInversed) { | |
130 SceneView* scene = [[SceneView alloc] init]; | |
131 [scene setContentSize:CGSizeMake(kClientSize.width(), kClientSize.height())]; | |
132 [scene setFrameSize:kLargeInversed]; | |
133 EXPECT_EQ(kLargeInversed.width(), scene.frameSize.width()); | |
134 EXPECT_EQ(kLargeInversed.height(), scene.frameSize.height()); | |
135 | |
136 // Screen is positioned in the lower,left corner, zoomed until the vertical | |
137 // fits exactly, and then centered horizontally | |
138 // HOST | |
139 // --------------- | |
140 // | | | |
141 // | | | |
142 // | | | |
143 // | | | |
144 // | | | |
145 // | | | |
146 // | | | |
147 // CLIENT | | | |
148 // ------------- | | | |
149 // | | | | | |
150 // | | | | | |
151 // | | | | | |
152 // ------------- --------------- | |
153 // RESULT, entire HOST is on screen | |
154 // (-.-) the mouse cursor, XX is black backdrop | |
155 // ------------- | |
156 // |XX| |XX| | |
157 // |XX| -.- |XX| | |
158 // |XX| |XX| | |
159 // ------------- | |
160 float scale = static_cast<float>(kClientSize.height()) / | |
161 static_cast<float>(kLargeInversed.height()); | |
162 // Vertical fits exactly | |
163 EXPECT_EQ(scale, scene.position.z); | |
164 | |
165 // centered | |
166 EXPECT_EQ( | |
167 (kClientSize.width() - static_cast<int>(scale * kLargeInversed.width())) / | |
168 2, | |
169 scene.position.x); | |
170 // sits on Axis | |
171 EXPECT_EQ(0, scene.position.y); | |
172 | |
173 // bound on all 4 sides | |
174 EXPECT_TRUE(scene.anchored.left); | |
175 EXPECT_TRUE(scene.anchored.right); | |
176 EXPECT_TRUE(scene.anchored.top); | |
177 EXPECT_TRUE(scene.anchored.bottom); | |
178 | |
179 // mouse is in centered both vertical and horizontal | |
180 EXPECT_EQ(kLargeInversed.width() / 2, scene.mousePosition.x()); | |
181 EXPECT_EQ(kLargeInversed.height() / 2, scene.mousePosition.y()); | |
182 } | |
183 | |
184 TEST(SceneViewTest_Property, FrameSizeSmall) { | |
185 SceneView* scene = [[SceneView alloc] init]; | |
186 [scene setContentSize:CGSizeMake(kClientSize.width(), kClientSize.height())]; | |
187 [scene setFrameSize:kSmall]; | |
188 EXPECT_EQ(kSmall.width(), scene.frameSize.width()); | |
189 EXPECT_EQ(kSmall.height(), scene.frameSize.height()); | |
190 | |
191 // Screen is positioned in the lower,left corner, zoomed until the vertical | |
192 // fits exactly, and then centered horizontally | |
193 // CLIENT | |
194 // --------------------------- | |
195 // | | HOST | |
196 // | | ------- | |
197 // | | | | | |
198 // | | | | | |
199 // | | | | | |
200 // | | | | | |
201 // | | | | | |
202 // --------------------------- ------- | |
203 // RESULT, entire HOST is on screen | |
204 // (-.-) the mouse cursor, XX is black backdrop | |
205 // --------------------------- | |
206 // |XXXXXXXXX| |XXXXXXXXX| | |
207 // |XXXXXXXXX| |XXXXXXXXX| | |
208 // |XXXXXXXXX| |XXXXXXXXX| | |
209 // |XXXXXXXXX| -.- |XXXXXXXXX| | |
210 // |XXXXXXXXX| |XXXXXXXXX| | |
211 // |XXXXXXXXX| |XXXXXXXXX| | |
212 // |XXXXXXXXX| |XXXXXXXXX| | |
213 // --------------------------- | |
214 float scale = static_cast<float>(kClientSize.height()) / | |
215 static_cast<float>(kSmall.height()); | |
216 // Vertical fits exactly | |
217 EXPECT_EQ(scale, scene.position.z); | |
218 | |
219 // centered | |
220 EXPECT_EQ( | |
221 (kClientSize.width() - static_cast<int>(scale * kSmall.width())) / 2, | |
222 scene.position.x); | |
223 // sits on Axis | |
224 EXPECT_EQ(0, scene.position.y); | |
225 | |
226 // bound on all 4 sides | |
227 EXPECT_TRUE(scene.anchored.left); | |
228 EXPECT_TRUE(scene.anchored.right); | |
229 EXPECT_TRUE(scene.anchored.top); | |
230 EXPECT_TRUE(scene.anchored.bottom); | |
231 | |
232 // mouse is in centered both vertical and horizontal | |
233 EXPECT_EQ((kSmall.width() / 2) - 1, // -1 for pixel rounding | |
234 scene.mousePosition.x()); | |
235 EXPECT_EQ(kSmall.height() / 2, scene.mousePosition.y()); | |
236 } | |
237 | |
238 TEST(SceneViewTest_Property, FrameSizeSmallInversed) { | |
239 SceneView* scene = [[SceneView alloc] init]; | |
240 [scene setContentSize:CGSizeMake(kClientSize.width(), kClientSize.height())]; | |
241 [scene setFrameSize:kSmallInversed]; | |
242 EXPECT_EQ(kSmallInversed.width(), scene.frameSize.width()); | |
243 EXPECT_EQ(kSmallInversed.height(), scene.frameSize.height()); | |
244 | |
245 // Screen is positioned in the lower,left corner, zoomed until the vertical | |
246 // fits exactly, and then centered horizontally | |
247 // CLIENT | |
248 // --------------------------- | |
249 // | | | |
250 // | | | |
251 // | | HOST | |
252 // | | ---------------------- | |
253 // | | | | | |
254 // | | | | | |
255 // | | | | | |
256 // --------------------------- ---------------------- | |
257 // RESULT - ONSCREEN is completely covered, with some of the HOST off screen | |
258 // (-.-) the mouse cursor | |
259 // -------------------------------------------- | |
260 // | ONSCREEN | OFFSCREEN | | |
261 // | | | | |
262 // | | | | |
263 // | -.- | | | |
264 // | | | | |
265 // | | | | |
266 // | | | | |
267 // -------------------------------------------- | |
268 float scale = static_cast<float>(kClientSize.height()) / | |
269 static_cast<float>(kSmallInversed.height()); | |
270 // vertical fits exactly | |
271 EXPECT_EQ(scale, scene.position.z); | |
272 | |
273 // sitting on both Axis | |
274 EXPECT_EQ(0, scene.position.x); | |
275 EXPECT_EQ(0, scene.position.y); | |
276 | |
277 // bound on 3 sides, not on the right | |
278 EXPECT_TRUE(scene.anchored.left); | |
279 EXPECT_FALSE(scene.anchored.right); | |
280 EXPECT_TRUE(scene.anchored.top); | |
281 EXPECT_TRUE(scene.anchored.bottom); | |
282 | |
283 // mouse is off center on the left horizontal | |
284 EXPECT_EQ(kClientSize.width() / (scale * 2), scene.mousePosition.x()); | |
285 // mouse is centered vertical | |
286 EXPECT_EQ(kSmallInversed.height() / 2, scene.mousePosition.y()); | |
287 } | |
288 | |
289 TEST_F(SceneViewTest, ContainsTouchPoint) { | |
290 int midWidth = kClientWidth / 2; | |
291 int midHeight = kClientHeight / 2; | |
292 // left | |
293 EXPECT_FALSE([scene_ containsTouchPoint:CGPointMake(-1, midHeight)]); | |
294 EXPECT_TRUE([scene_ containsTouchPoint:CGPointMake(0, midHeight)]); | |
295 // right | |
296 EXPECT_FALSE( | |
297 [scene_ containsTouchPoint:CGPointMake(kClientWidth, midHeight)]); | |
298 EXPECT_TRUE( | |
299 [scene_ containsTouchPoint:CGPointMake(kClientWidth - 1, midHeight)]); | |
300 // top | |
301 EXPECT_FALSE( | |
302 [scene_ containsTouchPoint:CGPointMake(midWidth, kClientHeight)]); | |
303 EXPECT_TRUE( | |
304 [scene_ containsTouchPoint:CGPointMake(midWidth, kClientHeight - 1)]); | |
305 // bottom | |
306 EXPECT_FALSE([scene_ containsTouchPoint:CGPointMake(midWidth, -1)]); | |
307 EXPECT_TRUE([scene_ containsTouchPoint:CGPointMake(midWidth, 0)]); | |
308 | |
309 [scene_ setMarginsFromLeft:10 right:10 top:10 bottom:10]; | |
310 | |
311 // left | |
312 EXPECT_FALSE([scene_ containsTouchPoint:CGPointMake(9, midHeight)]); | |
313 EXPECT_TRUE([scene_ containsTouchPoint:CGPointMake(10, midHeight)]); | |
314 // right | |
315 EXPECT_FALSE( | |
316 [scene_ containsTouchPoint:CGPointMake(kClientWidth - 10, midHeight)]); | |
317 EXPECT_TRUE( | |
318 [scene_ containsTouchPoint:CGPointMake(kClientWidth - 11, midHeight)]); | |
319 // top | |
320 EXPECT_FALSE( | |
321 [scene_ containsTouchPoint:CGPointMake(midWidth, kClientHeight - 10)]); | |
322 EXPECT_TRUE( | |
323 [scene_ containsTouchPoint:CGPointMake(midWidth, kClientHeight - 11)]); | |
324 // bottom | |
325 EXPECT_FALSE([scene_ containsTouchPoint:CGPointMake(midWidth, 9)]); | |
326 EXPECT_TRUE([scene_ containsTouchPoint:CGPointMake(midWidth, 10)]); | |
327 } | |
328 | |
329 TEST_F(SceneViewTest, | |
330 UpdateMousePositionAndAnchorsWithTranslationNoMovement) { | |
331 | |
332 webrtc::DesktopVector originalPosition = scene_.mousePosition; | |
333 AnchorPosition originalAnchors = scene_.anchored; | |
334 | |
335 [scene_ updateMousePositionAndAnchorsWithTranslation:CGPointMake(0, 0) | |
336 scale:1]; | |
337 | |
338 webrtc::DesktopVector newPosition = scene_.mousePosition; | |
339 | |
340 EXPECT_EQ(0, abs(originalPosition.x() - newPosition.x())); | |
341 EXPECT_EQ(0, abs(originalPosition.y() - newPosition.y())); | |
342 | |
343 EXPECT_EQ(originalAnchors.right, scene_.anchored.right); | |
344 EXPECT_EQ(originalAnchors.top, scene_.anchored.top); | |
345 EXPECT_EQ(originalAnchors.left, scene_.anchored.left); | |
346 EXPECT_EQ(originalAnchors.bottom, scene_.anchored.bottom); | |
347 | |
348 EXPECT_FALSE(scene_.tickPanVelocity); | |
349 } | |
350 | |
351 TEST_F(SceneViewTest, | |
352 UpdateMousePositionAndAnchorsWithTranslationTowardLeftAndTop) { | |
353 // Translation is in a coordinate space where (0,0) is the bottom left of the | |
354 // view. Mouse position in in a coordinate space where (0,0) is the top left | |
355 // of the view. So |y| is moved in the negative direction. | |
356 | |
357 webrtc::DesktopVector originalPosition = scene_.mousePosition; | |
358 | |
359 [scene_ setPanVelocity:CGPointMake(1, 1)]; | |
360 [scene_ updateMousePositionAndAnchorsWithTranslation:CGPointMake(2, -1) | |
361 scale:1]; | |
362 | |
363 webrtc::DesktopVector newPosition = scene_.mousePosition; | |
364 | |
365 // We could do these checks as a single test, for a positive vs negative | |
366 // difference. But this style has a clearer meaning that the position moved | |
367 // toward or away from the origin. | |
368 EXPECT_LT(newPosition.x(), originalPosition.x()); | |
369 EXPECT_LT(newPosition.y(), originalPosition.y()); | |
370 EXPECT_EQ(2, abs(originalPosition.x() - newPosition.x())); | |
371 EXPECT_EQ(1, abs(originalPosition.y() - newPosition.y())); | |
372 | |
373 EXPECT_TRUE(scene_.anchored.left); | |
374 EXPECT_TRUE(scene_.anchored.top); | |
375 | |
376 EXPECT_FALSE(scene_.anchored.right); | |
377 EXPECT_FALSE(scene_.anchored.bottom); | |
378 | |
379 EXPECT_TRUE(scene_.tickPanVelocity); | |
380 | |
381 // move much further than the bounds allow | |
382 [scene_ setPanVelocity:CGPointMake(1, 1)]; | |
383 [scene_ | |
384 updateMousePositionAndAnchorsWithTranslation:CGPointMake(10000, -10000) | |
385 scale:1]; | |
386 | |
387 newPosition = scene_.mousePosition; | |
388 | |
389 EXPECT_EQ(0, newPosition.x()); | |
390 EXPECT_EQ(0, newPosition.y()); | |
391 | |
392 EXPECT_TRUE(scene_.anchored.left); | |
393 EXPECT_TRUE(scene_.anchored.top); | |
394 | |
395 EXPECT_FALSE(scene_.anchored.right); | |
396 EXPECT_FALSE(scene_.anchored.bottom); | |
397 | |
398 EXPECT_FALSE(scene_.tickPanVelocity); | |
399 } | |
400 | |
401 TEST_F(SceneViewTest, | |
402 UpdateMousePositionAndAnchorsWithTranslationTowardLeftAndBottom) { | |
403 webrtc::DesktopVector originalPosition = scene_.mousePosition; | |
404 | |
405 // see notes for Test | |
406 // UpdateMousePositionAndAnchorsWithTranslationTowardLeftAndTop | |
407 [scene_ setPanVelocity:CGPointMake(1, 1)]; | |
408 [scene_ updateMousePositionAndAnchorsWithTranslation:CGPointMake(2, 1) | |
409 scale:1]; | |
410 webrtc::DesktopVector newPosition = scene_.mousePosition; | |
411 | |
412 EXPECT_LT(newPosition.x(), originalPosition.x()); | |
413 EXPECT_GT(newPosition.y(), originalPosition.y()); | |
414 EXPECT_EQ(2, abs(originalPosition.x() - newPosition.x())); | |
415 EXPECT_EQ(1, abs(originalPosition.y() - newPosition.y())); | |
416 | |
417 EXPECT_TRUE(scene_.anchored.left); | |
418 EXPECT_TRUE(scene_.anchored.bottom); | |
419 | |
420 EXPECT_FALSE(scene_.anchored.right); | |
421 EXPECT_FALSE(scene_.anchored.top); | |
422 | |
423 EXPECT_TRUE(scene_.tickPanVelocity); | |
424 | |
425 [scene_ setPanVelocity:CGPointMake(1, 1)]; | |
426 [scene_ updateMousePositionAndAnchorsWithTranslation:CGPointMake(10000, 10000) | |
427 scale:1]; | |
428 newPosition = scene_.mousePosition; | |
429 | |
430 EXPECT_EQ(0, newPosition.x()); | |
431 EXPECT_EQ(scene_.frameSize.height() - 1, newPosition.y()); | |
432 | |
433 EXPECT_TRUE(scene_.anchored.left); | |
434 EXPECT_TRUE(scene_.anchored.bottom); | |
435 | |
436 EXPECT_FALSE(scene_.anchored.right); | |
437 EXPECT_FALSE(scene_.anchored.top); | |
438 | |
439 EXPECT_FALSE(scene_.tickPanVelocity); | |
440 } | |
441 | |
442 TEST_F(SceneViewTest, | |
443 UpdateMousePositionAndAnchorsWithTranslationTowardRightAndTop) { | |
444 webrtc::DesktopVector originalPosition = scene_.mousePosition; | |
445 | |
446 // see notes for Test | |
447 // UpdateMousePositionAndAnchorsWithTranslationTowardLeftAndTop | |
448 | |
449 // When moving to the right the mouse remains centered since the horizontal | |
450 // display space is larger than the view space | |
451 [scene_ setPanVelocity:CGPointMake(1, 1)]; | |
452 [scene_ updateMousePositionAndAnchorsWithTranslation:CGPointMake(-2, -1) | |
453 scale:1]; | |
454 webrtc::DesktopVector newPosition = scene_.mousePosition; | |
455 | |
456 EXPECT_LT(newPosition.y(), originalPosition.y()); | |
457 EXPECT_EQ(0, abs(originalPosition.x() - newPosition.x())); | |
458 EXPECT_EQ(1, abs(originalPosition.y() - newPosition.y())); | |
459 | |
460 EXPECT_TRUE(scene_.anchored.top); | |
461 | |
462 EXPECT_FALSE(scene_.anchored.left); | |
463 EXPECT_FALSE(scene_.anchored.right); | |
464 EXPECT_FALSE(scene_.anchored.bottom); | |
465 | |
466 EXPECT_TRUE(scene_.tickPanVelocity); | |
467 | |
468 [scene_ setPanVelocity:CGPointMake(1, 1)]; | |
469 [scene_ | |
470 updateMousePositionAndAnchorsWithTranslation:CGPointMake(-10000, -10000) | |
471 scale:1]; | |
472 newPosition = scene_.mousePosition; | |
473 | |
474 EXPECT_EQ(scene_.frameSize.width() - 1, newPosition.x()); | |
475 EXPECT_EQ(0, newPosition.y()); | |
476 | |
477 EXPECT_TRUE(scene_.anchored.right); | |
478 EXPECT_TRUE(scene_.anchored.top); | |
479 | |
480 EXPECT_FALSE(scene_.anchored.left); | |
481 EXPECT_FALSE(scene_.anchored.bottom); | |
482 | |
483 EXPECT_FALSE(scene_.tickPanVelocity); | |
484 } | |
485 | |
486 TEST_F(SceneViewTest, | |
487 UpdateMousePositionAndAnchorsWithTranslationTowardRightAndBottom) { | |
488 webrtc::DesktopVector originalPosition = scene_.mousePosition; | |
489 | |
490 // see notes for Test | |
491 // UpdateMousePositionAndAnchorsWithTranslationTowardLeftAndTop | |
492 | |
493 // When moving to the right the mouse remains centered since the horizontal | |
494 // display space is larger than the view space | |
495 [scene_ setPanVelocity:CGPointMake(1, 1)]; | |
496 [scene_ updateMousePositionAndAnchorsWithTranslation:CGPointMake(-2, 1) | |
497 scale:1]; | |
498 webrtc::DesktopVector newPosition = scene_.mousePosition; | |
499 | |
500 EXPECT_GT(newPosition.y(), originalPosition.y()); | |
501 EXPECT_EQ(0, abs(originalPosition.x() - newPosition.x())); | |
502 EXPECT_EQ(1, abs(originalPosition.y() - newPosition.y())); | |
503 | |
504 EXPECT_TRUE(scene_.anchored.bottom); | |
505 | |
506 EXPECT_FALSE(scene_.anchored.left); | |
507 EXPECT_FALSE(scene_.anchored.right); | |
508 EXPECT_FALSE(scene_.anchored.top); | |
509 | |
510 EXPECT_TRUE(scene_.tickPanVelocity); | |
511 | |
512 [scene_ setPanVelocity:CGPointMake(1, 1)]; | |
513 [scene_ | |
514 updateMousePositionAndAnchorsWithTranslation:CGPointMake(-10000, 10000) | |
515 scale:1]; | |
516 newPosition = scene_.mousePosition; | |
517 | |
518 EXPECT_EQ(scene_.frameSize.width() - 1, newPosition.x()); | |
519 EXPECT_EQ(scene_.frameSize.height() - 1, newPosition.y()); | |
520 | |
521 EXPECT_TRUE(scene_.anchored.right); | |
522 EXPECT_TRUE(scene_.anchored.bottom); | |
523 | |
524 EXPECT_FALSE(scene_.anchored.left); | |
525 EXPECT_FALSE(scene_.anchored.top); | |
526 | |
527 EXPECT_FALSE(scene_.tickPanVelocity); | |
528 } | |
529 | |
530 TEST(SceneViewTest_Static, PositionDeltaFromScaling) { | |
531 | |
532 // Legend: | |
533 // * anchored point or end point | |
534 // | unanchored endpoint | |
535 // - onscreen | |
536 // # offscreen | |
537 | |
538 // *---| | |
539 // *-------| | |
540 EXPECT_EQ( | |
541 0, | |
542 [SceneView positionDeltaFromScaling:2.0F position:0 length:100 anchor:0]); | |
543 // *---| | |
544 // *-| | |
545 EXPECT_EQ( | |
546 0, | |
547 [SceneView positionDeltaFromScaling:0.5F position:0 length:100 anchor:0]); | |
548 // |---* | |
549 // |-------* | |
550 EXPECT_EQ(100, | |
551 [SceneView positionDeltaFromScaling:2.0F | |
552 position:0 | |
553 length:100 | |
554 anchor:100]); | |
555 // |----* | |
556 // |--* | |
557 EXPECT_EQ(-50, | |
558 [SceneView positionDeltaFromScaling:0.5F | |
559 position:0 | |
560 length:100 | |
561 anchor:100]); | |
562 // |*---| | |
563 // |-*-------| | |
564 EXPECT_EQ(25, | |
565 [SceneView positionDeltaFromScaling:2.0F | |
566 position:0 | |
567 length:100 | |
568 anchor:25]); | |
569 // |-*--| | |
570 // |*-| | |
571 EXPECT_EQ(-12.5, | |
572 [SceneView positionDeltaFromScaling:0.5F | |
573 position:0 | |
574 length:100 | |
575 anchor:25]); | |
576 // |---*| | |
577 // |------*-| | |
578 EXPECT_EQ(75, | |
579 [SceneView positionDeltaFromScaling:2.0F | |
580 position:0 | |
581 length:100 | |
582 anchor:75]); | |
583 // |--*-| | |
584 // |-*| | |
585 EXPECT_EQ(-37.5, | |
586 [SceneView positionDeltaFromScaling:0.5F | |
587 position:0 | |
588 length:100 | |
589 anchor:75]); | |
590 // |-*-| | |
591 // |---*---| | |
592 EXPECT_EQ(50, | |
593 [SceneView positionDeltaFromScaling:2.0F | |
594 position:0 | |
595 length:100 | |
596 anchor:50]); | |
597 // |--*--| | |
598 // |*| | |
599 EXPECT_EQ(-25, | |
600 [SceneView positionDeltaFromScaling:0.5F | |
601 position:0 | |
602 length:100 | |
603 anchor:50]); | |
604 ////////////////////////////////// | |
605 // Change position to 50, anchor is relatively the same | |
606 ////////////////////////////////// | |
607 EXPECT_EQ(0, | |
608 [SceneView positionDeltaFromScaling:2.0F | |
609 position:50 | |
610 length:100 | |
611 anchor:50]); | |
612 EXPECT_EQ(0, | |
613 [SceneView positionDeltaFromScaling:0.5F | |
614 position:50 | |
615 length:100 | |
616 anchor:50]); | |
617 EXPECT_EQ(100, | |
618 [SceneView positionDeltaFromScaling:2.0F | |
619 position:50 | |
620 length:100 | |
621 anchor:150]); | |
622 EXPECT_EQ(-50, | |
623 [SceneView positionDeltaFromScaling:0.5F | |
624 position:50 | |
625 length:100 | |
626 anchor:150]); | |
627 EXPECT_EQ(25, | |
628 [SceneView positionDeltaFromScaling:2.0F | |
629 position:50 | |
630 length:100 | |
631 anchor:75]); | |
632 EXPECT_EQ(-12.5, | |
633 [SceneView positionDeltaFromScaling:0.5F | |
634 position:50 | |
635 length:100 | |
636 anchor:75]); | |
637 EXPECT_EQ(75, | |
638 [SceneView positionDeltaFromScaling:2.0F | |
639 position:50 | |
640 length:100 | |
641 anchor:125]); | |
642 EXPECT_EQ(-37.5, | |
643 [SceneView positionDeltaFromScaling:0.5F | |
644 position:50 | |
645 length:100 | |
646 anchor:125]); | |
647 EXPECT_EQ(50, | |
648 [SceneView positionDeltaFromScaling:2.0F | |
649 position:50 | |
650 length:100 | |
651 anchor:100]); | |
652 EXPECT_EQ(-25, | |
653 [SceneView positionDeltaFromScaling:0.5F | |
654 position:50 | |
655 length:100 | |
656 anchor:100]); | |
657 | |
658 ////////////////////////////////// | |
659 // Change position to -50, length to 200, anchor is relatively the same | |
660 ////////////////////////////////// | |
661 EXPECT_EQ(0, | |
662 [SceneView positionDeltaFromScaling:2.0F | |
663 position:-50 | |
664 length:200 | |
665 anchor:-50]); | |
666 EXPECT_EQ(0, | |
667 [SceneView positionDeltaFromScaling:0.5F | |
668 position:-50 | |
669 length:200 | |
670 anchor:-50]); | |
671 EXPECT_EQ(200, | |
672 [SceneView positionDeltaFromScaling:2.0F | |
673 position:-50 | |
674 length:200 | |
675 anchor:150]); | |
676 EXPECT_EQ(-100, | |
677 [SceneView positionDeltaFromScaling:0.5F | |
678 position:-50 | |
679 length:200 | |
680 anchor:150]); | |
681 EXPECT_EQ(50, | |
682 [SceneView positionDeltaFromScaling:2.0F | |
683 position:-50 | |
684 length:200 | |
685 anchor:0]); | |
686 EXPECT_EQ(-25, | |
687 [SceneView positionDeltaFromScaling:0.5F | |
688 position:-50 | |
689 length:200 | |
690 anchor:0]); | |
691 EXPECT_EQ(150, | |
692 [SceneView positionDeltaFromScaling:2.0F | |
693 position:-50 | |
694 length:200 | |
695 anchor:100]); | |
696 EXPECT_EQ(-75, | |
697 [SceneView positionDeltaFromScaling:0.5F | |
698 position:-50 | |
699 length:200 | |
700 anchor:100]); | |
701 EXPECT_EQ(100, | |
702 [SceneView positionDeltaFromScaling:2.0F | |
703 position:-50 | |
704 length:200 | |
705 anchor:50]); | |
706 EXPECT_EQ(-50, | |
707 [SceneView positionDeltaFromScaling:0.5F | |
708 position:-50 | |
709 length:200 | |
710 anchor:50]); | |
711 } | |
712 | |
713 TEST(SceneViewTest_Static, PositionDeltaFromTranslation) { | |
714 // Anchored on both sides. Center it by using 1/2 the free space, offset by | |
715 // the current position | |
716 EXPECT_EQ(50, | |
717 [SceneView positionDeltaFromTranslation:0 | |
718 position:0 | |
719 freeSpace:100 | |
720 scaleingPositionDelta:0 | |
721 isAnchoredLow:YES | |
722 isAnchoredHigh:YES]); | |
723 EXPECT_EQ(50, | |
724 [SceneView positionDeltaFromTranslation:100 | |
725 position:0 | |
726 freeSpace:100 | |
727 scaleingPositionDelta:0 | |
728 isAnchoredLow:YES | |
729 isAnchoredHigh:YES]); | |
730 EXPECT_EQ(-50, | |
731 [SceneView positionDeltaFromTranslation:0 | |
732 position:100 | |
733 freeSpace:100 | |
734 scaleingPositionDelta:0 | |
735 isAnchoredLow:YES | |
736 isAnchoredHigh:YES]); | |
737 EXPECT_EQ(50, | |
738 [SceneView positionDeltaFromTranslation:0 | |
739 position:0 | |
740 freeSpace:100 | |
741 scaleingPositionDelta:100 | |
742 isAnchoredLow:YES | |
743 isAnchoredHigh:YES]); | |
744 EXPECT_EQ(100, | |
745 [SceneView positionDeltaFromTranslation:0 | |
746 position:0 | |
747 freeSpace:200 | |
748 scaleingPositionDelta:0 | |
749 isAnchoredLow:YES | |
750 isAnchoredHigh:YES]); | |
751 | |
752 // Anchored only on the left. Don't move it | |
753 EXPECT_EQ(0, | |
754 [SceneView positionDeltaFromTranslation:0 | |
755 position:0 | |
756 freeSpace:100 | |
757 scaleingPositionDelta:0 | |
758 isAnchoredLow:YES | |
759 isAnchoredHigh:NO]); | |
760 EXPECT_EQ(0, | |
761 [SceneView positionDeltaFromTranslation:100 | |
762 position:0 | |
763 freeSpace:100 | |
764 scaleingPositionDelta:0 | |
765 isAnchoredLow:YES | |
766 isAnchoredHigh:NO]); | |
767 EXPECT_EQ(0, | |
768 [SceneView positionDeltaFromTranslation:0 | |
769 position:100 | |
770 freeSpace:100 | |
771 scaleingPositionDelta:0 | |
772 isAnchoredLow:YES | |
773 isAnchoredHigh:NO]); | |
774 EXPECT_EQ(0, | |
775 [SceneView positionDeltaFromTranslation:0 | |
776 position:0 | |
777 freeSpace:200 | |
778 scaleingPositionDelta:100 | |
779 isAnchoredLow:YES | |
780 isAnchoredHigh:NO]); | |
781 EXPECT_EQ(0, | |
782 [SceneView positionDeltaFromTranslation:0 | |
783 position:0 | |
784 freeSpace:200 | |
785 scaleingPositionDelta:0 | |
786 isAnchoredLow:YES | |
787 isAnchoredHigh:NO]); | |
788 // Anchored only on the right. Move by the scaling delta | |
789 EXPECT_EQ(25, | |
790 [SceneView positionDeltaFromTranslation:0 | |
791 position:0 | |
792 freeSpace:100 | |
793 scaleingPositionDelta:25 | |
794 isAnchoredLow:NO | |
795 isAnchoredHigh:YES]); | |
796 EXPECT_EQ(50, | |
797 [SceneView positionDeltaFromTranslation:100 | |
798 position:0 | |
799 freeSpace:100 | |
800 scaleingPositionDelta:50 | |
801 isAnchoredLow:NO | |
802 isAnchoredHigh:YES]); | |
803 EXPECT_EQ(75, | |
804 [SceneView positionDeltaFromTranslation:0 | |
805 position:100 | |
806 freeSpace:100 | |
807 scaleingPositionDelta:75 | |
808 isAnchoredLow:NO | |
809 isAnchoredHigh:YES]); | |
810 EXPECT_EQ(100, | |
811 [SceneView positionDeltaFromTranslation:0 | |
812 position:0 | |
813 freeSpace:100 | |
814 scaleingPositionDelta:100 | |
815 isAnchoredLow:NO | |
816 isAnchoredHigh:YES]); | |
817 EXPECT_EQ(125, | |
818 [SceneView positionDeltaFromTranslation:0 | |
819 position:0 | |
820 freeSpace:200 | |
821 scaleingPositionDelta:125 | |
822 isAnchoredLow:NO | |
823 isAnchoredHigh:YES]); | |
824 // Not anchored, translate and move by the scaling delta | |
825 EXPECT_EQ(0, | |
826 [SceneView positionDeltaFromTranslation:0 | |
827 position:0 | |
828 freeSpace:100 | |
829 scaleingPositionDelta:0 | |
830 isAnchoredLow:NO | |
831 isAnchoredHigh:NO]); | |
832 EXPECT_EQ(25, | |
833 [SceneView positionDeltaFromTranslation:25 | |
834 position:0 | |
835 freeSpace:100 | |
836 scaleingPositionDelta:0 | |
837 isAnchoredLow:NO | |
838 isAnchoredHigh:NO]); | |
839 EXPECT_EQ(50, | |
840 [SceneView positionDeltaFromTranslation:50 | |
841 position:100 | |
842 freeSpace:100 | |
843 scaleingPositionDelta:0 | |
844 isAnchoredLow:NO | |
845 isAnchoredHigh:NO]); | |
846 EXPECT_EQ(175, | |
847 [SceneView positionDeltaFromTranslation:75 | |
848 position:0 | |
849 freeSpace:100 | |
850 scaleingPositionDelta:100 | |
851 isAnchoredLow:NO | |
852 isAnchoredHigh:NO]); | |
853 EXPECT_EQ(100, | |
854 [SceneView positionDeltaFromTranslation:100 | |
855 position:0 | |
856 freeSpace:200 | |
857 scaleingPositionDelta:0 | |
858 isAnchoredLow:NO | |
859 isAnchoredHigh:NO]); | |
860 } | |
861 | |
862 TEST(SceneViewTest_Static, BoundDeltaFromPosition) { | |
863 // Entire entity fits in our view, lower bound is not less than the | |
864 // upperBound. The delta is bounded to the lowerBound. | |
865 EXPECT_EQ(200, | |
866 [SceneView boundDeltaFromPosition:0 | |
867 delta:0 | |
868 lowerBound:200 | |
869 upperBound:100]); | |
870 EXPECT_EQ(100, | |
871 [SceneView boundDeltaFromPosition:100 | |
872 delta:0 | |
873 lowerBound:200 | |
874 upperBound:100]); | |
875 EXPECT_EQ(200, | |
876 [SceneView boundDeltaFromPosition:0 | |
877 delta:100 | |
878 lowerBound:200 | |
879 upperBound:100]); | |
880 EXPECT_EQ(150, | |
881 [SceneView boundDeltaFromPosition:50 | |
882 delta:100 | |
883 lowerBound:200 | |
884 upperBound:200]); | |
885 // Entity does not fit in our view. The result would be out of bounds on the | |
886 // high bound. The delta is bounded to the upper bound and the delta from the | |
887 // position is returned. | |
888 EXPECT_EQ(100, | |
889 [SceneView boundDeltaFromPosition:0 | |
890 delta:1000 | |
891 lowerBound:0 | |
892 upperBound:100]); | |
893 EXPECT_EQ(99, | |
894 [SceneView boundDeltaFromPosition:1 | |
895 delta:1000 | |
896 lowerBound:0 | |
897 upperBound:100]); | |
898 EXPECT_EQ(-50, | |
899 [SceneView boundDeltaFromPosition:150 | |
900 delta:1000 | |
901 lowerBound:50 | |
902 upperBound:100]); | |
903 EXPECT_EQ(100, | |
904 [SceneView boundDeltaFromPosition:100 | |
905 delta:1000 | |
906 lowerBound:0 | |
907 upperBound:200]); | |
908 // Entity does not fit in our view. The result would be out of bounds on the | |
909 // low bound. The delta is bounded to the lower bound and the delta from the | |
910 // position is returned. | |
911 EXPECT_EQ(0, | |
912 [SceneView boundDeltaFromPosition:0 | |
913 delta:-1000 | |
914 lowerBound:0 | |
915 upperBound:100]); | |
916 EXPECT_EQ(-20, | |
917 [SceneView boundDeltaFromPosition:20 | |
918 delta:-1000 | |
919 lowerBound:0 | |
920 upperBound:100]); | |
921 EXPECT_EQ(21, | |
922 [SceneView boundDeltaFromPosition:29 | |
923 delta:-1000 | |
924 lowerBound:50 | |
925 upperBound:100]); | |
926 EXPECT_EQ(1, | |
927 [SceneView boundDeltaFromPosition:-1 | |
928 delta:-1000 | |
929 lowerBound:0 | |
930 upperBound:200]); | |
931 // Entity does not fit in our view. The result is in bounds. The delta is | |
932 // returned unchanged. | |
933 EXPECT_EQ(50, | |
934 [SceneView boundDeltaFromPosition:0 | |
935 delta:50 | |
936 lowerBound:0 | |
937 upperBound:100]); | |
938 EXPECT_EQ(-10, | |
939 [SceneView boundDeltaFromPosition:20 | |
940 delta:-10 | |
941 lowerBound:0 | |
942 upperBound:100]); | |
943 EXPECT_EQ(31, | |
944 [SceneView boundDeltaFromPosition:29 | |
945 delta:31 | |
946 lowerBound:50 | |
947 upperBound:100]); | |
948 EXPECT_EQ(50, | |
949 [SceneView boundDeltaFromPosition:100 | |
950 delta:50 | |
951 lowerBound:0 | |
952 upperBound:200]); | |
953 } | |
954 | |
955 TEST(SceneViewTest_Static, BoundMouseGivenNextPosition) { | |
956 // Mouse would move off screen in the negative | |
957 EXPECT_EQ(0, | |
958 [SceneView boundMouseGivenNextPosition:-1 | |
959 maxPosition:50 | |
960 centerPosition:2 | |
961 isAnchoredLow:YES | |
962 isAnchoredHigh:YES]); | |
963 EXPECT_EQ(0, | |
964 [SceneView boundMouseGivenNextPosition:-1 | |
965 maxPosition:25 | |
966 centerPosition:99 | |
967 isAnchoredLow:NO | |
968 isAnchoredHigh:NO]); | |
969 EXPECT_EQ(0, | |
970 [SceneView boundMouseGivenNextPosition:-11 | |
971 maxPosition:0 | |
972 centerPosition:-52 | |
973 isAnchoredLow:YES | |
974 isAnchoredHigh:YES]); | |
975 EXPECT_EQ(0, | |
976 [SceneView boundMouseGivenNextPosition:-11 | |
977 maxPosition:-100 | |
978 centerPosition:44 | |
979 isAnchoredLow:NO | |
980 isAnchoredHigh:NO]); | |
981 EXPECT_EQ(0, | |
982 [SceneView boundMouseGivenNextPosition:-1 | |
983 maxPosition:50 | |
984 centerPosition:-20 | |
985 isAnchoredLow:YES | |
986 isAnchoredHigh:YES]); | |
987 | |
988 // Mouse would move off screen in the positive | |
989 EXPECT_EQ(49, | |
990 [SceneView boundMouseGivenNextPosition:50 | |
991 maxPosition:50 | |
992 centerPosition:2 | |
993 isAnchoredLow:YES | |
994 isAnchoredHigh:YES]); | |
995 EXPECT_EQ(24, | |
996 [SceneView boundMouseGivenNextPosition:26 | |
997 maxPosition:25 | |
998 centerPosition:99 | |
999 isAnchoredLow:NO | |
1000 isAnchoredHigh:NO]); | |
1001 EXPECT_EQ(-1, | |
1002 [SceneView boundMouseGivenNextPosition:1 | |
1003 maxPosition:0 | |
1004 centerPosition:-52 | |
1005 isAnchoredLow:YES | |
1006 isAnchoredHigh:YES]); | |
1007 EXPECT_EQ(-101, | |
1008 [SceneView boundMouseGivenNextPosition:0 | |
1009 maxPosition:-100 | |
1010 centerPosition:44 | |
1011 isAnchoredLow:NO | |
1012 isAnchoredHigh:NO]); | |
1013 EXPECT_EQ(49, | |
1014 [SceneView boundMouseGivenNextPosition:60 | |
1015 maxPosition:50 | |
1016 centerPosition:-20 | |
1017 isAnchoredLow:YES | |
1018 isAnchoredHigh:YES]); | |
1019 | |
1020 // Mouse is not out of bounds, and not anchored. The Center is returned. | |
1021 EXPECT_EQ(2, | |
1022 [SceneView boundMouseGivenNextPosition:0 | |
1023 maxPosition:100 | |
1024 centerPosition:2 | |
1025 isAnchoredLow:NO | |
1026 isAnchoredHigh:NO]); | |
1027 EXPECT_EQ(99, | |
1028 [SceneView boundMouseGivenNextPosition:25 | |
1029 maxPosition:100 | |
1030 centerPosition:99 | |
1031 isAnchoredLow:NO | |
1032 isAnchoredHigh:NO]); | |
1033 EXPECT_EQ(-52, | |
1034 [SceneView boundMouseGivenNextPosition:99 | |
1035 maxPosition:100 | |
1036 centerPosition:-52 | |
1037 isAnchoredLow:NO | |
1038 isAnchoredHigh:NO]); | |
1039 EXPECT_EQ(44, | |
1040 [SceneView boundMouseGivenNextPosition:120 | |
1041 maxPosition:200 | |
1042 centerPosition:44 | |
1043 isAnchoredLow:NO | |
1044 isAnchoredHigh:NO]); | |
1045 EXPECT_EQ(-20, | |
1046 [SceneView boundMouseGivenNextPosition:180 | |
1047 maxPosition:200 | |
1048 centerPosition:-20 | |
1049 isAnchoredLow:NO | |
1050 isAnchoredHigh:NO]); | |
1051 | |
1052 // Mouse is not out of bounds, and anchored. The position closest | |
1053 // to the anchor is returned. | |
1054 EXPECT_EQ(0, | |
1055 [SceneView boundMouseGivenNextPosition:0 | |
1056 maxPosition:100 | |
1057 centerPosition:2 | |
1058 isAnchoredLow:YES | |
1059 isAnchoredHigh:NO]); | |
1060 EXPECT_EQ(25, | |
1061 [SceneView boundMouseGivenNextPosition:25 | |
1062 maxPosition:100 | |
1063 centerPosition:99 | |
1064 isAnchoredLow:YES | |
1065 isAnchoredHigh:NO]); | |
1066 EXPECT_EQ(-52, | |
1067 [SceneView boundMouseGivenNextPosition:99 | |
1068 maxPosition:100 | |
1069 centerPosition:-52 | |
1070 isAnchoredLow:YES | |
1071 isAnchoredHigh:NO]); | |
1072 EXPECT_EQ(44, | |
1073 [SceneView boundMouseGivenNextPosition:120 | |
1074 maxPosition:200 | |
1075 centerPosition:44 | |
1076 isAnchoredLow:YES | |
1077 isAnchoredHigh:NO]); | |
1078 EXPECT_EQ(-20, | |
1079 [SceneView boundMouseGivenNextPosition:180 | |
1080 maxPosition:200 | |
1081 centerPosition:-20 | |
1082 isAnchoredLow:YES | |
1083 isAnchoredHigh:NO]); | |
1084 EXPECT_EQ(2, | |
1085 [SceneView boundMouseGivenNextPosition:0 | |
1086 maxPosition:100 | |
1087 centerPosition:2 | |
1088 isAnchoredLow:NO | |
1089 isAnchoredHigh:YES]); | |
1090 EXPECT_EQ(99, | |
1091 [SceneView boundMouseGivenNextPosition:25 | |
1092 maxPosition:100 | |
1093 centerPosition:99 | |
1094 isAnchoredLow:NO | |
1095 isAnchoredHigh:YES]); | |
1096 EXPECT_EQ(99, | |
1097 [SceneView boundMouseGivenNextPosition:99 | |
1098 maxPosition:100 | |
1099 centerPosition:-52 | |
1100 isAnchoredLow:NO | |
1101 isAnchoredHigh:YES]); | |
1102 EXPECT_EQ(120, | |
1103 [SceneView boundMouseGivenNextPosition:120 | |
1104 maxPosition:200 | |
1105 centerPosition:44 | |
1106 isAnchoredLow:NO | |
1107 isAnchoredHigh:YES]); | |
1108 EXPECT_EQ(180, | |
1109 [SceneView boundMouseGivenNextPosition:180 | |
1110 maxPosition:200 | |
1111 centerPosition:-20 | |
1112 isAnchoredLow:NO | |
1113 isAnchoredHigh:YES]); | |
1114 EXPECT_EQ(0, | |
1115 [SceneView boundMouseGivenNextPosition:0 | |
1116 maxPosition:100 | |
1117 centerPosition:2 | |
1118 isAnchoredLow:YES | |
1119 isAnchoredHigh:YES]); | |
1120 EXPECT_EQ(25, | |
1121 [SceneView boundMouseGivenNextPosition:25 | |
1122 maxPosition:100 | |
1123 centerPosition:99 | |
1124 isAnchoredLow:YES | |
1125 isAnchoredHigh:YES]); | |
1126 EXPECT_EQ(99, | |
1127 [SceneView boundMouseGivenNextPosition:99 | |
1128 maxPosition:100 | |
1129 centerPosition:-52 | |
1130 isAnchoredLow:YES | |
1131 isAnchoredHigh:YES]); | |
1132 EXPECT_EQ(120, | |
1133 [SceneView boundMouseGivenNextPosition:120 | |
1134 maxPosition:200 | |
1135 centerPosition:44 | |
1136 isAnchoredLow:YES | |
1137 isAnchoredHigh:YES]); | |
1138 EXPECT_EQ(180, | |
1139 [SceneView boundMouseGivenNextPosition:180 | |
1140 maxPosition:200 | |
1141 centerPosition:-20 | |
1142 isAnchoredLow:YES | |
1143 isAnchoredHigh:YES]); | |
1144 } | |
1145 | |
1146 TEST(SceneViewTest_Static, BoundVelocity) { | |
1147 // Outside bounds of the axis | |
1148 EXPECT_EQ(0, [SceneView boundVelocity:5.0f axisLength:100 mousePosition:0]); | |
1149 EXPECT_EQ(0, [SceneView boundVelocity:5.0f axisLength:100 mousePosition:99]); | |
1150 EXPECT_EQ(0, [SceneView boundVelocity:5.0f axisLength:200 mousePosition:200]); | |
1151 // Not outside bounds of the axis | |
1152 EXPECT_EQ(5.0f, | |
1153 [SceneView boundVelocity:5.0f axisLength:100 mousePosition:1]); | |
1154 EXPECT_EQ(5.0f, | |
1155 [SceneView boundVelocity:5.0f axisLength:100 mousePosition:98]); | |
1156 EXPECT_EQ(5.0f, | |
1157 [SceneView boundVelocity:5.0f axisLength:200 mousePosition:100]); | |
1158 } | |
1159 | |
1160 TEST_F(SceneViewTest, TickPanVelocity) { | |
1161 // We are in the large frame, which can pan left and right but not up and | |
1162 // down. Start by resizing it to allow panning up and down. | |
1163 | |
1164 [scene_ panAndZoom:CGPointMake(0, 0) scaleBy:2.0f]; | |
1165 | |
1166 // Going up and right | |
1167 [scene_ setPanVelocity:CGPointMake(1000, 1000)]; | |
1168 [scene_ tickPanVelocity]; | |
1169 | |
1170 webrtc::DesktopVector pos = scene_.mousePosition; | |
1171 int loopLimit = 0; | |
1172 bool didMove = false; | |
1173 bool inMotion = true; | |
1174 | |
1175 while (inMotion && loopLimit < 100) { | |
1176 inMotion = [scene_ tickPanVelocity]; | |
1177 if (inMotion) { | |
1178 ASSERT_TRUE(pos.x() <= scene_.mousePosition.x()) << " after " << loopLimit | |
1179 << " iterations."; | |
1180 ASSERT_TRUE(pos.y() <= scene_.mousePosition.y()) << " after " << loopLimit | |
1181 << " iterations."; | |
1182 didMove = true; | |
1183 } | |
1184 pos = scene_.mousePosition; | |
1185 loopLimit++; | |
1186 } | |
1187 | |
1188 EXPECT_LT(1, loopLimit); | |
1189 EXPECT_TRUE(!inMotion); | |
1190 EXPECT_TRUE(didMove); | |
1191 | |
1192 // Going down and left | |
1193 [scene_ setPanVelocity:CGPointMake(-1000, -1000)]; | |
1194 [scene_ tickPanVelocity]; | |
1195 | |
1196 pos = scene_.mousePosition; | |
1197 loopLimit = 0; | |
1198 didMove = false; | |
1199 inMotion = true; | |
1200 | |
1201 while (inMotion && loopLimit < 100) { | |
1202 inMotion = [scene_ tickPanVelocity]; | |
1203 if (inMotion) { | |
1204 ASSERT_TRUE(pos.x() >= scene_.mousePosition.x()) << " after " << loopLimit | |
1205 << " iterations."; | |
1206 ASSERT_TRUE(pos.y() >= scene_.mousePosition.y()) << " after " << loopLimit | |
1207 << " iterations."; | |
1208 didMove = true; | |
1209 } | |
1210 pos = scene_.mousePosition; | |
1211 loopLimit++; | |
1212 } | |
1213 | |
1214 EXPECT_LT(1, loopLimit); | |
1215 EXPECT_TRUE(!inMotion); | |
1216 EXPECT_TRUE(didMove); | |
1217 } | |
1218 | |
1219 } // namespace remoting | |
OLD | NEW |