blob: eb8591d01a57f57da03fc685497694c844c750c7 [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]578048512012-09-19 20:01:2414#include "ash/wm/window_properties.h"
[email protected]c39be8f2012-06-15 22:58:3615#include "ash/wm/window_util.h"
[email protected]0836da02013-06-10 19:33:3516#include "base/strings/string_util.h"
[email protected]74f778e2014-03-14 21:11:4617#include "base/strings/utf_string_conversions.h"
[email protected]c39be8f2012-06-15 22:58:3618#include "ui/aura/client/capture_client.h"
[email protected]8cfb6722012-11-28 03:28:4619#include "ui/aura/client/focus_client.h"
[email protected]c39be8f2012-06-15 22:58:3620#include "ui/aura/test/event_generator.h"
[email protected]a5e71c92012-06-22 22:09:0821#include "ui/aura/test/test_windows.h"
[email protected]553eae12013-02-01 02:33:5222#include "ui/aura/test/window_test_api.h"
[email protected]c39be8f2012-06-15 22:58:3623#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2624#include "ui/aura/window_event_dispatcher.h"
[email protected]c39be8f2012-06-15 22:58:3625#include "ui/base/cursor/cursor.h"
[email protected]86ccbd42013-09-18 18:11:5426#include "ui/events/event_handler.h"
[email protected]a5e71c92012-06-22 22:09:0827#include "ui/gfx/display.h"
[email protected]718b26c2012-07-24 20:53:2328#include "ui/gfx/screen.h"
[email protected]e67291f12012-10-10 05:52:3829#include "ui/views/controls/textfield/textfield.h"
[email protected]c39be8f2012-06-15 22:58:3630#include "ui/views/widget/widget.h"
31#include "ui/views/widget/widget_delegate.h"
[email protected]af4552b22014-03-21 19:45:0132#include "ui/wm/public/activation_client.h"
[email protected]c39be8f2012-06-15 22:58:3633
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]093b8d642014-04-03 20:59:28166 EXPECT_TRUE(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]20c59762012-06-23 01:10:24287TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
[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]edbfb8d2012-09-03 08:33:43292 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]c9390bd2013-11-08 20:33:13293 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24294
[email protected]7203a5e2012-08-06 18:27:46295 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100)));
296 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100)));
297 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300)));
298 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700,300)));
[email protected]20c59762012-06-23 01:10:24299
300 // Zero origin.
[email protected]7203a5e2012-08-06 18:27:46301 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0)));
[email protected]20c59762012-06-23 01:10:24302
[email protected]36168852014-01-07 12:23:28303 // Out of range point should return the nearest root window
304 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-600, 0)));
[email protected]7203a5e2012-08-06 18:27:46305 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100)));
[email protected]20c59762012-06-23 01:10:24306}
307
308TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
[email protected]e75642a2013-06-12 17:21:18309 if (!SupportsMultipleDisplays())
310 return;
311
[email protected]f634dd32012-07-23 22:49:07312 UpdateDisplay("700x500,500x500");
[email protected]edbfb8d2012-09-03 08:33:43313 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]66b05eac2012-06-27 23:53:10314
[email protected]c9390bd2013-11-08 20:33:13315 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24316
317 // Containing rect.
318 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46319 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24320 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46321 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24322
323 // Intersecting rect.
324 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46325 wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24326 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46327 wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24328
329 // Zero origin.
[email protected]66b05eac2012-06-27 23:53:10330 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46331 wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0)));
[email protected]66b05eac2012-06-27 23:53:10332 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46333 wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1)));
[email protected]20c59762012-06-23 01:10:24334
335 // Empty rect.
336 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46337 wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24338 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46339 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24340
341 // Out of range rect should return the primary root window.
342 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46343 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50)));
[email protected]20c59762012-06-23 01:10:24344 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46345 wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50)));
[email protected]0f81f442012-06-22 06:20:27346}
347
[email protected]1a015382012-12-01 19:44:59348TEST_F(ExtendedDesktopTest, Capture) {
[email protected]e75642a2013-06-12 17:21:18349 if (!SupportsMultipleDisplays())
350 return;
351
[email protected]f634dd32012-07-23 22:49:07352 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13353 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a5e71c92012-06-22 22:09:08354
355 aura::test::EventCountDelegate r1_d1;
356 aura::test::EventCountDelegate r1_d2;
357 aura::test::EventCountDelegate r2_d1;
358
359 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
360 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
361 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
362 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
363 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
364 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
[email protected]f634dd32012-07-23 22:49:07365
[email protected]a5e71c92012-06-22 22:09:08366 r1_w1->SetCapture();
367
368 EXPECT_EQ(r1_w1.get(),
369 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]334e6182013-01-11 18:35:41370
[email protected]d05cf2f2014-02-26 05:31:43371 aura::test::EventGenerator& generator = GetEventGenerator();
372 generator.MoveMouseToCenterOf(r2_w1.get());
373 // |r1_w1| will receive the events because it has capture.
374 EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset());
375 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
376 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
377
378 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08379 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
380 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]b19ba4adf2012-09-07 16:13:29381 // The mouse is outside. On chromeos, the mouse is warped to the
382 // dest root window, but it's not implemented on Win yet, so
383 // no mouse move event on Win.
[email protected]d05cf2f2014-02-26 05:31:43384 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08385 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43386
387 generator.MoveMouseTo(15, 15);
[email protected]f634dd32012-07-23 22:49:07388 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43389 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08390
391 r1_w2->SetCapture();
392 EXPECT_EQ(r1_w2.get(),
393 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43394 generator.MoveMouseBy(10, 10);
395 // |r1_w2| has the capture. So it will receive the mouse-move event.
396 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
397 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset());
398 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
399
400 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08401 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
402 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43403 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08404 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43405
[email protected]a5e71c92012-06-22 22:09:08406 r1_w2->ReleaseCapture();
[email protected]36f566532012-09-19 04:07:24407 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43408
409 generator.MoveMouseToCenterOf(r2_w1.get());
410 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08411 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
412 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
413 // Make sure the mouse_moved_handler_ is properly reset.
414 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
415 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
416}
417
[email protected]f059c6942012-07-21 14:27:57418TEST_F(ExtendedDesktopTest, MoveWindow) {
[email protected]e75642a2013-06-12 17:21:18419 if (!SupportsMultipleDisplays())
420 return;
421
[email protected]f634dd32012-07-23 22:49:07422 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13423 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f059c6942012-07-21 14:27:57424 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
425
426 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
427
428 d1->SetBounds(gfx::Rect(1010, 10, 100, 100));
429 EXPECT_EQ("1010,10 100x100",
430 d1->GetWindowBoundsInScreen().ToString());
431
432 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
433
434 d1->SetBounds(gfx::Rect(10, 10, 100, 100));
435 EXPECT_EQ("10,10 100x100",
436 d1->GetWindowBoundsInScreen().ToString());
437
438 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
439
440 // Make sure the bounds which doesn't fit to the root window
441 // works correctly.
442 d1->SetBounds(gfx::Rect(1560, 30, 100, 100));
443 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
444 EXPECT_EQ("1560,30 100x100",
445 d1->GetWindowBoundsInScreen().ToString());
446
447 // Setting outside of root windows will be moved to primary root window.
448 // TODO(oshima): This one probably should pick the closest root window.
449 d1->SetBounds(gfx::Rect(200, 10, 100, 100));
450 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
[email protected]f059c6942012-07-21 14:27:57451}
452
[email protected]2e98aaf72012-11-08 06:30:59453// Verifies if the mouse event arrives to the window even when the window
454// moves to another root in a pre-target handler. See: crbug.com/157583
455TEST_F(ExtendedDesktopTest, MoveWindowByMouseClick) {
[email protected]e75642a2013-06-12 17:21:18456 if (!SupportsMultipleDisplays())
457 return;
458
[email protected]2e98aaf72012-11-08 06:30:59459 UpdateDisplay("1000x600,600x400");
460
[email protected]c9390bd2013-11-08 20:33:13461 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2e98aaf72012-11-08 06:30:59462 aura::test::EventCountDelegate delegate;
463 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate(
464 &delegate, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
[email protected]334e6182013-01-11 18:35:41465 MoveWindowByClickEventHandler event_handler(window.get());
466 window->AddPreTargetHandler(&event_handler);
467
468 aura::test::EventGenerator& event_generator(GetEventGenerator());
469
470 event_generator.MoveMouseToCenterOf(window.get());
471 event_generator.ClickLeftButton();
[email protected]2e98aaf72012-11-08 06:30:59472 // Both mouse pressed and released arrive at the window and its delegate.
473 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset());
[email protected]334e6182013-01-11 18:35:41474 // Also event_handler moves the window to another root at mouse release.
[email protected]2e98aaf72012-11-08 06:30:59475 EXPECT_EQ(root_windows[1], window->GetRootWindow());
476}
477
[email protected]1a015382012-12-01 19:44:59478TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) {
[email protected]e75642a2013-06-12 17:21:18479 if (!SupportsMultipleDisplays())
480 return;
481
[email protected]e79f26e2012-08-09 07:12:48482 UpdateDisplay("1000x1000,1000x1000");
[email protected]c9390bd2013-11-08 20:33:13483 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e79f26e2012-08-09 07:12:48484
[email protected]ffabb1e2012-10-12 19:51:17485 gfx::Display display0 = Shell::GetScreen()->GetDisplayMatching(
486 root_windows[0]->GetBoundsInScreen());
487 gfx::Display display1 = Shell::GetScreen()->GetDisplayMatching(
488 root_windows[1]->GetBoundsInScreen());
[email protected]e79f26e2012-08-09 07:12:48489 EXPECT_NE(display0.id(), display1.id());
490
491 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100));
492 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
493
494 // Move the window where the window spans both root windows. Since the second
495 // parameter is |display1|, the window should be shown on the secondary root.
496 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
497 display1);
498 EXPECT_EQ("500,10 1000x100",
499 d1->GetWindowBoundsInScreen().ToString());
500 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
501
502 // Move to the primary root.
503 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
504 display0);
505 EXPECT_EQ("500,10 1000x100",
506 d1->GetWindowBoundsInScreen().ToString());
507 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
508}
509
[email protected]f059c6942012-07-21 14:27:57510TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
[email protected]e75642a2013-06-12 17:21:18511 if (!SupportsMultipleDisplays())
512 return;
513
[email protected]f634dd32012-07-23 22:49:07514 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13515 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f059c6942012-07-21 14:27:57516 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
517 views::Widget* w1_t1 = CreateTestWidgetWithParent(
518 w1, gfx::Rect(50, 50, 50, 50), false /* transient */);
519 // Transient child of the transient child.
520 views::Widget* w1_t11 = CreateTestWidgetWithParent(
[email protected]e6de8552014-05-23 19:05:39521 w1_t1, gfx::Rect(1200, 70, 35, 35), false /* transient */);
[email protected]f059c6942012-07-21 14:27:57522
523 views::Widget* w11 = CreateTestWidgetWithParent(
524 w1, gfx::Rect(10, 10, 40, 40), true /* child */);
525 views::Widget* w11_t1 = CreateTestWidgetWithParent(
526 w1, gfx::Rect(1300, 100, 80, 80), false /* transient */);
527
528 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
529 EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow());
530 EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow());
531 EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow());
532 EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow());
533 EXPECT_EQ("50,50 50x50",
534 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]e6de8552014-05-23 19:05:39535 EXPECT_EQ("1200,70 35x35",
[email protected]f059c6942012-07-21 14:27:57536 w1_t11->GetWindowBoundsInScreen().ToString());
537 EXPECT_EQ("20,20 40x40",
538 w11->GetWindowBoundsInScreen().ToString());
539 EXPECT_EQ("1300,100 80x80",
540 w11_t1->GetWindowBoundsInScreen().ToString());
541
542 w1->SetBounds(gfx::Rect(1100,10,100,100));
543
544 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
545 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
546 EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow());
547 EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow());
548 EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow());
549
550 EXPECT_EQ("1110,20 40x40",
551 w11->GetWindowBoundsInScreen().ToString());
552 // Transient window's screen bounds stays the same.
553 EXPECT_EQ("50,50 50x50",
554 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]e6de8552014-05-23 19:05:39555 EXPECT_EQ("1200,70 35x35",
[email protected]f059c6942012-07-21 14:27:57556 w1_t11->GetWindowBoundsInScreen().ToString());
557 EXPECT_EQ("1300,100 80x80",
558 w11_t1->GetWindowBoundsInScreen().ToString());
559
560 // Transient window doesn't move between root window unless
561 // its transient parent moves.
562 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50));
563 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
564 EXPECT_EQ("10,50 50x50",
565 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57566}
567
[email protected]ca7060982012-08-08 18:05:25568// Test if the Window::ConvertPointToTarget works across root windows.
[email protected]a5e71c92012-06-22 22:09:08569// TODO(oshima): Move multiple display suport and this test to aura.
570TEST_F(ExtendedDesktopTest, ConvertPoint) {
[email protected]e75642a2013-06-12 17:21:18571 if (!SupportsMultipleDisplays())
572 return;
[email protected]55ad8c12014-01-17 18:24:33573 gfx::Screen* screen = Shell::GetScreen();
[email protected]f634dd32012-07-23 22:49:07574 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13575 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]b8984242013-07-12 07:55:38576 gfx::Display display_1 = screen->GetDisplayNearestWindow(root_windows[0]);
[email protected]a5e71c92012-06-22 22:09:08577 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
[email protected]b8984242013-07-12 07:55:38578 gfx::Display display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07579 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
580
[email protected]a5e71c92012-06-22 22:09:08581 aura::Window* d1 =
582 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
[email protected]a5e71c92012-06-22 22:09:08583 aura::Window* d2 =
[email protected]f634dd32012-07-23 22:49:07584 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
585 EXPECT_EQ(root_windows[0], d1->GetRootWindow());
586 EXPECT_EQ(root_windows[1], d2->GetRootWindow());
[email protected]a5e71c92012-06-22 22:09:08587
[email protected]a5e71c92012-06-22 22:09:08588 // Convert point in the Root2's window to the Root1's window Coord.
589 gfx::Point p(0, 0);
[email protected]ca7060982012-08-08 18:05:25590 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07591 EXPECT_EQ("1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08592 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25593 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07594 EXPECT_EQ("1010,10", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08595
596 // Convert point in the Root1's window to the Root2's window Coord.
597 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25598 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07599 EXPECT_EQ("-1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08600 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25601 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07602 EXPECT_EQ("-1010,-10", p.ToString());
603
604 // Move the 2nd display to the bottom and test again.
[email protected]edbfb8d2012-09-03 08:33:43605 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
[email protected]f634dd32012-07-23 22:49:07606
[email protected]b8984242013-07-12 07:55:38607 display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07608 EXPECT_EQ("0,600", display_2.bounds().origin().ToString());
609
610 // Convert point in Root2's window to Root1's window Coord.
611 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25612 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07613 EXPECT_EQ("0,600", p.ToString());
614 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25615 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07616 EXPECT_EQ("10,610", p.ToString());
617
618 // Convert point in Root1's window to Root2's window Coord.
619 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25620 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07621 EXPECT_EQ("0,-600", p.ToString());
622 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25623 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07624 EXPECT_EQ("-10,-610", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08625}
[email protected]f634dd32012-07-23 22:49:07626
[email protected]263898a2012-09-17 17:20:07627TEST_F(ExtendedDesktopTest, OpenSystemTray) {
[email protected]e75642a2013-06-12 17:21:18628 if (!SupportsMultipleDisplays())
629 return;
630
[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) {
[email protected]e75642a2013-06-12 17:21:18662 if (!SupportsMultipleDisplays())
663 return;
664
[email protected]578048512012-09-19 20:01:24665 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13666 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a2e6af12013-01-07 21:40:35667 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 50, 50));
[email protected]578048512012-09-19 20:01:24668 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
669 w1->SetBounds(gfx::Rect(150, 10, 50, 50));
670 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
671
672 // The widget stays in the same root if kStayInSameRootWindowKey is set to
673 // true.
[email protected]093b8d642014-04-03 20:59:28674 w1->GetNativeView()->SetProperty(kStayInSameRootWindowKey, true);
[email protected]578048512012-09-19 20:01:24675 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
676 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
677
678 // The widget should now move to the 1st root window without the property.
[email protected]093b8d642014-04-03 20:59:28679 w1->GetNativeView()->ClearProperty(kStayInSameRootWindowKey);
[email protected]578048512012-09-19 20:01:24680 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
681 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
[email protected]e887c6c2013-07-08 19:35:53682
683 // a window in SettingsBubbleContainer and StatusContainer should
684 // not move to another root window regardles of the bounds specified.
685 aura::Window* settings_bubble_container =
686 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]093b8d642014-04-03 20:59:28687 kShellWindowId_SettingBubbleContainer);
[email protected]e887c6c2013-07-08 19:35:53688 aura::Window* window = aura::test::CreateTestWindowWithId(
689 100, settings_bubble_container);
690 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50),
[email protected]55ad8c12014-01-17 18:24:33691 ScreenUtil::GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53692 EXPECT_EQ(root_windows[0], window->GetRootWindow());
693
694 aura::Window* status_container =
695 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]093b8d642014-04-03 20:59:28696 kShellWindowId_StatusContainer);
[email protected]e887c6c2013-07-08 19:35:53697 window = aura::test::CreateTestWindowWithId(100, status_container);
698 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50),
[email protected]55ad8c12014-01-17 18:24:33699 ScreenUtil::GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53700 EXPECT_EQ(root_windows[0], window->GetRootWindow());
[email protected]578048512012-09-19 20:01:24701}
702
[email protected]e67291f12012-10-10 05:52:38703TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) {
[email protected]e75642a2013-06-12 17:21:18704 if (!SupportsMultipleDisplays())
705 return;
706
[email protected]e67291f12012-10-10 05:52:38707 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13708 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e67291f12012-10-10 05:52:38709
710 // Create normal windows on both displays.
711 views::Widget* widget1 = CreateTestWidget(
[email protected]ffabb1e2012-10-12 19:51:17712 Shell::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38713 widget1->Show();
714 EXPECT_EQ(root_windows[0], widget1->GetNativeView()->GetRootWindow());
715 views::Widget* widget2 = CreateTestWidget(
[email protected]55ad8c12014-01-17 18:24:33716 ScreenUtil::GetSecondaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38717 widget2->Show();
718 EXPECT_EQ(root_windows[1], widget2->GetNativeView()->GetRootWindow());
719
720 // Create a LockScreen window.
721 views::Widget* lock_widget = CreateTestWidget(
[email protected]ffabb1e2012-10-12 19:51:17722 Shell::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38723 views::Textfield* textfield = new views::Textfield;
[email protected]09148952013-03-13 13:25:43724 lock_widget->client_view()->AddChildView(textfield);
[email protected]e67291f12012-10-10 05:52:38725
[email protected]093b8d642014-04-03 20:59:28726 ash::Shell::GetContainer(Shell::GetPrimaryRootWindow(),
727 ash::kShellWindowId_LockScreenContainer)
728 ->AddChild(lock_widget->GetNativeView());
[email protected]e67291f12012-10-10 05:52:38729 lock_widget->Show();
730 textfield->RequestFocus();
731
[email protected]8cfb6722012-11-28 03:28:46732 aura::client::FocusClient* focus_client =
733 aura::client::GetFocusClient(root_windows[0]);
734 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38735
736 // The lock window should get events on both root windows.
[email protected]334e6182013-01-11 18:35:41737 aura::test::EventGenerator& event_generator(GetEventGenerator());
738
[email protected]a06955222014-03-10 22:47:32739 event_generator.set_current_host(root_windows[0]->GetHost());
[email protected]334e6182013-01-11 18:35:41740 event_generator.PressKey(ui::VKEY_A, 0);
741 event_generator.ReleaseKey(ui::VKEY_A, 0);
[email protected]8cfb6722012-11-28 03:28:46742 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46743 EXPECT_EQ("a", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38744
[email protected]a06955222014-03-10 22:47:32745 event_generator.set_current_host(root_windows[1]->GetHost());
[email protected]334e6182013-01-11 18:35:41746 event_generator.PressKey(ui::VKEY_B, 0);
747 event_generator.ReleaseKey(ui::VKEY_B, 0);
[email protected]8cfb6722012-11-28 03:28:46748 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46749 EXPECT_EQ("ab", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38750
751 // Deleting 2nd display. The lock window still should get the events.
752 UpdateDisplay("100x100");
[email protected]334e6182013-01-11 18:35:41753 event_generator.PressKey(ui::VKEY_C, 0);
754 event_generator.ReleaseKey(ui::VKEY_C, 0);
[email protected]8cfb6722012-11-28 03:28:46755 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46756 EXPECT_EQ("abc", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38757
758 // Creating 2nd display again, and lock window still should get events
759 // on both root windows.
760 UpdateDisplay("100x100,200x200");
761 root_windows = Shell::GetAllRootWindows();
[email protected]a06955222014-03-10 22:47:32762 event_generator.set_current_host(root_windows[0]->GetHost());
[email protected]334e6182013-01-11 18:35:41763 event_generator.PressKey(ui::VKEY_D, 0);
764 event_generator.ReleaseKey(ui::VKEY_D, 0);
[email protected]8cfb6722012-11-28 03:28:46765 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46766 EXPECT_EQ("abcd", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38767
[email protected]a06955222014-03-10 22:47:32768 event_generator.set_current_host(root_windows[1]->GetHost());
[email protected]334e6182013-01-11 18:35:41769 event_generator.PressKey(ui::VKEY_E, 0);
770 event_generator.ReleaseKey(ui::VKEY_E, 0);
[email protected]8cfb6722012-11-28 03:28:46771 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46772 EXPECT_EQ("abcde", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38773}
774
[email protected]334e6182013-01-11 18:35:41775TEST_F(ExtendedDesktopTest, PassiveGrab) {
[email protected]e75642a2013-06-12 17:21:18776 if (!SupportsMultipleDisplays())
777 return;
778
[email protected]334e6182013-01-11 18:35:41779 EventLocationRecordingEventHandler event_handler;
780 ash::Shell::GetInstance()->AddPreTargetHandler(&event_handler);
781
782 UpdateDisplay("300x300,200x200");
783
784 views::Widget* widget = CreateTestWidget(gfx::Rect(50, 50, 200, 200));
785 widget->Show();
786 ASSERT_EQ("50,50 200x200", widget->GetWindowBoundsInScreen().ToString());
787
788 aura::test::EventGenerator& generator(GetEventGenerator());
789 generator.MoveMouseTo(150, 150);
790 EXPECT_EQ("100,100 150,150", event_handler.GetLocationsAndReset());
791
792 generator.PressLeftButton();
793 generator.MoveMouseTo(400, 150);
794
795 EXPECT_EQ("350,100 400,150", event_handler.GetLocationsAndReset());
796
797 generator.ReleaseLeftButton();
798 EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset());
799
800 generator.MoveMouseTo(400, 150);
801 EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset());
802
803 ash::Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
804}
805
[email protected]c39be8f2012-06-15 22:58:36806} // namespace ash