[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 1 | // 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] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 5 | #include "ash/root_window_controller.h" |
| 6 | |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 7 | #include <memory> |
| 8 | |
jamescook | e3d63f6 | 2017-01-12 07:12:40 | [diff] [blame] | 9 | #include "ash/common/session/session_controller.h" |
jamescook | 2b624c5a | 2016-06-08 01:34:02 | [diff] [blame] | 10 | #include "ash/common/session/session_state_delegate.h" |
jamescook | 2a4d1eb | 2016-06-09 20:10:07 | [diff] [blame] | 11 | #include "ash/common/system/tray/system_tray_delegate.h" |
sky | ea4ca94 | 2016-09-12 21:56:19 | [diff] [blame] | 12 | #include "ash/common/wm/system_modal_container_layout_manager.h" |
sky | d606377 | 2016-06-01 17:52:21 | [diff] [blame] | 13 | #include "ash/common/wm/window_state.h" |
sky | ea4ca94 | 2016-09-12 21:56:19 | [diff] [blame] | 14 | #include "ash/common/wm_lookup.h" |
jamescook | 443e42d | 2016-06-10 21:44:46 | [diff] [blame] | 15 | #include "ash/common/wm_shell.h" |
sky | ea4ca94 | 2016-09-12 21:56:19 | [diff] [blame] | 16 | #include "ash/common/wm_window.h" |
jamescook | 8800b823 | 2016-10-19 12:46:27 | [diff] [blame] | 17 | #include "ash/public/cpp/shell_window_ids.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 18 | #include "ash/shell.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 19 | #include "ash/test/ash_test_base.h" |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 20 | #include "ash/wm/window_properties.h" |
sky | 8d5646fe | 2016-04-15 17:03:46 | [diff] [blame] | 21 | #include "ash/wm/window_state_aura.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 22 | #include "ash/wm/window_util.h" |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 23 | #include "base/command_line.h" |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 24 | #include "ui/aura/client/focus_change_observer.h" |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 25 | #include "ui/aura/client/focus_client.h" |
sky | 28f20d6 | 2016-10-20 23:21:59 | [diff] [blame] | 26 | #include "ui/aura/client/window_parenting_client.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 27 | #include "ui/aura/env.h" |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 28 | #include "ui/aura/test/test_window_delegate.h" |
| 29 | #include "ui/aura/test/test_windows.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 30 | #include "ui/aura/window.h" |
[email protected] | fcc51c95 | 2014-02-21 21:31:26 | [diff] [blame] | 31 | #include "ui/aura/window_event_dispatcher.h" |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 32 | #include "ui/aura/window_tracker.h" |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 33 | #include "ui/base/ime/dummy_text_input_client.h" |
| 34 | #include "ui/base/ime/input_method.h" |
| 35 | #include "ui/base/ime/text_input_client.h" |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 36 | #include "ui/display/manager/display_manager.h" |
yhanada | 7e20c9b | 2016-11-25 00:03:19 | [diff] [blame] | 37 | #include "ui/display/test/display_manager_test_api.h" |
| 38 | #include "ui/events/devices/device_data_manager.h" |
| 39 | #include "ui/events/devices/touchscreen_device.h" |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 40 | #include "ui/events/test/event_generator.h" |
[email protected] | cd9f71d | 2014-03-20 21:54:21 | [diff] [blame] | 41 | #include "ui/events/test/test_event_handler.h" |
jamescook | cf8b648f | 2016-06-01 19:58:17 | [diff] [blame] | 42 | #include "ui/keyboard/keyboard_controller.h" |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 43 | #include "ui/keyboard/keyboard_switches.h" |
ben | 974286a | 2015-10-10 00:45:12 | [diff] [blame] | 44 | #include "ui/keyboard/keyboard_ui.h" |
[email protected] | 39e9521 | 2014-04-23 20:00:01 | [diff] [blame] | 45 | #include "ui/keyboard/keyboard_util.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 46 | #include "ui/views/controls/menu/menu_controller.h" |
| 47 | #include "ui/views/widget/widget.h" |
| 48 | #include "ui/views/widget/widget_delegate.h" |
| 49 | |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 50 | using aura::Window; |
| 51 | using views::Widget; |
| 52 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 53 | namespace ash { |
| 54 | namespace { |
| 55 | |
| 56 | class TestDelegate : public views::WidgetDelegateView { |
| 57 | public: |
| 58 | explicit TestDelegate(bool system_modal) : system_modal_(system_modal) {} |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 59 | ~TestDelegate() override {} |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 60 | |
| 61 | // Overridden from views::WidgetDelegate: |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 62 | ui::ModalType GetModalType() const override { |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 63 | return system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE; |
| 64 | } |
| 65 | |
| 66 | private: |
| 67 | bool system_modal_; |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 68 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 69 | DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
| 70 | }; |
| 71 | |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 72 | class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate, |
| 73 | public aura::client::FocusChangeObserver { |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 74 | public: |
| 75 | DeleteOnBlurDelegate() : window_(NULL) {} |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 76 | ~DeleteOnBlurDelegate() override {} |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 77 | |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 78 | void SetWindow(aura::Window* window) { |
| 79 | window_ = window; |
| 80 | aura::client::SetFocusChangeObserver(window_, this); |
| 81 | } |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 82 | |
[email protected] | 869f635 | 2012-12-06 20:47:17 | [diff] [blame] | 83 | private: |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 84 | // aura::test::TestWindowDelegate overrides: |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 85 | bool CanFocus() override { return true; } |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 86 | |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 87 | // aura::client::FocusChangeObserver implementation: |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 88 | void OnWindowFocused(aura::Window* gained_focus, |
| 89 | aura::Window* lost_focus) override { |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 90 | if (window_ == lost_focus) |
| 91 | delete window_; |
[email protected] | 869f635 | 2012-12-06 20:47:17 | [diff] [blame] | 92 | } |
| 93 | |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 94 | aura::Window* window_; |
| 95 | |
| 96 | DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate); |
| 97 | }; |
| 98 | |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 99 | WmLayoutManager* GetLayoutManager(RootWindowController* controller, int id) { |
sky | 5dbc91d5 | 2017-01-13 00:26:14 | [diff] [blame] | 100 | return WmWindow::Get(controller->GetContainer(id))->GetLayoutManager(); |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 101 | } |
| 102 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 103 | } // namespace |
| 104 | |
| 105 | namespace test { |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 106 | |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 107 | class RootWindowControllerTest : public AshTestBase { |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 108 | public: |
| 109 | views::Widget* CreateTestWidget(const gfx::Rect& bounds) { |
| 110 | views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 111 | NULL, CurrentContext(), bounds); |
| 112 | widget->Show(); |
| 113 | return widget; |
| 114 | } |
| 115 | |
| 116 | views::Widget* CreateModalWidget(const gfx::Rect& bounds) { |
| 117 | views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 118 | new TestDelegate(true), CurrentContext(), bounds); |
| 119 | widget->Show(); |
| 120 | return widget; |
| 121 | } |
| 122 | |
| 123 | views::Widget* CreateModalWidgetWithParent(const gfx::Rect& bounds, |
| 124 | gfx::NativeWindow parent) { |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 125 | views::Widget* widget = views::Widget::CreateWindowWithParentAndBounds( |
| 126 | new TestDelegate(true), parent, bounds); |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 127 | widget->Show(); |
| 128 | return widget; |
| 129 | } |
| 130 | |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 131 | aura::Window* GetModalContainer(aura::Window* root_window) { |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 132 | return Shell::GetContainer(root_window, |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 133 | kShellWindowId_SystemModalContainer); |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 134 | } |
| 135 | }; |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 136 | |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 137 | TEST_F(RootWindowControllerTest, MoveWindows_Basic) { |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 138 | // Windows origin should be doubled when moved to the 1st display. |
| 139 | UpdateDisplay("600x600,300x300"); |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 140 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 141 | |
| 142 | views::Widget* normal = CreateTestWidget(gfx::Rect(650, 10, 100, 100)); |
| 143 | EXPECT_EQ(root_windows[1], normal->GetNativeView()->GetRootWindow()); |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 144 | EXPECT_EQ("650,10 100x100", normal->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 145 | EXPECT_EQ("50,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 146 | normal->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 147 | |
| 148 | views::Widget* maximized = CreateTestWidget(gfx::Rect(700, 10, 100, 100)); |
| 149 | maximized->Maximize(); |
| 150 | EXPECT_EQ(root_windows[1], maximized->GetNativeView()->GetRootWindow()); |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 151 | EXPECT_EQ(gfx::Rect(600, 0, 300, 252).ToString(), |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 152 | maximized->GetWindowBoundsInScreen().ToString()); |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 153 | EXPECT_EQ(gfx::Rect(0, 0, 300, 252).ToString(), |
[email protected] | 8c0ec43 | 2013-05-10 04:33:39 | [diff] [blame] | 154 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 155 | |
| 156 | views::Widget* minimized = CreateTestWidget(gfx::Rect(800, 10, 100, 100)); |
| 157 | minimized->Minimize(); |
| 158 | EXPECT_EQ(root_windows[1], minimized->GetNativeView()->GetRootWindow()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 159 | EXPECT_EQ("800,10 100x100", minimized->GetWindowBoundsInScreen().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 160 | |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 161 | views::Widget* fullscreen = CreateTestWidget(gfx::Rect(850, 10, 100, 100)); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 162 | fullscreen->SetFullscreen(true); |
| 163 | EXPECT_EQ(root_windows[1], fullscreen->GetNativeView()->GetRootWindow()); |
[email protected] | 1a01538 | 2012-12-01 19:44:59 | [diff] [blame] | 164 | |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 165 | EXPECT_EQ("600,0 300x300", fullscreen->GetWindowBoundsInScreen().ToString()); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 166 | EXPECT_EQ("0,0 300x300", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 167 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 168 | |
[email protected] | 8f2f15141 | 2013-01-26 03:58:37 | [diff] [blame] | 169 | views::Widget* unparented_control = new Widget; |
| 170 | Widget::InitParams params; |
| 171 | params.bounds = gfx::Rect(650, 10, 100, 100); |
| 172 | params.context = CurrentContext(); |
| 173 | params.type = Widget::InitParams::TYPE_CONTROL; |
| 174 | unparented_control->Init(params); |
| 175 | EXPECT_EQ(root_windows[1], |
| 176 | unparented_control->GetNativeView()->GetRootWindow()); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 177 | EXPECT_EQ(kShellWindowId_UnparentedControlContainer, |
[email protected] | 8f2f15141 | 2013-01-26 03:58:37 | [diff] [blame] | 178 | unparented_control->GetNativeView()->parent()->id()); |
| 179 | |
[email protected] | 95db9c1 | 2013-01-31 11:47:44 | [diff] [blame] | 180 | aura::Window* panel = CreateTestWindowInShellWithDelegateAndType( |
[email protected] | 5b251f1 | 2013-12-19 01:50:05 | [diff] [blame] | 181 | NULL, ui::wm::WINDOW_TYPE_PANEL, 0, gfx::Rect(700, 100, 100, 100)); |
[email protected] | 95db9c1 | 2013-01-31 11:47:44 | [diff] [blame] | 182 | EXPECT_EQ(root_windows[1], panel->GetRootWindow()); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 183 | EXPECT_EQ(kShellWindowId_PanelContainer, panel->parent()->id()); |
[email protected] | 95db9c1 | 2013-01-31 11:47:44 | [diff] [blame] | 184 | |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 185 | // Make sure a window that will delete itself when losing focus |
| 186 | // will not crash. |
| 187 | aura::WindowTracker tracker; |
| 188 | DeleteOnBlurDelegate delete_on_blur_delegate; |
[email protected] | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 189 | aura::Window* d2 = CreateTestWindowInShellWithDelegate( |
| 190 | &delete_on_blur_delegate, 0, gfx::Rect(50, 50, 100, 100)); |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 191 | delete_on_blur_delegate.SetWindow(d2); |
[email protected] | 550543e | 2013-01-11 22:43:44 | [diff] [blame] | 192 | aura::client::GetFocusClient(root_windows[0])->FocusWindow(d2); |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 193 | tracker.Add(d2); |
| 194 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 195 | UpdateDisplay("600x600"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 196 | |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 197 | // d2 must have been deleted. |
| 198 | EXPECT_FALSE(tracker.Contains(d2)); |
| 199 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 200 | EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow()); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 201 | EXPECT_EQ("100,20 100x100", normal->GetWindowBoundsInScreen().ToString()); |
| 202 | EXPECT_EQ("100,20 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 203 | normal->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 204 | |
yiyix | 20e7d3f | 2016-06-14 21:49:36 | [diff] [blame] | 205 | // Maximized area on primary display has 47px for non-md and 48px for md |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 206 | // (defined in SHELF_SIZE) inset at the bottom. |
[email protected] | 2a64b0a | 2013-07-23 23:15:54 | [diff] [blame] | 207 | |
| 208 | // First clear fullscreen status, since both fullscreen and maximized windows |
| 209 | // share the same desktop workspace, which cancels the shelf status. |
| 210 | fullscreen->SetFullscreen(false); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 211 | EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow()); |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 212 | EXPECT_EQ(gfx::Rect(0, 0, 600, 552).ToString(), |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 213 | maximized->GetWindowBoundsInScreen().ToString()); |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 214 | EXPECT_EQ(gfx::Rect(0, 0, 600, 552).ToString(), |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 215 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 216 | |
oshima | 5594d123 | 2015-12-04 18:58:38 | [diff] [blame] | 217 | // Set fullscreen to true, but maximized window's size won't change because |
| 218 | // it's not visible. see crbug.com/504299. |
[email protected] | 2a64b0a | 2013-07-23 23:15:54 | [diff] [blame] | 219 | fullscreen->SetFullscreen(true); |
| 220 | EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow()); |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 221 | EXPECT_EQ(gfx::Rect(0, 0, 600, 552).ToString(), |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 222 | maximized->GetWindowBoundsInScreen().ToString()); |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 223 | EXPECT_EQ(gfx::Rect(0, 0, 600, 552).ToString(), |
[email protected] | 2a64b0a | 2013-07-23 23:15:54 | [diff] [blame] | 224 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
| 225 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 226 | EXPECT_EQ(root_windows[0], minimized->GetNativeView()->GetRootWindow()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 227 | EXPECT_EQ("400,20 100x100", minimized->GetWindowBoundsInScreen().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 228 | |
| 229 | EXPECT_EQ(root_windows[0], fullscreen->GetNativeView()->GetRootWindow()); |
| 230 | EXPECT_TRUE(fullscreen->IsFullscreen()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 231 | EXPECT_EQ("0,0 600x600", fullscreen->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 232 | EXPECT_EQ("0,0 600x600", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 233 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 234 | |
| 235 | // Test if the restore bounds are correctly updated. |
[email protected] | a41b4e1 | 2013-09-20 04:36:34 | [diff] [blame] | 236 | wm::GetWindowState(maximized->GetNativeView())->Restore(); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 237 | EXPECT_EQ("200,20 100x100", maximized->GetWindowBoundsInScreen().ToString()); |
| 238 | EXPECT_EQ("200,20 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 239 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 240 | |
| 241 | fullscreen->SetFullscreen(false); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 242 | EXPECT_EQ("500,20 100x100", fullscreen->GetWindowBoundsInScreen().ToString()); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 243 | EXPECT_EQ("500,20 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 244 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | 8f2f15141 | 2013-01-26 03:58:37 | [diff] [blame] | 245 | |
| 246 | // Test if the unparented widget has moved. |
| 247 | EXPECT_EQ(root_windows[0], |
| 248 | unparented_control->GetNativeView()->GetRootWindow()); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 249 | EXPECT_EQ(kShellWindowId_UnparentedControlContainer, |
[email protected] | 8f2f15141 | 2013-01-26 03:58:37 | [diff] [blame] | 250 | unparented_control->GetNativeView()->parent()->id()); |
[email protected] | 95db9c1 | 2013-01-31 11:47:44 | [diff] [blame] | 251 | |
| 252 | // Test if the panel has moved. |
| 253 | EXPECT_EQ(root_windows[0], panel->GetRootWindow()); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 254 | EXPECT_EQ(kShellWindowId_PanelContainer, panel->parent()->id()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 255 | } |
| 256 | |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 257 | TEST_F(RootWindowControllerTest, MoveWindows_Modal) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 258 | UpdateDisplay("500x500,500x500"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 259 | |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 260 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 261 | // Emulate virtual screen coordinate system. |
| 262 | root_windows[0]->SetBounds(gfx::Rect(0, 0, 500, 500)); |
| 263 | root_windows[1]->SetBounds(gfx::Rect(500, 0, 500, 500)); |
| 264 | |
| 265 | views::Widget* normal = CreateTestWidget(gfx::Rect(300, 10, 100, 100)); |
| 266 | EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow()); |
| 267 | EXPECT_TRUE(wm::IsActiveWindow(normal->GetNativeView())); |
| 268 | |
| 269 | views::Widget* modal = CreateModalWidget(gfx::Rect(650, 10, 100, 100)); |
| 270 | EXPECT_EQ(root_windows[1], modal->GetNativeView()->GetRootWindow()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 271 | EXPECT_TRUE( |
| 272 | GetModalContainer(root_windows[1])->Contains(modal->GetNativeView())); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 273 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 274 | |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 275 | ui::test::EventGenerator generator_1st(root_windows[0]); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 276 | generator_1st.ClickLeftButton(); |
| 277 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 278 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 279 | UpdateDisplay("500x500"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 280 | EXPECT_EQ(root_windows[0], modal->GetNativeView()->GetRootWindow()); |
| 281 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 282 | generator_1st.ClickLeftButton(); |
| 283 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 284 | } |
| 285 | |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 286 | // Make sure lock related windows moves. |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 287 | TEST_F(RootWindowControllerTest, MoveWindows_LockWindowsInUnified) { |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 288 | display_manager()->SetUnifiedDesktopEnabled(true); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 289 | |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 290 | UpdateDisplay("500x500"); |
| 291 | const int kLockScreenWindowId = 1000; |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 292 | const int kLockWallpaperWindowId = 1001; |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 293 | |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 294 | RootWindowController* controller = Shell::GetPrimaryRootWindowController(); |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 295 | |
| 296 | aura::Window* lock_container = |
| 297 | controller->GetContainer(kShellWindowId_LockScreenContainer); |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 298 | aura::Window* lock_wallpaper_container = |
| 299 | controller->GetContainer(kShellWindowId_LockScreenWallpaperContainer); |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 300 | |
| 301 | views::Widget* lock_screen = |
| 302 | CreateModalWidgetWithParent(gfx::Rect(10, 10, 100, 100), lock_container); |
| 303 | lock_screen->GetNativeWindow()->set_id(kLockScreenWindowId); |
| 304 | lock_screen->SetFullscreen(true); |
| 305 | |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 306 | views::Widget* lock_wallpaper = CreateModalWidgetWithParent( |
| 307 | gfx::Rect(10, 10, 100, 100), lock_wallpaper_container); |
| 308 | lock_wallpaper->GetNativeWindow()->set_id(kLockWallpaperWindowId); |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 309 | |
| 310 | ASSERT_EQ(lock_screen->GetNativeWindow(), |
| 311 | controller->GetRootWindow()->GetChildById(kLockScreenWindowId)); |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 312 | ASSERT_EQ(lock_wallpaper->GetNativeWindow(), |
| 313 | controller->GetRootWindow()->GetChildById(kLockWallpaperWindowId)); |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 314 | EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString()); |
| 315 | |
| 316 | // Switch to unified. |
| 317 | UpdateDisplay("500x500,500x500"); |
| 318 | |
| 319 | // In unified mode, RWC is created |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 320 | controller = Shell::GetPrimaryRootWindowController(); |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 321 | |
| 322 | ASSERT_EQ(lock_screen->GetNativeWindow(), |
| 323 | controller->GetRootWindow()->GetChildById(kLockScreenWindowId)); |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 324 | ASSERT_EQ(lock_wallpaper->GetNativeWindow(), |
| 325 | controller->GetRootWindow()->GetChildById(kLockWallpaperWindowId)); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 326 | EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString()); |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 327 | |
| 328 | // Switch to mirror. |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 329 | display_manager()->SetMirrorMode(true); |
| 330 | EXPECT_TRUE(display_manager()->IsInMirrorMode()); |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 331 | |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 332 | controller = Shell::GetPrimaryRootWindowController(); |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 333 | ASSERT_EQ(lock_screen->GetNativeWindow(), |
| 334 | controller->GetRootWindow()->GetChildById(kLockScreenWindowId)); |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 335 | ASSERT_EQ(lock_wallpaper->GetNativeWindow(), |
| 336 | controller->GetRootWindow()->GetChildById(kLockWallpaperWindowId)); |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 337 | EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString()); |
| 338 | |
| 339 | // Switch to unified. |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 340 | display_manager()->SetMirrorMode(false); |
| 341 | EXPECT_TRUE(display_manager()->IsInUnifiedMode()); |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 342 | |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 343 | controller = Shell::GetPrimaryRootWindowController(); |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 344 | |
| 345 | ASSERT_EQ(lock_screen->GetNativeWindow(), |
| 346 | controller->GetRootWindow()->GetChildById(kLockScreenWindowId)); |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 347 | ASSERT_EQ(lock_wallpaper->GetNativeWindow(), |
| 348 | controller->GetRootWindow()->GetChildById(kLockWallpaperWindowId)); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 349 | EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString()); |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 350 | |
| 351 | // Switch to single display. |
| 352 | UpdateDisplay("600x500"); |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 353 | EXPECT_FALSE(display_manager()->IsInUnifiedMode()); |
| 354 | EXPECT_FALSE(display_manager()->IsInMirrorMode()); |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 355 | |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 356 | controller = Shell::GetPrimaryRootWindowController(); |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 357 | |
| 358 | ASSERT_EQ(lock_screen->GetNativeWindow(), |
| 359 | controller->GetRootWindow()->GetChildById(kLockScreenWindowId)); |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 360 | ASSERT_EQ(lock_wallpaper->GetNativeWindow(), |
| 361 | controller->GetRootWindow()->GetChildById(kLockWallpaperWindowId)); |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 362 | EXPECT_EQ("0,0 600x500", lock_screen->GetNativeWindow()->bounds().ToString()); |
| 363 | } |
| 364 | |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 365 | TEST_F(RootWindowControllerTest, ModalContainer) { |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 366 | UpdateDisplay("600x600"); |
jamescook | 443e42d | 2016-06-10 21:44:46 | [diff] [blame] | 367 | WmShell* wm_shell = WmShell::Get(); |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 368 | RootWindowController* controller = wm_shell->GetPrimaryRootWindowController(); |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 369 | EXPECT_EQ(LoginStatus::USER, |
jamescook | 443e42d | 2016-06-10 21:44:46 | [diff] [blame] | 370 | wm_shell->system_tray_delegate()->GetUserLoginStatus()); |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 371 | EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer), |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 372 | controller->GetSystemModalLayoutManager(NULL)); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 373 | |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 374 | views::Widget* session_modal_widget = |
| 375 | CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 376 | EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer), |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 377 | controller->GetSystemModalLayoutManager( |
sky | ea4ca94 | 2016-09-12 21:56:19 | [diff] [blame] | 378 | WmLookup::Get()->GetWindowForWidget(session_modal_widget))); |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 379 | |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 380 | wm_shell->GetSessionStateDelegate()->LockScreen(); |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 381 | EXPECT_EQ(LoginStatus::LOCKED, |
jamescook | 443e42d | 2016-06-10 21:44:46 | [diff] [blame] | 382 | wm_shell->system_tray_delegate()->GetUserLoginStatus()); |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 383 | EXPECT_EQ( |
| 384 | GetLayoutManager(controller, kShellWindowId_LockSystemModalContainer), |
| 385 | controller->GetSystemModalLayoutManager(nullptr)); |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 386 | |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 387 | aura::Window* lock_container = |
| 388 | controller->GetContainer(kShellWindowId_LockScreenContainer); |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 389 | views::Widget* lock_modal_widget = |
| 390 | CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container); |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 391 | EXPECT_EQ( |
| 392 | GetLayoutManager(controller, kShellWindowId_LockSystemModalContainer), |
| 393 | controller->GetSystemModalLayoutManager( |
| 394 | WmLookup::Get()->GetWindowForWidget(lock_modal_widget))); |
| 395 | EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer), |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 396 | controller->GetSystemModalLayoutManager( |
sky | ea4ca94 | 2016-09-12 21:56:19 | [diff] [blame] | 397 | WmLookup::Get()->GetWindowForWidget(session_modal_widget))); |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 398 | |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 399 | wm_shell->GetSessionStateDelegate()->UnlockScreen(); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 400 | } |
| 401 | |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 402 | TEST_F(RootWindowControllerTest, ModalContainerNotLoggedInLoggedIn) { |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 403 | UpdateDisplay("600x600"); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 404 | |
| 405 | // Configure login screen environment. |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 406 | SessionStateDelegate* session_state_delegate = |
| 407 | WmShell::Get()->GetSessionStateDelegate(); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 408 | SetUserLoggedIn(false); |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 409 | EXPECT_EQ(LoginStatus::NOT_LOGGED_IN, |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 410 | WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()); |
| 411 | EXPECT_EQ(0, session_state_delegate->NumberOfLoggedInUsers()); |
| 412 | EXPECT_FALSE(session_state_delegate->IsActiveUserSessionStarted()); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 413 | |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 414 | RootWindowController* controller = |
sky | ea4ca94 | 2016-09-12 21:56:19 | [diff] [blame] | 415 | WmShell::Get()->GetPrimaryRootWindowController(); |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 416 | EXPECT_EQ( |
| 417 | GetLayoutManager(controller, kShellWindowId_LockSystemModalContainer), |
| 418 | controller->GetSystemModalLayoutManager(NULL)); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 419 | |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 420 | aura::Window* lock_container = |
| 421 | controller->GetContainer(kShellWindowId_LockScreenContainer); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 422 | views::Widget* login_modal_widget = |
| 423 | CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container); |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 424 | EXPECT_EQ( |
| 425 | GetLayoutManager(controller, kShellWindowId_LockSystemModalContainer), |
| 426 | controller->GetSystemModalLayoutManager( |
| 427 | WmLookup::Get()->GetWindowForWidget(login_modal_widget))); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 428 | login_modal_widget->Close(); |
| 429 | |
| 430 | // Configure user session environment. |
| 431 | SetUserLoggedIn(true); |
| 432 | SetSessionStarted(true); |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 433 | EXPECT_EQ(LoginStatus::USER, |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 434 | WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()); |
| 435 | EXPECT_EQ(1, session_state_delegate->NumberOfLoggedInUsers()); |
| 436 | EXPECT_TRUE(session_state_delegate->IsActiveUserSessionStarted()); |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 437 | EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer), |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 438 | controller->GetSystemModalLayoutManager(NULL)); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 439 | |
| 440 | views::Widget* session_modal_widget = |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 441 | CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 442 | EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer), |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 443 | controller->GetSystemModalLayoutManager( |
sky | ea4ca94 | 2016-09-12 21:56:19 | [diff] [blame] | 444 | WmLookup::Get()->GetWindowForWidget(session_modal_widget))); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 445 | } |
| 446 | |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 447 | TEST_F(RootWindowControllerTest, ModalContainerBlockedSession) { |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 448 | UpdateDisplay("600x600"); |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 449 | RootWindowController* controller = |
sky | ea4ca94 | 2016-09-12 21:56:19 | [diff] [blame] | 450 | WmShell::Get()->GetPrimaryRootWindowController(); |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 451 | aura::Window* lock_container = |
| 452 | controller->GetContainer(kShellWindowId_LockScreenContainer); |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 453 | for (int block_reason = FIRST_BLOCK_REASON; |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 454 | block_reason < NUMBER_OF_BLOCK_REASONS; ++block_reason) { |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 455 | views::Widget* session_modal_widget = |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 456 | CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 457 | EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer), |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 458 | controller->GetSystemModalLayoutManager( |
sky | ea4ca94 | 2016-09-12 21:56:19 | [diff] [blame] | 459 | WmLookup::Get()->GetWindowForWidget(session_modal_widget))); |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 460 | EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer), |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 461 | controller->GetSystemModalLayoutManager(NULL)); |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 462 | session_modal_widget->Close(); |
| 463 | |
| 464 | BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 465 | |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 466 | EXPECT_EQ( |
| 467 | GetLayoutManager(controller, kShellWindowId_LockSystemModalContainer), |
| 468 | controller->GetSystemModalLayoutManager(NULL)); |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 469 | |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 470 | views::Widget* lock_modal_widget = CreateModalWidgetWithParent( |
| 471 | gfx::Rect(300, 10, 100, 100), lock_container); |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 472 | EXPECT_EQ( |
| 473 | GetLayoutManager(controller, kShellWindowId_LockSystemModalContainer), |
| 474 | controller->GetSystemModalLayoutManager( |
| 475 | WmLookup::Get()->GetWindowForWidget(lock_modal_widget))); |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 476 | |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 477 | session_modal_widget = CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
sky | b664383 | 2017-01-11 22:08:45 | [diff] [blame] | 478 | EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer), |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 479 | controller->GetSystemModalLayoutManager( |
sky | ea4ca94 | 2016-09-12 21:56:19 | [diff] [blame] | 480 | WmLookup::Get()->GetWindowForWidget(session_modal_widget))); |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 481 | session_modal_widget->Close(); |
| 482 | |
| 483 | lock_modal_widget->Close(); |
| 484 | UnblockUserSession(); |
| 485 | } |
| 486 | } |
| 487 | |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 488 | TEST_F(RootWindowControllerTest, GetWindowForFullscreenMode) { |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 489 | UpdateDisplay("600x600"); |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 490 | RootWindowController* controller = Shell::GetPrimaryRootWindowController(); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 491 | |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 492 | Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 493 | w1->Maximize(); |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 494 | Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
| 495 | w2->SetFullscreen(true); |
| 496 | // |w3| is a transient child of |w2|. |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 497 | Widget* w3 = Widget::CreateWindowWithParentAndBounds( |
| 498 | NULL, w2->GetNativeWindow(), gfx::Rect(0, 0, 100, 100)); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 499 | |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 500 | // Test that GetWindowForFullscreenMode() finds the fullscreen window when one |
[email protected] | e3bc88e | 2013-09-06 06:22:06 | [diff] [blame] | 501 | // of its transient children is active. |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 502 | w3->Activate(); |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 503 | EXPECT_EQ(w2->GetNativeWindow(), controller->GetWindowForFullscreenMode()); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 504 | |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 505 | // If the topmost window is not fullscreen, it returns NULL. |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 506 | w1->Activate(); |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 507 | EXPECT_EQ(NULL, controller->GetWindowForFullscreenMode()); |
| 508 | w1->Close(); |
| 509 | w3->Close(); |
[email protected] | e3bc88e | 2013-09-06 06:22:06 | [diff] [blame] | 510 | |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 511 | // Only w2 remains, if minimized GetWindowForFullscreenMode should return |
| 512 | // NULL. |
[email protected] | e3bc88e | 2013-09-06 06:22:06 | [diff] [blame] | 513 | w2->Activate(); |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 514 | EXPECT_EQ(w2->GetNativeWindow(), controller->GetWindowForFullscreenMode()); |
| 515 | w2->Minimize(); |
| 516 | EXPECT_EQ(NULL, controller->GetWindowForFullscreenMode()); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 517 | } |
| 518 | |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 519 | TEST_F(RootWindowControllerTest, MultipleDisplaysGetWindowForFullscreenMode) { |
[email protected] | 2c5db9e | 2014-02-27 13:58:14 | [diff] [blame] | 520 | UpdateDisplay("600x600,600x600"); |
| 521 | Shell::RootWindowControllerList controllers = |
| 522 | Shell::GetInstance()->GetAllRootWindowControllers(); |
| 523 | |
| 524 | Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
| 525 | w1->Maximize(); |
| 526 | Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
| 527 | w2->SetFullscreen(true); |
| 528 | Widget* w3 = CreateTestWidget(gfx::Rect(600, 0, 100, 100)); |
| 529 | |
| 530 | EXPECT_EQ(w1->GetNativeWindow()->GetRootWindow(), |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 531 | controllers[0]->GetRootWindow()); |
[email protected] | 2c5db9e | 2014-02-27 13:58:14 | [diff] [blame] | 532 | EXPECT_EQ(w2->GetNativeWindow()->GetRootWindow(), |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 533 | controllers[0]->GetRootWindow()); |
[email protected] | 2c5db9e | 2014-02-27 13:58:14 | [diff] [blame] | 534 | EXPECT_EQ(w3->GetNativeWindow()->GetRootWindow(), |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 535 | controllers[1]->GetRootWindow()); |
[email protected] | 2c5db9e | 2014-02-27 13:58:14 | [diff] [blame] | 536 | |
| 537 | w1->Activate(); |
| 538 | EXPECT_EQ(NULL, controllers[0]->GetWindowForFullscreenMode()); |
| 539 | EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode()); |
| 540 | |
| 541 | w2->Activate(); |
| 542 | EXPECT_EQ(w2->GetNativeWindow(), |
| 543 | controllers[0]->GetWindowForFullscreenMode()); |
| 544 | EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode()); |
| 545 | |
| 546 | // Verify that the first root window controller remains in fullscreen mode |
| 547 | // when a window on the other display is activated. |
| 548 | w3->Activate(); |
| 549 | EXPECT_EQ(w2->GetNativeWindow(), |
| 550 | controllers[0]->GetWindowForFullscreenMode()); |
| 551 | EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode()); |
| 552 | } |
| 553 | |
jamescook | 5d74ac0 | 2016-05-12 19:57:12 | [diff] [blame] | 554 | // Test that GetRootWindowController() works with multiple displays and |
| 555 | // child widgets. |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 556 | TEST_F(RootWindowControllerTest, GetRootWindowController) { |
jamescook | 5d74ac0 | 2016-05-12 19:57:12 | [diff] [blame] | 557 | UpdateDisplay("600x600,600x600"); |
| 558 | Shell::RootWindowControllerList controllers = |
| 559 | Shell::GetInstance()->GetAllRootWindowControllers(); |
| 560 | ASSERT_EQ(2u, controllers.size()); |
| 561 | |
| 562 | // Test null. |
| 563 | EXPECT_FALSE(GetRootWindowController(nullptr)); |
| 564 | |
| 565 | // Test a widget on the first display. |
| 566 | Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
| 567 | EXPECT_EQ(controllers[0], |
| 568 | GetRootWindowController(w1->GetNativeWindow()->GetRootWindow())); |
| 569 | |
| 570 | // Test a child widget. |
| 571 | Widget* w2 = Widget::CreateWindowWithParentAndBounds( |
| 572 | nullptr, w1->GetNativeWindow(), gfx::Rect(0, 0, 100, 100)); |
| 573 | EXPECT_EQ(controllers[0], |
| 574 | GetRootWindowController(w2->GetNativeWindow()->GetRootWindow())); |
| 575 | |
| 576 | // Test a widget on the second display. |
| 577 | Widget* w3 = CreateTestWidget(gfx::Rect(600, 0, 100, 100)); |
| 578 | EXPECT_EQ(controllers[1], |
| 579 | GetRootWindowController(w3->GetNativeWindow()->GetRootWindow())); |
| 580 | } |
| 581 | |
[email protected] | 82ced235 | 2013-07-19 20:49:06 | [diff] [blame] | 582 | // Test that user session window can't be focused if user session blocked by |
| 583 | // some overlapping UI. |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 584 | TEST_F(RootWindowControllerTest, FocusBlockedWindow) { |
[email protected] | 82ced235 | 2013-07-19 20:49:06 | [diff] [blame] | 585 | UpdateDisplay("600x600"); |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 586 | RootWindowController* controller = Shell::GetPrimaryRootWindowController(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 587 | aura::Window* lock_container = |
| 588 | controller->GetContainer(kShellWindowId_LockScreenContainer); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 589 | aura::Window* lock_window = |
| 590 | Widget::CreateWindowWithParentAndBounds(NULL, lock_container, |
| 591 | gfx::Rect(0, 0, 100, 100)) |
| 592 | ->GetNativeView(); |
[email protected] | 82ced235 | 2013-07-19 20:49:06 | [diff] [blame] | 593 | lock_window->Show(); |
| 594 | aura::Window* session_window = |
| 595 | CreateTestWidget(gfx::Rect(0, 0, 100, 100))->GetNativeView(); |
| 596 | session_window->Show(); |
| 597 | |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 598 | for (int block_reason = FIRST_BLOCK_REASON; |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 599 | block_reason < NUMBER_OF_BLOCK_REASONS; ++block_reason) { |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 600 | BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 601 | lock_window->Focus(); |
| 602 | EXPECT_TRUE(lock_window->HasFocus()); |
| 603 | session_window->Focus(); |
| 604 | EXPECT_FALSE(session_window->HasFocus()); |
| 605 | UnblockUserSession(); |
| 606 | } |
[email protected] | 82ced235 | 2013-07-19 20:49:06 | [diff] [blame] | 607 | } |
| 608 | |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 609 | // Tracks whether OnWindowDestroying() has been invoked. |
| 610 | class DestroyedWindowObserver : public aura::WindowObserver { |
| 611 | public: |
| 612 | DestroyedWindowObserver() : destroyed_(false), window_(NULL) {} |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 613 | ~DestroyedWindowObserver() override { Shutdown(); } |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 614 | |
| 615 | void SetWindow(Window* window) { |
| 616 | window_ = window; |
| 617 | window->AddObserver(this); |
| 618 | } |
| 619 | |
| 620 | bool destroyed() const { return destroyed_; } |
| 621 | |
| 622 | // WindowObserver overrides: |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 623 | void OnWindowDestroying(Window* window) override { |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 624 | destroyed_ = true; |
| 625 | Shutdown(); |
| 626 | } |
| 627 | |
| 628 | private: |
| 629 | void Shutdown() { |
| 630 | if (!window_) |
| 631 | return; |
| 632 | window_->RemoveObserver(this); |
| 633 | window_ = NULL; |
| 634 | } |
| 635 | |
| 636 | bool destroyed_; |
| 637 | Window* window_; |
| 638 | |
| 639 | DISALLOW_COPY_AND_ASSIGN(DestroyedWindowObserver); |
| 640 | }; |
| 641 | |
| 642 | // Verifies shutdown doesn't delete windows that are not owned by the parent. |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 643 | TEST_F(RootWindowControllerTest, DontDeleteWindowsNotOwnedByParent) { |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 644 | DestroyedWindowObserver observer1; |
| 645 | aura::test::TestWindowDelegate delegate1; |
| 646 | aura::Window* window1 = new aura::Window(&delegate1); |
[email protected] | 5b251f1 | 2013-12-19 01:50:05 | [diff] [blame] | 647 | window1->SetType(ui::wm::WINDOW_TYPE_CONTROL); |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 648 | window1->set_owned_by_parent(false); |
| 649 | observer1.SetWindow(window1); |
danakj | b161836d | 2015-04-03 05:14:18 | [diff] [blame] | 650 | window1->Init(ui::LAYER_NOT_DRAWN); |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 651 | aura::client::ParentWindowWithContext( |
| 652 | window1, Shell::GetInstance()->GetPrimaryRootWindow(), gfx::Rect()); |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 653 | |
| 654 | DestroyedWindowObserver observer2; |
| 655 | aura::Window* window2 = new aura::Window(NULL); |
| 656 | window2->set_owned_by_parent(false); |
| 657 | observer2.SetWindow(window2); |
danakj | b161836d | 2015-04-03 05:14:18 | [diff] [blame] | 658 | window2->Init(ui::LAYER_NOT_DRAWN); |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 659 | Shell::GetInstance()->GetPrimaryRootWindow()->AddChild(window2); |
| 660 | |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 661 | Shell::GetPrimaryRootWindowController()->CloseChildWindows(); |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 662 | |
| 663 | ASSERT_FALSE(observer1.destroyed()); |
| 664 | delete window1; |
| 665 | |
| 666 | ASSERT_FALSE(observer2.destroyed()); |
| 667 | delete window2; |
| 668 | } |
| 669 | |
[email protected] | 24f5e24 | 2014-07-22 02:16:09 | [diff] [blame] | 670 | class VirtualKeyboardRootWindowControllerTest |
| 671 | : public RootWindowControllerTest { |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 672 | public: |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 673 | VirtualKeyboardRootWindowControllerTest() {} |
| 674 | ~VirtualKeyboardRootWindowControllerTest() override {} |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 675 | |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 676 | void SetUp() override { |
pgal.u-szeged | d84534d3 | 2014-10-29 12:34:30 | [diff] [blame] | 677 | base::CommandLine::ForCurrentProcess()->AppendSwitch( |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 678 | keyboard::switches::kEnableVirtualKeyboard); |
| 679 | test::AshTestBase::SetUp(); |
yhanada | 7e20c9b | 2016-11-25 00:03:19 | [diff] [blame] | 680 | keyboard::SetTouchKeyboardEnabled(true); |
| 681 | Shell::GetInstance()->CreateKeyboard(); |
| 682 | } |
| 683 | |
| 684 | void TearDown() override { |
| 685 | keyboard::SetTouchKeyboardEnabled(false); |
| 686 | test::AshTestBase::TearDown(); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | private: |
| 690 | DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest); |
| 691 | }; |
| 692 | |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 693 | class MockTextInputClient : public ui::DummyTextInputClient { |
| 694 | public: |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 695 | MockTextInputClient() : ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT) {} |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 696 | |
yhanada | 0ddd346 | 2016-12-08 05:04:18 | [diff] [blame] | 697 | void EnsureCaretNotInRect(const gfx::Rect& rect) override { |
| 698 | caret_exclude_rect_ = rect; |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 699 | } |
| 700 | |
yhanada | 0ddd346 | 2016-12-08 05:04:18 | [diff] [blame] | 701 | const gfx::Rect& caret_exclude_rect() const { return caret_exclude_rect_; } |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 702 | |
| 703 | private: |
yhanada | 0ddd346 | 2016-12-08 05:04:18 | [diff] [blame] | 704 | gfx::Rect caret_exclude_rect_; |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 705 | |
| 706 | DISALLOW_COPY_AND_ASSIGN(MockTextInputClient); |
| 707 | }; |
| 708 | |
kevers | 23f3987d | 2014-09-17 13:50:12 | [diff] [blame] | 709 | class TargetHitTestEventHandler : public ui::test::TestEventHandler { |
| 710 | public: |
| 711 | TargetHitTestEventHandler() {} |
| 712 | |
| 713 | // ui::test::TestEventHandler overrides. |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 714 | void OnMouseEvent(ui::MouseEvent* event) override { |
kevers | 23f3987d | 2014-09-17 13:50:12 | [diff] [blame] | 715 | if (event->type() == ui::ET_MOUSE_PRESSED) |
| 716 | ui::test::TestEventHandler::OnMouseEvent(event); |
| 717 | event->StopPropagation(); |
| 718 | } |
| 719 | |
| 720 | private: |
| 721 | DISALLOW_COPY_AND_ASSIGN(TargetHitTestEventHandler); |
| 722 | }; |
| 723 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 724 | // Test for http://crbug.com/297858. Virtual keyboard container should only show |
yhanada | 7e20c9b | 2016-11-25 00:03:19 | [diff] [blame] | 725 | // on primary root window if no window has touch capability. |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 726 | TEST_F(VirtualKeyboardRootWindowControllerTest, |
yhanada | 7e20c9b | 2016-11-25 00:03:19 | [diff] [blame] | 727 | VirtualKeyboardOnPrimaryRootWindowDefault) { |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 728 | UpdateDisplay("500x500,500x500"); |
| 729 | |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 730 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 731 | aura::Window* primary_root_window = Shell::GetPrimaryRootWindow(); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 732 | aura::Window* secondary_root_window = root_windows[0] == primary_root_window |
| 733 | ? root_windows[1] |
| 734 | : root_windows[0]; |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 735 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 736 | ASSERT_TRUE(Shell::GetContainer(primary_root_window, |
| 737 | kShellWindowId_VirtualKeyboardContainer)); |
| 738 | ASSERT_FALSE(Shell::GetContainer(secondary_root_window, |
| 739 | kShellWindowId_VirtualKeyboardContainer)); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 740 | } |
| 741 | |
yhanada | 7e20c9b | 2016-11-25 00:03:19 | [diff] [blame] | 742 | // Test for http://crbug.com/303429. Virtual keyboard container should show on |
| 743 | // a display which has touch capability. |
| 744 | TEST_F(VirtualKeyboardRootWindowControllerTest, |
| 745 | VirtualKeyboardOnTouchableDisplayOnly) { |
yhanada | 7e20c9b | 2016-11-25 00:03:19 | [diff] [blame] | 746 | UpdateDisplay("500x500,500x500"); |
| 747 | display::Display secondary_display = |
| 748 | Shell::GetInstance()->display_manager()->GetSecondaryDisplay(); |
| 749 | display::test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()) |
| 750 | .SetTouchSupport(secondary_display.id(), |
| 751 | display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE); |
| 752 | |
| 753 | // The primary display doesn't have touch capability and the secondary display |
| 754 | // does. |
| 755 | ASSERT_NE(display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE, |
| 756 | display::Screen::GetScreen()->GetPrimaryDisplay().touch_support()); |
| 757 | ASSERT_EQ(display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE, |
| 758 | Shell::GetInstance() |
| 759 | ->display_manager() |
| 760 | ->GetSecondaryDisplay() |
| 761 | .touch_support()); |
| 762 | |
| 763 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 764 | aura::Window* primary_root_window = Shell::GetPrimaryRootWindow(); |
| 765 | aura::Window* secondary_root_window = root_windows[0] == primary_root_window |
| 766 | ? root_windows[1] |
| 767 | : root_windows[0]; |
| 768 | |
| 769 | keyboard::KeyboardController::GetInstance()->ShowKeyboard(false); |
| 770 | ASSERT_FALSE(Shell::GetContainer(primary_root_window, |
| 771 | kShellWindowId_VirtualKeyboardContainer)); |
| 772 | ASSERT_TRUE(Shell::GetContainer(secondary_root_window, |
| 773 | kShellWindowId_VirtualKeyboardContainer)); |
| 774 | |
| 775 | // Move the focus to the primary display. |
| 776 | aura::Window* focusable_window_in_primary_display = |
| 777 | CreateTestWindowInShellWithBounds( |
| 778 | primary_root_window->GetBoundsInScreen()); |
| 779 | ASSERT_EQ(primary_root_window, |
| 780 | focusable_window_in_primary_display->GetRootWindow()); |
| 781 | focusable_window_in_primary_display->Focus(); |
| 782 | ASSERT_TRUE(focusable_window_in_primary_display->HasFocus()); |
| 783 | |
| 784 | // Virtual keyboard shows up on the secondary display even if a window in the |
| 785 | // primary screen has the focus. |
| 786 | keyboard::KeyboardController::GetInstance()->ShowKeyboard(false); |
| 787 | EXPECT_FALSE(Shell::GetContainer(primary_root_window, |
| 788 | kShellWindowId_VirtualKeyboardContainer)); |
| 789 | EXPECT_TRUE(Shell::GetContainer(secondary_root_window, |
| 790 | kShellWindowId_VirtualKeyboardContainer)); |
| 791 | } |
| 792 | |
| 793 | // Test for http://crbug.com/303429. If both of displays have touch capability, |
| 794 | // virtual keyboard follows the input focus. |
| 795 | TEST_F(VirtualKeyboardRootWindowControllerTest, FollowInputFocus) { |
yhanada | 7e20c9b | 2016-11-25 00:03:19 | [diff] [blame] | 796 | UpdateDisplay("500x500,500x500"); |
| 797 | const int64_t primary_display_id = |
| 798 | display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 799 | display::test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()) |
| 800 | .SetTouchSupport(primary_display_id, |
| 801 | display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE); |
| 802 | const int64_t secondary_display_id = |
| 803 | Shell::GetInstance()->display_manager()->GetSecondaryDisplay().id(); |
| 804 | display::test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()) |
| 805 | .SetTouchSupport(secondary_display_id, |
| 806 | display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE); |
| 807 | |
| 808 | // Both of displays have touch capability. |
| 809 | ASSERT_EQ(display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE, |
| 810 | display::Screen::GetScreen()->GetPrimaryDisplay().touch_support()); |
| 811 | ASSERT_EQ(display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE, |
| 812 | Shell::GetInstance() |
| 813 | ->display_manager() |
| 814 | ->GetSecondaryDisplay() |
| 815 | .touch_support()); |
| 816 | |
| 817 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 818 | aura::Window* primary_root_window = Shell::GetPrimaryRootWindow(); |
| 819 | aura::Window* secondary_root_window = root_windows[0] == primary_root_window |
| 820 | ? root_windows[1] |
| 821 | : root_windows[0]; |
| 822 | aura::Window* focusable_window_in_primary_display = |
| 823 | CreateTestWindowInShellWithBounds( |
| 824 | primary_root_window->GetBoundsInScreen()); |
| 825 | ASSERT_EQ(primary_root_window, |
| 826 | focusable_window_in_primary_display->GetRootWindow()); |
| 827 | aura::Window* focusable_window_in_secondary_display = |
| 828 | CreateTestWindowInShellWithBounds( |
| 829 | secondary_root_window->GetBoundsInScreen()); |
| 830 | ASSERT_EQ(secondary_root_window, |
| 831 | focusable_window_in_secondary_display->GetRootWindow()); |
| 832 | |
| 833 | keyboard::KeyboardController::GetInstance()->ShowKeyboard(false); |
| 834 | EXPECT_TRUE(Shell::GetContainer(primary_root_window, |
| 835 | kShellWindowId_VirtualKeyboardContainer)); |
| 836 | EXPECT_FALSE(Shell::GetContainer(secondary_root_window, |
| 837 | kShellWindowId_VirtualKeyboardContainer)); |
| 838 | |
| 839 | // Move the focus to the secondary display. |
| 840 | focusable_window_in_secondary_display->Focus(); |
| 841 | ASSERT_TRUE(focusable_window_in_secondary_display->HasFocus()); |
| 842 | |
| 843 | keyboard::KeyboardController::GetInstance()->ShowKeyboard(false); |
| 844 | ASSERT_FALSE(Shell::GetContainer(primary_root_window, |
| 845 | kShellWindowId_VirtualKeyboardContainer)); |
| 846 | ASSERT_TRUE(Shell::GetContainer(secondary_root_window, |
| 847 | kShellWindowId_VirtualKeyboardContainer)); |
| 848 | |
| 849 | // Move back focus to the primary display. |
| 850 | focusable_window_in_primary_display->Focus(); |
| 851 | ASSERT_TRUE(focusable_window_in_primary_display->HasFocus()); |
| 852 | |
| 853 | keyboard::KeyboardController::GetInstance()->ShowKeyboard(false); |
| 854 | EXPECT_TRUE(Shell::GetContainer(primary_root_window, |
| 855 | kShellWindowId_VirtualKeyboardContainer)); |
| 856 | EXPECT_FALSE(Shell::GetContainer(secondary_root_window, |
| 857 | kShellWindowId_VirtualKeyboardContainer)); |
| 858 | } |
| 859 | |
| 860 | // Test for http://crbug.com/303429. Even if both of display don't have touch |
| 861 | // capability, the virtual keyboard shows up on the specified display. |
| 862 | TEST_F(VirtualKeyboardRootWindowControllerTest, |
| 863 | VirtualKeyboardShowOnSpecifiedDisplay) { |
yhanada | 7e20c9b | 2016-11-25 00:03:19 | [diff] [blame] | 864 | UpdateDisplay("500x500,500x500"); |
| 865 | display::Display secondary_display = |
| 866 | Shell::GetInstance()->display_manager()->GetSecondaryDisplay(); |
| 867 | |
| 868 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 869 | aura::Window* primary_root_window = Shell::GetPrimaryRootWindow(); |
| 870 | aura::Window* secondary_root_window = root_windows[0] == primary_root_window |
| 871 | ? root_windows[1] |
| 872 | : root_windows[0]; |
| 873 | |
| 874 | ASSERT_TRUE(Shell::GetContainer(primary_root_window, |
| 875 | kShellWindowId_VirtualKeyboardContainer)); |
| 876 | ASSERT_FALSE(Shell::GetContainer(secondary_root_window, |
| 877 | kShellWindowId_VirtualKeyboardContainer)); |
| 878 | |
| 879 | const int64_t secondary_display_id = secondary_display.id(); |
| 880 | keyboard::KeyboardController::GetInstance()->ShowKeyboardInDisplay( |
| 881 | secondary_display_id); |
| 882 | |
| 883 | EXPECT_FALSE(Shell::GetContainer(primary_root_window, |
| 884 | kShellWindowId_VirtualKeyboardContainer)); |
| 885 | EXPECT_TRUE(Shell::GetContainer(secondary_root_window, |
| 886 | kShellWindowId_VirtualKeyboardContainer)); |
| 887 | } |
| 888 | |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 889 | // Test for http://crbug.com/263599. Virtual keyboard should be able to receive |
| 890 | // events at blocked user session. |
| 891 | TEST_F(VirtualKeyboardRootWindowControllerTest, |
| 892 | ClickVirtualKeyboardInBlockedWindow) { |
[email protected] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 893 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 894 | aura::Window* keyboard_container = |
| 895 | Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 896 | ASSERT_TRUE(keyboard_container); |
| 897 | keyboard_container->Show(); |
| 898 | |
ben | 974286a | 2015-10-10 00:45:12 | [diff] [blame] | 899 | aura::Window* keyboard_window = |
| 900 | keyboard::KeyboardController::GetInstance()->ui()->GetKeyboardWindow(); |
[email protected] | 647b484 | 2013-12-12 14:24:24 | [diff] [blame] | 901 | keyboard_container->AddChild(keyboard_window); |
[email protected] | 183e28d | 2014-01-20 18:18:02 | [diff] [blame] | 902 | keyboard_window->set_owned_by_parent(false); |
[email protected] | 647b484 | 2013-12-12 14:24:24 | [diff] [blame] | 903 | keyboard_window->SetBounds(gfx::Rect()); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 904 | keyboard_window->Show(); |
[email protected] | 647b484 | 2013-12-12 14:24:24 | [diff] [blame] | 905 | |
[email protected] | 3193ea72 | 2014-04-23 22:19:19 | [diff] [blame] | 906 | ui::test::TestEventHandler handler; |
| 907 | root_window->AddPreTargetHandler(&handler); |
[email protected] | 647b484 | 2013-12-12 14:24:24 | [diff] [blame] | 908 | |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 909 | ui::test::EventGenerator event_generator(root_window, keyboard_window); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 910 | event_generator.ClickLeftButton(); |
| 911 | int expected_mouse_presses = 1; |
[email protected] | 3193ea72 | 2014-04-23 22:19:19 | [diff] [blame] | 912 | EXPECT_EQ(expected_mouse_presses, handler.num_mouse_events() / 2); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 913 | |
| 914 | for (int block_reason = FIRST_BLOCK_REASON; |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 915 | block_reason < NUMBER_OF_BLOCK_REASONS; ++block_reason) { |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 916 | BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 917 | event_generator.ClickLeftButton(); |
| 918 | expected_mouse_presses++; |
[email protected] | 3193ea72 | 2014-04-23 22:19:19 | [diff] [blame] | 919 | EXPECT_EQ(expected_mouse_presses, handler.num_mouse_events() / 2); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 920 | UnblockUserSession(); |
| 921 | } |
[email protected] | 3193ea72 | 2014-04-23 22:19:19 | [diff] [blame] | 922 | root_window->RemovePreTargetHandler(&handler); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 923 | } |
| 924 | |
[email protected] | 45c6667 | 2013-10-01 22:48:56 | [diff] [blame] | 925 | // Test for http://crbug.com/299787. RootWindowController should delete |
| 926 | // the old container since the keyboard controller creates a new window in |
| 927 | // GetWindowContainer(). |
| 928 | TEST_F(VirtualKeyboardRootWindowControllerTest, |
| 929 | DeleteOldContainerOnVirtualKeyboardInit) { |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 930 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 931 | aura::Window* keyboard_container = |
| 932 | Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
[email protected] | 45c6667 | 2013-10-01 22:48:56 | [diff] [blame] | 933 | ASSERT_TRUE(keyboard_container); |
| 934 | // Track the keyboard container window. |
| 935 | aura::WindowTracker tracker; |
| 936 | tracker.Add(keyboard_container); |
jamescook | e3d63f6 | 2017-01-12 07:12:40 | [diff] [blame] | 937 | // Reinitialize the keyboard. |
| 938 | Shell::GetInstance()->CreateKeyboard(); |
[email protected] | 45c6667 | 2013-10-01 22:48:56 | [diff] [blame] | 939 | // keyboard_container should no longer be present. |
| 940 | EXPECT_FALSE(tracker.Contains(keyboard_container)); |
| 941 | } |
| 942 | |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 943 | // Test for crbug.com/342524. After user login, the work space should restore to |
| 944 | // full screen. |
| 945 | TEST_F(VirtualKeyboardRootWindowControllerTest, RestoreWorkspaceAfterLogin) { |
| 946 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 947 | aura::Window* keyboard_container = |
| 948 | Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 949 | keyboard_container->Show(); |
| 950 | keyboard::KeyboardController* controller = |
[email protected] | a0b3fb88 | 2014-04-07 19:26:03 | [diff] [blame] | 951 | keyboard::KeyboardController::GetInstance(); |
ben | 974286a | 2015-10-10 00:45:12 | [diff] [blame] | 952 | aura::Window* keyboard_window = controller->ui()->GetKeyboardWindow(); |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 953 | keyboard_container->AddChild(keyboard_window); |
| 954 | keyboard_window->set_owned_by_parent(false); |
bshe | a0a5780 | 2015-04-08 18:21:29 | [diff] [blame] | 955 | keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds( |
| 956 | root_window->bounds(), 100)); |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 957 | keyboard_window->Show(); |
| 958 | |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 959 | gfx::Rect before = |
| 960 | display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 961 | |
| 962 | // Notify keyboard bounds changing. |
bshe | a0a5780 | 2015-04-08 18:21:29 | [diff] [blame] | 963 | controller->NotifyKeyboardBoundsChanging(keyboard_container->bounds()); |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 964 | |
[email protected] | 25df7ad | 2014-04-30 18:10:25 | [diff] [blame] | 965 | if (!keyboard::IsKeyboardOverscrollEnabled()) { |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 966 | gfx::Rect after = |
| 967 | display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
[email protected] | 25df7ad | 2014-04-30 18:10:25 | [diff] [blame] | 968 | EXPECT_LT(after, before); |
| 969 | } |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 970 | |
| 971 | // Mock a login user profile change to reinitialize the keyboard. |
jamescook | e3d63f6 | 2017-01-12 07:12:40 | [diff] [blame] | 972 | mojom::SessionInfoPtr info = mojom::SessionInfo::New(); |
| 973 | info->state = session_manager::SessionState::ACTIVE; |
| 974 | WmShell::Get()->session_controller()->SetSessionInfo(std::move(info)); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 975 | EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().work_area(), |
| 976 | before); |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 977 | } |
| 978 | |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 979 | // Ensure that system modal dialogs do not block events targeted at the virtual |
| 980 | // keyboard. |
| 981 | TEST_F(VirtualKeyboardRootWindowControllerTest, ClickWithActiveModalDialog) { |
| 982 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 983 | aura::Window* keyboard_container = |
| 984 | Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 985 | ASSERT_TRUE(keyboard_container); |
| 986 | keyboard_container->Show(); |
| 987 | |
ben | 974286a | 2015-10-10 00:45:12 | [diff] [blame] | 988 | aura::Window* keyboard_window = |
| 989 | keyboard::KeyboardController::GetInstance()->ui()->GetKeyboardWindow(); |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 990 | keyboard_container->AddChild(keyboard_window); |
| 991 | keyboard_window->set_owned_by_parent(false); |
bshe | a0a5780 | 2015-04-08 18:21:29 | [diff] [blame] | 992 | keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds( |
| 993 | root_window->bounds(), 100)); |
[email protected] | 3193ea72 | 2014-04-23 22:19:19 | [diff] [blame] | 994 | |
| 995 | ui::test::TestEventHandler handler; |
| 996 | root_window->AddPreTargetHandler(&handler); |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 997 | ui::test::EventGenerator root_window_event_generator(root_window); |
| 998 | ui::test::EventGenerator keyboard_event_generator(root_window, |
| 999 | keyboard_window); |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 1000 | |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 1001 | views::Widget* modal_widget = CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 1002 | |
| 1003 | // Verify that mouse events to the root window are block with a visble modal |
| 1004 | // dialog. |
| 1005 | root_window_event_generator.ClickLeftButton(); |
[email protected] | 3193ea72 | 2014-04-23 22:19:19 | [diff] [blame] | 1006 | EXPECT_EQ(0, handler.num_mouse_events()); |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 1007 | |
| 1008 | // Verify that event dispatch to the virtual keyboard is unblocked. |
| 1009 | keyboard_event_generator.ClickLeftButton(); |
[email protected] | 3193ea72 | 2014-04-23 22:19:19 | [diff] [blame] | 1010 | EXPECT_EQ(1, handler.num_mouse_events() / 2); |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 1011 | |
| 1012 | modal_widget->Close(); |
| 1013 | |
| 1014 | // Verify that mouse events are now unblocked to the root window. |
| 1015 | root_window_event_generator.ClickLeftButton(); |
[email protected] | 3193ea72 | 2014-04-23 22:19:19 | [diff] [blame] | 1016 | EXPECT_EQ(2, handler.num_mouse_events() / 2); |
| 1017 | root_window->RemovePreTargetHandler(&handler); |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 1018 | } |
| 1019 | |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 1020 | // Ensure that the visible area for scrolling the text caret excludes the |
| 1021 | // region occluded by the on-screen keyboard. |
| 1022 | TEST_F(VirtualKeyboardRootWindowControllerTest, EnsureCaretInWorkArea) { |
| 1023 | keyboard::KeyboardController* keyboard_controller = |
| 1024 | keyboard::KeyboardController::GetInstance(); |
ben | 974286a | 2015-10-10 00:45:12 | [diff] [blame] | 1025 | keyboard::KeyboardUI* ui = keyboard_controller->ui(); |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 1026 | |
| 1027 | MockTextInputClient text_input_client; |
ben | 974286a | 2015-10-10 00:45:12 | [diff] [blame] | 1028 | ui::InputMethod* input_method = ui->GetInputMethod(); |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 1029 | ASSERT_TRUE(input_method); |
shuchen | 4e09795a | 2015-06-15 15:07:20 | [diff] [blame] | 1030 | input_method->SetFocusedTextInputClient(&text_input_client); |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 1031 | |
| 1032 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 1033 | aura::Window* keyboard_container = |
| 1034 | Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
| 1035 | ASSERT_TRUE(keyboard_container); |
| 1036 | keyboard_container->Show(); |
| 1037 | |
| 1038 | const int keyboard_height = 100; |
ben | 974286a | 2015-10-10 00:45:12 | [diff] [blame] | 1039 | aura::Window* keyboard_window = ui->GetKeyboardWindow(); |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 1040 | keyboard_container->AddChild(keyboard_window); |
| 1041 | keyboard_window->set_owned_by_parent(false); |
bshe | a0a5780 | 2015-04-08 18:21:29 | [diff] [blame] | 1042 | keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds( |
| 1043 | root_window->bounds(), keyboard_height)); |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 1044 | |
ben | 974286a | 2015-10-10 00:45:12 | [diff] [blame] | 1045 | ui->EnsureCaretInWorkArea(); |
bshe | a0a5780 | 2015-04-08 18:21:29 | [diff] [blame] | 1046 | ASSERT_EQ(root_window->bounds().width(), |
yhanada | 0ddd346 | 2016-12-08 05:04:18 | [diff] [blame] | 1047 | text_input_client.caret_exclude_rect().width()); |
| 1048 | ASSERT_EQ(keyboard_height, text_input_client.caret_exclude_rect().height()); |
[email protected] | 00a38679 | 2014-06-16 15:09:20 | [diff] [blame] | 1049 | |
shuchen | 4e09795a | 2015-06-15 15:07:20 | [diff] [blame] | 1050 | input_method->SetFocusedTextInputClient(NULL); |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 1051 | } |
| 1052 | |
yhanada | 0ddd346 | 2016-12-08 05:04:18 | [diff] [blame] | 1053 | TEST_F(VirtualKeyboardRootWindowControllerTest, |
| 1054 | EnsureCaretInWorkAreaWithMultipleDisplays) { |
yhanada | 0ddd346 | 2016-12-08 05:04:18 | [diff] [blame] | 1055 | UpdateDisplay("500x500,600x600"); |
| 1056 | const int64_t primary_display_id = |
| 1057 | display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 1058 | const int64_t secondary_display_id = |
| 1059 | Shell::GetInstance()->display_manager()->GetSecondaryDisplay().id(); |
| 1060 | ASSERT_NE(primary_display_id, secondary_display_id); |
| 1061 | |
| 1062 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 1063 | ASSERT_EQ(static_cast<size_t>(2), root_windows.size()); |
| 1064 | aura::Window* primary_root_window = root_windows[0]; |
| 1065 | aura::Window* secondary_root_window = root_windows[1]; |
| 1066 | |
| 1067 | keyboard::KeyboardController* keyboard_controller = |
| 1068 | keyboard::KeyboardController::GetInstance(); |
| 1069 | keyboard::KeyboardUI* ui = keyboard_controller->ui(); |
| 1070 | |
| 1071 | MockTextInputClient text_input_client; |
| 1072 | ui::InputMethod* input_method = ui->GetInputMethod(); |
| 1073 | ASSERT_TRUE(input_method); |
| 1074 | input_method->SetFocusedTextInputClient(&text_input_client); |
| 1075 | |
| 1076 | const int keyboard_height = 100; |
| 1077 | // Check that the keyboard on the primary screen doesn't cover the window on |
| 1078 | // the secondary screen. |
| 1079 | aura::Window* keyboard_container = Shell::GetContainer( |
| 1080 | primary_root_window, kShellWindowId_VirtualKeyboardContainer); |
| 1081 | ASSERT_TRUE(keyboard_container); |
| 1082 | keyboard_container->Show(); |
| 1083 | aura::Window* keyboard_window = ui->GetKeyboardWindow(); |
| 1084 | keyboard_container->AddChild(keyboard_window); |
| 1085 | keyboard_window->set_owned_by_parent(false); |
| 1086 | keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds( |
| 1087 | primary_root_window->bounds(), keyboard_height)); |
| 1088 | |
| 1089 | EXPECT_TRUE(primary_root_window->GetBoundsInScreen().Contains( |
| 1090 | text_input_client.caret_exclude_rect())); |
| 1091 | EXPECT_FALSE(secondary_root_window->GetBoundsInScreen().Contains( |
| 1092 | text_input_client.caret_exclude_rect())); |
| 1093 | |
| 1094 | // Move the keyboard into the secondary display and check that the keyboard |
| 1095 | // doesn't cover the window on the primary screen. |
| 1096 | keyboard_controller->ShowKeyboardInDisplay(secondary_display_id); |
| 1097 | keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds( |
| 1098 | secondary_root_window->bounds(), keyboard_height)); |
| 1099 | |
| 1100 | ui->EnsureCaretInWorkArea(); |
| 1101 | EXPECT_FALSE(primary_root_window->GetBoundsInScreen().Contains( |
| 1102 | text_input_client.caret_exclude_rect())); |
| 1103 | EXPECT_TRUE(secondary_root_window->GetBoundsInScreen().Contains( |
| 1104 | text_input_client.caret_exclude_rect())); |
| 1105 | |
| 1106 | input_method->SetFocusedTextInputClient(nullptr); |
| 1107 | } |
| 1108 | |
kevers | 23f3987d | 2014-09-17 13:50:12 | [diff] [blame] | 1109 | // Tests that the virtual keyboard does not block context menus. The virtual |
| 1110 | // keyboard should appear in front of most content, but not context menus. See |
| 1111 | // crbug/377180. |
| 1112 | TEST_F(VirtualKeyboardRootWindowControllerTest, ZOrderTest) { |
| 1113 | UpdateDisplay("800x600"); |
| 1114 | keyboard::KeyboardController* keyboard_controller = |
| 1115 | keyboard::KeyboardController::GetInstance(); |
ben | 974286a | 2015-10-10 00:45:12 | [diff] [blame] | 1116 | keyboard::KeyboardUI* ui = keyboard_controller->ui(); |
kevers | 23f3987d | 2014-09-17 13:50:12 | [diff] [blame] | 1117 | |
| 1118 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 1119 | aura::Window* keyboard_container = |
| 1120 | Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
| 1121 | ASSERT_TRUE(keyboard_container); |
| 1122 | keyboard_container->Show(); |
| 1123 | |
| 1124 | const int keyboard_height = 200; |
ben | 974286a | 2015-10-10 00:45:12 | [diff] [blame] | 1125 | aura::Window* keyboard_window = ui->GetKeyboardWindow(); |
kevers | 23f3987d | 2014-09-17 13:50:12 | [diff] [blame] | 1126 | keyboard_container->AddChild(keyboard_window); |
| 1127 | keyboard_window->set_owned_by_parent(false); |
bshe | a0a5780 | 2015-04-08 18:21:29 | [diff] [blame] | 1128 | gfx::Rect keyboard_bounds = keyboard::FullWidthKeyboardBoundsFromRootBounds( |
| 1129 | root_window->bounds(), keyboard_height); |
kevers | 23f3987d | 2014-09-17 13:50:12 | [diff] [blame] | 1130 | keyboard_window->SetBounds(keyboard_bounds); |
| 1131 | keyboard_window->Show(); |
| 1132 | |
| 1133 | ui::test::EventGenerator generator(root_window); |
| 1134 | |
| 1135 | // Cover the screen with two windows: a normal window on the left side and a |
| 1136 | // context menu on the right side. When the virtual keyboard is displayed it |
| 1137 | // partially occludes the normal window, but not the context menu. Compute |
| 1138 | // positions for generating synthetic click events to perform hit tests, |
| 1139 | // ensuring the correct window layering. 'top' is above the VK, whereas |
| 1140 | // 'bottom' lies within the VK. 'left' is centered in the normal window, and |
| 1141 | // 'right' is centered in the context menu. |
| 1142 | int window_height = keyboard_bounds.bottom(); |
| 1143 | int window_width = keyboard_bounds.width() / 2; |
| 1144 | int left = window_width / 2; |
| 1145 | int right = 3 * window_width / 2; |
| 1146 | int top = keyboard_bounds.y() / 2; |
| 1147 | int bottom = window_height - keyboard_height / 2; |
| 1148 | |
| 1149 | // Normal window is partially occluded by the virtual keyboard. |
| 1150 | aura::test::TestWindowDelegate delegate; |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 1151 | std::unique_ptr<aura::Window> normal( |
| 1152 | CreateTestWindowInShellWithDelegateAndType( |
| 1153 | &delegate, ui::wm::WINDOW_TYPE_NORMAL, 0, |
| 1154 | gfx::Rect(0, 0, window_width, window_height))); |
kevers | 23f3987d | 2014-09-17 13:50:12 | [diff] [blame] | 1155 | normal->set_owned_by_parent(false); |
| 1156 | normal->Show(); |
| 1157 | TargetHitTestEventHandler normal_handler; |
| 1158 | normal->AddPreTargetHandler(&normal_handler); |
| 1159 | |
| 1160 | // Test that only the click on the top portion of the window is picked up. The |
| 1161 | // click on the bottom hits the virtual keyboard instead. |
| 1162 | generator.MoveMouseTo(left, top); |
| 1163 | generator.ClickLeftButton(); |
| 1164 | EXPECT_EQ(1, normal_handler.num_mouse_events()); |
| 1165 | generator.MoveMouseTo(left, bottom); |
| 1166 | generator.ClickLeftButton(); |
| 1167 | EXPECT_EQ(1, normal_handler.num_mouse_events()); |
| 1168 | |
| 1169 | // Menu overlaps virtual keyboard. |
| 1170 | aura::test::TestWindowDelegate delegate2; |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 1171 | std::unique_ptr<aura::Window> menu(CreateTestWindowInShellWithDelegateAndType( |
| 1172 | &delegate2, ui::wm::WINDOW_TYPE_MENU, 0, |
kevers | 23f3987d | 2014-09-17 13:50:12 | [diff] [blame] | 1173 | gfx::Rect(window_width, 0, window_width, window_height))); |
| 1174 | menu->set_owned_by_parent(false); |
| 1175 | menu->Show(); |
| 1176 | TargetHitTestEventHandler menu_handler; |
| 1177 | menu->AddPreTargetHandler(&menu_handler); |
| 1178 | |
| 1179 | // Test that both clicks register. |
| 1180 | generator.MoveMouseTo(right, top); |
| 1181 | generator.ClickLeftButton(); |
| 1182 | EXPECT_EQ(1, menu_handler.num_mouse_events()); |
| 1183 | generator.MoveMouseTo(right, bottom); |
| 1184 | generator.ClickLeftButton(); |
| 1185 | EXPECT_EQ(2, menu_handler.num_mouse_events()); |
| 1186 | |
| 1187 | // Cleanup to ensure that the test windows are destroyed before their |
| 1188 | // delegates. |
| 1189 | normal.reset(); |
| 1190 | menu.reset(); |
| 1191 | } |
| 1192 | |
kevers | 0e45049 | 2014-09-30 16:02:31 | [diff] [blame] | 1193 | // Tests that the virtual keyboard correctly resizes with a change to display |
| 1194 | // orientation. See crbug/417612. |
jamescook | 01bf23e7 | 2017-01-09 19:58:15 | [diff] [blame] | 1195 | TEST_F(VirtualKeyboardRootWindowControllerTest, DisplayRotation) { |
kevers | 0e45049 | 2014-09-30 16:02:31 | [diff] [blame] | 1196 | UpdateDisplay("800x600"); |
| 1197 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 1198 | aura::Window* keyboard_container = |
| 1199 | Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
| 1200 | ASSERT_TRUE(keyboard_container); |
bshe | a0a5780 | 2015-04-08 18:21:29 | [diff] [blame] | 1201 | keyboard::KeyboardController* keyboard_controller = |
| 1202 | keyboard::KeyboardController::GetInstance(); |
| 1203 | keyboard_controller->ShowKeyboard(false); |
ben | 974286a | 2015-10-10 00:45:12 | [diff] [blame] | 1204 | keyboard_controller->ui()->GetKeyboardWindow()->SetBounds( |
bshe | a0a5780 | 2015-04-08 18:21:29 | [diff] [blame] | 1205 | gfx::Rect(0, 400, 800, 200)); |
| 1206 | EXPECT_EQ("0,400 800x200", keyboard_container->bounds().ToString()); |
kevers | 0e45049 | 2014-09-30 16:02:31 | [diff] [blame] | 1207 | |
| 1208 | UpdateDisplay("600x800"); |
bshe | a0a5780 | 2015-04-08 18:21:29 | [diff] [blame] | 1209 | EXPECT_EQ("0,600 600x200", keyboard_container->bounds().ToString()); |
kevers | 0e45049 | 2014-09-30 16:02:31 | [diff] [blame] | 1210 | } |
| 1211 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 1212 | } // namespace test |
| 1213 | } // namespace ash |