Don't consider a Bluetooth adapter present until it has an address.
[chromium-blink-merge.git] / ash / extended_desktop_unittest.cc
blobb1e9583cae9990fa34c3514704e5fc67d86b2e06
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/display_controller.h"
6 #include "ash/display/multi_display_manager.h"
7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h"
9 #include "ash/wm/coordinate_conversion.h"
10 #include "ash/wm/property_util.h"
11 #include "ash/wm/window_cycle_controller.h"
12 #include "ash/wm/window_util.h"
13 #include "ui/aura/client/activation_client.h"
14 #include "ui/aura/client/capture_client.h"
15 #include "ui/aura/env.h"
16 #include "ui/aura/focus_manager.h"
17 #include "ui/aura/root_window.h"
18 #include "ui/aura/test/event_generator.h"
19 #include "ui/aura/test/test_windows.h"
20 #include "ui/aura/window.h"
21 #include "ui/base/cursor/cursor.h"
22 #include "ui/gfx/display.h"
23 #include "ui/gfx/screen.h"
24 #include "ui/views/widget/widget.h"
25 #include "ui/views/widget/widget_delegate.h"
27 namespace ash {
28 namespace {
30 views::Widget* CreateTestWidgetWithParent(views::Widget* parent,
31 const gfx::Rect& bounds,
32 bool child) {
33 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
34 params.parent_widget = parent;
35 params.bounds = bounds;
36 params.child = child;
37 views::Widget* widget = new views::Widget;
38 widget->Init(params);
39 widget->Show();
40 return widget;
43 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
44 return CreateTestWidgetWithParent(NULL, bounds, false);
47 void SetSecondaryDisplayLayout(DisplayLayout::Position position) {
48 DisplayController* display_controller =
49 Shell::GetInstance()->display_controller();
50 DisplayLayout layout = display_controller->default_display_layout();
51 layout.position = position;
52 display_controller->SetDefaultDisplayLayout(layout);
55 class ModalWidgetDelegate : public views::WidgetDelegateView {
56 public:
57 ModalWidgetDelegate() {}
58 virtual ~ModalWidgetDelegate() {}
60 // Overridden from views::WidgetDelegate:
61 virtual views::View* GetContentsView() OVERRIDE {
62 return this;
64 virtual ui::ModalType GetModalType() const OVERRIDE {
65 return ui::MODAL_TYPE_SYSTEM;
68 private:
69 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
72 internal::MultiDisplayManager* GetDisplayManager() {
73 return static_cast<internal::MultiDisplayManager*>(
74 aura::Env::GetInstance()->display_manager());
77 } // namespace
79 typedef test::AshTestBase ExtendedDesktopTest;
81 // Test conditions that root windows in extended desktop mode
82 // must satisfy.
83 TEST_F(ExtendedDesktopTest, Basic) {
84 UpdateDisplay("1000x600,600x400");
85 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
87 // All root windows must have the root window controller.
88 ASSERT_EQ(2U, root_windows.size());
89 for (Shell::RootWindowList::const_iterator iter = root_windows.begin();
90 iter != root_windows.end(); ++iter) {
91 EXPECT_TRUE(GetRootWindowController(*iter) != NULL);
93 // Make sure root windows share the same controllers.
94 EXPECT_EQ(root_windows[0]->GetFocusManager(),
95 root_windows[1]->GetFocusManager());
96 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]),
97 aura::client::GetActivationClient(root_windows[1]));
98 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
99 aura::client::GetCaptureClient(root_windows[1]));
102 TEST_F(ExtendedDesktopTest, Activation) {
103 UpdateDisplay("1000x600,600x400");
104 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
106 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
107 views::Widget* widget_on_2nd =
108 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
109 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
110 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
112 EXPECT_EQ(widget_on_2nd->GetNativeView(),
113 root_windows[0]->GetFocusManager()->GetFocusedWindow());
114 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
116 aura::test::EventGenerator generator_1st(root_windows[0]);
117 aura::test::EventGenerator generator_2nd(root_windows[1]);
119 // Clicking a window changes the active window and active root window.
120 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
121 generator_1st.ClickLeftButton();
123 EXPECT_EQ(widget_on_1st->GetNativeView(),
124 root_windows[0]->GetFocusManager()->GetFocusedWindow());
125 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
127 generator_2nd.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
128 generator_2nd.ClickLeftButton();
130 EXPECT_EQ(widget_on_2nd->GetNativeView(),
131 root_windows[0]->GetFocusManager()->GetFocusedWindow());
132 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
135 TEST_F(ExtendedDesktopTest, SystemModal) {
136 UpdateDisplay("1000x600,600x400");
137 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
139 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
140 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
141 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
143 // Open system modal. Make sure it's on 2nd root window and active.
144 views::Widget* modal_widget = views::Widget::CreateWindowWithBounds(
145 new ModalWidgetDelegate(), gfx::Rect(1200, 100, 100, 100));
146 modal_widget->Show();
147 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
148 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow());
149 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
151 // Clicking a widget on widget_on_1st display should not change activation.
152 aura::test::EventGenerator generator_1st(root_windows[0]);
153 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
154 generator_1st.ClickLeftButton();
155 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
156 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
158 // Close system modal and so clicking a widget should work now.
159 modal_widget->Close();
160 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
161 generator_1st.ClickLeftButton();
162 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
163 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
166 TEST_F(ExtendedDesktopTest, TestCursor) {
167 UpdateDisplay("1000x600,600x400");
168 Shell::GetInstance()->ShowCursor(false);
169 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
170 EXPECT_FALSE(root_windows[0]->cursor_shown());
171 EXPECT_FALSE(root_windows[1]->cursor_shown());
172 Shell::GetInstance()->ShowCursor(true);
173 EXPECT_TRUE(root_windows[0]->cursor_shown());
174 EXPECT_TRUE(root_windows[1]->cursor_shown());
176 EXPECT_EQ(ui::kCursorPointer, root_windows[0]->last_cursor().native_type());
177 EXPECT_EQ(ui::kCursorPointer, root_windows[1]->last_cursor().native_type());
178 Shell::GetInstance()->SetCursor(ui::kCursorCopy);
179 EXPECT_EQ(ui::kCursorCopy, root_windows[0]->last_cursor().native_type());
180 EXPECT_EQ(ui::kCursorCopy, root_windows[1]->last_cursor().native_type());
183 TEST_F(ExtendedDesktopTest, TestCursorLocation) {
184 UpdateDisplay("0+0-1000x600,1001+0-600x400");
185 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
186 aura::Window::TestApi root_window0_test_api(root_windows[0]);
187 aura::Window::TestApi root_window1_test_api(root_windows[1]);
189 root_windows[0]->MoveCursorTo(gfx::Point(10, 10));
190 EXPECT_EQ("10,10", gfx::Screen::GetCursorScreenPoint().ToString());
191 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
192 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
193 root_windows[1]->MoveCursorTo(gfx::Point(10, 20));
194 EXPECT_EQ("1010,20", gfx::Screen::GetCursorScreenPoint().ToString());
195 EXPECT_FALSE(root_window0_test_api.ContainsMouse());
196 EXPECT_TRUE(root_window1_test_api.ContainsMouse());
197 root_windows[0]->MoveCursorTo(gfx::Point(20, 10));
198 EXPECT_EQ("20,10", gfx::Screen::GetCursorScreenPoint().ToString());
199 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
200 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
203 TEST_F(ExtendedDesktopTest, CycleWindows) {
204 UpdateDisplay("700x500,500x500");
205 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
207 WindowCycleController* controller =
208 Shell::GetInstance()->window_cycle_controller();
210 views::Widget* d1_w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
211 EXPECT_EQ(root_windows[0], d1_w1->GetNativeView()->GetRootWindow());
212 views::Widget* d2_w1 = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
213 EXPECT_EQ(root_windows[1], d2_w1->GetNativeView()->GetRootWindow());
214 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
216 controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
217 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
218 controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
219 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
220 controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
221 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
222 controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
223 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
225 // Cycle through all windows across root windows.
226 views::Widget* d1_w2 = CreateTestWidget(gfx::Rect(10, 200, 100, 100));
227 EXPECT_EQ(root_windows[0], d1_w2->GetNativeView()->GetRootWindow());
228 views::Widget* d2_w2 = CreateTestWidget(gfx::Rect(800, 200, 100, 100));
229 EXPECT_EQ(root_windows[1], d2_w2->GetNativeView()->GetRootWindow());
231 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
232 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
233 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
234 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
235 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
236 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
237 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
238 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
240 // Backwards
241 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
242 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
243 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
244 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
245 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
246 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
247 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
248 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
251 TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
252 UpdateDisplay("700x500,500x500");
253 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
254 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
256 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100)));
257 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100)));
258 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300)));
259 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700,300)));
261 // Zero origin.
262 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0)));
264 // Out of range point should return the primary root window
265 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(-600, 0)));
266 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100)));
269 TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
270 UpdateDisplay("700x500,500x500");
271 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
273 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
275 // Containing rect.
276 EXPECT_EQ(root_windows[1],
277 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50)));
278 EXPECT_EQ(root_windows[0],
279 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50)));
281 // Intersecting rect.
282 EXPECT_EQ(root_windows[1],
283 wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300)));
284 EXPECT_EQ(root_windows[0],
285 wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300)));
287 // Zero origin.
288 EXPECT_EQ(root_windows[0],
289 wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0)));
290 EXPECT_EQ(root_windows[0],
291 wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1)));
293 // Empty rect.
294 EXPECT_EQ(root_windows[1],
295 wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0)));
296 EXPECT_EQ(root_windows[0],
297 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0)));
299 // Out of range rect should return the primary root window.
300 EXPECT_EQ(root_windows[0],
301 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50)));
302 EXPECT_EQ(root_windows[0],
303 wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50)));
306 TEST_F(ExtendedDesktopTest, Capture) {
307 UpdateDisplay("1000x600,600x400");
308 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
310 aura::test::EventCountDelegate r1_d1;
311 aura::test::EventCountDelegate r1_d2;
312 aura::test::EventCountDelegate r2_d1;
314 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
315 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
316 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
317 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
318 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
319 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
321 r1_w1->SetCapture();
323 EXPECT_EQ(r1_w1.get(),
324 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
325 aura::test::EventGenerator generator2(root_windows[1]);
326 generator2.MoveMouseToCenterOf(r2_w1.get());
327 generator2.ClickLeftButton();
328 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
329 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
330 // The mouse is outside. On chromeos, the mouse is warped to the
331 // dest root window, but it's not implemented on Win yet, so
332 // no mouse move event on Win.
333 #if defined(OS_WIN)
334 EXPECT_EQ("1 0 0", r1_d1.GetMouseMotionCountsAndReset());
335 #else
336 EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset());
337 #endif
338 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
339 // (15,15) on 1st display is (-985,15) on 2nd display.
340 generator2.MoveMouseTo(-985, 15);
341 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset());
343 r1_w2->SetCapture();
344 EXPECT_EQ(r1_w2.get(),
345 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
346 generator2.MoveMouseBy(10, 10);
347 generator2.ClickLeftButton();
348 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
349 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
350 // mouse is already entered.
351 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset());
352 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset());
354 r1_w2->ReleaseCapture();
355 EXPECT_EQ(NULL,
356 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
357 generator2.MoveMouseTo(15, 15);
358 generator2.ClickLeftButton();
359 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
360 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
361 // Make sure the mouse_moved_handler_ is properly reset.
362 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
363 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
366 TEST_F(ExtendedDesktopTest, MoveWindow) {
367 UpdateDisplay("1000x600,600x400");
368 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
369 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
371 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
373 d1->SetBounds(gfx::Rect(1010, 10, 100, 100));
374 EXPECT_EQ("1010,10 100x100",
375 d1->GetWindowBoundsInScreen().ToString());
377 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
379 d1->SetBounds(gfx::Rect(10, 10, 100, 100));
380 EXPECT_EQ("10,10 100x100",
381 d1->GetWindowBoundsInScreen().ToString());
383 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
385 // Make sure the bounds which doesn't fit to the root window
386 // works correctly.
387 d1->SetBounds(gfx::Rect(1560, 30, 100, 100));
388 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
389 EXPECT_EQ("1560,30 100x100",
390 d1->GetWindowBoundsInScreen().ToString());
392 // Setting outside of root windows will be moved to primary root window.
393 // TODO(oshima): This one probably should pick the closest root window.
394 d1->SetBounds(gfx::Rect(200, 10, 100, 100));
395 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
398 TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) {
399 UpdateDisplay("1000x1000,1000x1000");
400 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
402 gfx::Display display0 =
403 gfx::Screen::GetDisplayMatching(root_windows[0]->GetBoundsInScreen());
404 gfx::Display display1 =
405 gfx::Screen::GetDisplayMatching(root_windows[1]->GetBoundsInScreen());
406 EXPECT_NE(display0.id(), display1.id());
408 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100));
409 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
411 // Move the window where the window spans both root windows. Since the second
412 // parameter is |display1|, the window should be shown on the secondary root.
413 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
414 display1);
415 EXPECT_EQ("500,10 1000x100",
416 d1->GetWindowBoundsInScreen().ToString());
417 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
419 // Move to the primary root.
420 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
421 display0);
422 EXPECT_EQ("500,10 1000x100",
423 d1->GetWindowBoundsInScreen().ToString());
424 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
427 TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
428 UpdateDisplay("1000x600,600x400");
429 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
430 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
431 views::Widget* w1_t1 = CreateTestWidgetWithParent(
432 w1, gfx::Rect(50, 50, 50, 50), false /* transient */);
433 // Transient child of the transient child.
434 views::Widget* w1_t11 = CreateTestWidgetWithParent(
435 w1_t1, gfx::Rect(1200, 70, 30, 30), false /* transient */);
437 views::Widget* w11 = CreateTestWidgetWithParent(
438 w1, gfx::Rect(10, 10, 40, 40), true /* child */);
439 views::Widget* w11_t1 = CreateTestWidgetWithParent(
440 w1, gfx::Rect(1300, 100, 80, 80), false /* transient */);
442 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
443 EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow());
444 EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow());
445 EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow());
446 EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow());
447 EXPECT_EQ("50,50 50x50",
448 w1_t1->GetWindowBoundsInScreen().ToString());
449 EXPECT_EQ("1200,70 30x30",
450 w1_t11->GetWindowBoundsInScreen().ToString());
451 EXPECT_EQ("20,20 40x40",
452 w11->GetWindowBoundsInScreen().ToString());
453 EXPECT_EQ("1300,100 80x80",
454 w11_t1->GetWindowBoundsInScreen().ToString());
456 w1->SetBounds(gfx::Rect(1100,10,100,100));
458 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
459 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
460 EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow());
461 EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow());
462 EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow());
464 EXPECT_EQ("1110,20 40x40",
465 w11->GetWindowBoundsInScreen().ToString());
466 // Transient window's screen bounds stays the same.
467 EXPECT_EQ("50,50 50x50",
468 w1_t1->GetWindowBoundsInScreen().ToString());
469 EXPECT_EQ("1200,70 30x30",
470 w1_t11->GetWindowBoundsInScreen().ToString());
471 EXPECT_EQ("1300,100 80x80",
472 w11_t1->GetWindowBoundsInScreen().ToString());
474 // Transient window doesn't move between root window unless
475 // its transient parent moves.
476 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50));
477 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
478 EXPECT_EQ("10,50 50x50",
479 w1_t1->GetWindowBoundsInScreen().ToString());
482 namespace internal {
483 // Test if the Window::ConvertPointToTarget works across root windows.
484 // TODO(oshima): Move multiple display suport and this test to aura.
485 TEST_F(ExtendedDesktopTest, ConvertPoint) {
486 UpdateDisplay("1000x600,600x400");
487 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
488 gfx::Display& display_1 =
489 GetDisplayManager()->FindDisplayForRootWindow(root_windows[0]);
490 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
491 gfx::Display& display_2 =
492 GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]);
493 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
495 aura::Window* d1 =
496 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
497 aura::Window* d2 =
498 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
499 EXPECT_EQ(root_windows[0], d1->GetRootWindow());
500 EXPECT_EQ(root_windows[1], d2->GetRootWindow());
502 // Convert point in the Root2's window to the Root1's window Coord.
503 gfx::Point p(0, 0);
504 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
505 EXPECT_EQ("1000,0", p.ToString());
506 p.SetPoint(0, 0);
507 aura::Window::ConvertPointToTarget(d2, d1, &p);
508 EXPECT_EQ("1010,10", p.ToString());
510 // Convert point in the Root1's window to the Root2's window Coord.
511 p.SetPoint(0, 0);
512 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
513 EXPECT_EQ("-1000,0", p.ToString());
514 p.SetPoint(0, 0);
515 aura::Window::ConvertPointToTarget(d1, d2, &p);
516 EXPECT_EQ("-1010,-10", p.ToString());
518 // Move the 2nd display to the bottom and test again.
519 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
521 display_2 = GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]);
522 EXPECT_EQ("0,600", display_2.bounds().origin().ToString());
524 // Convert point in Root2's window to Root1's window Coord.
525 p.SetPoint(0, 0);
526 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
527 EXPECT_EQ("0,600", p.ToString());
528 p.SetPoint(0, 0);
529 aura::Window::ConvertPointToTarget(d2, d1, &p);
530 EXPECT_EQ("10,610", p.ToString());
532 // Convert point in Root1's window to Root2's window Coord.
533 p.SetPoint(0, 0);
534 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
535 EXPECT_EQ("0,-600", p.ToString());
536 p.SetPoint(0, 0);
537 aura::Window::ConvertPointToTarget(d1, d2, &p);
538 EXPECT_EQ("-10,-610", p.ToString());
541 } // namespace internal
542 } // namespace ash