blob: 8807851def2b3c7f7b55e9cc2c7bda4abbd3950b [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
[email protected]fdf74bf2014-04-30 21:24:027#include "ash/session/session_state_delegate.h"
[email protected]478c6c32013-03-09 02:50:588#include "ash/shelf/shelf_layout_manager.h"
[email protected]f1853122012-06-27 16:21:269#include "ash/shell.h"
10#include "ash/shell_window_ids.h"
[email protected]8674b312012-10-12 19:02:4411#include "ash/system/tray/system_tray_delegate.h"
[email protected]f1853122012-06-27 16:21:2612#include "ash/test/ash_test_base.h"
oshima022a9542015-05-01 00:15:0213#include "ash/test/display_manager_test_api.h"
[email protected]8674b312012-10-12 19:02:4414#include "ash/wm/system_modal_container_layout_manager.h"
[email protected]2ee2f5d2013-01-10 23:37:1615#include "ash/wm/window_properties.h"
[email protected]a41b4e12013-09-20 04:36:3416#include "ash/wm/window_state.h"
[email protected]f1853122012-06-27 16:21:2617#include "ash/wm/window_util.h"
[email protected]eff4c7f2013-08-13 01:45:5018#include "base/command_line.h"
kevers23f3987d2014-09-17 13:50:1219#include "base/memory/scoped_ptr.h"
[email protected]792b9b12012-12-11 03:53:2720#include "ui/aura/client/focus_change_observer.h"
[email protected]8cfb6722012-11-28 03:28:4621#include "ui/aura/client/focus_client.h"
[email protected]e3225e02013-10-23 20:44:3722#include "ui/aura/client/window_tree_client.h"
[email protected]f1853122012-06-27 16:21:2623#include "ui/aura/env.h"
[email protected]dbf835d82012-09-11 18:23:0924#include "ui/aura/test/test_window_delegate.h"
25#include "ui/aura/test/test_windows.h"
[email protected]f1853122012-06-27 16:21:2626#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2627#include "ui/aura/window_event_dispatcher.h"
[email protected]dbf835d82012-09-11 18:23:0928#include "ui/aura/window_tracker.h"
[email protected]2082d7d2014-05-13 14:44:2329#include "ui/base/ime/dummy_text_input_client.h"
30#include "ui/base/ime/input_method.h"
31#include "ui/base/ime/text_input_client.h"
[email protected]00a386792014-06-16 15:09:2032#include "ui/base/ime/text_input_focus_manager.h"
33#include "ui/base/ui_base_switches_util.h"
[email protected]73c9fd02014-07-28 01:48:5234#include "ui/events/test/event_generator.h"
[email protected]cd9f71d2014-03-20 21:54:2135#include "ui/events/test/test_event_handler.h"
[email protected]647b4842013-12-12 14:24:2436#include "ui/keyboard/keyboard_controller_proxy.h"
[email protected]eff4c7f2013-08-13 01:45:5037#include "ui/keyboard/keyboard_switches.h"
[email protected]39e95212014-04-23 20:00:0138#include "ui/keyboard/keyboard_util.h"
[email protected]f1853122012-06-27 16:21:2639#include "ui/views/controls/menu/menu_controller.h"
40#include "ui/views/widget/widget.h"
41#include "ui/views/widget/widget_delegate.h"
42
[email protected]2ee2f5d2013-01-10 23:37:1643using aura::Window;
44using views::Widget;
45
[email protected]f1853122012-06-27 16:21:2646namespace ash {
47namespace {
48
49class TestDelegate : public views::WidgetDelegateView {
50 public:
51 explicit TestDelegate(bool system_modal) : system_modal_(system_modal) {}
dcheng1f4538e2014-10-27 23:57:0552 ~TestDelegate() override {}
[email protected]f1853122012-06-27 16:21:2653
54 // Overridden from views::WidgetDelegate:
dcheng1f4538e2014-10-27 23:57:0555 views::View* GetContentsView() override { return this; }
[email protected]f1853122012-06-27 16:21:2656
dcheng1f4538e2014-10-27 23:57:0557 ui::ModalType GetModalType() const override {
[email protected]f1853122012-06-27 16:21:2658 return system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE;
59 }
60
61 private:
62 bool system_modal_;
[email protected]0fbfa972013-10-02 19:23:3363
[email protected]f1853122012-06-27 16:21:2664 DISALLOW_COPY_AND_ASSIGN(TestDelegate);
65};
66
[email protected]792b9b12012-12-11 03:53:2767class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate,
68 public aura::client::FocusChangeObserver {
[email protected]dbf835d82012-09-11 18:23:0969 public:
70 DeleteOnBlurDelegate() : window_(NULL) {}
dcheng1f4538e2014-10-27 23:57:0571 ~DeleteOnBlurDelegate() override {}
[email protected]dbf835d82012-09-11 18:23:0972
[email protected]792b9b12012-12-11 03:53:2773 void SetWindow(aura::Window* window) {
74 window_ = window;
75 aura::client::SetFocusChangeObserver(window_, this);
76 }
[email protected]dbf835d82012-09-11 18:23:0977
[email protected]869f6352012-12-06 20:47:1778 private:
[email protected]dbf835d82012-09-11 18:23:0979 // aura::test::TestWindowDelegate overrides:
dcheng1f4538e2014-10-27 23:57:0580 bool CanFocus() override { return true; }
[email protected]dbf835d82012-09-11 18:23:0981
[email protected]792b9b12012-12-11 03:53:2782 // aura::client::FocusChangeObserver implementation:
dcheng1f4538e2014-10-27 23:57:0583 void OnWindowFocused(aura::Window* gained_focus,
84 aura::Window* lost_focus) override {
[email protected]792b9b12012-12-11 03:53:2785 if (window_ == lost_focus)
86 delete window_;
[email protected]869f6352012-12-06 20:47:1787 }
88
[email protected]dbf835d82012-09-11 18:23:0989 aura::Window* window_;
90
91 DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate);
92};
93
[email protected]f1853122012-06-27 16:21:2694} // namespace
95
96namespace test {
[email protected]f1853122012-06-27 16:21:2697
[email protected]a2e6af12013-01-07 21:40:3598class RootWindowControllerTest : public test::AshTestBase {
99 public:
100 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
101 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
102 NULL, CurrentContext(), bounds);
103 widget->Show();
104 return widget;
105 }
106
107 views::Widget* CreateModalWidget(const gfx::Rect& bounds) {
108 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
109 new TestDelegate(true), CurrentContext(), bounds);
110 widget->Show();
111 return widget;
112 }
113
114 views::Widget* CreateModalWidgetWithParent(const gfx::Rect& bounds,
115 gfx::NativeWindow parent) {
116 views::Widget* widget =
117 views::Widget::CreateWindowWithParentAndBounds(new TestDelegate(true),
118 parent,
119 bounds);
120 widget->Show();
121 return widget;
122 }
123
[email protected]c9390bd2013-11-08 20:33:13124 aura::Window* GetModalContainer(aura::Window* root_window) {
[email protected]093b8d642014-04-03 20:59:28125 return Shell::GetContainer(root_window,
126 ash::kShellWindowId_SystemModalContainer);
[email protected]a2e6af12013-01-07 21:40:35127 }
128};
[email protected]f1853122012-06-27 16:21:26129
[email protected]e75642a2013-06-12 17:21:18130TEST_F(RootWindowControllerTest, MoveWindows_Basic) {
131 if (!SupportsMultipleDisplays())
132 return;
[email protected]2816c2462013-12-17 02:22:25133 // Windows origin should be doubled when moved to the 1st display.
134 UpdateDisplay("600x600,300x300");
[email protected]c9390bd2013-11-08 20:33:13135 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]093b8d642014-04-03 20:59:28136 RootWindowController* controller = Shell::GetPrimaryRootWindowController();
137 ShelfLayoutManager* shelf_layout_manager =
[email protected]478c6c32013-03-09 02:50:58138 controller->GetShelfLayoutManager();
139 shelf_layout_manager->SetAutoHideBehavior(
140 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
[email protected]f1853122012-06-27 16:21:26141
142 views::Widget* normal = CreateTestWidget(gfx::Rect(650, 10, 100, 100));
143 EXPECT_EQ(root_windows[1], normal->GetNativeView()->GetRootWindow());
[email protected]e2f64d102012-07-19 19:17:04144 EXPECT_EQ("650,10 100x100", normal->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06145 EXPECT_EQ("50,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04146 normal->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26147
148 views::Widget* maximized = CreateTestWidget(gfx::Rect(700, 10, 100, 100));
149 maximized->Maximize();
150 EXPECT_EQ(root_windows[1], maximized->GetNativeView()->GetRootWindow());
[email protected]2816c2462013-12-17 02:22:25151 EXPECT_EQ("600,0 300x253", maximized->GetWindowBoundsInScreen().ToString());
152 EXPECT_EQ("0,0 300x253",
[email protected]8c0ec432013-05-10 04:33:39153 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26154
155 views::Widget* minimized = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
156 minimized->Minimize();
157 EXPECT_EQ(root_windows[1], minimized->GetNativeView()->GetRootWindow());
[email protected]8d625fb2012-07-18 16:40:06158 EXPECT_EQ("800,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04159 minimized->GetWindowBoundsInScreen().ToString());
[email protected]f1853122012-06-27 16:21:26160
[email protected]2816c2462013-12-17 02:22:25161 views::Widget* fullscreen = CreateTestWidget(gfx::Rect(850, 10, 100, 100));
[email protected]f1853122012-06-27 16:21:26162 fullscreen->SetFullscreen(true);
163 EXPECT_EQ(root_windows[1], fullscreen->GetNativeView()->GetRootWindow());
[email protected]1a015382012-12-01 19:44:59164
[email protected]2816c2462013-12-17 02:22:25165 EXPECT_EQ("600,0 300x300",
[email protected]e2f64d102012-07-19 19:17:04166 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]2816c2462013-12-17 02:22:25167 EXPECT_EQ("0,0 300x300",
[email protected]e2f64d102012-07-19 19:17:04168 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26169
[email protected]8f2f151412013-01-26 03:58:37170 views::Widget* unparented_control = new Widget;
171 Widget::InitParams params;
172 params.bounds = gfx::Rect(650, 10, 100, 100);
173 params.context = CurrentContext();
174 params.type = Widget::InitParams::TYPE_CONTROL;
175 unparented_control->Init(params);
176 EXPECT_EQ(root_windows[1],
177 unparented_control->GetNativeView()->GetRootWindow());
[email protected]093b8d642014-04-03 20:59:28178 EXPECT_EQ(kShellWindowId_UnparentedControlContainer,
[email protected]8f2f151412013-01-26 03:58:37179 unparented_control->GetNativeView()->parent()->id());
180
[email protected]95db9c12013-01-31 11:47:44181 aura::Window* panel = CreateTestWindowInShellWithDelegateAndType(
[email protected]5b251f12013-12-19 01:50:05182 NULL, ui::wm::WINDOW_TYPE_PANEL, 0, gfx::Rect(700, 100, 100, 100));
[email protected]95db9c12013-01-31 11:47:44183 EXPECT_EQ(root_windows[1], panel->GetRootWindow());
[email protected]093b8d642014-04-03 20:59:28184 EXPECT_EQ(kShellWindowId_PanelContainer, panel->parent()->id());
[email protected]95db9c12013-01-31 11:47:44185
[email protected]dbf835d82012-09-11 18:23:09186 // Make sure a window that will delete itself when losing focus
187 // will not crash.
188 aura::WindowTracker tracker;
189 DeleteOnBlurDelegate delete_on_blur_delegate;
[email protected]5ebe6102012-11-28 21:00:03190 aura::Window* d2 = CreateTestWindowInShellWithDelegate(
191 &delete_on_blur_delegate, 0, gfx::Rect(50, 50, 100, 100));
[email protected]792b9b12012-12-11 03:53:27192 delete_on_blur_delegate.SetWindow(d2);
[email protected]550543e2013-01-11 22:43:44193 aura::client::GetFocusClient(root_windows[0])->FocusWindow(d2);
[email protected]dbf835d82012-09-11 18:23:09194 tracker.Add(d2);
195
[email protected]f634dd32012-07-23 22:49:07196 UpdateDisplay("600x600");
[email protected]f1853122012-06-27 16:21:26197
[email protected]dbf835d82012-09-11 18:23:09198 // d2 must have been deleted.
199 EXPECT_FALSE(tracker.Contains(d2));
200
[email protected]f1853122012-06-27 16:21:26201 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
[email protected]2816c2462013-12-17 02:22:25202 EXPECT_EQ("100,20 100x100", normal->GetWindowBoundsInScreen().ToString());
203 EXPECT_EQ("100,20 100x100",
[email protected]e2f64d102012-07-19 19:17:04204 normal->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26205
[email protected]eefd51b22012-09-25 20:26:24206 // Maximized area on primary display has 3px (given as
[email protected]f1853122012-06-27 16:21:26207 // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom.
[email protected]2a64b0a2013-07-23 23:15:54208
209 // First clear fullscreen status, since both fullscreen and maximized windows
210 // share the same desktop workspace, which cancels the shelf status.
211 fullscreen->SetFullscreen(false);
[email protected]f1853122012-06-27 16:21:26212 EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow());
[email protected]7b675df612012-09-16 18:33:20213 EXPECT_EQ("0,0 600x597",
[email protected]e2f64d102012-07-19 19:17:04214 maximized->GetWindowBoundsInScreen().ToString());
[email protected]7b675df612012-09-16 18:33:20215 EXPECT_EQ("0,0 600x597",
[email protected]e2f64d102012-07-19 19:17:04216 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26217
[email protected]2a64b0a2013-07-23 23:15:54218 // Set fullscreen to true. In that case the 3px inset becomes invisible so
219 // the maximized window can also use the area fully.
220 fullscreen->SetFullscreen(true);
221 EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow());
222 EXPECT_EQ("0,0 600x600",
223 maximized->GetWindowBoundsInScreen().ToString());
224 EXPECT_EQ("0,0 600x600",
225 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
226
[email protected]f1853122012-06-27 16:21:26227 EXPECT_EQ(root_windows[0], minimized->GetNativeView()->GetRootWindow());
[email protected]2816c2462013-12-17 02:22:25228 EXPECT_EQ("400,20 100x100",
[email protected]e2f64d102012-07-19 19:17:04229 minimized->GetWindowBoundsInScreen().ToString());
[email protected]f1853122012-06-27 16:21:26230
231 EXPECT_EQ(root_windows[0], fullscreen->GetNativeView()->GetRootWindow());
232 EXPECT_TRUE(fullscreen->IsFullscreen());
[email protected]8d625fb2012-07-18 16:40:06233 EXPECT_EQ("0,0 600x600",
[email protected]e2f64d102012-07-19 19:17:04234 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06235 EXPECT_EQ("0,0 600x600",
[email protected]e2f64d102012-07-19 19:17:04236 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]8d625fb2012-07-18 16:40:06237
238 // Test if the restore bounds are correctly updated.
[email protected]a41b4e12013-09-20 04:36:34239 wm::GetWindowState(maximized->GetNativeView())->Restore();
[email protected]2816c2462013-12-17 02:22:25240 EXPECT_EQ("200,20 100x100", maximized->GetWindowBoundsInScreen().ToString());
241 EXPECT_EQ("200,20 100x100",
[email protected]e2f64d102012-07-19 19:17:04242 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]8d625fb2012-07-18 16:40:06243
244 fullscreen->SetFullscreen(false);
[email protected]2816c2462013-12-17 02:22:25245 EXPECT_EQ("500,20 100x100",
[email protected]e2f64d102012-07-19 19:17:04246 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]2816c2462013-12-17 02:22:25247 EXPECT_EQ("500,20 100x100",
[email protected]e2f64d102012-07-19 19:17:04248 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]8f2f151412013-01-26 03:58:37249
250 // Test if the unparented widget has moved.
251 EXPECT_EQ(root_windows[0],
252 unparented_control->GetNativeView()->GetRootWindow());
[email protected]093b8d642014-04-03 20:59:28253 EXPECT_EQ(kShellWindowId_UnparentedControlContainer,
[email protected]8f2f151412013-01-26 03:58:37254 unparented_control->GetNativeView()->parent()->id());
[email protected]95db9c12013-01-31 11:47:44255
256 // Test if the panel has moved.
257 EXPECT_EQ(root_windows[0], panel->GetRootWindow());
[email protected]093b8d642014-04-03 20:59:28258 EXPECT_EQ(kShellWindowId_PanelContainer, panel->parent()->id());
[email protected]f1853122012-06-27 16:21:26259}
260
[email protected]e75642a2013-06-12 17:21:18261TEST_F(RootWindowControllerTest, MoveWindows_Modal) {
262 if (!SupportsMultipleDisplays())
263 return;
[email protected]1c3f7002013-01-21 18:46:05264
[email protected]f634dd32012-07-23 22:49:07265 UpdateDisplay("500x500,500x500");
[email protected]f1853122012-06-27 16:21:26266
[email protected]c9390bd2013-11-08 20:33:13267 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f1853122012-06-27 16:21:26268 // Emulate virtual screen coordinate system.
269 root_windows[0]->SetBounds(gfx::Rect(0, 0, 500, 500));
270 root_windows[1]->SetBounds(gfx::Rect(500, 0, 500, 500));
271
272 views::Widget* normal = CreateTestWidget(gfx::Rect(300, 10, 100, 100));
273 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
274 EXPECT_TRUE(wm::IsActiveWindow(normal->GetNativeView()));
275
276 views::Widget* modal = CreateModalWidget(gfx::Rect(650, 10, 100, 100));
277 EXPECT_EQ(root_windows[1], modal->GetNativeView()->GetRootWindow());
278 EXPECT_TRUE(GetModalContainer(root_windows[1])->Contains(
279 modal->GetNativeView()));
280 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
281
[email protected]73c9fd02014-07-28 01:48:52282 ui::test::EventGenerator generator_1st(root_windows[0]);
[email protected]f1853122012-06-27 16:21:26283 generator_1st.ClickLeftButton();
284 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
285
[email protected]f634dd32012-07-23 22:49:07286 UpdateDisplay("500x500");
[email protected]f1853122012-06-27 16:21:26287 EXPECT_EQ(root_windows[0], modal->GetNativeView()->GetRootWindow());
288 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
289 generator_1st.ClickLeftButton();
290 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
291}
292
oshima022a9542015-05-01 00:15:02293// Make sure lock related windows moves.
294TEST_F(RootWindowControllerTest, MoveWindows_LockWindowsInUnified) {
295 if (!SupportsMultipleDisplays())
296 return;
297 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
298 DisplayManagerTestApi test_api(display_manager);
299 test_api.SetDefaultMultiDisplayMode(DisplayManager::UNIFIED);
300 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));
338 EXPECT_EQ("0,0 1000x500",
339 lock_screen->GetNativeWindow()->bounds().ToString());
340
341 // Switch to mirror.
342 display_manager->SetMirrorMode(true);
343 EXPECT_TRUE(display_manager->IsInMirrorMode());
344
345 controller = Shell::GetInstance()->GetPrimaryRootWindowController();
346 ASSERT_EQ(lock_screen->GetNativeWindow(),
347 controller->GetRootWindow()->GetChildById(kLockScreenWindowId));
348 ASSERT_EQ(lock_background->GetNativeWindow(),
349 controller->GetRootWindow()->GetChildById(kLockBackgroundWindowId));
350 EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString());
351
352 // Switch to unified.
353 display_manager->SetMirrorMode(false);
354 EXPECT_TRUE(display_manager->IsInUnifiedMode());
355
356 controller = Shell::GetInstance()->GetPrimaryRootWindowController();
357
358 ASSERT_EQ(lock_screen->GetNativeWindow(),
359 controller->GetRootWindow()->GetChildById(kLockScreenWindowId));
360 ASSERT_EQ(lock_background->GetNativeWindow(),
361 controller->GetRootWindow()->GetChildById(kLockBackgroundWindowId));
362 EXPECT_EQ("0,0 1000x500",
363 lock_screen->GetNativeWindow()->bounds().ToString());
364
365 // Switch to single display.
366 UpdateDisplay("600x500");
367 EXPECT_FALSE(display_manager->IsInUnifiedMode());
368 EXPECT_FALSE(display_manager->IsInMirrorMode());
369
370 controller = Shell::GetInstance()->GetPrimaryRootWindowController();
371
372 ASSERT_EQ(lock_screen->GetNativeWindow(),
373 controller->GetRootWindow()->GetChildById(kLockScreenWindowId));
374 ASSERT_EQ(lock_background->GetNativeWindow(),
375 controller->GetRootWindow()->GetChildById(kLockBackgroundWindowId));
376 EXPECT_EQ("0,0 600x500", lock_screen->GetNativeWindow()->bounds().ToString());
377}
378
[email protected]8674b312012-10-12 19:02:44379TEST_F(RootWindowControllerTest, ModalContainer) {
380 UpdateDisplay("600x600");
381 Shell* shell = Shell::GetInstance();
[email protected]093b8d642014-04-03 20:59:28382 RootWindowController* controller = shell->GetPrimaryRootWindowController();
[email protected]8674b312012-10-12 19:02:44383 EXPECT_EQ(user::LOGGED_IN_USER,
[email protected]945f9cae2012-12-12 09:54:29384 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]f5c9dbc2014-04-11 08:13:45385 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28386 ->layout_manager(),
387 controller->GetSystemModalLayoutManager(NULL));
[email protected]8674b312012-10-12 19:02:44388
[email protected]3b162e12012-11-09 11:52:35389 views::Widget* session_modal_widget =
390 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
[email protected]f5c9dbc2014-04-11 08:13:45391 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28392 ->layout_manager(),
393 controller->GetSystemModalLayoutManager(
394 session_modal_widget->GetNativeView()));
[email protected]3b162e12012-11-09 11:52:35395
[email protected]fcb123d2013-04-17 15:58:49396 shell->session_state_delegate()->LockScreen();
[email protected]8674b312012-10-12 19:02:44397 EXPECT_EQ(user::LOGGED_IN_LOCKED,
[email protected]945f9cae2012-12-12 09:54:29398 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]f5c9dbc2014-04-11 08:13:45399 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28400 ->layout_manager(),
401 controller->GetSystemModalLayoutManager(NULL));
[email protected]3b162e12012-11-09 11:52:35402
[email protected]f5c9dbc2014-04-11 08:13:45403 aura::Window* lock_container =
404 controller->GetContainer(kShellWindowId_LockScreenContainer);
[email protected]3b162e12012-11-09 11:52:35405 views::Widget* lock_modal_widget =
406 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container);
[email protected]f5c9dbc2014-04-11 08:13:45407 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28408 ->layout_manager(),
409 controller->GetSystemModalLayoutManager(
410 lock_modal_widget->GetNativeView()));
[email protected]f5c9dbc2014-04-11 08:13:45411 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28412 ->layout_manager(),
[email protected]3b162e12012-11-09 11:52:35413 controller->GetSystemModalLayoutManager(
414 session_modal_widget->GetNativeView()));
415
[email protected]fcb123d2013-04-17 15:58:49416 shell->session_state_delegate()->UnlockScreen();
[email protected]8674b312012-10-12 19:02:44417}
418
[email protected]1b219922012-11-13 21:16:43419TEST_F(RootWindowControllerTest, ModalContainerNotLoggedInLoggedIn) {
420 UpdateDisplay("600x600");
421 Shell* shell = Shell::GetInstance();
422
423 // Configure login screen environment.
424 SetUserLoggedIn(false);
425 EXPECT_EQ(user::LOGGED_IN_NONE,
[email protected]945f9cae2012-12-12 09:54:29426 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]c8d19f82013-05-18 09:09:41427 EXPECT_EQ(0, shell->session_state_delegate()->NumberOfLoggedInUsers());
[email protected]fcb123d2013-04-17 15:58:49428 EXPECT_FALSE(shell->session_state_delegate()->IsActiveUserSessionStarted());
[email protected]1b219922012-11-13 21:16:43429
[email protected]093b8d642014-04-03 20:59:28430 RootWindowController* controller = shell->GetPrimaryRootWindowController();
[email protected]f5c9dbc2014-04-11 08:13:45431 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28432 ->layout_manager(),
433 controller->GetSystemModalLayoutManager(NULL));
[email protected]1b219922012-11-13 21:16:43434
[email protected]f5c9dbc2014-04-11 08:13:45435 aura::Window* lock_container =
436 controller->GetContainer(kShellWindowId_LockScreenContainer);
[email protected]1b219922012-11-13 21:16:43437 views::Widget* login_modal_widget =
438 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container);
[email protected]f5c9dbc2014-04-11 08:13:45439 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28440 ->layout_manager(),
441 controller->GetSystemModalLayoutManager(
442 login_modal_widget->GetNativeView()));
[email protected]1b219922012-11-13 21:16:43443 login_modal_widget->Close();
444
445 // Configure user session environment.
446 SetUserLoggedIn(true);
447 SetSessionStarted(true);
448 EXPECT_EQ(user::LOGGED_IN_USER,
[email protected]945f9cae2012-12-12 09:54:29449 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]c8d19f82013-05-18 09:09:41450 EXPECT_EQ(1, shell->session_state_delegate()->NumberOfLoggedInUsers());
[email protected]fcb123d2013-04-17 15:58:49451 EXPECT_TRUE(shell->session_state_delegate()->IsActiveUserSessionStarted());
[email protected]f5c9dbc2014-04-11 08:13:45452 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28453 ->layout_manager(),
454 controller->GetSystemModalLayoutManager(NULL));
[email protected]1b219922012-11-13 21:16:43455
456 views::Widget* session_modal_widget =
457 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
[email protected]f5c9dbc2014-04-11 08:13:45458 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28459 ->layout_manager(),
460 controller->GetSystemModalLayoutManager(
461 session_modal_widget->GetNativeView()));
[email protected]1b219922012-11-13 21:16:43462}
463
[email protected]a44afbbd2013-07-24 21:49:35464TEST_F(RootWindowControllerTest, ModalContainerBlockedSession) {
465 UpdateDisplay("600x600");
Peter Kastingbe940e92014-11-20 23:14:08466 RootWindowController* controller = Shell::GetPrimaryRootWindowController();
[email protected]f5c9dbc2014-04-11 08:13:45467 aura::Window* lock_container =
468 controller->GetContainer(kShellWindowId_LockScreenContainer);
[email protected]a44afbbd2013-07-24 21:49:35469 for (int block_reason = FIRST_BLOCK_REASON;
470 block_reason < NUMBER_OF_BLOCK_REASONS;
471 ++block_reason) {
472 views::Widget* session_modal_widget =
473 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
[email protected]f5c9dbc2014-04-11 08:13:45474 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28475 ->layout_manager(),
476 controller->GetSystemModalLayoutManager(
477 session_modal_widget->GetNativeView()));
[email protected]f5c9dbc2014-04-11 08:13:45478 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28479 ->layout_manager(),
480 controller->GetSystemModalLayoutManager(NULL));
[email protected]a44afbbd2013-07-24 21:49:35481 session_modal_widget->Close();
482
483 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
484
[email protected]f5c9dbc2014-04-11 08:13:45485 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28486 ->layout_manager(),
487 controller->GetSystemModalLayoutManager(NULL));
[email protected]a44afbbd2013-07-24 21:49:35488
489 views::Widget* lock_modal_widget =
490 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100),
491 lock_container);
[email protected]f5c9dbc2014-04-11 08:13:45492 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28493 ->layout_manager(),
[email protected]a44afbbd2013-07-24 21:49:35494 controller->GetSystemModalLayoutManager(
495 lock_modal_widget->GetNativeView()));
496
497 session_modal_widget =
498 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
[email protected]f5c9dbc2014-04-11 08:13:45499 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28500 ->layout_manager(),
501 controller->GetSystemModalLayoutManager(
502 session_modal_widget->GetNativeView()));
[email protected]a44afbbd2013-07-24 21:49:35503 session_modal_widget->Close();
504
505 lock_modal_widget->Close();
506 UnblockUserSession();
507 }
508}
509
[email protected]2c9171d22013-12-10 21:55:10510TEST_F(RootWindowControllerTest, GetWindowForFullscreenMode) {
[email protected]2ee2f5d2013-01-10 23:37:16511 UpdateDisplay("600x600");
[email protected]093b8d642014-04-03 20:59:28512 RootWindowController* controller =
[email protected]2ee2f5d2013-01-10 23:37:16513 Shell::GetInstance()->GetPrimaryRootWindowController();
514
[email protected]700849f2013-04-30 17:49:20515 Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
[email protected]2ee2f5d2013-01-10 23:37:16516 w1->Maximize();
[email protected]700849f2013-04-30 17:49:20517 Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
518 w2->SetFullscreen(true);
519 // |w3| is a transient child of |w2|.
520 Widget* w3 = Widget::CreateWindowWithParentAndBounds(NULL,
521 w2->GetNativeWindow(), gfx::Rect(0, 0, 100, 100));
[email protected]2ee2f5d2013-01-10 23:37:16522
[email protected]2c9171d22013-12-10 21:55:10523 // Test that GetWindowForFullscreenMode() finds the fullscreen window when one
[email protected]e3bc88e2013-09-06 06:22:06524 // of its transient children is active.
[email protected]700849f2013-04-30 17:49:20525 w3->Activate();
[email protected]2c9171d22013-12-10 21:55:10526 EXPECT_EQ(w2->GetNativeWindow(), controller->GetWindowForFullscreenMode());
[email protected]2ee2f5d2013-01-10 23:37:16527
[email protected]2c9171d22013-12-10 21:55:10528 // If the topmost window is not fullscreen, it returns NULL.
[email protected]700849f2013-04-30 17:49:20529 w1->Activate();
[email protected]2c9171d22013-12-10 21:55:10530 EXPECT_EQ(NULL, controller->GetWindowForFullscreenMode());
531 w1->Close();
532 w3->Close();
[email protected]e3bc88e2013-09-06 06:22:06533
[email protected]2c9171d22013-12-10 21:55:10534 // Only w2 remains, if minimized GetWindowForFullscreenMode should return
535 // NULL.
[email protected]e3bc88e2013-09-06 06:22:06536 w2->Activate();
[email protected]2c9171d22013-12-10 21:55:10537 EXPECT_EQ(w2->GetNativeWindow(), controller->GetWindowForFullscreenMode());
538 w2->Minimize();
539 EXPECT_EQ(NULL, controller->GetWindowForFullscreenMode());
[email protected]2ee2f5d2013-01-10 23:37:16540}
541
[email protected]2c5db9e2014-02-27 13:58:14542TEST_F(RootWindowControllerTest, MultipleDisplaysGetWindowForFullscreenMode) {
543 if (!SupportsMultipleDisplays())
544 return;
545
546 UpdateDisplay("600x600,600x600");
547 Shell::RootWindowControllerList controllers =
548 Shell::GetInstance()->GetAllRootWindowControllers();
549
550 Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
551 w1->Maximize();
552 Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
553 w2->SetFullscreen(true);
554 Widget* w3 = CreateTestWidget(gfx::Rect(600, 0, 100, 100));
555
556 EXPECT_EQ(w1->GetNativeWindow()->GetRootWindow(),
[email protected]f5c9dbc2014-04-11 08:13:45557 controllers[0]->GetRootWindow());
[email protected]2c5db9e2014-02-27 13:58:14558 EXPECT_EQ(w2->GetNativeWindow()->GetRootWindow(),
[email protected]f5c9dbc2014-04-11 08:13:45559 controllers[0]->GetRootWindow());
[email protected]2c5db9e2014-02-27 13:58:14560 EXPECT_EQ(w3->GetNativeWindow()->GetRootWindow(),
[email protected]f5c9dbc2014-04-11 08:13:45561 controllers[1]->GetRootWindow());
[email protected]2c5db9e2014-02-27 13:58:14562
563 w1->Activate();
564 EXPECT_EQ(NULL, controllers[0]->GetWindowForFullscreenMode());
565 EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode());
566
567 w2->Activate();
568 EXPECT_EQ(w2->GetNativeWindow(),
569 controllers[0]->GetWindowForFullscreenMode());
570 EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode());
571
572 // Verify that the first root window controller remains in fullscreen mode
573 // when a window on the other display is activated.
574 w3->Activate();
575 EXPECT_EQ(w2->GetNativeWindow(),
576 controllers[0]->GetWindowForFullscreenMode());
577 EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode());
578}
579
[email protected]82ced2352013-07-19 20:49:06580// Test that user session window can't be focused if user session blocked by
581// some overlapping UI.
582TEST_F(RootWindowControllerTest, FocusBlockedWindow) {
583 UpdateDisplay("600x600");
[email protected]093b8d642014-04-03 20:59:28584 RootWindowController* controller =
[email protected]82ced2352013-07-19 20:49:06585 Shell::GetInstance()->GetPrimaryRootWindowController();
[email protected]f5c9dbc2014-04-11 08:13:45586 aura::Window* lock_container =
587 controller->GetContainer(kShellWindowId_LockScreenContainer);
[email protected]82ced2352013-07-19 20:49:06588 aura::Window* lock_window = Widget::CreateWindowWithParentAndBounds(NULL,
589 lock_container, gfx::Rect(0, 0, 100, 100))->GetNativeView();
590 lock_window->Show();
591 aura::Window* session_window =
592 CreateTestWidget(gfx::Rect(0, 0, 100, 100))->GetNativeView();
593 session_window->Show();
594
[email protected]a44afbbd2013-07-24 21:49:35595 for (int block_reason = FIRST_BLOCK_REASON;
596 block_reason < NUMBER_OF_BLOCK_REASONS;
597 ++block_reason) {
598 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
599 lock_window->Focus();
600 EXPECT_TRUE(lock_window->HasFocus());
601 session_window->Focus();
602 EXPECT_FALSE(session_window->HasFocus());
603 UnblockUserSession();
604 }
[email protected]82ced2352013-07-19 20:49:06605}
606
[email protected]0fbfa972013-10-02 19:23:33607// Tracks whether OnWindowDestroying() has been invoked.
608class DestroyedWindowObserver : public aura::WindowObserver {
609 public:
610 DestroyedWindowObserver() : destroyed_(false), window_(NULL) {}
dcheng1f4538e2014-10-27 23:57:05611 ~DestroyedWindowObserver() override { Shutdown(); }
[email protected]0fbfa972013-10-02 19:23:33612
613 void SetWindow(Window* window) {
614 window_ = window;
615 window->AddObserver(this);
616 }
617
618 bool destroyed() const { return destroyed_; }
619
620 // WindowObserver overrides:
dcheng1f4538e2014-10-27 23:57:05621 void OnWindowDestroying(Window* window) override {
[email protected]0fbfa972013-10-02 19:23:33622 destroyed_ = true;
623 Shutdown();
624 }
625
626 private:
627 void Shutdown() {
628 if (!window_)
629 return;
630 window_->RemoveObserver(this);
631 window_ = NULL;
632 }
633
634 bool destroyed_;
635 Window* window_;
636
637 DISALLOW_COPY_AND_ASSIGN(DestroyedWindowObserver);
638};
639
640// Verifies shutdown doesn't delete windows that are not owned by the parent.
641TEST_F(RootWindowControllerTest, DontDeleteWindowsNotOwnedByParent) {
642 DestroyedWindowObserver observer1;
643 aura::test::TestWindowDelegate delegate1;
644 aura::Window* window1 = new aura::Window(&delegate1);
[email protected]5b251f12013-12-19 01:50:05645 window1->SetType(ui::wm::WINDOW_TYPE_CONTROL);
[email protected]0fbfa972013-10-02 19:23:33646 window1->set_owned_by_parent(false);
647 observer1.SetWindow(window1);
danakjb161836d2015-04-03 05:14:18648 window1->Init(ui::LAYER_NOT_DRAWN);
[email protected]e3225e02013-10-23 20:44:37649 aura::client::ParentWindowWithContext(
650 window1, Shell::GetInstance()->GetPrimaryRootWindow(), gfx::Rect());
[email protected]0fbfa972013-10-02 19:23:33651
652 DestroyedWindowObserver observer2;
653 aura::Window* window2 = new aura::Window(NULL);
654 window2->set_owned_by_parent(false);
655 observer2.SetWindow(window2);
danakjb161836d2015-04-03 05:14:18656 window2->Init(ui::LAYER_NOT_DRAWN);
[email protected]0fbfa972013-10-02 19:23:33657 Shell::GetInstance()->GetPrimaryRootWindow()->AddChild(window2);
658
659 Shell::GetInstance()->GetPrimaryRootWindowController()->CloseChildWindows();
660
661 ASSERT_FALSE(observer1.destroyed());
662 delete window1;
663
664 ASSERT_FALSE(observer2.destroyed());
665 delete window2;
666}
667
[email protected]cf6fea22013-08-07 14:24:01668typedef test::NoSessionAshTestBase NoSessionRootWindowControllerTest;
669
670// Make sure that an event handler exists for entire display area.
671TEST_F(NoSessionRootWindowControllerTest, Event) {
[email protected]75a88c92014-05-14 01:57:32672 // Hide the shelf since it might otherwise get an event target.
673 RootWindowController* controller = Shell::GetPrimaryRootWindowController();
674 ShelfLayoutManager* shelf_layout_manager =
675 controller->GetShelfLayoutManager();
676 shelf_layout_manager->SetAutoHideBehavior(
677 ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
678
[email protected]bf9cdb362013-10-25 19:22:45679 aura::Window* root = Shell::GetPrimaryRootWindow();
[email protected]cf6fea22013-08-07 14:24:01680 const gfx::Size size = root->bounds().size();
681 aura::Window* event_target = root->GetEventHandlerForPoint(gfx::Point(0, 0));
682 EXPECT_TRUE(event_target);
683 EXPECT_EQ(event_target,
684 root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1)));
685 EXPECT_EQ(event_target,
686 root->GetEventHandlerForPoint(gfx::Point(size.width() - 1, 0)));
687 EXPECT_EQ(event_target,
688 root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1)));
689 EXPECT_EQ(event_target,
690 root->GetEventHandlerForPoint(
691 gfx::Point(size.width() - 1, size.height() - 1)));
692}
693
[email protected]24f5e242014-07-22 02:16:09694class VirtualKeyboardRootWindowControllerTest
695 : public RootWindowControllerTest {
[email protected]eff4c7f2013-08-13 01:45:50696 public:
dcheng1f4538e2014-10-27 23:57:05697 VirtualKeyboardRootWindowControllerTest() {}
698 ~VirtualKeyboardRootWindowControllerTest() override {}
[email protected]eff4c7f2013-08-13 01:45:50699
dcheng1f4538e2014-10-27 23:57:05700 void SetUp() override {
pgal.u-szegedd84534d32014-10-29 12:34:30701 base::CommandLine::ForCurrentProcess()->AppendSwitch(
[email protected]eff4c7f2013-08-13 01:45:50702 keyboard::switches::kEnableVirtualKeyboard);
703 test::AshTestBase::SetUp();
[email protected]24ca45d2013-10-25 03:37:44704 Shell::GetPrimaryRootWindowController()->ActivateKeyboard(
[email protected]a0b3fb882014-04-07 19:26:03705 keyboard::KeyboardController::GetInstance());
[email protected]eff4c7f2013-08-13 01:45:50706 }
707
708 private:
709 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest);
710};
711
[email protected]2082d7d2014-05-13 14:44:23712class MockTextInputClient : public ui::DummyTextInputClient {
713 public:
714 MockTextInputClient() :
715 ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT) {}
716
dcheng1f4538e2014-10-27 23:57:05717 void EnsureCaretInRect(const gfx::Rect& rect) override {
[email protected]2082d7d2014-05-13 14:44:23718 visible_rect_ = rect;
719 }
720
721 const gfx::Rect& visible_rect() const {
722 return visible_rect_;
723 }
724
725 private:
726 gfx::Rect visible_rect_;
727
728 DISALLOW_COPY_AND_ASSIGN(MockTextInputClient);
729};
730
kevers23f3987d2014-09-17 13:50:12731class TargetHitTestEventHandler : public ui::test::TestEventHandler {
732 public:
733 TargetHitTestEventHandler() {}
734
735 // ui::test::TestEventHandler overrides.
dcheng1f4538e2014-10-27 23:57:05736 void OnMouseEvent(ui::MouseEvent* event) override {
kevers23f3987d2014-09-17 13:50:12737 if (event->type() == ui::ET_MOUSE_PRESSED)
738 ui::test::TestEventHandler::OnMouseEvent(event);
739 event->StopPropagation();
740 }
741
742 private:
743 DISALLOW_COPY_AND_ASSIGN(TargetHitTestEventHandler);
744};
745
[email protected]b6ba05d902013-10-04 21:38:45746// Test for http://crbug.com/297858. Virtual keyboard container should only show
747// on primary root window.
748TEST_F(VirtualKeyboardRootWindowControllerTest,
749 VirtualKeyboardOnPrimaryRootWindowOnly) {
750 if (!SupportsMultipleDisplays())
751 return;
752
753 UpdateDisplay("500x500,500x500");
754
[email protected]c9390bd2013-11-08 20:33:13755 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]bf9cdb362013-10-25 19:22:45756 aura::Window* primary_root_window = Shell::GetPrimaryRootWindow();
757 aura::Window* secondary_root_window =
[email protected]b6ba05d902013-10-04 21:38:45758 root_windows[0] == primary_root_window ?
759 root_windows[1] : root_windows[0];
760
[email protected]093b8d642014-04-03 20:59:28761 ASSERT_TRUE(Shell::GetContainer(primary_root_window,
762 kShellWindowId_VirtualKeyboardContainer));
763 ASSERT_FALSE(Shell::GetContainer(secondary_root_window,
764 kShellWindowId_VirtualKeyboardContainer));
[email protected]b6ba05d902013-10-04 21:38:45765}
766
[email protected]eff4c7f2013-08-13 01:45:50767// Test for http://crbug.com/263599. Virtual keyboard should be able to receive
768// events at blocked user session.
769TEST_F(VirtualKeyboardRootWindowControllerTest,
770 ClickVirtualKeyboardInBlockedWindow) {
[email protected]bf9cdb362013-10-25 19:22:45771 aura::Window* root_window = Shell::GetPrimaryRootWindow();
[email protected]093b8d642014-04-03 20:59:28772 aura::Window* keyboard_container =
773 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
[email protected]eff4c7f2013-08-13 01:45:50774 ASSERT_TRUE(keyboard_container);
775 keyboard_container->Show();
776
[email protected]a0b3fb882014-04-07 19:26:03777 aura::Window* keyboard_window = keyboard::KeyboardController::GetInstance()->
[email protected]647b4842013-12-12 14:24:24778 proxy()->GetKeyboardWindow();
779 keyboard_container->AddChild(keyboard_window);
[email protected]183e28d2014-01-20 18:18:02780 keyboard_window->set_owned_by_parent(false);
[email protected]647b4842013-12-12 14:24:24781 keyboard_window->SetBounds(gfx::Rect());
[email protected]eff4c7f2013-08-13 01:45:50782 keyboard_window->Show();
[email protected]647b4842013-12-12 14:24:24783
[email protected]3193ea722014-04-23 22:19:19784 ui::test::TestEventHandler handler;
785 root_window->AddPreTargetHandler(&handler);
[email protected]647b4842013-12-12 14:24:24786
[email protected]73c9fd02014-07-28 01:48:52787 ui::test::EventGenerator event_generator(root_window, keyboard_window);
[email protected]eff4c7f2013-08-13 01:45:50788 event_generator.ClickLeftButton();
789 int expected_mouse_presses = 1;
[email protected]3193ea722014-04-23 22:19:19790 EXPECT_EQ(expected_mouse_presses, handler.num_mouse_events() / 2);
[email protected]eff4c7f2013-08-13 01:45:50791
792 for (int block_reason = FIRST_BLOCK_REASON;
793 block_reason < NUMBER_OF_BLOCK_REASONS;
794 ++block_reason) {
795 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
796 event_generator.ClickLeftButton();
797 expected_mouse_presses++;
[email protected]3193ea722014-04-23 22:19:19798 EXPECT_EQ(expected_mouse_presses, handler.num_mouse_events() / 2);
[email protected]eff4c7f2013-08-13 01:45:50799 UnblockUserSession();
800 }
[email protected]3193ea722014-04-23 22:19:19801 root_window->RemovePreTargetHandler(&handler);
[email protected]eff4c7f2013-08-13 01:45:50802}
803
[email protected]45c66672013-10-01 22:48:56804// Test for http://crbug.com/299787. RootWindowController should delete
805// the old container since the keyboard controller creates a new window in
806// GetWindowContainer().
807TEST_F(VirtualKeyboardRootWindowControllerTest,
808 DeleteOldContainerOnVirtualKeyboardInit) {
[email protected]1025937e2014-02-13 01:25:50809 aura::Window* root_window = Shell::GetPrimaryRootWindow();
[email protected]093b8d642014-04-03 20:59:28810 aura::Window* keyboard_container =
811 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
[email protected]45c66672013-10-01 22:48:56812 ASSERT_TRUE(keyboard_container);
813 // Track the keyboard container window.
814 aura::WindowTracker tracker;
815 tracker.Add(keyboard_container);
[email protected]51f438112013-11-18 19:32:50816 // Mock a login user profile change to reinitialize the keyboard.
817 ash::Shell::GetInstance()->OnLoginUserProfilePrepared();
[email protected]45c66672013-10-01 22:48:56818 // keyboard_container should no longer be present.
819 EXPECT_FALSE(tracker.Contains(keyboard_container));
820}
821
[email protected]1025937e2014-02-13 01:25:50822// Test for crbug.com/342524. After user login, the work space should restore to
823// full screen.
824TEST_F(VirtualKeyboardRootWindowControllerTest, RestoreWorkspaceAfterLogin) {
825 aura::Window* root_window = Shell::GetPrimaryRootWindow();
[email protected]093b8d642014-04-03 20:59:28826 aura::Window* keyboard_container =
827 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
[email protected]1025937e2014-02-13 01:25:50828 keyboard_container->Show();
829 keyboard::KeyboardController* controller =
[email protected]a0b3fb882014-04-07 19:26:03830 keyboard::KeyboardController::GetInstance();
[email protected]1025937e2014-02-13 01:25:50831 aura::Window* keyboard_window = controller->proxy()->GetKeyboardWindow();
832 keyboard_container->AddChild(keyboard_window);
833 keyboard_window->set_owned_by_parent(false);
bshea0a57802015-04-08 18:21:29834 keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds(
835 root_window->bounds(), 100));
[email protected]1025937e2014-02-13 01:25:50836 keyboard_window->Show();
837
838 gfx::Rect before = ash::Shell::GetScreen()->GetPrimaryDisplay().work_area();
839
840 // Notify keyboard bounds changing.
bshea0a57802015-04-08 18:21:29841 controller->NotifyKeyboardBoundsChanging(keyboard_container->bounds());
[email protected]1025937e2014-02-13 01:25:50842
[email protected]25df7ad2014-04-30 18:10:25843 if (!keyboard::IsKeyboardOverscrollEnabled()) {
844 gfx::Rect after = ash::Shell::GetScreen()->GetPrimaryDisplay().work_area();
845 EXPECT_LT(after, before);
846 }
[email protected]1025937e2014-02-13 01:25:50847
848 // Mock a login user profile change to reinitialize the keyboard.
849 ash::Shell::GetInstance()->OnLoginUserProfilePrepared();
850 EXPECT_EQ(ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(), before);
851}
852
[email protected]602022b2014-03-31 17:07:31853// Ensure that system modal dialogs do not block events targeted at the virtual
854// keyboard.
855TEST_F(VirtualKeyboardRootWindowControllerTest, ClickWithActiveModalDialog) {
856 aura::Window* root_window = Shell::GetPrimaryRootWindow();
[email protected]093b8d642014-04-03 20:59:28857 aura::Window* keyboard_container =
858 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
[email protected]602022b2014-03-31 17:07:31859 ASSERT_TRUE(keyboard_container);
860 keyboard_container->Show();
861
[email protected]a0b3fb882014-04-07 19:26:03862 aura::Window* keyboard_window = keyboard::KeyboardController::GetInstance()->
[email protected]602022b2014-03-31 17:07:31863 proxy()->GetKeyboardWindow();
864 keyboard_container->AddChild(keyboard_window);
865 keyboard_window->set_owned_by_parent(false);
bshea0a57802015-04-08 18:21:29866 keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds(
867 root_window->bounds(), 100));
[email protected]3193ea722014-04-23 22:19:19868
869 ui::test::TestEventHandler handler;
870 root_window->AddPreTargetHandler(&handler);
[email protected]73c9fd02014-07-28 01:48:52871 ui::test::EventGenerator root_window_event_generator(root_window);
872 ui::test::EventGenerator keyboard_event_generator(root_window,
873 keyboard_window);
[email protected]602022b2014-03-31 17:07:31874
875 views::Widget* modal_widget =
876 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
877
878 // Verify that mouse events to the root window are block with a visble modal
879 // dialog.
880 root_window_event_generator.ClickLeftButton();
[email protected]3193ea722014-04-23 22:19:19881 EXPECT_EQ(0, handler.num_mouse_events());
[email protected]602022b2014-03-31 17:07:31882
883 // Verify that event dispatch to the virtual keyboard is unblocked.
884 keyboard_event_generator.ClickLeftButton();
[email protected]3193ea722014-04-23 22:19:19885 EXPECT_EQ(1, handler.num_mouse_events() / 2);
[email protected]602022b2014-03-31 17:07:31886
887 modal_widget->Close();
888
889 // Verify that mouse events are now unblocked to the root window.
890 root_window_event_generator.ClickLeftButton();
[email protected]3193ea722014-04-23 22:19:19891 EXPECT_EQ(2, handler.num_mouse_events() / 2);
892 root_window->RemovePreTargetHandler(&handler);
[email protected]602022b2014-03-31 17:07:31893}
894
[email protected]2082d7d2014-05-13 14:44:23895// Ensure that the visible area for scrolling the text caret excludes the
896// region occluded by the on-screen keyboard.
897TEST_F(VirtualKeyboardRootWindowControllerTest, EnsureCaretInWorkArea) {
898 keyboard::KeyboardController* keyboard_controller =
899 keyboard::KeyboardController::GetInstance();
900 keyboard::KeyboardControllerProxy* proxy = keyboard_controller->proxy();
901
902 MockTextInputClient text_input_client;
903 ui::InputMethod* input_method = proxy->GetInputMethod();
904 ASSERT_TRUE(input_method);
[email protected]00a386792014-06-16 15:09:20905 if (switches::IsTextInputFocusManagerEnabled()) {
906 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(
907 &text_input_client);
908 } else {
909 input_method->SetFocusedTextInputClient(&text_input_client);
910 }
[email protected]2082d7d2014-05-13 14:44:23911
912 aura::Window* root_window = Shell::GetPrimaryRootWindow();
913 aura::Window* keyboard_container =
914 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
915 ASSERT_TRUE(keyboard_container);
916 keyboard_container->Show();
917
918 const int keyboard_height = 100;
919 aura::Window* keyboard_window =proxy->GetKeyboardWindow();
920 keyboard_container->AddChild(keyboard_window);
921 keyboard_window->set_owned_by_parent(false);
bshea0a57802015-04-08 18:21:29922 keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds(
923 root_window->bounds(), keyboard_height));
[email protected]2082d7d2014-05-13 14:44:23924
925 proxy->EnsureCaretInWorkArea();
bshea0a57802015-04-08 18:21:29926 ASSERT_EQ(root_window->bounds().width(),
[email protected]2082d7d2014-05-13 14:44:23927 text_input_client.visible_rect().width());
bshea0a57802015-04-08 18:21:29928 ASSERT_EQ(root_window->bounds().height() - keyboard_height,
[email protected]2082d7d2014-05-13 14:44:23929 text_input_client.visible_rect().height());
[email protected]00a386792014-06-16 15:09:20930
931 if (switches::IsTextInputFocusManagerEnabled()) {
932 ui::TextInputFocusManager::GetInstance()->BlurTextInputClient(
933 &text_input_client);
934 } else {
935 input_method->SetFocusedTextInputClient(NULL);
936 }
[email protected]2082d7d2014-05-13 14:44:23937}
938
kevers23f3987d2014-09-17 13:50:12939// Tests that the virtual keyboard does not block context menus. The virtual
940// keyboard should appear in front of most content, but not context menus. See
941// crbug/377180.
942TEST_F(VirtualKeyboardRootWindowControllerTest, ZOrderTest) {
943 UpdateDisplay("800x600");
944 keyboard::KeyboardController* keyboard_controller =
945 keyboard::KeyboardController::GetInstance();
946 keyboard::KeyboardControllerProxy* proxy = keyboard_controller->proxy();
947
948 aura::Window* root_window = Shell::GetPrimaryRootWindow();
949 aura::Window* keyboard_container =
950 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
951 ASSERT_TRUE(keyboard_container);
952 keyboard_container->Show();
953
954 const int keyboard_height = 200;
955 aura::Window* keyboard_window = proxy->GetKeyboardWindow();
956 keyboard_container->AddChild(keyboard_window);
957 keyboard_window->set_owned_by_parent(false);
bshea0a57802015-04-08 18:21:29958 gfx::Rect keyboard_bounds = keyboard::FullWidthKeyboardBoundsFromRootBounds(
959 root_window->bounds(), keyboard_height);
kevers23f3987d2014-09-17 13:50:12960 keyboard_window->SetBounds(keyboard_bounds);
961 keyboard_window->Show();
962
963 ui::test::EventGenerator generator(root_window);
964
965 // Cover the screen with two windows: a normal window on the left side and a
966 // context menu on the right side. When the virtual keyboard is displayed it
967 // partially occludes the normal window, but not the context menu. Compute
968 // positions for generating synthetic click events to perform hit tests,
969 // ensuring the correct window layering. 'top' is above the VK, whereas
970 // 'bottom' lies within the VK. 'left' is centered in the normal window, and
971 // 'right' is centered in the context menu.
972 int window_height = keyboard_bounds.bottom();
973 int window_width = keyboard_bounds.width() / 2;
974 int left = window_width / 2;
975 int right = 3 * window_width / 2;
976 int top = keyboard_bounds.y() / 2;
977 int bottom = window_height - keyboard_height / 2;
978
979 // Normal window is partially occluded by the virtual keyboard.
980 aura::test::TestWindowDelegate delegate;
981 scoped_ptr<aura::Window> normal(CreateTestWindowInShellWithDelegateAndType(
982 &delegate,
983 ui::wm::WINDOW_TYPE_NORMAL,
984 0,
985 gfx::Rect(0, 0, window_width, window_height)));
986 normal->set_owned_by_parent(false);
987 normal->Show();
988 TargetHitTestEventHandler normal_handler;
989 normal->AddPreTargetHandler(&normal_handler);
990
991 // Test that only the click on the top portion of the window is picked up. The
992 // click on the bottom hits the virtual keyboard instead.
993 generator.MoveMouseTo(left, top);
994 generator.ClickLeftButton();
995 EXPECT_EQ(1, normal_handler.num_mouse_events());
996 generator.MoveMouseTo(left, bottom);
997 generator.ClickLeftButton();
998 EXPECT_EQ(1, normal_handler.num_mouse_events());
999
1000 // Menu overlaps virtual keyboard.
1001 aura::test::TestWindowDelegate delegate2;
1002 scoped_ptr<aura::Window> menu(CreateTestWindowInShellWithDelegateAndType(
1003 &delegate2,
1004 ui::wm::WINDOW_TYPE_MENU,
1005 0,
1006 gfx::Rect(window_width, 0, window_width, window_height)));
1007 menu->set_owned_by_parent(false);
1008 menu->Show();
1009 TargetHitTestEventHandler menu_handler;
1010 menu->AddPreTargetHandler(&menu_handler);
1011
1012 // Test that both clicks register.
1013 generator.MoveMouseTo(right, top);
1014 generator.ClickLeftButton();
1015 EXPECT_EQ(1, menu_handler.num_mouse_events());
1016 generator.MoveMouseTo(right, bottom);
1017 generator.ClickLeftButton();
1018 EXPECT_EQ(2, menu_handler.num_mouse_events());
1019
1020 // Cleanup to ensure that the test windows are destroyed before their
1021 // delegates.
1022 normal.reset();
1023 menu.reset();
1024}
1025
kevers0e450492014-09-30 16:02:311026// Resolution in UpdateDisplay is not being respected on Windows 8.
1027#if defined(OS_WIN)
1028#define MAYBE_DisplayRotation DISABLED_DisplayRotation
1029#else
1030#define MAYBE_DisplayRotation DisplayRotation
1031#endif
1032
1033// Tests that the virtual keyboard correctly resizes with a change to display
1034// orientation. See crbug/417612.
1035TEST_F(VirtualKeyboardRootWindowControllerTest, MAYBE_DisplayRotation) {
1036 UpdateDisplay("800x600");
1037 aura::Window* root_window = Shell::GetPrimaryRootWindow();
1038 aura::Window* keyboard_container =
1039 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
1040 ASSERT_TRUE(keyboard_container);
bshea0a57802015-04-08 18:21:291041 keyboard::KeyboardController* keyboard_controller =
1042 keyboard::KeyboardController::GetInstance();
1043 keyboard_controller->ShowKeyboard(false);
1044 keyboard_controller->proxy()->GetKeyboardWindow()->SetBounds(
1045 gfx::Rect(0, 400, 800, 200));
1046 EXPECT_EQ("0,400 800x200", keyboard_container->bounds().ToString());
kevers0e450492014-09-30 16:02:311047
1048 UpdateDisplay("600x800");
bshea0a57802015-04-08 18:21:291049 EXPECT_EQ("0,600 600x200", keyboard_container->bounds().ToString());
kevers0e450492014-09-30 16:02:311050}
1051
[email protected]f1853122012-06-27 16:21:261052} // namespace test
1053} // namespace ash