blob: 8189581e9ded2831d961615d297217dadabdb652 [file] [log] [blame]
[email protected]f1853122012-06-27 16:21:261// 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]8674b312012-10-12 19:02:445#include "ash/root_window_controller.h"
6
oshima38dffad2015-05-05 17:22:567#include "ash/display/display_manager.h"
[email protected]fdf74bf2014-04-30 21:24:028#include "ash/session/session_state_delegate.h"
[email protected]478c6c32013-03-09 02:50:589#include "ash/shelf/shelf_layout_manager.h"
[email protected]f1853122012-06-27 16:21:2610#include "ash/shell.h"
11#include "ash/shell_window_ids.h"
[email protected]8674b312012-10-12 19:02:4412#include "ash/system/tray/system_tray_delegate.h"
[email protected]f1853122012-06-27 16:21:2613#include "ash/test/ash_test_base.h"
oshimabba2d992015-05-22 19:21:3914#include "ash/test/display_manager_test_api.h"
[email protected]8674b312012-10-12 19:02:4415#include "ash/wm/system_modal_container_layout_manager.h"
[email protected]2ee2f5d2013-01-10 23:37:1616#include "ash/wm/window_properties.h"
[email protected]a41b4e12013-09-20 04:36:3417#include "ash/wm/window_state.h"
[email protected]f1853122012-06-27 16:21:2618#include "ash/wm/window_util.h"
[email protected]eff4c7f2013-08-13 01:45:5019#include "base/command_line.h"
kevers23f3987d2014-09-17 13:50:1220#include "base/memory/scoped_ptr.h"
[email protected]792b9b12012-12-11 03:53:2721#include "ui/aura/client/focus_change_observer.h"
[email protected]8cfb6722012-11-28 03:28:4622#include "ui/aura/client/focus_client.h"
[email protected]e3225e02013-10-23 20:44:3723#include "ui/aura/client/window_tree_client.h"
[email protected]f1853122012-06-27 16:21:2624#include "ui/aura/env.h"
[email protected]dbf835d82012-09-11 18:23:0925#include "ui/aura/test/test_window_delegate.h"
26#include "ui/aura/test/test_windows.h"
[email protected]f1853122012-06-27 16:21:2627#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2628#include "ui/aura/window_event_dispatcher.h"
[email protected]dbf835d82012-09-11 18:23:0929#include "ui/aura/window_tracker.h"
[email protected]2082d7d2014-05-13 14:44:2330#include "ui/base/ime/dummy_text_input_client.h"
31#include "ui/base/ime/input_method.h"
32#include "ui/base/ime/text_input_client.h"
[email protected]73c9fd02014-07-28 01:48:5233#include "ui/events/test/event_generator.h"
[email protected]cd9f71d2014-03-20 21:54:2134#include "ui/events/test/test_event_handler.h"
[email protected]647b4842013-12-12 14:24:2435#include "ui/keyboard/keyboard_controller_proxy.h"
[email protected]eff4c7f2013-08-13 01:45:5036#include "ui/keyboard/keyboard_switches.h"
[email protected]39e95212014-04-23 20:00:0137#include "ui/keyboard/keyboard_util.h"
[email protected]f1853122012-06-27 16:21:2638#include "ui/views/controls/menu/menu_controller.h"
39#include "ui/views/widget/widget.h"
40#include "ui/views/widget/widget_delegate.h"
41
[email protected]2ee2f5d2013-01-10 23:37:1642using aura::Window;
43using views::Widget;
44
[email protected]f1853122012-06-27 16:21:2645namespace ash {
46namespace {
47
48class TestDelegate : public views::WidgetDelegateView {
49 public:
50 explicit TestDelegate(bool system_modal) : system_modal_(system_modal) {}
dcheng1f4538e2014-10-27 23:57:0551 ~TestDelegate() override {}
[email protected]f1853122012-06-27 16:21:2652
53 // Overridden from views::WidgetDelegate:
dcheng1f4538e2014-10-27 23:57:0554 views::View* GetContentsView() override { return this; }
[email protected]f1853122012-06-27 16:21:2655
dcheng1f4538e2014-10-27 23:57:0556 ui::ModalType GetModalType() const override {
[email protected]f1853122012-06-27 16:21:2657 return system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE;
58 }
59
60 private:
61 bool system_modal_;
[email protected]0fbfa972013-10-02 19:23:3362
[email protected]f1853122012-06-27 16:21:2663 DISALLOW_COPY_AND_ASSIGN(TestDelegate);
64};
65
[email protected]792b9b12012-12-11 03:53:2766class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate,
67 public aura::client::FocusChangeObserver {
[email protected]dbf835d82012-09-11 18:23:0968 public:
69 DeleteOnBlurDelegate() : window_(NULL) {}
dcheng1f4538e2014-10-27 23:57:0570 ~DeleteOnBlurDelegate() override {}
[email protected]dbf835d82012-09-11 18:23:0971
[email protected]792b9b12012-12-11 03:53:2772 void SetWindow(aura::Window* window) {
73 window_ = window;
74 aura::client::SetFocusChangeObserver(window_, this);
75 }
[email protected]dbf835d82012-09-11 18:23:0976
[email protected]869f6352012-12-06 20:47:1777 private:
[email protected]dbf835d82012-09-11 18:23:0978 // aura::test::TestWindowDelegate overrides:
dcheng1f4538e2014-10-27 23:57:0579 bool CanFocus() override { return true; }
[email protected]dbf835d82012-09-11 18:23:0980
[email protected]792b9b12012-12-11 03:53:2781 // aura::client::FocusChangeObserver implementation:
dcheng1f4538e2014-10-27 23:57:0582 void OnWindowFocused(aura::Window* gained_focus,
83 aura::Window* lost_focus) override {
[email protected]792b9b12012-12-11 03:53:2784 if (window_ == lost_focus)
85 delete window_;
[email protected]869f6352012-12-06 20:47:1786 }
87
[email protected]dbf835d82012-09-11 18:23:0988 aura::Window* window_;
89
90 DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate);
91};
92
[email protected]f1853122012-06-27 16:21:2693} // namespace
94
95namespace test {
[email protected]f1853122012-06-27 16:21:2696
[email protected]a2e6af12013-01-07 21:40:3597class RootWindowControllerTest : public test::AshTestBase {
98 public:
99 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
100 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
101 NULL, CurrentContext(), bounds);
102 widget->Show();
103 return widget;
104 }
105
106 views::Widget* CreateModalWidget(const gfx::Rect& bounds) {
107 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
108 new TestDelegate(true), CurrentContext(), bounds);
109 widget->Show();
110 return widget;
111 }
112
113 views::Widget* CreateModalWidgetWithParent(const gfx::Rect& bounds,
114 gfx::NativeWindow parent) {
115 views::Widget* widget =
116 views::Widget::CreateWindowWithParentAndBounds(new TestDelegate(true),
117 parent,
118 bounds);
119 widget->Show();
120 return widget;
121 }
122
[email protected]c9390bd2013-11-08 20:33:13123 aura::Window* GetModalContainer(aura::Window* root_window) {
[email protected]093b8d642014-04-03 20:59:28124 return Shell::GetContainer(root_window,
125 ash::kShellWindowId_SystemModalContainer);
[email protected]a2e6af12013-01-07 21:40:35126 }
127};
[email protected]f1853122012-06-27 16:21:26128
[email protected]e75642a2013-06-12 17:21:18129TEST_F(RootWindowControllerTest, MoveWindows_Basic) {
130 if (!SupportsMultipleDisplays())
131 return;
[email protected]2816c2462013-12-17 02:22:25132 // Windows origin should be doubled when moved to the 1st display.
133 UpdateDisplay("600x600,300x300");
[email protected]c9390bd2013-11-08 20:33:13134 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]093b8d642014-04-03 20:59:28135 RootWindowController* controller = Shell::GetPrimaryRootWindowController();
136 ShelfLayoutManager* shelf_layout_manager =
[email protected]478c6c32013-03-09 02:50:58137 controller->GetShelfLayoutManager();
138 shelf_layout_manager->SetAutoHideBehavior(
139 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
[email protected]f1853122012-06-27 16:21:26140
141 views::Widget* normal = CreateTestWidget(gfx::Rect(650, 10, 100, 100));
142 EXPECT_EQ(root_windows[1], normal->GetNativeView()->GetRootWindow());
[email protected]e2f64d102012-07-19 19:17:04143 EXPECT_EQ("650,10 100x100", normal->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06144 EXPECT_EQ("50,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04145 normal->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26146
147 views::Widget* maximized = CreateTestWidget(gfx::Rect(700, 10, 100, 100));
148 maximized->Maximize();
149 EXPECT_EQ(root_windows[1], maximized->GetNativeView()->GetRootWindow());
[email protected]2816c2462013-12-17 02:22:25150 EXPECT_EQ("600,0 300x253", maximized->GetWindowBoundsInScreen().ToString());
151 EXPECT_EQ("0,0 300x253",
[email protected]8c0ec432013-05-10 04:33:39152 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26153
154 views::Widget* minimized = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
155 minimized->Minimize();
156 EXPECT_EQ(root_windows[1], minimized->GetNativeView()->GetRootWindow());
[email protected]8d625fb2012-07-18 16:40:06157 EXPECT_EQ("800,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04158 minimized->GetWindowBoundsInScreen().ToString());
[email protected]f1853122012-06-27 16:21:26159
[email protected]2816c2462013-12-17 02:22:25160 views::Widget* fullscreen = CreateTestWidget(gfx::Rect(850, 10, 100, 100));
[email protected]f1853122012-06-27 16:21:26161 fullscreen->SetFullscreen(true);
162 EXPECT_EQ(root_windows[1], fullscreen->GetNativeView()->GetRootWindow());
[email protected]1a015382012-12-01 19:44:59163
[email protected]2816c2462013-12-17 02:22:25164 EXPECT_EQ("600,0 300x300",
[email protected]e2f64d102012-07-19 19:17:04165 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]2816c2462013-12-17 02:22:25166 EXPECT_EQ("0,0 300x300",
[email protected]e2f64d102012-07-19 19:17:04167 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26168
[email protected]8f2f151412013-01-26 03:58:37169 views::Widget* unparented_control = new Widget;
170 Widget::InitParams params;
171 params.bounds = gfx::Rect(650, 10, 100, 100);
172 params.context = CurrentContext();
173 params.type = Widget::InitParams::TYPE_CONTROL;
174 unparented_control->Init(params);
175 EXPECT_EQ(root_windows[1],
176 unparented_control->GetNativeView()->GetRootWindow());
[email protected]093b8d642014-04-03 20:59:28177 EXPECT_EQ(kShellWindowId_UnparentedControlContainer,
[email protected]8f2f151412013-01-26 03:58:37178 unparented_control->GetNativeView()->parent()->id());
179
[email protected]95db9c12013-01-31 11:47:44180 aura::Window* panel = CreateTestWindowInShellWithDelegateAndType(
[email protected]5b251f12013-12-19 01:50:05181 NULL, ui::wm::WINDOW_TYPE_PANEL, 0, gfx::Rect(700, 100, 100, 100));
[email protected]95db9c12013-01-31 11:47:44182 EXPECT_EQ(root_windows[1], panel->GetRootWindow());
[email protected]093b8d642014-04-03 20:59:28183 EXPECT_EQ(kShellWindowId_PanelContainer, panel->parent()->id());
[email protected]95db9c12013-01-31 11:47:44184
[email protected]dbf835d82012-09-11 18:23:09185 // Make sure a window that will delete itself when losing focus
186 // will not crash.
187 aura::WindowTracker tracker;
188 DeleteOnBlurDelegate delete_on_blur_delegate;
[email protected]5ebe6102012-11-28 21:00:03189 aura::Window* d2 = CreateTestWindowInShellWithDelegate(
190 &delete_on_blur_delegate, 0, gfx::Rect(50, 50, 100, 100));
[email protected]792b9b12012-12-11 03:53:27191 delete_on_blur_delegate.SetWindow(d2);
[email protected]550543e2013-01-11 22:43:44192 aura::client::GetFocusClient(root_windows[0])->FocusWindow(d2);
[email protected]dbf835d82012-09-11 18:23:09193 tracker.Add(d2);
194
[email protected]f634dd32012-07-23 22:49:07195 UpdateDisplay("600x600");
[email protected]f1853122012-06-27 16:21:26196
[email protected]dbf835d82012-09-11 18:23:09197 // d2 must have been deleted.
198 EXPECT_FALSE(tracker.Contains(d2));
199
[email protected]f1853122012-06-27 16:21:26200 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
[email protected]2816c2462013-12-17 02:22:25201 EXPECT_EQ("100,20 100x100", normal->GetWindowBoundsInScreen().ToString());
202 EXPECT_EQ("100,20 100x100",
[email protected]e2f64d102012-07-19 19:17:04203 normal->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26204
[email protected]eefd51b22012-09-25 20:26:24205 // Maximized area on primary display has 3px (given as
[email protected]f1853122012-06-27 16:21:26206 // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom.
[email protected]2a64b0a2013-07-23 23:15:54207
208 // First clear fullscreen status, since both fullscreen and maximized windows
209 // share the same desktop workspace, which cancels the shelf status.
210 fullscreen->SetFullscreen(false);
[email protected]f1853122012-06-27 16:21:26211 EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow());
[email protected]7b675df612012-09-16 18:33:20212 EXPECT_EQ("0,0 600x597",
[email protected]e2f64d102012-07-19 19:17:04213 maximized->GetWindowBoundsInScreen().ToString());
[email protected]7b675df612012-09-16 18:33:20214 EXPECT_EQ("0,0 600x597",
[email protected]e2f64d102012-07-19 19:17:04215 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26216
[email protected]2a64b0a2013-07-23 23:15:54217 // Set fullscreen to true. In that case the 3px inset becomes invisible so
218 // the maximized window can also use the area fully.
219 fullscreen->SetFullscreen(true);
220 EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow());
221 EXPECT_EQ("0,0 600x600",
222 maximized->GetWindowBoundsInScreen().ToString());
223 EXPECT_EQ("0,0 600x600",
224 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
225
[email protected]f1853122012-06-27 16:21:26226 EXPECT_EQ(root_windows[0], minimized->GetNativeView()->GetRootWindow());
[email protected]2816c2462013-12-17 02:22:25227 EXPECT_EQ("400,20 100x100",
[email protected]e2f64d102012-07-19 19:17:04228 minimized->GetWindowBoundsInScreen().ToString());
[email protected]f1853122012-06-27 16:21:26229
230 EXPECT_EQ(root_windows[0], fullscreen->GetNativeView()->GetRootWindow());
231 EXPECT_TRUE(fullscreen->IsFullscreen());
[email protected]8d625fb2012-07-18 16:40:06232 EXPECT_EQ("0,0 600x600",
[email protected]e2f64d102012-07-19 19:17:04233 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06234 EXPECT_EQ("0,0 600x600",
[email protected]e2f64d102012-07-19 19:17:04235 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]8d625fb2012-07-18 16:40:06236
237 // Test if the restore bounds are correctly updated.
[email protected]a41b4e12013-09-20 04:36:34238 wm::GetWindowState(maximized->GetNativeView())->Restore();
[email protected]2816c2462013-12-17 02:22:25239 EXPECT_EQ("200,20 100x100", maximized->GetWindowBoundsInScreen().ToString());
240 EXPECT_EQ("200,20 100x100",
[email protected]e2f64d102012-07-19 19:17:04241 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]8d625fb2012-07-18 16:40:06242
243 fullscreen->SetFullscreen(false);
[email protected]2816c2462013-12-17 02:22:25244 EXPECT_EQ("500,20 100x100",
[email protected]e2f64d102012-07-19 19:17:04245 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]2816c2462013-12-17 02:22:25246 EXPECT_EQ("500,20 100x100",
[email protected]e2f64d102012-07-19 19:17:04247 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]8f2f151412013-01-26 03:58:37248
249 // Test if the unparented widget has moved.
250 EXPECT_EQ(root_windows[0],
251 unparented_control->GetNativeView()->GetRootWindow());
[email protected]093b8d642014-04-03 20:59:28252 EXPECT_EQ(kShellWindowId_UnparentedControlContainer,
[email protected]8f2f151412013-01-26 03:58:37253 unparented_control->GetNativeView()->parent()->id());
[email protected]95db9c12013-01-31 11:47:44254
255 // Test if the panel has moved.
256 EXPECT_EQ(root_windows[0], panel->GetRootWindow());
[email protected]093b8d642014-04-03 20:59:28257 EXPECT_EQ(kShellWindowId_PanelContainer, panel->parent()->id());
[email protected]f1853122012-06-27 16:21:26258}
259
[email protected]e75642a2013-06-12 17:21:18260TEST_F(RootWindowControllerTest, MoveWindows_Modal) {
261 if (!SupportsMultipleDisplays())
262 return;
[email protected]1c3f7002013-01-21 18:46:05263
[email protected]f634dd32012-07-23 22:49:07264 UpdateDisplay("500x500,500x500");
[email protected]f1853122012-06-27 16:21:26265
[email protected]c9390bd2013-11-08 20:33:13266 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f1853122012-06-27 16:21:26267 // Emulate virtual screen coordinate system.
268 root_windows[0]->SetBounds(gfx::Rect(0, 0, 500, 500));
269 root_windows[1]->SetBounds(gfx::Rect(500, 0, 500, 500));
270
271 views::Widget* normal = CreateTestWidget(gfx::Rect(300, 10, 100, 100));
272 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
273 EXPECT_TRUE(wm::IsActiveWindow(normal->GetNativeView()));
274
275 views::Widget* modal = CreateModalWidget(gfx::Rect(650, 10, 100, 100));
276 EXPECT_EQ(root_windows[1], modal->GetNativeView()->GetRootWindow());
277 EXPECT_TRUE(GetModalContainer(root_windows[1])->Contains(
278 modal->GetNativeView()));
279 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
280
[email protected]73c9fd02014-07-28 01:48:52281 ui::test::EventGenerator generator_1st(root_windows[0]);
[email protected]f1853122012-06-27 16:21:26282 generator_1st.ClickLeftButton();
283 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
284
[email protected]f634dd32012-07-23 22:49:07285 UpdateDisplay("500x500");
[email protected]f1853122012-06-27 16:21:26286 EXPECT_EQ(root_windows[0], modal->GetNativeView()->GetRootWindow());
287 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
288 generator_1st.ClickLeftButton();
289 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
290}
291
oshima022a9542015-05-01 00:15:02292// Make sure lock related windows moves.
293TEST_F(RootWindowControllerTest, MoveWindows_LockWindowsInUnified) {
294 if (!SupportsMultipleDisplays())
295 return;
oshimabba2d992015-05-22 19:21:39296 test::DisplayManagerTestApi::EnableUnifiedDesktopForTest();
297
oshima022a9542015-05-01 00:15:02298 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
oshima38dffad2015-05-05 17:22:56299 display_manager->SetDefaultMultiDisplayMode(DisplayManager::UNIFIED);
oshima022a9542015-05-01 00:15:02300 display_manager->SetMultiDisplayMode(DisplayManager::UNIFIED);
301 UpdateDisplay("500x500");
302 const int kLockScreenWindowId = 1000;
303 const int kLockBackgroundWindowId = 1001;
304
305 RootWindowController* controller =
306 Shell::GetInstance()->GetPrimaryRootWindowController();
307
308 aura::Window* lock_container =
309 controller->GetContainer(kShellWindowId_LockScreenContainer);
310 aura::Window* lock_background_container =
311 controller->GetContainer(kShellWindowId_LockScreenBackgroundContainer);
312
313 views::Widget* lock_screen =
314 CreateModalWidgetWithParent(gfx::Rect(10, 10, 100, 100), lock_container);
315 lock_screen->GetNativeWindow()->set_id(kLockScreenWindowId);
316 lock_screen->SetFullscreen(true);
317
318 views::Widget* lock_background = CreateModalWidgetWithParent(
319 gfx::Rect(10, 10, 100, 100), lock_background_container);
320 lock_background->GetNativeWindow()->set_id(kLockBackgroundWindowId);
321
322 ASSERT_EQ(lock_screen->GetNativeWindow(),
323 controller->GetRootWindow()->GetChildById(kLockScreenWindowId));
324 ASSERT_EQ(lock_background->GetNativeWindow(),
325 controller->GetRootWindow()->GetChildById(kLockBackgroundWindowId));
326 EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString());
327
328 // Switch to unified.
329 UpdateDisplay("500x500,500x500");
330
331 // In unified mode, RWC is created
332 controller = Shell::GetInstance()->GetPrimaryRootWindowController();
333
334 ASSERT_EQ(lock_screen->GetNativeWindow(),
335 controller->GetRootWindow()->GetChildById(kLockScreenWindowId));
336 ASSERT_EQ(lock_background->GetNativeWindow(),
337 controller->GetRootWindow()->GetChildById(kLockBackgroundWindowId));
oshima96f6a502015-05-02 08:43:32338 EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString());
oshima022a9542015-05-01 00:15:02339
340 // Switch to mirror.
341 display_manager->SetMirrorMode(true);
342 EXPECT_TRUE(display_manager->IsInMirrorMode());
343
344 controller = Shell::GetInstance()->GetPrimaryRootWindowController();
345 ASSERT_EQ(lock_screen->GetNativeWindow(),
346 controller->GetRootWindow()->GetChildById(kLockScreenWindowId));
347 ASSERT_EQ(lock_background->GetNativeWindow(),
348 controller->GetRootWindow()->GetChildById(kLockBackgroundWindowId));
349 EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString());
350
351 // Switch to unified.
352 display_manager->SetMirrorMode(false);
353 EXPECT_TRUE(display_manager->IsInUnifiedMode());
354
355 controller = Shell::GetInstance()->GetPrimaryRootWindowController();
356
357 ASSERT_EQ(lock_screen->GetNativeWindow(),
358 controller->GetRootWindow()->GetChildById(kLockScreenWindowId));
359 ASSERT_EQ(lock_background->GetNativeWindow(),
360 controller->GetRootWindow()->GetChildById(kLockBackgroundWindowId));
oshima96f6a502015-05-02 08:43:32361 EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString());
oshima022a9542015-05-01 00:15:02362
363 // Switch to single display.
364 UpdateDisplay("600x500");
365 EXPECT_FALSE(display_manager->IsInUnifiedMode());
366 EXPECT_FALSE(display_manager->IsInMirrorMode());
367
368 controller = Shell::GetInstance()->GetPrimaryRootWindowController();
369
370 ASSERT_EQ(lock_screen->GetNativeWindow(),
371 controller->GetRootWindow()->GetChildById(kLockScreenWindowId));
372 ASSERT_EQ(lock_background->GetNativeWindow(),
373 controller->GetRootWindow()->GetChildById(kLockBackgroundWindowId));
374 EXPECT_EQ("0,0 600x500", lock_screen->GetNativeWindow()->bounds().ToString());
375}
376
[email protected]8674b312012-10-12 19:02:44377TEST_F(RootWindowControllerTest, ModalContainer) {
378 UpdateDisplay("600x600");
379 Shell* shell = Shell::GetInstance();
[email protected]093b8d642014-04-03 20:59:28380 RootWindowController* controller = shell->GetPrimaryRootWindowController();
[email protected]8674b312012-10-12 19:02:44381 EXPECT_EQ(user::LOGGED_IN_USER,
[email protected]945f9cae2012-12-12 09:54:29382 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]f5c9dbc2014-04-11 08:13:45383 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28384 ->layout_manager(),
385 controller->GetSystemModalLayoutManager(NULL));
[email protected]8674b312012-10-12 19:02:44386
[email protected]3b162e12012-11-09 11:52:35387 views::Widget* session_modal_widget =
388 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
[email protected]f5c9dbc2014-04-11 08:13:45389 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28390 ->layout_manager(),
391 controller->GetSystemModalLayoutManager(
392 session_modal_widget->GetNativeView()));
[email protected]3b162e12012-11-09 11:52:35393
[email protected]fcb123d2013-04-17 15:58:49394 shell->session_state_delegate()->LockScreen();
[email protected]8674b312012-10-12 19:02:44395 EXPECT_EQ(user::LOGGED_IN_LOCKED,
[email protected]945f9cae2012-12-12 09:54:29396 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]f5c9dbc2014-04-11 08:13:45397 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28398 ->layout_manager(),
399 controller->GetSystemModalLayoutManager(NULL));
[email protected]3b162e12012-11-09 11:52:35400
[email protected]f5c9dbc2014-04-11 08:13:45401 aura::Window* lock_container =
402 controller->GetContainer(kShellWindowId_LockScreenContainer);
[email protected]3b162e12012-11-09 11:52:35403 views::Widget* lock_modal_widget =
404 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container);
[email protected]f5c9dbc2014-04-11 08:13:45405 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28406 ->layout_manager(),
407 controller->GetSystemModalLayoutManager(
408 lock_modal_widget->GetNativeView()));
[email protected]f5c9dbc2014-04-11 08:13:45409 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28410 ->layout_manager(),
[email protected]3b162e12012-11-09 11:52:35411 controller->GetSystemModalLayoutManager(
412 session_modal_widget->GetNativeView()));
413
[email protected]fcb123d2013-04-17 15:58:49414 shell->session_state_delegate()->UnlockScreen();
[email protected]8674b312012-10-12 19:02:44415}
416
[email protected]1b219922012-11-13 21:16:43417TEST_F(RootWindowControllerTest, ModalContainerNotLoggedInLoggedIn) {
418 UpdateDisplay("600x600");
419 Shell* shell = Shell::GetInstance();
420
421 // Configure login screen environment.
422 SetUserLoggedIn(false);
423 EXPECT_EQ(user::LOGGED_IN_NONE,
[email protected]945f9cae2012-12-12 09:54:29424 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]c8d19f82013-05-18 09:09:41425 EXPECT_EQ(0, shell->session_state_delegate()->NumberOfLoggedInUsers());
[email protected]fcb123d2013-04-17 15:58:49426 EXPECT_FALSE(shell->session_state_delegate()->IsActiveUserSessionStarted());
[email protected]1b219922012-11-13 21:16:43427
[email protected]093b8d642014-04-03 20:59:28428 RootWindowController* controller = shell->GetPrimaryRootWindowController();
[email protected]f5c9dbc2014-04-11 08:13:45429 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28430 ->layout_manager(),
431 controller->GetSystemModalLayoutManager(NULL));
[email protected]1b219922012-11-13 21:16:43432
[email protected]f5c9dbc2014-04-11 08:13:45433 aura::Window* lock_container =
434 controller->GetContainer(kShellWindowId_LockScreenContainer);
[email protected]1b219922012-11-13 21:16:43435 views::Widget* login_modal_widget =
436 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container);
[email protected]f5c9dbc2014-04-11 08:13:45437 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28438 ->layout_manager(),
439 controller->GetSystemModalLayoutManager(
440 login_modal_widget->GetNativeView()));
[email protected]1b219922012-11-13 21:16:43441 login_modal_widget->Close();
442
443 // Configure user session environment.
444 SetUserLoggedIn(true);
445 SetSessionStarted(true);
446 EXPECT_EQ(user::LOGGED_IN_USER,
[email protected]945f9cae2012-12-12 09:54:29447 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]c8d19f82013-05-18 09:09:41448 EXPECT_EQ(1, shell->session_state_delegate()->NumberOfLoggedInUsers());
[email protected]fcb123d2013-04-17 15:58:49449 EXPECT_TRUE(shell->session_state_delegate()->IsActiveUserSessionStarted());
[email protected]f5c9dbc2014-04-11 08:13:45450 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28451 ->layout_manager(),
452 controller->GetSystemModalLayoutManager(NULL));
[email protected]1b219922012-11-13 21:16:43453
454 views::Widget* session_modal_widget =
455 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
[email protected]f5c9dbc2014-04-11 08:13:45456 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28457 ->layout_manager(),
458 controller->GetSystemModalLayoutManager(
459 session_modal_widget->GetNativeView()));
[email protected]1b219922012-11-13 21:16:43460}
461
[email protected]a44afbbd2013-07-24 21:49:35462TEST_F(RootWindowControllerTest, ModalContainerBlockedSession) {
463 UpdateDisplay("600x600");
Peter Kastingbe940e92014-11-20 23:14:08464 RootWindowController* controller = Shell::GetPrimaryRootWindowController();
[email protected]f5c9dbc2014-04-11 08:13:45465 aura::Window* lock_container =
466 controller->GetContainer(kShellWindowId_LockScreenContainer);
[email protected]a44afbbd2013-07-24 21:49:35467 for (int block_reason = FIRST_BLOCK_REASON;
468 block_reason < NUMBER_OF_BLOCK_REASONS;
469 ++block_reason) {
470 views::Widget* session_modal_widget =
471 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
[email protected]f5c9dbc2014-04-11 08:13:45472 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28473 ->layout_manager(),
474 controller->GetSystemModalLayoutManager(
475 session_modal_widget->GetNativeView()));
[email protected]f5c9dbc2014-04-11 08:13:45476 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28477 ->layout_manager(),
478 controller->GetSystemModalLayoutManager(NULL));
[email protected]a44afbbd2013-07-24 21:49:35479 session_modal_widget->Close();
480
481 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
482
[email protected]f5c9dbc2014-04-11 08:13:45483 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28484 ->layout_manager(),
485 controller->GetSystemModalLayoutManager(NULL));
[email protected]a44afbbd2013-07-24 21:49:35486
487 views::Widget* lock_modal_widget =
488 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100),
489 lock_container);
[email protected]f5c9dbc2014-04-11 08:13:45490 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28491 ->layout_manager(),
[email protected]a44afbbd2013-07-24 21:49:35492 controller->GetSystemModalLayoutManager(
493 lock_modal_widget->GetNativeView()));
494
495 session_modal_widget =
496 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
[email protected]f5c9dbc2014-04-11 08:13:45497 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28498 ->layout_manager(),
499 controller->GetSystemModalLayoutManager(
500 session_modal_widget->GetNativeView()));
[email protected]a44afbbd2013-07-24 21:49:35501 session_modal_widget->Close();
502
503 lock_modal_widget->Close();
504 UnblockUserSession();
505 }
506}
507
[email protected]2c9171d22013-12-10 21:55:10508TEST_F(RootWindowControllerTest, GetWindowForFullscreenMode) {
[email protected]2ee2f5d2013-01-10 23:37:16509 UpdateDisplay("600x600");
[email protected]093b8d642014-04-03 20:59:28510 RootWindowController* controller =
[email protected]2ee2f5d2013-01-10 23:37:16511 Shell::GetInstance()->GetPrimaryRootWindowController();
512
[email protected]700849f2013-04-30 17:49:20513 Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
[email protected]2ee2f5d2013-01-10 23:37:16514 w1->Maximize();
[email protected]700849f2013-04-30 17:49:20515 Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
516 w2->SetFullscreen(true);
517 // |w3| is a transient child of |w2|.
518 Widget* w3 = Widget::CreateWindowWithParentAndBounds(NULL,
519 w2->GetNativeWindow(), gfx::Rect(0, 0, 100, 100));
[email protected]2ee2f5d2013-01-10 23:37:16520
[email protected]2c9171d22013-12-10 21:55:10521 // Test that GetWindowForFullscreenMode() finds the fullscreen window when one
[email protected]e3bc88e2013-09-06 06:22:06522 // of its transient children is active.
[email protected]700849f2013-04-30 17:49:20523 w3->Activate();
[email protected]2c9171d22013-12-10 21:55:10524 EXPECT_EQ(w2->GetNativeWindow(), controller->GetWindowForFullscreenMode());
[email protected]2ee2f5d2013-01-10 23:37:16525
[email protected]2c9171d22013-12-10 21:55:10526 // If the topmost window is not fullscreen, it returns NULL.
[email protected]700849f2013-04-30 17:49:20527 w1->Activate();
[email protected]2c9171d22013-12-10 21:55:10528 EXPECT_EQ(NULL, controller->GetWindowForFullscreenMode());
529 w1->Close();
530 w3->Close();
[email protected]e3bc88e2013-09-06 06:22:06531
[email protected]2c9171d22013-12-10 21:55:10532 // Only w2 remains, if minimized GetWindowForFullscreenMode should return
533 // NULL.
[email protected]e3bc88e2013-09-06 06:22:06534 w2->Activate();
[email protected]2c9171d22013-12-10 21:55:10535 EXPECT_EQ(w2->GetNativeWindow(), controller->GetWindowForFullscreenMode());
536 w2->Minimize();
537 EXPECT_EQ(NULL, controller->GetWindowForFullscreenMode());
[email protected]2ee2f5d2013-01-10 23:37:16538}
539
[email protected]2c5db9e2014-02-27 13:58:14540TEST_F(RootWindowControllerTest, MultipleDisplaysGetWindowForFullscreenMode) {
541 if (!SupportsMultipleDisplays())
542 return;
543
544 UpdateDisplay("600x600,600x600");
545 Shell::RootWindowControllerList controllers =
546 Shell::GetInstance()->GetAllRootWindowControllers();
547
548 Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
549 w1->Maximize();
550 Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
551 w2->SetFullscreen(true);
552 Widget* w3 = CreateTestWidget(gfx::Rect(600, 0, 100, 100));
553
554 EXPECT_EQ(w1->GetNativeWindow()->GetRootWindow(),
[email protected]f5c9dbc2014-04-11 08:13:45555 controllers[0]->GetRootWindow());
[email protected]2c5db9e2014-02-27 13:58:14556 EXPECT_EQ(w2->GetNativeWindow()->GetRootWindow(),
[email protected]f5c9dbc2014-04-11 08:13:45557 controllers[0]->GetRootWindow());
[email protected]2c5db9e2014-02-27 13:58:14558 EXPECT_EQ(w3->GetNativeWindow()->GetRootWindow(),
[email protected]f5c9dbc2014-04-11 08:13:45559 controllers[1]->GetRootWindow());
[email protected]2c5db9e2014-02-27 13:58:14560
561 w1->Activate();
562 EXPECT_EQ(NULL, controllers[0]->GetWindowForFullscreenMode());
563 EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode());
564
565 w2->Activate();
566 EXPECT_EQ(w2->GetNativeWindow(),
567 controllers[0]->GetWindowForFullscreenMode());
568 EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode());
569
570 // Verify that the first root window controller remains in fullscreen mode
571 // when a window on the other display is activated.
572 w3->Activate();
573 EXPECT_EQ(w2->GetNativeWindow(),
574 controllers[0]->GetWindowForFullscreenMode());
575 EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode());
576}
577
[email protected]82ced2352013-07-19 20:49:06578// Test that user session window can't be focused if user session blocked by
579// some overlapping UI.
580TEST_F(RootWindowControllerTest, FocusBlockedWindow) {
581 UpdateDisplay("600x600");
[email protected]093b8d642014-04-03 20:59:28582 RootWindowController* controller =
[email protected]82ced2352013-07-19 20:49:06583 Shell::GetInstance()->GetPrimaryRootWindowController();
[email protected]f5c9dbc2014-04-11 08:13:45584 aura::Window* lock_container =
585 controller->GetContainer(kShellWindowId_LockScreenContainer);
[email protected]82ced2352013-07-19 20:49:06586 aura::Window* lock_window = Widget::CreateWindowWithParentAndBounds(NULL,
587 lock_container, gfx::Rect(0, 0, 100, 100))->GetNativeView();
588 lock_window->Show();
589 aura::Window* session_window =
590 CreateTestWidget(gfx::Rect(0, 0, 100, 100))->GetNativeView();
591 session_window->Show();
592
[email protected]a44afbbd2013-07-24 21:49:35593 for (int block_reason = FIRST_BLOCK_REASON;
594 block_reason < NUMBER_OF_BLOCK_REASONS;
595 ++block_reason) {
596 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
597 lock_window->Focus();
598 EXPECT_TRUE(lock_window->HasFocus());
599 session_window->Focus();
600 EXPECT_FALSE(session_window->HasFocus());
601 UnblockUserSession();
602 }
[email protected]82ced2352013-07-19 20:49:06603}
604
[email protected]0fbfa972013-10-02 19:23:33605// Tracks whether OnWindowDestroying() has been invoked.
606class DestroyedWindowObserver : public aura::WindowObserver {
607 public:
608 DestroyedWindowObserver() : destroyed_(false), window_(NULL) {}
dcheng1f4538e2014-10-27 23:57:05609 ~DestroyedWindowObserver() override { Shutdown(); }
[email protected]0fbfa972013-10-02 19:23:33610
611 void SetWindow(Window* window) {
612 window_ = window;
613 window->AddObserver(this);
614 }
615
616 bool destroyed() const { return destroyed_; }
617
618 // WindowObserver overrides:
dcheng1f4538e2014-10-27 23:57:05619 void OnWindowDestroying(Window* window) override {
[email protected]0fbfa972013-10-02 19:23:33620 destroyed_ = true;
621 Shutdown();
622 }
623
624 private:
625 void Shutdown() {
626 if (!window_)
627 return;
628 window_->RemoveObserver(this);
629 window_ = NULL;
630 }
631
632 bool destroyed_;
633 Window* window_;
634
635 DISALLOW_COPY_AND_ASSIGN(DestroyedWindowObserver);
636};
637
638// Verifies shutdown doesn't delete windows that are not owned by the parent.
639TEST_F(RootWindowControllerTest, DontDeleteWindowsNotOwnedByParent) {
640 DestroyedWindowObserver observer1;
641 aura::test::TestWindowDelegate delegate1;
642 aura::Window* window1 = new aura::Window(&delegate1);
[email protected]5b251f12013-12-19 01:50:05643 window1->SetType(ui::wm::WINDOW_TYPE_CONTROL);
[email protected]0fbfa972013-10-02 19:23:33644 window1->set_owned_by_parent(false);
645 observer1.SetWindow(window1);
danakjb161836d2015-04-03 05:14:18646 window1->Init(ui::LAYER_NOT_DRAWN);
[email protected]e3225e02013-10-23 20:44:37647 aura::client::ParentWindowWithContext(
648 window1, Shell::GetInstance()->GetPrimaryRootWindow(), gfx::Rect());
[email protected]0fbfa972013-10-02 19:23:33649
650 DestroyedWindowObserver observer2;
651 aura::Window* window2 = new aura::Window(NULL);
652 window2->set_owned_by_parent(false);
653 observer2.SetWindow(window2);
danakjb161836d2015-04-03 05:14:18654 window2->Init(ui::LAYER_NOT_DRAWN);
[email protected]0fbfa972013-10-02 19:23:33655 Shell::GetInstance()->GetPrimaryRootWindow()->AddChild(window2);
656
657 Shell::GetInstance()->GetPrimaryRootWindowController()->CloseChildWindows();
658
659 ASSERT_FALSE(observer1.destroyed());
660 delete window1;
661
662 ASSERT_FALSE(observer2.destroyed());
663 delete window2;
664}
665
[email protected]cf6fea22013-08-07 14:24:01666typedef test::NoSessionAshTestBase NoSessionRootWindowControllerTest;
667
668// Make sure that an event handler exists for entire display area.
669TEST_F(NoSessionRootWindowControllerTest, Event) {
[email protected]75a88c92014-05-14 01:57:32670 // Hide the shelf since it might otherwise get an event target.
671 RootWindowController* controller = Shell::GetPrimaryRootWindowController();
672 ShelfLayoutManager* shelf_layout_manager =
673 controller->GetShelfLayoutManager();
674 shelf_layout_manager->SetAutoHideBehavior(
675 ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
676
[email protected]bf9cdb362013-10-25 19:22:45677 aura::Window* root = Shell::GetPrimaryRootWindow();
[email protected]cf6fea22013-08-07 14:24:01678 const gfx::Size size = root->bounds().size();
679 aura::Window* event_target = root->GetEventHandlerForPoint(gfx::Point(0, 0));
680 EXPECT_TRUE(event_target);
681 EXPECT_EQ(event_target,
682 root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1)));
683 EXPECT_EQ(event_target,
684 root->GetEventHandlerForPoint(gfx::Point(size.width() - 1, 0)));
685 EXPECT_EQ(event_target,
686 root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1)));
687 EXPECT_EQ(event_target,
688 root->GetEventHandlerForPoint(
689 gfx::Point(size.width() - 1, size.height() - 1)));
690}
691
[email protected]24f5e242014-07-22 02:16:09692class VirtualKeyboardRootWindowControllerTest
693 : public RootWindowControllerTest {
[email protected]eff4c7f2013-08-13 01:45:50694 public:
dcheng1f4538e2014-10-27 23:57:05695 VirtualKeyboardRootWindowControllerTest() {}
696 ~VirtualKeyboardRootWindowControllerTest() override {}
[email protected]eff4c7f2013-08-13 01:45:50697
dcheng1f4538e2014-10-27 23:57:05698 void SetUp() override {
pgal.u-szegedd84534d32014-10-29 12:34:30699 base::CommandLine::ForCurrentProcess()->AppendSwitch(
[email protected]eff4c7f2013-08-13 01:45:50700 keyboard::switches::kEnableVirtualKeyboard);
701 test::AshTestBase::SetUp();
[email protected]24ca45d2013-10-25 03:37:44702 Shell::GetPrimaryRootWindowController()->ActivateKeyboard(
[email protected]a0b3fb882014-04-07 19:26:03703 keyboard::KeyboardController::GetInstance());
[email protected]eff4c7f2013-08-13 01:45:50704 }
705
706 private:
707 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest);
708};
709
[email protected]2082d7d2014-05-13 14:44:23710class MockTextInputClient : public ui::DummyTextInputClient {
711 public:
712 MockTextInputClient() :
713 ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT) {}
714
dcheng1f4538e2014-10-27 23:57:05715 void EnsureCaretInRect(const gfx::Rect& rect) override {
[email protected]2082d7d2014-05-13 14:44:23716 visible_rect_ = rect;
717 }
718
719 const gfx::Rect& visible_rect() const {
720 return visible_rect_;
721 }
722
723 private:
724 gfx::Rect visible_rect_;
725
726 DISALLOW_COPY_AND_ASSIGN(MockTextInputClient);
727};
728
kevers23f3987d2014-09-17 13:50:12729class TargetHitTestEventHandler : public ui::test::TestEventHandler {
730 public:
731 TargetHitTestEventHandler() {}
732
733 // ui::test::TestEventHandler overrides.
dcheng1f4538e2014-10-27 23:57:05734 void OnMouseEvent(ui::MouseEvent* event) override {
kevers23f3987d2014-09-17 13:50:12735 if (event->type() == ui::ET_MOUSE_PRESSED)
736 ui::test::TestEventHandler::OnMouseEvent(event);
737 event->StopPropagation();
738 }
739
740 private:
741 DISALLOW_COPY_AND_ASSIGN(TargetHitTestEventHandler);
742};
743
[email protected]b6ba05d902013-10-04 21:38:45744// Test for http://crbug.com/297858. Virtual keyboard container should only show
745// on primary root window.
746TEST_F(VirtualKeyboardRootWindowControllerTest,
747 VirtualKeyboardOnPrimaryRootWindowOnly) {
748 if (!SupportsMultipleDisplays())
749 return;
750
751 UpdateDisplay("500x500,500x500");
752
[email protected]c9390bd2013-11-08 20:33:13753 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]bf9cdb362013-10-25 19:22:45754 aura::Window* primary_root_window = Shell::GetPrimaryRootWindow();
755 aura::Window* secondary_root_window =
[email protected]b6ba05d902013-10-04 21:38:45756 root_windows[0] == primary_root_window ?
757 root_windows[1] : root_windows[0];
758
[email protected]093b8d642014-04-03 20:59:28759 ASSERT_TRUE(Shell::GetContainer(primary_root_window,
760 kShellWindowId_VirtualKeyboardContainer));
761 ASSERT_FALSE(Shell::GetContainer(secondary_root_window,
762 kShellWindowId_VirtualKeyboardContainer));
[email protected]b6ba05d902013-10-04 21:38:45763}
764
[email protected]eff4c7f2013-08-13 01:45:50765// Test for http://crbug.com/263599. Virtual keyboard should be able to receive
766// events at blocked user session.
767TEST_F(VirtualKeyboardRootWindowControllerTest,
768 ClickVirtualKeyboardInBlockedWindow) {
[email protected]bf9cdb362013-10-25 19:22:45769 aura::Window* root_window = Shell::GetPrimaryRootWindow();
[email protected]093b8d642014-04-03 20:59:28770 aura::Window* keyboard_container =
771 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
[email protected]eff4c7f2013-08-13 01:45:50772 ASSERT_TRUE(keyboard_container);
773 keyboard_container->Show();
774
[email protected]a0b3fb882014-04-07 19:26:03775 aura::Window* keyboard_window = keyboard::KeyboardController::GetInstance()->
[email protected]647b4842013-12-12 14:24:24776 proxy()->GetKeyboardWindow();
777 keyboard_container->AddChild(keyboard_window);
[email protected]183e28d2014-01-20 18:18:02778 keyboard_window->set_owned_by_parent(false);
[email protected]647b4842013-12-12 14:24:24779 keyboard_window->SetBounds(gfx::Rect());
[email protected]eff4c7f2013-08-13 01:45:50780 keyboard_window->Show();
[email protected]647b4842013-12-12 14:24:24781
[email protected]3193ea722014-04-23 22:19:19782 ui::test::TestEventHandler handler;
783 root_window->AddPreTargetHandler(&handler);
[email protected]647b4842013-12-12 14:24:24784
[email protected]73c9fd02014-07-28 01:48:52785 ui::test::EventGenerator event_generator(root_window, keyboard_window);
[email protected]eff4c7f2013-08-13 01:45:50786 event_generator.ClickLeftButton();
787 int expected_mouse_presses = 1;
[email protected]3193ea722014-04-23 22:19:19788 EXPECT_EQ(expected_mouse_presses, handler.num_mouse_events() / 2);
[email protected]eff4c7f2013-08-13 01:45:50789
790 for (int block_reason = FIRST_BLOCK_REASON;
791 block_reason < NUMBER_OF_BLOCK_REASONS;
792 ++block_reason) {
793 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
794 event_generator.ClickLeftButton();
795 expected_mouse_presses++;
[email protected]3193ea722014-04-23 22:19:19796 EXPECT_EQ(expected_mouse_presses, handler.num_mouse_events() / 2);
[email protected]eff4c7f2013-08-13 01:45:50797 UnblockUserSession();
798 }
[email protected]3193ea722014-04-23 22:19:19799 root_window->RemovePreTargetHandler(&handler);
[email protected]eff4c7f2013-08-13 01:45:50800}
801
[email protected]45c66672013-10-01 22:48:56802// Test for http://crbug.com/299787. RootWindowController should delete
803// the old container since the keyboard controller creates a new window in
804// GetWindowContainer().
805TEST_F(VirtualKeyboardRootWindowControllerTest,
806 DeleteOldContainerOnVirtualKeyboardInit) {
[email protected]1025937e2014-02-13 01:25:50807 aura::Window* root_window = Shell::GetPrimaryRootWindow();
[email protected]093b8d642014-04-03 20:59:28808 aura::Window* keyboard_container =
809 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
[email protected]45c66672013-10-01 22:48:56810 ASSERT_TRUE(keyboard_container);
811 // Track the keyboard container window.
812 aura::WindowTracker tracker;
813 tracker.Add(keyboard_container);
[email protected]51f438112013-11-18 19:32:50814 // Mock a login user profile change to reinitialize the keyboard.
815 ash::Shell::GetInstance()->OnLoginUserProfilePrepared();
[email protected]45c66672013-10-01 22:48:56816 // keyboard_container should no longer be present.
817 EXPECT_FALSE(tracker.Contains(keyboard_container));
818}
819
[email protected]1025937e2014-02-13 01:25:50820// Test for crbug.com/342524. After user login, the work space should restore to
821// full screen.
822TEST_F(VirtualKeyboardRootWindowControllerTest, RestoreWorkspaceAfterLogin) {
823 aura::Window* root_window = Shell::GetPrimaryRootWindow();
[email protected]093b8d642014-04-03 20:59:28824 aura::Window* keyboard_container =
825 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
[email protected]1025937e2014-02-13 01:25:50826 keyboard_container->Show();
827 keyboard::KeyboardController* controller =
[email protected]a0b3fb882014-04-07 19:26:03828 keyboard::KeyboardController::GetInstance();
[email protected]1025937e2014-02-13 01:25:50829 aura::Window* keyboard_window = controller->proxy()->GetKeyboardWindow();
830 keyboard_container->AddChild(keyboard_window);
831 keyboard_window->set_owned_by_parent(false);
bshea0a57802015-04-08 18:21:29832 keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds(
833 root_window->bounds(), 100));
[email protected]1025937e2014-02-13 01:25:50834 keyboard_window->Show();
835
836 gfx::Rect before = ash::Shell::GetScreen()->GetPrimaryDisplay().work_area();
837
838 // Notify keyboard bounds changing.
bshea0a57802015-04-08 18:21:29839 controller->NotifyKeyboardBoundsChanging(keyboard_container->bounds());
[email protected]1025937e2014-02-13 01:25:50840
[email protected]25df7ad2014-04-30 18:10:25841 if (!keyboard::IsKeyboardOverscrollEnabled()) {
842 gfx::Rect after = ash::Shell::GetScreen()->GetPrimaryDisplay().work_area();
843 EXPECT_LT(after, before);
844 }
[email protected]1025937e2014-02-13 01:25:50845
846 // Mock a login user profile change to reinitialize the keyboard.
847 ash::Shell::GetInstance()->OnLoginUserProfilePrepared();
848 EXPECT_EQ(ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(), before);
849}
850
[email protected]602022b2014-03-31 17:07:31851// Ensure that system modal dialogs do not block events targeted at the virtual
852// keyboard.
853TEST_F(VirtualKeyboardRootWindowControllerTest, ClickWithActiveModalDialog) {
854 aura::Window* root_window = Shell::GetPrimaryRootWindow();
[email protected]093b8d642014-04-03 20:59:28855 aura::Window* keyboard_container =
856 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
[email protected]602022b2014-03-31 17:07:31857 ASSERT_TRUE(keyboard_container);
858 keyboard_container->Show();
859
[email protected]a0b3fb882014-04-07 19:26:03860 aura::Window* keyboard_window = keyboard::KeyboardController::GetInstance()->
[email protected]602022b2014-03-31 17:07:31861 proxy()->GetKeyboardWindow();
862 keyboard_container->AddChild(keyboard_window);
863 keyboard_window->set_owned_by_parent(false);
bshea0a57802015-04-08 18:21:29864 keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds(
865 root_window->bounds(), 100));
[email protected]3193ea722014-04-23 22:19:19866
867 ui::test::TestEventHandler handler;
868 root_window->AddPreTargetHandler(&handler);
[email protected]73c9fd02014-07-28 01:48:52869 ui::test::EventGenerator root_window_event_generator(root_window);
870 ui::test::EventGenerator keyboard_event_generator(root_window,
871 keyboard_window);
[email protected]602022b2014-03-31 17:07:31872
873 views::Widget* modal_widget =
874 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
875
876 // Verify that mouse events to the root window are block with a visble modal
877 // dialog.
878 root_window_event_generator.ClickLeftButton();
[email protected]3193ea722014-04-23 22:19:19879 EXPECT_EQ(0, handler.num_mouse_events());
[email protected]602022b2014-03-31 17:07:31880
881 // Verify that event dispatch to the virtual keyboard is unblocked.
882 keyboard_event_generator.ClickLeftButton();
[email protected]3193ea722014-04-23 22:19:19883 EXPECT_EQ(1, handler.num_mouse_events() / 2);
[email protected]602022b2014-03-31 17:07:31884
885 modal_widget->Close();
886
887 // Verify that mouse events are now unblocked to the root window.
888 root_window_event_generator.ClickLeftButton();
[email protected]3193ea722014-04-23 22:19:19889 EXPECT_EQ(2, handler.num_mouse_events() / 2);
890 root_window->RemovePreTargetHandler(&handler);
[email protected]602022b2014-03-31 17:07:31891}
892
[email protected]2082d7d2014-05-13 14:44:23893// Ensure that the visible area for scrolling the text caret excludes the
894// region occluded by the on-screen keyboard.
895TEST_F(VirtualKeyboardRootWindowControllerTest, EnsureCaretInWorkArea) {
896 keyboard::KeyboardController* keyboard_controller =
897 keyboard::KeyboardController::GetInstance();
898 keyboard::KeyboardControllerProxy* proxy = keyboard_controller->proxy();
899
900 MockTextInputClient text_input_client;
901 ui::InputMethod* input_method = proxy->GetInputMethod();
902 ASSERT_TRUE(input_method);
shuchen4e09795a2015-06-15 15:07:20903 input_method->SetFocusedTextInputClient(&text_input_client);
[email protected]2082d7d2014-05-13 14:44:23904
905 aura::Window* root_window = Shell::GetPrimaryRootWindow();
906 aura::Window* keyboard_container =
907 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
908 ASSERT_TRUE(keyboard_container);
909 keyboard_container->Show();
910
911 const int keyboard_height = 100;
912 aura::Window* keyboard_window =proxy->GetKeyboardWindow();
913 keyboard_container->AddChild(keyboard_window);
914 keyboard_window->set_owned_by_parent(false);
bshea0a57802015-04-08 18:21:29915 keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds(
916 root_window->bounds(), keyboard_height));
[email protected]2082d7d2014-05-13 14:44:23917
918 proxy->EnsureCaretInWorkArea();
bshea0a57802015-04-08 18:21:29919 ASSERT_EQ(root_window->bounds().width(),
[email protected]2082d7d2014-05-13 14:44:23920 text_input_client.visible_rect().width());
bshea0a57802015-04-08 18:21:29921 ASSERT_EQ(root_window->bounds().height() - keyboard_height,
[email protected]2082d7d2014-05-13 14:44:23922 text_input_client.visible_rect().height());
[email protected]00a386792014-06-16 15:09:20923
shuchen4e09795a2015-06-15 15:07:20924 input_method->SetFocusedTextInputClient(NULL);
[email protected]2082d7d2014-05-13 14:44:23925}
926
kevers23f3987d2014-09-17 13:50:12927// Tests that the virtual keyboard does not block context menus. The virtual
928// keyboard should appear in front of most content, but not context menus. See
929// crbug/377180.
930TEST_F(VirtualKeyboardRootWindowControllerTest, ZOrderTest) {
931 UpdateDisplay("800x600");
932 keyboard::KeyboardController* keyboard_controller =
933 keyboard::KeyboardController::GetInstance();
934 keyboard::KeyboardControllerProxy* proxy = keyboard_controller->proxy();
935
936 aura::Window* root_window = Shell::GetPrimaryRootWindow();
937 aura::Window* keyboard_container =
938 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
939 ASSERT_TRUE(keyboard_container);
940 keyboard_container->Show();
941
942 const int keyboard_height = 200;
943 aura::Window* keyboard_window = proxy->GetKeyboardWindow();
944 keyboard_container->AddChild(keyboard_window);
945 keyboard_window->set_owned_by_parent(false);
bshea0a57802015-04-08 18:21:29946 gfx::Rect keyboard_bounds = keyboard::FullWidthKeyboardBoundsFromRootBounds(
947 root_window->bounds(), keyboard_height);
kevers23f3987d2014-09-17 13:50:12948 keyboard_window->SetBounds(keyboard_bounds);
949 keyboard_window->Show();
950
951 ui::test::EventGenerator generator(root_window);
952
953 // Cover the screen with two windows: a normal window on the left side and a
954 // context menu on the right side. When the virtual keyboard is displayed it
955 // partially occludes the normal window, but not the context menu. Compute
956 // positions for generating synthetic click events to perform hit tests,
957 // ensuring the correct window layering. 'top' is above the VK, whereas
958 // 'bottom' lies within the VK. 'left' is centered in the normal window, and
959 // 'right' is centered in the context menu.
960 int window_height = keyboard_bounds.bottom();
961 int window_width = keyboard_bounds.width() / 2;
962 int left = window_width / 2;
963 int right = 3 * window_width / 2;
964 int top = keyboard_bounds.y() / 2;
965 int bottom = window_height - keyboard_height / 2;
966
967 // Normal window is partially occluded by the virtual keyboard.
968 aura::test::TestWindowDelegate delegate;
969 scoped_ptr<aura::Window> normal(CreateTestWindowInShellWithDelegateAndType(
970 &delegate,
971 ui::wm::WINDOW_TYPE_NORMAL,
972 0,
973 gfx::Rect(0, 0, window_width, window_height)));
974 normal->set_owned_by_parent(false);
975 normal->Show();
976 TargetHitTestEventHandler normal_handler;
977 normal->AddPreTargetHandler(&normal_handler);
978
979 // Test that only the click on the top portion of the window is picked up. The
980 // click on the bottom hits the virtual keyboard instead.
981 generator.MoveMouseTo(left, top);
982 generator.ClickLeftButton();
983 EXPECT_EQ(1, normal_handler.num_mouse_events());
984 generator.MoveMouseTo(left, bottom);
985 generator.ClickLeftButton();
986 EXPECT_EQ(1, normal_handler.num_mouse_events());
987
988 // Menu overlaps virtual keyboard.
989 aura::test::TestWindowDelegate delegate2;
990 scoped_ptr<aura::Window> menu(CreateTestWindowInShellWithDelegateAndType(
991 &delegate2,
992 ui::wm::WINDOW_TYPE_MENU,
993 0,
994 gfx::Rect(window_width, 0, window_width, window_height)));
995 menu->set_owned_by_parent(false);
996 menu->Show();
997 TargetHitTestEventHandler menu_handler;
998 menu->AddPreTargetHandler(&menu_handler);
999
1000 // Test that both clicks register.
1001 generator.MoveMouseTo(right, top);
1002 generator.ClickLeftButton();
1003 EXPECT_EQ(1, menu_handler.num_mouse_events());
1004 generator.MoveMouseTo(right, bottom);
1005 generator.ClickLeftButton();
1006 EXPECT_EQ(2, menu_handler.num_mouse_events());
1007
1008 // Cleanup to ensure that the test windows are destroyed before their
1009 // delegates.
1010 normal.reset();
1011 menu.reset();
1012}
1013
kevers0e450492014-09-30 16:02:311014// Resolution in UpdateDisplay is not being respected on Windows 8.
1015#if defined(OS_WIN)
1016#define MAYBE_DisplayRotation DISABLED_DisplayRotation
1017#else
1018#define MAYBE_DisplayRotation DisplayRotation
1019#endif
1020
1021// Tests that the virtual keyboard correctly resizes with a change to display
1022// orientation. See crbug/417612.
1023TEST_F(VirtualKeyboardRootWindowControllerTest, MAYBE_DisplayRotation) {
1024 UpdateDisplay("800x600");
1025 aura::Window* root_window = Shell::GetPrimaryRootWindow();
1026 aura::Window* keyboard_container =
1027 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
1028 ASSERT_TRUE(keyboard_container);
bshea0a57802015-04-08 18:21:291029 keyboard::KeyboardController* keyboard_controller =
1030 keyboard::KeyboardController::GetInstance();
1031 keyboard_controller->ShowKeyboard(false);
1032 keyboard_controller->proxy()->GetKeyboardWindow()->SetBounds(
1033 gfx::Rect(0, 400, 800, 200));
1034 EXPECT_EQ("0,400 800x200", keyboard_container->bounds().ToString());
kevers0e450492014-09-30 16:02:311035
1036 UpdateDisplay("600x800");
bshea0a57802015-04-08 18:21:291037 EXPECT_EQ("0,600 600x200", keyboard_container->bounds().ToString());
kevers0e450492014-09-30 16:02:311038}
1039
[email protected]f1853122012-06-27 16:21:261040} // namespace test
1041} // namespace ash