Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(896)

Side by Side Diff: ash/display/screen_position_controller_unittest.cc

Issue 10911342: Add ScreenPositionClient::ConvertNativePointToScreen. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "ash/display/screen_position_controller.h"
6
7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h"
9 #include "ui/aura/test/test_window_delegate.h"
10 #include "ui/aura/env.h"
11 #include "ui/aura/root_window.h"
12 #include "ui/base/layout.h"
13 #include "ash/display/display_controller.h"
oshima 2012/09/18 10:02:34 sort includes
mazda 2012/09/18 16:35:01 Done.
14
15 namespace ash {
16 namespace test {
17
18 namespace {
19 void SetSecondaryDisplayLayout(DisplayLayout::Position position) {
20 DisplayController* display_controller =
21 Shell::GetInstance()->display_controller();
22 DisplayLayout layout = display_controller->default_display_layout();
23 layout.position = position;
24 display_controller->SetDefaultDisplayLayout(layout);
25 }
26
27 const gfx::Display& GetDisplayAt(const gfx::Point& point) {
28 return aura::Env::GetInstance()->display_manager()->GetDisplayNearestPoint(
29 point);
oshima 2012/09/18 10:02:34 use gfx::Screen::GetDisplayNearestPoint()
mazda 2012/09/18 16:35:01 Done.
30 }
31
32 internal::ScreenPositionController* GetScreenPositionController() {
33 Shell::TestApi test_api(Shell::GetInstance());
34 return test_api.screen_position_controller();
35 }
36
37 class ScreenPositionControllerTest : public test::AshTestBase {
38 public:
39 ScreenPositionControllerTest() : window_(NULL) {}
40 virtual ~ScreenPositionControllerTest() {}
41
42 virtual void SetUp() OVERRIDE {
43 AshTestBase::SetUp();
44 window_.reset(new aura::Window(&window_delegate_));
45 window_->SetType(aura::client::WINDOW_TYPE_NORMAL);
46 window_->Init(ui::LAYER_NOT_DRAWN);
47 window_->SetParent(NULL);
48 window_->set_id(1);
49 }
50
51 virtual void TearDown() OVERRIDE {
52 window_.reset();
53 AshTestBase::TearDown();
54 }
55
56 protected:
57 scoped_ptr<aura::Window> window_;
58 aura::test::TestWindowDelegate window_delegate_;
59
60 private:
61 DISALLOW_COPY_AND_ASSIGN(ScreenPositionControllerTest);
62 };
63
64 } // namespace
65
66 TEST_F(ScreenPositionControllerTest, ConvertNativePointToScreen) {
67 UpdateDisplay("100+100-200x200,100+500-200x200");
68
69 Shell::RootWindowList root_windows =
70 Shell::GetInstance()->GetAllRootWindows();
71 EXPECT_EQ("100,100", root_windows[0]->GetHostOrigin().ToString());
72 EXPECT_EQ("200x200", root_windows[0]->GetHostSize().ToString());
73 EXPECT_EQ("100,500", root_windows[1]->GetHostOrigin().ToString());
74 EXPECT_EQ("200x200", root_windows[1]->GetHostSize().ToString());
75
76 internal::ScreenPositionController* controller =
77 GetScreenPositionController();
78
79 const gfx::Point window_pos(100, 100);
80 window_->SetBoundsInScreen(gfx::Rect(window_pos, gfx::Size(100, 100)),
81 GetDisplayAt(window_pos));
82 SetSecondaryDisplayLayout(DisplayLayout::RIGHT);
83 {
84 // |point| is on the primary root window.
85 gfx::Point point(50, 50);
86 controller->ConvertNativePointToScreen(window_.get(), &point);
87 EXPECT_EQ("150,150", point.ToString());
oshima 2012/09/18 10:02:34 since you have window_ as instance and controller
mazda 2012/09/18 16:35:01 Done. That's much simpler. Thanks.
88 }
89
90 {
91 // |point| is out of the all root windows.
92 gfx::Point point(250, 250);
93 controller->ConvertNativePointToScreen(window_.get(), &point);
94 EXPECT_EQ("350,350", point.ToString());
95 }
96
97 {
98 // |point| is on the secondary display.
99 gfx::Point point(50, 400);
100 controller->ConvertNativePointToScreen(window_.get(), &point);
101 EXPECT_EQ("350,100", point.ToString());
102 }
103
104 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
105 {
106 // |point| is on the primary root window.
107 gfx::Point point(50, 50);
108 controller->ConvertNativePointToScreen(window_.get(), &point);
109 EXPECT_EQ("150,150", point.ToString());
110 }
111
112 {
113 // |point| is out of the all root windows.
114 gfx::Point point(250, 250);
115 controller->ConvertNativePointToScreen(window_.get(), &point);
116 EXPECT_EQ("350,350", point.ToString());
117 }
118
119 {
120 // |point| is on the secondary display.
121 gfx::Point point(50, 400);
122 controller->ConvertNativePointToScreen(window_.get(), &point);
123 EXPECT_EQ("150,300", point.ToString());
124 }
125
126 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
127 {
128 // |point| is on the primary root window.
129 gfx::Point point(50, 50);
130 controller->ConvertNativePointToScreen(window_.get(), &point);
131 EXPECT_EQ("150,150", point.ToString());
132 }
133
134 {
135 // |point| is out of the all root windows.
136 gfx::Point point(250, 250);
137 controller->ConvertNativePointToScreen(window_.get(), &point);
138 EXPECT_EQ("350,350", point.ToString());
139 }
140
141 {
142 // |point| is on the secondary display.
143 gfx::Point point(50, 400);
144 controller->ConvertNativePointToScreen(window_.get(), &point);
145 EXPECT_EQ("-50,100", point.ToString());
146 }
147
148 SetSecondaryDisplayLayout(DisplayLayout::TOP);
149 {
150 // |point| is on the primary root window.
151 gfx::Point point(50, 50);
152 controller->ConvertNativePointToScreen(window_.get(), &point);
153 EXPECT_EQ("150,150", point.ToString());
154 }
155
156 {
157 // |point| is out of the all root windows.
158 gfx::Point point(250, 250);
159 controller->ConvertNativePointToScreen(window_.get(), &point);
160 EXPECT_EQ("350,350", point.ToString());
161 }
162
163 {
164 // |point| is on the secondary display.
165 gfx::Point point(50, 400);
166 controller->ConvertNativePointToScreen(window_.get(), &point);
167 EXPECT_EQ("150,-100", point.ToString());
168 }
169
170
171 SetSecondaryDisplayLayout(DisplayLayout::RIGHT);
172 const gfx::Point window_pos2(300, 100);
173 window_->SetBoundsInScreen(gfx::Rect(window_pos2, gfx::Size(100, 100)),
174 GetDisplayAt(window_pos2));
175 {
176 // |point| is on the secondary display.
177 gfx::Point point(50, 50);
178 controller->ConvertNativePointToScreen(window_.get(), &point);
179 EXPECT_EQ("350,150", point.ToString());
180 }
181
182 {
183 // |point| is out of the all root windows.
184 gfx::Point point(250, 250);
185 controller->ConvertNativePointToScreen(window_.get(), &point);
186 EXPECT_EQ("550,350", point.ToString());
187 }
188
189 {
190 // |point| is on the primary root window.
191 gfx::Point point(50, -400);
192 controller->ConvertNativePointToScreen(window_.get(), &point);
193 EXPECT_EQ("150,100", point.ToString());
194 }
195
196 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
197 {
198 // |point| is on the secondary display.
199 gfx::Point point(50, 50);
200 controller->ConvertNativePointToScreen(window_.get(), &point);
201 EXPECT_EQ("150,350", point.ToString());
202 }
203
204 {
205 // |point| is out of the all root windows.
206 gfx::Point point(250, 250);
207 controller->ConvertNativePointToScreen(window_.get(), &point);
208 EXPECT_EQ("350,550", point.ToString());
209 }
210
211 {
212 // |point| is on the primary root window.
213 gfx::Point point(50, -400);
214 controller->ConvertNativePointToScreen(window_.get(), &point);
215 EXPECT_EQ("150,100", point.ToString());
216 }
217
218 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
219 {
220 // |point| is on the secondary display.
221 gfx::Point point(50, 50);
222 controller->ConvertNativePointToScreen(window_.get(), &point);
223 EXPECT_EQ("-50,150", point.ToString());
224 }
225
226 {
227 // |point| is out of the all root windows.
228 gfx::Point point(250, 250);
229 controller->ConvertNativePointToScreen(window_.get(), &point);
230 EXPECT_EQ("150,350", point.ToString());
231 }
232
233 {
234 // |point| is on the primary root window.
235 gfx::Point point(50, -400);
236 controller->ConvertNativePointToScreen(window_.get(), &point);
237 EXPECT_EQ("150,100", point.ToString());
238 }
239
240 SetSecondaryDisplayLayout(DisplayLayout::TOP);
241 {
242 // |point| is on the secondary display.
243 gfx::Point point(50, 50);
244 controller->ConvertNativePointToScreen(window_.get(), &point);
245 EXPECT_EQ("150,-50", point.ToString());
246 }
247
248 {
249 // |point| is out of the all root windows.
250 gfx::Point point(250, 250);
251 controller->ConvertNativePointToScreen(window_.get(), &point);
252 EXPECT_EQ("350,150", point.ToString());
253 }
254
255 {
256 // |point| is on the primary root window.
257 gfx::Point point(50, -400);
258 controller->ConvertNativePointToScreen(window_.get(), &point);
259 EXPECT_EQ("150,100", point.ToString());
260 }
261 }
262
263 } // namespace test
264 } // namespace ash
oshima 2012/09/18 10:02:34 two spaces before //
mazda 2012/09/18 16:35:01 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698