blob: 2b1108df8970fbbb9c82f520877ac3ebc701bcd1 [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]c39be8f2012-06-15 22:58:3647class ModalWidgetDelegate : public views::WidgetDelegateView {
48 public:
49 ModalWidgetDelegate() {}
50 virtual ~ModalWidgetDelegate() {}
51
52 // Overridden from views::WidgetDelegate:
53 virtual views::View* GetContentsView() OVERRIDE {
54 return this;
55 }
56 virtual ui::ModalType GetModalType() const OVERRIDE {
57 return ui::MODAL_TYPE_SYSTEM;
58 }
59
60 private:
61 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
62};
63
[email protected]3e4351b2012-08-09 04:04:1664internal::MultiDisplayManager* GetDisplayManager() {
65 return static_cast<internal::MultiDisplayManager*>(
66 aura::Env::GetInstance()->display_manager());
67}
68
[email protected]c39be8f2012-06-15 22:58:3669} // namespace
70
[email protected]3e4351b2012-08-09 04:04:1671typedef test::AshTestBase ExtendedDesktopTest;
[email protected]c39be8f2012-06-15 22:58:3672
73// Test conditions that root windows in extended desktop mode
74// must satisfy.
75TEST_F(ExtendedDesktopTest, Basic) {
[email protected]f634dd32012-07-23 22:49:0776 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:3677 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
78
79 // All root windows must have the root window controller.
80 ASSERT_EQ(2U, root_windows.size());
81 for (Shell::RootWindowList::const_iterator iter = root_windows.begin();
82 iter != root_windows.end(); ++iter) {
[email protected]7ae525002012-07-26 23:55:1083 EXPECT_TRUE(GetRootWindowController(*iter) != NULL);
[email protected]c39be8f2012-06-15 22:58:3684 }
85 // Make sure root windows share the same controllers.
86 EXPECT_EQ(root_windows[0]->GetFocusManager(),
87 root_windows[1]->GetFocusManager());
88 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]),
89 aura::client::GetActivationClient(root_windows[1]));
90 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
91 aura::client::GetCaptureClient(root_windows[1]));
92}
93
94TEST_F(ExtendedDesktopTest, Activation) {
[email protected]f634dd32012-07-23 22:49:0795 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:3696 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
97
[email protected]c39be8f2012-06-15 22:58:3698 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]f634dd32012-07-23 22:49:0799 views::Widget* widget_on_2nd =
100 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36101 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]f634dd32012-07-23 22:49:07102 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36103
104 EXPECT_EQ(widget_on_2nd->GetNativeView(),
105 root_windows[0]->GetFocusManager()->GetFocusedWindow());
106 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
107
[email protected]f634dd32012-07-23 22:49:07108 aura::test::EventGenerator generator_1st(root_windows[0]);
109 aura::test::EventGenerator generator_2nd(root_windows[1]);
110
111 // Clicking a window changes the active window and active root window.
[email protected]c39be8f2012-06-15 22:58:36112 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
113 generator_1st.ClickLeftButton();
114
115 EXPECT_EQ(widget_on_1st->GetNativeView(),
116 root_windows[0]->GetFocusManager()->GetFocusedWindow());
117 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]f634dd32012-07-23 22:49:07118
119 generator_2nd.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
120 generator_2nd.ClickLeftButton();
121
122 EXPECT_EQ(widget_on_2nd->GetNativeView(),
123 root_windows[0]->GetFocusManager()->GetFocusedWindow());
124 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
[email protected]c39be8f2012-06-15 22:58:36125}
126
127TEST_F(ExtendedDesktopTest, SystemModal) {
[email protected]f634dd32012-07-23 22:49:07128 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36129 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36130
131 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36132 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
133 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
134
[email protected]c39be8f2012-06-15 22:58:36135 // Open system modal. Make sure it's on 2nd root window and active.
[email protected]f634dd32012-07-23 22:49:07136 views::Widget* modal_widget = views::Widget::CreateWindowWithBounds(
137 new ModalWidgetDelegate(), gfx::Rect(1200, 100, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36138 modal_widget->Show();
139 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
140 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow());
141 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
142
[email protected]2e236a52012-06-27 22:21:47143 // Clicking a widget on widget_on_1st display should not change activation.
[email protected]c39be8f2012-06-15 22:58:36144 aura::test::EventGenerator generator_1st(root_windows[0]);
145 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
146 generator_1st.ClickLeftButton();
147 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
148 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
149
150 // Close system modal and so clicking a widget should work now.
151 modal_widget->Close();
152 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
153 generator_1st.ClickLeftButton();
154 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
155 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
156}
157
158TEST_F(ExtendedDesktopTest, TestCursor) {
[email protected]f634dd32012-07-23 22:49:07159 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36160 Shell::GetInstance()->ShowCursor(false);
161 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
162 EXPECT_FALSE(root_windows[0]->cursor_shown());
163 EXPECT_FALSE(root_windows[1]->cursor_shown());
164 Shell::GetInstance()->ShowCursor(true);
165 EXPECT_TRUE(root_windows[0]->cursor_shown());
166 EXPECT_TRUE(root_windows[1]->cursor_shown());
167
168 EXPECT_EQ(ui::kCursorPointer, root_windows[0]->last_cursor().native_type());
169 EXPECT_EQ(ui::kCursorPointer, root_windows[1]->last_cursor().native_type());
170 Shell::GetInstance()->SetCursor(ui::kCursorCopy);
171 EXPECT_EQ(ui::kCursorCopy, root_windows[0]->last_cursor().native_type());
172 EXPECT_EQ(ui::kCursorCopy, root_windows[1]->last_cursor().native_type());
173}
174
[email protected]718b26c2012-07-24 20:53:23175TEST_F(ExtendedDesktopTest, TestCursorLocation) {
176 UpdateDisplay("0+0-1000x600,1001+0-600x400");
177 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
178 aura::Window::TestApi root_window0_test_api(root_windows[0]);
179 aura::Window::TestApi root_window1_test_api(root_windows[1]);
180
181 root_windows[0]->MoveCursorTo(gfx::Point(10, 10));
182 EXPECT_EQ("10,10", gfx::Screen::GetCursorScreenPoint().ToString());
183 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
184 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
185 root_windows[1]->MoveCursorTo(gfx::Point(10, 20));
186 EXPECT_EQ("1010,20", gfx::Screen::GetCursorScreenPoint().ToString());
187 EXPECT_FALSE(root_window0_test_api.ContainsMouse());
188 EXPECT_TRUE(root_window1_test_api.ContainsMouse());
189 root_windows[0]->MoveCursorTo(gfx::Point(20, 10));
190 EXPECT_EQ("20,10", gfx::Screen::GetCursorScreenPoint().ToString());
191 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
192 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
193}
194
[email protected]0f81f442012-06-22 06:20:27195TEST_F(ExtendedDesktopTest, CycleWindows) {
[email protected]f634dd32012-07-23 22:49:07196 UpdateDisplay("700x500,500x500");
[email protected]0f81f442012-06-22 06:20:27197 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24198
[email protected]0f81f442012-06-22 06:20:27199 WindowCycleController* controller =
200 Shell::GetInstance()->window_cycle_controller();
201
[email protected]0f81f442012-06-22 06:20:27202 views::Widget* d1_w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
203 EXPECT_EQ(root_windows[0], d1_w1->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24204 views::Widget* d2_w1 = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
[email protected]0f81f442012-06-22 06:20:27205 EXPECT_EQ(root_windows[1], d2_w1->GetNativeView()->GetRootWindow());
206 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
207
208 controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
209 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
210 controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
211 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
212 controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
213 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
214 controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
215 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
216
217 // Cycle through all windows across root windows.
[email protected]20c59762012-06-23 01:10:24218 views::Widget* d1_w2 = CreateTestWidget(gfx::Rect(10, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27219 EXPECT_EQ(root_windows[0], d1_w2->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24220 views::Widget* d2_w2 = CreateTestWidget(gfx::Rect(800, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27221 EXPECT_EQ(root_windows[1], d2_w2->GetNativeView()->GetRootWindow());
222
223 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]0f81f442012-06-22 06:20:27224 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
225 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]8fef7432012-08-06 15:34:25226 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
227 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]0f81f442012-06-22 06:20:27228 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
229 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
230 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
231
232 // Backwards
233 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
234 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
235 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]0f81f442012-06-22 06:20:27236 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
237 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]8fef7432012-08-06 15:34:25238 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
239 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]0f81f442012-06-22 06:20:27240 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
[email protected]20c59762012-06-23 01:10:24241}
242
243TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
[email protected]f634dd32012-07-23 22:49:07244 UpdateDisplay("700x500,500x500");
[email protected]66b05eac2012-06-27 23:53:10245 Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout(
246 internal::DisplayController::LEFT);
[email protected]20c59762012-06-23 01:10:24247 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24248
[email protected]7203a5e2012-08-06 18:27:46249 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100)));
250 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100)));
251 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300)));
252 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700,300)));
[email protected]20c59762012-06-23 01:10:24253
254 // Zero origin.
[email protected]7203a5e2012-08-06 18:27:46255 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0)));
[email protected]20c59762012-06-23 01:10:24256
257 // Out of range point should return the primary root window
[email protected]7203a5e2012-08-06 18:27:46258 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(-600, 0)));
259 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100)));
[email protected]20c59762012-06-23 01:10:24260}
261
262TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
[email protected]f634dd32012-07-23 22:49:07263 UpdateDisplay("700x500,500x500");
[email protected]66b05eac2012-06-27 23:53:10264 Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout(
265 internal::DisplayController::LEFT);
266
[email protected]20c59762012-06-23 01:10:24267 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24268
269 // Containing rect.
270 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46271 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24272 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46273 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24274
275 // Intersecting rect.
276 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46277 wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300)));
[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, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24280
281 // Zero origin.
[email protected]66b05eac2012-06-27 23:53:10282 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46283 wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0)));
[email protected]66b05eac2012-06-27 23:53:10284 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46285 wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1)));
[email protected]20c59762012-06-23 01:10:24286
287 // Empty rect.
288 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46289 wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24290 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46291 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24292
293 // Out of range rect should return the primary root window.
294 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46295 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50)));
[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(0, 1000, 50, 50)));
[email protected]0f81f442012-06-22 06:20:27298}
299
[email protected]a5e71c92012-06-22 22:09:08300TEST_F(ExtendedDesktopTest, Capture) {
[email protected]f634dd32012-07-23 22:49:07301 UpdateDisplay("1000x600,600x400");
[email protected]a5e71c92012-06-22 22:09:08302 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
303
304 aura::test::EventCountDelegate r1_d1;
305 aura::test::EventCountDelegate r1_d2;
306 aura::test::EventCountDelegate r2_d1;
307
308 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
309 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
310 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
311 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
312 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
313 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
[email protected]f634dd32012-07-23 22:49:07314
[email protected]a5e71c92012-06-22 22:09:08315 r1_w1->SetCapture();
316
317 EXPECT_EQ(r1_w1.get(),
318 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
319 aura::test::EventGenerator generator2(root_windows[1]);
320 generator2.MoveMouseToCenterOf(r2_w1.get());
321 generator2.ClickLeftButton();
322 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
323 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]f634dd32012-07-23 22:49:07324 // The mouse is outside, so no move event will be sent.
325 EXPECT_EQ("1 0 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08326 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
[email protected]f634dd32012-07-23 22:49:07327 // (15,15) on 1st display is (-985,15) on 2nd display.
328 generator2.MoveMouseTo(-985, 15);
329 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08330
331 r1_w2->SetCapture();
332 EXPECT_EQ(r1_w2.get(),
333 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
334 generator2.MoveMouseBy(10, 10);
335 generator2.ClickLeftButton();
336 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
337 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
338 // mouse is already entered.
339 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset());
340 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset());
341
342 r1_w2->ReleaseCapture();
343 EXPECT_EQ(NULL,
344 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]f634dd32012-07-23 22:49:07345 generator2.MoveMouseTo(15, 15);
[email protected]a5e71c92012-06-22 22:09:08346 generator2.ClickLeftButton();
347 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
348 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
349 // Make sure the mouse_moved_handler_ is properly reset.
350 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
351 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
352}
353
[email protected]f059c6942012-07-21 14:27:57354TEST_F(ExtendedDesktopTest, MoveWindow) {
[email protected]f634dd32012-07-23 22:49:07355 UpdateDisplay("1000x600,600x400");
[email protected]f059c6942012-07-21 14:27:57356 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
357 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
358
359 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
360
361 d1->SetBounds(gfx::Rect(1010, 10, 100, 100));
362 EXPECT_EQ("1010,10 100x100",
363 d1->GetWindowBoundsInScreen().ToString());
364
365 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
366
367 d1->SetBounds(gfx::Rect(10, 10, 100, 100));
368 EXPECT_EQ("10,10 100x100",
369 d1->GetWindowBoundsInScreen().ToString());
370
371 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
372
373 // Make sure the bounds which doesn't fit to the root window
374 // works correctly.
375 d1->SetBounds(gfx::Rect(1560, 30, 100, 100));
376 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
377 EXPECT_EQ("1560,30 100x100",
378 d1->GetWindowBoundsInScreen().ToString());
379
380 // Setting outside of root windows will be moved to primary root window.
381 // TODO(oshima): This one probably should pick the closest root window.
382 d1->SetBounds(gfx::Rect(200, 10, 100, 100));
383 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
[email protected]f059c6942012-07-21 14:27:57384}
385
386TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
[email protected]f634dd32012-07-23 22:49:07387 UpdateDisplay("1000x600,600x400");
[email protected]f059c6942012-07-21 14:27:57388 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
389 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
390 views::Widget* w1_t1 = CreateTestWidgetWithParent(
391 w1, gfx::Rect(50, 50, 50, 50), false /* transient */);
392 // Transient child of the transient child.
393 views::Widget* w1_t11 = CreateTestWidgetWithParent(
394 w1_t1, gfx::Rect(1200, 70, 30, 30), false /* transient */);
395
396 views::Widget* w11 = CreateTestWidgetWithParent(
397 w1, gfx::Rect(10, 10, 40, 40), true /* child */);
398 views::Widget* w11_t1 = CreateTestWidgetWithParent(
399 w1, gfx::Rect(1300, 100, 80, 80), false /* transient */);
400
401 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
402 EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow());
403 EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow());
404 EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow());
405 EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow());
406 EXPECT_EQ("50,50 50x50",
407 w1_t1->GetWindowBoundsInScreen().ToString());
408 EXPECT_EQ("1200,70 30x30",
409 w1_t11->GetWindowBoundsInScreen().ToString());
410 EXPECT_EQ("20,20 40x40",
411 w11->GetWindowBoundsInScreen().ToString());
412 EXPECT_EQ("1300,100 80x80",
413 w11_t1->GetWindowBoundsInScreen().ToString());
414
415 w1->SetBounds(gfx::Rect(1100,10,100,100));
416
417 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
418 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
419 EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow());
420 EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow());
421 EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow());
422
423 EXPECT_EQ("1110,20 40x40",
424 w11->GetWindowBoundsInScreen().ToString());
425 // Transient window's screen bounds stays the same.
426 EXPECT_EQ("50,50 50x50",
427 w1_t1->GetWindowBoundsInScreen().ToString());
428 EXPECT_EQ("1200,70 30x30",
429 w1_t11->GetWindowBoundsInScreen().ToString());
430 EXPECT_EQ("1300,100 80x80",
431 w11_t1->GetWindowBoundsInScreen().ToString());
432
433 // Transient window doesn't move between root window unless
434 // its transient parent moves.
435 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50));
436 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
437 EXPECT_EQ("10,50 50x50",
438 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57439}
440
[email protected]a5e71c92012-06-22 22:09:08441namespace internal {
[email protected]ca7060982012-08-08 18:05:25442// Test if the Window::ConvertPointToTarget works across root windows.
[email protected]a5e71c92012-06-22 22:09:08443// TODO(oshima): Move multiple display suport and this test to aura.
444TEST_F(ExtendedDesktopTest, ConvertPoint) {
[email protected]f634dd32012-07-23 22:49:07445 UpdateDisplay("1000x600,600x400");
[email protected]a5e71c92012-06-22 22:09:08446 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
447 gfx::Display& display_1 =
[email protected]3e4351b2012-08-09 04:04:16448 GetDisplayManager()->FindDisplayForRootWindow(root_windows[0]);
[email protected]a5e71c92012-06-22 22:09:08449 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
450 gfx::Display& display_2 =
[email protected]3e4351b2012-08-09 04:04:16451 GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07452 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
453
[email protected]a5e71c92012-06-22 22:09:08454 aura::Window* d1 =
455 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
[email protected]a5e71c92012-06-22 22:09:08456 aura::Window* d2 =
[email protected]f634dd32012-07-23 22:49:07457 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
458 EXPECT_EQ(root_windows[0], d1->GetRootWindow());
459 EXPECT_EQ(root_windows[1], d2->GetRootWindow());
[email protected]a5e71c92012-06-22 22:09:08460
[email protected]a5e71c92012-06-22 22:09:08461 // Convert point in the Root2's window to the Root1's window Coord.
462 gfx::Point p(0, 0);
[email protected]ca7060982012-08-08 18:05:25463 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07464 EXPECT_EQ("1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08465 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25466 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07467 EXPECT_EQ("1010,10", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08468
469 // Convert point in the Root1's window to the Root2's window Coord.
470 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25471 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07472 EXPECT_EQ("-1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08473 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25474 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07475 EXPECT_EQ("-1010,-10", p.ToString());
476
477 // Move the 2nd display to the bottom and test again.
478 Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout(
479 internal::DisplayController::BOTTOM);
480
[email protected]3e4351b2012-08-09 04:04:16481 display_2 = GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07482 EXPECT_EQ("0,600", display_2.bounds().origin().ToString());
483
484 // Convert point in Root2's window to Root1's window Coord.
485 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25486 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07487 EXPECT_EQ("0,600", p.ToString());
488 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25489 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07490 EXPECT_EQ("10,610", p.ToString());
491
492 // Convert point in Root1's window to Root2's window Coord.
493 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25494 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07495 EXPECT_EQ("0,-600", p.ToString());
496 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25497 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07498 EXPECT_EQ("-10,-610", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08499}
[email protected]f634dd32012-07-23 22:49:07500
[email protected]a5e71c92012-06-22 22:09:08501} // namespace internal
[email protected]c39be8f2012-06-15 22:58:36502} // namespace ash