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