| 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 // +-- V3 | |
| 21 TEST_F(ViewTargetTest, GetRoot) { | |
| 22 TestView v1(1, gfx::Rect(20, 20, 400, 400)); | |
| 23 TestView v2(2, gfx::Rect(10, 10, 350, 350)); | |
| 24 TestView v3(3, gfx::Rect(10, 10, 100, 100)); | |
| 25 v1.AddChild(&v2); | |
| 26 v2.AddChild(&v3); | |
| 27 | |
| 28 EXPECT_EQ(ViewTarget::TargetFromView(&v1), | |
| 29 ViewTarget::TargetFromView(&v1)->GetRoot()); | |
| 30 EXPECT_EQ(ViewTarget::TargetFromView(&v1), | |
| 31 ViewTarget::TargetFromView(&v2)->GetRoot()); | |
| 32 EXPECT_EQ(ViewTarget::TargetFromView(&v1), | |
| 33 ViewTarget::TargetFromView(&v3)->GetRoot()); | |
| 34 } | |
| 35 | |
| 36 // V1 | |
| 37 // +-- V2 | |
| 38 TEST_F(ViewTargetTest, ConvertPointToTarget_Simple) { | |
| 39 TestView v1(1, gfx::Rect(20, 20, 400, 400)); | |
| 40 TestView v2(2, gfx::Rect(10, 10, 350, 350)); | |
| 41 v1.AddChild(&v2); | |
| 42 | |
| 43 ViewTarget* t1 = v1.target(); | |
| 44 ViewTarget* t2 = v2.target(); | |
| 45 | |
| 46 gfx::Point point1_in_t2_coords(5, 5); | |
| 47 ViewTarget::ConvertPointToTarget(t2, t1, &point1_in_t2_coords); | |
| 48 gfx::Point point1_in_t1_coords(15, 15); | |
| 49 EXPECT_EQ(point1_in_t1_coords, point1_in_t2_coords); | |
| 50 | |
| 51 gfx::Point point2_in_t1_coords(5, 5); | |
| 52 ViewTarget::ConvertPointToTarget(t1, t2, &point2_in_t1_coords); | |
| 53 gfx::Point point2_in_t2_coords(-5, -5); | |
| 54 EXPECT_EQ(point2_in_t2_coords, point2_in_t1_coords); | |
| 55 } | |
| 56 | |
| 57 // V1 | |
| 58 // +-- V2 | |
| 59 // +-- V3 | |
| 60 TEST_F(ViewTargetTest, ConvertPointToTarget_Medium) { | |
| 61 TestView v1(1, gfx::Rect(20, 20, 400, 400)); | |
| 62 TestView v2(2, gfx::Rect(10, 10, 350, 350)); | |
| 63 TestView v3(3, gfx::Rect(10, 10, 100, 100)); | |
| 64 v1.AddChild(&v2); | |
| 65 v2.AddChild(&v3); | |
| 66 | |
| 67 ViewTarget* t1 = v1.target(); | |
| 68 ViewTarget* t3 = v3.target(); | |
| 69 | |
| 70 gfx::Point point1_in_t3_coords(5, 5); | |
| 71 ViewTarget::ConvertPointToTarget(t3, t1, &point1_in_t3_coords); | |
| 72 gfx::Point point1_in_t1_coords(25, 25); | |
| 73 EXPECT_EQ(point1_in_t1_coords, point1_in_t3_coords); | |
| 74 | |
| 75 gfx::Point point2_in_t1_coords(5, 5); | |
| 76 ViewTarget::ConvertPointToTarget(t1, t3, &point2_in_t1_coords); | |
| 77 gfx::Point point2_in_t3_coords(-15, -15); | |
| 78 EXPECT_EQ(point2_in_t3_coords, point2_in_t1_coords); | |
| 79 } | |
| 80 | |
| 81 } // namespace mojo | |
| OLD | NEW |