Add ScreenPositionClient::ConvertNativePointToScreen.
[chromium-blink-merge.git] / ash / display / screen_position_controller_unittest.cc
blobfeea1b56714b83e956ccafaefe626d9498ed8bc4
1 // Copyright (c) 2012 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 "ash/display/screen_position_controller.h"
7 #include "ash/display/display_controller.h"
8 #include "ash/shell.h"
9 #include "ash/test/ash_test_base.h"
10 #include "ui/aura/env.h"
11 #include "ui/aura/root_window.h"
12 #include "ui/aura/test/test_window_delegate.h"
13 #include "ui/base/layout.h"
14 #include "ui/gfx/screen.h"
16 namespace ash {
17 namespace test {
19 namespace {
20 void SetSecondaryDisplayLayout(DisplayLayout::Position position) {
21 DisplayController* display_controller =
22 Shell::GetInstance()->display_controller();
23 DisplayLayout layout = display_controller->default_display_layout();
24 layout.position = position;
25 display_controller->SetDefaultDisplayLayout(layout);
28 internal::ScreenPositionController* GetScreenPositionController() {
29 Shell::TestApi test_api(Shell::GetInstance());
30 return test_api.screen_position_controller();
33 class ScreenPositionControllerTest : public test::AshTestBase {
34 public:
35 ScreenPositionControllerTest() : window_(NULL) {}
36 virtual ~ScreenPositionControllerTest() {}
38 virtual void SetUp() OVERRIDE {
39 AshTestBase::SetUp();
40 window_.reset(new aura::Window(&window_delegate_));
41 window_->SetType(aura::client::WINDOW_TYPE_NORMAL);
42 window_->Init(ui::LAYER_NOT_DRAWN);
43 window_->SetParent(NULL);
44 window_->set_id(1);
47 virtual void TearDown() OVERRIDE {
48 window_.reset();
49 AshTestBase::TearDown();
52 // Converts a native point (x, y) to screen and returns its string
53 // representation.
54 std::string ConvertNativePointToScreen(int x, int y) const {
55 gfx::Point point(x, y);
56 GetScreenPositionController()->ConvertNativePointToScreen(
57 window_.get(), &point);
58 return point.ToString();
61 protected:
62 scoped_ptr<aura::Window> window_;
63 aura::test::TestWindowDelegate window_delegate_;
65 private:
66 DISALLOW_COPY_AND_ASSIGN(ScreenPositionControllerTest);
69 } // namespace
71 TEST_F(ScreenPositionControllerTest, ConvertNativePointToScreen) {
72 UpdateDisplay("100+100-200x200,100+500-200x200");
74 Shell::RootWindowList root_windows =
75 Shell::GetInstance()->GetAllRootWindows();
76 EXPECT_EQ("100,100", root_windows[0]->GetHostOrigin().ToString());
77 EXPECT_EQ("200x200", root_windows[0]->GetHostSize().ToString());
78 EXPECT_EQ("100,500", root_windows[1]->GetHostOrigin().ToString());
79 EXPECT_EQ("200x200", root_windows[1]->GetHostSize().ToString());
81 const gfx::Point window_pos(100, 100);
82 window_->SetBoundsInScreen(gfx::Rect(window_pos, gfx::Size(100, 100)),
83 gfx::Screen::GetDisplayNearestPoint(window_pos));
84 SetSecondaryDisplayLayout(DisplayLayout::RIGHT);
85 // The point is on the primary root window.
86 EXPECT_EQ("150,150", ConvertNativePointToScreen(50, 50));
87 // The point is out of the all root windows.
88 EXPECT_EQ("350,350", ConvertNativePointToScreen(250, 250));
89 // The point is on the secondary display.
90 EXPECT_EQ("350,100", ConvertNativePointToScreen(50, 400));
92 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
93 // The point is on the primary root window.
94 EXPECT_EQ("150,150", ConvertNativePointToScreen(50, 50));
95 // The point is out of the all root windows.
96 EXPECT_EQ("350,350", ConvertNativePointToScreen(250, 250));
97 // The point is on the secondary display.
98 EXPECT_EQ("150,300", ConvertNativePointToScreen(50, 400));
100 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
101 // The point is on the primary root window.
102 EXPECT_EQ("150,150", ConvertNativePointToScreen(50, 50));
103 // The point is out of the all root windows.
104 EXPECT_EQ("350,350", ConvertNativePointToScreen(250, 250));
105 // The point is on the secondary display.
106 EXPECT_EQ("-50,100", ConvertNativePointToScreen(50, 400));
108 SetSecondaryDisplayLayout(DisplayLayout::TOP);
109 // The point is on the primary root window.
110 EXPECT_EQ("150,150", ConvertNativePointToScreen(50, 50));
111 // The point is out of the all root windows.
112 EXPECT_EQ("350,350", ConvertNativePointToScreen(250, 250));
113 // The point is on the secondary display.
114 EXPECT_EQ("150,-100", ConvertNativePointToScreen(50, 400));
117 SetSecondaryDisplayLayout(DisplayLayout::RIGHT);
118 const gfx::Point window_pos2(300, 100);
119 window_->SetBoundsInScreen(gfx::Rect(window_pos2, gfx::Size(100, 100)),
120 gfx::Screen::GetDisplayNearestPoint(window_pos2));
121 // The point is on the secondary display.
122 EXPECT_EQ("350,150", ConvertNativePointToScreen(50, 50));
123 // The point is out of the all root windows.
124 EXPECT_EQ("550,350", ConvertNativePointToScreen(250, 250));
125 // The point is on the primary root window.
126 EXPECT_EQ("150,100", ConvertNativePointToScreen(50, -400));
128 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
129 // The point is on the secondary display.
130 EXPECT_EQ("150,350", ConvertNativePointToScreen(50, 50));
131 // The point is out of the all root windows.
132 EXPECT_EQ("350,550", ConvertNativePointToScreen(250, 250));
133 // The point is on the primary root window.
134 EXPECT_EQ("150,100", ConvertNativePointToScreen(50, -400));
136 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
137 // The point is on the secondary display.
138 EXPECT_EQ("-50,150", ConvertNativePointToScreen(50, 50));
139 // The point is out of the all root windows.
140 EXPECT_EQ("150,350", ConvertNativePointToScreen(250, 250));
141 // The point is on the primary root window.
142 EXPECT_EQ("150,100", ConvertNativePointToScreen(50, -400));
144 SetSecondaryDisplayLayout(DisplayLayout::TOP);
145 // The point is on the secondary display.
146 EXPECT_EQ("150,-50", ConvertNativePointToScreen(50, 50));
147 // The point is out of the all root windows.
148 EXPECT_EQ("350,150", ConvertNativePointToScreen(250, 250));
149 // The point is on the primary root window.
150 EXPECT_EQ("150,100", ConvertNativePointToScreen(50, -400));
153 } // namespace test
154 } // namespace ash