blob: dbab0792c767f8af3c5638ada5a5b0ae229d6ad2 [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]e887c6c2013-07-08 19:35:537#include "ash/root_window_controller.h"
[email protected]55ad8c12014-01-17 18:24:338#include "ash/screen_util.h"
[email protected]c39be8f2012-06-15 22:58:369#include "ash/shell.h"
[email protected]e67291f12012-10-10 05:52:3810#include "ash/shell_window_ids.h"
[email protected]263898a2012-09-17 17:20:0711#include "ash/system/tray/system_tray.h"
[email protected]c39be8f2012-06-15 22:58:3612#include "ash/test/ash_test_base.h"
[email protected]7203a5e2012-08-06 18:27:4613#include "ash/wm/coordinate_conversion.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]0836da02013-06-10 19:33:3517#include "base/strings/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/test/event_generator.h"
[email protected]a5e71c92012-06-22 22:09:0822#include "ui/aura/test/test_windows.h"
[email protected]553eae12013-02-01 02:33:5223#include "ui/aura/test/window_test_api.h"
[email protected]c39be8f2012-06-15 22:58:3624#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2625#include "ui/aura/window_event_dispatcher.h"
[email protected]c39be8f2012-06-15 22:58:3626#include "ui/base/cursor/cursor.h"
[email protected]86ccbd42013-09-18 18:11:5427#include "ui/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) {
[email protected]4bfb3722013-08-14 10:47:2938 DisplayLayout layout =
39 Shell::GetInstance()->display_manager()->GetCurrentDisplayLayout();
[email protected]edbfb8d2012-09-03 08:33:4340 layout.position = position;
[email protected]efbc0502013-10-16 22:24:1541 Shell::GetInstance()->display_manager()->
[email protected]4bfb3722013-08-14 10:47:2942 SetLayoutForCurrentDisplays(layout);
[email protected]edbfb8d2012-09-03 08:33:4343}
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]334e6182013-01-11 18:35:4162// An event handler which moves the target window to the secondary root window
[email protected]2e98aaf72012-11-08 06:30:5963// at pre-handle phase of a mouse release event.
[email protected]334e6182013-01-11 18:35:4164class MoveWindowByClickEventHandler : public ui::EventHandler {
[email protected]2e98aaf72012-11-08 06:30:5965 public:
[email protected]334e6182013-01-11 18:35:4166 explicit MoveWindowByClickEventHandler(aura::Window* target)
[email protected]2e98aaf72012-11-08 06:30:5967 : target_(target) {}
[email protected]334e6182013-01-11 18:35:4168 virtual ~MoveWindowByClickEventHandler() {}
[email protected]2e98aaf72012-11-08 06:30:5969
70 private:
71 // ui::EventHandler overrides:
[email protected]d44efe02012-12-18 06:08:1872 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
[email protected]2e98aaf72012-11-08 06:30:5973 if (event->type() == ui::ET_MOUSE_RELEASED) {
[email protected]c9390bd2013-11-08 20:33:1374 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2e98aaf72012-11-08 06:30:5975 DCHECK_LT(1u, root_windows.size());
76 root_windows[1]->AddChild(target_);
77 }
[email protected]2e98aaf72012-11-08 06:30:5978 }
79
[email protected]2e98aaf72012-11-08 06:30:5980 aura::Window* target_;
[email protected]334e6182013-01-11 18:35:4181 DISALLOW_COPY_AND_ASSIGN(MoveWindowByClickEventHandler);
82};
83
84// An event handler which records the event's locations.
85class EventLocationRecordingEventHandler : public ui::EventHandler {
86 public:
87 explicit EventLocationRecordingEventHandler() {
88 reset();
89 }
90 virtual ~EventLocationRecordingEventHandler() {}
91
92 std::string GetLocationsAndReset() {
93 std::string result =
94 location_.ToString() + " " + root_location_.ToString();
95 reset();
96 return result;
97 }
98
99 private:
100 // ui::EventHandler overrides:
101 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
102 if (event->type() == ui::ET_MOUSE_MOVED ||
103 event->type() == ui::ET_MOUSE_DRAGGED) {
104 location_ = event->location();
105 root_location_ = event->root_location();
106 }
107 }
108
109 void reset() {
110 location_.SetPoint(-999, -999);
111 root_location_.SetPoint(-999, -999);
112 }
113
114 gfx::Point root_location_;
115 gfx::Point location_;
116
117 DISALLOW_COPY_AND_ASSIGN(EventLocationRecordingEventHandler);
[email protected]2e98aaf72012-11-08 06:30:59118};
119
[email protected]c39be8f2012-06-15 22:58:36120} // namespace
121
[email protected]a2e6af12013-01-07 21:40:35122class ExtendedDesktopTest : public test::AshTestBase {
123 public:
124 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
125 return CreateTestWidgetWithParentAndContext(
126 NULL, CurrentContext(), bounds, false);
127 }
128
129 views::Widget* CreateTestWidgetWithParent(views::Widget* parent,
130 const gfx::Rect& bounds,
131 bool child) {
132 CHECK(parent);
133 return CreateTestWidgetWithParentAndContext(parent, NULL, bounds, child);
134 }
135
136 views::Widget* CreateTestWidgetWithParentAndContext(views::Widget* parent,
137 gfx::NativeView context,
138 const gfx::Rect& bounds,
139 bool child) {
140 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
141 if (parent)
142 params.parent = parent->GetNativeView();
143 params.context = context;
144 params.bounds = bounds;
145 params.child = child;
146 views::Widget* widget = new views::Widget;
147 widget->Init(params);
148 widget->Show();
149 return widget;
150 }
151};
[email protected]c39be8f2012-06-15 22:58:36152
153// Test conditions that root windows in extended desktop mode
154// must satisfy.
155TEST_F(ExtendedDesktopTest, Basic) {
[email protected]e75642a2013-06-12 17:21:18156 if (!SupportsMultipleDisplays())
157 return;
158
[email protected]f634dd32012-07-23 22:49:07159 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13160 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36161
162 // All root windows must have the root window controller.
163 ASSERT_EQ(2U, root_windows.size());
[email protected]c9390bd2013-11-08 20:33:13164 for (aura::Window::Windows::const_iterator iter = root_windows.begin();
[email protected]c39be8f2012-06-15 22:58:36165 iter != root_windows.end(); ++iter) {
[email protected]6b2d4a0b2013-09-06 06:29:54166 EXPECT_TRUE(internal::GetRootWindowController(*iter) != NULL);
[email protected]c39be8f2012-06-15 22:58:36167 }
168 // Make sure root windows share the same controllers.
[email protected]8cfb6722012-11-28 03:28:46169 EXPECT_EQ(aura::client::GetFocusClient(root_windows[0]),
170 aura::client::GetFocusClient(root_windows[1]));
[email protected]c39be8f2012-06-15 22:58:36171 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]),
172 aura::client::GetActivationClient(root_windows[1]));
173 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
174 aura::client::GetCaptureClient(root_windows[1]));
175}
176
177TEST_F(ExtendedDesktopTest, Activation) {
[email protected]e75642a2013-06-12 17:21:18178 if (!SupportsMultipleDisplays())
179 return;
180
[email protected]f634dd32012-07-23 22:49:07181 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13182 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36183
[email protected]c39be8f2012-06-15 22:58:36184 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]f634dd32012-07-23 22:49:07185 views::Widget* widget_on_2nd =
186 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36187 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]f634dd32012-07-23 22:49:07188 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36189
190 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46191 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36192 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
193
[email protected]334e6182013-01-11 18:35:41194 aura::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]f634dd32012-07-23 22:49:07195 // Clicking a window changes the active window and active root window.
[email protected]334e6182013-01-11 18:35:41196 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
197 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36198
199 EXPECT_EQ(widget_on_1st->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46200 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36201 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]f634dd32012-07-23 22:49:07202
[email protected]334e6182013-01-11 18:35:41203 event_generator.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
204 event_generator.ClickLeftButton();
[email protected]f634dd32012-07-23 22:49:07205
206 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46207 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]f634dd32012-07-23 22:49:07208 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
[email protected]c39be8f2012-06-15 22:58:36209}
210
211TEST_F(ExtendedDesktopTest, SystemModal) {
[email protected]e75642a2013-06-12 17:21:18212 if (!SupportsMultipleDisplays())
213 return;
214
[email protected]f634dd32012-07-23 22:49:07215 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13216 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36217
218 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36219 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]492533b32012-09-21 19:06:14220 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]d17642d2013-09-12 23:44:38221 EXPECT_EQ(root_windows[0], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36222
[email protected]c39be8f2012-06-15 22:58:36223 // Open system modal. Make sure it's on 2nd root window and active.
[email protected]a2e6af12013-01-07 21:40:35224 views::Widget* modal_widget = views::Widget::CreateWindowWithContextAndBounds(
225 new ModalWidgetDelegate(),
226 CurrentContext(),
227 gfx::Rect(1200, 100, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36228 modal_widget->Show();
229 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
230 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow());
[email protected]d17642d2013-09-12 23:44:38231 EXPECT_EQ(root_windows[1], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36232
[email protected]334e6182013-01-11 18:35:41233 aura::test::EventGenerator& event_generator(GetEventGenerator());
234
[email protected]2e236a52012-06-27 22:21:47235 // Clicking a widget on widget_on_1st display should not change activation.
[email protected]334e6182013-01-11 18:35:41236 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
237 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36238 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
[email protected]d17642d2013-09-12 23:44:38239 EXPECT_EQ(root_windows[1], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36240
241 // Close system modal and so clicking a widget should work now.
242 modal_widget->Close();
[email protected]334e6182013-01-11 18:35:41243 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
244 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36245 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]d17642d2013-09-12 23:44:38246 EXPECT_EQ(root_windows[0], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36247}
248
249TEST_F(ExtendedDesktopTest, TestCursor) {
[email protected]e75642a2013-06-12 17:21:18250 if (!SupportsMultipleDisplays())
251 return;
252
[email protected]f634dd32012-07-23 22:49:07253 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13254 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2374d1812014-03-04 03:42:27255 aura::WindowTreeHost* host0 = root_windows[0]->GetHost();
256 aura::WindowTreeHost* host1 = root_windows[1]->GetHost();
257 EXPECT_EQ(ui::kCursorPointer, host0->last_cursor().native_type());
258 EXPECT_EQ(ui::kCursorPointer, host1->last_cursor().native_type());
[email protected]151ffdff2012-09-11 20:18:35259 Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy);
[email protected]2374d1812014-03-04 03:42:27260 EXPECT_EQ(ui::kCursorCopy, host0->last_cursor().native_type());
261 EXPECT_EQ(ui::kCursorCopy, host1->last_cursor().native_type());
[email protected]c39be8f2012-06-15 22:58:36262}
263
[email protected]718b26c2012-07-24 20:53:23264TEST_F(ExtendedDesktopTest, TestCursorLocation) {
[email protected]e75642a2013-06-12 17:21:18265 if (!SupportsMultipleDisplays())
266 return;
267
[email protected]d0064722013-03-14 18:16:43268 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13269 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]553eae12013-02-01 02:33:52270 aura::test::WindowTestApi root_window0_test_api(root_windows[0]);
271 aura::test::WindowTestApi root_window1_test_api(root_windows[1]);
[email protected]718b26c2012-07-24 20:53:23272
273 root_windows[0]->MoveCursorTo(gfx::Point(10, 10));
[email protected]ffabb1e2012-10-12 19:51:17274 EXPECT_EQ("10,10", Shell::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23275 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
276 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
277 root_windows[1]->MoveCursorTo(gfx::Point(10, 20));
[email protected]ffabb1e2012-10-12 19:51:17278 EXPECT_EQ("1010,20", Shell::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23279 EXPECT_FALSE(root_window0_test_api.ContainsMouse());
280 EXPECT_TRUE(root_window1_test_api.ContainsMouse());
281 root_windows[0]->MoveCursorTo(gfx::Point(20, 10));
[email protected]ffabb1e2012-10-12 19:51:17282 EXPECT_EQ("20,10", Shell::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23283 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
284 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
285}
286
[email protected]0f81f442012-06-22 06:20:27287TEST_F(ExtendedDesktopTest, CycleWindows) {
[email protected]e75642a2013-06-12 17:21:18288 if (!SupportsMultipleDisplays())
289 return;
290
[email protected]f634dd32012-07-23 22:49:07291 UpdateDisplay("700x500,500x500");
[email protected]c9390bd2013-11-08 20:33:13292 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24293
[email protected]0f81f442012-06-22 06:20:27294 WindowCycleController* controller =
295 Shell::GetInstance()->window_cycle_controller();
296
[email protected]0f81f442012-06-22 06:20:27297 views::Widget* d1_w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
298 EXPECT_EQ(root_windows[0], d1_w1->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24299 views::Widget* d2_w1 = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
[email protected]0f81f442012-06-22 06:20:27300 EXPECT_EQ(root_windows[1], d2_w1->GetNativeView()->GetRootWindow());
301 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
302
303 controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
304 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
305 controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
306 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
307 controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
308 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
309 controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
310 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
311
312 // Cycle through all windows across root windows.
[email protected]20c59762012-06-23 01:10:24313 views::Widget* d1_w2 = CreateTestWidget(gfx::Rect(10, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27314 EXPECT_EQ(root_windows[0], d1_w2->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24315 views::Widget* d2_w2 = CreateTestWidget(gfx::Rect(800, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27316 EXPECT_EQ(root_windows[1], d2_w2->GetNativeView()->GetRootWindow());
317
318 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]0f81f442012-06-22 06:20:27319 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
320 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]8fef7432012-08-06 15:34:25321 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
322 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]0f81f442012-06-22 06:20:27323 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
324 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
325 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
326
327 // Backwards
328 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
329 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
330 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]0f81f442012-06-22 06:20:27331 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
332 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]8fef7432012-08-06 15:34:25333 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
334 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]0f81f442012-06-22 06:20:27335 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
[email protected]20c59762012-06-23 01:10:24336}
337
338TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
[email protected]e75642a2013-06-12 17:21:18339 if (!SupportsMultipleDisplays())
340 return;
341
[email protected]f634dd32012-07-23 22:49:07342 UpdateDisplay("700x500,500x500");
[email protected]edbfb8d2012-09-03 08:33:43343 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]c9390bd2013-11-08 20:33:13344 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24345
[email protected]7203a5e2012-08-06 18:27:46346 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100)));
347 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100)));
348 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300)));
349 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700,300)));
[email protected]20c59762012-06-23 01:10:24350
351 // Zero origin.
[email protected]7203a5e2012-08-06 18:27:46352 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0)));
[email protected]20c59762012-06-23 01:10:24353
[email protected]36168852014-01-07 12:23:28354 // Out of range point should return the nearest root window
355 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-600, 0)));
[email protected]7203a5e2012-08-06 18:27:46356 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100)));
[email protected]20c59762012-06-23 01:10:24357}
358
359TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
[email protected]e75642a2013-06-12 17:21:18360 if (!SupportsMultipleDisplays())
361 return;
362
[email protected]f634dd32012-07-23 22:49:07363 UpdateDisplay("700x500,500x500");
[email protected]edbfb8d2012-09-03 08:33:43364 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]66b05eac2012-06-27 23:53:10365
[email protected]c9390bd2013-11-08 20:33:13366 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24367
368 // Containing rect.
369 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46370 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24371 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46372 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24373
374 // Intersecting rect.
375 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46376 wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24377 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46378 wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24379
380 // Zero origin.
[email protected]66b05eac2012-06-27 23:53:10381 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46382 wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0)));
[email protected]66b05eac2012-06-27 23:53:10383 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46384 wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1)));
[email protected]20c59762012-06-23 01:10:24385
386 // Empty rect.
387 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46388 wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24389 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46390 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24391
392 // Out of range rect should return the primary root window.
393 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46394 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50)));
[email protected]20c59762012-06-23 01:10:24395 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46396 wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50)));
[email protected]0f81f442012-06-22 06:20:27397}
398
[email protected]1a015382012-12-01 19:44:59399TEST_F(ExtendedDesktopTest, Capture) {
[email protected]e75642a2013-06-12 17:21:18400 if (!SupportsMultipleDisplays())
401 return;
402
[email protected]f634dd32012-07-23 22:49:07403 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13404 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a5e71c92012-06-22 22:09:08405
406 aura::test::EventCountDelegate r1_d1;
407 aura::test::EventCountDelegate r1_d2;
408 aura::test::EventCountDelegate r2_d1;
409
410 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
411 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
412 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
413 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
414 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
415 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
[email protected]f634dd32012-07-23 22:49:07416
[email protected]a5e71c92012-06-22 22:09:08417 r1_w1->SetCapture();
418
419 EXPECT_EQ(r1_w1.get(),
420 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]334e6182013-01-11 18:35:41421
[email protected]d05cf2f2014-02-26 05:31:43422 aura::test::EventGenerator& generator = GetEventGenerator();
423 generator.MoveMouseToCenterOf(r2_w1.get());
424 // |r1_w1| will receive the events because it has capture.
425 EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset());
426 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
427 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
428
429 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08430 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
431 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]b19ba4adf2012-09-07 16:13:29432 // The mouse is outside. On chromeos, the mouse is warped to the
433 // dest root window, but it's not implemented on Win yet, so
434 // no mouse move event on Win.
[email protected]d05cf2f2014-02-26 05:31:43435 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08436 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43437
438 generator.MoveMouseTo(15, 15);
[email protected]f634dd32012-07-23 22:49:07439 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43440 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08441
442 r1_w2->SetCapture();
443 EXPECT_EQ(r1_w2.get(),
444 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43445 generator.MoveMouseBy(10, 10);
446 // |r1_w2| has the capture. So it will receive the mouse-move event.
447 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
448 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset());
449 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
450
451 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08452 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
453 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43454 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08455 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43456
[email protected]a5e71c92012-06-22 22:09:08457 r1_w2->ReleaseCapture();
[email protected]36f566532012-09-19 04:07:24458 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43459
460 generator.MoveMouseToCenterOf(r2_w1.get());
461 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08462 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
463 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
464 // Make sure the mouse_moved_handler_ is properly reset.
465 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
466 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
467}
468
[email protected]f059c6942012-07-21 14:27:57469TEST_F(ExtendedDesktopTest, MoveWindow) {
[email protected]e75642a2013-06-12 17:21:18470 if (!SupportsMultipleDisplays())
471 return;
472
[email protected]f634dd32012-07-23 22:49:07473 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13474 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f059c6942012-07-21 14:27:57475 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
476
477 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
478
479 d1->SetBounds(gfx::Rect(1010, 10, 100, 100));
480 EXPECT_EQ("1010,10 100x100",
481 d1->GetWindowBoundsInScreen().ToString());
482
483 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
484
485 d1->SetBounds(gfx::Rect(10, 10, 100, 100));
486 EXPECT_EQ("10,10 100x100",
487 d1->GetWindowBoundsInScreen().ToString());
488
489 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
490
491 // Make sure the bounds which doesn't fit to the root window
492 // works correctly.
493 d1->SetBounds(gfx::Rect(1560, 30, 100, 100));
494 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
495 EXPECT_EQ("1560,30 100x100",
496 d1->GetWindowBoundsInScreen().ToString());
497
498 // Setting outside of root windows will be moved to primary root window.
499 // TODO(oshima): This one probably should pick the closest root window.
500 d1->SetBounds(gfx::Rect(200, 10, 100, 100));
501 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
[email protected]f059c6942012-07-21 14:27:57502}
503
[email protected]2e98aaf72012-11-08 06:30:59504// Verifies if the mouse event arrives to the window even when the window
505// moves to another root in a pre-target handler. See: crbug.com/157583
506TEST_F(ExtendedDesktopTest, MoveWindowByMouseClick) {
[email protected]e75642a2013-06-12 17:21:18507 if (!SupportsMultipleDisplays())
508 return;
509
[email protected]2e98aaf72012-11-08 06:30:59510 UpdateDisplay("1000x600,600x400");
511
[email protected]c9390bd2013-11-08 20:33:13512 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2e98aaf72012-11-08 06:30:59513 aura::test::EventCountDelegate delegate;
514 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate(
515 &delegate, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
[email protected]334e6182013-01-11 18:35:41516 MoveWindowByClickEventHandler event_handler(window.get());
517 window->AddPreTargetHandler(&event_handler);
518
519 aura::test::EventGenerator& event_generator(GetEventGenerator());
520
521 event_generator.MoveMouseToCenterOf(window.get());
522 event_generator.ClickLeftButton();
[email protected]2e98aaf72012-11-08 06:30:59523 // Both mouse pressed and released arrive at the window and its delegate.
524 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset());
[email protected]334e6182013-01-11 18:35:41525 // Also event_handler moves the window to another root at mouse release.
[email protected]2e98aaf72012-11-08 06:30:59526 EXPECT_EQ(root_windows[1], window->GetRootWindow());
527}
528
[email protected]1a015382012-12-01 19:44:59529TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) {
[email protected]e75642a2013-06-12 17:21:18530 if (!SupportsMultipleDisplays())
531 return;
532
[email protected]e79f26e2012-08-09 07:12:48533 UpdateDisplay("1000x1000,1000x1000");
[email protected]c9390bd2013-11-08 20:33:13534 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e79f26e2012-08-09 07:12:48535
[email protected]ffabb1e2012-10-12 19:51:17536 gfx::Display display0 = Shell::GetScreen()->GetDisplayMatching(
537 root_windows[0]->GetBoundsInScreen());
538 gfx::Display display1 = Shell::GetScreen()->GetDisplayMatching(
539 root_windows[1]->GetBoundsInScreen());
[email protected]e79f26e2012-08-09 07:12:48540 EXPECT_NE(display0.id(), display1.id());
541
542 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100));
543 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
544
545 // Move the window where the window spans both root windows. Since the second
546 // parameter is |display1|, the window should be shown on the secondary root.
547 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
548 display1);
549 EXPECT_EQ("500,10 1000x100",
550 d1->GetWindowBoundsInScreen().ToString());
551 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
552
553 // Move to the primary root.
554 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
555 display0);
556 EXPECT_EQ("500,10 1000x100",
557 d1->GetWindowBoundsInScreen().ToString());
558 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
559}
560
[email protected]f059c6942012-07-21 14:27:57561TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
[email protected]e75642a2013-06-12 17:21:18562 if (!SupportsMultipleDisplays())
563 return;
564
[email protected]f634dd32012-07-23 22:49:07565 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13566 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f059c6942012-07-21 14:27:57567 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
568 views::Widget* w1_t1 = CreateTestWidgetWithParent(
569 w1, gfx::Rect(50, 50, 50, 50), false /* transient */);
570 // Transient child of the transient child.
571 views::Widget* w1_t11 = CreateTestWidgetWithParent(
572 w1_t1, gfx::Rect(1200, 70, 30, 30), false /* transient */);
573
574 views::Widget* w11 = CreateTestWidgetWithParent(
575 w1, gfx::Rect(10, 10, 40, 40), true /* child */);
576 views::Widget* w11_t1 = CreateTestWidgetWithParent(
577 w1, gfx::Rect(1300, 100, 80, 80), false /* transient */);
578
579 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
580 EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow());
581 EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow());
582 EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow());
583 EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow());
584 EXPECT_EQ("50,50 50x50",
585 w1_t1->GetWindowBoundsInScreen().ToString());
586 EXPECT_EQ("1200,70 30x30",
587 w1_t11->GetWindowBoundsInScreen().ToString());
588 EXPECT_EQ("20,20 40x40",
589 w11->GetWindowBoundsInScreen().ToString());
590 EXPECT_EQ("1300,100 80x80",
591 w11_t1->GetWindowBoundsInScreen().ToString());
592
593 w1->SetBounds(gfx::Rect(1100,10,100,100));
594
595 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
596 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
597 EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow());
598 EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow());
599 EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow());
600
601 EXPECT_EQ("1110,20 40x40",
602 w11->GetWindowBoundsInScreen().ToString());
603 // Transient window's screen bounds stays the same.
604 EXPECT_EQ("50,50 50x50",
605 w1_t1->GetWindowBoundsInScreen().ToString());
606 EXPECT_EQ("1200,70 30x30",
607 w1_t11->GetWindowBoundsInScreen().ToString());
608 EXPECT_EQ("1300,100 80x80",
609 w11_t1->GetWindowBoundsInScreen().ToString());
610
611 // Transient window doesn't move between root window unless
612 // its transient parent moves.
613 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50));
614 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
615 EXPECT_EQ("10,50 50x50",
616 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57617}
618
[email protected]ca7060982012-08-08 18:05:25619// Test if the Window::ConvertPointToTarget works across root windows.
[email protected]a5e71c92012-06-22 22:09:08620// TODO(oshima): Move multiple display suport and this test to aura.
621TEST_F(ExtendedDesktopTest, ConvertPoint) {
[email protected]e75642a2013-06-12 17:21:18622 if (!SupportsMultipleDisplays())
623 return;
[email protected]55ad8c12014-01-17 18:24:33624 gfx::Screen* screen = Shell::GetScreen();
[email protected]f634dd32012-07-23 22:49:07625 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13626 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]b8984242013-07-12 07:55:38627 gfx::Display display_1 = screen->GetDisplayNearestWindow(root_windows[0]);
[email protected]a5e71c92012-06-22 22:09:08628 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
[email protected]b8984242013-07-12 07:55:38629 gfx::Display display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07630 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
631
[email protected]a5e71c92012-06-22 22:09:08632 aura::Window* d1 =
633 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
[email protected]a5e71c92012-06-22 22:09:08634 aura::Window* d2 =
[email protected]f634dd32012-07-23 22:49:07635 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
636 EXPECT_EQ(root_windows[0], d1->GetRootWindow());
637 EXPECT_EQ(root_windows[1], d2->GetRootWindow());
[email protected]a5e71c92012-06-22 22:09:08638
[email protected]a5e71c92012-06-22 22:09:08639 // Convert point in the Root2's window to the Root1's window Coord.
640 gfx::Point p(0, 0);
[email protected]ca7060982012-08-08 18:05:25641 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07642 EXPECT_EQ("1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08643 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25644 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07645 EXPECT_EQ("1010,10", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08646
647 // Convert point in the Root1's window to the Root2's window Coord.
648 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25649 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07650 EXPECT_EQ("-1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08651 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25652 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07653 EXPECT_EQ("-1010,-10", p.ToString());
654
655 // Move the 2nd display to the bottom and test again.
[email protected]edbfb8d2012-09-03 08:33:43656 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
[email protected]f634dd32012-07-23 22:49:07657
[email protected]b8984242013-07-12 07:55:38658 display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07659 EXPECT_EQ("0,600", display_2.bounds().origin().ToString());
660
661 // Convert point in Root2's window to Root1's window Coord.
662 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25663 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07664 EXPECT_EQ("0,600", p.ToString());
665 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25666 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07667 EXPECT_EQ("10,610", p.ToString());
668
669 // Convert point in Root1's window to Root2's window Coord.
670 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25671 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07672 EXPECT_EQ("0,-600", p.ToString());
673 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25674 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07675 EXPECT_EQ("-10,-610", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08676}
[email protected]f634dd32012-07-23 22:49:07677
[email protected]263898a2012-09-17 17:20:07678TEST_F(ExtendedDesktopTest, OpenSystemTray) {
[email protected]e75642a2013-06-12 17:21:18679 if (!SupportsMultipleDisplays())
680 return;
681
[email protected]596c61c2012-10-29 17:29:43682 UpdateDisplay("500x600,600x400");
[email protected]a0afeb12012-12-10 22:57:09683 SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray();
[email protected]263898a2012-09-17 17:20:07684 ASSERT_FALSE(tray->HasSystemBubble());
685
[email protected]334e6182013-01-11 18:35:41686 aura::test::EventGenerator& event_generator(GetEventGenerator());
687
[email protected]263898a2012-09-17 17:20:07688 // Opens the tray by a dummy click event and makes sure that adding/removing
689 // displays doesn't break anything.
[email protected]334e6182013-01-11 18:35:41690 event_generator.MoveMouseToCenterOf(tray->GetWidget()->GetNativeWindow());
[email protected]263898a2012-09-17 17:20:07691 event_generator.ClickLeftButton();
692 EXPECT_TRUE(tray->HasSystemBubble());
693
[email protected]596c61c2012-10-29 17:29:43694 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07695 EXPECT_TRUE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43696 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07697 EXPECT_TRUE(tray->HasSystemBubble());
698
699 // Closes the tray and again makes sure that adding/removing displays doesn't
700 // break anything.
701 event_generator.ClickLeftButton();
702 RunAllPendingInMessageLoop();
703
704 EXPECT_FALSE(tray->HasSystemBubble());
705
[email protected]596c61c2012-10-29 17:29:43706 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07707 EXPECT_FALSE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43708 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07709 EXPECT_FALSE(tray->HasSystemBubble());
710}
711
[email protected]578048512012-09-19 20:01:24712TEST_F(ExtendedDesktopTest, StayInSameRootWindow) {
[email protected]e75642a2013-06-12 17:21:18713 if (!SupportsMultipleDisplays())
714 return;
715
[email protected]578048512012-09-19 20:01:24716 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13717 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a2e6af12013-01-07 21:40:35718 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 50, 50));
[email protected]578048512012-09-19 20:01:24719 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
720 w1->SetBounds(gfx::Rect(150, 10, 50, 50));
721 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
722
723 // The widget stays in the same root if kStayInSameRootWindowKey is set to
724 // true.
725 w1->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, true);
726 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
727 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
728
729 // The widget should now move to the 1st root window without the property.
730 w1->GetNativeView()->ClearProperty(internal::kStayInSameRootWindowKey);
731 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
732 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
[email protected]e887c6c2013-07-08 19:35:53733
734 // a window in SettingsBubbleContainer and StatusContainer should
735 // not move to another root window regardles of the bounds specified.
736 aura::Window* settings_bubble_container =
737 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]b8984242013-07-12 07:55:38738 internal::kShellWindowId_SettingBubbleContainer);
[email protected]e887c6c2013-07-08 19:35:53739 aura::Window* window = aura::test::CreateTestWindowWithId(
740 100, settings_bubble_container);
741 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50),
[email protected]55ad8c12014-01-17 18:24:33742 ScreenUtil::GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53743 EXPECT_EQ(root_windows[0], window->GetRootWindow());
744
745 aura::Window* status_container =
746 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]b8984242013-07-12 07:55:38747 internal::kShellWindowId_StatusContainer);
[email protected]e887c6c2013-07-08 19:35:53748 window = aura::test::CreateTestWindowWithId(100, status_container);
749 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50),
[email protected]55ad8c12014-01-17 18:24:33750 ScreenUtil::GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53751 EXPECT_EQ(root_windows[0], window->GetRootWindow());
[email protected]578048512012-09-19 20:01:24752}
753
[email protected]e67291f12012-10-10 05:52:38754TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) {
[email protected]e75642a2013-06-12 17:21:18755 if (!SupportsMultipleDisplays())
756 return;
757
[email protected]e67291f12012-10-10 05:52:38758 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13759 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e67291f12012-10-10 05:52:38760
761 // Create normal windows on both displays.
762 views::Widget* widget1 = CreateTestWidget(
[email protected]ffabb1e2012-10-12 19:51:17763 Shell::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38764 widget1->Show();
765 EXPECT_EQ(root_windows[0], widget1->GetNativeView()->GetRootWindow());
766 views::Widget* widget2 = CreateTestWidget(
[email protected]55ad8c12014-01-17 18:24:33767 ScreenUtil::GetSecondaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38768 widget2->Show();
769 EXPECT_EQ(root_windows[1], widget2->GetNativeView()->GetRootWindow());
770
771 // Create a LockScreen window.
772 views::Widget* lock_widget = CreateTestWidget(
[email protected]ffabb1e2012-10-12 19:51:17773 Shell::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38774 views::Textfield* textfield = new views::Textfield;
[email protected]09148952013-03-13 13:25:43775 lock_widget->client_view()->AddChildView(textfield);
[email protected]e67291f12012-10-10 05:52:38776
777 ash::Shell::GetContainer(
778 Shell::GetPrimaryRootWindow(),
779 ash::internal::kShellWindowId_LockScreenContainer)->
780 AddChild(lock_widget->GetNativeView());
781 lock_widget->Show();
782 textfield->RequestFocus();
783
[email protected]8cfb6722012-11-28 03:28:46784 aura::client::FocusClient* focus_client =
785 aura::client::GetFocusClient(root_windows[0]);
786 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38787
788 // The lock window should get events on both root windows.
[email protected]334e6182013-01-11 18:35:41789 aura::test::EventGenerator& event_generator(GetEventGenerator());
790
[email protected]a06955222014-03-10 22:47:32791 event_generator.set_current_host(root_windows[0]->GetHost());
[email protected]334e6182013-01-11 18:35:41792 event_generator.PressKey(ui::VKEY_A, 0);
793 event_generator.ReleaseKey(ui::VKEY_A, 0);
[email protected]8cfb6722012-11-28 03:28:46794 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38795 EXPECT_EQ("a", UTF16ToASCII(textfield->text()));
796
[email protected]a06955222014-03-10 22:47:32797 event_generator.set_current_host(root_windows[1]->GetHost());
[email protected]334e6182013-01-11 18:35:41798 event_generator.PressKey(ui::VKEY_B, 0);
799 event_generator.ReleaseKey(ui::VKEY_B, 0);
[email protected]8cfb6722012-11-28 03:28:46800 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38801 EXPECT_EQ("ab", UTF16ToASCII(textfield->text()));
802
803 // Deleting 2nd display. The lock window still should get the events.
804 UpdateDisplay("100x100");
[email protected]334e6182013-01-11 18:35:41805 event_generator.PressKey(ui::VKEY_C, 0);
806 event_generator.ReleaseKey(ui::VKEY_C, 0);
[email protected]8cfb6722012-11-28 03:28:46807 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38808 EXPECT_EQ("abc", UTF16ToASCII(textfield->text()));
809
810 // Creating 2nd display again, and lock window still should get events
811 // on both root windows.
812 UpdateDisplay("100x100,200x200");
813 root_windows = Shell::GetAllRootWindows();
[email protected]a06955222014-03-10 22:47:32814 event_generator.set_current_host(root_windows[0]->GetHost());
[email protected]334e6182013-01-11 18:35:41815 event_generator.PressKey(ui::VKEY_D, 0);
816 event_generator.ReleaseKey(ui::VKEY_D, 0);
[email protected]8cfb6722012-11-28 03:28:46817 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38818 EXPECT_EQ("abcd", UTF16ToASCII(textfield->text()));
819
[email protected]a06955222014-03-10 22:47:32820 event_generator.set_current_host(root_windows[1]->GetHost());
[email protected]334e6182013-01-11 18:35:41821 event_generator.PressKey(ui::VKEY_E, 0);
822 event_generator.ReleaseKey(ui::VKEY_E, 0);
[email protected]8cfb6722012-11-28 03:28:46823 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38824 EXPECT_EQ("abcde", UTF16ToASCII(textfield->text()));
825}
826
[email protected]334e6182013-01-11 18:35:41827TEST_F(ExtendedDesktopTest, PassiveGrab) {
[email protected]e75642a2013-06-12 17:21:18828 if (!SupportsMultipleDisplays())
829 return;
830
[email protected]334e6182013-01-11 18:35:41831 EventLocationRecordingEventHandler event_handler;
832 ash::Shell::GetInstance()->AddPreTargetHandler(&event_handler);
833
834 UpdateDisplay("300x300,200x200");
835
836 views::Widget* widget = CreateTestWidget(gfx::Rect(50, 50, 200, 200));
837 widget->Show();
838 ASSERT_EQ("50,50 200x200", widget->GetWindowBoundsInScreen().ToString());
839
840 aura::test::EventGenerator& generator(GetEventGenerator());
841 generator.MoveMouseTo(150, 150);
842 EXPECT_EQ("100,100 150,150", event_handler.GetLocationsAndReset());
843
844 generator.PressLeftButton();
845 generator.MoveMouseTo(400, 150);
846
847 EXPECT_EQ("350,100 400,150", event_handler.GetLocationsAndReset());
848
849 generator.ReleaseLeftButton();
850 EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset());
851
852 generator.MoveMouseTo(400, 150);
853 EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset());
854
855 ash::Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
856}
857
[email protected]c39be8f2012-06-15 22:58:36858} // namespace ash