[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 | |
[email protected] | fdf74bf | 2014-04-30 21:24:02 | [diff] [blame] | 7 | #include "ash/session/session_state_delegate.h" |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 8 | #include "ash/shelf/shelf_layout_manager.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 9 | #include "ash/shell.h" |
| 10 | #include "ash/shell_window_ids.h" |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 11 | #include "ash/system/tray/system_tray_delegate.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 12 | #include "ash/test/ash_test_base.h" |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 13 | #include "ash/test/display_manager_test_api.h" |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 14 | #include "ash/wm/system_modal_container_layout_manager.h" |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 15 | #include "ash/wm/window_properties.h" |
[email protected] | a41b4e1 | 2013-09-20 04:36:34 | [diff] [blame] | 16 | #include "ash/wm/window_state.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 17 | #include "ash/wm/window_util.h" |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 18 | #include "base/command_line.h" |
kevers | 23f3987d | 2014-09-17 13:50:12 | [diff] [blame] | 19 | #include "base/memory/scoped_ptr.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" |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 22 | #include "ui/aura/client/window_tree_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" |
[email protected] | 00a38679 | 2014-06-16 15:09:20 | [diff] [blame] | 32 | #include "ui/base/ime/text_input_focus_manager.h" |
| 33 | #include "ui/base/ui_base_switches_util.h" |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 34 | #include "ui/events/test/event_generator.h" |
[email protected] | cd9f71d | 2014-03-20 21:54:21 | [diff] [blame] | 35 | #include "ui/events/test/test_event_handler.h" |
[email protected] | 647b484 | 2013-12-12 14:24:24 | [diff] [blame] | 36 | #include "ui/keyboard/keyboard_controller_proxy.h" |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 37 | #include "ui/keyboard/keyboard_switches.h" |
[email protected] | 39e9521 | 2014-04-23 20:00:01 | [diff] [blame] | 38 | #include "ui/keyboard/keyboard_util.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 39 | #include "ui/views/controls/menu/menu_controller.h" |
| 40 | #include "ui/views/widget/widget.h" |
| 41 | #include "ui/views/widget/widget_delegate.h" |
| 42 | |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 43 | using aura::Window; |
| 44 | using views::Widget; |
| 45 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 46 | namespace ash { |
| 47 | namespace { |
| 48 | |
| 49 | class TestDelegate : public views::WidgetDelegateView { |
| 50 | public: |
| 51 | explicit TestDelegate(bool system_modal) : system_modal_(system_modal) {} |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 52 | ~TestDelegate() override {} |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 53 | |
| 54 | // Overridden from views::WidgetDelegate: |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 55 | views::View* GetContentsView() override { return this; } |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 56 | |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 57 | ui::ModalType GetModalType() const override { |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 58 | return system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE; |
| 59 | } |
| 60 | |
| 61 | private: |
| 62 | bool system_modal_; |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 63 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 64 | DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
| 65 | }; |
| 66 | |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 67 | class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate, |
| 68 | public aura::client::FocusChangeObserver { |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 69 | public: |
| 70 | DeleteOnBlurDelegate() : window_(NULL) {} |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 71 | ~DeleteOnBlurDelegate() override {} |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 72 | |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 73 | void SetWindow(aura::Window* window) { |
| 74 | window_ = window; |
| 75 | aura::client::SetFocusChangeObserver(window_, this); |
| 76 | } |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 77 | |
[email protected] | 869f635 | 2012-12-06 20:47:17 | [diff] [blame] | 78 | private: |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 79 | // aura::test::TestWindowDelegate overrides: |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 80 | bool CanFocus() override { return true; } |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 81 | |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 82 | // aura::client::FocusChangeObserver implementation: |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 83 | void OnWindowFocused(aura::Window* gained_focus, |
| 84 | aura::Window* lost_focus) override { |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 85 | if (window_ == lost_focus) |
| 86 | delete window_; |
[email protected] | 869f635 | 2012-12-06 20:47:17 | [diff] [blame] | 87 | } |
| 88 | |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 89 | aura::Window* window_; |
| 90 | |
| 91 | DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate); |
| 92 | }; |
| 93 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 94 | } // namespace |
| 95 | |
| 96 | namespace test { |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 97 | |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 98 | class RootWindowControllerTest : public test::AshTestBase { |
| 99 | public: |
| 100 | views::Widget* CreateTestWidget(const gfx::Rect& bounds) { |
| 101 | views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 102 | NULL, CurrentContext(), bounds); |
| 103 | widget->Show(); |
| 104 | return widget; |
| 105 | } |
| 106 | |
| 107 | views::Widget* CreateModalWidget(const gfx::Rect& bounds) { |
| 108 | views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 109 | new TestDelegate(true), CurrentContext(), bounds); |
| 110 | widget->Show(); |
| 111 | return widget; |
| 112 | } |
| 113 | |
| 114 | views::Widget* CreateModalWidgetWithParent(const gfx::Rect& bounds, |
| 115 | gfx::NativeWindow parent) { |
| 116 | views::Widget* widget = |
| 117 | views::Widget::CreateWindowWithParentAndBounds(new TestDelegate(true), |
| 118 | parent, |
| 119 | bounds); |
| 120 | widget->Show(); |
| 121 | return widget; |
| 122 | } |
| 123 | |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 124 | aura::Window* GetModalContainer(aura::Window* root_window) { |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 125 | return Shell::GetContainer(root_window, |
| 126 | ash::kShellWindowId_SystemModalContainer); |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 127 | } |
| 128 | }; |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 129 | |
[email protected] | e75642a | 2013-06-12 17:21:18 | [diff] [blame] | 130 | TEST_F(RootWindowControllerTest, MoveWindows_Basic) { |
| 131 | if (!SupportsMultipleDisplays()) |
| 132 | return; |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 133 | // Windows origin should be doubled when moved to the 1st display. |
| 134 | UpdateDisplay("600x600,300x300"); |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 135 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 136 | RootWindowController* controller = Shell::GetPrimaryRootWindowController(); |
| 137 | ShelfLayoutManager* shelf_layout_manager = |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 138 | controller->GetShelfLayoutManager(); |
| 139 | shelf_layout_manager->SetAutoHideBehavior( |
| 140 | ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
[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()); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 151 | EXPECT_EQ("600,0 300x253", maximized->GetWindowBoundsInScreen().ToString()); |
| 152 | EXPECT_EQ("0,0 300x253", |
[email protected] | 8c0ec43 | 2013-05-10 04:33:39 | [diff] [blame] | 153 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 154 | |
| 155 | views::Widget* minimized = CreateTestWidget(gfx::Rect(800, 10, 100, 100)); |
| 156 | minimized->Minimize(); |
| 157 | EXPECT_EQ(root_windows[1], minimized->GetNativeView()->GetRootWindow()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 158 | EXPECT_EQ("800,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 159 | 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 | |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 165 | EXPECT_EQ("600,0 300x300", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 166 | fullscreen->GetWindowBoundsInScreen().ToString()); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 167 | EXPECT_EQ("0,0 300x300", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 168 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 169 | |
[email protected] | 8f2f15141 | 2013-01-26 03:58:37 | [diff] [blame] | 170 | views::Widget* unparented_control = new Widget; |
| 171 | Widget::InitParams params; |
| 172 | params.bounds = gfx::Rect(650, 10, 100, 100); |
| 173 | params.context = CurrentContext(); |
| 174 | params.type = Widget::InitParams::TYPE_CONTROL; |
| 175 | unparented_control->Init(params); |
| 176 | EXPECT_EQ(root_windows[1], |
| 177 | unparented_control->GetNativeView()->GetRootWindow()); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 178 | EXPECT_EQ(kShellWindowId_UnparentedControlContainer, |
[email protected] | 8f2f15141 | 2013-01-26 03:58:37 | [diff] [blame] | 179 | unparented_control->GetNativeView()->parent()->id()); |
| 180 | |
[email protected] | 95db9c1 | 2013-01-31 11:47:44 | [diff] [blame] | 181 | aura::Window* panel = CreateTestWindowInShellWithDelegateAndType( |
[email protected] | 5b251f1 | 2013-12-19 01:50:05 | [diff] [blame] | 182 | NULL, ui::wm::WINDOW_TYPE_PANEL, 0, gfx::Rect(700, 100, 100, 100)); |
[email protected] | 95db9c1 | 2013-01-31 11:47:44 | [diff] [blame] | 183 | EXPECT_EQ(root_windows[1], panel->GetRootWindow()); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 184 | EXPECT_EQ(kShellWindowId_PanelContainer, panel->parent()->id()); |
[email protected] | 95db9c1 | 2013-01-31 11:47:44 | [diff] [blame] | 185 | |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 186 | // Make sure a window that will delete itself when losing focus |
| 187 | // will not crash. |
| 188 | aura::WindowTracker tracker; |
| 189 | DeleteOnBlurDelegate delete_on_blur_delegate; |
[email protected] | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 190 | aura::Window* d2 = CreateTestWindowInShellWithDelegate( |
| 191 | &delete_on_blur_delegate, 0, gfx::Rect(50, 50, 100, 100)); |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 192 | delete_on_blur_delegate.SetWindow(d2); |
[email protected] | 550543e | 2013-01-11 22:43:44 | [diff] [blame] | 193 | aura::client::GetFocusClient(root_windows[0])->FocusWindow(d2); |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 194 | tracker.Add(d2); |
| 195 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 196 | UpdateDisplay("600x600"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 197 | |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 198 | // d2 must have been deleted. |
| 199 | EXPECT_FALSE(tracker.Contains(d2)); |
| 200 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 201 | EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow()); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 202 | EXPECT_EQ("100,20 100x100", normal->GetWindowBoundsInScreen().ToString()); |
| 203 | EXPECT_EQ("100,20 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 204 | normal->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 205 | |
[email protected] | eefd51b2 | 2012-09-25 20:26:24 | [diff] [blame] | 206 | // Maximized area on primary display has 3px (given as |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 207 | // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom. |
[email protected] | 2a64b0a | 2013-07-23 23:15:54 | [diff] [blame] | 208 | |
| 209 | // First clear fullscreen status, since both fullscreen and maximized windows |
| 210 | // share the same desktop workspace, which cancels the shelf status. |
| 211 | fullscreen->SetFullscreen(false); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 212 | EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow()); |
[email protected] | 7b675df61 | 2012-09-16 18:33:20 | [diff] [blame] | 213 | EXPECT_EQ("0,0 600x597", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 214 | maximized->GetWindowBoundsInScreen().ToString()); |
[email protected] | 7b675df61 | 2012-09-16 18:33:20 | [diff] [blame] | 215 | EXPECT_EQ("0,0 600x597", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 216 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 217 | |
[email protected] | 2a64b0a | 2013-07-23 23:15:54 | [diff] [blame] | 218 | // Set fullscreen to true. In that case the 3px inset becomes invisible so |
| 219 | // the maximized window can also use the area fully. |
| 220 | fullscreen->SetFullscreen(true); |
| 221 | EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow()); |
| 222 | EXPECT_EQ("0,0 600x600", |
| 223 | maximized->GetWindowBoundsInScreen().ToString()); |
| 224 | EXPECT_EQ("0,0 600x600", |
| 225 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
| 226 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 227 | EXPECT_EQ(root_windows[0], minimized->GetNativeView()->GetRootWindow()); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 228 | EXPECT_EQ("400,20 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 229 | minimized->GetWindowBoundsInScreen().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 230 | |
| 231 | EXPECT_EQ(root_windows[0], fullscreen->GetNativeView()->GetRootWindow()); |
| 232 | EXPECT_TRUE(fullscreen->IsFullscreen()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 233 | EXPECT_EQ("0,0 600x600", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 234 | fullscreen->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 235 | EXPECT_EQ("0,0 600x600", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 236 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 237 | |
| 238 | // Test if the restore bounds are correctly updated. |
[email protected] | a41b4e1 | 2013-09-20 04:36:34 | [diff] [blame] | 239 | wm::GetWindowState(maximized->GetNativeView())->Restore(); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 240 | EXPECT_EQ("200,20 100x100", maximized->GetWindowBoundsInScreen().ToString()); |
| 241 | EXPECT_EQ("200,20 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 242 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 243 | |
| 244 | fullscreen->SetFullscreen(false); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 245 | EXPECT_EQ("500,20 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 246 | fullscreen->GetWindowBoundsInScreen().ToString()); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 247 | EXPECT_EQ("500,20 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 248 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | 8f2f15141 | 2013-01-26 03:58:37 | [diff] [blame] | 249 | |
| 250 | // Test if the unparented widget has moved. |
| 251 | EXPECT_EQ(root_windows[0], |
| 252 | unparented_control->GetNativeView()->GetRootWindow()); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 253 | EXPECT_EQ(kShellWindowId_UnparentedControlContainer, |
[email protected] | 8f2f15141 | 2013-01-26 03:58:37 | [diff] [blame] | 254 | unparented_control->GetNativeView()->parent()->id()); |
[email protected] | 95db9c1 | 2013-01-31 11:47:44 | [diff] [blame] | 255 | |
| 256 | // Test if the panel has moved. |
| 257 | EXPECT_EQ(root_windows[0], panel->GetRootWindow()); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 258 | EXPECT_EQ(kShellWindowId_PanelContainer, panel->parent()->id()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 259 | } |
| 260 | |
[email protected] | e75642a | 2013-06-12 17:21:18 | [diff] [blame] | 261 | TEST_F(RootWindowControllerTest, MoveWindows_Modal) { |
| 262 | if (!SupportsMultipleDisplays()) |
| 263 | return; |
[email protected] | 1c3f700 | 2013-01-21 18:46:05 | [diff] [blame] | 264 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 265 | UpdateDisplay("500x500,500x500"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 266 | |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 267 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 268 | // Emulate virtual screen coordinate system. |
| 269 | root_windows[0]->SetBounds(gfx::Rect(0, 0, 500, 500)); |
| 270 | root_windows[1]->SetBounds(gfx::Rect(500, 0, 500, 500)); |
| 271 | |
| 272 | views::Widget* normal = CreateTestWidget(gfx::Rect(300, 10, 100, 100)); |
| 273 | EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow()); |
| 274 | EXPECT_TRUE(wm::IsActiveWindow(normal->GetNativeView())); |
| 275 | |
| 276 | views::Widget* modal = CreateModalWidget(gfx::Rect(650, 10, 100, 100)); |
| 277 | EXPECT_EQ(root_windows[1], modal->GetNativeView()->GetRootWindow()); |
| 278 | EXPECT_TRUE(GetModalContainer(root_windows[1])->Contains( |
| 279 | modal->GetNativeView())); |
| 280 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 281 | |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 282 | ui::test::EventGenerator generator_1st(root_windows[0]); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 283 | generator_1st.ClickLeftButton(); |
| 284 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 285 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 286 | UpdateDisplay("500x500"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 287 | EXPECT_EQ(root_windows[0], modal->GetNativeView()->GetRootWindow()); |
| 288 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 289 | generator_1st.ClickLeftButton(); |
| 290 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 291 | } |
| 292 | |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 293 | // Make sure lock related windows moves. |
| 294 | TEST_F(RootWindowControllerTest, MoveWindows_LockWindowsInUnified) { |
| 295 | if (!SupportsMultipleDisplays()) |
| 296 | return; |
| 297 | DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 298 | DisplayManagerTestApi test_api(display_manager); |
| 299 | test_api.SetDefaultMultiDisplayMode(DisplayManager::UNIFIED); |
| 300 | display_manager->SetMultiDisplayMode(DisplayManager::UNIFIED); |
| 301 | UpdateDisplay("500x500"); |
| 302 | const int kLockScreenWindowId = 1000; |
| 303 | const int kLockBackgroundWindowId = 1001; |
| 304 | |
| 305 | RootWindowController* controller = |
| 306 | Shell::GetInstance()->GetPrimaryRootWindowController(); |
| 307 | |
| 308 | aura::Window* lock_container = |
| 309 | controller->GetContainer(kShellWindowId_LockScreenContainer); |
| 310 | aura::Window* lock_background_container = |
| 311 | controller->GetContainer(kShellWindowId_LockScreenBackgroundContainer); |
| 312 | |
| 313 | views::Widget* lock_screen = |
| 314 | CreateModalWidgetWithParent(gfx::Rect(10, 10, 100, 100), lock_container); |
| 315 | lock_screen->GetNativeWindow()->set_id(kLockScreenWindowId); |
| 316 | lock_screen->SetFullscreen(true); |
| 317 | |
| 318 | views::Widget* lock_background = CreateModalWidgetWithParent( |
| 319 | gfx::Rect(10, 10, 100, 100), lock_background_container); |
| 320 | lock_background->GetNativeWindow()->set_id(kLockBackgroundWindowId); |
| 321 | |
| 322 | ASSERT_EQ(lock_screen->GetNativeWindow(), |
| 323 | controller->GetRootWindow()->GetChildById(kLockScreenWindowId)); |
| 324 | ASSERT_EQ(lock_background->GetNativeWindow(), |
| 325 | controller->GetRootWindow()->GetChildById(kLockBackgroundWindowId)); |
| 326 | EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString()); |
| 327 | |
| 328 | // Switch to unified. |
| 329 | UpdateDisplay("500x500,500x500"); |
| 330 | |
| 331 | // In unified mode, RWC is created |
| 332 | controller = Shell::GetInstance()->GetPrimaryRootWindowController(); |
| 333 | |
| 334 | ASSERT_EQ(lock_screen->GetNativeWindow(), |
| 335 | controller->GetRootWindow()->GetChildById(kLockScreenWindowId)); |
| 336 | ASSERT_EQ(lock_background->GetNativeWindow(), |
| 337 | controller->GetRootWindow()->GetChildById(kLockBackgroundWindowId)); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame^] | 338 | EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString()); |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 339 | |
| 340 | // Switch to mirror. |
| 341 | display_manager->SetMirrorMode(true); |
| 342 | EXPECT_TRUE(display_manager->IsInMirrorMode()); |
| 343 | |
| 344 | controller = Shell::GetInstance()->GetPrimaryRootWindowController(); |
| 345 | ASSERT_EQ(lock_screen->GetNativeWindow(), |
| 346 | controller->GetRootWindow()->GetChildById(kLockScreenWindowId)); |
| 347 | ASSERT_EQ(lock_background->GetNativeWindow(), |
| 348 | controller->GetRootWindow()->GetChildById(kLockBackgroundWindowId)); |
| 349 | EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString()); |
| 350 | |
| 351 | // Switch to unified. |
| 352 | display_manager->SetMirrorMode(false); |
| 353 | EXPECT_TRUE(display_manager->IsInUnifiedMode()); |
| 354 | |
| 355 | controller = Shell::GetInstance()->GetPrimaryRootWindowController(); |
| 356 | |
| 357 | ASSERT_EQ(lock_screen->GetNativeWindow(), |
| 358 | controller->GetRootWindow()->GetChildById(kLockScreenWindowId)); |
| 359 | ASSERT_EQ(lock_background->GetNativeWindow(), |
| 360 | controller->GetRootWindow()->GetChildById(kLockBackgroundWindowId)); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame^] | 361 | EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString()); |
oshima | 022a954 | 2015-05-01 00:15:02 | [diff] [blame] | 362 | |
| 363 | // Switch to single display. |
| 364 | UpdateDisplay("600x500"); |
| 365 | EXPECT_FALSE(display_manager->IsInUnifiedMode()); |
| 366 | EXPECT_FALSE(display_manager->IsInMirrorMode()); |
| 367 | |
| 368 | controller = Shell::GetInstance()->GetPrimaryRootWindowController(); |
| 369 | |
| 370 | ASSERT_EQ(lock_screen->GetNativeWindow(), |
| 371 | controller->GetRootWindow()->GetChildById(kLockScreenWindowId)); |
| 372 | ASSERT_EQ(lock_background->GetNativeWindow(), |
| 373 | controller->GetRootWindow()->GetChildById(kLockBackgroundWindowId)); |
| 374 | EXPECT_EQ("0,0 600x500", lock_screen->GetNativeWindow()->bounds().ToString()); |
| 375 | } |
| 376 | |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 377 | TEST_F(RootWindowControllerTest, ModalContainer) { |
| 378 | UpdateDisplay("600x600"); |
| 379 | Shell* shell = Shell::GetInstance(); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 380 | RootWindowController* controller = shell->GetPrimaryRootWindowController(); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 381 | EXPECT_EQ(user::LOGGED_IN_USER, |
[email protected] | 945f9cae | 2012-12-12 09:54:29 | [diff] [blame] | 382 | shell->system_tray_delegate()->GetUserLoginStatus()); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 383 | EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 384 | ->layout_manager(), |
| 385 | controller->GetSystemModalLayoutManager(NULL)); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 386 | |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 387 | views::Widget* session_modal_widget = |
| 388 | CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 389 | EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 390 | ->layout_manager(), |
| 391 | controller->GetSystemModalLayoutManager( |
| 392 | session_modal_widget->GetNativeView())); |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 393 | |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 394 | shell->session_state_delegate()->LockScreen(); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 395 | EXPECT_EQ(user::LOGGED_IN_LOCKED, |
[email protected] | 945f9cae | 2012-12-12 09:54:29 | [diff] [blame] | 396 | shell->system_tray_delegate()->GetUserLoginStatus()); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 397 | EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 398 | ->layout_manager(), |
| 399 | controller->GetSystemModalLayoutManager(NULL)); |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 400 | |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 401 | aura::Window* lock_container = |
| 402 | controller->GetContainer(kShellWindowId_LockScreenContainer); |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 403 | views::Widget* lock_modal_widget = |
| 404 | CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 405 | EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 406 | ->layout_manager(), |
| 407 | controller->GetSystemModalLayoutManager( |
| 408 | lock_modal_widget->GetNativeView())); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 409 | EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 410 | ->layout_manager(), |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 411 | controller->GetSystemModalLayoutManager( |
| 412 | session_modal_widget->GetNativeView())); |
| 413 | |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 414 | shell->session_state_delegate()->UnlockScreen(); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 415 | } |
| 416 | |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 417 | TEST_F(RootWindowControllerTest, ModalContainerNotLoggedInLoggedIn) { |
| 418 | UpdateDisplay("600x600"); |
| 419 | Shell* shell = Shell::GetInstance(); |
| 420 | |
| 421 | // Configure login screen environment. |
| 422 | SetUserLoggedIn(false); |
| 423 | EXPECT_EQ(user::LOGGED_IN_NONE, |
[email protected] | 945f9cae | 2012-12-12 09:54:29 | [diff] [blame] | 424 | shell->system_tray_delegate()->GetUserLoginStatus()); |
[email protected] | c8d19f8 | 2013-05-18 09:09:41 | [diff] [blame] | 425 | EXPECT_EQ(0, shell->session_state_delegate()->NumberOfLoggedInUsers()); |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 426 | EXPECT_FALSE(shell->session_state_delegate()->IsActiveUserSessionStarted()); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 427 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 428 | RootWindowController* controller = shell->GetPrimaryRootWindowController(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 429 | EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 430 | ->layout_manager(), |
| 431 | controller->GetSystemModalLayoutManager(NULL)); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 432 | |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 433 | aura::Window* lock_container = |
| 434 | controller->GetContainer(kShellWindowId_LockScreenContainer); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 435 | views::Widget* login_modal_widget = |
| 436 | CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 437 | EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 438 | ->layout_manager(), |
| 439 | controller->GetSystemModalLayoutManager( |
| 440 | login_modal_widget->GetNativeView())); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 441 | login_modal_widget->Close(); |
| 442 | |
| 443 | // Configure user session environment. |
| 444 | SetUserLoggedIn(true); |
| 445 | SetSessionStarted(true); |
| 446 | EXPECT_EQ(user::LOGGED_IN_USER, |
[email protected] | 945f9cae | 2012-12-12 09:54:29 | [diff] [blame] | 447 | shell->system_tray_delegate()->GetUserLoginStatus()); |
[email protected] | c8d19f8 | 2013-05-18 09:09:41 | [diff] [blame] | 448 | EXPECT_EQ(1, shell->session_state_delegate()->NumberOfLoggedInUsers()); |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 449 | EXPECT_TRUE(shell->session_state_delegate()->IsActiveUserSessionStarted()); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 450 | EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 451 | ->layout_manager(), |
| 452 | controller->GetSystemModalLayoutManager(NULL)); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 453 | |
| 454 | views::Widget* session_modal_widget = |
| 455 | CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 456 | EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 457 | ->layout_manager(), |
| 458 | controller->GetSystemModalLayoutManager( |
| 459 | session_modal_widget->GetNativeView())); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 460 | } |
| 461 | |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 462 | TEST_F(RootWindowControllerTest, ModalContainerBlockedSession) { |
| 463 | UpdateDisplay("600x600"); |
Peter Kasting | be940e9 | 2014-11-20 23:14:08 | [diff] [blame] | 464 | RootWindowController* controller = Shell::GetPrimaryRootWindowController(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 465 | aura::Window* lock_container = |
| 466 | controller->GetContainer(kShellWindowId_LockScreenContainer); |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 467 | for (int block_reason = FIRST_BLOCK_REASON; |
| 468 | block_reason < NUMBER_OF_BLOCK_REASONS; |
| 469 | ++block_reason) { |
| 470 | views::Widget* session_modal_widget = |
| 471 | CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 472 | EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 473 | ->layout_manager(), |
| 474 | controller->GetSystemModalLayoutManager( |
| 475 | session_modal_widget->GetNativeView())); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 476 | EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 477 | ->layout_manager(), |
| 478 | controller->GetSystemModalLayoutManager(NULL)); |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 479 | session_modal_widget->Close(); |
| 480 | |
| 481 | BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 482 | |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 483 | EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 484 | ->layout_manager(), |
| 485 | controller->GetSystemModalLayoutManager(NULL)); |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 486 | |
| 487 | views::Widget* lock_modal_widget = |
| 488 | CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), |
| 489 | lock_container); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 490 | EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 491 | ->layout_manager(), |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 492 | controller->GetSystemModalLayoutManager( |
| 493 | lock_modal_widget->GetNativeView())); |
| 494 | |
| 495 | session_modal_widget = |
| 496 | CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 497 | EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 498 | ->layout_manager(), |
| 499 | controller->GetSystemModalLayoutManager( |
| 500 | session_modal_widget->GetNativeView())); |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 501 | session_modal_widget->Close(); |
| 502 | |
| 503 | lock_modal_widget->Close(); |
| 504 | UnblockUserSession(); |
| 505 | } |
| 506 | } |
| 507 | |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 508 | TEST_F(RootWindowControllerTest, GetWindowForFullscreenMode) { |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 509 | UpdateDisplay("600x600"); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 510 | RootWindowController* controller = |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 511 | Shell::GetInstance()->GetPrimaryRootWindowController(); |
| 512 | |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 513 | Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 514 | w1->Maximize(); |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 515 | Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
| 516 | w2->SetFullscreen(true); |
| 517 | // |w3| is a transient child of |w2|. |
| 518 | Widget* w3 = Widget::CreateWindowWithParentAndBounds(NULL, |
| 519 | w2->GetNativeWindow(), gfx::Rect(0, 0, 100, 100)); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 520 | |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 521 | // Test that GetWindowForFullscreenMode() finds the fullscreen window when one |
[email protected] | e3bc88e | 2013-09-06 06:22:06 | [diff] [blame] | 522 | // of its transient children is active. |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 523 | w3->Activate(); |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 524 | EXPECT_EQ(w2->GetNativeWindow(), controller->GetWindowForFullscreenMode()); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 525 | |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 526 | // If the topmost window is not fullscreen, it returns NULL. |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 527 | w1->Activate(); |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 528 | EXPECT_EQ(NULL, controller->GetWindowForFullscreenMode()); |
| 529 | w1->Close(); |
| 530 | w3->Close(); |
[email protected] | e3bc88e | 2013-09-06 06:22:06 | [diff] [blame] | 531 | |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 532 | // Only w2 remains, if minimized GetWindowForFullscreenMode should return |
| 533 | // NULL. |
[email protected] | e3bc88e | 2013-09-06 06:22:06 | [diff] [blame] | 534 | w2->Activate(); |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 535 | EXPECT_EQ(w2->GetNativeWindow(), controller->GetWindowForFullscreenMode()); |
| 536 | w2->Minimize(); |
| 537 | EXPECT_EQ(NULL, controller->GetWindowForFullscreenMode()); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 538 | } |
| 539 | |
[email protected] | 2c5db9e | 2014-02-27 13:58:14 | [diff] [blame] | 540 | TEST_F(RootWindowControllerTest, MultipleDisplaysGetWindowForFullscreenMode) { |
| 541 | if (!SupportsMultipleDisplays()) |
| 542 | return; |
| 543 | |
| 544 | UpdateDisplay("600x600,600x600"); |
| 545 | Shell::RootWindowControllerList controllers = |
| 546 | Shell::GetInstance()->GetAllRootWindowControllers(); |
| 547 | |
| 548 | Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
| 549 | w1->Maximize(); |
| 550 | Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
| 551 | w2->SetFullscreen(true); |
| 552 | Widget* w3 = CreateTestWidget(gfx::Rect(600, 0, 100, 100)); |
| 553 | |
| 554 | EXPECT_EQ(w1->GetNativeWindow()->GetRootWindow(), |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 555 | controllers[0]->GetRootWindow()); |
[email protected] | 2c5db9e | 2014-02-27 13:58:14 | [diff] [blame] | 556 | EXPECT_EQ(w2->GetNativeWindow()->GetRootWindow(), |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 557 | controllers[0]->GetRootWindow()); |
[email protected] | 2c5db9e | 2014-02-27 13:58:14 | [diff] [blame] | 558 | EXPECT_EQ(w3->GetNativeWindow()->GetRootWindow(), |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 559 | controllers[1]->GetRootWindow()); |
[email protected] | 2c5db9e | 2014-02-27 13:58:14 | [diff] [blame] | 560 | |
| 561 | w1->Activate(); |
| 562 | EXPECT_EQ(NULL, controllers[0]->GetWindowForFullscreenMode()); |
| 563 | EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode()); |
| 564 | |
| 565 | w2->Activate(); |
| 566 | EXPECT_EQ(w2->GetNativeWindow(), |
| 567 | controllers[0]->GetWindowForFullscreenMode()); |
| 568 | EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode()); |
| 569 | |
| 570 | // Verify that the first root window controller remains in fullscreen mode |
| 571 | // when a window on the other display is activated. |
| 572 | w3->Activate(); |
| 573 | EXPECT_EQ(w2->GetNativeWindow(), |
| 574 | controllers[0]->GetWindowForFullscreenMode()); |
| 575 | EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode()); |
| 576 | } |
| 577 | |
[email protected] | 82ced235 | 2013-07-19 20:49:06 | [diff] [blame] | 578 | // Test that user session window can't be focused if user session blocked by |
| 579 | // some overlapping UI. |
| 580 | TEST_F(RootWindowControllerTest, FocusBlockedWindow) { |
| 581 | UpdateDisplay("600x600"); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 582 | RootWindowController* controller = |
[email protected] | 82ced235 | 2013-07-19 20:49:06 | [diff] [blame] | 583 | Shell::GetInstance()->GetPrimaryRootWindowController(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 584 | aura::Window* lock_container = |
| 585 | controller->GetContainer(kShellWindowId_LockScreenContainer); |
[email protected] | 82ced235 | 2013-07-19 20:49:06 | [diff] [blame] | 586 | aura::Window* lock_window = Widget::CreateWindowWithParentAndBounds(NULL, |
| 587 | lock_container, gfx::Rect(0, 0, 100, 100))->GetNativeView(); |
| 588 | lock_window->Show(); |
| 589 | aura::Window* session_window = |
| 590 | CreateTestWidget(gfx::Rect(0, 0, 100, 100))->GetNativeView(); |
| 591 | session_window->Show(); |
| 592 | |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 593 | for (int block_reason = FIRST_BLOCK_REASON; |
| 594 | block_reason < NUMBER_OF_BLOCK_REASONS; |
| 595 | ++block_reason) { |
| 596 | BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 597 | lock_window->Focus(); |
| 598 | EXPECT_TRUE(lock_window->HasFocus()); |
| 599 | session_window->Focus(); |
| 600 | EXPECT_FALSE(session_window->HasFocus()); |
| 601 | UnblockUserSession(); |
| 602 | } |
[email protected] | 82ced235 | 2013-07-19 20:49:06 | [diff] [blame] | 603 | } |
| 604 | |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 605 | // Tracks whether OnWindowDestroying() has been invoked. |
| 606 | class DestroyedWindowObserver : public aura::WindowObserver { |
| 607 | public: |
| 608 | DestroyedWindowObserver() : destroyed_(false), window_(NULL) {} |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 609 | ~DestroyedWindowObserver() override { Shutdown(); } |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 610 | |
| 611 | void SetWindow(Window* window) { |
| 612 | window_ = window; |
| 613 | window->AddObserver(this); |
| 614 | } |
| 615 | |
| 616 | bool destroyed() const { return destroyed_; } |
| 617 | |
| 618 | // WindowObserver overrides: |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 619 | void OnWindowDestroying(Window* window) override { |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 620 | destroyed_ = true; |
| 621 | Shutdown(); |
| 622 | } |
| 623 | |
| 624 | private: |
| 625 | void Shutdown() { |
| 626 | if (!window_) |
| 627 | return; |
| 628 | window_->RemoveObserver(this); |
| 629 | window_ = NULL; |
| 630 | } |
| 631 | |
| 632 | bool destroyed_; |
| 633 | Window* window_; |
| 634 | |
| 635 | DISALLOW_COPY_AND_ASSIGN(DestroyedWindowObserver); |
| 636 | }; |
| 637 | |
| 638 | // Verifies shutdown doesn't delete windows that are not owned by the parent. |
| 639 | TEST_F(RootWindowControllerTest, DontDeleteWindowsNotOwnedByParent) { |
| 640 | DestroyedWindowObserver observer1; |
| 641 | aura::test::TestWindowDelegate delegate1; |
| 642 | aura::Window* window1 = new aura::Window(&delegate1); |
[email protected] | 5b251f1 | 2013-12-19 01:50:05 | [diff] [blame] | 643 | window1->SetType(ui::wm::WINDOW_TYPE_CONTROL); |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 644 | window1->set_owned_by_parent(false); |
| 645 | observer1.SetWindow(window1); |
danakj | b161836d | 2015-04-03 05:14:18 | [diff] [blame] | 646 | window1->Init(ui::LAYER_NOT_DRAWN); |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 647 | aura::client::ParentWindowWithContext( |
| 648 | window1, Shell::GetInstance()->GetPrimaryRootWindow(), gfx::Rect()); |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 649 | |
| 650 | DestroyedWindowObserver observer2; |
| 651 | aura::Window* window2 = new aura::Window(NULL); |
| 652 | window2->set_owned_by_parent(false); |
| 653 | observer2.SetWindow(window2); |
danakj | b161836d | 2015-04-03 05:14:18 | [diff] [blame] | 654 | window2->Init(ui::LAYER_NOT_DRAWN); |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 655 | Shell::GetInstance()->GetPrimaryRootWindow()->AddChild(window2); |
| 656 | |
| 657 | Shell::GetInstance()->GetPrimaryRootWindowController()->CloseChildWindows(); |
| 658 | |
| 659 | ASSERT_FALSE(observer1.destroyed()); |
| 660 | delete window1; |
| 661 | |
| 662 | ASSERT_FALSE(observer2.destroyed()); |
| 663 | delete window2; |
| 664 | } |
| 665 | |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 666 | typedef test::NoSessionAshTestBase NoSessionRootWindowControllerTest; |
| 667 | |
| 668 | // Make sure that an event handler exists for entire display area. |
| 669 | TEST_F(NoSessionRootWindowControllerTest, Event) { |
[email protected] | 75a88c9 | 2014-05-14 01:57:32 | [diff] [blame] | 670 | // Hide the shelf since it might otherwise get an event target. |
| 671 | RootWindowController* controller = Shell::GetPrimaryRootWindowController(); |
| 672 | ShelfLayoutManager* shelf_layout_manager = |
| 673 | controller->GetShelfLayoutManager(); |
| 674 | shelf_layout_manager->SetAutoHideBehavior( |
| 675 | ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
| 676 | |
[email protected] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 677 | aura::Window* root = Shell::GetPrimaryRootWindow(); |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 678 | const gfx::Size size = root->bounds().size(); |
| 679 | aura::Window* event_target = root->GetEventHandlerForPoint(gfx::Point(0, 0)); |
| 680 | EXPECT_TRUE(event_target); |
| 681 | EXPECT_EQ(event_target, |
| 682 | root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1))); |
| 683 | EXPECT_EQ(event_target, |
| 684 | root->GetEventHandlerForPoint(gfx::Point(size.width() - 1, 0))); |
| 685 | EXPECT_EQ(event_target, |
| 686 | root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1))); |
| 687 | EXPECT_EQ(event_target, |
| 688 | root->GetEventHandlerForPoint( |
| 689 | gfx::Point(size.width() - 1, size.height() - 1))); |
| 690 | } |
| 691 | |
[email protected] | 24f5e24 | 2014-07-22 02:16:09 | [diff] [blame] | 692 | class VirtualKeyboardRootWindowControllerTest |
| 693 | : public RootWindowControllerTest { |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 694 | public: |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 695 | VirtualKeyboardRootWindowControllerTest() {} |
| 696 | ~VirtualKeyboardRootWindowControllerTest() override {} |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 697 | |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 698 | void SetUp() override { |
pgal.u-szeged | d84534d3 | 2014-10-29 12:34:30 | [diff] [blame] | 699 | base::CommandLine::ForCurrentProcess()->AppendSwitch( |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 700 | keyboard::switches::kEnableVirtualKeyboard); |
| 701 | test::AshTestBase::SetUp(); |
[email protected] | 24ca45d | 2013-10-25 03:37:44 | [diff] [blame] | 702 | Shell::GetPrimaryRootWindowController()->ActivateKeyboard( |
[email protected] | a0b3fb88 | 2014-04-07 19:26:03 | [diff] [blame] | 703 | keyboard::KeyboardController::GetInstance()); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | private: |
| 707 | DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest); |
| 708 | }; |
| 709 | |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 710 | class MockTextInputClient : public ui::DummyTextInputClient { |
| 711 | public: |
| 712 | MockTextInputClient() : |
| 713 | ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT) {} |
| 714 | |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 715 | void EnsureCaretInRect(const gfx::Rect& rect) override { |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 716 | visible_rect_ = rect; |
| 717 | } |
| 718 | |
| 719 | const gfx::Rect& visible_rect() const { |
| 720 | return visible_rect_; |
| 721 | } |
| 722 | |
| 723 | private: |
| 724 | gfx::Rect visible_rect_; |
| 725 | |
| 726 | DISALLOW_COPY_AND_ASSIGN(MockTextInputClient); |
| 727 | }; |
| 728 | |
kevers | 23f3987d | 2014-09-17 13:50:12 | [diff] [blame] | 729 | class TargetHitTestEventHandler : public ui::test::TestEventHandler { |
| 730 | public: |
| 731 | TargetHitTestEventHandler() {} |
| 732 | |
| 733 | // ui::test::TestEventHandler overrides. |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 734 | void OnMouseEvent(ui::MouseEvent* event) override { |
kevers | 23f3987d | 2014-09-17 13:50:12 | [diff] [blame] | 735 | if (event->type() == ui::ET_MOUSE_PRESSED) |
| 736 | ui::test::TestEventHandler::OnMouseEvent(event); |
| 737 | event->StopPropagation(); |
| 738 | } |
| 739 | |
| 740 | private: |
| 741 | DISALLOW_COPY_AND_ASSIGN(TargetHitTestEventHandler); |
| 742 | }; |
| 743 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 744 | // Test for http://crbug.com/297858. Virtual keyboard container should only show |
| 745 | // on primary root window. |
| 746 | TEST_F(VirtualKeyboardRootWindowControllerTest, |
| 747 | VirtualKeyboardOnPrimaryRootWindowOnly) { |
| 748 | if (!SupportsMultipleDisplays()) |
| 749 | return; |
| 750 | |
| 751 | UpdateDisplay("500x500,500x500"); |
| 752 | |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 753 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 754 | aura::Window* primary_root_window = Shell::GetPrimaryRootWindow(); |
| 755 | aura::Window* secondary_root_window = |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 756 | root_windows[0] == primary_root_window ? |
| 757 | root_windows[1] : root_windows[0]; |
| 758 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 759 | ASSERT_TRUE(Shell::GetContainer(primary_root_window, |
| 760 | kShellWindowId_VirtualKeyboardContainer)); |
| 761 | ASSERT_FALSE(Shell::GetContainer(secondary_root_window, |
| 762 | kShellWindowId_VirtualKeyboardContainer)); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 763 | } |
| 764 | |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 765 | // Test for http://crbug.com/263599. Virtual keyboard should be able to receive |
| 766 | // events at blocked user session. |
| 767 | TEST_F(VirtualKeyboardRootWindowControllerTest, |
| 768 | ClickVirtualKeyboardInBlockedWindow) { |
[email protected] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 769 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 770 | aura::Window* keyboard_container = |
| 771 | Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 772 | ASSERT_TRUE(keyboard_container); |
| 773 | keyboard_container->Show(); |
| 774 | |
[email protected] | a0b3fb88 | 2014-04-07 19:26:03 | [diff] [blame] | 775 | aura::Window* keyboard_window = keyboard::KeyboardController::GetInstance()-> |
[email protected] | 647b484 | 2013-12-12 14:24:24 | [diff] [blame] | 776 | proxy()->GetKeyboardWindow(); |
| 777 | keyboard_container->AddChild(keyboard_window); |
[email protected] | 183e28d | 2014-01-20 18:18:02 | [diff] [blame] | 778 | keyboard_window->set_owned_by_parent(false); |
[email protected] | 647b484 | 2013-12-12 14:24:24 | [diff] [blame] | 779 | keyboard_window->SetBounds(gfx::Rect()); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 780 | keyboard_window->Show(); |
[email protected] | 647b484 | 2013-12-12 14:24:24 | [diff] [blame] | 781 | |
[email protected] | 3193ea72 | 2014-04-23 22:19:19 | [diff] [blame] | 782 | ui::test::TestEventHandler handler; |
| 783 | root_window->AddPreTargetHandler(&handler); |
[email protected] | 647b484 | 2013-12-12 14:24:24 | [diff] [blame] | 784 | |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 785 | ui::test::EventGenerator event_generator(root_window, keyboard_window); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 786 | event_generator.ClickLeftButton(); |
| 787 | int expected_mouse_presses = 1; |
[email protected] | 3193ea72 | 2014-04-23 22:19:19 | [diff] [blame] | 788 | EXPECT_EQ(expected_mouse_presses, handler.num_mouse_events() / 2); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 789 | |
| 790 | for (int block_reason = FIRST_BLOCK_REASON; |
| 791 | block_reason < NUMBER_OF_BLOCK_REASONS; |
| 792 | ++block_reason) { |
| 793 | BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 794 | event_generator.ClickLeftButton(); |
| 795 | expected_mouse_presses++; |
[email protected] | 3193ea72 | 2014-04-23 22:19:19 | [diff] [blame] | 796 | EXPECT_EQ(expected_mouse_presses, handler.num_mouse_events() / 2); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 797 | UnblockUserSession(); |
| 798 | } |
[email protected] | 3193ea72 | 2014-04-23 22:19:19 | [diff] [blame] | 799 | root_window->RemovePreTargetHandler(&handler); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 800 | } |
| 801 | |
[email protected] | 45c6667 | 2013-10-01 22:48:56 | [diff] [blame] | 802 | // Test for http://crbug.com/299787. RootWindowController should delete |
| 803 | // the old container since the keyboard controller creates a new window in |
| 804 | // GetWindowContainer(). |
| 805 | TEST_F(VirtualKeyboardRootWindowControllerTest, |
| 806 | DeleteOldContainerOnVirtualKeyboardInit) { |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 807 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 808 | aura::Window* keyboard_container = |
| 809 | Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
[email protected] | 45c6667 | 2013-10-01 22:48:56 | [diff] [blame] | 810 | ASSERT_TRUE(keyboard_container); |
| 811 | // Track the keyboard container window. |
| 812 | aura::WindowTracker tracker; |
| 813 | tracker.Add(keyboard_container); |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 814 | // Mock a login user profile change to reinitialize the keyboard. |
| 815 | ash::Shell::GetInstance()->OnLoginUserProfilePrepared(); |
[email protected] | 45c6667 | 2013-10-01 22:48:56 | [diff] [blame] | 816 | // keyboard_container should no longer be present. |
| 817 | EXPECT_FALSE(tracker.Contains(keyboard_container)); |
| 818 | } |
| 819 | |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 820 | // Test for crbug.com/342524. After user login, the work space should restore to |
| 821 | // full screen. |
| 822 | TEST_F(VirtualKeyboardRootWindowControllerTest, RestoreWorkspaceAfterLogin) { |
| 823 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 824 | aura::Window* keyboard_container = |
| 825 | Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 826 | keyboard_container->Show(); |
| 827 | keyboard::KeyboardController* controller = |
[email protected] | a0b3fb88 | 2014-04-07 19:26:03 | [diff] [blame] | 828 | keyboard::KeyboardController::GetInstance(); |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 829 | aura::Window* keyboard_window = controller->proxy()->GetKeyboardWindow(); |
| 830 | keyboard_container->AddChild(keyboard_window); |
| 831 | keyboard_window->set_owned_by_parent(false); |
bshe | a0a5780 | 2015-04-08 18:21:29 | [diff] [blame] | 832 | keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds( |
| 833 | root_window->bounds(), 100)); |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 834 | keyboard_window->Show(); |
| 835 | |
| 836 | gfx::Rect before = ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); |
| 837 | |
| 838 | // Notify keyboard bounds changing. |
bshe | a0a5780 | 2015-04-08 18:21:29 | [diff] [blame] | 839 | controller->NotifyKeyboardBoundsChanging(keyboard_container->bounds()); |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 840 | |
[email protected] | 25df7ad | 2014-04-30 18:10:25 | [diff] [blame] | 841 | if (!keyboard::IsKeyboardOverscrollEnabled()) { |
| 842 | gfx::Rect after = ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); |
| 843 | EXPECT_LT(after, before); |
| 844 | } |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 845 | |
| 846 | // Mock a login user profile change to reinitialize the keyboard. |
| 847 | ash::Shell::GetInstance()->OnLoginUserProfilePrepared(); |
| 848 | EXPECT_EQ(ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(), before); |
| 849 | } |
| 850 | |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 851 | // Ensure that system modal dialogs do not block events targeted at the virtual |
| 852 | // keyboard. |
| 853 | TEST_F(VirtualKeyboardRootWindowControllerTest, ClickWithActiveModalDialog) { |
| 854 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 855 | aura::Window* keyboard_container = |
| 856 | Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 857 | ASSERT_TRUE(keyboard_container); |
| 858 | keyboard_container->Show(); |
| 859 | |
[email protected] | a0b3fb88 | 2014-04-07 19:26:03 | [diff] [blame] | 860 | aura::Window* keyboard_window = keyboard::KeyboardController::GetInstance()-> |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 861 | proxy()->GetKeyboardWindow(); |
| 862 | keyboard_container->AddChild(keyboard_window); |
| 863 | keyboard_window->set_owned_by_parent(false); |
bshe | a0a5780 | 2015-04-08 18:21:29 | [diff] [blame] | 864 | keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds( |
| 865 | root_window->bounds(), 100)); |
[email protected] | 3193ea72 | 2014-04-23 22:19:19 | [diff] [blame] | 866 | |
| 867 | ui::test::TestEventHandler handler; |
| 868 | root_window->AddPreTargetHandler(&handler); |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 869 | ui::test::EventGenerator root_window_event_generator(root_window); |
| 870 | ui::test::EventGenerator keyboard_event_generator(root_window, |
| 871 | keyboard_window); |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 872 | |
| 873 | views::Widget* modal_widget = |
| 874 | CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
| 875 | |
| 876 | // Verify that mouse events to the root window are block with a visble modal |
| 877 | // dialog. |
| 878 | root_window_event_generator.ClickLeftButton(); |
[email protected] | 3193ea72 | 2014-04-23 22:19:19 | [diff] [blame] | 879 | EXPECT_EQ(0, handler.num_mouse_events()); |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 880 | |
| 881 | // Verify that event dispatch to the virtual keyboard is unblocked. |
| 882 | keyboard_event_generator.ClickLeftButton(); |
[email protected] | 3193ea72 | 2014-04-23 22:19:19 | [diff] [blame] | 883 | EXPECT_EQ(1, handler.num_mouse_events() / 2); |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 884 | |
| 885 | modal_widget->Close(); |
| 886 | |
| 887 | // Verify that mouse events are now unblocked to the root window. |
| 888 | root_window_event_generator.ClickLeftButton(); |
[email protected] | 3193ea72 | 2014-04-23 22:19:19 | [diff] [blame] | 889 | EXPECT_EQ(2, handler.num_mouse_events() / 2); |
| 890 | root_window->RemovePreTargetHandler(&handler); |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 891 | } |
| 892 | |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 893 | // Ensure that the visible area for scrolling the text caret excludes the |
| 894 | // region occluded by the on-screen keyboard. |
| 895 | TEST_F(VirtualKeyboardRootWindowControllerTest, EnsureCaretInWorkArea) { |
| 896 | keyboard::KeyboardController* keyboard_controller = |
| 897 | keyboard::KeyboardController::GetInstance(); |
| 898 | keyboard::KeyboardControllerProxy* proxy = keyboard_controller->proxy(); |
| 899 | |
| 900 | MockTextInputClient text_input_client; |
| 901 | ui::InputMethod* input_method = proxy->GetInputMethod(); |
| 902 | ASSERT_TRUE(input_method); |
[email protected] | 00a38679 | 2014-06-16 15:09:20 | [diff] [blame] | 903 | if (switches::IsTextInputFocusManagerEnabled()) { |
| 904 | ui::TextInputFocusManager::GetInstance()->FocusTextInputClient( |
| 905 | &text_input_client); |
| 906 | } else { |
| 907 | input_method->SetFocusedTextInputClient(&text_input_client); |
| 908 | } |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 909 | |
| 910 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 911 | aura::Window* keyboard_container = |
| 912 | Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
| 913 | ASSERT_TRUE(keyboard_container); |
| 914 | keyboard_container->Show(); |
| 915 | |
| 916 | const int keyboard_height = 100; |
| 917 | aura::Window* keyboard_window =proxy->GetKeyboardWindow(); |
| 918 | keyboard_container->AddChild(keyboard_window); |
| 919 | keyboard_window->set_owned_by_parent(false); |
bshe | a0a5780 | 2015-04-08 18:21:29 | [diff] [blame] | 920 | keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds( |
| 921 | root_window->bounds(), keyboard_height)); |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 922 | |
| 923 | proxy->EnsureCaretInWorkArea(); |
bshe | a0a5780 | 2015-04-08 18:21:29 | [diff] [blame] | 924 | ASSERT_EQ(root_window->bounds().width(), |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 925 | text_input_client.visible_rect().width()); |
bshe | a0a5780 | 2015-04-08 18:21:29 | [diff] [blame] | 926 | ASSERT_EQ(root_window->bounds().height() - keyboard_height, |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 927 | text_input_client.visible_rect().height()); |
[email protected] | 00a38679 | 2014-06-16 15:09:20 | [diff] [blame] | 928 | |
| 929 | if (switches::IsTextInputFocusManagerEnabled()) { |
| 930 | ui::TextInputFocusManager::GetInstance()->BlurTextInputClient( |
| 931 | &text_input_client); |
| 932 | } else { |
| 933 | input_method->SetFocusedTextInputClient(NULL); |
| 934 | } |
[email protected] | 2082d7d | 2014-05-13 14:44:23 | [diff] [blame] | 935 | } |
| 936 | |
kevers | 23f3987d | 2014-09-17 13:50:12 | [diff] [blame] | 937 | // Tests that the virtual keyboard does not block context menus. The virtual |
| 938 | // keyboard should appear in front of most content, but not context menus. See |
| 939 | // crbug/377180. |
| 940 | TEST_F(VirtualKeyboardRootWindowControllerTest, ZOrderTest) { |
| 941 | UpdateDisplay("800x600"); |
| 942 | keyboard::KeyboardController* keyboard_controller = |
| 943 | keyboard::KeyboardController::GetInstance(); |
| 944 | keyboard::KeyboardControllerProxy* proxy = keyboard_controller->proxy(); |
| 945 | |
| 946 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 947 | aura::Window* keyboard_container = |
| 948 | Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
| 949 | ASSERT_TRUE(keyboard_container); |
| 950 | keyboard_container->Show(); |
| 951 | |
| 952 | const int keyboard_height = 200; |
| 953 | aura::Window* keyboard_window = proxy->GetKeyboardWindow(); |
| 954 | keyboard_container->AddChild(keyboard_window); |
| 955 | keyboard_window->set_owned_by_parent(false); |
bshe | a0a5780 | 2015-04-08 18:21:29 | [diff] [blame] | 956 | gfx::Rect keyboard_bounds = keyboard::FullWidthKeyboardBoundsFromRootBounds( |
| 957 | root_window->bounds(), keyboard_height); |
kevers | 23f3987d | 2014-09-17 13:50:12 | [diff] [blame] | 958 | keyboard_window->SetBounds(keyboard_bounds); |
| 959 | keyboard_window->Show(); |
| 960 | |
| 961 | ui::test::EventGenerator generator(root_window); |
| 962 | |
| 963 | // Cover the screen with two windows: a normal window on the left side and a |
| 964 | // context menu on the right side. When the virtual keyboard is displayed it |
| 965 | // partially occludes the normal window, but not the context menu. Compute |
| 966 | // positions for generating synthetic click events to perform hit tests, |
| 967 | // ensuring the correct window layering. 'top' is above the VK, whereas |
| 968 | // 'bottom' lies within the VK. 'left' is centered in the normal window, and |
| 969 | // 'right' is centered in the context menu. |
| 970 | int window_height = keyboard_bounds.bottom(); |
| 971 | int window_width = keyboard_bounds.width() / 2; |
| 972 | int left = window_width / 2; |
| 973 | int right = 3 * window_width / 2; |
| 974 | int top = keyboard_bounds.y() / 2; |
| 975 | int bottom = window_height - keyboard_height / 2; |
| 976 | |
| 977 | // Normal window is partially occluded by the virtual keyboard. |
| 978 | aura::test::TestWindowDelegate delegate; |
| 979 | scoped_ptr<aura::Window> normal(CreateTestWindowInShellWithDelegateAndType( |
| 980 | &delegate, |
| 981 | ui::wm::WINDOW_TYPE_NORMAL, |
| 982 | 0, |
| 983 | gfx::Rect(0, 0, window_width, window_height))); |
| 984 | normal->set_owned_by_parent(false); |
| 985 | normal->Show(); |
| 986 | TargetHitTestEventHandler normal_handler; |
| 987 | normal->AddPreTargetHandler(&normal_handler); |
| 988 | |
| 989 | // Test that only the click on the top portion of the window is picked up. The |
| 990 | // click on the bottom hits the virtual keyboard instead. |
| 991 | generator.MoveMouseTo(left, top); |
| 992 | generator.ClickLeftButton(); |
| 993 | EXPECT_EQ(1, normal_handler.num_mouse_events()); |
| 994 | generator.MoveMouseTo(left, bottom); |
| 995 | generator.ClickLeftButton(); |
| 996 | EXPECT_EQ(1, normal_handler.num_mouse_events()); |
| 997 | |
| 998 | // Menu overlaps virtual keyboard. |
| 999 | aura::test::TestWindowDelegate delegate2; |
| 1000 | scoped_ptr<aura::Window> menu(CreateTestWindowInShellWithDelegateAndType( |
| 1001 | &delegate2, |
| 1002 | ui::wm::WINDOW_TYPE_MENU, |
| 1003 | 0, |
| 1004 | gfx::Rect(window_width, 0, window_width, window_height))); |
| 1005 | menu->set_owned_by_parent(false); |
| 1006 | menu->Show(); |
| 1007 | TargetHitTestEventHandler menu_handler; |
| 1008 | menu->AddPreTargetHandler(&menu_handler); |
| 1009 | |
| 1010 | // Test that both clicks register. |
| 1011 | generator.MoveMouseTo(right, top); |
| 1012 | generator.ClickLeftButton(); |
| 1013 | EXPECT_EQ(1, menu_handler.num_mouse_events()); |
| 1014 | generator.MoveMouseTo(right, bottom); |
| 1015 | generator.ClickLeftButton(); |
| 1016 | EXPECT_EQ(2, menu_handler.num_mouse_events()); |
| 1017 | |
| 1018 | // Cleanup to ensure that the test windows are destroyed before their |
| 1019 | // delegates. |
| 1020 | normal.reset(); |
| 1021 | menu.reset(); |
| 1022 | } |
| 1023 | |
kevers | 0e45049 | 2014-09-30 16:02:31 | [diff] [blame] | 1024 | // Resolution in UpdateDisplay is not being respected on Windows 8. |
| 1025 | #if defined(OS_WIN) |
| 1026 | #define MAYBE_DisplayRotation DISABLED_DisplayRotation |
| 1027 | #else |
| 1028 | #define MAYBE_DisplayRotation DisplayRotation |
| 1029 | #endif |
| 1030 | |
| 1031 | // Tests that the virtual keyboard correctly resizes with a change to display |
| 1032 | // orientation. See crbug/417612. |
| 1033 | TEST_F(VirtualKeyboardRootWindowControllerTest, MAYBE_DisplayRotation) { |
| 1034 | UpdateDisplay("800x600"); |
| 1035 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 1036 | aura::Window* keyboard_container = |
| 1037 | Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
| 1038 | ASSERT_TRUE(keyboard_container); |
bshe | a0a5780 | 2015-04-08 18:21:29 | [diff] [blame] | 1039 | keyboard::KeyboardController* keyboard_controller = |
| 1040 | keyboard::KeyboardController::GetInstance(); |
| 1041 | keyboard_controller->ShowKeyboard(false); |
| 1042 | keyboard_controller->proxy()->GetKeyboardWindow()->SetBounds( |
| 1043 | gfx::Rect(0, 400, 800, 200)); |
| 1044 | EXPECT_EQ("0,400 800x200", keyboard_container->bounds().ToString()); |
kevers | 0e45049 | 2014-09-30 16:02:31 | [diff] [blame] | 1045 | |
| 1046 | UpdateDisplay("600x800"); |
bshe | a0a5780 | 2015-04-08 18:21:29 | [diff] [blame] | 1047 | EXPECT_EQ("0,600 600x200", keyboard_container->bounds().ToString()); |
kevers | 0e45049 | 2014-09-30 16:02:31 | [diff] [blame] | 1048 | } |
| 1049 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 1050 | } // namespace test |
| 1051 | } // namespace ash |