blob: 20e4115945e2d592ab4fb8e3bf09904a268f3fb0 [file] [log] [blame]
[email protected]c39be8f2012-06-15 22:58:361// 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
[email protected]2e236a52012-06-27 22:21:475#include "ash/display/display_controller.h"
6#include "ash/display/multi_display_manager.h"
[email protected]c39be8f2012-06-15 22:58:367#include "ash/shell.h"
8#include "ash/test/ash_test_base.h"
[email protected]7203a5e2012-08-06 18:27:469#include "ash/wm/coordinate_conversion.h"
[email protected]7ae525002012-07-26 23:55:1010#include "ash/wm/property_util.h"
[email protected]0f81f442012-06-22 06:20:2711#include "ash/wm/window_cycle_controller.h"
[email protected]c39be8f2012-06-15 22:58:3612#include "ash/wm/window_util.h"
13#include "ui/aura/client/activation_client.h"
14#include "ui/aura/client/capture_client.h"
[email protected]a5e71c92012-06-22 22:09:0815#include "ui/aura/env.h"
[email protected]c39be8f2012-06-15 22:58:3616#include "ui/aura/focus_manager.h"
17#include "ui/aura/root_window.h"
18#include "ui/aura/test/event_generator.h"
[email protected]a5e71c92012-06-22 22:09:0819#include "ui/aura/test/test_windows.h"
[email protected]c39be8f2012-06-15 22:58:3620#include "ui/aura/window.h"
21#include "ui/base/cursor/cursor.h"
[email protected]a5e71c92012-06-22 22:09:0822#include "ui/gfx/display.h"
[email protected]718b26c2012-07-24 20:53:2323#include "ui/gfx/screen.h"
[email protected]c39be8f2012-06-15 22:58:3624#include "ui/views/widget/widget.h"
25#include "ui/views/widget/widget_delegate.h"
26
27namespace ash {
28namespace {
29
[email protected]f059c6942012-07-21 14:27:5730views::Widget* CreateTestWidgetWithParent(views::Widget* parent,
31 const gfx::Rect& bounds,
32 bool child) {
[email protected]c39be8f2012-06-15 22:58:3633 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
[email protected]f059c6942012-07-21 14:27:5734 params.parent_widget = parent;
[email protected]c39be8f2012-06-15 22:58:3635 params.bounds = bounds;
[email protected]f059c6942012-07-21 14:27:5736 params.child = child;
[email protected]c39be8f2012-06-15 22:58:3637 views::Widget* widget = new views::Widget;
38 widget->Init(params);
[email protected]0f81f442012-06-22 06:20:2739 widget->Show();
[email protected]c39be8f2012-06-15 22:58:3640 return widget;
41}
42
[email protected]f059c6942012-07-21 14:27:5743views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
44 return CreateTestWidgetWithParent(NULL, bounds, false);
45}
46
[email protected]edbfb8d2012-09-03 08:33:4347void 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);
53}
54
[email protected]c39be8f2012-06-15 22:58:3655class ModalWidgetDelegate : public views::WidgetDelegateView {
56 public:
57 ModalWidgetDelegate() {}
58 virtual ~ModalWidgetDelegate() {}
59
60 // Overridden from views::WidgetDelegate:
61 virtual views::View* GetContentsView() OVERRIDE {
62 return this;
63 }
64 virtual ui::ModalType GetModalType() const OVERRIDE {
65 return ui::MODAL_TYPE_SYSTEM;
66 }
67
68 private:
69 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
70};
71
[email protected]3e4351b2012-08-09 04:04:1672internal::MultiDisplayManager* GetDisplayManager() {
73 return static_cast<internal::MultiDisplayManager*>(
74 aura::Env::GetInstance()->display_manager());
75}
76
[email protected]c39be8f2012-06-15 22:58:3677} // namespace
78
[email protected]3e4351b2012-08-09 04:04:1679typedef test::AshTestBase ExtendedDesktopTest;
[email protected]c39be8f2012-06-15 22:58:3680
81// Test conditions that root windows in extended desktop mode
82// must satisfy.
83TEST_F(ExtendedDesktopTest, Basic) {
[email protected]f634dd32012-07-23 22:49:0784 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:3685 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
86
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) {
[email protected]7ae525002012-07-26 23:55:1091 EXPECT_TRUE(GetRootWindowController(*iter) != NULL);
[email protected]c39be8f2012-06-15 22:58:3692 }
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]));
100}
101
102TEST_F(ExtendedDesktopTest, Activation) {
[email protected]f634dd32012-07-23 22:49:07103 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36104 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
105
[email protected]c39be8f2012-06-15 22:58:36106 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]f634dd32012-07-23 22:49:07107 views::Widget* widget_on_2nd =
108 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36109 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]f634dd32012-07-23 22:49:07110 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36111
112 EXPECT_EQ(widget_on_2nd->GetNativeView(),
113 root_windows[0]->GetFocusManager()->GetFocusedWindow());
114 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
115
[email protected]f634dd32012-07-23 22:49:07116 aura::test::EventGenerator generator_1st(root_windows[0]);
117 aura::test::EventGenerator generator_2nd(root_windows[1]);
118
119 // Clicking a window changes the active window and active root window.
[email protected]c39be8f2012-06-15 22:58:36120 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
121 generator_1st.ClickLeftButton();
122
123 EXPECT_EQ(widget_on_1st->GetNativeView(),
124 root_windows[0]->GetFocusManager()->GetFocusedWindow());
125 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]f634dd32012-07-23 22:49:07126
127 generator_2nd.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
128 generator_2nd.ClickLeftButton();
129
130 EXPECT_EQ(widget_on_2nd->GetNativeView(),
131 root_windows[0]->GetFocusManager()->GetFocusedWindow());
132 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
[email protected]c39be8f2012-06-15 22:58:36133}
134
135TEST_F(ExtendedDesktopTest, SystemModal) {
[email protected]f634dd32012-07-23 22:49:07136 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36137 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36138
139 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36140 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
141 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
142
[email protected]c39be8f2012-06-15 22:58:36143 // Open system modal. Make sure it's on 2nd root window and active.
[email protected]f634dd32012-07-23 22:49:07144 views::Widget* modal_widget = views::Widget::CreateWindowWithBounds(
145 new ModalWidgetDelegate(), gfx::Rect(1200, 100, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36146 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());
150
[email protected]2e236a52012-06-27 22:21:47151 // Clicking a widget on widget_on_1st display should not change activation.
[email protected]c39be8f2012-06-15 22:58:36152 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());
157
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());
164}
165
166TEST_F(ExtendedDesktopTest, TestCursor) {
[email protected]f634dd32012-07-23 22:49:07167 UpdateDisplay("1000x600,600x400");
[email protected]151ffdff2012-09-11 20:18:35168 Shell::GetInstance()->cursor_manager()->ShowCursor(false);
[email protected]c39be8f2012-06-15 22:58:36169 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
170 EXPECT_FALSE(root_windows[0]->cursor_shown());
171 EXPECT_FALSE(root_windows[1]->cursor_shown());
[email protected]151ffdff2012-09-11 20:18:35172 Shell::GetInstance()->cursor_manager()->ShowCursor(true);
[email protected]c39be8f2012-06-15 22:58:36173 EXPECT_TRUE(root_windows[0]->cursor_shown());
174 EXPECT_TRUE(root_windows[1]->cursor_shown());
175
176 EXPECT_EQ(ui::kCursorPointer, root_windows[0]->last_cursor().native_type());
177 EXPECT_EQ(ui::kCursorPointer, root_windows[1]->last_cursor().native_type());
[email protected]151ffdff2012-09-11 20:18:35178 Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy);
[email protected]c39be8f2012-06-15 22:58:36179 EXPECT_EQ(ui::kCursorCopy, root_windows[0]->last_cursor().native_type());
180 EXPECT_EQ(ui::kCursorCopy, root_windows[1]->last_cursor().native_type());
181}
182
[email protected]718b26c2012-07-24 20:53:23183TEST_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]);
188
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());
201}
202
[email protected]0f81f442012-06-22 06:20:27203TEST_F(ExtendedDesktopTest, CycleWindows) {
[email protected]f634dd32012-07-23 22:49:07204 UpdateDisplay("700x500,500x500");
[email protected]0f81f442012-06-22 06:20:27205 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24206
[email protected]0f81f442012-06-22 06:20:27207 WindowCycleController* controller =
208 Shell::GetInstance()->window_cycle_controller();
209
[email protected]0f81f442012-06-22 06:20:27210 views::Widget* d1_w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
211 EXPECT_EQ(root_windows[0], d1_w1->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24212 views::Widget* d2_w1 = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
[email protected]0f81f442012-06-22 06:20:27213 EXPECT_EQ(root_windows[1], d2_w1->GetNativeView()->GetRootWindow());
214 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
215
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()));
224
225 // Cycle through all windows across root windows.
[email protected]20c59762012-06-23 01:10:24226 views::Widget* d1_w2 = CreateTestWidget(gfx::Rect(10, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27227 EXPECT_EQ(root_windows[0], d1_w2->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24228 views::Widget* d2_w2 = CreateTestWidget(gfx::Rect(800, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27229 EXPECT_EQ(root_windows[1], d2_w2->GetNativeView()->GetRootWindow());
230
231 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]0f81f442012-06-22 06:20:27232 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
233 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]8fef7432012-08-06 15:34:25234 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
235 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]0f81f442012-06-22 06:20:27236 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
237 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
238 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
239
240 // Backwards
241 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
242 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
243 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]0f81f442012-06-22 06:20:27244 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
245 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]8fef7432012-08-06 15:34:25246 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
247 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]0f81f442012-06-22 06:20:27248 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
[email protected]20c59762012-06-23 01:10:24249}
250
251TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
[email protected]f634dd32012-07-23 22:49:07252 UpdateDisplay("700x500,500x500");
[email protected]edbfb8d2012-09-03 08:33:43253 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]20c59762012-06-23 01:10:24254 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24255
[email protected]7203a5e2012-08-06 18:27:46256 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)));
[email protected]20c59762012-06-23 01:10:24260
261 // Zero origin.
[email protected]7203a5e2012-08-06 18:27:46262 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0)));
[email protected]20c59762012-06-23 01:10:24263
264 // Out of range point should return the primary root window
[email protected]7203a5e2012-08-06 18:27:46265 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(-600, 0)));
266 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100)));
[email protected]20c59762012-06-23 01:10:24267}
268
269TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
[email protected]f634dd32012-07-23 22:49:07270 UpdateDisplay("700x500,500x500");
[email protected]edbfb8d2012-09-03 08:33:43271 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]66b05eac2012-06-27 23:53:10272
[email protected]20c59762012-06-23 01:10:24273 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24274
275 // Containing rect.
276 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46277 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24278 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46279 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24280
281 // Intersecting rect.
282 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46283 wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24284 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46285 wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24286
287 // Zero origin.
[email protected]66b05eac2012-06-27 23:53:10288 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46289 wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0)));
[email protected]66b05eac2012-06-27 23:53:10290 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46291 wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1)));
[email protected]20c59762012-06-23 01:10:24292
293 // Empty rect.
294 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46295 wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24296 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46297 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24298
299 // Out of range rect should return the primary root window.
300 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46301 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50)));
[email protected]20c59762012-06-23 01:10:24302 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46303 wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50)));
[email protected]0f81f442012-06-22 06:20:27304}
305
[email protected]a5e71c92012-06-22 22:09:08306TEST_F(ExtendedDesktopTest, Capture) {
[email protected]f634dd32012-07-23 22:49:07307 UpdateDisplay("1000x600,600x400");
[email protected]a5e71c92012-06-22 22:09:08308 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
309
310 aura::test::EventCountDelegate r1_d1;
311 aura::test::EventCountDelegate r1_d2;
312 aura::test::EventCountDelegate r2_d1;
313
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]));
[email protected]f634dd32012-07-23 22:49:07320
[email protected]a5e71c92012-06-22 22:09:08321 r1_w1->SetCapture();
322
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());
[email protected]b19ba4adf2012-09-07 16:13:29330 // 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
[email protected]7495e5032012-09-07 15:31:45336 EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]b19ba4adf2012-09-07 16:13:29337#endif
[email protected]a5e71c92012-06-22 22:09:08338 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
[email protected]f634dd32012-07-23 22:49:07339 // (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());
[email protected]a5e71c92012-06-22 22:09:08342
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());
353
354 r1_w2->ReleaseCapture();
355 EXPECT_EQ(NULL,
356 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]f634dd32012-07-23 22:49:07357 generator2.MoveMouseTo(15, 15);
[email protected]a5e71c92012-06-22 22:09:08358 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());
364}
365
[email protected]f059c6942012-07-21 14:27:57366TEST_F(ExtendedDesktopTest, MoveWindow) {
[email protected]f634dd32012-07-23 22:49:07367 UpdateDisplay("1000x600,600x400");
[email protected]f059c6942012-07-21 14:27:57368 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
369 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
370
371 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
372
373 d1->SetBounds(gfx::Rect(1010, 10, 100, 100));
374 EXPECT_EQ("1010,10 100x100",
375 d1->GetWindowBoundsInScreen().ToString());
376
377 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
378
379 d1->SetBounds(gfx::Rect(10, 10, 100, 100));
380 EXPECT_EQ("10,10 100x100",
381 d1->GetWindowBoundsInScreen().ToString());
382
383 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
384
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());
391
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());
[email protected]f059c6942012-07-21 14:27:57396}
397
[email protected]e79f26e2012-08-09 07:12:48398TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) {
399 UpdateDisplay("1000x1000,1000x1000");
400 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
401
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());
407
408 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100));
409 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
410
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());
418
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());
425}
426
[email protected]f059c6942012-07-21 14:27:57427TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
[email protected]f634dd32012-07-23 22:49:07428 UpdateDisplay("1000x600,600x400");
[email protected]f059c6942012-07-21 14:27:57429 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 */);
436
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 */);
441
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());
455
456 w1->SetBounds(gfx::Rect(1100,10,100,100));
457
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());
463
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());
473
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());
[email protected]f059c6942012-07-21 14:27:57480}
481
[email protected]a5e71c92012-06-22 22:09:08482namespace internal {
[email protected]ca7060982012-08-08 18:05:25483// Test if the Window::ConvertPointToTarget works across root windows.
[email protected]a5e71c92012-06-22 22:09:08484// TODO(oshima): Move multiple display suport and this test to aura.
485TEST_F(ExtendedDesktopTest, ConvertPoint) {
[email protected]f634dd32012-07-23 22:49:07486 UpdateDisplay("1000x600,600x400");
[email protected]a5e71c92012-06-22 22:09:08487 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
488 gfx::Display& display_1 =
[email protected]3e4351b2012-08-09 04:04:16489 GetDisplayManager()->FindDisplayForRootWindow(root_windows[0]);
[email protected]a5e71c92012-06-22 22:09:08490 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
491 gfx::Display& display_2 =
[email protected]3e4351b2012-08-09 04:04:16492 GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07493 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
494
[email protected]a5e71c92012-06-22 22:09:08495 aura::Window* d1 =
496 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
[email protected]a5e71c92012-06-22 22:09:08497 aura::Window* d2 =
[email protected]f634dd32012-07-23 22:49:07498 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
499 EXPECT_EQ(root_windows[0], d1->GetRootWindow());
500 EXPECT_EQ(root_windows[1], d2->GetRootWindow());
[email protected]a5e71c92012-06-22 22:09:08501
[email protected]a5e71c92012-06-22 22:09:08502 // Convert point in the Root2's window to the Root1's window Coord.
503 gfx::Point p(0, 0);
[email protected]ca7060982012-08-08 18:05:25504 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07505 EXPECT_EQ("1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08506 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25507 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07508 EXPECT_EQ("1010,10", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08509
510 // Convert point in the Root1's window to the Root2's window Coord.
511 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25512 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07513 EXPECT_EQ("-1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08514 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25515 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07516 EXPECT_EQ("-1010,-10", p.ToString());
517
518 // Move the 2nd display to the bottom and test again.
[email protected]edbfb8d2012-09-03 08:33:43519 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
[email protected]f634dd32012-07-23 22:49:07520
[email protected]3e4351b2012-08-09 04:04:16521 display_2 = GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07522 EXPECT_EQ("0,600", display_2.bounds().origin().ToString());
523
524 // Convert point in Root2's window to Root1's window Coord.
525 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25526 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07527 EXPECT_EQ("0,600", p.ToString());
528 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25529 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07530 EXPECT_EQ("10,610", p.ToString());
531
532 // Convert point in Root1's window to Root2's window Coord.
533 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25534 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07535 EXPECT_EQ("0,-600", p.ToString());
536 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25537 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07538 EXPECT_EQ("-10,-610", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08539}
[email protected]f634dd32012-07-23 22:49:07540
[email protected]a5e71c92012-06-22 22:09:08541} // namespace internal
[email protected]c39be8f2012-06-15 22:58:36542} // namespace ash