blob: 49ba6fe1b3333fff8670779940b0f939fa99de53 [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
dchenga94547472016-04-08 08:41:117#include <memory>
8
oshima38dffad2015-05-05 17:22:569#include "ash/display/display_manager.h"
[email protected]fdf74bf2014-04-30 21:24:0210#include "ash/session/session_state_delegate.h"
[email protected]478c6c32013-03-09 02:50:5811#include "ash/shelf/shelf_layout_manager.h"
[email protected]f1853122012-06-27 16:21:2612#include "ash/shell.h"
13#include "ash/shell_window_ids.h"
[email protected]8674b312012-10-12 19:02:4414#include "ash/system/tray/system_tray_delegate.h"
[email protected]f1853122012-06-27 16:21:2615#include "ash/test/ash_test_base.h"
oshimabba2d992015-05-22 19:21:3916#include "ash/test/display_manager_test_api.h"
sky75677b502016-04-26 22:41:5917#include "ash/wm/common/window_state.h"
[email protected]8674b312012-10-12 19:02:4418#include "ash/wm/system_modal_container_layout_manager.h"
[email protected]2ee2f5d2013-01-10 23:37:1619#include "ash/wm/window_properties.h"
sky8d5646fe2016-04-15 17:03:4620#include "ash/wm/window_state_aura.h"
[email protected]f1853122012-06-27 16:21:2621#include "ash/wm/window_util.h"
[email protected]eff4c7f2013-08-13 01:45:5022#include "base/command_line.h"
[email protected]792b9b12012-12-11 03:53:2723#include "ui/aura/client/focus_change_observer.h"
[email protected]8cfb6722012-11-28 03:28:4624#include "ui/aura/client/focus_client.h"
[email protected]e3225e02013-10-23 20:44:3725#include "ui/aura/client/window_tree_client.h"
[email protected]f1853122012-06-27 16:21:2626#include "ui/aura/env.h"
[email protected]dbf835d82012-09-11 18:23:0927#include "ui/aura/test/test_window_delegate.h"
28#include "ui/aura/test/test_windows.h"
[email protected]f1853122012-06-27 16:21:2629#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2630#include "ui/aura/window_event_dispatcher.h"
[email protected]dbf835d82012-09-11 18:23:0931#include "ui/aura/window_tracker.h"
[email protected]2082d7d2014-05-13 14:44:2332#include "ui/base/ime/dummy_text_input_client.h"
33#include "ui/base/ime/input_method.h"
34#include "ui/base/ime/text_input_client.h"
[email protected]73c9fd02014-07-28 01:48:5235#include "ui/events/test/event_generator.h"
[email protected]cd9f71d2014-03-20 21:54:2136#include "ui/events/test/test_event_handler.h"
[email protected]eff4c7f2013-08-13 01:45:5037#include "ui/keyboard/keyboard_switches.h"
ben974286a2015-10-10 00:45:1238#include "ui/keyboard/keyboard_ui.h"
[email protected]39e95212014-04-23 20:00:0139#include "ui/keyboard/keyboard_util.h"
[email protected]f1853122012-06-27 16:21:2640#include "ui/views/controls/menu/menu_controller.h"
41#include "ui/views/widget/widget.h"
42#include "ui/views/widget/widget_delegate.h"
43
[email protected]2ee2f5d2013-01-10 23:37:1644using aura::Window;
45using views::Widget;
46
[email protected]f1853122012-06-27 16:21:2647namespace ash {
48namespace {
49
50class TestDelegate : public views::WidgetDelegateView {
51 public:
52 explicit TestDelegate(bool system_modal) : system_modal_(system_modal) {}
dcheng1f4538e2014-10-27 23:57:0553 ~TestDelegate() override {}
[email protected]f1853122012-06-27 16:21:2654
55 // Overridden from views::WidgetDelegate:
dcheng1f4538e2014-10-27 23:57:0556 views::View* GetContentsView() override { return this; }
[email protected]f1853122012-06-27 16:21:2657
dcheng1f4538e2014-10-27 23:57:0558 ui::ModalType GetModalType() const override {
[email protected]f1853122012-06-27 16:21:2659 return system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE;
60 }
61
62 private:
63 bool system_modal_;
[email protected]0fbfa972013-10-02 19:23:3364
[email protected]f1853122012-06-27 16:21:2665 DISALLOW_COPY_AND_ASSIGN(TestDelegate);
66};
67
[email protected]792b9b12012-12-11 03:53:2768class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate,
69 public aura::client::FocusChangeObserver {
[email protected]dbf835d82012-09-11 18:23:0970 public:
71 DeleteOnBlurDelegate() : window_(NULL) {}
dcheng1f4538e2014-10-27 23:57:0572 ~DeleteOnBlurDelegate() override {}
[email protected]dbf835d82012-09-11 18:23:0973
[email protected]792b9b12012-12-11 03:53:2774 void SetWindow(aura::Window* window) {
75 window_ = window;
76 aura::client::SetFocusChangeObserver(window_, this);
77 }
[email protected]dbf835d82012-09-11 18:23:0978
[email protected]869f6352012-12-06 20:47:1779 private:
[email protected]dbf835d82012-09-11 18:23:0980 // aura::test::TestWindowDelegate overrides:
dcheng1f4538e2014-10-27 23:57:0581 bool CanFocus() override { return true; }
[email protected]dbf835d82012-09-11 18:23:0982
[email protected]792b9b12012-12-11 03:53:2783 // aura::client::FocusChangeObserver implementation:
dcheng1f4538e2014-10-27 23:57:0584 void OnWindowFocused(aura::Window* gained_focus,
85 aura::Window* lost_focus) override {
[email protected]792b9b12012-12-11 03:53:2786 if (window_ == lost_focus)
87 delete window_;
[email protected]869f6352012-12-06 20:47:1788 }
89
[email protected]dbf835d82012-09-11 18:23:0990 aura::Window* window_;
91
92 DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate);
93};
94
[email protected]f1853122012-06-27 16:21:2695} // namespace
96
97namespace test {
[email protected]f1853122012-06-27 16:21:2698
[email protected]a2e6af12013-01-07 21:40:3599class RootWindowControllerTest : public test::AshTestBase {
100 public:
101 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
102 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
103 NULL, CurrentContext(), bounds);
104 widget->Show();
105 return widget;
106 }
107
108 views::Widget* CreateModalWidget(const gfx::Rect& bounds) {
109 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
110 new TestDelegate(true), CurrentContext(), bounds);
111 widget->Show();
112 return widget;
113 }
114
115 views::Widget* CreateModalWidgetWithParent(const gfx::Rect& bounds,
116 gfx::NativeWindow parent) {
117 views::Widget* widget =
118 views::Widget::CreateWindowWithParentAndBounds(new TestDelegate(true),
119 parent,
120 bounds);
121 widget->Show();
122 return widget;
123 }
124
[email protected]c9390bd2013-11-08 20:33:13125 aura::Window* GetModalContainer(aura::Window* root_window) {
[email protected]093b8d642014-04-03 20:59:28126 return Shell::GetContainer(root_window,
127 ash::kShellWindowId_SystemModalContainer);
[email protected]a2e6af12013-01-07 21:40:35128 }
129};
[email protected]f1853122012-06-27 16:21:26130
[email protected]e75642a2013-06-12 17:21:18131TEST_F(RootWindowControllerTest, MoveWindows_Basic) {
132 if (!SupportsMultipleDisplays())
133 return;
[email protected]2816c2462013-12-17 02:22:25134 // Windows origin should be doubled when moved to the 1st display.
135 UpdateDisplay("600x600,300x300");
[email protected]c9390bd2013-11-08 20:33:13136 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]093b8d642014-04-03 20:59:28137 RootWindowController* controller = Shell::GetPrimaryRootWindowController();
138 ShelfLayoutManager* shelf_layout_manager =
[email protected]478c6c32013-03-09 02:50:58139 controller->GetShelfLayoutManager();
140 shelf_layout_manager->SetAutoHideBehavior(
141 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
[email protected]f1853122012-06-27 16:21:26142
143 views::Widget* normal = CreateTestWidget(gfx::Rect(650, 10, 100, 100));
144 EXPECT_EQ(root_windows[1], normal->GetNativeView()->GetRootWindow());
[email protected]e2f64d102012-07-19 19:17:04145 EXPECT_EQ("650,10 100x100", normal->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06146 EXPECT_EQ("50,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04147 normal->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26148
149 views::Widget* maximized = CreateTestWidget(gfx::Rect(700, 10, 100, 100));
150 maximized->Maximize();
151 EXPECT_EQ(root_windows[1], maximized->GetNativeView()->GetRootWindow());
[email protected]2816c2462013-12-17 02:22:25152 EXPECT_EQ("600,0 300x253", maximized->GetWindowBoundsInScreen().ToString());
153 EXPECT_EQ("0,0 300x253",
[email protected]8c0ec432013-05-10 04:33:39154 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26155
156 views::Widget* minimized = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
157 minimized->Minimize();
158 EXPECT_EQ(root_windows[1], minimized->GetNativeView()->GetRootWindow());
[email protected]8d625fb2012-07-18 16:40:06159 EXPECT_EQ("800,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04160 minimized->GetWindowBoundsInScreen().ToString());
[email protected]f1853122012-06-27 16:21:26161
[email protected]2816c2462013-12-17 02:22:25162 views::Widget* fullscreen = CreateTestWidget(gfx::Rect(850, 10, 100, 100));
[email protected]f1853122012-06-27 16:21:26163 fullscreen->SetFullscreen(true);
164 EXPECT_EQ(root_windows[1], fullscreen->GetNativeView()->GetRootWindow());
[email protected]1a015382012-12-01 19:44:59165
[email protected]2816c2462013-12-17 02:22:25166 EXPECT_EQ("600,0 300x300",
[email protected]e2f64d102012-07-19 19:17:04167 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]2816c2462013-12-17 02:22:25168 EXPECT_EQ("0,0 300x300",
[email protected]e2f64d102012-07-19 19:17:04169 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26170
[email protected]8f2f151412013-01-26 03:58:37171 views::Widget* unparented_control = new Widget;
172 Widget::InitParams params;
173 params.bounds = gfx::Rect(650, 10, 100, 100);
174 params.context = CurrentContext();
175 params.type = Widget::InitParams::TYPE_CONTROL;
176 unparented_control->Init(params);
177 EXPECT_EQ(root_windows[1],
178 unparented_control->GetNativeView()->GetRootWindow());
[email protected]093b8d642014-04-03 20:59:28179 EXPECT_EQ(kShellWindowId_UnparentedControlContainer,
[email protected]8f2f151412013-01-26 03:58:37180 unparented_control->GetNativeView()->parent()->id());
181
[email protected]95db9c12013-01-31 11:47:44182 aura::Window* panel = CreateTestWindowInShellWithDelegateAndType(
[email protected]5b251f12013-12-19 01:50:05183 NULL, ui::wm::WINDOW_TYPE_PANEL, 0, gfx::Rect(700, 100, 100, 100));
[email protected]95db9c12013-01-31 11:47:44184 EXPECT_EQ(root_windows[1], panel->GetRootWindow());
[email protected]093b8d642014-04-03 20:59:28185 EXPECT_EQ(kShellWindowId_PanelContainer, panel->parent()->id());
[email protected]95db9c12013-01-31 11:47:44186
[email protected]dbf835d82012-09-11 18:23:09187 // Make sure a window that will delete itself when losing focus
188 // will not crash.
189 aura::WindowTracker tracker;
190 DeleteOnBlurDelegate delete_on_blur_delegate;
[email protected]5ebe6102012-11-28 21:00:03191 aura::Window* d2 = CreateTestWindowInShellWithDelegate(
192 &delete_on_blur_delegate, 0, gfx::Rect(50, 50, 100, 100));
[email protected]792b9b12012-12-11 03:53:27193 delete_on_blur_delegate.SetWindow(d2);
[email protected]550543e2013-01-11 22:43:44194 aura::client::GetFocusClient(root_windows[0])->FocusWindow(d2);
[email protected]dbf835d82012-09-11 18:23:09195 tracker.Add(d2);
196
[email protected]f634dd32012-07-23 22:49:07197 UpdateDisplay("600x600");
[email protected]f1853122012-06-27 16:21:26198
[email protected]dbf835d82012-09-11 18:23:09199 // d2 must have been deleted.
200 EXPECT_FALSE(tracker.Contains(d2));
201
[email protected]f1853122012-06-27 16:21:26202 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
[email protected]2816c2462013-12-17 02:22:25203 EXPECT_EQ("100,20 100x100", normal->GetWindowBoundsInScreen().ToString());
204 EXPECT_EQ("100,20 100x100",
[email protected]e2f64d102012-07-19 19:17:04205 normal->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26206
[email protected]eefd51b22012-09-25 20:26:24207 // Maximized area on primary display has 3px (given as
[email protected]f1853122012-06-27 16:21:26208 // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom.
[email protected]2a64b0a2013-07-23 23:15:54209
210 // First clear fullscreen status, since both fullscreen and maximized windows
211 // share the same desktop workspace, which cancels the shelf status.
212 fullscreen->SetFullscreen(false);
[email protected]f1853122012-06-27 16:21:26213 EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow());
[email protected]7b675df612012-09-16 18:33:20214 EXPECT_EQ("0,0 600x597",
[email protected]e2f64d102012-07-19 19:17:04215 maximized->GetWindowBoundsInScreen().ToString());
[email protected]7b675df612012-09-16 18:33:20216 EXPECT_EQ("0,0 600x597",
[email protected]e2f64d102012-07-19 19:17:04217 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26218
oshima5594d1232015-12-04 18:58:38219 // Set fullscreen to true, but maximized window's size won't change because
220 // it's not visible. see crbug.com/504299.
[email protected]2a64b0a2013-07-23 23:15:54221 fullscreen->SetFullscreen(true);
222 EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow());
oshima5594d1232015-12-04 18:58:38223 EXPECT_EQ("0,0 600x597", maximized->GetWindowBoundsInScreen().ToString());
224 EXPECT_EQ("0,0 600x597",
[email protected]2a64b0a2013-07-23 23:15:54225 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;
oshima628a6172015-08-01 01:33:14297 Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled(true);
oshimabba2d992015-05-22 19:21:39298
oshima022a9542015-05-01 00:15:02299 UpdateDisplay("500x500");
300 const int kLockScreenWindowId = 1000;
301 const int kLockBackgroundWindowId = 1001;
302
303 RootWindowController* controller =
304 Shell::GetInstance()->GetPrimaryRootWindowController();
305
306 aura::Window* lock_container =
307 controller->GetContainer(kShellWindowId_LockScreenContainer);
308 aura::Window* lock_background_container =
309 controller->GetContainer(kShellWindowId_LockScreenBackgroundContainer);
310
311 views::Widget* lock_screen =
312 CreateModalWidgetWithParent(gfx::Rect(10, 10, 100, 100), lock_container);
313 lock_screen->GetNativeWindow()->set_id(kLockScreenWindowId);
314 lock_screen->SetFullscreen(true);
315
316 views::Widget* lock_background = CreateModalWidgetWithParent(
317 gfx::Rect(10, 10, 100, 100), lock_background_container);
318 lock_background->GetNativeWindow()->set_id(kLockBackgroundWindowId);
319
320 ASSERT_EQ(lock_screen->GetNativeWindow(),
321 controller->GetRootWindow()->GetChildById(kLockScreenWindowId));
322 ASSERT_EQ(lock_background->GetNativeWindow(),
323 controller->GetRootWindow()->GetChildById(kLockBackgroundWindowId));
324 EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString());
325
326 // Switch to unified.
327 UpdateDisplay("500x500,500x500");
328
329 // In unified mode, RWC is created
330 controller = Shell::GetInstance()->GetPrimaryRootWindowController();
331
332 ASSERT_EQ(lock_screen->GetNativeWindow(),
333 controller->GetRootWindow()->GetChildById(kLockScreenWindowId));
334 ASSERT_EQ(lock_background->GetNativeWindow(),
335 controller->GetRootWindow()->GetChildById(kLockBackgroundWindowId));
oshima96f6a502015-05-02 08:43:32336 EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString());
oshima022a9542015-05-01 00:15:02337
338 // Switch to mirror.
oshima43436d32015-06-19 02:35:25339 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
oshima022a9542015-05-01 00:15:02340 display_manager->SetMirrorMode(true);
341 EXPECT_TRUE(display_manager->IsInMirrorMode());
342
343 controller = Shell::GetInstance()->GetPrimaryRootWindowController();
344 ASSERT_EQ(lock_screen->GetNativeWindow(),
345 controller->GetRootWindow()->GetChildById(kLockScreenWindowId));
346 ASSERT_EQ(lock_background->GetNativeWindow(),
347 controller->GetRootWindow()->GetChildById(kLockBackgroundWindowId));
348 EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString());
349
350 // Switch to unified.
351 display_manager->SetMirrorMode(false);
352 EXPECT_TRUE(display_manager->IsInUnifiedMode());
353
354 controller = Shell::GetInstance()->GetPrimaryRootWindowController();
355
356 ASSERT_EQ(lock_screen->GetNativeWindow(),
357 controller->GetRootWindow()->GetChildById(kLockScreenWindowId));
358 ASSERT_EQ(lock_background->GetNativeWindow(),
359 controller->GetRootWindow()->GetChildById(kLockBackgroundWindowId));
oshima96f6a502015-05-02 08:43:32360 EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString());
oshima022a9542015-05-01 00:15:02361
362 // Switch to single display.
363 UpdateDisplay("600x500");
364 EXPECT_FALSE(display_manager->IsInUnifiedMode());
365 EXPECT_FALSE(display_manager->IsInMirrorMode());
366
367 controller = Shell::GetInstance()->GetPrimaryRootWindowController();
368
369 ASSERT_EQ(lock_screen->GetNativeWindow(),
370 controller->GetRootWindow()->GetChildById(kLockScreenWindowId));
371 ASSERT_EQ(lock_background->GetNativeWindow(),
372 controller->GetRootWindow()->GetChildById(kLockBackgroundWindowId));
373 EXPECT_EQ("0,0 600x500", lock_screen->GetNativeWindow()->bounds().ToString());
374}
375
[email protected]8674b312012-10-12 19:02:44376TEST_F(RootWindowControllerTest, ModalContainer) {
377 UpdateDisplay("600x600");
378 Shell* shell = Shell::GetInstance();
[email protected]093b8d642014-04-03 20:59:28379 RootWindowController* controller = shell->GetPrimaryRootWindowController();
[email protected]8674b312012-10-12 19:02:44380 EXPECT_EQ(user::LOGGED_IN_USER,
[email protected]945f9cae2012-12-12 09:54:29381 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]f5c9dbc2014-04-11 08:13:45382 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28383 ->layout_manager(),
384 controller->GetSystemModalLayoutManager(NULL));
[email protected]8674b312012-10-12 19:02:44385
[email protected]3b162e12012-11-09 11:52:35386 views::Widget* session_modal_widget =
387 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
[email protected]f5c9dbc2014-04-11 08:13:45388 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28389 ->layout_manager(),
390 controller->GetSystemModalLayoutManager(
391 session_modal_widget->GetNativeView()));
[email protected]3b162e12012-11-09 11:52:35392
[email protected]fcb123d2013-04-17 15:58:49393 shell->session_state_delegate()->LockScreen();
[email protected]8674b312012-10-12 19:02:44394 EXPECT_EQ(user::LOGGED_IN_LOCKED,
[email protected]945f9cae2012-12-12 09:54:29395 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]f5c9dbc2014-04-11 08:13:45396 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28397 ->layout_manager(),
398 controller->GetSystemModalLayoutManager(NULL));
[email protected]3b162e12012-11-09 11:52:35399
[email protected]f5c9dbc2014-04-11 08:13:45400 aura::Window* lock_container =
401 controller->GetContainer(kShellWindowId_LockScreenContainer);
[email protected]3b162e12012-11-09 11:52:35402 views::Widget* lock_modal_widget =
403 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container);
[email protected]f5c9dbc2014-04-11 08:13:45404 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28405 ->layout_manager(),
406 controller->GetSystemModalLayoutManager(
407 lock_modal_widget->GetNativeView()));
[email protected]f5c9dbc2014-04-11 08:13:45408 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28409 ->layout_manager(),
[email protected]3b162e12012-11-09 11:52:35410 controller->GetSystemModalLayoutManager(
411 session_modal_widget->GetNativeView()));
412
[email protected]fcb123d2013-04-17 15:58:49413 shell->session_state_delegate()->UnlockScreen();
[email protected]8674b312012-10-12 19:02:44414}
415
[email protected]1b219922012-11-13 21:16:43416TEST_F(RootWindowControllerTest, ModalContainerNotLoggedInLoggedIn) {
417 UpdateDisplay("600x600");
418 Shell* shell = Shell::GetInstance();
419
420 // Configure login screen environment.
421 SetUserLoggedIn(false);
422 EXPECT_EQ(user::LOGGED_IN_NONE,
[email protected]945f9cae2012-12-12 09:54:29423 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]c8d19f82013-05-18 09:09:41424 EXPECT_EQ(0, shell->session_state_delegate()->NumberOfLoggedInUsers());
[email protected]fcb123d2013-04-17 15:58:49425 EXPECT_FALSE(shell->session_state_delegate()->IsActiveUserSessionStarted());
[email protected]1b219922012-11-13 21:16:43426
[email protected]093b8d642014-04-03 20:59:28427 RootWindowController* controller = shell->GetPrimaryRootWindowController();
[email protected]f5c9dbc2014-04-11 08:13:45428 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28429 ->layout_manager(),
430 controller->GetSystemModalLayoutManager(NULL));
[email protected]1b219922012-11-13 21:16:43431
[email protected]f5c9dbc2014-04-11 08:13:45432 aura::Window* lock_container =
433 controller->GetContainer(kShellWindowId_LockScreenContainer);
[email protected]1b219922012-11-13 21:16:43434 views::Widget* login_modal_widget =
435 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container);
[email protected]f5c9dbc2014-04-11 08:13:45436 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28437 ->layout_manager(),
438 controller->GetSystemModalLayoutManager(
439 login_modal_widget->GetNativeView()));
[email protected]1b219922012-11-13 21:16:43440 login_modal_widget->Close();
441
442 // Configure user session environment.
443 SetUserLoggedIn(true);
444 SetSessionStarted(true);
445 EXPECT_EQ(user::LOGGED_IN_USER,
[email protected]945f9cae2012-12-12 09:54:29446 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]c8d19f82013-05-18 09:09:41447 EXPECT_EQ(1, shell->session_state_delegate()->NumberOfLoggedInUsers());
[email protected]fcb123d2013-04-17 15:58:49448 EXPECT_TRUE(shell->session_state_delegate()->IsActiveUserSessionStarted());
[email protected]f5c9dbc2014-04-11 08:13:45449 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28450 ->layout_manager(),
451 controller->GetSystemModalLayoutManager(NULL));
[email protected]1b219922012-11-13 21:16:43452
453 views::Widget* session_modal_widget =
454 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
[email protected]f5c9dbc2014-04-11 08:13:45455 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28456 ->layout_manager(),
457 controller->GetSystemModalLayoutManager(
458 session_modal_widget->GetNativeView()));
[email protected]1b219922012-11-13 21:16:43459}
460
[email protected]a44afbbd2013-07-24 21:49:35461TEST_F(RootWindowControllerTest, ModalContainerBlockedSession) {
462 UpdateDisplay("600x600");
Peter Kastingbe940e92014-11-20 23:14:08463 RootWindowController* controller = Shell::GetPrimaryRootWindowController();
[email protected]f5c9dbc2014-04-11 08:13:45464 aura::Window* lock_container =
465 controller->GetContainer(kShellWindowId_LockScreenContainer);
[email protected]a44afbbd2013-07-24 21:49:35466 for (int block_reason = FIRST_BLOCK_REASON;
467 block_reason < NUMBER_OF_BLOCK_REASONS;
468 ++block_reason) {
469 views::Widget* session_modal_widget =
470 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
[email protected]f5c9dbc2014-04-11 08:13:45471 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28472 ->layout_manager(),
473 controller->GetSystemModalLayoutManager(
474 session_modal_widget->GetNativeView()));
[email protected]f5c9dbc2014-04-11 08:13:45475 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28476 ->layout_manager(),
477 controller->GetSystemModalLayoutManager(NULL));
[email protected]a44afbbd2013-07-24 21:49:35478 session_modal_widget->Close();
479
480 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
481
[email protected]f5c9dbc2014-04-11 08:13:45482 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28483 ->layout_manager(),
484 controller->GetSystemModalLayoutManager(NULL));
[email protected]a44afbbd2013-07-24 21:49:35485
486 views::Widget* lock_modal_widget =
487 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100),
488 lock_container);
[email protected]f5c9dbc2014-04-11 08:13:45489 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28490 ->layout_manager(),
[email protected]a44afbbd2013-07-24 21:49:35491 controller->GetSystemModalLayoutManager(
492 lock_modal_widget->GetNativeView()));
493
494 session_modal_widget =
495 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
[email protected]f5c9dbc2014-04-11 08:13:45496 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28497 ->layout_manager(),
498 controller->GetSystemModalLayoutManager(
499 session_modal_widget->GetNativeView()));
[email protected]a44afbbd2013-07-24 21:49:35500 session_modal_widget->Close();
501
502 lock_modal_widget->Close();
503 UnblockUserSession();
504 }
505}
506
[email protected]2c9171d22013-12-10 21:55:10507TEST_F(RootWindowControllerTest, GetWindowForFullscreenMode) {
[email protected]2ee2f5d2013-01-10 23:37:16508 UpdateDisplay("600x600");
[email protected]093b8d642014-04-03 20:59:28509 RootWindowController* controller =
[email protected]2ee2f5d2013-01-10 23:37:16510 Shell::GetInstance()->GetPrimaryRootWindowController();
511
[email protected]700849f2013-04-30 17:49:20512 Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
[email protected]2ee2f5d2013-01-10 23:37:16513 w1->Maximize();
[email protected]700849f2013-04-30 17:49:20514 Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
515 w2->SetFullscreen(true);
516 // |w3| is a transient child of |w2|.
517 Widget* w3 = Widget::CreateWindowWithParentAndBounds(NULL,
518 w2->GetNativeWindow(), gfx::Rect(0, 0, 100, 100));
[email protected]2ee2f5d2013-01-10 23:37:16519
[email protected]2c9171d22013-12-10 21:55:10520 // Test that GetWindowForFullscreenMode() finds the fullscreen window when one
[email protected]e3bc88e2013-09-06 06:22:06521 // of its transient children is active.
[email protected]700849f2013-04-30 17:49:20522 w3->Activate();
[email protected]2c9171d22013-12-10 21:55:10523 EXPECT_EQ(w2->GetNativeWindow(), controller->GetWindowForFullscreenMode());
[email protected]2ee2f5d2013-01-10 23:37:16524
[email protected]2c9171d22013-12-10 21:55:10525 // If the topmost window is not fullscreen, it returns NULL.
[email protected]700849f2013-04-30 17:49:20526 w1->Activate();
[email protected]2c9171d22013-12-10 21:55:10527 EXPECT_EQ(NULL, controller->GetWindowForFullscreenMode());
528 w1->Close();
529 w3->Close();
[email protected]e3bc88e2013-09-06 06:22:06530
[email protected]2c9171d22013-12-10 21:55:10531 // Only w2 remains, if minimized GetWindowForFullscreenMode should return
532 // NULL.
[email protected]e3bc88e2013-09-06 06:22:06533 w2->Activate();
[email protected]2c9171d22013-12-10 21:55:10534 EXPECT_EQ(w2->GetNativeWindow(), controller->GetWindowForFullscreenMode());
535 w2->Minimize();
536 EXPECT_EQ(NULL, controller->GetWindowForFullscreenMode());
[email protected]2ee2f5d2013-01-10 23:37:16537}
538
[email protected]2c5db9e2014-02-27 13:58:14539TEST_F(RootWindowControllerTest, MultipleDisplaysGetWindowForFullscreenMode) {
540 if (!SupportsMultipleDisplays())
541 return;
542
543 UpdateDisplay("600x600,600x600");
544 Shell::RootWindowControllerList controllers =
545 Shell::GetInstance()->GetAllRootWindowControllers();
546
547 Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
548 w1->Maximize();
549 Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
550 w2->SetFullscreen(true);
551 Widget* w3 = CreateTestWidget(gfx::Rect(600, 0, 100, 100));
552
553 EXPECT_EQ(w1->GetNativeWindow()->GetRootWindow(),
[email protected]f5c9dbc2014-04-11 08:13:45554 controllers[0]->GetRootWindow());
[email protected]2c5db9e2014-02-27 13:58:14555 EXPECT_EQ(w2->GetNativeWindow()->GetRootWindow(),
[email protected]f5c9dbc2014-04-11 08:13:45556 controllers[0]->GetRootWindow());
[email protected]2c5db9e2014-02-27 13:58:14557 EXPECT_EQ(w3->GetNativeWindow()->GetRootWindow(),
[email protected]f5c9dbc2014-04-11 08:13:45558 controllers[1]->GetRootWindow());
[email protected]2c5db9e2014-02-27 13:58:14559
560 w1->Activate();
561 EXPECT_EQ(NULL, controllers[0]->GetWindowForFullscreenMode());
562 EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode());
563
564 w2->Activate();
565 EXPECT_EQ(w2->GetNativeWindow(),
566 controllers[0]->GetWindowForFullscreenMode());
567 EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode());
568
569 // Verify that the first root window controller remains in fullscreen mode
570 // when a window on the other display is activated.
571 w3->Activate();
572 EXPECT_EQ(w2->GetNativeWindow(),
573 controllers[0]->GetWindowForFullscreenMode());
574 EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode());
575}
576
[email protected]82ced2352013-07-19 20:49:06577// Test that user session window can't be focused if user session blocked by
578// some overlapping UI.
579TEST_F(RootWindowControllerTest, FocusBlockedWindow) {
580 UpdateDisplay("600x600");
[email protected]093b8d642014-04-03 20:59:28581 RootWindowController* controller =
[email protected]82ced2352013-07-19 20:49:06582 Shell::GetInstance()->GetPrimaryRootWindowController();
[email protected]f5c9dbc2014-04-11 08:13:45583 aura::Window* lock_container =
584 controller->GetContainer(kShellWindowId_LockScreenContainer);
[email protected]82ced2352013-07-19 20:49:06585 aura::Window* lock_window = Widget::CreateWindowWithParentAndBounds(NULL,
586 lock_container, gfx::Rect(0, 0, 100, 100))->GetNativeView();
587 lock_window->Show();
588 aura::Window* session_window =
589 CreateTestWidget(gfx::Rect(0, 0, 100, 100))->GetNativeView();
590 session_window->Show();
591
[email protected]a44afbbd2013-07-24 21:49:35592 for (int block_reason = FIRST_BLOCK_REASON;
593 block_reason < NUMBER_OF_BLOCK_REASONS;
594 ++block_reason) {
595 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
596 lock_window->Focus();
597 EXPECT_TRUE(lock_window->HasFocus());
598 session_window->Focus();
599 EXPECT_FALSE(session_window->HasFocus());
600 UnblockUserSession();
601 }
[email protected]82ced2352013-07-19 20:49:06602}
603
[email protected]0fbfa972013-10-02 19:23:33604// Tracks whether OnWindowDestroying() has been invoked.
605class DestroyedWindowObserver : public aura::WindowObserver {
606 public:
607 DestroyedWindowObserver() : destroyed_(false), window_(NULL) {}
dcheng1f4538e2014-10-27 23:57:05608 ~DestroyedWindowObserver() override { Shutdown(); }
[email protected]0fbfa972013-10-02 19:23:33609
610 void SetWindow(Window* window) {
611 window_ = window;
612 window->AddObserver(this);
613 }
614
615 bool destroyed() const { return destroyed_; }
616
617 // WindowObserver overrides:
dcheng1f4538e2014-10-27 23:57:05618 void OnWindowDestroying(Window* window) override {
[email protected]0fbfa972013-10-02 19:23:33619 destroyed_ = true;
620 Shutdown();
621 }
622
623 private:
624 void Shutdown() {
625 if (!window_)
626 return;
627 window_->RemoveObserver(this);
628 window_ = NULL;
629 }
630
631 bool destroyed_;
632 Window* window_;
633
634 DISALLOW_COPY_AND_ASSIGN(DestroyedWindowObserver);
635};
636
637// Verifies shutdown doesn't delete windows that are not owned by the parent.
638TEST_F(RootWindowControllerTest, DontDeleteWindowsNotOwnedByParent) {
639 DestroyedWindowObserver observer1;
640 aura::test::TestWindowDelegate delegate1;
641 aura::Window* window1 = new aura::Window(&delegate1);
[email protected]5b251f12013-12-19 01:50:05642 window1->SetType(ui::wm::WINDOW_TYPE_CONTROL);
[email protected]0fbfa972013-10-02 19:23:33643 window1->set_owned_by_parent(false);
644 observer1.SetWindow(window1);
danakjb161836d2015-04-03 05:14:18645 window1->Init(ui::LAYER_NOT_DRAWN);
[email protected]e3225e02013-10-23 20:44:37646 aura::client::ParentWindowWithContext(
647 window1, Shell::GetInstance()->GetPrimaryRootWindow(), gfx::Rect());
[email protected]0fbfa972013-10-02 19:23:33648
649 DestroyedWindowObserver observer2;
650 aura::Window* window2 = new aura::Window(NULL);
651 window2->set_owned_by_parent(false);
652 observer2.SetWindow(window2);
danakjb161836d2015-04-03 05:14:18653 window2->Init(ui::LAYER_NOT_DRAWN);
[email protected]0fbfa972013-10-02 19:23:33654 Shell::GetInstance()->GetPrimaryRootWindow()->AddChild(window2);
655
656 Shell::GetInstance()->GetPrimaryRootWindowController()->CloseChildWindows();
657
658 ASSERT_FALSE(observer1.destroyed());
659 delete window1;
660
661 ASSERT_FALSE(observer2.destroyed());
662 delete window2;
663}
664
[email protected]cf6fea22013-08-07 14:24:01665typedef test::NoSessionAshTestBase NoSessionRootWindowControllerTest;
666
667// Make sure that an event handler exists for entire display area.
668TEST_F(NoSessionRootWindowControllerTest, Event) {
[email protected]bf9cdb362013-10-25 19:22:45669 aura::Window* root = Shell::GetPrimaryRootWindow();
[email protected]cf6fea22013-08-07 14:24:01670 const gfx::Size size = root->bounds().size();
mswf9da4d82016-04-07 18:19:35671 EXPECT_TRUE(root->GetEventHandlerForPoint(gfx::Point(0, 0)));
672 EXPECT_TRUE(root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1)));
673 EXPECT_TRUE(root->GetEventHandlerForPoint(gfx::Point(size.width() - 1, 0)));
674 EXPECT_TRUE(root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1)));
675 EXPECT_TRUE(root->GetEventHandlerForPoint(
676 gfx::Point(size.width() - 1, size.height() - 1)));
[email protected]cf6fea22013-08-07 14:24:01677}
678
[email protected]24f5e242014-07-22 02:16:09679class VirtualKeyboardRootWindowControllerTest
680 : public RootWindowControllerTest {
[email protected]eff4c7f2013-08-13 01:45:50681 public:
dcheng1f4538e2014-10-27 23:57:05682 VirtualKeyboardRootWindowControllerTest() {}
683 ~VirtualKeyboardRootWindowControllerTest() override {}
[email protected]eff4c7f2013-08-13 01:45:50684
dcheng1f4538e2014-10-27 23:57:05685 void SetUp() override {
pgal.u-szegedd84534d32014-10-29 12:34:30686 base::CommandLine::ForCurrentProcess()->AppendSwitch(
[email protected]eff4c7f2013-08-13 01:45:50687 keyboard::switches::kEnableVirtualKeyboard);
688 test::AshTestBase::SetUp();
[email protected]24ca45d2013-10-25 03:37:44689 Shell::GetPrimaryRootWindowController()->ActivateKeyboard(
[email protected]a0b3fb882014-04-07 19:26:03690 keyboard::KeyboardController::GetInstance());
[email protected]eff4c7f2013-08-13 01:45:50691 }
692
693 private:
694 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest);
695};
696
[email protected]2082d7d2014-05-13 14:44:23697class MockTextInputClient : public ui::DummyTextInputClient {
698 public:
699 MockTextInputClient() :
700 ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT) {}
701
dcheng1f4538e2014-10-27 23:57:05702 void EnsureCaretInRect(const gfx::Rect& rect) override {
[email protected]2082d7d2014-05-13 14:44:23703 visible_rect_ = rect;
704 }
705
706 const gfx::Rect& visible_rect() const {
707 return visible_rect_;
708 }
709
710 private:
711 gfx::Rect visible_rect_;
712
713 DISALLOW_COPY_AND_ASSIGN(MockTextInputClient);
714};
715
kevers23f3987d2014-09-17 13:50:12716class TargetHitTestEventHandler : public ui::test::TestEventHandler {
717 public:
718 TargetHitTestEventHandler() {}
719
720 // ui::test::TestEventHandler overrides.
dcheng1f4538e2014-10-27 23:57:05721 void OnMouseEvent(ui::MouseEvent* event) override {
kevers23f3987d2014-09-17 13:50:12722 if (event->type() == ui::ET_MOUSE_PRESSED)
723 ui::test::TestEventHandler::OnMouseEvent(event);
724 event->StopPropagation();
725 }
726
727 private:
728 DISALLOW_COPY_AND_ASSIGN(TargetHitTestEventHandler);
729};
730
[email protected]b6ba05d902013-10-04 21:38:45731// Test for http://crbug.com/297858. Virtual keyboard container should only show
732// on primary root window.
733TEST_F(VirtualKeyboardRootWindowControllerTest,
734 VirtualKeyboardOnPrimaryRootWindowOnly) {
735 if (!SupportsMultipleDisplays())
736 return;
737
738 UpdateDisplay("500x500,500x500");
739
[email protected]c9390bd2013-11-08 20:33:13740 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]bf9cdb362013-10-25 19:22:45741 aura::Window* primary_root_window = Shell::GetPrimaryRootWindow();
742 aura::Window* secondary_root_window =
[email protected]b6ba05d902013-10-04 21:38:45743 root_windows[0] == primary_root_window ?
744 root_windows[1] : root_windows[0];
745
[email protected]093b8d642014-04-03 20:59:28746 ASSERT_TRUE(Shell::GetContainer(primary_root_window,
747 kShellWindowId_VirtualKeyboardContainer));
748 ASSERT_FALSE(Shell::GetContainer(secondary_root_window,
749 kShellWindowId_VirtualKeyboardContainer));
[email protected]b6ba05d902013-10-04 21:38:45750}
751
[email protected]eff4c7f2013-08-13 01:45:50752// Test for http://crbug.com/263599. Virtual keyboard should be able to receive
753// events at blocked user session.
754TEST_F(VirtualKeyboardRootWindowControllerTest,
755 ClickVirtualKeyboardInBlockedWindow) {
[email protected]bf9cdb362013-10-25 19:22:45756 aura::Window* root_window = Shell::GetPrimaryRootWindow();
[email protected]093b8d642014-04-03 20:59:28757 aura::Window* keyboard_container =
758 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
[email protected]eff4c7f2013-08-13 01:45:50759 ASSERT_TRUE(keyboard_container);
760 keyboard_container->Show();
761
ben974286a2015-10-10 00:45:12762 aura::Window* keyboard_window =
763 keyboard::KeyboardController::GetInstance()->ui()->GetKeyboardWindow();
[email protected]647b4842013-12-12 14:24:24764 keyboard_container->AddChild(keyboard_window);
[email protected]183e28d2014-01-20 18:18:02765 keyboard_window->set_owned_by_parent(false);
[email protected]647b4842013-12-12 14:24:24766 keyboard_window->SetBounds(gfx::Rect());
[email protected]eff4c7f2013-08-13 01:45:50767 keyboard_window->Show();
[email protected]647b4842013-12-12 14:24:24768
[email protected]3193ea722014-04-23 22:19:19769 ui::test::TestEventHandler handler;
770 root_window->AddPreTargetHandler(&handler);
[email protected]647b4842013-12-12 14:24:24771
[email protected]73c9fd02014-07-28 01:48:52772 ui::test::EventGenerator event_generator(root_window, keyboard_window);
[email protected]eff4c7f2013-08-13 01:45:50773 event_generator.ClickLeftButton();
774 int expected_mouse_presses = 1;
[email protected]3193ea722014-04-23 22:19:19775 EXPECT_EQ(expected_mouse_presses, handler.num_mouse_events() / 2);
[email protected]eff4c7f2013-08-13 01:45:50776
777 for (int block_reason = FIRST_BLOCK_REASON;
778 block_reason < NUMBER_OF_BLOCK_REASONS;
779 ++block_reason) {
780 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
781 event_generator.ClickLeftButton();
782 expected_mouse_presses++;
[email protected]3193ea722014-04-23 22:19:19783 EXPECT_EQ(expected_mouse_presses, handler.num_mouse_events() / 2);
[email protected]eff4c7f2013-08-13 01:45:50784 UnblockUserSession();
785 }
[email protected]3193ea722014-04-23 22:19:19786 root_window->RemovePreTargetHandler(&handler);
[email protected]eff4c7f2013-08-13 01:45:50787}
788
[email protected]45c66672013-10-01 22:48:56789// Test for http://crbug.com/299787. RootWindowController should delete
790// the old container since the keyboard controller creates a new window in
791// GetWindowContainer().
792TEST_F(VirtualKeyboardRootWindowControllerTest,
793 DeleteOldContainerOnVirtualKeyboardInit) {
[email protected]1025937e2014-02-13 01:25:50794 aura::Window* root_window = Shell::GetPrimaryRootWindow();
[email protected]093b8d642014-04-03 20:59:28795 aura::Window* keyboard_container =
796 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
[email protected]45c66672013-10-01 22:48:56797 ASSERT_TRUE(keyboard_container);
798 // Track the keyboard container window.
799 aura::WindowTracker tracker;
800 tracker.Add(keyboard_container);
[email protected]51f438112013-11-18 19:32:50801 // Mock a login user profile change to reinitialize the keyboard.
802 ash::Shell::GetInstance()->OnLoginUserProfilePrepared();
[email protected]45c66672013-10-01 22:48:56803 // keyboard_container should no longer be present.
804 EXPECT_FALSE(tracker.Contains(keyboard_container));
805}
806
[email protected]1025937e2014-02-13 01:25:50807// Test for crbug.com/342524. After user login, the work space should restore to
808// full screen.
809TEST_F(VirtualKeyboardRootWindowControllerTest, RestoreWorkspaceAfterLogin) {
810 aura::Window* root_window = Shell::GetPrimaryRootWindow();
[email protected]093b8d642014-04-03 20:59:28811 aura::Window* keyboard_container =
812 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
[email protected]1025937e2014-02-13 01:25:50813 keyboard_container->Show();
814 keyboard::KeyboardController* controller =
[email protected]a0b3fb882014-04-07 19:26:03815 keyboard::KeyboardController::GetInstance();
ben974286a2015-10-10 00:45:12816 aura::Window* keyboard_window = controller->ui()->GetKeyboardWindow();
[email protected]1025937e2014-02-13 01:25:50817 keyboard_container->AddChild(keyboard_window);
818 keyboard_window->set_owned_by_parent(false);
bshea0a57802015-04-08 18:21:29819 keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds(
820 root_window->bounds(), 100));
[email protected]1025937e2014-02-13 01:25:50821 keyboard_window->Show();
822
scottmge8b042972016-01-27 05:07:35823 gfx::Rect before = gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area();
[email protected]1025937e2014-02-13 01:25:50824
825 // Notify keyboard bounds changing.
bshea0a57802015-04-08 18:21:29826 controller->NotifyKeyboardBoundsChanging(keyboard_container->bounds());
[email protected]1025937e2014-02-13 01:25:50827
[email protected]25df7ad2014-04-30 18:10:25828 if (!keyboard::IsKeyboardOverscrollEnabled()) {
scottmge8b042972016-01-27 05:07:35829 gfx::Rect after = gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area();
[email protected]25df7ad2014-04-30 18:10:25830 EXPECT_LT(after, before);
831 }
[email protected]1025937e2014-02-13 01:25:50832
833 // Mock a login user profile change to reinitialize the keyboard.
834 ash::Shell::GetInstance()->OnLoginUserProfilePrepared();
scottmge8b042972016-01-27 05:07:35835 EXPECT_EQ(gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(), before);
[email protected]1025937e2014-02-13 01:25:50836}
837
[email protected]602022b2014-03-31 17:07:31838// Ensure that system modal dialogs do not block events targeted at the virtual
839// keyboard.
840TEST_F(VirtualKeyboardRootWindowControllerTest, ClickWithActiveModalDialog) {
841 aura::Window* root_window = Shell::GetPrimaryRootWindow();
[email protected]093b8d642014-04-03 20:59:28842 aura::Window* keyboard_container =
843 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
[email protected]602022b2014-03-31 17:07:31844 ASSERT_TRUE(keyboard_container);
845 keyboard_container->Show();
846
ben974286a2015-10-10 00:45:12847 aura::Window* keyboard_window =
848 keyboard::KeyboardController::GetInstance()->ui()->GetKeyboardWindow();
[email protected]602022b2014-03-31 17:07:31849 keyboard_container->AddChild(keyboard_window);
850 keyboard_window->set_owned_by_parent(false);
bshea0a57802015-04-08 18:21:29851 keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds(
852 root_window->bounds(), 100));
[email protected]3193ea722014-04-23 22:19:19853
854 ui::test::TestEventHandler handler;
855 root_window->AddPreTargetHandler(&handler);
[email protected]73c9fd02014-07-28 01:48:52856 ui::test::EventGenerator root_window_event_generator(root_window);
857 ui::test::EventGenerator keyboard_event_generator(root_window,
858 keyboard_window);
[email protected]602022b2014-03-31 17:07:31859
860 views::Widget* modal_widget =
861 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
862
863 // Verify that mouse events to the root window are block with a visble modal
864 // dialog.
865 root_window_event_generator.ClickLeftButton();
[email protected]3193ea722014-04-23 22:19:19866 EXPECT_EQ(0, handler.num_mouse_events());
[email protected]602022b2014-03-31 17:07:31867
868 // Verify that event dispatch to the virtual keyboard is unblocked.
869 keyboard_event_generator.ClickLeftButton();
[email protected]3193ea722014-04-23 22:19:19870 EXPECT_EQ(1, handler.num_mouse_events() / 2);
[email protected]602022b2014-03-31 17:07:31871
872 modal_widget->Close();
873
874 // Verify that mouse events are now unblocked to the root window.
875 root_window_event_generator.ClickLeftButton();
[email protected]3193ea722014-04-23 22:19:19876 EXPECT_EQ(2, handler.num_mouse_events() / 2);
877 root_window->RemovePreTargetHandler(&handler);
[email protected]602022b2014-03-31 17:07:31878}
879
[email protected]2082d7d2014-05-13 14:44:23880// Ensure that the visible area for scrolling the text caret excludes the
881// region occluded by the on-screen keyboard.
882TEST_F(VirtualKeyboardRootWindowControllerTest, EnsureCaretInWorkArea) {
883 keyboard::KeyboardController* keyboard_controller =
884 keyboard::KeyboardController::GetInstance();
ben974286a2015-10-10 00:45:12885 keyboard::KeyboardUI* ui = keyboard_controller->ui();
[email protected]2082d7d2014-05-13 14:44:23886
887 MockTextInputClient text_input_client;
ben974286a2015-10-10 00:45:12888 ui::InputMethod* input_method = ui->GetInputMethod();
[email protected]2082d7d2014-05-13 14:44:23889 ASSERT_TRUE(input_method);
shuchen4e09795a2015-06-15 15:07:20890 input_method->SetFocusedTextInputClient(&text_input_client);
[email protected]2082d7d2014-05-13 14:44:23891
892 aura::Window* root_window = Shell::GetPrimaryRootWindow();
893 aura::Window* keyboard_container =
894 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
895 ASSERT_TRUE(keyboard_container);
896 keyboard_container->Show();
897
898 const int keyboard_height = 100;
ben974286a2015-10-10 00:45:12899 aura::Window* keyboard_window = ui->GetKeyboardWindow();
[email protected]2082d7d2014-05-13 14:44:23900 keyboard_container->AddChild(keyboard_window);
901 keyboard_window->set_owned_by_parent(false);
bshea0a57802015-04-08 18:21:29902 keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds(
903 root_window->bounds(), keyboard_height));
[email protected]2082d7d2014-05-13 14:44:23904
ben974286a2015-10-10 00:45:12905 ui->EnsureCaretInWorkArea();
bshea0a57802015-04-08 18:21:29906 ASSERT_EQ(root_window->bounds().width(),
[email protected]2082d7d2014-05-13 14:44:23907 text_input_client.visible_rect().width());
bshea0a57802015-04-08 18:21:29908 ASSERT_EQ(root_window->bounds().height() - keyboard_height,
[email protected]2082d7d2014-05-13 14:44:23909 text_input_client.visible_rect().height());
[email protected]00a386792014-06-16 15:09:20910
shuchen4e09795a2015-06-15 15:07:20911 input_method->SetFocusedTextInputClient(NULL);
[email protected]2082d7d2014-05-13 14:44:23912}
913
kevers23f3987d2014-09-17 13:50:12914// Tests that the virtual keyboard does not block context menus. The virtual
915// keyboard should appear in front of most content, but not context menus. See
916// crbug/377180.
917TEST_F(VirtualKeyboardRootWindowControllerTest, ZOrderTest) {
918 UpdateDisplay("800x600");
919 keyboard::KeyboardController* keyboard_controller =
920 keyboard::KeyboardController::GetInstance();
ben974286a2015-10-10 00:45:12921 keyboard::KeyboardUI* ui = keyboard_controller->ui();
kevers23f3987d2014-09-17 13:50:12922
923 aura::Window* root_window = Shell::GetPrimaryRootWindow();
924 aura::Window* keyboard_container =
925 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
926 ASSERT_TRUE(keyboard_container);
927 keyboard_container->Show();
928
929 const int keyboard_height = 200;
ben974286a2015-10-10 00:45:12930 aura::Window* keyboard_window = ui->GetKeyboardWindow();
kevers23f3987d2014-09-17 13:50:12931 keyboard_container->AddChild(keyboard_window);
932 keyboard_window->set_owned_by_parent(false);
bshea0a57802015-04-08 18:21:29933 gfx::Rect keyboard_bounds = keyboard::FullWidthKeyboardBoundsFromRootBounds(
934 root_window->bounds(), keyboard_height);
kevers23f3987d2014-09-17 13:50:12935 keyboard_window->SetBounds(keyboard_bounds);
936 keyboard_window->Show();
937
938 ui::test::EventGenerator generator(root_window);
939
940 // Cover the screen with two windows: a normal window on the left side and a
941 // context menu on the right side. When the virtual keyboard is displayed it
942 // partially occludes the normal window, but not the context menu. Compute
943 // positions for generating synthetic click events to perform hit tests,
944 // ensuring the correct window layering. 'top' is above the VK, whereas
945 // 'bottom' lies within the VK. 'left' is centered in the normal window, and
946 // 'right' is centered in the context menu.
947 int window_height = keyboard_bounds.bottom();
948 int window_width = keyboard_bounds.width() / 2;
949 int left = window_width / 2;
950 int right = 3 * window_width / 2;
951 int top = keyboard_bounds.y() / 2;
952 int bottom = window_height - keyboard_height / 2;
953
954 // Normal window is partially occluded by the virtual keyboard.
955 aura::test::TestWindowDelegate delegate;
dchenga94547472016-04-08 08:41:11956 std::unique_ptr<aura::Window> normal(
957 CreateTestWindowInShellWithDelegateAndType(
958 &delegate, ui::wm::WINDOW_TYPE_NORMAL, 0,
959 gfx::Rect(0, 0, window_width, window_height)));
kevers23f3987d2014-09-17 13:50:12960 normal->set_owned_by_parent(false);
961 normal->Show();
962 TargetHitTestEventHandler normal_handler;
963 normal->AddPreTargetHandler(&normal_handler);
964
965 // Test that only the click on the top portion of the window is picked up. The
966 // click on the bottom hits the virtual keyboard instead.
967 generator.MoveMouseTo(left, top);
968 generator.ClickLeftButton();
969 EXPECT_EQ(1, normal_handler.num_mouse_events());
970 generator.MoveMouseTo(left, bottom);
971 generator.ClickLeftButton();
972 EXPECT_EQ(1, normal_handler.num_mouse_events());
973
974 // Menu overlaps virtual keyboard.
975 aura::test::TestWindowDelegate delegate2;
dchenga94547472016-04-08 08:41:11976 std::unique_ptr<aura::Window> menu(CreateTestWindowInShellWithDelegateAndType(
977 &delegate2, ui::wm::WINDOW_TYPE_MENU, 0,
kevers23f3987d2014-09-17 13:50:12978 gfx::Rect(window_width, 0, window_width, window_height)));
979 menu->set_owned_by_parent(false);
980 menu->Show();
981 TargetHitTestEventHandler menu_handler;
982 menu->AddPreTargetHandler(&menu_handler);
983
984 // Test that both clicks register.
985 generator.MoveMouseTo(right, top);
986 generator.ClickLeftButton();
987 EXPECT_EQ(1, menu_handler.num_mouse_events());
988 generator.MoveMouseTo(right, bottom);
989 generator.ClickLeftButton();
990 EXPECT_EQ(2, menu_handler.num_mouse_events());
991
992 // Cleanup to ensure that the test windows are destroyed before their
993 // delegates.
994 normal.reset();
995 menu.reset();
996}
997
kevers0e450492014-09-30 16:02:31998// Resolution in UpdateDisplay is not being respected on Windows 8.
999#if defined(OS_WIN)
1000#define MAYBE_DisplayRotation DISABLED_DisplayRotation
1001#else
1002#define MAYBE_DisplayRotation DisplayRotation
1003#endif
1004
1005// Tests that the virtual keyboard correctly resizes with a change to display
1006// orientation. See crbug/417612.
1007TEST_F(VirtualKeyboardRootWindowControllerTest, MAYBE_DisplayRotation) {
1008 UpdateDisplay("800x600");
1009 aura::Window* root_window = Shell::GetPrimaryRootWindow();
1010 aura::Window* keyboard_container =
1011 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
1012 ASSERT_TRUE(keyboard_container);
bshea0a57802015-04-08 18:21:291013 keyboard::KeyboardController* keyboard_controller =
1014 keyboard::KeyboardController::GetInstance();
1015 keyboard_controller->ShowKeyboard(false);
ben974286a2015-10-10 00:45:121016 keyboard_controller->ui()->GetKeyboardWindow()->SetBounds(
bshea0a57802015-04-08 18:21:291017 gfx::Rect(0, 400, 800, 200));
1018 EXPECT_EQ("0,400 800x200", keyboard_container->bounds().ToString());
kevers0e450492014-09-30 16:02:311019
1020 UpdateDisplay("600x800");
bshea0a57802015-04-08 18:21:291021 EXPECT_EQ("0,600 600x200", keyboard_container->bounds().ToString());
kevers0e450492014-09-30 16:02:311022}
1023
[email protected]f1853122012-06-27 16:21:261024} // namespace test
1025} // namespace ash