blob: e5fafa47d067b3c9e9b9f69bc11f00d6263fa356 [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]7ae525002012-07-26 23:55:109#include "ash/wm/property_util.h"
[email protected]0f81f442012-06-22 06:20:2710#include "ash/wm/window_cycle_controller.h"
[email protected]c39be8f2012-06-15 22:58:3611#include "ash/wm/window_util.h"
12#include "ui/aura/client/activation_client.h"
13#include "ui/aura/client/capture_client.h"
[email protected]a5e71c92012-06-22 22:09:0814#include "ui/aura/env.h"
[email protected]c39be8f2012-06-15 22:58:3615#include "ui/aura/focus_manager.h"
16#include "ui/aura/root_window.h"
17#include "ui/aura/test/event_generator.h"
[email protected]a5e71c92012-06-22 22:09:0818#include "ui/aura/test/test_windows.h"
[email protected]c39be8f2012-06-15 22:58:3619#include "ui/aura/window.h"
20#include "ui/base/cursor/cursor.h"
[email protected]a5e71c92012-06-22 22:09:0821#include "ui/gfx/display.h"
[email protected]718b26c2012-07-24 20:53:2322#include "ui/gfx/screen.h"
[email protected]c39be8f2012-06-15 22:58:3623#include "ui/views/widget/widget.h"
24#include "ui/views/widget/widget_delegate.h"
25
26namespace ash {
27namespace {
28
[email protected]f059c6942012-07-21 14:27:5729views::Widget* CreateTestWidgetWithParent(views::Widget* parent,
30 const gfx::Rect& bounds,
31 bool child) {
[email protected]c39be8f2012-06-15 22:58:3632 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
[email protected]f059c6942012-07-21 14:27:5733 params.parent_widget = parent;
[email protected]c39be8f2012-06-15 22:58:3634 params.bounds = bounds;
[email protected]f059c6942012-07-21 14:27:5735 params.child = child;
[email protected]c39be8f2012-06-15 22:58:3636 views::Widget* widget = new views::Widget;
37 widget->Init(params);
[email protected]0f81f442012-06-22 06:20:2738 widget->Show();
[email protected]c39be8f2012-06-15 22:58:3639 return widget;
40}
41
[email protected]f059c6942012-07-21 14:27:5742views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
43 return CreateTestWidgetWithParent(NULL, bounds, false);
44}
45
[email protected]c39be8f2012-06-15 22:58:3646class ModalWidgetDelegate : public views::WidgetDelegateView {
47 public:
48 ModalWidgetDelegate() {}
49 virtual ~ModalWidgetDelegate() {}
50
51 // Overridden from views::WidgetDelegate:
52 virtual views::View* GetContentsView() OVERRIDE {
53 return this;
54 }
55 virtual ui::ModalType GetModalType() const OVERRIDE {
56 return ui::MODAL_TYPE_SYSTEM;
57 }
58
59 private:
60 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
61};
62
[email protected]b3c8d982012-07-25 07:03:0663internal::MultiDisplayManager* GetDisplayManager() {
64 return static_cast<internal::MultiDisplayManager*>(
65 aura::Env::GetInstance()->display_manager());
66}
67
[email protected]c39be8f2012-06-15 22:58:3668} // namespace
69
[email protected]b3c8d982012-07-25 07:03:0670typedef test::AshTestBase ExtendedDesktopTest;
[email protected]c39be8f2012-06-15 22:58:3671
72// Test conditions that root windows in extended desktop mode
73// must satisfy.
74TEST_F(ExtendedDesktopTest, Basic) {
[email protected]f634dd32012-07-23 22:49:0775 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:3676 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
77
78 // All root windows must have the root window controller.
79 ASSERT_EQ(2U, root_windows.size());
80 for (Shell::RootWindowList::const_iterator iter = root_windows.begin();
81 iter != root_windows.end(); ++iter) {
[email protected]7ae525002012-07-26 23:55:1082 EXPECT_TRUE(GetRootWindowController(*iter) != NULL);
[email protected]c39be8f2012-06-15 22:58:3683 }
84 // Make sure root windows share the same controllers.
85 EXPECT_EQ(root_windows[0]->GetFocusManager(),
86 root_windows[1]->GetFocusManager());
87 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]),
88 aura::client::GetActivationClient(root_windows[1]));
89 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
90 aura::client::GetCaptureClient(root_windows[1]));
91}
92
93TEST_F(ExtendedDesktopTest, Activation) {
[email protected]f634dd32012-07-23 22:49:0794 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:3695 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
96
[email protected]c39be8f2012-06-15 22:58:3697 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]f634dd32012-07-23 22:49:0798 views::Widget* widget_on_2nd =
99 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36100 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]f634dd32012-07-23 22:49:07101 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36102
103 EXPECT_EQ(widget_on_2nd->GetNativeView(),
104 root_windows[0]->GetFocusManager()->GetFocusedWindow());
105 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
106
[email protected]f634dd32012-07-23 22:49:07107 aura::test::EventGenerator generator_1st(root_windows[0]);
108 aura::test::EventGenerator generator_2nd(root_windows[1]);
109
110 // Clicking a window changes the active window and active root window.
[email protected]c39be8f2012-06-15 22:58:36111 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
112 generator_1st.ClickLeftButton();
113
114 EXPECT_EQ(widget_on_1st->GetNativeView(),
115 root_windows[0]->GetFocusManager()->GetFocusedWindow());
116 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]f634dd32012-07-23 22:49:07117
118 generator_2nd.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
119 generator_2nd.ClickLeftButton();
120
121 EXPECT_EQ(widget_on_2nd->GetNativeView(),
122 root_windows[0]->GetFocusManager()->GetFocusedWindow());
123 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
[email protected]c39be8f2012-06-15 22:58:36124}
125
126TEST_F(ExtendedDesktopTest, SystemModal) {
[email protected]f634dd32012-07-23 22:49:07127 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36128 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36129
130 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36131 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
132 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
133
[email protected]c39be8f2012-06-15 22:58:36134 // Open system modal. Make sure it's on 2nd root window and active.
[email protected]f634dd32012-07-23 22:49:07135 views::Widget* modal_widget = views::Widget::CreateWindowWithBounds(
136 new ModalWidgetDelegate(), gfx::Rect(1200, 100, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36137 modal_widget->Show();
138 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
139 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow());
140 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
141
[email protected]2e236a52012-06-27 22:21:47142 // Clicking a widget on widget_on_1st display should not change activation.
[email protected]c39be8f2012-06-15 22:58:36143 aura::test::EventGenerator generator_1st(root_windows[0]);
144 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
145 generator_1st.ClickLeftButton();
146 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
147 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
148
149 // Close system modal and so clicking a widget should work now.
150 modal_widget->Close();
151 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
152 generator_1st.ClickLeftButton();
153 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
154 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
155}
156
157TEST_F(ExtendedDesktopTest, TestCursor) {
[email protected]f634dd32012-07-23 22:49:07158 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36159 Shell::GetInstance()->ShowCursor(false);
160 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
161 EXPECT_FALSE(root_windows[0]->cursor_shown());
162 EXPECT_FALSE(root_windows[1]->cursor_shown());
163 Shell::GetInstance()->ShowCursor(true);
164 EXPECT_TRUE(root_windows[0]->cursor_shown());
165 EXPECT_TRUE(root_windows[1]->cursor_shown());
166
167 EXPECT_EQ(ui::kCursorPointer, root_windows[0]->last_cursor().native_type());
168 EXPECT_EQ(ui::kCursorPointer, root_windows[1]->last_cursor().native_type());
169 Shell::GetInstance()->SetCursor(ui::kCursorCopy);
170 EXPECT_EQ(ui::kCursorCopy, root_windows[0]->last_cursor().native_type());
171 EXPECT_EQ(ui::kCursorCopy, root_windows[1]->last_cursor().native_type());
172}
173
[email protected]718b26c2012-07-24 20:53:23174TEST_F(ExtendedDesktopTest, TestCursorLocation) {
175 UpdateDisplay("0+0-1000x600,1001+0-600x400");
176 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
177 aura::Window::TestApi root_window0_test_api(root_windows[0]);
178 aura::Window::TestApi root_window1_test_api(root_windows[1]);
179
180 root_windows[0]->MoveCursorTo(gfx::Point(10, 10));
181 EXPECT_EQ("10,10", gfx::Screen::GetCursorScreenPoint().ToString());
182 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
183 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
184 root_windows[1]->MoveCursorTo(gfx::Point(10, 20));
185 EXPECT_EQ("1010,20", gfx::Screen::GetCursorScreenPoint().ToString());
186 EXPECT_FALSE(root_window0_test_api.ContainsMouse());
187 EXPECT_TRUE(root_window1_test_api.ContainsMouse());
188 root_windows[0]->MoveCursorTo(gfx::Point(20, 10));
189 EXPECT_EQ("20,10", gfx::Screen::GetCursorScreenPoint().ToString());
190 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
191 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
192}
193
[email protected]0f81f442012-06-22 06:20:27194TEST_F(ExtendedDesktopTest, CycleWindows) {
[email protected]f634dd32012-07-23 22:49:07195 UpdateDisplay("700x500,500x500");
[email protected]0f81f442012-06-22 06:20:27196 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24197
[email protected]0f81f442012-06-22 06:20:27198 WindowCycleController* controller =
199 Shell::GetInstance()->window_cycle_controller();
200
[email protected]0f81f442012-06-22 06:20:27201 views::Widget* d1_w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
202 EXPECT_EQ(root_windows[0], d1_w1->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24203 views::Widget* d2_w1 = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
[email protected]0f81f442012-06-22 06:20:27204 EXPECT_EQ(root_windows[1], d2_w1->GetNativeView()->GetRootWindow());
205 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
206
207 controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
208 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
209 controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
210 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
211 controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
212 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
213 controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
214 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
215
216 // Cycle through all windows across root windows.
[email protected]20c59762012-06-23 01:10:24217 views::Widget* d1_w2 = CreateTestWidget(gfx::Rect(10, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27218 EXPECT_EQ(root_windows[0], d1_w2->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24219 views::Widget* d2_w2 = CreateTestWidget(gfx::Rect(800, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27220 EXPECT_EQ(root_windows[1], d2_w2->GetNativeView()->GetRootWindow());
221
222 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]0f81f442012-06-22 06:20:27223 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
224 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]8fef7432012-08-06 15:34:25225 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
226 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]0f81f442012-06-22 06:20:27227 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
228 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
229 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
230
231 // Backwards
232 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
233 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
234 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]0f81f442012-06-22 06:20:27235 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
236 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]8fef7432012-08-06 15:34:25237 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
238 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]0f81f442012-06-22 06:20:27239 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
[email protected]20c59762012-06-23 01:10:24240}
241
242TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
[email protected]f634dd32012-07-23 22:49:07243 UpdateDisplay("700x500,500x500");
[email protected]66b05eac2012-06-27 23:53:10244 Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout(
245 internal::DisplayController::LEFT);
[email protected]20c59762012-06-23 01:10:24246 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24247
[email protected]66b05eac2012-06-27 23:53:10248 EXPECT_EQ(root_windows[1], Shell::GetRootWindowAt(gfx::Point(-400, 100)));
249 EXPECT_EQ(root_windows[1], Shell::GetRootWindowAt(gfx::Point(-1, 100)));
250 EXPECT_EQ(root_windows[0], Shell::GetRootWindowAt(gfx::Point(0, 300)));
251 EXPECT_EQ(root_windows[0], Shell::GetRootWindowAt(gfx::Point(700,300)));
[email protected]20c59762012-06-23 01:10:24252
253 // Zero origin.
[email protected]66b05eac2012-06-27 23:53:10254 EXPECT_EQ(root_windows[0], Shell::GetRootWindowAt(gfx::Point(0, 0)));
[email protected]20c59762012-06-23 01:10:24255
256 // Out of range point should return the primary root window
[email protected]66b05eac2012-06-27 23:53:10257 EXPECT_EQ(root_windows[0], Shell::GetRootWindowAt(gfx::Point(-600, 0)));
258 EXPECT_EQ(root_windows[0], Shell::GetRootWindowAt(gfx::Point(701, 100)));
[email protected]20c59762012-06-23 01:10:24259}
260
261TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
[email protected]f634dd32012-07-23 22:49:07262 UpdateDisplay("700x500,500x500");
[email protected]66b05eac2012-06-27 23:53:10263 Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout(
264 internal::DisplayController::LEFT);
265
[email protected]20c59762012-06-23 01:10:24266 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24267
268 // Containing rect.
269 EXPECT_EQ(root_windows[1],
[email protected]66b05eac2012-06-27 23:53:10270 Shell::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24271 EXPECT_EQ(root_windows[0],
[email protected]66b05eac2012-06-27 23:53:10272 Shell::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24273
274 // Intersecting rect.
275 EXPECT_EQ(root_windows[1],
[email protected]66b05eac2012-06-27 23:53:10276 Shell::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24277 EXPECT_EQ(root_windows[0],
[email protected]66b05eac2012-06-27 23:53:10278 Shell::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24279
280 // Zero origin.
[email protected]66b05eac2012-06-27 23:53:10281 EXPECT_EQ(root_windows[0],
[email protected]20c59762012-06-23 01:10:24282 Shell::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0)));
[email protected]66b05eac2012-06-27 23:53:10283 EXPECT_EQ(root_windows[0],
[email protected]20c59762012-06-23 01:10:24284 Shell::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1)));
285
286 // Empty rect.
287 EXPECT_EQ(root_windows[1],
[email protected]66b05eac2012-06-27 23:53:10288 Shell::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24289 EXPECT_EQ(root_windows[0],
[email protected]66b05eac2012-06-27 23:53:10290 Shell::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24291
292 // Out of range rect should return the primary root window.
293 EXPECT_EQ(root_windows[0],
[email protected]66b05eac2012-06-27 23:53:10294 Shell::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50)));
[email protected]20c59762012-06-23 01:10:24295 EXPECT_EQ(root_windows[0],
[email protected]66b05eac2012-06-27 23:53:10296 Shell::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50)));
[email protected]0f81f442012-06-22 06:20:27297}
298
[email protected]a5e71c92012-06-22 22:09:08299TEST_F(ExtendedDesktopTest, Capture) {
[email protected]f634dd32012-07-23 22:49:07300 UpdateDisplay("1000x600,600x400");
[email protected]a5e71c92012-06-22 22:09:08301 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
302
303 aura::test::EventCountDelegate r1_d1;
304 aura::test::EventCountDelegate r1_d2;
305 aura::test::EventCountDelegate r2_d1;
306
307 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
308 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
309 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
310 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
311 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
312 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
[email protected]f634dd32012-07-23 22:49:07313
[email protected]a5e71c92012-06-22 22:09:08314 r1_w1->SetCapture();
315
316 EXPECT_EQ(r1_w1.get(),
317 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
318 aura::test::EventGenerator generator2(root_windows[1]);
319 generator2.MoveMouseToCenterOf(r2_w1.get());
320 generator2.ClickLeftButton();
321 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
322 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]f634dd32012-07-23 22:49:07323 // The mouse is outside, so no move event will be sent.
324 EXPECT_EQ("1 0 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08325 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
[email protected]f634dd32012-07-23 22:49:07326 // (15,15) on 1st display is (-985,15) on 2nd display.
327 generator2.MoveMouseTo(-985, 15);
328 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08329
330 r1_w2->SetCapture();
331 EXPECT_EQ(r1_w2.get(),
332 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
333 generator2.MoveMouseBy(10, 10);
334 generator2.ClickLeftButton();
335 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
336 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
337 // mouse is already entered.
338 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset());
339 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset());
340
341 r1_w2->ReleaseCapture();
342 EXPECT_EQ(NULL,
343 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]f634dd32012-07-23 22:49:07344 generator2.MoveMouseTo(15, 15);
[email protected]a5e71c92012-06-22 22:09:08345 generator2.ClickLeftButton();
346 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
347 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
348 // Make sure the mouse_moved_handler_ is properly reset.
349 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
350 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
351}
352
[email protected]f059c6942012-07-21 14:27:57353TEST_F(ExtendedDesktopTest, MoveWindow) {
[email protected]f634dd32012-07-23 22:49:07354 UpdateDisplay("1000x600,600x400");
[email protected]f059c6942012-07-21 14:27:57355 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
356 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
357
358 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
359
360 d1->SetBounds(gfx::Rect(1010, 10, 100, 100));
361 EXPECT_EQ("1010,10 100x100",
362 d1->GetWindowBoundsInScreen().ToString());
363
364 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
365
366 d1->SetBounds(gfx::Rect(10, 10, 100, 100));
367 EXPECT_EQ("10,10 100x100",
368 d1->GetWindowBoundsInScreen().ToString());
369
370 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
371
372 // Make sure the bounds which doesn't fit to the root window
373 // works correctly.
374 d1->SetBounds(gfx::Rect(1560, 30, 100, 100));
375 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
376 EXPECT_EQ("1560,30 100x100",
377 d1->GetWindowBoundsInScreen().ToString());
378
379 // Setting outside of root windows will be moved to primary root window.
380 // TODO(oshima): This one probably should pick the closest root window.
381 d1->SetBounds(gfx::Rect(200, 10, 100, 100));
382 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
[email protected]f059c6942012-07-21 14:27:57383}
384
385TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
[email protected]f634dd32012-07-23 22:49:07386 UpdateDisplay("1000x600,600x400");
[email protected]f059c6942012-07-21 14:27:57387 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
388 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
389 views::Widget* w1_t1 = CreateTestWidgetWithParent(
390 w1, gfx::Rect(50, 50, 50, 50), false /* transient */);
391 // Transient child of the transient child.
392 views::Widget* w1_t11 = CreateTestWidgetWithParent(
393 w1_t1, gfx::Rect(1200, 70, 30, 30), false /* transient */);
394
395 views::Widget* w11 = CreateTestWidgetWithParent(
396 w1, gfx::Rect(10, 10, 40, 40), true /* child */);
397 views::Widget* w11_t1 = CreateTestWidgetWithParent(
398 w1, gfx::Rect(1300, 100, 80, 80), false /* transient */);
399
400 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
401 EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow());
402 EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow());
403 EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow());
404 EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow());
405 EXPECT_EQ("50,50 50x50",
406 w1_t1->GetWindowBoundsInScreen().ToString());
407 EXPECT_EQ("1200,70 30x30",
408 w1_t11->GetWindowBoundsInScreen().ToString());
409 EXPECT_EQ("20,20 40x40",
410 w11->GetWindowBoundsInScreen().ToString());
411 EXPECT_EQ("1300,100 80x80",
412 w11_t1->GetWindowBoundsInScreen().ToString());
413
414 w1->SetBounds(gfx::Rect(1100,10,100,100));
415
416 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
417 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
418 EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow());
419 EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow());
420 EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow());
421
422 EXPECT_EQ("1110,20 40x40",
423 w11->GetWindowBoundsInScreen().ToString());
424 // Transient window's screen bounds stays the same.
425 EXPECT_EQ("50,50 50x50",
426 w1_t1->GetWindowBoundsInScreen().ToString());
427 EXPECT_EQ("1200,70 30x30",
428 w1_t11->GetWindowBoundsInScreen().ToString());
429 EXPECT_EQ("1300,100 80x80",
430 w11_t1->GetWindowBoundsInScreen().ToString());
431
432 // Transient window doesn't move between root window unless
433 // its transient parent moves.
434 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50));
435 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
436 EXPECT_EQ("10,50 50x50",
437 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57438}
439
[email protected]a5e71c92012-06-22 22:09:08440namespace internal {
441// Test if the Window::ConvertPointToWindow works across root windows.
442// TODO(oshima): Move multiple display suport and this test to aura.
443TEST_F(ExtendedDesktopTest, ConvertPoint) {
[email protected]f634dd32012-07-23 22:49:07444 UpdateDisplay("1000x600,600x400");
[email protected]a5e71c92012-06-22 22:09:08445 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
446 gfx::Display& display_1 =
[email protected]b3c8d982012-07-25 07:03:06447 GetDisplayManager()->FindDisplayForRootWindow(root_windows[0]);
[email protected]a5e71c92012-06-22 22:09:08448 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
449 gfx::Display& display_2 =
[email protected]b3c8d982012-07-25 07:03:06450 GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07451 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
452
[email protected]a5e71c92012-06-22 22:09:08453 aura::Window* d1 =
454 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
[email protected]a5e71c92012-06-22 22:09:08455 aura::Window* d2 =
[email protected]f634dd32012-07-23 22:49:07456 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
457 EXPECT_EQ(root_windows[0], d1->GetRootWindow());
458 EXPECT_EQ(root_windows[1], d2->GetRootWindow());
[email protected]a5e71c92012-06-22 22:09:08459
[email protected]a5e71c92012-06-22 22:09:08460 // Convert point in the Root2's window to the Root1's window Coord.
461 gfx::Point p(0, 0);
462 aura::Window::ConvertPointToWindow(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07463 EXPECT_EQ("1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08464 p.SetPoint(0, 0);
465 aura::Window::ConvertPointToWindow(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07466 EXPECT_EQ("1010,10", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08467
468 // Convert point in the Root1's window to the Root2's window Coord.
469 p.SetPoint(0, 0);
470 aura::Window::ConvertPointToWindow(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07471 EXPECT_EQ("-1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08472 p.SetPoint(0, 0);
473 aura::Window::ConvertPointToWindow(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07474 EXPECT_EQ("-1010,-10", p.ToString());
475
476 // Move the 2nd display to the bottom and test again.
477 Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout(
478 internal::DisplayController::BOTTOM);
479
[email protected]b3c8d982012-07-25 07:03:06480 display_2 = GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07481 EXPECT_EQ("0,600", display_2.bounds().origin().ToString());
482
483 // Convert point in Root2's window to Root1's window Coord.
484 p.SetPoint(0, 0);
485 aura::Window::ConvertPointToWindow(root_windows[1], root_windows[0], &p);
486 EXPECT_EQ("0,600", p.ToString());
487 p.SetPoint(0, 0);
488 aura::Window::ConvertPointToWindow(d2, d1, &p);
489 EXPECT_EQ("10,610", p.ToString());
490
491 // Convert point in Root1's window to Root2's window Coord.
492 p.SetPoint(0, 0);
493 aura::Window::ConvertPointToWindow(root_windows[0], root_windows[1], &p);
494 EXPECT_EQ("0,-600", p.ToString());
495 p.SetPoint(0, 0);
496 aura::Window::ConvertPointToWindow(d1, d2, &p);
497 EXPECT_EQ("-10,-610", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08498}
[email protected]f634dd32012-07-23 22:49:07499
[email protected]a5e71c92012-06-22 22:09:08500} // namespace internal
[email protected]c39be8f2012-06-15 22:58:36501} // namespace ash