[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] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 7 | #include "ash/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" |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 18 | #include "ui/aura/client/focus_change_observer.h" |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 19 | #include "ui/aura/client/focus_client.h" |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 20 | #include "ui/aura/client/window_tree_client.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 21 | #include "ui/aura/env.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 22 | #include "ui/aura/test/event_generator.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] | cd9f71d | 2014-03-20 21:54:21 | [diff] [blame] | 28 | #include "ui/events/test/test_event_handler.h" |
[email protected] | 647b484 | 2013-12-12 14:24:24 | [diff] [blame] | 29 | #include "ui/keyboard/keyboard_controller_proxy.h" |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 30 | #include "ui/keyboard/keyboard_switches.h" |
[email protected] | 39e9521 | 2014-04-23 20:00:01 | [diff] [blame^] | 31 | #include "ui/keyboard/keyboard_util.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 32 | #include "ui/views/controls/menu/menu_controller.h" |
| 33 | #include "ui/views/widget/widget.h" |
| 34 | #include "ui/views/widget/widget_delegate.h" |
| 35 | |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 36 | using aura::Window; |
| 37 | using views::Widget; |
| 38 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 39 | namespace ash { |
| 40 | namespace { |
| 41 | |
| 42 | class TestDelegate : public views::WidgetDelegateView { |
| 43 | public: |
| 44 | explicit TestDelegate(bool system_modal) : system_modal_(system_modal) {} |
| 45 | virtual ~TestDelegate() {} |
| 46 | |
| 47 | // Overridden from views::WidgetDelegate: |
| 48 | virtual views::View* GetContentsView() OVERRIDE { |
| 49 | return this; |
| 50 | } |
| 51 | |
| 52 | virtual ui::ModalType GetModalType() const OVERRIDE { |
| 53 | return system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE; |
| 54 | } |
| 55 | |
| 56 | private: |
| 57 | bool system_modal_; |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 58 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 59 | DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
| 60 | }; |
| 61 | |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 62 | class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate, |
| 63 | public aura::client::FocusChangeObserver { |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 64 | public: |
| 65 | DeleteOnBlurDelegate() : window_(NULL) {} |
| 66 | virtual ~DeleteOnBlurDelegate() {} |
| 67 | |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 68 | void SetWindow(aura::Window* window) { |
| 69 | window_ = window; |
| 70 | aura::client::SetFocusChangeObserver(window_, this); |
| 71 | } |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 72 | |
[email protected] | 869f635 | 2012-12-06 20:47:17 | [diff] [blame] | 73 | private: |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 74 | // aura::test::TestWindowDelegate overrides: |
| 75 | virtual bool CanFocus() OVERRIDE { |
| 76 | return true; |
| 77 | } |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 78 | |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 79 | // aura::client::FocusChangeObserver implementation: |
| 80 | virtual void OnWindowFocused(aura::Window* gained_focus, |
| 81 | aura::Window* lost_focus) OVERRIDE { |
| 82 | if (window_ == lost_focus) |
| 83 | delete window_; |
[email protected] | 869f635 | 2012-12-06 20:47:17 | [diff] [blame] | 84 | } |
| 85 | |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 86 | aura::Window* window_; |
| 87 | |
| 88 | DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate); |
| 89 | }; |
| 90 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 91 | } // namespace |
| 92 | |
| 93 | namespace test { |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 94 | |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 95 | class RootWindowControllerTest : public test::AshTestBase { |
| 96 | public: |
| 97 | views::Widget* CreateTestWidget(const gfx::Rect& bounds) { |
| 98 | views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 99 | NULL, CurrentContext(), bounds); |
| 100 | widget->Show(); |
| 101 | return widget; |
| 102 | } |
| 103 | |
| 104 | views::Widget* CreateModalWidget(const gfx::Rect& bounds) { |
| 105 | views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 106 | new TestDelegate(true), CurrentContext(), bounds); |
| 107 | widget->Show(); |
| 108 | return widget; |
| 109 | } |
| 110 | |
| 111 | views::Widget* CreateModalWidgetWithParent(const gfx::Rect& bounds, |
| 112 | gfx::NativeWindow parent) { |
| 113 | views::Widget* widget = |
| 114 | views::Widget::CreateWindowWithParentAndBounds(new TestDelegate(true), |
| 115 | parent, |
| 116 | bounds); |
| 117 | widget->Show(); |
| 118 | return widget; |
| 119 | } |
| 120 | |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 121 | aura::Window* GetModalContainer(aura::Window* root_window) { |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 122 | return Shell::GetContainer(root_window, |
| 123 | ash::kShellWindowId_SystemModalContainer); |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 124 | } |
| 125 | }; |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 126 | |
[email protected] | e75642a | 2013-06-12 17:21:18 | [diff] [blame] | 127 | TEST_F(RootWindowControllerTest, MoveWindows_Basic) { |
| 128 | if (!SupportsMultipleDisplays()) |
| 129 | return; |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 130 | // Windows origin should be doubled when moved to the 1st display. |
| 131 | UpdateDisplay("600x600,300x300"); |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 132 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 133 | RootWindowController* controller = Shell::GetPrimaryRootWindowController(); |
| 134 | ShelfLayoutManager* shelf_layout_manager = |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 135 | controller->GetShelfLayoutManager(); |
| 136 | shelf_layout_manager->SetAutoHideBehavior( |
| 137 | ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 138 | |
| 139 | views::Widget* normal = CreateTestWidget(gfx::Rect(650, 10, 100, 100)); |
| 140 | EXPECT_EQ(root_windows[1], normal->GetNativeView()->GetRootWindow()); |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 141 | EXPECT_EQ("650,10 100x100", normal->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 142 | EXPECT_EQ("50,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 143 | normal->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 144 | |
| 145 | views::Widget* maximized = CreateTestWidget(gfx::Rect(700, 10, 100, 100)); |
| 146 | maximized->Maximize(); |
| 147 | EXPECT_EQ(root_windows[1], maximized->GetNativeView()->GetRootWindow()); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 148 | EXPECT_EQ("600,0 300x253", maximized->GetWindowBoundsInScreen().ToString()); |
| 149 | EXPECT_EQ("0,0 300x253", |
[email protected] | 8c0ec43 | 2013-05-10 04:33:39 | [diff] [blame] | 150 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 151 | |
| 152 | views::Widget* minimized = CreateTestWidget(gfx::Rect(800, 10, 100, 100)); |
| 153 | minimized->Minimize(); |
| 154 | EXPECT_EQ(root_windows[1], minimized->GetNativeView()->GetRootWindow()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 155 | EXPECT_EQ("800,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 156 | minimized->GetWindowBoundsInScreen().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 157 | |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 158 | views::Widget* fullscreen = CreateTestWidget(gfx::Rect(850, 10, 100, 100)); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 159 | fullscreen->SetFullscreen(true); |
| 160 | EXPECT_EQ(root_windows[1], fullscreen->GetNativeView()->GetRootWindow()); |
[email protected] | 1a01538 | 2012-12-01 19:44:59 | [diff] [blame] | 161 | |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 162 | EXPECT_EQ("600,0 300x300", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 163 | fullscreen->GetWindowBoundsInScreen().ToString()); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 164 | EXPECT_EQ("0,0 300x300", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 165 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 166 | |
[email protected] | 8f2f15141 | 2013-01-26 03:58:37 | [diff] [blame] | 167 | views::Widget* unparented_control = new Widget; |
| 168 | Widget::InitParams params; |
| 169 | params.bounds = gfx::Rect(650, 10, 100, 100); |
| 170 | params.context = CurrentContext(); |
| 171 | params.type = Widget::InitParams::TYPE_CONTROL; |
| 172 | unparented_control->Init(params); |
| 173 | EXPECT_EQ(root_windows[1], |
| 174 | unparented_control->GetNativeView()->GetRootWindow()); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 175 | EXPECT_EQ(kShellWindowId_UnparentedControlContainer, |
[email protected] | 8f2f15141 | 2013-01-26 03:58:37 | [diff] [blame] | 176 | unparented_control->GetNativeView()->parent()->id()); |
| 177 | |
[email protected] | 95db9c1 | 2013-01-31 11:47:44 | [diff] [blame] | 178 | aura::Window* panel = CreateTestWindowInShellWithDelegateAndType( |
[email protected] | 5b251f1 | 2013-12-19 01:50:05 | [diff] [blame] | 179 | NULL, ui::wm::WINDOW_TYPE_PANEL, 0, gfx::Rect(700, 100, 100, 100)); |
[email protected] | 95db9c1 | 2013-01-31 11:47:44 | [diff] [blame] | 180 | EXPECT_EQ(root_windows[1], panel->GetRootWindow()); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 181 | EXPECT_EQ(kShellWindowId_PanelContainer, panel->parent()->id()); |
[email protected] | 95db9c1 | 2013-01-31 11:47:44 | [diff] [blame] | 182 | |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 183 | // Make sure a window that will delete itself when losing focus |
| 184 | // will not crash. |
| 185 | aura::WindowTracker tracker; |
| 186 | DeleteOnBlurDelegate delete_on_blur_delegate; |
[email protected] | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 187 | aura::Window* d2 = CreateTestWindowInShellWithDelegate( |
| 188 | &delete_on_blur_delegate, 0, gfx::Rect(50, 50, 100, 100)); |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 189 | delete_on_blur_delegate.SetWindow(d2); |
[email protected] | 550543e | 2013-01-11 22:43:44 | [diff] [blame] | 190 | aura::client::GetFocusClient(root_windows[0])->FocusWindow(d2); |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 191 | tracker.Add(d2); |
| 192 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 193 | UpdateDisplay("600x600"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 194 | |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 195 | // d2 must have been deleted. |
| 196 | EXPECT_FALSE(tracker.Contains(d2)); |
| 197 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 198 | EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow()); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 199 | EXPECT_EQ("100,20 100x100", normal->GetWindowBoundsInScreen().ToString()); |
| 200 | EXPECT_EQ("100,20 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 201 | normal->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 202 | |
[email protected] | eefd51b2 | 2012-09-25 20:26:24 | [diff] [blame] | 203 | // Maximized area on primary display has 3px (given as |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 204 | // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom. |
[email protected] | 2a64b0a | 2013-07-23 23:15:54 | [diff] [blame] | 205 | |
| 206 | // First clear fullscreen status, since both fullscreen and maximized windows |
| 207 | // share the same desktop workspace, which cancels the shelf status. |
| 208 | fullscreen->SetFullscreen(false); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 209 | EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow()); |
[email protected] | 7b675df61 | 2012-09-16 18:33:20 | [diff] [blame] | 210 | EXPECT_EQ("0,0 600x597", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 211 | maximized->GetWindowBoundsInScreen().ToString()); |
[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->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 214 | |
[email protected] | 2a64b0a | 2013-07-23 23:15:54 | [diff] [blame] | 215 | // Set fullscreen to true. In that case the 3px inset becomes invisible so |
| 216 | // the maximized window can also use the area fully. |
| 217 | fullscreen->SetFullscreen(true); |
| 218 | EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow()); |
| 219 | EXPECT_EQ("0,0 600x600", |
| 220 | maximized->GetWindowBoundsInScreen().ToString()); |
| 221 | EXPECT_EQ("0,0 600x600", |
| 222 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
| 223 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 224 | EXPECT_EQ(root_windows[0], minimized->GetNativeView()->GetRootWindow()); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 225 | EXPECT_EQ("400,20 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 226 | minimized->GetWindowBoundsInScreen().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 227 | |
| 228 | EXPECT_EQ(root_windows[0], fullscreen->GetNativeView()->GetRootWindow()); |
| 229 | EXPECT_TRUE(fullscreen->IsFullscreen()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 230 | EXPECT_EQ("0,0 600x600", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 231 | fullscreen->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 232 | EXPECT_EQ("0,0 600x600", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 233 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 234 | |
| 235 | // Test if the restore bounds are correctly updated. |
[email protected] | a41b4e1 | 2013-09-20 04:36:34 | [diff] [blame] | 236 | wm::GetWindowState(maximized->GetNativeView())->Restore(); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 237 | EXPECT_EQ("200,20 100x100", maximized->GetWindowBoundsInScreen().ToString()); |
| 238 | EXPECT_EQ("200,20 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 239 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 240 | |
| 241 | fullscreen->SetFullscreen(false); |
[email protected] | 2816c246 | 2013-12-17 02:22:25 | [diff] [blame] | 242 | EXPECT_EQ("500,20 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 243 | fullscreen->GetWindowBoundsInScreen().ToString()); |
[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->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | 8f2f15141 | 2013-01-26 03:58:37 | [diff] [blame] | 246 | |
| 247 | // Test if the unparented widget has moved. |
| 248 | EXPECT_EQ(root_windows[0], |
| 249 | unparented_control->GetNativeView()->GetRootWindow()); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 250 | EXPECT_EQ(kShellWindowId_UnparentedControlContainer, |
[email protected] | 8f2f15141 | 2013-01-26 03:58:37 | [diff] [blame] | 251 | unparented_control->GetNativeView()->parent()->id()); |
[email protected] | 95db9c1 | 2013-01-31 11:47:44 | [diff] [blame] | 252 | |
| 253 | // Test if the panel has moved. |
| 254 | EXPECT_EQ(root_windows[0], panel->GetRootWindow()); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 255 | EXPECT_EQ(kShellWindowId_PanelContainer, panel->parent()->id()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 256 | } |
| 257 | |
[email protected] | e75642a | 2013-06-12 17:21:18 | [diff] [blame] | 258 | TEST_F(RootWindowControllerTest, MoveWindows_Modal) { |
| 259 | if (!SupportsMultipleDisplays()) |
| 260 | return; |
[email protected] | 1c3f700 | 2013-01-21 18:46:05 | [diff] [blame] | 261 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 262 | UpdateDisplay("500x500,500x500"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 263 | |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 264 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 265 | // Emulate virtual screen coordinate system. |
| 266 | root_windows[0]->SetBounds(gfx::Rect(0, 0, 500, 500)); |
| 267 | root_windows[1]->SetBounds(gfx::Rect(500, 0, 500, 500)); |
| 268 | |
| 269 | views::Widget* normal = CreateTestWidget(gfx::Rect(300, 10, 100, 100)); |
| 270 | EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow()); |
| 271 | EXPECT_TRUE(wm::IsActiveWindow(normal->GetNativeView())); |
| 272 | |
| 273 | views::Widget* modal = CreateModalWidget(gfx::Rect(650, 10, 100, 100)); |
| 274 | EXPECT_EQ(root_windows[1], modal->GetNativeView()->GetRootWindow()); |
| 275 | EXPECT_TRUE(GetModalContainer(root_windows[1])->Contains( |
| 276 | modal->GetNativeView())); |
| 277 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 278 | |
| 279 | aura::test::EventGenerator generator_1st(root_windows[0]); |
| 280 | generator_1st.ClickLeftButton(); |
| 281 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 282 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 283 | UpdateDisplay("500x500"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 284 | EXPECT_EQ(root_windows[0], modal->GetNativeView()->GetRootWindow()); |
| 285 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 286 | generator_1st.ClickLeftButton(); |
| 287 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 288 | } |
| 289 | |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 290 | TEST_F(RootWindowControllerTest, ModalContainer) { |
| 291 | UpdateDisplay("600x600"); |
| 292 | Shell* shell = Shell::GetInstance(); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 293 | RootWindowController* controller = shell->GetPrimaryRootWindowController(); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 294 | EXPECT_EQ(user::LOGGED_IN_USER, |
[email protected] | 945f9cae | 2012-12-12 09:54:29 | [diff] [blame] | 295 | shell->system_tray_delegate()->GetUserLoginStatus()); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 296 | EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 297 | ->layout_manager(), |
| 298 | controller->GetSystemModalLayoutManager(NULL)); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 299 | |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 300 | views::Widget* session_modal_widget = |
| 301 | CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 302 | EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 303 | ->layout_manager(), |
| 304 | controller->GetSystemModalLayoutManager( |
| 305 | session_modal_widget->GetNativeView())); |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 306 | |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 307 | shell->session_state_delegate()->LockScreen(); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 308 | EXPECT_EQ(user::LOGGED_IN_LOCKED, |
[email protected] | 945f9cae | 2012-12-12 09:54:29 | [diff] [blame] | 309 | shell->system_tray_delegate()->GetUserLoginStatus()); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 310 | EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 311 | ->layout_manager(), |
| 312 | controller->GetSystemModalLayoutManager(NULL)); |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 313 | |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 314 | aura::Window* lock_container = |
| 315 | controller->GetContainer(kShellWindowId_LockScreenContainer); |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 316 | views::Widget* lock_modal_widget = |
| 317 | CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 318 | EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 319 | ->layout_manager(), |
| 320 | controller->GetSystemModalLayoutManager( |
| 321 | lock_modal_widget->GetNativeView())); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 322 | EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 323 | ->layout_manager(), |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 324 | controller->GetSystemModalLayoutManager( |
| 325 | session_modal_widget->GetNativeView())); |
| 326 | |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 327 | shell->session_state_delegate()->UnlockScreen(); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 328 | } |
| 329 | |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 330 | TEST_F(RootWindowControllerTest, ModalContainerNotLoggedInLoggedIn) { |
| 331 | UpdateDisplay("600x600"); |
| 332 | Shell* shell = Shell::GetInstance(); |
| 333 | |
| 334 | // Configure login screen environment. |
| 335 | SetUserLoggedIn(false); |
| 336 | EXPECT_EQ(user::LOGGED_IN_NONE, |
[email protected] | 945f9cae | 2012-12-12 09:54:29 | [diff] [blame] | 337 | shell->system_tray_delegate()->GetUserLoginStatus()); |
[email protected] | c8d19f8 | 2013-05-18 09:09:41 | [diff] [blame] | 338 | EXPECT_EQ(0, shell->session_state_delegate()->NumberOfLoggedInUsers()); |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 339 | EXPECT_FALSE(shell->session_state_delegate()->IsActiveUserSessionStarted()); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 340 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 341 | RootWindowController* controller = shell->GetPrimaryRootWindowController(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 342 | EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 343 | ->layout_manager(), |
| 344 | controller->GetSystemModalLayoutManager(NULL)); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 345 | |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 346 | aura::Window* lock_container = |
| 347 | controller->GetContainer(kShellWindowId_LockScreenContainer); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 348 | views::Widget* login_modal_widget = |
| 349 | CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 350 | EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 351 | ->layout_manager(), |
| 352 | controller->GetSystemModalLayoutManager( |
| 353 | login_modal_widget->GetNativeView())); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 354 | login_modal_widget->Close(); |
| 355 | |
| 356 | // Configure user session environment. |
| 357 | SetUserLoggedIn(true); |
| 358 | SetSessionStarted(true); |
| 359 | EXPECT_EQ(user::LOGGED_IN_USER, |
[email protected] | 945f9cae | 2012-12-12 09:54:29 | [diff] [blame] | 360 | shell->system_tray_delegate()->GetUserLoginStatus()); |
[email protected] | c8d19f8 | 2013-05-18 09:09:41 | [diff] [blame] | 361 | EXPECT_EQ(1, shell->session_state_delegate()->NumberOfLoggedInUsers()); |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 362 | EXPECT_TRUE(shell->session_state_delegate()->IsActiveUserSessionStarted()); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 363 | EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 364 | ->layout_manager(), |
| 365 | controller->GetSystemModalLayoutManager(NULL)); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 366 | |
| 367 | views::Widget* session_modal_widget = |
| 368 | CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 369 | EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 370 | ->layout_manager(), |
| 371 | controller->GetSystemModalLayoutManager( |
| 372 | session_modal_widget->GetNativeView())); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 373 | } |
| 374 | |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 375 | TEST_F(RootWindowControllerTest, ModalContainerBlockedSession) { |
| 376 | UpdateDisplay("600x600"); |
| 377 | Shell* shell = Shell::GetInstance(); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 378 | RootWindowController* controller = shell->GetPrimaryRootWindowController(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 379 | aura::Window* lock_container = |
| 380 | controller->GetContainer(kShellWindowId_LockScreenContainer); |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 381 | for (int block_reason = FIRST_BLOCK_REASON; |
| 382 | block_reason < NUMBER_OF_BLOCK_REASONS; |
| 383 | ++block_reason) { |
| 384 | views::Widget* session_modal_widget = |
| 385 | CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 386 | EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 387 | ->layout_manager(), |
| 388 | controller->GetSystemModalLayoutManager( |
| 389 | session_modal_widget->GetNativeView())); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 390 | EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 391 | ->layout_manager(), |
| 392 | controller->GetSystemModalLayoutManager(NULL)); |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 393 | session_modal_widget->Close(); |
| 394 | |
| 395 | BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 396 | |
[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] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 400 | |
| 401 | views::Widget* lock_modal_widget = |
| 402 | CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), |
| 403 | lock_container); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 404 | EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 405 | ->layout_manager(), |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 406 | controller->GetSystemModalLayoutManager( |
| 407 | lock_modal_widget->GetNativeView())); |
| 408 | |
| 409 | session_modal_widget = |
| 410 | CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 411 | EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 412 | ->layout_manager(), |
| 413 | controller->GetSystemModalLayoutManager( |
| 414 | session_modal_widget->GetNativeView())); |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 415 | session_modal_widget->Close(); |
| 416 | |
| 417 | lock_modal_widget->Close(); |
| 418 | UnblockUserSession(); |
| 419 | } |
| 420 | } |
| 421 | |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 422 | TEST_F(RootWindowControllerTest, GetWindowForFullscreenMode) { |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 423 | UpdateDisplay("600x600"); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 424 | RootWindowController* controller = |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 425 | Shell::GetInstance()->GetPrimaryRootWindowController(); |
| 426 | |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 427 | Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 428 | w1->Maximize(); |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 429 | Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
| 430 | w2->SetFullscreen(true); |
| 431 | // |w3| is a transient child of |w2|. |
| 432 | Widget* w3 = Widget::CreateWindowWithParentAndBounds(NULL, |
| 433 | w2->GetNativeWindow(), gfx::Rect(0, 0, 100, 100)); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 434 | |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 435 | // Test that GetWindowForFullscreenMode() finds the fullscreen window when one |
[email protected] | e3bc88e | 2013-09-06 06:22:06 | [diff] [blame] | 436 | // of its transient children is active. |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 437 | w3->Activate(); |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 438 | EXPECT_EQ(w2->GetNativeWindow(), controller->GetWindowForFullscreenMode()); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 439 | |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 440 | // If the topmost window is not fullscreen, it returns NULL. |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 441 | w1->Activate(); |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 442 | EXPECT_EQ(NULL, controller->GetWindowForFullscreenMode()); |
| 443 | w1->Close(); |
| 444 | w3->Close(); |
[email protected] | e3bc88e | 2013-09-06 06:22:06 | [diff] [blame] | 445 | |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 446 | // Only w2 remains, if minimized GetWindowForFullscreenMode should return |
| 447 | // NULL. |
[email protected] | e3bc88e | 2013-09-06 06:22:06 | [diff] [blame] | 448 | w2->Activate(); |
[email protected] | 2c9171d2 | 2013-12-10 21:55:10 | [diff] [blame] | 449 | EXPECT_EQ(w2->GetNativeWindow(), controller->GetWindowForFullscreenMode()); |
| 450 | w2->Minimize(); |
| 451 | EXPECT_EQ(NULL, controller->GetWindowForFullscreenMode()); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 452 | } |
| 453 | |
[email protected] | 2c5db9e | 2014-02-27 13:58:14 | [diff] [blame] | 454 | TEST_F(RootWindowControllerTest, MultipleDisplaysGetWindowForFullscreenMode) { |
| 455 | if (!SupportsMultipleDisplays()) |
| 456 | return; |
| 457 | |
| 458 | UpdateDisplay("600x600,600x600"); |
| 459 | Shell::RootWindowControllerList controllers = |
| 460 | Shell::GetInstance()->GetAllRootWindowControllers(); |
| 461 | |
| 462 | Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
| 463 | w1->Maximize(); |
| 464 | Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
| 465 | w2->SetFullscreen(true); |
| 466 | Widget* w3 = CreateTestWidget(gfx::Rect(600, 0, 100, 100)); |
| 467 | |
| 468 | EXPECT_EQ(w1->GetNativeWindow()->GetRootWindow(), |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 469 | controllers[0]->GetRootWindow()); |
[email protected] | 2c5db9e | 2014-02-27 13:58:14 | [diff] [blame] | 470 | EXPECT_EQ(w2->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(w3->GetNativeWindow()->GetRootWindow(), |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 473 | controllers[1]->GetRootWindow()); |
[email protected] | 2c5db9e | 2014-02-27 13:58:14 | [diff] [blame] | 474 | |
| 475 | w1->Activate(); |
| 476 | EXPECT_EQ(NULL, controllers[0]->GetWindowForFullscreenMode()); |
| 477 | EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode()); |
| 478 | |
| 479 | w2->Activate(); |
| 480 | EXPECT_EQ(w2->GetNativeWindow(), |
| 481 | controllers[0]->GetWindowForFullscreenMode()); |
| 482 | EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode()); |
| 483 | |
| 484 | // Verify that the first root window controller remains in fullscreen mode |
| 485 | // when a window on the other display is activated. |
| 486 | w3->Activate(); |
| 487 | EXPECT_EQ(w2->GetNativeWindow(), |
| 488 | controllers[0]->GetWindowForFullscreenMode()); |
| 489 | EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode()); |
| 490 | } |
| 491 | |
[email protected] | 82ced235 | 2013-07-19 20:49:06 | [diff] [blame] | 492 | // Test that user session window can't be focused if user session blocked by |
| 493 | // some overlapping UI. |
| 494 | TEST_F(RootWindowControllerTest, FocusBlockedWindow) { |
| 495 | UpdateDisplay("600x600"); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 496 | RootWindowController* controller = |
[email protected] | 82ced235 | 2013-07-19 20:49:06 | [diff] [blame] | 497 | Shell::GetInstance()->GetPrimaryRootWindowController(); |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 498 | aura::Window* lock_container = |
| 499 | controller->GetContainer(kShellWindowId_LockScreenContainer); |
[email protected] | 82ced235 | 2013-07-19 20:49:06 | [diff] [blame] | 500 | aura::Window* lock_window = Widget::CreateWindowWithParentAndBounds(NULL, |
| 501 | lock_container, gfx::Rect(0, 0, 100, 100))->GetNativeView(); |
| 502 | lock_window->Show(); |
| 503 | aura::Window* session_window = |
| 504 | CreateTestWidget(gfx::Rect(0, 0, 100, 100))->GetNativeView(); |
| 505 | session_window->Show(); |
| 506 | |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 507 | for (int block_reason = FIRST_BLOCK_REASON; |
| 508 | block_reason < NUMBER_OF_BLOCK_REASONS; |
| 509 | ++block_reason) { |
| 510 | BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 511 | lock_window->Focus(); |
| 512 | EXPECT_TRUE(lock_window->HasFocus()); |
| 513 | session_window->Focus(); |
| 514 | EXPECT_FALSE(session_window->HasFocus()); |
| 515 | UnblockUserSession(); |
| 516 | } |
[email protected] | 82ced235 | 2013-07-19 20:49:06 | [diff] [blame] | 517 | } |
| 518 | |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 519 | // Tracks whether OnWindowDestroying() has been invoked. |
| 520 | class DestroyedWindowObserver : public aura::WindowObserver { |
| 521 | public: |
| 522 | DestroyedWindowObserver() : destroyed_(false), window_(NULL) {} |
| 523 | virtual ~DestroyedWindowObserver() { |
| 524 | Shutdown(); |
| 525 | } |
| 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: |
| 535 | virtual void OnWindowDestroying(Window* window) OVERRIDE { |
| 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] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 586 | aura::Window* root = Shell::GetPrimaryRootWindow(); |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 587 | const gfx::Size size = root->bounds().size(); |
| 588 | aura::Window* event_target = root->GetEventHandlerForPoint(gfx::Point(0, 0)); |
| 589 | EXPECT_TRUE(event_target); |
| 590 | EXPECT_EQ(event_target, |
| 591 | root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1))); |
| 592 | EXPECT_EQ(event_target, |
| 593 | root->GetEventHandlerForPoint(gfx::Point(size.width() - 1, 0))); |
| 594 | EXPECT_EQ(event_target, |
| 595 | root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1))); |
| 596 | EXPECT_EQ(event_target, |
| 597 | root->GetEventHandlerForPoint( |
| 598 | gfx::Point(size.width() - 1, size.height() - 1))); |
| 599 | } |
| 600 | |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 601 | class VirtualKeyboardRootWindowControllerTest : public RootWindowControllerTest |
| 602 | { |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 603 | public: |
| 604 | VirtualKeyboardRootWindowControllerTest() {}; |
| 605 | virtual ~VirtualKeyboardRootWindowControllerTest() {}; |
| 606 | |
| 607 | virtual void SetUp() OVERRIDE { |
| 608 | CommandLine::ForCurrentProcess()->AppendSwitch( |
| 609 | keyboard::switches::kEnableVirtualKeyboard); |
| 610 | test::AshTestBase::SetUp(); |
[email protected] | 24ca45d | 2013-10-25 03:37:44 | [diff] [blame] | 611 | Shell::GetPrimaryRootWindowController()->ActivateKeyboard( |
[email protected] | a0b3fb88 | 2014-04-07 19:26:03 | [diff] [blame] | 612 | keyboard::KeyboardController::GetInstance()); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | private: |
| 616 | DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest); |
| 617 | }; |
| 618 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 619 | // Test for http://crbug.com/297858. Virtual keyboard container should only show |
| 620 | // on primary root window. |
| 621 | TEST_F(VirtualKeyboardRootWindowControllerTest, |
| 622 | VirtualKeyboardOnPrimaryRootWindowOnly) { |
| 623 | if (!SupportsMultipleDisplays()) |
| 624 | return; |
| 625 | |
| 626 | UpdateDisplay("500x500,500x500"); |
| 627 | |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 628 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 629 | aura::Window* primary_root_window = Shell::GetPrimaryRootWindow(); |
| 630 | aura::Window* secondary_root_window = |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 631 | root_windows[0] == primary_root_window ? |
| 632 | root_windows[1] : root_windows[0]; |
| 633 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 634 | ASSERT_TRUE(Shell::GetContainer(primary_root_window, |
| 635 | kShellWindowId_VirtualKeyboardContainer)); |
| 636 | ASSERT_FALSE(Shell::GetContainer(secondary_root_window, |
| 637 | kShellWindowId_VirtualKeyboardContainer)); |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 638 | } |
| 639 | |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 640 | // Test for http://crbug.com/263599. Virtual keyboard should be able to receive |
| 641 | // events at blocked user session. |
| 642 | TEST_F(VirtualKeyboardRootWindowControllerTest, |
| 643 | ClickVirtualKeyboardInBlockedWindow) { |
[email protected] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 644 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 645 | aura::Window* keyboard_container = |
| 646 | Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 647 | ASSERT_TRUE(keyboard_container); |
| 648 | keyboard_container->Show(); |
| 649 | |
[email protected] | a0b3fb88 | 2014-04-07 19:26:03 | [diff] [blame] | 650 | aura::Window* keyboard_window = keyboard::KeyboardController::GetInstance()-> |
[email protected] | 647b484 | 2013-12-12 14:24:24 | [diff] [blame] | 651 | proxy()->GetKeyboardWindow(); |
| 652 | keyboard_container->AddChild(keyboard_window); |
[email protected] | 183e28d | 2014-01-20 18:18:02 | [diff] [blame] | 653 | keyboard_window->set_owned_by_parent(false); |
[email protected] | 647b484 | 2013-12-12 14:24:24 | [diff] [blame] | 654 | keyboard_window->SetBounds(gfx::Rect()); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 655 | keyboard_window->Show(); |
[email protected] | 647b484 | 2013-12-12 14:24:24 | [diff] [blame] | 656 | |
[email protected] | cd9f71d | 2014-03-20 21:54:21 | [diff] [blame] | 657 | ui::test::TestEventHandler* handler = new ui::test::TestEventHandler; |
[email protected] | 647b484 | 2013-12-12 14:24:24 | [diff] [blame] | 658 | root_window->SetEventFilter(handler); |
| 659 | |
| 660 | aura::test::EventGenerator event_generator(root_window, keyboard_window); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 661 | event_generator.ClickLeftButton(); |
| 662 | int expected_mouse_presses = 1; |
[email protected] | 647b484 | 2013-12-12 14:24:24 | [diff] [blame] | 663 | EXPECT_EQ(expected_mouse_presses, handler->num_mouse_events() / 2); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 664 | |
| 665 | for (int block_reason = FIRST_BLOCK_REASON; |
| 666 | block_reason < NUMBER_OF_BLOCK_REASONS; |
| 667 | ++block_reason) { |
| 668 | BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 669 | event_generator.ClickLeftButton(); |
| 670 | expected_mouse_presses++; |
[email protected] | 647b484 | 2013-12-12 14:24:24 | [diff] [blame] | 671 | EXPECT_EQ(expected_mouse_presses, handler->num_mouse_events() / 2); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 672 | UnblockUserSession(); |
| 673 | } |
| 674 | } |
| 675 | |
[email protected] | 45c6667 | 2013-10-01 22:48:56 | [diff] [blame] | 676 | // Test for http://crbug.com/299787. RootWindowController should delete |
| 677 | // the old container since the keyboard controller creates a new window in |
| 678 | // GetWindowContainer(). |
| 679 | TEST_F(VirtualKeyboardRootWindowControllerTest, |
| 680 | DeleteOldContainerOnVirtualKeyboardInit) { |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 681 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 682 | aura::Window* keyboard_container = |
| 683 | Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
[email protected] | 45c6667 | 2013-10-01 22:48:56 | [diff] [blame] | 684 | ASSERT_TRUE(keyboard_container); |
| 685 | // Track the keyboard container window. |
| 686 | aura::WindowTracker tracker; |
| 687 | tracker.Add(keyboard_container); |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 688 | // Mock a login user profile change to reinitialize the keyboard. |
| 689 | ash::Shell::GetInstance()->OnLoginUserProfilePrepared(); |
[email protected] | 45c6667 | 2013-10-01 22:48:56 | [diff] [blame] | 690 | // keyboard_container should no longer be present. |
| 691 | EXPECT_FALSE(tracker.Contains(keyboard_container)); |
| 692 | } |
| 693 | |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 694 | // Test for crbug.com/342524. After user login, the work space should restore to |
| 695 | // full screen. |
| 696 | TEST_F(VirtualKeyboardRootWindowControllerTest, RestoreWorkspaceAfterLogin) { |
| 697 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 698 | aura::Window* keyboard_container = |
| 699 | Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 700 | keyboard_container->Show(); |
| 701 | keyboard::KeyboardController* controller = |
[email protected] | a0b3fb88 | 2014-04-07 19:26:03 | [diff] [blame] | 702 | keyboard::KeyboardController::GetInstance(); |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 703 | aura::Window* keyboard_window = controller->proxy()->GetKeyboardWindow(); |
| 704 | keyboard_container->AddChild(keyboard_window); |
| 705 | keyboard_window->set_owned_by_parent(false); |
[email protected] | 39e9521 | 2014-04-23 20:00:01 | [diff] [blame^] | 706 | keyboard_window->SetBounds(keyboard::KeyboardBoundsFromWindowBounds( |
| 707 | keyboard_container->bounds(), 100)); |
[email protected] | 1025937e | 2014-02-13 01:25:50 | [diff] [blame] | 708 | keyboard_window->Show(); |
| 709 | |
| 710 | gfx::Rect before = ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); |
| 711 | |
| 712 | // Notify keyboard bounds changing. |
| 713 | controller->NotifyKeyboardBoundsChanging( |
| 714 | controller->proxy()->GetKeyboardWindow()->bounds()); |
| 715 | |
| 716 | gfx::Rect after = ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); |
| 717 | EXPECT_LT(after, before); |
| 718 | |
| 719 | // Mock a login user profile change to reinitialize the keyboard. |
| 720 | ash::Shell::GetInstance()->OnLoginUserProfilePrepared(); |
| 721 | EXPECT_EQ(ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(), before); |
| 722 | } |
| 723 | |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 724 | // Ensure that system modal dialogs do not block events targeted at the virtual |
| 725 | // keyboard. |
| 726 | TEST_F(VirtualKeyboardRootWindowControllerTest, ClickWithActiveModalDialog) { |
| 727 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 728 | aura::Window* keyboard_container = |
| 729 | Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 730 | ASSERT_TRUE(keyboard_container); |
| 731 | keyboard_container->Show(); |
| 732 | |
[email protected] | a0b3fb88 | 2014-04-07 19:26:03 | [diff] [blame] | 733 | aura::Window* keyboard_window = keyboard::KeyboardController::GetInstance()-> |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 734 | proxy()->GetKeyboardWindow(); |
| 735 | keyboard_container->AddChild(keyboard_window); |
| 736 | keyboard_window->set_owned_by_parent(false); |
[email protected] | 39e9521 | 2014-04-23 20:00:01 | [diff] [blame^] | 737 | keyboard_window->SetBounds(keyboard::KeyboardBoundsFromWindowBounds( |
| 738 | keyboard_container->bounds(), 100)); |
[email protected] | 602022b | 2014-03-31 17:07:31 | [diff] [blame] | 739 | ui::test::TestEventHandler* handler = new ui::test::TestEventHandler; |
| 740 | root_window->SetEventFilter(handler); |
| 741 | aura::test::EventGenerator root_window_event_generator(root_window); |
| 742 | aura::test::EventGenerator keyboard_event_generator(root_window, |
| 743 | keyboard_window); |
| 744 | |
| 745 | views::Widget* modal_widget = |
| 746 | CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
| 747 | |
| 748 | // Verify that mouse events to the root window are block with a visble modal |
| 749 | // dialog. |
| 750 | root_window_event_generator.ClickLeftButton(); |
| 751 | EXPECT_EQ(0, handler->num_mouse_events()); |
| 752 | |
| 753 | // Verify that event dispatch to the virtual keyboard is unblocked. |
| 754 | keyboard_event_generator.ClickLeftButton(); |
| 755 | EXPECT_EQ(1, handler->num_mouse_events() / 2); |
| 756 | |
| 757 | modal_widget->Close(); |
| 758 | |
| 759 | // Verify that mouse events are now unblocked to the root window. |
| 760 | root_window_event_generator.ClickLeftButton(); |
| 761 | EXPECT_EQ(2, handler->num_mouse_events() / 2); |
| 762 | } |
| 763 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 764 | } // namespace test |
| 765 | } // namespace ash |