OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/client/desktop_viewport.h" | 5 #include "remoting/client/desktop_viewport.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 public: | 21 public: |
22 void SetUp() override; | 22 void SetUp() override; |
23 void TearDown() override; | 23 void TearDown() override; |
24 | 24 |
25 protected: | 25 protected: |
26 void AssertTransformationReceived(const tracked_objects::Location& from_here, | 26 void AssertTransformationReceived(const tracked_objects::Location& from_here, |
27 float scale, | 27 float scale, |
28 float offset_x, | 28 float offset_x, |
29 float offset_y); | 29 float offset_y); |
30 | 30 |
| 31 ViewMatrix ReleaseReceivedTransformation(); |
| 32 |
31 DesktopViewport viewport_; | 33 DesktopViewport viewport_; |
32 | 34 |
33 private: | 35 private: |
34 void OnTransformationChanged(const ViewMatrix& matrix); | 36 void OnTransformationChanged(const ViewMatrix& matrix); |
35 | 37 |
36 ViewMatrix received_transformation_; | 38 ViewMatrix received_transformation_; |
37 }; | 39 }; |
38 | 40 |
39 void DesktopViewportTest::SetUp() { | 41 void DesktopViewportTest::SetUp() { |
40 viewport_.RegisterOnTransformationChangedCallback( | 42 viewport_.RegisterOnTransformationChangedCallback( |
(...skipping 26 matching lines...) Expand all Loading... |
67 expected_array[0], expected_array[2], | 69 expected_array[0], expected_array[2], |
68 expected_array[5]) | 70 expected_array[5]) |
69 << base::StringPrintf("Actual scale: %f, offset: (%f, %f)\n", | 71 << base::StringPrintf("Actual scale: %f, offset: (%f, %f)\n", |
70 actual_array[0], actual_array[2], actual_array[5]) | 72 actual_array[0], actual_array[2], actual_array[5]) |
71 << "Location: " << from_here.ToString(); | 73 << "Location: " << from_here.ToString(); |
72 } | 74 } |
73 | 75 |
74 received_transformation_ = ViewMatrix(); | 76 received_transformation_ = ViewMatrix(); |
75 } | 77 } |
76 | 78 |
| 79 ViewMatrix DesktopViewportTest::ReleaseReceivedTransformation() { |
| 80 EXPECT_FALSE(received_transformation_.IsEmpty()); |
| 81 ViewMatrix out = received_transformation_; |
| 82 received_transformation_ = ViewMatrix(); |
| 83 return out; |
| 84 } |
| 85 |
77 void DesktopViewportTest::OnTransformationChanged(const ViewMatrix& matrix) { | 86 void DesktopViewportTest::OnTransformationChanged(const ViewMatrix& matrix) { |
78 ASSERT_TRUE(received_transformation_.IsEmpty()) | 87 ASSERT_TRUE(received_transformation_.IsEmpty()) |
79 << "Previous matrix has not been asserted."; | 88 << "Previous matrix has not been asserted."; |
80 received_transformation_ = matrix; | 89 received_transformation_ = matrix; |
81 } | 90 } |
82 | 91 |
83 TEST_F(DesktopViewportTest, TestViewportInitialization1) { | 92 TEST_F(DesktopViewportTest, TestViewportInitialization1) { |
84 // VP < DP. Desktop shrinks to fit. | 93 // VP < DP. Desktop shrinks to fit. |
85 // +====+------+ | 94 // +====+------+ |
86 // | VP | DP | | 95 // | VP | DP | |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 // | | | 253 // | | |
245 // | DP | | 254 // | DP | |
246 // | +====+ | 255 // | +====+ |
247 // | | VP | | 256 // | | VP | |
248 // +---------------| | | 257 // +---------------| | |
249 // +====+ | 258 // +====+ |
250 viewport_.SetViewportCenter(1000.f, 1000.f); | 259 viewport_.SetViewportCenter(1000.f, 1000.f); |
251 AssertTransformationReceived(FROM_HERE, 1.25f, -8.f, -4.5f); | 260 AssertTransformationReceived(FROM_HERE, 1.25f, -8.f, -4.5f); |
252 } | 261 } |
253 | 262 |
| 263 TEST_F(DesktopViewportTest, TestScaleDesktop) { |
| 264 // Number in surface coordinate. |
| 265 // |
| 266 // +====+------+ |
| 267 // | VP | DP | |
| 268 // | | | 3 |
| 269 // +====+------+ |
| 270 // 4 |
| 271 viewport_.SetDesktopSize(8, 6); |
| 272 viewport_.SetSurfaceSize(2, 3); |
| 273 AssertTransformationReceived(FROM_HERE, 0.5f, 0.f, 0.f); |
| 274 |
| 275 ViewMatrix old_transformation(0.5f, {0.f, 0.f}); |
| 276 |
| 277 ViewMatrix::Point surface_point = old_transformation.MapPoint({1.2f, 1.3f}); |
| 278 |
| 279 // Scale a little bit at a pivot point. |
| 280 viewport_.ScaleDesktop(surface_point.x, surface_point.y, 1.1f); |
| 281 |
| 282 ViewMatrix new_transformation = ReleaseReceivedTransformation(); |
| 283 |
| 284 // Verify the pivot point is fixed. |
| 285 ViewMatrix::Point new_surface_point = |
| 286 new_transformation.MapPoint({1.2f, 1.3f}); |
| 287 ASSERT_FLOAT_EQ(surface_point.x, new_surface_point.x); |
| 288 ASSERT_FLOAT_EQ(surface_point.y, new_surface_point.y); |
| 289 |
| 290 // Verify the scale is correct. |
| 291 ASSERT_FLOAT_EQ(old_transformation.GetScale() * 1.1f, |
| 292 new_transformation.GetScale()); |
| 293 } |
| 294 |
254 } // namespace remoting | 295 } // namespace remoting |
OLD | NEW |