blob: 941e83b0dd2fe38bc0dd4f3e12355b03afb03b95 [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"
[email protected]6bdf7952012-11-14 10:10:586#include "ash/display/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]8cfb6722012-11-28 03:28:4620#include "ui/aura/client/focus_client.h"
[email protected]c39be8f2012-06-15 22:58:3621#include "ui/aura/root_window.h"
22#include "ui/aura/test/event_generator.h"
[email protected]a5e71c92012-06-22 22:09:0823#include "ui/aura/test/test_windows.h"
[email protected]553eae12013-02-01 02:33:5224#include "ui/aura/test/window_test_api.h"
[email protected]c39be8f2012-06-15 22:58:3625#include "ui/aura/window.h"
26#include "ui/base/cursor/cursor.h"
[email protected]2e98aaf72012-11-08 06:30:5927#include "ui/base/events/event_handler.h"
[email protected]a5e71c92012-06-22 22:09:0828#include "ui/gfx/display.h"
[email protected]718b26c2012-07-24 20:53:2329#include "ui/gfx/screen.h"
[email protected]e67291f12012-10-10 05:52:3830#include "ui/views/controls/textfield/textfield.h"
[email protected]c39be8f2012-06-15 22:58:3631#include "ui/views/widget/widget.h"
32#include "ui/views/widget/widget_delegate.h"
33
34namespace ash {
35namespace {
36
[email protected]edbfb8d2012-09-03 08:33:4337void SetSecondaryDisplayLayout(DisplayLayout::Position position) {
38 DisplayController* display_controller =
39 Shell::GetInstance()->display_controller();
40 DisplayLayout layout = display_controller->default_display_layout();
41 layout.position = position;
42 display_controller->SetDefaultDisplayLayout(layout);
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
[email protected]6bdf7952012-11-14 10:10:5862internal::DisplayManager* GetDisplayManager() {
63 return Shell::GetInstance()->display_manager();
[email protected]3e4351b2012-08-09 04:04:1664}
65
[email protected]334e6182013-01-11 18:35:4166// An event handler which moves the target window to the secondary root window
[email protected]2e98aaf72012-11-08 06:30:5967// at pre-handle phase of a mouse release event.
[email protected]334e6182013-01-11 18:35:4168class MoveWindowByClickEventHandler : public ui::EventHandler {
[email protected]2e98aaf72012-11-08 06:30:5969 public:
[email protected]334e6182013-01-11 18:35:4170 explicit MoveWindowByClickEventHandler(aura::Window* target)
[email protected]2e98aaf72012-11-08 06:30:5971 : target_(target) {}
[email protected]334e6182013-01-11 18:35:4172 virtual ~MoveWindowByClickEventHandler() {}
[email protected]2e98aaf72012-11-08 06:30:5973
74 private:
75 // ui::EventHandler overrides:
[email protected]d44efe02012-12-18 06:08:1876 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
[email protected]2e98aaf72012-11-08 06:30:5977 if (event->type() == ui::ET_MOUSE_RELEASED) {
78 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
79 DCHECK_LT(1u, root_windows.size());
80 root_windows[1]->AddChild(target_);
81 }
[email protected]2e98aaf72012-11-08 06:30:5982 }
83
[email protected]2e98aaf72012-11-08 06:30:5984 aura::Window* target_;
[email protected]334e6182013-01-11 18:35:4185 DISALLOW_COPY_AND_ASSIGN(MoveWindowByClickEventHandler);
86};
87
88// An event handler which records the event's locations.
89class EventLocationRecordingEventHandler : public ui::EventHandler {
90 public:
91 explicit EventLocationRecordingEventHandler() {
92 reset();
93 }
94 virtual ~EventLocationRecordingEventHandler() {}
95
96 std::string GetLocationsAndReset() {
97 std::string result =
98 location_.ToString() + " " + root_location_.ToString();
99 reset();
100 return result;
101 }
102
103 private:
104 // ui::EventHandler overrides:
105 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
106 if (event->type() == ui::ET_MOUSE_MOVED ||
107 event->type() == ui::ET_MOUSE_DRAGGED) {
108 location_ = event->location();
109 root_location_ = event->root_location();
110 }
111 }
112
113 void reset() {
114 location_.SetPoint(-999, -999);
115 root_location_.SetPoint(-999, -999);
116 }
117
118 gfx::Point root_location_;
119 gfx::Point location_;
120
121 DISALLOW_COPY_AND_ASSIGN(EventLocationRecordingEventHandler);
[email protected]2e98aaf72012-11-08 06:30:59122};
123
[email protected]c39be8f2012-06-15 22:58:36124} // namespace
125
[email protected]a2e6af12013-01-07 21:40:35126class ExtendedDesktopTest : public test::AshTestBase {
127 public:
128 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
129 return CreateTestWidgetWithParentAndContext(
130 NULL, CurrentContext(), bounds, false);
131 }
132
133 views::Widget* CreateTestWidgetWithParent(views::Widget* parent,
134 const gfx::Rect& bounds,
135 bool child) {
136 CHECK(parent);
137 return CreateTestWidgetWithParentAndContext(parent, NULL, bounds, child);
138 }
139
140 views::Widget* CreateTestWidgetWithParentAndContext(views::Widget* parent,
141 gfx::NativeView context,
142 const gfx::Rect& bounds,
143 bool child) {
144 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
145 if (parent)
146 params.parent = parent->GetNativeView();
147 params.context = context;
148 params.bounds = bounds;
149 params.child = child;
150 views::Widget* widget = new views::Widget;
151 widget->Init(params);
152 widget->Show();
153 return widget;
154 }
155};
[email protected]c39be8f2012-06-15 22:58:36156
157// Test conditions that root windows in extended desktop mode
158// must satisfy.
159TEST_F(ExtendedDesktopTest, Basic) {
[email protected]f634dd32012-07-23 22:49:07160 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36161 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
162
163 // All root windows must have the root window controller.
164 ASSERT_EQ(2U, root_windows.size());
165 for (Shell::RootWindowList::const_iterator iter = root_windows.begin();
166 iter != root_windows.end(); ++iter) {
[email protected]7ae525002012-07-26 23:55:10167 EXPECT_TRUE(GetRootWindowController(*iter) != NULL);
[email protected]c39be8f2012-06-15 22:58:36168 }
169 // Make sure root windows share the same controllers.
[email protected]8cfb6722012-11-28 03:28:46170 EXPECT_EQ(aura::client::GetFocusClient(root_windows[0]),
171 aura::client::GetFocusClient(root_windows[1]));
[email protected]c39be8f2012-06-15 22:58:36172 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]),
173 aura::client::GetActivationClient(root_windows[1]));
174 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
175 aura::client::GetCaptureClient(root_windows[1]));
176}
177
178TEST_F(ExtendedDesktopTest, Activation) {
[email protected]f634dd32012-07-23 22:49:07179 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36180 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
181
[email protected]c39be8f2012-06-15 22:58:36182 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]f634dd32012-07-23 22:49:07183 views::Widget* widget_on_2nd =
184 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36185 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]f634dd32012-07-23 22:49:07186 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36187
188 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46189 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36190 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
191
[email protected]334e6182013-01-11 18:35:41192 aura::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]f634dd32012-07-23 22:49:07193 // Clicking a window changes the active window and active root window.
[email protected]334e6182013-01-11 18:35:41194 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
195 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36196
197 EXPECT_EQ(widget_on_1st->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46198 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36199 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]f634dd32012-07-23 22:49:07200
[email protected]334e6182013-01-11 18:35:41201 event_generator.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
202 event_generator.ClickLeftButton();
[email protected]f634dd32012-07-23 22:49:07203
204 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46205 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]f634dd32012-07-23 22:49:07206 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
[email protected]c39be8f2012-06-15 22:58:36207}
208
209TEST_F(ExtendedDesktopTest, SystemModal) {
[email protected]f634dd32012-07-23 22:49:07210 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36211 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36212
213 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36214 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]492533b32012-09-21 19:06:14215 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36216 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
217
[email protected]c39be8f2012-06-15 22:58:36218 // Open system modal. Make sure it's on 2nd root window and active.
[email protected]a2e6af12013-01-07 21:40:35219 views::Widget* modal_widget = views::Widget::CreateWindowWithContextAndBounds(
220 new ModalWidgetDelegate(),
221 CurrentContext(),
222 gfx::Rect(1200, 100, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36223 modal_widget->Show();
224 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
225 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow());
226 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
227
[email protected]334e6182013-01-11 18:35:41228 aura::test::EventGenerator& event_generator(GetEventGenerator());
229
[email protected]2e236a52012-06-27 22:21:47230 // Clicking a widget on widget_on_1st display should not change activation.
[email protected]334e6182013-01-11 18:35:41231 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
232 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36233 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
234 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
235
236 // Close system modal and so clicking a widget should work now.
237 modal_widget->Close();
[email protected]334e6182013-01-11 18:35:41238 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
239 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36240 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
241 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
242}
243
244TEST_F(ExtendedDesktopTest, TestCursor) {
[email protected]f634dd32012-07-23 22:49:07245 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36246 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36247 EXPECT_EQ(ui::kCursorPointer, root_windows[0]->last_cursor().native_type());
248 EXPECT_EQ(ui::kCursorPointer, root_windows[1]->last_cursor().native_type());
[email protected]151ffdff2012-09-11 20:18:35249 Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy);
[email protected]c39be8f2012-06-15 22:58:36250 EXPECT_EQ(ui::kCursorCopy, root_windows[0]->last_cursor().native_type());
251 EXPECT_EQ(ui::kCursorCopy, root_windows[1]->last_cursor().native_type());
252}
253
[email protected]718b26c2012-07-24 20:53:23254TEST_F(ExtendedDesktopTest, TestCursorLocation) {
[email protected]d0064722013-03-14 18:16:43255 UpdateDisplay("1000x600,600x400");
[email protected]718b26c2012-07-24 20:53:23256 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]553eae12013-02-01 02:33:52257 aura::test::WindowTestApi root_window0_test_api(root_windows[0]);
258 aura::test::WindowTestApi root_window1_test_api(root_windows[1]);
[email protected]718b26c2012-07-24 20:53:23259
260 root_windows[0]->MoveCursorTo(gfx::Point(10, 10));
[email protected]ffabb1e2012-10-12 19:51:17261 EXPECT_EQ("10,10", Shell::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23262 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
263 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
264 root_windows[1]->MoveCursorTo(gfx::Point(10, 20));
[email protected]ffabb1e2012-10-12 19:51:17265 EXPECT_EQ("1010,20", Shell::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23266 EXPECT_FALSE(root_window0_test_api.ContainsMouse());
267 EXPECT_TRUE(root_window1_test_api.ContainsMouse());
268 root_windows[0]->MoveCursorTo(gfx::Point(20, 10));
[email protected]ffabb1e2012-10-12 19:51:17269 EXPECT_EQ("20,10", Shell::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23270 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
271 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
272}
273
[email protected]0f81f442012-06-22 06:20:27274TEST_F(ExtendedDesktopTest, CycleWindows) {
[email protected]f634dd32012-07-23 22:49:07275 UpdateDisplay("700x500,500x500");
[email protected]0f81f442012-06-22 06:20:27276 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24277
[email protected]0f81f442012-06-22 06:20:27278 WindowCycleController* controller =
279 Shell::GetInstance()->window_cycle_controller();
280
[email protected]0f81f442012-06-22 06:20:27281 views::Widget* d1_w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
282 EXPECT_EQ(root_windows[0], d1_w1->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24283 views::Widget* d2_w1 = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
[email protected]0f81f442012-06-22 06:20:27284 EXPECT_EQ(root_windows[1], d2_w1->GetNativeView()->GetRootWindow());
285 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
286
287 controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
288 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
289 controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
290 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
291 controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
292 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
293 controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
294 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
295
296 // Cycle through all windows across root windows.
[email protected]20c59762012-06-23 01:10:24297 views::Widget* d1_w2 = CreateTestWidget(gfx::Rect(10, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27298 EXPECT_EQ(root_windows[0], d1_w2->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24299 views::Widget* d2_w2 = CreateTestWidget(gfx::Rect(800, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27300 EXPECT_EQ(root_windows[1], d2_w2->GetNativeView()->GetRootWindow());
301
302 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]0f81f442012-06-22 06:20:27303 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
304 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]8fef7432012-08-06 15:34:25305 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
306 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]0f81f442012-06-22 06:20:27307 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
308 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
309 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
310
311 // Backwards
312 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
313 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
314 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]0f81f442012-06-22 06:20:27315 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
316 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]8fef7432012-08-06 15:34:25317 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
318 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]0f81f442012-06-22 06:20:27319 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
[email protected]20c59762012-06-23 01:10:24320}
321
322TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
[email protected]f634dd32012-07-23 22:49:07323 UpdateDisplay("700x500,500x500");
[email protected]edbfb8d2012-09-03 08:33:43324 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]20c59762012-06-23 01:10:24325 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24326
[email protected]7203a5e2012-08-06 18:27:46327 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100)));
328 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100)));
329 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300)));
330 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700,300)));
[email protected]20c59762012-06-23 01:10:24331
332 // Zero origin.
[email protected]7203a5e2012-08-06 18:27:46333 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0)));
[email protected]20c59762012-06-23 01:10:24334
335 // Out of range point should return the primary root window
[email protected]7203a5e2012-08-06 18:27:46336 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(-600, 0)));
337 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100)));
[email protected]20c59762012-06-23 01:10:24338}
339
340TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
[email protected]f634dd32012-07-23 22:49:07341 UpdateDisplay("700x500,500x500");
[email protected]edbfb8d2012-09-03 08:33:43342 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]66b05eac2012-06-27 23:53:10343
[email protected]20c59762012-06-23 01:10:24344 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24345
346 // Containing rect.
347 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46348 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24349 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46350 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24351
352 // Intersecting rect.
353 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46354 wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24355 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46356 wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24357
358 // Zero origin.
[email protected]66b05eac2012-06-27 23:53:10359 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46360 wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0)));
[email protected]66b05eac2012-06-27 23:53:10361 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46362 wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1)));
[email protected]20c59762012-06-23 01:10:24363
364 // Empty rect.
365 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46366 wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24367 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46368 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24369
370 // Out of range rect should return the primary root window.
371 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46372 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50)));
[email protected]20c59762012-06-23 01:10:24373 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46374 wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50)));
[email protected]0f81f442012-06-22 06:20:27375}
376
[email protected]1a015382012-12-01 19:44:59377TEST_F(ExtendedDesktopTest, Capture) {
[email protected]f634dd32012-07-23 22:49:07378 UpdateDisplay("1000x600,600x400");
[email protected]a5e71c92012-06-22 22:09:08379 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
380
381 aura::test::EventCountDelegate r1_d1;
382 aura::test::EventCountDelegate r1_d2;
383 aura::test::EventCountDelegate r2_d1;
384
385 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
386 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
387 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
388 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
389 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
390 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
[email protected]f634dd32012-07-23 22:49:07391
[email protected]a5e71c92012-06-22 22:09:08392 r1_w1->SetCapture();
393
394 EXPECT_EQ(r1_w1.get(),
395 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]334e6182013-01-11 18:35:41396
[email protected]a5e71c92012-06-22 22:09:08397 aura::test::EventGenerator generator2(root_windows[1]);
398 generator2.MoveMouseToCenterOf(r2_w1.get());
399 generator2.ClickLeftButton();
400 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
401 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]b19ba4adf2012-09-07 16:13:29402 // The mouse is outside. On chromeos, the mouse is warped to the
403 // dest root window, but it's not implemented on Win yet, so
404 // no mouse move event on Win.
[email protected]7495e5032012-09-07 15:31:45405 EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08406 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
[email protected]334e6182013-01-11 18:35:41407 // Emulate passive grab. (15,15) on 1st display is (-985,15) on 2nd
408 // display.
[email protected]f634dd32012-07-23 22:49:07409 generator2.MoveMouseTo(-985, 15);
410 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08411
412 r1_w2->SetCapture();
413 EXPECT_EQ(r1_w2.get(),
414 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
415 generator2.MoveMouseBy(10, 10);
416 generator2.ClickLeftButton();
417 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
418 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
419 // mouse is already entered.
420 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset());
421 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08422 r1_w2->ReleaseCapture();
[email protected]36f566532012-09-19 04:07:24423 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]f634dd32012-07-23 22:49:07424 generator2.MoveMouseTo(15, 15);
[email protected]a5e71c92012-06-22 22:09:08425 generator2.ClickLeftButton();
426 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
427 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
428 // Make sure the mouse_moved_handler_ is properly reset.
429 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
430 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
431}
432
[email protected]f059c6942012-07-21 14:27:57433TEST_F(ExtendedDesktopTest, MoveWindow) {
[email protected]f634dd32012-07-23 22:49:07434 UpdateDisplay("1000x600,600x400");
[email protected]f059c6942012-07-21 14:27:57435 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
436 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
437
438 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
439
440 d1->SetBounds(gfx::Rect(1010, 10, 100, 100));
441 EXPECT_EQ("1010,10 100x100",
442 d1->GetWindowBoundsInScreen().ToString());
443
444 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
445
446 d1->SetBounds(gfx::Rect(10, 10, 100, 100));
447 EXPECT_EQ("10,10 100x100",
448 d1->GetWindowBoundsInScreen().ToString());
449
450 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
451
452 // Make sure the bounds which doesn't fit to the root window
453 // works correctly.
454 d1->SetBounds(gfx::Rect(1560, 30, 100, 100));
455 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
456 EXPECT_EQ("1560,30 100x100",
457 d1->GetWindowBoundsInScreen().ToString());
458
459 // Setting outside of root windows will be moved to primary root window.
460 // TODO(oshima): This one probably should pick the closest root window.
461 d1->SetBounds(gfx::Rect(200, 10, 100, 100));
462 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
[email protected]f059c6942012-07-21 14:27:57463}
464
[email protected]2e98aaf72012-11-08 06:30:59465// Verifies if the mouse event arrives to the window even when the window
466// moves to another root in a pre-target handler. See: crbug.com/157583
467TEST_F(ExtendedDesktopTest, MoveWindowByMouseClick) {
468 UpdateDisplay("1000x600,600x400");
469
470 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
471 aura::test::EventCountDelegate delegate;
472 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate(
473 &delegate, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
[email protected]334e6182013-01-11 18:35:41474 MoveWindowByClickEventHandler event_handler(window.get());
475 window->AddPreTargetHandler(&event_handler);
476
477 aura::test::EventGenerator& event_generator(GetEventGenerator());
478
479 event_generator.MoveMouseToCenterOf(window.get());
480 event_generator.ClickLeftButton();
[email protected]2e98aaf72012-11-08 06:30:59481 // Both mouse pressed and released arrive at the window and its delegate.
482 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset());
[email protected]334e6182013-01-11 18:35:41483 // Also event_handler moves the window to another root at mouse release.
[email protected]2e98aaf72012-11-08 06:30:59484 EXPECT_EQ(root_windows[1], window->GetRootWindow());
485}
486
[email protected]1a015382012-12-01 19:44:59487TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) {
[email protected]e79f26e2012-08-09 07:12:48488 UpdateDisplay("1000x1000,1000x1000");
489 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
490
[email protected]ffabb1e2012-10-12 19:51:17491 gfx::Display display0 = Shell::GetScreen()->GetDisplayMatching(
492 root_windows[0]->GetBoundsInScreen());
493 gfx::Display display1 = Shell::GetScreen()->GetDisplayMatching(
494 root_windows[1]->GetBoundsInScreen());
[email protected]e79f26e2012-08-09 07:12:48495 EXPECT_NE(display0.id(), display1.id());
496
497 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100));
498 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
499
500 // Move the window where the window spans both root windows. Since the second
501 // parameter is |display1|, the window should be shown on the secondary root.
502 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
503 display1);
504 EXPECT_EQ("500,10 1000x100",
505 d1->GetWindowBoundsInScreen().ToString());
506 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
507
508 // Move to the primary root.
509 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
510 display0);
511 EXPECT_EQ("500,10 1000x100",
512 d1->GetWindowBoundsInScreen().ToString());
513 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
514}
515
[email protected]f059c6942012-07-21 14:27:57516TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
[email protected]f634dd32012-07-23 22:49:07517 UpdateDisplay("1000x600,600x400");
[email protected]f059c6942012-07-21 14:27:57518 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
519 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
520 views::Widget* w1_t1 = CreateTestWidgetWithParent(
521 w1, gfx::Rect(50, 50, 50, 50), false /* transient */);
522 // Transient child of the transient child.
523 views::Widget* w1_t11 = CreateTestWidgetWithParent(
524 w1_t1, gfx::Rect(1200, 70, 30, 30), false /* transient */);
525
526 views::Widget* w11 = CreateTestWidgetWithParent(
527 w1, gfx::Rect(10, 10, 40, 40), true /* child */);
528 views::Widget* w11_t1 = CreateTestWidgetWithParent(
529 w1, gfx::Rect(1300, 100, 80, 80), false /* transient */);
530
531 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
532 EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow());
533 EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow());
534 EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow());
535 EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow());
536 EXPECT_EQ("50,50 50x50",
537 w1_t1->GetWindowBoundsInScreen().ToString());
538 EXPECT_EQ("1200,70 30x30",
539 w1_t11->GetWindowBoundsInScreen().ToString());
540 EXPECT_EQ("20,20 40x40",
541 w11->GetWindowBoundsInScreen().ToString());
542 EXPECT_EQ("1300,100 80x80",
543 w11_t1->GetWindowBoundsInScreen().ToString());
544
545 w1->SetBounds(gfx::Rect(1100,10,100,100));
546
547 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
548 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
549 EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow());
550 EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow());
551 EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow());
552
553 EXPECT_EQ("1110,20 40x40",
554 w11->GetWindowBoundsInScreen().ToString());
555 // Transient window's screen bounds stays the same.
556 EXPECT_EQ("50,50 50x50",
557 w1_t1->GetWindowBoundsInScreen().ToString());
558 EXPECT_EQ("1200,70 30x30",
559 w1_t11->GetWindowBoundsInScreen().ToString());
560 EXPECT_EQ("1300,100 80x80",
561 w11_t1->GetWindowBoundsInScreen().ToString());
562
563 // Transient window doesn't move between root window unless
564 // its transient parent moves.
565 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50));
566 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
567 EXPECT_EQ("10,50 50x50",
568 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57569}
570
[email protected]a5e71c92012-06-22 22:09:08571namespace internal {
[email protected]ca7060982012-08-08 18:05:25572// Test if the Window::ConvertPointToTarget works across root windows.
[email protected]a5e71c92012-06-22 22:09:08573// TODO(oshima): Move multiple display suport and this test to aura.
574TEST_F(ExtendedDesktopTest, ConvertPoint) {
[email protected]f634dd32012-07-23 22:49:07575 UpdateDisplay("1000x600,600x400");
[email protected]a5e71c92012-06-22 22:09:08576 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
577 gfx::Display& display_1 =
[email protected]3e4351b2012-08-09 04:04:16578 GetDisplayManager()->FindDisplayForRootWindow(root_windows[0]);
[email protected]a5e71c92012-06-22 22:09:08579 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
580 gfx::Display& display_2 =
[email protected]3e4351b2012-08-09 04:04:16581 GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07582 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
583
[email protected]a5e71c92012-06-22 22:09:08584 aura::Window* d1 =
585 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
[email protected]a5e71c92012-06-22 22:09:08586 aura::Window* d2 =
[email protected]f634dd32012-07-23 22:49:07587 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
588 EXPECT_EQ(root_windows[0], d1->GetRootWindow());
589 EXPECT_EQ(root_windows[1], d2->GetRootWindow());
[email protected]a5e71c92012-06-22 22:09:08590
[email protected]a5e71c92012-06-22 22:09:08591 // Convert point in the Root2's window to the Root1's window Coord.
592 gfx::Point p(0, 0);
[email protected]ca7060982012-08-08 18:05:25593 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07594 EXPECT_EQ("1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08595 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25596 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07597 EXPECT_EQ("1010,10", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08598
599 // Convert point in the Root1's window to the Root2's window Coord.
600 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25601 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07602 EXPECT_EQ("-1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08603 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25604 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07605 EXPECT_EQ("-1010,-10", p.ToString());
606
607 // Move the 2nd display to the bottom and test again.
[email protected]edbfb8d2012-09-03 08:33:43608 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
[email protected]f634dd32012-07-23 22:49:07609
[email protected]3e4351b2012-08-09 04:04:16610 display_2 = GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07611 EXPECT_EQ("0,600", display_2.bounds().origin().ToString());
612
613 // Convert point in Root2's window to Root1's window Coord.
614 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25615 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07616 EXPECT_EQ("0,600", p.ToString());
617 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25618 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07619 EXPECT_EQ("10,610", p.ToString());
620
621 // Convert point in Root1's window to Root2's window Coord.
622 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25623 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07624 EXPECT_EQ("0,-600", p.ToString());
625 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25626 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07627 EXPECT_EQ("-10,-610", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08628}
[email protected]f634dd32012-07-23 22:49:07629
[email protected]263898a2012-09-17 17:20:07630TEST_F(ExtendedDesktopTest, OpenSystemTray) {
[email protected]596c61c2012-10-29 17:29:43631 UpdateDisplay("500x600,600x400");
[email protected]a0afeb12012-12-10 22:57:09632 SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray();
[email protected]263898a2012-09-17 17:20:07633 ASSERT_FALSE(tray->HasSystemBubble());
634
[email protected]334e6182013-01-11 18:35:41635 aura::test::EventGenerator& event_generator(GetEventGenerator());
636
[email protected]263898a2012-09-17 17:20:07637 // Opens the tray by a dummy click event and makes sure that adding/removing
638 // displays doesn't break anything.
[email protected]334e6182013-01-11 18:35:41639 event_generator.MoveMouseToCenterOf(tray->GetWidget()->GetNativeWindow());
[email protected]263898a2012-09-17 17:20:07640 event_generator.ClickLeftButton();
641 EXPECT_TRUE(tray->HasSystemBubble());
642
[email protected]596c61c2012-10-29 17:29:43643 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07644 EXPECT_TRUE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43645 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07646 EXPECT_TRUE(tray->HasSystemBubble());
647
648 // Closes the tray and again makes sure that adding/removing displays doesn't
649 // break anything.
650 event_generator.ClickLeftButton();
651 RunAllPendingInMessageLoop();
652
653 EXPECT_FALSE(tray->HasSystemBubble());
654
[email protected]596c61c2012-10-29 17:29:43655 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07656 EXPECT_FALSE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43657 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07658 EXPECT_FALSE(tray->HasSystemBubble());
659}
660
[email protected]578048512012-09-19 20:01:24661TEST_F(ExtendedDesktopTest, StayInSameRootWindow) {
662 UpdateDisplay("100x100,200x200");
663 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]a2e6af12013-01-07 21:40:35664 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 50, 50));
[email protected]578048512012-09-19 20:01:24665 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
666 w1->SetBounds(gfx::Rect(150, 10, 50, 50));
667 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
668
669 // The widget stays in the same root if kStayInSameRootWindowKey is set to
670 // true.
671 w1->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, true);
672 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
673 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
674
675 // The widget should now move to the 1st root window without the property.
676 w1->GetNativeView()->ClearProperty(internal::kStayInSameRootWindowKey);
677 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
678 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
679}
680
[email protected]e67291f12012-10-10 05:52:38681TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) {
682 UpdateDisplay("100x100,200x200");
683 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
684
685 // Create normal windows on both displays.
686 views::Widget* widget1 = CreateTestWidget(
[email protected]ffabb1e2012-10-12 19:51:17687 Shell::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38688 widget1->Show();
689 EXPECT_EQ(root_windows[0], widget1->GetNativeView()->GetRootWindow());
690 views::Widget* widget2 = CreateTestWidget(
691 ScreenAsh::GetSecondaryDisplay().bounds());
692 widget2->Show();
693 EXPECT_EQ(root_windows[1], widget2->GetNativeView()->GetRootWindow());
694
695 // Create a LockScreen window.
696 views::Widget* lock_widget = CreateTestWidget(
[email protected]ffabb1e2012-10-12 19:51:17697 Shell::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38698 views::Textfield* textfield = new views::Textfield;
[email protected]09148952013-03-13 13:25:43699 lock_widget->client_view()->AddChildView(textfield);
[email protected]e67291f12012-10-10 05:52:38700
701 ash::Shell::GetContainer(
702 Shell::GetPrimaryRootWindow(),
703 ash::internal::kShellWindowId_LockScreenContainer)->
704 AddChild(lock_widget->GetNativeView());
705 lock_widget->Show();
706 textfield->RequestFocus();
707
[email protected]8cfb6722012-11-28 03:28:46708 aura::client::FocusClient* focus_client =
709 aura::client::GetFocusClient(root_windows[0]);
710 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38711
712 // The lock window should get events on both root windows.
[email protected]334e6182013-01-11 18:35:41713 aura::test::EventGenerator& event_generator(GetEventGenerator());
714
715 event_generator.set_current_root_window(root_windows[0]);
716 event_generator.PressKey(ui::VKEY_A, 0);
717 event_generator.ReleaseKey(ui::VKEY_A, 0);
[email protected]8cfb6722012-11-28 03:28:46718 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38719 EXPECT_EQ("a", UTF16ToASCII(textfield->text()));
720
[email protected]334e6182013-01-11 18:35:41721 event_generator.set_current_root_window(root_windows[1]);
722 event_generator.PressKey(ui::VKEY_B, 0);
723 event_generator.ReleaseKey(ui::VKEY_B, 0);
[email protected]8cfb6722012-11-28 03:28:46724 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38725 EXPECT_EQ("ab", UTF16ToASCII(textfield->text()));
726
727 // Deleting 2nd display. The lock window still should get the events.
728 UpdateDisplay("100x100");
[email protected]334e6182013-01-11 18:35:41729 event_generator.PressKey(ui::VKEY_C, 0);
730 event_generator.ReleaseKey(ui::VKEY_C, 0);
[email protected]8cfb6722012-11-28 03:28:46731 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38732 EXPECT_EQ("abc", UTF16ToASCII(textfield->text()));
733
734 // Creating 2nd display again, and lock window still should get events
735 // on both root windows.
736 UpdateDisplay("100x100,200x200");
737 root_windows = Shell::GetAllRootWindows();
[email protected]334e6182013-01-11 18:35:41738 event_generator.set_current_root_window(root_windows[0]);
739 event_generator.PressKey(ui::VKEY_D, 0);
740 event_generator.ReleaseKey(ui::VKEY_D, 0);
[email protected]8cfb6722012-11-28 03:28:46741 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38742 EXPECT_EQ("abcd", UTF16ToASCII(textfield->text()));
743
[email protected]334e6182013-01-11 18:35:41744 event_generator.set_current_root_window(root_windows[1]);
745 event_generator.PressKey(ui::VKEY_E, 0);
746 event_generator.ReleaseKey(ui::VKEY_E, 0);
[email protected]8cfb6722012-11-28 03:28:46747 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38748 EXPECT_EQ("abcde", UTF16ToASCII(textfield->text()));
749}
750
[email protected]334e6182013-01-11 18:35:41751TEST_F(ExtendedDesktopTest, PassiveGrab) {
752 EventLocationRecordingEventHandler event_handler;
753 ash::Shell::GetInstance()->AddPreTargetHandler(&event_handler);
754
755 UpdateDisplay("300x300,200x200");
756
757 views::Widget* widget = CreateTestWidget(gfx::Rect(50, 50, 200, 200));
758 widget->Show();
759 ASSERT_EQ("50,50 200x200", widget->GetWindowBoundsInScreen().ToString());
760
761 aura::test::EventGenerator& generator(GetEventGenerator());
762 generator.MoveMouseTo(150, 150);
763 EXPECT_EQ("100,100 150,150", event_handler.GetLocationsAndReset());
764
765 generator.PressLeftButton();
766 generator.MoveMouseTo(400, 150);
767
768 EXPECT_EQ("350,100 400,150", event_handler.GetLocationsAndReset());
769
770 generator.ReleaseLeftButton();
771 EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset());
772
773 generator.MoveMouseTo(400, 150);
774 EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset());
775
776 ash::Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
777}
778
[email protected]a5e71c92012-06-22 22:09:08779} // namespace internal
[email protected]c39be8f2012-06-15 22:58:36780} // namespace ash