blob: 04439ab7cd71fff90fe3a121ad700847d2880313 [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"
[email protected]263898a2012-09-17 17:20:078#include "ash/system/tray/system_tray.h"
[email protected]c39be8f2012-06-15 22:58:369#include "ash/test/ash_test_base.h"
[email protected]7203a5e2012-08-06 18:27:4610#include "ash/wm/coordinate_conversion.h"
[email protected]7ae525002012-07-26 23:55:1011#include "ash/wm/property_util.h"
[email protected]0f81f442012-06-22 06:20:2712#include "ash/wm/window_cycle_controller.h"
[email protected]578048512012-09-19 20:01:2413#include "ash/wm/window_properties.h"
[email protected]c39be8f2012-06-15 22:58:3614#include "ash/wm/window_util.h"
15#include "ui/aura/client/activation_client.h"
16#include "ui/aura/client/capture_client.h"
[email protected]a5e71c92012-06-22 22:09:0817#include "ui/aura/env.h"
[email protected]c39be8f2012-06-15 22:58:3618#include "ui/aura/focus_manager.h"
19#include "ui/aura/root_window.h"
20#include "ui/aura/test/event_generator.h"
[email protected]a5e71c92012-06-22 22:09:0821#include "ui/aura/test/test_windows.h"
[email protected]c39be8f2012-06-15 22:58:3622#include "ui/aura/window.h"
23#include "ui/base/cursor/cursor.h"
[email protected]a5e71c92012-06-22 22:09:0824#include "ui/gfx/display.h"
[email protected]718b26c2012-07-24 20:53:2325#include "ui/gfx/screen.h"
[email protected]c39be8f2012-06-15 22:58:3626#include "ui/views/widget/widget.h"
27#include "ui/views/widget/widget_delegate.h"
28
29namespace ash {
30namespace {
31
[email protected]f059c6942012-07-21 14:27:5732views::Widget* CreateTestWidgetWithParent(views::Widget* parent,
33 const gfx::Rect& bounds,
34 bool child) {
[email protected]c39be8f2012-06-15 22:58:3635 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
[email protected]f059c6942012-07-21 14:27:5736 params.parent_widget = parent;
[email protected]c39be8f2012-06-15 22:58:3637 params.bounds = bounds;
[email protected]f059c6942012-07-21 14:27:5738 params.child = child;
[email protected]c39be8f2012-06-15 22:58:3639 views::Widget* widget = new views::Widget;
40 widget->Init(params);
[email protected]0f81f442012-06-22 06:20:2741 widget->Show();
[email protected]c39be8f2012-06-15 22:58:3642 return widget;
43}
44
[email protected]f059c6942012-07-21 14:27:5745views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
46 return CreateTestWidgetWithParent(NULL, bounds, false);
47}
48
[email protected]edbfb8d2012-09-03 08:33:4349void SetSecondaryDisplayLayout(DisplayLayout::Position position) {
50 DisplayController* display_controller =
51 Shell::GetInstance()->display_controller();
52 DisplayLayout layout = display_controller->default_display_layout();
53 layout.position = position;
54 display_controller->SetDefaultDisplayLayout(layout);
55}
56
[email protected]c39be8f2012-06-15 22:58:3657class ModalWidgetDelegate : public views::WidgetDelegateView {
58 public:
59 ModalWidgetDelegate() {}
60 virtual ~ModalWidgetDelegate() {}
61
62 // Overridden from views::WidgetDelegate:
63 virtual views::View* GetContentsView() OVERRIDE {
64 return this;
65 }
66 virtual ui::ModalType GetModalType() const OVERRIDE {
67 return ui::MODAL_TYPE_SYSTEM;
68 }
69
70 private:
71 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
72};
73
[email protected]3e4351b2012-08-09 04:04:1674internal::MultiDisplayManager* GetDisplayManager() {
75 return static_cast<internal::MultiDisplayManager*>(
76 aura::Env::GetInstance()->display_manager());
77}
78
[email protected]c39be8f2012-06-15 22:58:3679} // namespace
80
[email protected]3e4351b2012-08-09 04:04:1681typedef test::AshTestBase ExtendedDesktopTest;
[email protected]c39be8f2012-06-15 22:58:3682
83// Test conditions that root windows in extended desktop mode
84// must satisfy.
85TEST_F(ExtendedDesktopTest, Basic) {
[email protected]f634dd32012-07-23 22:49:0786 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:3687 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
88
89 // All root windows must have the root window controller.
90 ASSERT_EQ(2U, root_windows.size());
91 for (Shell::RootWindowList::const_iterator iter = root_windows.begin();
92 iter != root_windows.end(); ++iter) {
[email protected]7ae525002012-07-26 23:55:1093 EXPECT_TRUE(GetRootWindowController(*iter) != NULL);
[email protected]c39be8f2012-06-15 22:58:3694 }
95 // Make sure root windows share the same controllers.
96 EXPECT_EQ(root_windows[0]->GetFocusManager(),
97 root_windows[1]->GetFocusManager());
98 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]),
99 aura::client::GetActivationClient(root_windows[1]));
100 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
101 aura::client::GetCaptureClient(root_windows[1]));
102}
103
104TEST_F(ExtendedDesktopTest, Activation) {
[email protected]f634dd32012-07-23 22:49:07105 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36106 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
107
[email protected]c39be8f2012-06-15 22:58:36108 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]f634dd32012-07-23 22:49:07109 views::Widget* widget_on_2nd =
110 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36111 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]f634dd32012-07-23 22:49:07112 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36113
114 EXPECT_EQ(widget_on_2nd->GetNativeView(),
115 root_windows[0]->GetFocusManager()->GetFocusedWindow());
116 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
117
[email protected]f634dd32012-07-23 22:49:07118 aura::test::EventGenerator generator_1st(root_windows[0]);
119 aura::test::EventGenerator generator_2nd(root_windows[1]);
120
121 // Clicking a window changes the active window and active root window.
[email protected]c39be8f2012-06-15 22:58:36122 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
123 generator_1st.ClickLeftButton();
124
125 EXPECT_EQ(widget_on_1st->GetNativeView(),
126 root_windows[0]->GetFocusManager()->GetFocusedWindow());
127 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]f634dd32012-07-23 22:49:07128
129 generator_2nd.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
130 generator_2nd.ClickLeftButton();
131
132 EXPECT_EQ(widget_on_2nd->GetNativeView(),
133 root_windows[0]->GetFocusManager()->GetFocusedWindow());
134 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
[email protected]c39be8f2012-06-15 22:58:36135}
136
137TEST_F(ExtendedDesktopTest, SystemModal) {
[email protected]f634dd32012-07-23 22:49:07138 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36139 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36140
141 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36142 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
143 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
144
[email protected]c39be8f2012-06-15 22:58:36145 // Open system modal. Make sure it's on 2nd root window and active.
[email protected]f634dd32012-07-23 22:49:07146 views::Widget* modal_widget = views::Widget::CreateWindowWithBounds(
147 new ModalWidgetDelegate(), gfx::Rect(1200, 100, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36148 modal_widget->Show();
149 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
150 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow());
151 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
152
[email protected]2e236a52012-06-27 22:21:47153 // Clicking a widget on widget_on_1st display should not change activation.
[email protected]c39be8f2012-06-15 22:58:36154 aura::test::EventGenerator generator_1st(root_windows[0]);
155 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
156 generator_1st.ClickLeftButton();
157 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
158 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
159
160 // Close system modal and so clicking a widget should work now.
161 modal_widget->Close();
162 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
163 generator_1st.ClickLeftButton();
164 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
165 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
166}
167
168TEST_F(ExtendedDesktopTest, TestCursor) {
[email protected]f634dd32012-07-23 22:49:07169 UpdateDisplay("1000x600,600x400");
[email protected]151ffdff2012-09-11 20:18:35170 Shell::GetInstance()->cursor_manager()->ShowCursor(false);
[email protected]c39be8f2012-06-15 22:58:36171 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
172 EXPECT_FALSE(root_windows[0]->cursor_shown());
173 EXPECT_FALSE(root_windows[1]->cursor_shown());
[email protected]151ffdff2012-09-11 20:18:35174 Shell::GetInstance()->cursor_manager()->ShowCursor(true);
[email protected]c39be8f2012-06-15 22:58:36175 EXPECT_TRUE(root_windows[0]->cursor_shown());
176 EXPECT_TRUE(root_windows[1]->cursor_shown());
177
178 EXPECT_EQ(ui::kCursorPointer, root_windows[0]->last_cursor().native_type());
179 EXPECT_EQ(ui::kCursorPointer, root_windows[1]->last_cursor().native_type());
[email protected]151ffdff2012-09-11 20:18:35180 Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy);
[email protected]c39be8f2012-06-15 22:58:36181 EXPECT_EQ(ui::kCursorCopy, root_windows[0]->last_cursor().native_type());
182 EXPECT_EQ(ui::kCursorCopy, root_windows[1]->last_cursor().native_type());
183}
184
[email protected]718b26c2012-07-24 20:53:23185TEST_F(ExtendedDesktopTest, TestCursorLocation) {
186 UpdateDisplay("0+0-1000x600,1001+0-600x400");
187 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
188 aura::Window::TestApi root_window0_test_api(root_windows[0]);
189 aura::Window::TestApi root_window1_test_api(root_windows[1]);
190
191 root_windows[0]->MoveCursorTo(gfx::Point(10, 10));
192 EXPECT_EQ("10,10", gfx::Screen::GetCursorScreenPoint().ToString());
193 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
194 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
195 root_windows[1]->MoveCursorTo(gfx::Point(10, 20));
196 EXPECT_EQ("1010,20", gfx::Screen::GetCursorScreenPoint().ToString());
197 EXPECT_FALSE(root_window0_test_api.ContainsMouse());
198 EXPECT_TRUE(root_window1_test_api.ContainsMouse());
199 root_windows[0]->MoveCursorTo(gfx::Point(20, 10));
200 EXPECT_EQ("20,10", gfx::Screen::GetCursorScreenPoint().ToString());
201 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
202 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
203}
204
[email protected]0f81f442012-06-22 06:20:27205TEST_F(ExtendedDesktopTest, CycleWindows) {
[email protected]f634dd32012-07-23 22:49:07206 UpdateDisplay("700x500,500x500");
[email protected]0f81f442012-06-22 06:20:27207 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24208
[email protected]0f81f442012-06-22 06:20:27209 WindowCycleController* controller =
210 Shell::GetInstance()->window_cycle_controller();
211
[email protected]0f81f442012-06-22 06:20:27212 views::Widget* d1_w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
213 EXPECT_EQ(root_windows[0], d1_w1->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24214 views::Widget* d2_w1 = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
[email protected]0f81f442012-06-22 06:20:27215 EXPECT_EQ(root_windows[1], d2_w1->GetNativeView()->GetRootWindow());
216 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
217
218 controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
219 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
220 controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
221 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
222 controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
223 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
224 controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
225 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
226
227 // Cycle through all windows across root windows.
[email protected]20c59762012-06-23 01:10:24228 views::Widget* d1_w2 = CreateTestWidget(gfx::Rect(10, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27229 EXPECT_EQ(root_windows[0], d1_w2->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24230 views::Widget* d2_w2 = CreateTestWidget(gfx::Rect(800, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27231 EXPECT_EQ(root_windows[1], d2_w2->GetNativeView()->GetRootWindow());
232
233 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]0f81f442012-06-22 06:20:27234 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
235 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]8fef7432012-08-06 15:34:25236 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
237 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]0f81f442012-06-22 06:20:27238 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
239 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
240 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
241
242 // Backwards
243 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
244 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
245 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]0f81f442012-06-22 06:20:27246 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
247 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]8fef7432012-08-06 15:34:25248 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
249 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]0f81f442012-06-22 06:20:27250 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
[email protected]20c59762012-06-23 01:10:24251}
252
253TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
[email protected]f634dd32012-07-23 22:49:07254 UpdateDisplay("700x500,500x500");
[email protected]edbfb8d2012-09-03 08:33:43255 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]20c59762012-06-23 01:10:24256 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24257
[email protected]7203a5e2012-08-06 18:27:46258 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100)));
259 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100)));
260 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300)));
261 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700,300)));
[email protected]20c59762012-06-23 01:10:24262
263 // Zero origin.
[email protected]7203a5e2012-08-06 18:27:46264 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0)));
[email protected]20c59762012-06-23 01:10:24265
266 // Out of range point should return the primary root window
[email protected]7203a5e2012-08-06 18:27:46267 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(-600, 0)));
268 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100)));
[email protected]20c59762012-06-23 01:10:24269}
270
271TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
[email protected]f634dd32012-07-23 22:49:07272 UpdateDisplay("700x500,500x500");
[email protected]edbfb8d2012-09-03 08:33:43273 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]66b05eac2012-06-27 23:53:10274
[email protected]20c59762012-06-23 01:10:24275 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24276
277 // Containing rect.
278 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46279 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24280 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46281 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24282
283 // Intersecting rect.
284 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46285 wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24286 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46287 wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24288
289 // Zero origin.
[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, 0, 0)));
[email protected]66b05eac2012-06-27 23:53:10292 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46293 wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1)));
[email protected]20c59762012-06-23 01:10:24294
295 // Empty rect.
296 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46297 wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24298 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46299 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24300
301 // Out of range rect should return the primary root window.
302 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46303 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50)));
[email protected]20c59762012-06-23 01:10:24304 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46305 wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50)));
[email protected]0f81f442012-06-22 06:20:27306}
307
[email protected]7f502eb2012-09-20 09:17:12308#if defined(OS_WIN)
309// TODO(mazda): Re-enable this (http://crbug.com/150986).
310#define MAYBE_Capture DISABLED_Capture
311#else
312#define MAYBE_Capture Capture
313#endif
314
315TEST_F(ExtendedDesktopTest, MAYBE_Capture) {
[email protected]f634dd32012-07-23 22:49:07316 UpdateDisplay("1000x600,600x400");
[email protected]a5e71c92012-06-22 22:09:08317 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
318
319 aura::test::EventCountDelegate r1_d1;
320 aura::test::EventCountDelegate r1_d2;
321 aura::test::EventCountDelegate r2_d1;
322
323 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
324 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
325 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
326 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
327 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
328 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
[email protected]f634dd32012-07-23 22:49:07329
[email protected]a5e71c92012-06-22 22:09:08330 r1_w1->SetCapture();
331
332 EXPECT_EQ(r1_w1.get(),
333 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
334 aura::test::EventGenerator generator2(root_windows[1]);
335 generator2.MoveMouseToCenterOf(r2_w1.get());
336 generator2.ClickLeftButton();
337 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
338 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]b19ba4adf2012-09-07 16:13:29339 // The mouse is outside. On chromeos, the mouse is warped to the
340 // dest root window, but it's not implemented on Win yet, so
341 // no mouse move event on Win.
342#if defined(OS_WIN)
343 EXPECT_EQ("1 0 0", r1_d1.GetMouseMotionCountsAndReset());
344#else
[email protected]7495e5032012-09-07 15:31:45345 EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]b19ba4adf2012-09-07 16:13:29346#endif
[email protected]a5e71c92012-06-22 22:09:08347 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
[email protected]f634dd32012-07-23 22:49:07348 // (15,15) on 1st display is (-985,15) on 2nd display.
349 generator2.MoveMouseTo(-985, 15);
350 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08351
352 r1_w2->SetCapture();
353 EXPECT_EQ(r1_w2.get(),
354 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
355 generator2.MoveMouseBy(10, 10);
356 generator2.ClickLeftButton();
357 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
358 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
359 // mouse is already entered.
360 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset());
361 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset());
362
363 r1_w2->ReleaseCapture();
[email protected]36f566532012-09-19 04:07:24364 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]f634dd32012-07-23 22:49:07365 generator2.MoveMouseTo(15, 15);
[email protected]a5e71c92012-06-22 22:09:08366 generator2.ClickLeftButton();
367 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
368 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
369 // Make sure the mouse_moved_handler_ is properly reset.
370 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
371 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
372}
373
[email protected]f059c6942012-07-21 14:27:57374TEST_F(ExtendedDesktopTest, MoveWindow) {
[email protected]f634dd32012-07-23 22:49:07375 UpdateDisplay("1000x600,600x400");
[email protected]f059c6942012-07-21 14:27:57376 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
377 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
378
379 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
380
381 d1->SetBounds(gfx::Rect(1010, 10, 100, 100));
382 EXPECT_EQ("1010,10 100x100",
383 d1->GetWindowBoundsInScreen().ToString());
384
385 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
386
387 d1->SetBounds(gfx::Rect(10, 10, 100, 100));
388 EXPECT_EQ("10,10 100x100",
389 d1->GetWindowBoundsInScreen().ToString());
390
391 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
392
393 // Make sure the bounds which doesn't fit to the root window
394 // works correctly.
395 d1->SetBounds(gfx::Rect(1560, 30, 100, 100));
396 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
397 EXPECT_EQ("1560,30 100x100",
398 d1->GetWindowBoundsInScreen().ToString());
399
400 // Setting outside of root windows will be moved to primary root window.
401 // TODO(oshima): This one probably should pick the closest root window.
402 d1->SetBounds(gfx::Rect(200, 10, 100, 100));
403 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
[email protected]f059c6942012-07-21 14:27:57404}
405
[email protected]e79f26e2012-08-09 07:12:48406TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) {
407 UpdateDisplay("1000x1000,1000x1000");
408 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
409
410 gfx::Display display0 =
411 gfx::Screen::GetDisplayMatching(root_windows[0]->GetBoundsInScreen());
412 gfx::Display display1 =
413 gfx::Screen::GetDisplayMatching(root_windows[1]->GetBoundsInScreen());
414 EXPECT_NE(display0.id(), display1.id());
415
416 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100));
417 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
418
419 // Move the window where the window spans both root windows. Since the second
420 // parameter is |display1|, the window should be shown on the secondary root.
421 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
422 display1);
423 EXPECT_EQ("500,10 1000x100",
424 d1->GetWindowBoundsInScreen().ToString());
425 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
426
427 // Move to the primary root.
428 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
429 display0);
430 EXPECT_EQ("500,10 1000x100",
431 d1->GetWindowBoundsInScreen().ToString());
432 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
433}
434
[email protected]f059c6942012-07-21 14:27:57435TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
[email protected]f634dd32012-07-23 22:49:07436 UpdateDisplay("1000x600,600x400");
[email protected]f059c6942012-07-21 14:27:57437 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
438 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
439 views::Widget* w1_t1 = CreateTestWidgetWithParent(
440 w1, gfx::Rect(50, 50, 50, 50), false /* transient */);
441 // Transient child of the transient child.
442 views::Widget* w1_t11 = CreateTestWidgetWithParent(
443 w1_t1, gfx::Rect(1200, 70, 30, 30), false /* transient */);
444
445 views::Widget* w11 = CreateTestWidgetWithParent(
446 w1, gfx::Rect(10, 10, 40, 40), true /* child */);
447 views::Widget* w11_t1 = CreateTestWidgetWithParent(
448 w1, gfx::Rect(1300, 100, 80, 80), false /* transient */);
449
450 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
451 EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow());
452 EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow());
453 EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow());
454 EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow());
455 EXPECT_EQ("50,50 50x50",
456 w1_t1->GetWindowBoundsInScreen().ToString());
457 EXPECT_EQ("1200,70 30x30",
458 w1_t11->GetWindowBoundsInScreen().ToString());
459 EXPECT_EQ("20,20 40x40",
460 w11->GetWindowBoundsInScreen().ToString());
461 EXPECT_EQ("1300,100 80x80",
462 w11_t1->GetWindowBoundsInScreen().ToString());
463
464 w1->SetBounds(gfx::Rect(1100,10,100,100));
465
466 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
467 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
468 EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow());
469 EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow());
470 EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow());
471
472 EXPECT_EQ("1110,20 40x40",
473 w11->GetWindowBoundsInScreen().ToString());
474 // Transient window's screen bounds stays the same.
475 EXPECT_EQ("50,50 50x50",
476 w1_t1->GetWindowBoundsInScreen().ToString());
477 EXPECT_EQ("1200,70 30x30",
478 w1_t11->GetWindowBoundsInScreen().ToString());
479 EXPECT_EQ("1300,100 80x80",
480 w11_t1->GetWindowBoundsInScreen().ToString());
481
482 // Transient window doesn't move between root window unless
483 // its transient parent moves.
484 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50));
485 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
486 EXPECT_EQ("10,50 50x50",
487 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57488}
489
[email protected]a5e71c92012-06-22 22:09:08490namespace internal {
[email protected]ca7060982012-08-08 18:05:25491// Test if the Window::ConvertPointToTarget works across root windows.
[email protected]a5e71c92012-06-22 22:09:08492// TODO(oshima): Move multiple display suport and this test to aura.
493TEST_F(ExtendedDesktopTest, ConvertPoint) {
[email protected]f634dd32012-07-23 22:49:07494 UpdateDisplay("1000x600,600x400");
[email protected]a5e71c92012-06-22 22:09:08495 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
496 gfx::Display& display_1 =
[email protected]3e4351b2012-08-09 04:04:16497 GetDisplayManager()->FindDisplayForRootWindow(root_windows[0]);
[email protected]a5e71c92012-06-22 22:09:08498 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
499 gfx::Display& display_2 =
[email protected]3e4351b2012-08-09 04:04:16500 GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07501 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
502
[email protected]a5e71c92012-06-22 22:09:08503 aura::Window* d1 =
504 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
[email protected]a5e71c92012-06-22 22:09:08505 aura::Window* d2 =
[email protected]f634dd32012-07-23 22:49:07506 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
507 EXPECT_EQ(root_windows[0], d1->GetRootWindow());
508 EXPECT_EQ(root_windows[1], d2->GetRootWindow());
[email protected]a5e71c92012-06-22 22:09:08509
[email protected]a5e71c92012-06-22 22:09:08510 // Convert point in the Root2's window to the Root1's window Coord.
511 gfx::Point p(0, 0);
[email protected]ca7060982012-08-08 18:05:25512 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &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(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07516 EXPECT_EQ("1010,10", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08517
518 // Convert point in the Root1's window to the Root2's window Coord.
519 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25520 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07521 EXPECT_EQ("-1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08522 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25523 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07524 EXPECT_EQ("-1010,-10", p.ToString());
525
526 // Move the 2nd display to the bottom and test again.
[email protected]edbfb8d2012-09-03 08:33:43527 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
[email protected]f634dd32012-07-23 22:49:07528
[email protected]3e4351b2012-08-09 04:04:16529 display_2 = GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07530 EXPECT_EQ("0,600", display_2.bounds().origin().ToString());
531
532 // Convert point in Root2's window to Root1's window Coord.
533 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25534 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &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(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07538 EXPECT_EQ("10,610", p.ToString());
539
540 // Convert point in Root1's window to Root2's window Coord.
541 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25542 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07543 EXPECT_EQ("0,-600", p.ToString());
544 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25545 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07546 EXPECT_EQ("-10,-610", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08547}
[email protected]f634dd32012-07-23 22:49:07548
[email protected]263898a2012-09-17 17:20:07549TEST_F(ExtendedDesktopTest, OpenSystemTray) {
550 UpdateDisplay("1000x600,600x400");
551 SystemTray* tray = ash::Shell::GetInstance()->system_tray();
552 ASSERT_FALSE(tray->HasSystemBubble());
553
554 // Opens the tray by a dummy click event and makes sure that adding/removing
555 // displays doesn't break anything.
556 aura::test::EventGenerator event_generator(
557 ash::Shell::GetInstance()->GetPrimaryRootWindow(),
558 tray->GetWidget()->GetNativeWindow());
559 event_generator.ClickLeftButton();
560 EXPECT_TRUE(tray->HasSystemBubble());
561
562 UpdateDisplay("100x600");
563 EXPECT_TRUE(tray->HasSystemBubble());
564 UpdateDisplay("100x600,600x400");
565 EXPECT_TRUE(tray->HasSystemBubble());
566
567 // Closes the tray and again makes sure that adding/removing displays doesn't
568 // break anything.
569 event_generator.ClickLeftButton();
570 RunAllPendingInMessageLoop();
571
572 EXPECT_FALSE(tray->HasSystemBubble());
573
574 UpdateDisplay("100x600");
575 EXPECT_FALSE(tray->HasSystemBubble());
576 UpdateDisplay("100x600,600x400");
577 EXPECT_FALSE(tray->HasSystemBubble());
578}
579
[email protected]578048512012-09-19 20:01:24580TEST_F(ExtendedDesktopTest, StayInSameRootWindow) {
581 UpdateDisplay("100x100,200x200");
582 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
583 views::Widget* w1 = CreateTestWidgetWithParent(
584 NULL, gfx::Rect(10, 10, 50, 50), false);
585 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
586 w1->SetBounds(gfx::Rect(150, 10, 50, 50));
587 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
588
589 // The widget stays in the same root if kStayInSameRootWindowKey is set to
590 // true.
591 w1->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, true);
592 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
593 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
594
595 // The widget should now move to the 1st root window without the property.
596 w1->GetNativeView()->ClearProperty(internal::kStayInSameRootWindowKey);
597 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
598 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
599}
600
[email protected]a5e71c92012-06-22 22:09:08601} // namespace internal
[email protected]c39be8f2012-06-15 22:58:36602} // namespace ash