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 #include "mojo/services/window_manager/view_target.h" |
| 6 |
| 7 #include <set> |
| 8 |
| 9 #include "mojo/services/public/cpp/view_manager/view.h" |
| 10 #include "mojo/services/window_manager/window_manager_test_util.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/gfx/geometry/rect.h" |
| 13 |
| 14 namespace mojo { |
| 15 |
| 16 using ViewTargetTest = testing::Test; |
| 17 |
| 18 // V1 |
| 19 // +-- V2 |
| 20 TEST_F(ViewTargetTest, ConvertPointToTarget_Simple) { |
| 21 TestView v1(1, gfx::Rect(20, 20, 400, 400)); |
| 22 TestView v2(2, gfx::Rect(10, 10, 350, 350)); |
| 23 v1.AddChild(&v2); |
| 24 |
| 25 ViewTarget* t1 = v1.target(); |
| 26 ViewTarget* t2 = v2.target(); |
| 27 |
| 28 gfx::Point point1_in_t2_coords(5, 5); |
| 29 ViewTarget::ConvertPointToTarget(t2, t1, &point1_in_t2_coords); |
| 30 gfx::Point point1_in_t1_coords(15, 15); |
| 31 EXPECT_EQ(point1_in_t1_coords, point1_in_t2_coords); |
| 32 |
| 33 gfx::Point point2_in_t1_coords(5, 5); |
| 34 ViewTarget::ConvertPointToTarget(t1, t2, &point2_in_t1_coords); |
| 35 gfx::Point point2_in_t2_coords(-5, -5); |
| 36 EXPECT_EQ(point2_in_t2_coords, point2_in_t1_coords); |
| 37 } |
| 38 |
| 39 // V1 |
| 40 // +-- V2 |
| 41 // +-- V3 |
| 42 TEST_F(ViewTargetTest, ConvertPointToTarget_Medium) { |
| 43 TestView v1(1, gfx::Rect(20, 20, 400, 400)); |
| 44 TestView v2(2, gfx::Rect(10, 10, 350, 350)); |
| 45 TestView v3(3, gfx::Rect(10, 10, 100, 100)); |
| 46 v1.AddChild(&v2); |
| 47 v2.AddChild(&v3); |
| 48 |
| 49 ViewTarget* t1 = v1.target(); |
| 50 ViewTarget* t3 = v3.target(); |
| 51 |
| 52 gfx::Point point1_in_t3_coords(5, 5); |
| 53 ViewTarget::ConvertPointToTarget(t3, t1, &point1_in_t3_coords); |
| 54 gfx::Point point1_in_t1_coords(25, 25); |
| 55 EXPECT_EQ(point1_in_t1_coords, point1_in_t3_coords); |
| 56 |
| 57 gfx::Point point2_in_t1_coords(5, 5); |
| 58 ViewTarget::ConvertPointToTarget(t1, t3, &point2_in_t1_coords); |
| 59 gfx::Point point2_in_t3_coords(-15, -15); |
| 60 EXPECT_EQ(point2_in_t3_coords, point2_in_t1_coords); |
| 61 } |
| 62 |
| 63 } // namespace mojo |
OLD | NEW |