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