1 // Copyright 2020 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 "ui/aura/client/screen_position_client.h"
6 
7 #include <memory>
8 
9 #include "ui/aura/test/aura_test_base.h"
10 
11 namespace aura {
12 namespace client {
13 
14 using ScreenPositionClientTest = test::AuraTestBase;
15 
16 class TestScreenPositionClient : public ScreenPositionClient {
17  public:
18   TestScreenPositionClient() = default;
19   TestScreenPositionClient(const TestScreenPositionClient&) = delete;
20   TestScreenPositionClient& operator=(const TestScreenPositionClient&) = delete;
21   ~TestScreenPositionClient() override = default;
22 
23   // ScreenPositionClient:
ConvertPointToScreen(const Window * window,gfx::PointF * point)24   void ConvertPointToScreen(const Window* window, gfx::PointF* point) override {
25   }
ConvertPointFromScreen(const Window * window,gfx::PointF * point)26   void ConvertPointFromScreen(const Window* window,
27                               gfx::PointF* point) override {}
ConvertHostPointToScreen(Window * root_window,gfx::Point * point)28   void ConvertHostPointToScreen(Window* root_window,
29                                 gfx::Point* point) override {}
SetBounds(Window * window,const gfx::Rect & bounds,const display::Display & display)30   void SetBounds(Window* window,
31                  const gfx::Rect& bounds,
32                  const display::Display& display) override {}
33 
34  protected:
35   // ScreenPositionClient:
GetRootWindowOriginInScreen(const aura::Window * root_window)36   gfx::Point GetRootWindowOriginInScreen(
37       const aura::Window* root_window) override {
38     return gfx::Point();
39   }
40 };
41 
TEST_F(ScreenPositionClientTest,ConvertPointToRootWindowIgnoringTransforms)42 TEST_F(ScreenPositionClientTest, ConvertPointToRootWindowIgnoringTransforms) {
43   std::unique_ptr<Window> parent(CreateNormalWindow(1, root_window(), nullptr));
44   std::unique_ptr<Window> child(CreateNormalWindow(2, parent.get(), nullptr));
45 
46   parent->SetBounds(gfx::Rect(50, 50, 200, 200));
47   child->SetBounds(gfx::Rect(150, 150, 200, 200));
48 
49   TestScreenPositionClient test_client;
50   gfx::Point point(100, 100);
51   test_client.ConvertPointToRootWindowIgnoringTransforms(parent.get(), &point);
52   EXPECT_EQ(gfx::Point(150, 150), point);
53 
54   point = gfx::Point(100, 100);
55   test_client.ConvertPointToRootWindowIgnoringTransforms(child.get(), &point);
56   EXPECT_EQ(gfx::Point(300, 300), point);
57 
58   point = gfx::Point(100, 100);
59   child->SetTransform(gfx::Transform(1, 0, 0, 1, 100, 100));
60   test_client.ConvertPointToRootWindowIgnoringTransforms(child.get(), &point);
61   EXPECT_EQ(gfx::Point(300, 300), point);
62 }
63 
64 }  // namespace client
65 }  // namespace aura
66