[Sync] Add auto-generated ModelType in Java.
[chromium-blink-merge.git] / components / view_manager / view_coordinate_conversions_unittest.cc
blobaddd466bee06c83fdb7c073e12c460be6f392753
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.
5 #include "components/view_manager/view_coordinate_conversions.h"
7 #include "components/view_manager/server_view.h"
8 #include "components/view_manager/server_view_delegate.h"
9 #include "components/view_manager/test_server_view_delegate.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/gfx/geometry/point_f.h"
12 #include "ui/gfx/geometry/rect.h"
14 namespace view_manager {
16 using ViewCoordinateConversionsTest = testing::Test;
18 TEST_F(ViewCoordinateConversionsTest, ConvertRectBetweenViews) {
19 TestServerViewDelegate d1, d2, d3;
20 ServerView v1(&d1, ViewId()), v2(&d2, ViewId()), v3(&d3, ViewId());
21 v1.SetBounds(gfx::Rect(1, 2, 100, 100));
22 v2.SetBounds(gfx::Rect(3, 4, 100, 100));
23 v3.SetBounds(gfx::Rect(5, 6, 100, 100));
24 v1.Add(&v2);
25 v2.Add(&v3);
27 EXPECT_EQ(gfx::Rect(2, 1, 8, 9),
28 ConvertRectBetweenViews(&v1, &v3, gfx::Rect(10, 11, 8, 9)));
30 EXPECT_EQ(gfx::Rect(18, 21, 8, 9),
31 ConvertRectBetweenViews(&v3, &v1, gfx::Rect(10, 11, 8, 9)));
34 TEST_F(ViewCoordinateConversionsTest, ConvertPointFBetweenViews) {
35 TestServerViewDelegate d1, d2, d3;
36 ServerView v1(&d1, ViewId()), v2(&d2, ViewId()), v3(&d3, ViewId());
37 v1.SetBounds(gfx::Rect(1, 2, 100, 100));
38 v2.SetBounds(gfx::Rect(3, 4, 100, 100));
39 v3.SetBounds(gfx::Rect(5, 6, 100, 100));
40 v1.Add(&v2);
41 v2.Add(&v3);
44 const gfx::PointF result(
45 ConvertPointFBetweenViews(&v1, &v3, gfx::PointF(10.5f, 11.9f)));
46 EXPECT_FLOAT_EQ(2.5f, result.x());
47 EXPECT_FLOAT_EQ(1.9f, result.y());
51 const gfx::PointF result(
52 ConvertPointFBetweenViews(&v3, &v1, gfx::PointF(10.2f, 11.4f)));
53 EXPECT_FLOAT_EQ(18.2f, result.x());
54 EXPECT_FLOAT_EQ(21.4f, result.y());
58 } // namespace view_manager