blob: 4cc75faa136612d24197472f18dd7330e5bfaf19 [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]e67291f12012-10-10 05:52:387#include "ash/screen_ash.h"
[email protected]c39be8f2012-06-15 22:58:368#include "ash/shell.h"
[email protected]e67291f12012-10-10 05:52:389#include "ash/shell_window_ids.h"
[email protected]263898a2012-09-17 17:20:0710#include "ash/system/tray/system_tray.h"
[email protected]c39be8f2012-06-15 22:58:3611#include "ash/test/ash_test_base.h"
[email protected]7203a5e2012-08-06 18:27:4612#include "ash/wm/coordinate_conversion.h"
[email protected]7ae525002012-07-26 23:55:1013#include "ash/wm/property_util.h"
[email protected]0f81f442012-06-22 06:20:2714#include "ash/wm/window_cycle_controller.h"
[email protected]578048512012-09-19 20:01:2415#include "ash/wm/window_properties.h"
[email protected]c39be8f2012-06-15 22:58:3616#include "ash/wm/window_util.h"
[email protected]e67291f12012-10-10 05:52:3817#include "base/string_util.h"
[email protected]c39be8f2012-06-15 22:58:3618#include "ui/aura/client/activation_client.h"
19#include "ui/aura/client/capture_client.h"
[email protected]a5e71c92012-06-22 22:09:0820#include "ui/aura/env.h"
[email protected]c39be8f2012-06-15 22:58:3621#include "ui/aura/focus_manager.h"
22#include "ui/aura/root_window.h"
23#include "ui/aura/test/event_generator.h"
[email protected]a5e71c92012-06-22 22:09:0824#include "ui/aura/test/test_windows.h"
[email protected]c39be8f2012-06-15 22:58:3625#include "ui/aura/window.h"
26#include "ui/base/cursor/cursor.h"
[email protected]a5e71c92012-06-22 22:09:0827#include "ui/gfx/display.h"
[email protected]718b26c2012-07-24 20:53:2328#include "ui/gfx/screen.h"
[email protected]e67291f12012-10-10 05:52:3829#include "ui/views/controls/textfield/textfield.h"
[email protected]c39be8f2012-06-15 22:58:3630#include "ui/views/widget/widget.h"
31#include "ui/views/widget/widget_delegate.h"
32
33namespace ash {
34namespace {
35
[email protected]f059c6942012-07-21 14:27:5736views::Widget* CreateTestWidgetWithParent(views::Widget* parent,
37 const gfx::Rect& bounds,
38 bool child) {
[email protected]c39be8f2012-06-15 22:58:3639 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
[email protected]f059c6942012-07-21 14:27:5740 params.parent_widget = parent;
[email protected]c39be8f2012-06-15 22:58:3641 params.bounds = bounds;
[email protected]f059c6942012-07-21 14:27:5742 params.child = child;
[email protected]c39be8f2012-06-15 22:58:3643 views::Widget* widget = new views::Widget;
44 widget->Init(params);
[email protected]0f81f442012-06-22 06:20:2745 widget->Show();
[email protected]c39be8f2012-06-15 22:58:3646 return widget;
47}
48
[email protected]f059c6942012-07-21 14:27:5749views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
50 return CreateTestWidgetWithParent(NULL, bounds, false);
51}
52
[email protected]edbfb8d2012-09-03 08:33:4353void SetSecondaryDisplayLayout(DisplayLayout::Position position) {
54 DisplayController* display_controller =
55 Shell::GetInstance()->display_controller();
56 DisplayLayout layout = display_controller->default_display_layout();
57 layout.position = position;
58 display_controller->SetDefaultDisplayLayout(layout);
59}
60
[email protected]c39be8f2012-06-15 22:58:3661class ModalWidgetDelegate : public views::WidgetDelegateView {
62 public:
63 ModalWidgetDelegate() {}
64 virtual ~ModalWidgetDelegate() {}
65
66 // Overridden from views::WidgetDelegate:
67 virtual views::View* GetContentsView() OVERRIDE {
68 return this;
69 }
70 virtual ui::ModalType GetModalType() const OVERRIDE {
71 return ui::MODAL_TYPE_SYSTEM;
72 }
73
74 private:
75 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
76};
77
[email protected]3e4351b2012-08-09 04:04:1678internal::MultiDisplayManager* GetDisplayManager() {
79 return static_cast<internal::MultiDisplayManager*>(
80 aura::Env::GetInstance()->display_manager());
81}
82
[email protected]c39be8f2012-06-15 22:58:3683} // namespace
84
[email protected]3e4351b2012-08-09 04:04:1685typedef test::AshTestBase ExtendedDesktopTest;
[email protected]c39be8f2012-06-15 22:58:3686
87// Test conditions that root windows in extended desktop mode
88// must satisfy.
89TEST_F(ExtendedDesktopTest, Basic) {
[email protected]f634dd32012-07-23 22:49:0790 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:3691 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
92
93 // All root windows must have the root window controller.
94 ASSERT_EQ(2U, root_windows.size());
95 for (Shell::RootWindowList::const_iterator iter = root_windows.begin();
96 iter != root_windows.end(); ++iter) {
[email protected]7ae525002012-07-26 23:55:1097 EXPECT_TRUE(GetRootWindowController(*iter) != NULL);
[email protected]c39be8f2012-06-15 22:58:3698 }
99 // Make sure root windows share the same controllers.
100 EXPECT_EQ(root_windows[0]->GetFocusManager(),
101 root_windows[1]->GetFocusManager());
102 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]),
103 aura::client::GetActivationClient(root_windows[1]));
104 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
105 aura::client::GetCaptureClient(root_windows[1]));
106}
107
108TEST_F(ExtendedDesktopTest, Activation) {
[email protected]f634dd32012-07-23 22:49:07109 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36110 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
111
[email protected]c39be8f2012-06-15 22:58:36112 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]f634dd32012-07-23 22:49:07113 views::Widget* widget_on_2nd =
114 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36115 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]f634dd32012-07-23 22:49:07116 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36117
118 EXPECT_EQ(widget_on_2nd->GetNativeView(),
119 root_windows[0]->GetFocusManager()->GetFocusedWindow());
120 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
121
[email protected]f634dd32012-07-23 22:49:07122 aura::test::EventGenerator generator_1st(root_windows[0]);
123 aura::test::EventGenerator generator_2nd(root_windows[1]);
124
125 // Clicking a window changes the active window and active root window.
[email protected]c39be8f2012-06-15 22:58:36126 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
127 generator_1st.ClickLeftButton();
128
129 EXPECT_EQ(widget_on_1st->GetNativeView(),
130 root_windows[0]->GetFocusManager()->GetFocusedWindow());
131 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]f634dd32012-07-23 22:49:07132
133 generator_2nd.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
134 generator_2nd.ClickLeftButton();
135
136 EXPECT_EQ(widget_on_2nd->GetNativeView(),
137 root_windows[0]->GetFocusManager()->GetFocusedWindow());
138 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
[email protected]c39be8f2012-06-15 22:58:36139}
140
141TEST_F(ExtendedDesktopTest, SystemModal) {
[email protected]f634dd32012-07-23 22:49:07142 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36143 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36144
145 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36146 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]492533b32012-09-21 19:06:14147 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36148 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
149
[email protected]c39be8f2012-06-15 22:58:36150 // Open system modal. Make sure it's on 2nd root window and active.
[email protected]f634dd32012-07-23 22:49:07151 views::Widget* modal_widget = views::Widget::CreateWindowWithBounds(
152 new ModalWidgetDelegate(), gfx::Rect(1200, 100, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36153 modal_widget->Show();
154 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
155 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow());
156 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
157
[email protected]2e236a52012-06-27 22:21:47158 // Clicking a widget on widget_on_1st display should not change activation.
[email protected]c39be8f2012-06-15 22:58:36159 aura::test::EventGenerator generator_1st(root_windows[0]);
160 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
161 generator_1st.ClickLeftButton();
162 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
163 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
164
165 // Close system modal and so clicking a widget should work now.
166 modal_widget->Close();
167 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
168 generator_1st.ClickLeftButton();
169 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
170 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
171}
172
173TEST_F(ExtendedDesktopTest, TestCursor) {
[email protected]f634dd32012-07-23 22:49:07174 UpdateDisplay("1000x600,600x400");
[email protected]151ffdff2012-09-11 20:18:35175 Shell::GetInstance()->cursor_manager()->ShowCursor(false);
[email protected]c39be8f2012-06-15 22:58:36176 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
177 EXPECT_FALSE(root_windows[0]->cursor_shown());
178 EXPECT_FALSE(root_windows[1]->cursor_shown());
[email protected]151ffdff2012-09-11 20:18:35179 Shell::GetInstance()->cursor_manager()->ShowCursor(true);
[email protected]c39be8f2012-06-15 22:58:36180 EXPECT_TRUE(root_windows[0]->cursor_shown());
181 EXPECT_TRUE(root_windows[1]->cursor_shown());
182
183 EXPECT_EQ(ui::kCursorPointer, root_windows[0]->last_cursor().native_type());
184 EXPECT_EQ(ui::kCursorPointer, root_windows[1]->last_cursor().native_type());
[email protected]151ffdff2012-09-11 20:18:35185 Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy);
[email protected]c39be8f2012-06-15 22:58:36186 EXPECT_EQ(ui::kCursorCopy, root_windows[0]->last_cursor().native_type());
187 EXPECT_EQ(ui::kCursorCopy, root_windows[1]->last_cursor().native_type());
188}
189
[email protected]718b26c2012-07-24 20:53:23190TEST_F(ExtendedDesktopTest, TestCursorLocation) {
191 UpdateDisplay("0+0-1000x600,1001+0-600x400");
192 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
193 aura::Window::TestApi root_window0_test_api(root_windows[0]);
194 aura::Window::TestApi root_window1_test_api(root_windows[1]);
195
196 root_windows[0]->MoveCursorTo(gfx::Point(10, 10));
197 EXPECT_EQ("10,10", gfx::Screen::GetCursorScreenPoint().ToString());
198 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
199 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
200 root_windows[1]->MoveCursorTo(gfx::Point(10, 20));
201 EXPECT_EQ("1010,20", gfx::Screen::GetCursorScreenPoint().ToString());
202 EXPECT_FALSE(root_window0_test_api.ContainsMouse());
203 EXPECT_TRUE(root_window1_test_api.ContainsMouse());
204 root_windows[0]->MoveCursorTo(gfx::Point(20, 10));
205 EXPECT_EQ("20,10", gfx::Screen::GetCursorScreenPoint().ToString());
206 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
207 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
208}
209
[email protected]0f81f442012-06-22 06:20:27210TEST_F(ExtendedDesktopTest, CycleWindows) {
[email protected]f634dd32012-07-23 22:49:07211 UpdateDisplay("700x500,500x500");
[email protected]0f81f442012-06-22 06:20:27212 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24213
[email protected]0f81f442012-06-22 06:20:27214 WindowCycleController* controller =
215 Shell::GetInstance()->window_cycle_controller();
216
[email protected]0f81f442012-06-22 06:20:27217 views::Widget* d1_w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
218 EXPECT_EQ(root_windows[0], d1_w1->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24219 views::Widget* d2_w1 = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
[email protected]0f81f442012-06-22 06:20:27220 EXPECT_EQ(root_windows[1], d2_w1->GetNativeView()->GetRootWindow());
221 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
222
223 controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
224 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
225 controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
226 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
227 controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
228 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
229 controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
230 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
231
232 // Cycle through all windows across root windows.
[email protected]20c59762012-06-23 01:10:24233 views::Widget* d1_w2 = CreateTestWidget(gfx::Rect(10, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27234 EXPECT_EQ(root_windows[0], d1_w2->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24235 views::Widget* d2_w2 = CreateTestWidget(gfx::Rect(800, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27236 EXPECT_EQ(root_windows[1], d2_w2->GetNativeView()->GetRootWindow());
237
238 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]0f81f442012-06-22 06:20:27239 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
240 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]8fef7432012-08-06 15:34:25241 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
242 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]0f81f442012-06-22 06:20:27243 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
244 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
245 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
246
247 // Backwards
248 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
249 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
250 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]0f81f442012-06-22 06:20:27251 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
252 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]8fef7432012-08-06 15:34:25253 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
254 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]0f81f442012-06-22 06:20:27255 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
[email protected]20c59762012-06-23 01:10:24256}
257
258TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
[email protected]f634dd32012-07-23 22:49:07259 UpdateDisplay("700x500,500x500");
[email protected]edbfb8d2012-09-03 08:33:43260 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]20c59762012-06-23 01:10:24261 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24262
[email protected]7203a5e2012-08-06 18:27:46263 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100)));
264 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100)));
265 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300)));
266 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700,300)));
[email protected]20c59762012-06-23 01:10:24267
268 // Zero origin.
[email protected]7203a5e2012-08-06 18:27:46269 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0)));
[email protected]20c59762012-06-23 01:10:24270
271 // Out of range point should return the primary root window
[email protected]7203a5e2012-08-06 18:27:46272 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(-600, 0)));
273 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100)));
[email protected]20c59762012-06-23 01:10:24274}
275
276TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
[email protected]f634dd32012-07-23 22:49:07277 UpdateDisplay("700x500,500x500");
[email protected]edbfb8d2012-09-03 08:33:43278 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]66b05eac2012-06-27 23:53:10279
[email protected]20c59762012-06-23 01:10:24280 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24281
282 // Containing rect.
283 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46284 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24285 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46286 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24287
288 // Intersecting rect.
289 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46290 wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24291 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46292 wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24293
294 // Zero origin.
[email protected]66b05eac2012-06-27 23:53:10295 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46296 wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0)));
[email protected]66b05eac2012-06-27 23:53:10297 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46298 wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1)));
[email protected]20c59762012-06-23 01:10:24299
300 // Empty rect.
301 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46302 wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24303 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46304 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24305
306 // Out of range rect should return the primary root window.
307 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46308 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50)));
[email protected]20c59762012-06-23 01:10:24309 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46310 wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50)));
[email protected]0f81f442012-06-22 06:20:27311}
312
[email protected]7f502eb2012-09-20 09:17:12313#if defined(OS_WIN)
314// TODO(mazda): Re-enable this (http://crbug.com/150986).
315#define MAYBE_Capture DISABLED_Capture
316#else
317#define MAYBE_Capture Capture
318#endif
319
320TEST_F(ExtendedDesktopTest, MAYBE_Capture) {
[email protected]f634dd32012-07-23 22:49:07321 UpdateDisplay("1000x600,600x400");
[email protected]a5e71c92012-06-22 22:09:08322 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
323
324 aura::test::EventCountDelegate r1_d1;
325 aura::test::EventCountDelegate r1_d2;
326 aura::test::EventCountDelegate r2_d1;
327
328 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
329 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
330 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
331 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
332 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
333 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
[email protected]f634dd32012-07-23 22:49:07334
[email protected]a5e71c92012-06-22 22:09:08335 r1_w1->SetCapture();
336
337 EXPECT_EQ(r1_w1.get(),
338 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
339 aura::test::EventGenerator generator2(root_windows[1]);
340 generator2.MoveMouseToCenterOf(r2_w1.get());
341 generator2.ClickLeftButton();
342 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
343 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]b19ba4adf2012-09-07 16:13:29344 // The mouse is outside. On chromeos, the mouse is warped to the
345 // dest root window, but it's not implemented on Win yet, so
346 // no mouse move event on Win.
347#if defined(OS_WIN)
348 EXPECT_EQ("1 0 0", r1_d1.GetMouseMotionCountsAndReset());
349#else
[email protected]7495e5032012-09-07 15:31:45350 EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]b19ba4adf2012-09-07 16:13:29351#endif
[email protected]a5e71c92012-06-22 22:09:08352 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
[email protected]f634dd32012-07-23 22:49:07353 // (15,15) on 1st display is (-985,15) on 2nd display.
354 generator2.MoveMouseTo(-985, 15);
355 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08356
357 r1_w2->SetCapture();
358 EXPECT_EQ(r1_w2.get(),
359 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
360 generator2.MoveMouseBy(10, 10);
361 generator2.ClickLeftButton();
362 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
363 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
364 // mouse is already entered.
365 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset());
366 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset());
367
368 r1_w2->ReleaseCapture();
[email protected]36f566532012-09-19 04:07:24369 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]f634dd32012-07-23 22:49:07370 generator2.MoveMouseTo(15, 15);
[email protected]a5e71c92012-06-22 22:09:08371 generator2.ClickLeftButton();
372 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
373 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
374 // Make sure the mouse_moved_handler_ is properly reset.
375 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
376 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
377}
378
[email protected]f059c6942012-07-21 14:27:57379TEST_F(ExtendedDesktopTest, MoveWindow) {
[email protected]f634dd32012-07-23 22:49:07380 UpdateDisplay("1000x600,600x400");
[email protected]f059c6942012-07-21 14:27:57381 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
382 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
383
384 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
385
386 d1->SetBounds(gfx::Rect(1010, 10, 100, 100));
387 EXPECT_EQ("1010,10 100x100",
388 d1->GetWindowBoundsInScreen().ToString());
389
390 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
391
392 d1->SetBounds(gfx::Rect(10, 10, 100, 100));
393 EXPECT_EQ("10,10 100x100",
394 d1->GetWindowBoundsInScreen().ToString());
395
396 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
397
398 // Make sure the bounds which doesn't fit to the root window
399 // works correctly.
400 d1->SetBounds(gfx::Rect(1560, 30, 100, 100));
401 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
402 EXPECT_EQ("1560,30 100x100",
403 d1->GetWindowBoundsInScreen().ToString());
404
405 // Setting outside of root windows will be moved to primary root window.
406 // TODO(oshima): This one probably should pick the closest root window.
407 d1->SetBounds(gfx::Rect(200, 10, 100, 100));
408 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
[email protected]f059c6942012-07-21 14:27:57409}
410
[email protected]e79f26e2012-08-09 07:12:48411TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) {
412 UpdateDisplay("1000x1000,1000x1000");
413 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
414
415 gfx::Display display0 =
416 gfx::Screen::GetDisplayMatching(root_windows[0]->GetBoundsInScreen());
417 gfx::Display display1 =
418 gfx::Screen::GetDisplayMatching(root_windows[1]->GetBoundsInScreen());
419 EXPECT_NE(display0.id(), display1.id());
420
421 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100));
422 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
423
424 // Move the window where the window spans both root windows. Since the second
425 // parameter is |display1|, the window should be shown on the secondary root.
426 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
427 display1);
428 EXPECT_EQ("500,10 1000x100",
429 d1->GetWindowBoundsInScreen().ToString());
430 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
431
432 // Move to the primary root.
433 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
434 display0);
435 EXPECT_EQ("500,10 1000x100",
436 d1->GetWindowBoundsInScreen().ToString());
437 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
438}
439
[email protected]f059c6942012-07-21 14:27:57440TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
[email protected]f634dd32012-07-23 22:49:07441 UpdateDisplay("1000x600,600x400");
[email protected]f059c6942012-07-21 14:27:57442 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
443 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
444 views::Widget* w1_t1 = CreateTestWidgetWithParent(
445 w1, gfx::Rect(50, 50, 50, 50), false /* transient */);
446 // Transient child of the transient child.
447 views::Widget* w1_t11 = CreateTestWidgetWithParent(
448 w1_t1, gfx::Rect(1200, 70, 30, 30), false /* transient */);
449
450 views::Widget* w11 = CreateTestWidgetWithParent(
451 w1, gfx::Rect(10, 10, 40, 40), true /* child */);
452 views::Widget* w11_t1 = CreateTestWidgetWithParent(
453 w1, gfx::Rect(1300, 100, 80, 80), false /* transient */);
454
455 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
456 EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow());
457 EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow());
458 EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow());
459 EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow());
460 EXPECT_EQ("50,50 50x50",
461 w1_t1->GetWindowBoundsInScreen().ToString());
462 EXPECT_EQ("1200,70 30x30",
463 w1_t11->GetWindowBoundsInScreen().ToString());
464 EXPECT_EQ("20,20 40x40",
465 w11->GetWindowBoundsInScreen().ToString());
466 EXPECT_EQ("1300,100 80x80",
467 w11_t1->GetWindowBoundsInScreen().ToString());
468
469 w1->SetBounds(gfx::Rect(1100,10,100,100));
470
471 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
472 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
473 EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow());
474 EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow());
475 EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow());
476
477 EXPECT_EQ("1110,20 40x40",
478 w11->GetWindowBoundsInScreen().ToString());
479 // Transient window's screen bounds stays the same.
480 EXPECT_EQ("50,50 50x50",
481 w1_t1->GetWindowBoundsInScreen().ToString());
482 EXPECT_EQ("1200,70 30x30",
483 w1_t11->GetWindowBoundsInScreen().ToString());
484 EXPECT_EQ("1300,100 80x80",
485 w11_t1->GetWindowBoundsInScreen().ToString());
486
487 // Transient window doesn't move between root window unless
488 // its transient parent moves.
489 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50));
490 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
491 EXPECT_EQ("10,50 50x50",
492 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57493}
494
[email protected]a5e71c92012-06-22 22:09:08495namespace internal {
[email protected]ca7060982012-08-08 18:05:25496// Test if the Window::ConvertPointToTarget works across root windows.
[email protected]a5e71c92012-06-22 22:09:08497// TODO(oshima): Move multiple display suport and this test to aura.
498TEST_F(ExtendedDesktopTest, ConvertPoint) {
[email protected]f634dd32012-07-23 22:49:07499 UpdateDisplay("1000x600,600x400");
[email protected]a5e71c92012-06-22 22:09:08500 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
501 gfx::Display& display_1 =
[email protected]3e4351b2012-08-09 04:04:16502 GetDisplayManager()->FindDisplayForRootWindow(root_windows[0]);
[email protected]a5e71c92012-06-22 22:09:08503 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
504 gfx::Display& display_2 =
[email protected]3e4351b2012-08-09 04:04:16505 GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07506 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
507
[email protected]a5e71c92012-06-22 22:09:08508 aura::Window* d1 =
509 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
[email protected]a5e71c92012-06-22 22:09:08510 aura::Window* d2 =
[email protected]f634dd32012-07-23 22:49:07511 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
512 EXPECT_EQ(root_windows[0], d1->GetRootWindow());
513 EXPECT_EQ(root_windows[1], d2->GetRootWindow());
[email protected]a5e71c92012-06-22 22:09:08514
[email protected]a5e71c92012-06-22 22:09:08515 // Convert point in the Root2's window to the Root1's window Coord.
516 gfx::Point p(0, 0);
[email protected]ca7060982012-08-08 18:05:25517 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07518 EXPECT_EQ("1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08519 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25520 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07521 EXPECT_EQ("1010,10", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08522
523 // Convert point in the Root1's window to the Root2's window Coord.
524 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25525 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07526 EXPECT_EQ("-1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08527 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25528 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07529 EXPECT_EQ("-1010,-10", p.ToString());
530
531 // Move the 2nd display to the bottom and test again.
[email protected]edbfb8d2012-09-03 08:33:43532 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
[email protected]f634dd32012-07-23 22:49:07533
[email protected]3e4351b2012-08-09 04:04:16534 display_2 = GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07535 EXPECT_EQ("0,600", display_2.bounds().origin().ToString());
536
537 // Convert point in Root2's window to Root1's window Coord.
538 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25539 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07540 EXPECT_EQ("0,600", p.ToString());
541 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25542 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07543 EXPECT_EQ("10,610", p.ToString());
544
545 // Convert point in Root1's window to Root2's window Coord.
546 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25547 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07548 EXPECT_EQ("0,-600", p.ToString());
549 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25550 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07551 EXPECT_EQ("-10,-610", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08552}
[email protected]f634dd32012-07-23 22:49:07553
[email protected]263898a2012-09-17 17:20:07554TEST_F(ExtendedDesktopTest, OpenSystemTray) {
555 UpdateDisplay("1000x600,600x400");
556 SystemTray* tray = ash::Shell::GetInstance()->system_tray();
557 ASSERT_FALSE(tray->HasSystemBubble());
558
559 // Opens the tray by a dummy click event and makes sure that adding/removing
560 // displays doesn't break anything.
561 aura::test::EventGenerator event_generator(
562 ash::Shell::GetInstance()->GetPrimaryRootWindow(),
563 tray->GetWidget()->GetNativeWindow());
564 event_generator.ClickLeftButton();
565 EXPECT_TRUE(tray->HasSystemBubble());
566
567 UpdateDisplay("100x600");
568 EXPECT_TRUE(tray->HasSystemBubble());
569 UpdateDisplay("100x600,600x400");
570 EXPECT_TRUE(tray->HasSystemBubble());
571
572 // Closes the tray and again makes sure that adding/removing displays doesn't
573 // break anything.
574 event_generator.ClickLeftButton();
575 RunAllPendingInMessageLoop();
576
577 EXPECT_FALSE(tray->HasSystemBubble());
578
579 UpdateDisplay("100x600");
580 EXPECT_FALSE(tray->HasSystemBubble());
581 UpdateDisplay("100x600,600x400");
582 EXPECT_FALSE(tray->HasSystemBubble());
583}
584
[email protected]578048512012-09-19 20:01:24585TEST_F(ExtendedDesktopTest, StayInSameRootWindow) {
586 UpdateDisplay("100x100,200x200");
587 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
588 views::Widget* w1 = CreateTestWidgetWithParent(
589 NULL, gfx::Rect(10, 10, 50, 50), false);
590 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
591 w1->SetBounds(gfx::Rect(150, 10, 50, 50));
592 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
593
594 // The widget stays in the same root if kStayInSameRootWindowKey is set to
595 // true.
596 w1->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, true);
597 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
598 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
599
600 // The widget should now move to the 1st root window without the property.
601 w1->GetNativeView()->ClearProperty(internal::kStayInSameRootWindowKey);
602 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
603 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
604}
605
[email protected]e67291f12012-10-10 05:52:38606TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) {
607 UpdateDisplay("100x100,200x200");
608 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
609
610 // Create normal windows on both displays.
611 views::Widget* widget1 = CreateTestWidget(
612 gfx::Screen::GetPrimaryDisplay().bounds());
613 widget1->Show();
614 EXPECT_EQ(root_windows[0], widget1->GetNativeView()->GetRootWindow());
615 views::Widget* widget2 = CreateTestWidget(
616 ScreenAsh::GetSecondaryDisplay().bounds());
617 widget2->Show();
618 EXPECT_EQ(root_windows[1], widget2->GetNativeView()->GetRootWindow());
619
620 // Create a LockScreen window.
621 views::Widget* lock_widget = CreateTestWidget(
622 gfx::Screen::GetPrimaryDisplay().bounds());
623 views::Textfield* textfield = new views::Textfield;
624 lock_widget->SetContentsView(textfield);
625
626 ash::Shell::GetContainer(
627 Shell::GetPrimaryRootWindow(),
628 ash::internal::kShellWindowId_LockScreenContainer)->
629 AddChild(lock_widget->GetNativeView());
630 lock_widget->Show();
631 textfield->RequestFocus();
632
633 aura::FocusManager* focus_manager = root_windows[0]->GetFocusManager();
634 EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow());
635
636 // The lock window should get events on both root windows.
637 aura::test::EventGenerator generator1(root_windows[0]);
638 generator1.PressKey(ui::VKEY_A, 0);
639 generator1.ReleaseKey(ui::VKEY_A, 0);
640 EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow());
641 EXPECT_EQ("a", UTF16ToASCII(textfield->text()));
642
643 aura::test::EventGenerator generator2(root_windows[1]);
644 generator2.PressKey(ui::VKEY_B, 0);
645 generator2.ReleaseKey(ui::VKEY_B, 0);
646 EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow());
647 EXPECT_EQ("ab", UTF16ToASCII(textfield->text()));
648
649 // Deleting 2nd display. The lock window still should get the events.
650 UpdateDisplay("100x100");
651 generator2.PressKey(ui::VKEY_C, 0);
652 generator2.ReleaseKey(ui::VKEY_C, 0);
653 EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow());
654 EXPECT_EQ("abc", UTF16ToASCII(textfield->text()));
655
656 // Creating 2nd display again, and lock window still should get events
657 // on both root windows.
658 UpdateDisplay("100x100,200x200");
659 root_windows = Shell::GetAllRootWindows();
660 generator1.PressKey(ui::VKEY_D, 0);
661 generator1.ReleaseKey(ui::VKEY_D, 0);
662 EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow());
663 EXPECT_EQ("abcd", UTF16ToASCII(textfield->text()));
664
665 aura::test::EventGenerator generator22(root_windows[1]);
666 generator22.PressKey(ui::VKEY_E, 0);
667 generator22.ReleaseKey(ui::VKEY_E, 0);
668 EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow());
669 EXPECT_EQ("abcde", UTF16ToASCII(textfield->text()));
670}
671
[email protected]a5e71c92012-06-22 22:09:08672} // namespace internal
[email protected]c39be8f2012-06-15 22:58:36673} // namespace ash