blob: 8e346a7402757abbb8ca9975cab41b88b41e99a3 [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]0f81f442012-06-22 06:20:279#include "ash/wm/window_cycle_controller.h"
[email protected]c39be8f2012-06-15 22:58:3610#include "ash/wm/window_util.h"
11#include "ui/aura/client/activation_client.h"
12#include "ui/aura/client/capture_client.h"
[email protected]a5e71c92012-06-22 22:09:0813#include "ui/aura/env.h"
[email protected]c39be8f2012-06-15 22:58:3614#include "ui/aura/focus_manager.h"
15#include "ui/aura/root_window.h"
16#include "ui/aura/test/event_generator.h"
[email protected]a5e71c92012-06-22 22:09:0817#include "ui/aura/test/test_windows.h"
[email protected]c39be8f2012-06-15 22:58:3618#include "ui/aura/window.h"
19#include "ui/base/cursor/cursor.h"
[email protected]a5e71c92012-06-22 22:09:0820#include "ui/gfx/display.h"
[email protected]718b26c2012-07-24 20:53:2321#include "ui/gfx/screen.h"
[email protected]c39be8f2012-06-15 22:58:3622#include "ui/views/widget/widget.h"
23#include "ui/views/widget/widget_delegate.h"
24
25namespace ash {
26namespace {
27
[email protected]f059c6942012-07-21 14:27:5728views::Widget* CreateTestWidgetWithParent(views::Widget* parent,
29 const gfx::Rect& bounds,
30 bool child) {
[email protected]c39be8f2012-06-15 22:58:3631 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
[email protected]f059c6942012-07-21 14:27:5732 params.parent_widget = parent;
[email protected]c39be8f2012-06-15 22:58:3633 params.bounds = bounds;
[email protected]f059c6942012-07-21 14:27:5734 params.child = child;
[email protected]c39be8f2012-06-15 22:58:3635 views::Widget* widget = new views::Widget;
36 widget->Init(params);
[email protected]0f81f442012-06-22 06:20:2737 widget->Show();
[email protected]c39be8f2012-06-15 22:58:3638 return widget;
39}
40
[email protected]f059c6942012-07-21 14:27:5741views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
42 return CreateTestWidgetWithParent(NULL, bounds, false);
43}
44
[email protected]c39be8f2012-06-15 22:58:3645class ModalWidgetDelegate : public views::WidgetDelegateView {
46 public:
47 ModalWidgetDelegate() {}
48 virtual ~ModalWidgetDelegate() {}
49
50 // Overridden from views::WidgetDelegate:
51 virtual views::View* GetContentsView() OVERRIDE {
52 return this;
53 }
54 virtual ui::ModalType GetModalType() const OVERRIDE {
55 return ui::MODAL_TYPE_SYSTEM;
56 }
57
58 private:
59 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
60};
61
62} // namespace
63
64class ExtendedDesktopTest : public test::AshTestBase {
65 public:
66 ExtendedDesktopTest() {}
67 virtual ~ExtendedDesktopTest() {}
68
69 virtual void SetUp() OVERRIDE {
[email protected]2e236a52012-06-27 22:21:4770 internal::DisplayController::SetExtendedDesktopEnabled(true);
[email protected]c39be8f2012-06-15 22:58:3671 AshTestBase::SetUp();
72 }
73
74 virtual void TearDown() OVERRIDE {
75 AshTestBase::TearDown();
[email protected]2e236a52012-06-27 22:21:4776 internal::DisplayController::SetExtendedDesktopEnabled(false);
[email protected]c39be8f2012-06-15 22:58:3677 }
78
[email protected]a5e71c92012-06-22 22:09:0879 protected:
[email protected]2e236a52012-06-27 22:21:4780 internal::MultiDisplayManager* display_manager() {
81 return static_cast<internal::MultiDisplayManager*>(
82 aura::Env::GetInstance()->display_manager());
[email protected]a5e71c92012-06-22 22:09:0883 }
84
[email protected]c39be8f2012-06-15 22:58:3685 private:
86 DISALLOW_COPY_AND_ASSIGN(ExtendedDesktopTest);
87};
88
89// Test conditions that root windows in extended desktop mode
90// must satisfy.
91TEST_F(ExtendedDesktopTest, Basic) {
[email protected]f634dd32012-07-23 22:49:0792 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:3693 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
94
95 // All root windows must have the root window controller.
96 ASSERT_EQ(2U, root_windows.size());
97 for (Shell::RootWindowList::const_iterator iter = root_windows.begin();
98 iter != root_windows.end(); ++iter) {
99 EXPECT_TRUE(wm::GetRootWindowController(*iter) != NULL);
100 }
101 // Make sure root windows share the same controllers.
102 EXPECT_EQ(root_windows[0]->GetFocusManager(),
103 root_windows[1]->GetFocusManager());
104 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]),
105 aura::client::GetActivationClient(root_windows[1]));
106 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
107 aura::client::GetCaptureClient(root_windows[1]));
108}
109
110TEST_F(ExtendedDesktopTest, Activation) {
[email protected]f634dd32012-07-23 22:49:07111 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36112 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
113
[email protected]c39be8f2012-06-15 22:58:36114 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]f634dd32012-07-23 22:49:07115 views::Widget* widget_on_2nd =
116 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36117 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]f634dd32012-07-23 22:49:07118 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36119
120 EXPECT_EQ(widget_on_2nd->GetNativeView(),
121 root_windows[0]->GetFocusManager()->GetFocusedWindow());
122 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
123
[email protected]f634dd32012-07-23 22:49:07124 aura::test::EventGenerator generator_1st(root_windows[0]);
125 aura::test::EventGenerator generator_2nd(root_windows[1]);
126
127 // Clicking a window changes the active window and active root window.
[email protected]c39be8f2012-06-15 22:58:36128 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
129 generator_1st.ClickLeftButton();
130
131 EXPECT_EQ(widget_on_1st->GetNativeView(),
132 root_windows[0]->GetFocusManager()->GetFocusedWindow());
133 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]f634dd32012-07-23 22:49:07134
135 generator_2nd.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
136 generator_2nd.ClickLeftButton();
137
138 EXPECT_EQ(widget_on_2nd->GetNativeView(),
139 root_windows[0]->GetFocusManager()->GetFocusedWindow());
140 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
[email protected]c39be8f2012-06-15 22:58:36141}
142
143TEST_F(ExtendedDesktopTest, SystemModal) {
[email protected]f634dd32012-07-23 22:49:07144 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36145 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36146
147 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36148 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
149 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
150
[email protected]c39be8f2012-06-15 22:58:36151 // Open system modal. Make sure it's on 2nd root window and active.
[email protected]f634dd32012-07-23 22:49:07152 views::Widget* modal_widget = views::Widget::CreateWindowWithBounds(
153 new ModalWidgetDelegate(), gfx::Rect(1200, 100, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36154 modal_widget->Show();
155 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
156 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow());
157 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
158
[email protected]2e236a52012-06-27 22:21:47159 // Clicking a widget on widget_on_1st display should not change activation.
[email protected]c39be8f2012-06-15 22:58:36160 aura::test::EventGenerator generator_1st(root_windows[0]);
161 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
162 generator_1st.ClickLeftButton();
163 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
164 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
165
166 // Close system modal and so clicking a widget should work now.
167 modal_widget->Close();
168 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
169 generator_1st.ClickLeftButton();
170 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
171 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
172}
173
174TEST_F(ExtendedDesktopTest, TestCursor) {
[email protected]f634dd32012-07-23 22:49:07175 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36176 Shell::GetInstance()->ShowCursor(false);
177 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
178 EXPECT_FALSE(root_windows[0]->cursor_shown());
179 EXPECT_FALSE(root_windows[1]->cursor_shown());
180 Shell::GetInstance()->ShowCursor(true);
181 EXPECT_TRUE(root_windows[0]->cursor_shown());
182 EXPECT_TRUE(root_windows[1]->cursor_shown());
183
184 EXPECT_EQ(ui::kCursorPointer, root_windows[0]->last_cursor().native_type());
185 EXPECT_EQ(ui::kCursorPointer, root_windows[1]->last_cursor().native_type());
186 Shell::GetInstance()->SetCursor(ui::kCursorCopy);
187 EXPECT_EQ(ui::kCursorCopy, root_windows[0]->last_cursor().native_type());
188 EXPECT_EQ(ui::kCursorCopy, root_windows[1]->last_cursor().native_type());
189}
190
[email protected]718b26c2012-07-24 20:53:23191TEST_F(ExtendedDesktopTest, TestCursorLocation) {
192 UpdateDisplay("0+0-1000x600,1001+0-600x400");
193 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
194 aura::Window::TestApi root_window0_test_api(root_windows[0]);
195 aura::Window::TestApi root_window1_test_api(root_windows[1]);
196
197 root_windows[0]->MoveCursorTo(gfx::Point(10, 10));
198 EXPECT_EQ("10,10", gfx::Screen::GetCursorScreenPoint().ToString());
199 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
200 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
201 root_windows[1]->MoveCursorTo(gfx::Point(10, 20));
202 EXPECT_EQ("1010,20", gfx::Screen::GetCursorScreenPoint().ToString());
203 EXPECT_FALSE(root_window0_test_api.ContainsMouse());
204 EXPECT_TRUE(root_window1_test_api.ContainsMouse());
205 root_windows[0]->MoveCursorTo(gfx::Point(20, 10));
206 EXPECT_EQ("20,10", gfx::Screen::GetCursorScreenPoint().ToString());
207 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
208 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
209}
210
[email protected]0f81f442012-06-22 06:20:27211TEST_F(ExtendedDesktopTest, CycleWindows) {
[email protected]f634dd32012-07-23 22:49:07212 UpdateDisplay("700x500,500x500");
[email protected]0f81f442012-06-22 06:20:27213 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24214
[email protected]0f81f442012-06-22 06:20:27215 WindowCycleController* controller =
216 Shell::GetInstance()->window_cycle_controller();
217
[email protected]0f81f442012-06-22 06:20:27218 views::Widget* d1_w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
219 EXPECT_EQ(root_windows[0], d1_w1->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24220 views::Widget* d2_w1 = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
[email protected]0f81f442012-06-22 06:20:27221 EXPECT_EQ(root_windows[1], d2_w1->GetNativeView()->GetRootWindow());
222 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
223
224 controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
225 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
226 controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
227 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
228 controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
229 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
230 controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
231 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
232
233 // Cycle through all windows across root windows.
[email protected]20c59762012-06-23 01:10:24234 views::Widget* d1_w2 = CreateTestWidget(gfx::Rect(10, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27235 EXPECT_EQ(root_windows[0], d1_w2->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24236 views::Widget* d2_w2 = CreateTestWidget(gfx::Rect(800, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27237 EXPECT_EQ(root_windows[1], d2_w2->GetNativeView()->GetRootWindow());
238
239 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
240 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
241 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
242 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
243 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
244 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
245 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
246 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
247
248 // Backwards
249 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
250 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
251 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
252 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
253 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
254 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
255 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
256 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
[email protected]20c59762012-06-23 01:10:24257}
258
259TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
[email protected]f634dd32012-07-23 22:49:07260 UpdateDisplay("700x500,500x500");
[email protected]66b05eac2012-06-27 23:53:10261 Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout(
262 internal::DisplayController::LEFT);
[email protected]20c59762012-06-23 01:10:24263 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24264
[email protected]66b05eac2012-06-27 23:53:10265 EXPECT_EQ(root_windows[1], Shell::GetRootWindowAt(gfx::Point(-400, 100)));
266 EXPECT_EQ(root_windows[1], Shell::GetRootWindowAt(gfx::Point(-1, 100)));
267 EXPECT_EQ(root_windows[0], Shell::GetRootWindowAt(gfx::Point(0, 300)));
268 EXPECT_EQ(root_windows[0], Shell::GetRootWindowAt(gfx::Point(700,300)));
[email protected]20c59762012-06-23 01:10:24269
270 // Zero origin.
[email protected]66b05eac2012-06-27 23:53:10271 EXPECT_EQ(root_windows[0], Shell::GetRootWindowAt(gfx::Point(0, 0)));
[email protected]20c59762012-06-23 01:10:24272
273 // Out of range point should return the primary root window
[email protected]66b05eac2012-06-27 23:53:10274 EXPECT_EQ(root_windows[0], Shell::GetRootWindowAt(gfx::Point(-600, 0)));
275 EXPECT_EQ(root_windows[0], Shell::GetRootWindowAt(gfx::Point(701, 100)));
[email protected]20c59762012-06-23 01:10:24276}
277
278TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
[email protected]f634dd32012-07-23 22:49:07279 UpdateDisplay("700x500,500x500");
[email protected]66b05eac2012-06-27 23:53:10280 Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout(
281 internal::DisplayController::LEFT);
282
[email protected]20c59762012-06-23 01:10:24283 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24284
285 // Containing rect.
286 EXPECT_EQ(root_windows[1],
[email protected]66b05eac2012-06-27 23:53:10287 Shell::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24288 EXPECT_EQ(root_windows[0],
[email protected]66b05eac2012-06-27 23:53:10289 Shell::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24290
291 // Intersecting rect.
292 EXPECT_EQ(root_windows[1],
[email protected]66b05eac2012-06-27 23:53:10293 Shell::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24294 EXPECT_EQ(root_windows[0],
[email protected]66b05eac2012-06-27 23:53:10295 Shell::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24296
297 // Zero origin.
[email protected]66b05eac2012-06-27 23:53:10298 EXPECT_EQ(root_windows[0],
[email protected]20c59762012-06-23 01:10:24299 Shell::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0)));
[email protected]66b05eac2012-06-27 23:53:10300 EXPECT_EQ(root_windows[0],
[email protected]20c59762012-06-23 01:10:24301 Shell::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1)));
302
303 // Empty rect.
304 EXPECT_EQ(root_windows[1],
[email protected]66b05eac2012-06-27 23:53:10305 Shell::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24306 EXPECT_EQ(root_windows[0],
[email protected]66b05eac2012-06-27 23:53:10307 Shell::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24308
309 // Out of range rect should return the primary root window.
310 EXPECT_EQ(root_windows[0],
[email protected]66b05eac2012-06-27 23:53:10311 Shell::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50)));
[email protected]20c59762012-06-23 01:10:24312 EXPECT_EQ(root_windows[0],
[email protected]66b05eac2012-06-27 23:53:10313 Shell::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50)));
[email protected]0f81f442012-06-22 06:20:27314}
315
[email protected]a5e71c92012-06-22 22:09:08316TEST_F(ExtendedDesktopTest, Capture) {
[email protected]f634dd32012-07-23 22:49:07317 UpdateDisplay("1000x600,600x400");
[email protected]a5e71c92012-06-22 22:09:08318 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
319
320 aura::test::EventCountDelegate r1_d1;
321 aura::test::EventCountDelegate r1_d2;
322 aura::test::EventCountDelegate r2_d1;
323
324 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
325 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
326 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
327 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
328 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
329 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
[email protected]f634dd32012-07-23 22:49:07330
[email protected]a5e71c92012-06-22 22:09:08331 r1_w1->SetCapture();
332
333 EXPECT_EQ(r1_w1.get(),
334 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
335 aura::test::EventGenerator generator2(root_windows[1]);
336 generator2.MoveMouseToCenterOf(r2_w1.get());
337 generator2.ClickLeftButton();
338 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
339 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]f634dd32012-07-23 22:49:07340 // The mouse is outside, so no move event will be sent.
341 EXPECT_EQ("1 0 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08342 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
[email protected]f634dd32012-07-23 22:49:07343 // (15,15) on 1st display is (-985,15) on 2nd display.
344 generator2.MoveMouseTo(-985, 15);
345 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08346
347 r1_w2->SetCapture();
348 EXPECT_EQ(r1_w2.get(),
349 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
350 generator2.MoveMouseBy(10, 10);
351 generator2.ClickLeftButton();
352 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
353 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
354 // mouse is already entered.
355 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset());
356 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset());
357
358 r1_w2->ReleaseCapture();
359 EXPECT_EQ(NULL,
360 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]f634dd32012-07-23 22:49:07361 generator2.MoveMouseTo(15, 15);
[email protected]a5e71c92012-06-22 22:09:08362 generator2.ClickLeftButton();
363 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
364 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
365 // Make sure the mouse_moved_handler_ is properly reset.
366 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
367 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
368}
369
[email protected]f059c6942012-07-21 14:27:57370TEST_F(ExtendedDesktopTest, MoveWindow) {
[email protected]f634dd32012-07-23 22:49:07371 UpdateDisplay("1000x600,600x400");
[email protected]f059c6942012-07-21 14:27:57372 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
373 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
374
375 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
376
377 d1->SetBounds(gfx::Rect(1010, 10, 100, 100));
378 EXPECT_EQ("1010,10 100x100",
379 d1->GetWindowBoundsInScreen().ToString());
380
381 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
382
383 d1->SetBounds(gfx::Rect(10, 10, 100, 100));
384 EXPECT_EQ("10,10 100x100",
385 d1->GetWindowBoundsInScreen().ToString());
386
387 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
388
389 // Make sure the bounds which doesn't fit to the root window
390 // works correctly.
391 d1->SetBounds(gfx::Rect(1560, 30, 100, 100));
392 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
393 EXPECT_EQ("1560,30 100x100",
394 d1->GetWindowBoundsInScreen().ToString());
395
396 // Setting outside of root windows will be moved to primary root window.
397 // TODO(oshima): This one probably should pick the closest root window.
398 d1->SetBounds(gfx::Rect(200, 10, 100, 100));
399 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
[email protected]f059c6942012-07-21 14:27:57400}
401
402TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
[email protected]f634dd32012-07-23 22:49:07403 UpdateDisplay("1000x600,600x400");
[email protected]f059c6942012-07-21 14:27:57404 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
405 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
406 views::Widget* w1_t1 = CreateTestWidgetWithParent(
407 w1, gfx::Rect(50, 50, 50, 50), false /* transient */);
408 // Transient child of the transient child.
409 views::Widget* w1_t11 = CreateTestWidgetWithParent(
410 w1_t1, gfx::Rect(1200, 70, 30, 30), false /* transient */);
411
412 views::Widget* w11 = CreateTestWidgetWithParent(
413 w1, gfx::Rect(10, 10, 40, 40), true /* child */);
414 views::Widget* w11_t1 = CreateTestWidgetWithParent(
415 w1, gfx::Rect(1300, 100, 80, 80), false /* transient */);
416
417 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
418 EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow());
419 EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow());
420 EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow());
421 EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow());
422 EXPECT_EQ("50,50 50x50",
423 w1_t1->GetWindowBoundsInScreen().ToString());
424 EXPECT_EQ("1200,70 30x30",
425 w1_t11->GetWindowBoundsInScreen().ToString());
426 EXPECT_EQ("20,20 40x40",
427 w11->GetWindowBoundsInScreen().ToString());
428 EXPECT_EQ("1300,100 80x80",
429 w11_t1->GetWindowBoundsInScreen().ToString());
430
431 w1->SetBounds(gfx::Rect(1100,10,100,100));
432
433 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
434 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
435 EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow());
436 EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow());
437 EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow());
438
439 EXPECT_EQ("1110,20 40x40",
440 w11->GetWindowBoundsInScreen().ToString());
441 // Transient window's screen bounds stays the same.
442 EXPECT_EQ("50,50 50x50",
443 w1_t1->GetWindowBoundsInScreen().ToString());
444 EXPECT_EQ("1200,70 30x30",
445 w1_t11->GetWindowBoundsInScreen().ToString());
446 EXPECT_EQ("1300,100 80x80",
447 w11_t1->GetWindowBoundsInScreen().ToString());
448
449 // Transient window doesn't move between root window unless
450 // its transient parent moves.
451 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50));
452 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
453 EXPECT_EQ("10,50 50x50",
454 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57455}
456
[email protected]a5e71c92012-06-22 22:09:08457namespace internal {
458// Test if the Window::ConvertPointToWindow works across root windows.
459// TODO(oshima): Move multiple display suport and this test to aura.
460TEST_F(ExtendedDesktopTest, ConvertPoint) {
[email protected]f634dd32012-07-23 22:49:07461 UpdateDisplay("1000x600,600x400");
[email protected]a5e71c92012-06-22 22:09:08462 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
463 gfx::Display& display_1 =
[email protected]2e236a52012-06-27 22:21:47464 display_manager()->FindDisplayForRootWindow(root_windows[0]);
[email protected]a5e71c92012-06-22 22:09:08465 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
466 gfx::Display& display_2 =
[email protected]2e236a52012-06-27 22:21:47467 display_manager()->FindDisplayForRootWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07468 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
469
[email protected]a5e71c92012-06-22 22:09:08470 aura::Window* d1 =
471 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
[email protected]a5e71c92012-06-22 22:09:08472 aura::Window* d2 =
[email protected]f634dd32012-07-23 22:49:07473 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
474 EXPECT_EQ(root_windows[0], d1->GetRootWindow());
475 EXPECT_EQ(root_windows[1], d2->GetRootWindow());
[email protected]a5e71c92012-06-22 22:09:08476
[email protected]a5e71c92012-06-22 22:09:08477 // Convert point in the Root2's window to the Root1's window Coord.
478 gfx::Point p(0, 0);
479 aura::Window::ConvertPointToWindow(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07480 EXPECT_EQ("1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08481 p.SetPoint(0, 0);
482 aura::Window::ConvertPointToWindow(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07483 EXPECT_EQ("1010,10", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08484
485 // Convert point in the Root1's window to the Root2's window Coord.
486 p.SetPoint(0, 0);
487 aura::Window::ConvertPointToWindow(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07488 EXPECT_EQ("-1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08489 p.SetPoint(0, 0);
490 aura::Window::ConvertPointToWindow(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07491 EXPECT_EQ("-1010,-10", p.ToString());
492
493 // Move the 2nd display to the bottom and test again.
494 Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout(
495 internal::DisplayController::BOTTOM);
496
497 display_2 = display_manager()->FindDisplayForRootWindow(root_windows[1]);
498 EXPECT_EQ("0,600", display_2.bounds().origin().ToString());
499
500 // Convert point in Root2's window to Root1's window Coord.
501 p.SetPoint(0, 0);
502 aura::Window::ConvertPointToWindow(root_windows[1], root_windows[0], &p);
503 EXPECT_EQ("0,600", p.ToString());
504 p.SetPoint(0, 0);
505 aura::Window::ConvertPointToWindow(d2, d1, &p);
506 EXPECT_EQ("10,610", p.ToString());
507
508 // Convert point in Root1's window to Root2's window Coord.
509 p.SetPoint(0, 0);
510 aura::Window::ConvertPointToWindow(root_windows[0], root_windows[1], &p);
511 EXPECT_EQ("0,-600", p.ToString());
512 p.SetPoint(0, 0);
513 aura::Window::ConvertPointToWindow(d1, d2, &p);
514 EXPECT_EQ("-10,-610", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08515}
[email protected]f634dd32012-07-23 22:49:07516
[email protected]a5e71c92012-06-22 22:09:08517} // namespace internal
[email protected]c39be8f2012-06-15 22:58:36518} // namespace ash