[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" |
| 22 | #include "ui/aura/root_window.h" |
| 23 | #include "ui/aura/test/event_generator.h" |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 24 | #include "ui/aura/test/test_window_delegate.h" |
| 25 | #include "ui/aura/test/test_windows.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 26 | #include "ui/aura/window.h" |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 27 | #include "ui/aura/window_tracker.h" |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 28 | #include "ui/keyboard/keyboard_switches.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 29 | #include "ui/views/controls/menu/menu_controller.h" |
| 30 | #include "ui/views/widget/widget.h" |
| 31 | #include "ui/views/widget/widget_delegate.h" |
| 32 | |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 33 | using aura::Window; |
| 34 | using views::Widget; |
| 35 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 36 | namespace ash { |
| 37 | namespace { |
| 38 | |
| 39 | class TestDelegate : public views::WidgetDelegateView { |
| 40 | public: |
| 41 | explicit TestDelegate(bool system_modal) : system_modal_(system_modal) {} |
| 42 | virtual ~TestDelegate() {} |
| 43 | |
| 44 | // Overridden from views::WidgetDelegate: |
| 45 | virtual views::View* GetContentsView() OVERRIDE { |
| 46 | return this; |
| 47 | } |
| 48 | |
| 49 | virtual ui::ModalType GetModalType() const OVERRIDE { |
| 50 | return system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE; |
| 51 | } |
| 52 | |
| 53 | private: |
| 54 | bool system_modal_; |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 55 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 56 | DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
| 57 | }; |
| 58 | |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 59 | class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate, |
| 60 | public aura::client::FocusChangeObserver { |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 61 | public: |
| 62 | DeleteOnBlurDelegate() : window_(NULL) {} |
| 63 | virtual ~DeleteOnBlurDelegate() {} |
| 64 | |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 65 | void SetWindow(aura::Window* window) { |
| 66 | window_ = window; |
| 67 | aura::client::SetFocusChangeObserver(window_, this); |
| 68 | } |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 69 | |
[email protected] | 869f635 | 2012-12-06 20:47:17 | [diff] [blame] | 70 | private: |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 71 | // aura::test::TestWindowDelegate overrides: |
| 72 | virtual bool CanFocus() OVERRIDE { |
| 73 | return true; |
| 74 | } |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 75 | |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 76 | // aura::client::FocusChangeObserver implementation: |
| 77 | virtual void OnWindowFocused(aura::Window* gained_focus, |
| 78 | aura::Window* lost_focus) OVERRIDE { |
| 79 | if (window_ == lost_focus) |
| 80 | delete window_; |
[email protected] | 869f635 | 2012-12-06 20:47:17 | [diff] [blame] | 81 | } |
| 82 | |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 83 | aura::Window* window_; |
| 84 | |
| 85 | DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate); |
| 86 | }; |
| 87 | |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 88 | class ClickTestWindow : public views::WidgetDelegateView { |
| 89 | public: |
| 90 | ClickTestWindow() : mouse_presses_(0) {} |
| 91 | virtual ~ClickTestWindow() {} |
| 92 | |
| 93 | // Overridden from views::WidgetDelegate: |
| 94 | virtual views::View* GetContentsView() OVERRIDE { |
| 95 | return this; |
| 96 | } |
| 97 | |
| 98 | aura::Window* CreateTestWindowWithParent(aura::Window* parent) { |
| 99 | DCHECK(parent); |
| 100 | views::Widget* widget = Widget::CreateWindowWithParent(this, parent); |
| 101 | return widget->GetNativeView(); |
| 102 | } |
| 103 | |
| 104 | // Overridden from views::View: |
| 105 | virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE { |
| 106 | mouse_presses_++; |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | int mouse_presses() const { return mouse_presses_; } |
| 111 | |
| 112 | private: |
| 113 | int mouse_presses_; |
| 114 | |
| 115 | DISALLOW_COPY_AND_ASSIGN(ClickTestWindow); |
| 116 | }; |
| 117 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 118 | } // namespace |
| 119 | |
| 120 | namespace test { |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 121 | |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 122 | class RootWindowControllerTest : public test::AshTestBase { |
| 123 | public: |
| 124 | views::Widget* CreateTestWidget(const gfx::Rect& bounds) { |
| 125 | views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 126 | NULL, CurrentContext(), bounds); |
| 127 | widget->Show(); |
| 128 | return widget; |
| 129 | } |
| 130 | |
| 131 | views::Widget* CreateModalWidget(const gfx::Rect& bounds) { |
| 132 | views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 133 | new TestDelegate(true), CurrentContext(), bounds); |
| 134 | widget->Show(); |
| 135 | return widget; |
| 136 | } |
| 137 | |
| 138 | views::Widget* CreateModalWidgetWithParent(const gfx::Rect& bounds, |
| 139 | gfx::NativeWindow parent) { |
| 140 | views::Widget* widget = |
| 141 | views::Widget::CreateWindowWithParentAndBounds(new TestDelegate(true), |
| 142 | parent, |
| 143 | bounds); |
| 144 | widget->Show(); |
| 145 | return widget; |
| 146 | } |
| 147 | |
| 148 | aura::Window* GetModalContainer(aura::RootWindow* root_window) { |
| 149 | return Shell::GetContainer( |
| 150 | root_window, |
| 151 | ash::internal::kShellWindowId_SystemModalContainer); |
| 152 | } |
| 153 | }; |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 154 | |
[email protected] | e75642a | 2013-06-12 17:21:18 | [diff] [blame] | 155 | TEST_F(RootWindowControllerTest, MoveWindows_Basic) { |
| 156 | if (!SupportsMultipleDisplays()) |
| 157 | return; |
[email protected] | 1c3f700 | 2013-01-21 18:46:05 | [diff] [blame] | 158 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 159 | UpdateDisplay("600x600,500x500"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 160 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 161 | internal::RootWindowController* controller = |
| 162 | Shell::GetPrimaryRootWindowController(); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 163 | internal::ShelfLayoutManager* shelf_layout_manager = |
| 164 | controller->GetShelfLayoutManager(); |
| 165 | shelf_layout_manager->SetAutoHideBehavior( |
| 166 | ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 167 | |
| 168 | views::Widget* normal = CreateTestWidget(gfx::Rect(650, 10, 100, 100)); |
| 169 | EXPECT_EQ(root_windows[1], normal->GetNativeView()->GetRootWindow()); |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 170 | EXPECT_EQ("650,10 100x100", normal->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 171 | EXPECT_EQ("50,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 172 | normal->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 173 | |
| 174 | views::Widget* maximized = CreateTestWidget(gfx::Rect(700, 10, 100, 100)); |
| 175 | maximized->Maximize(); |
| 176 | EXPECT_EQ(root_windows[1], maximized->GetNativeView()->GetRootWindow()); |
[email protected] | f54effe | 2013-09-05 01:09:02 | [diff] [blame] | 177 | EXPECT_EQ("600,0 500x453", maximized->GetWindowBoundsInScreen().ToString()); |
| 178 | EXPECT_EQ("0,0 500x453", |
[email protected] | 8c0ec43 | 2013-05-10 04:33:39 | [diff] [blame] | 179 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 180 | |
| 181 | views::Widget* minimized = CreateTestWidget(gfx::Rect(800, 10, 100, 100)); |
| 182 | minimized->Minimize(); |
| 183 | EXPECT_EQ(root_windows[1], minimized->GetNativeView()->GetRootWindow()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 184 | EXPECT_EQ("800,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 185 | minimized->GetWindowBoundsInScreen().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 186 | |
| 187 | views::Widget* fullscreen = CreateTestWidget(gfx::Rect(900, 10, 100, 100)); |
| 188 | fullscreen->SetFullscreen(true); |
| 189 | EXPECT_EQ(root_windows[1], fullscreen->GetNativeView()->GetRootWindow()); |
[email protected] | 1a01538 | 2012-12-01 19:44:59 | [diff] [blame] | 190 | |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 191 | EXPECT_EQ("600,0 500x500", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 192 | fullscreen->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 193 | EXPECT_EQ("0,0 500x500", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 194 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 195 | |
[email protected] | 8f2f15141 | 2013-01-26 03:58:37 | [diff] [blame] | 196 | views::Widget* unparented_control = new Widget; |
| 197 | Widget::InitParams params; |
| 198 | params.bounds = gfx::Rect(650, 10, 100, 100); |
| 199 | params.context = CurrentContext(); |
| 200 | params.type = Widget::InitParams::TYPE_CONTROL; |
| 201 | unparented_control->Init(params); |
| 202 | EXPECT_EQ(root_windows[1], |
| 203 | unparented_control->GetNativeView()->GetRootWindow()); |
| 204 | EXPECT_EQ(internal::kShellWindowId_UnparentedControlContainer, |
| 205 | unparented_control->GetNativeView()->parent()->id()); |
| 206 | |
[email protected] | 95db9c1 | 2013-01-31 11:47:44 | [diff] [blame] | 207 | aura::Window* panel = CreateTestWindowInShellWithDelegateAndType( |
| 208 | NULL, aura::client::WINDOW_TYPE_PANEL, 0, gfx::Rect(700, 100, 100, 100)); |
| 209 | EXPECT_EQ(root_windows[1], panel->GetRootWindow()); |
| 210 | EXPECT_EQ(internal::kShellWindowId_PanelContainer, panel->parent()->id()); |
| 211 | |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 212 | // Make sure a window that will delete itself when losing focus |
| 213 | // will not crash. |
| 214 | aura::WindowTracker tracker; |
| 215 | DeleteOnBlurDelegate delete_on_blur_delegate; |
[email protected] | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 216 | aura::Window* d2 = CreateTestWindowInShellWithDelegate( |
| 217 | &delete_on_blur_delegate, 0, gfx::Rect(50, 50, 100, 100)); |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 218 | delete_on_blur_delegate.SetWindow(d2); |
[email protected] | 550543e | 2013-01-11 22:43:44 | [diff] [blame] | 219 | aura::client::GetFocusClient(root_windows[0])->FocusWindow(d2); |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 220 | tracker.Add(d2); |
| 221 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 222 | UpdateDisplay("600x600"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 223 | |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 224 | // d2 must have been deleted. |
| 225 | EXPECT_FALSE(tracker.Contains(d2)); |
| 226 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 227 | EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow()); |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 228 | EXPECT_EQ("50,10 100x100", normal->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 229 | EXPECT_EQ("50,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 230 | normal->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 231 | |
[email protected] | eefd51b2 | 2012-09-25 20:26:24 | [diff] [blame] | 232 | // Maximized area on primary display has 3px (given as |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 233 | // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom. |
[email protected] | 2a64b0a | 2013-07-23 23:15:54 | [diff] [blame] | 234 | |
| 235 | // First clear fullscreen status, since both fullscreen and maximized windows |
| 236 | // share the same desktop workspace, which cancels the shelf status. |
| 237 | fullscreen->SetFullscreen(false); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 238 | EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow()); |
[email protected] | 7b675df61 | 2012-09-16 18:33:20 | [diff] [blame] | 239 | EXPECT_EQ("0,0 600x597", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 240 | maximized->GetWindowBoundsInScreen().ToString()); |
[email protected] | 7b675df61 | 2012-09-16 18:33:20 | [diff] [blame] | 241 | EXPECT_EQ("0,0 600x597", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 242 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 243 | |
[email protected] | 2a64b0a | 2013-07-23 23:15:54 | [diff] [blame] | 244 | // Set fullscreen to true. In that case the 3px inset becomes invisible so |
| 245 | // the maximized window can also use the area fully. |
| 246 | fullscreen->SetFullscreen(true); |
| 247 | EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow()); |
| 248 | EXPECT_EQ("0,0 600x600", |
| 249 | maximized->GetWindowBoundsInScreen().ToString()); |
| 250 | EXPECT_EQ("0,0 600x600", |
| 251 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
| 252 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 253 | EXPECT_EQ(root_windows[0], minimized->GetNativeView()->GetRootWindow()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 254 | EXPECT_EQ("200,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 255 | minimized->GetWindowBoundsInScreen().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 256 | |
| 257 | EXPECT_EQ(root_windows[0], fullscreen->GetNativeView()->GetRootWindow()); |
| 258 | EXPECT_TRUE(fullscreen->IsFullscreen()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 259 | EXPECT_EQ("0,0 600x600", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 260 | fullscreen->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 261 | EXPECT_EQ("0,0 600x600", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 262 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 263 | |
| 264 | // Test if the restore bounds are correctly updated. |
[email protected] | a41b4e1 | 2013-09-20 04:36:34 | [diff] [blame] | 265 | wm::GetWindowState(maximized->GetNativeView())->Restore(); |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 266 | EXPECT_EQ("100,10 100x100", maximized->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 267 | EXPECT_EQ("100,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 268 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 269 | |
| 270 | fullscreen->SetFullscreen(false); |
| 271 | EXPECT_EQ("300,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 272 | fullscreen->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 273 | EXPECT_EQ("300,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 274 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | 8f2f15141 | 2013-01-26 03:58:37 | [diff] [blame] | 275 | |
| 276 | // Test if the unparented widget has moved. |
| 277 | EXPECT_EQ(root_windows[0], |
| 278 | unparented_control->GetNativeView()->GetRootWindow()); |
| 279 | EXPECT_EQ(internal::kShellWindowId_UnparentedControlContainer, |
| 280 | unparented_control->GetNativeView()->parent()->id()); |
[email protected] | 95db9c1 | 2013-01-31 11:47:44 | [diff] [blame] | 281 | |
| 282 | // Test if the panel has moved. |
| 283 | EXPECT_EQ(root_windows[0], panel->GetRootWindow()); |
| 284 | EXPECT_EQ(internal::kShellWindowId_PanelContainer, panel->parent()->id()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 285 | } |
| 286 | |
[email protected] | e75642a | 2013-06-12 17:21:18 | [diff] [blame] | 287 | TEST_F(RootWindowControllerTest, MoveWindows_Modal) { |
| 288 | if (!SupportsMultipleDisplays()) |
| 289 | return; |
[email protected] | 1c3f700 | 2013-01-21 18:46:05 | [diff] [blame] | 290 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 291 | UpdateDisplay("500x500,500x500"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 292 | |
| 293 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 294 | // Emulate virtual screen coordinate system. |
| 295 | root_windows[0]->SetBounds(gfx::Rect(0, 0, 500, 500)); |
| 296 | root_windows[1]->SetBounds(gfx::Rect(500, 0, 500, 500)); |
| 297 | |
| 298 | views::Widget* normal = CreateTestWidget(gfx::Rect(300, 10, 100, 100)); |
| 299 | EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow()); |
| 300 | EXPECT_TRUE(wm::IsActiveWindow(normal->GetNativeView())); |
| 301 | |
| 302 | views::Widget* modal = CreateModalWidget(gfx::Rect(650, 10, 100, 100)); |
| 303 | EXPECT_EQ(root_windows[1], modal->GetNativeView()->GetRootWindow()); |
| 304 | EXPECT_TRUE(GetModalContainer(root_windows[1])->Contains( |
| 305 | modal->GetNativeView())); |
| 306 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 307 | |
| 308 | aura::test::EventGenerator generator_1st(root_windows[0]); |
| 309 | generator_1st.ClickLeftButton(); |
| 310 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 311 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 312 | UpdateDisplay("500x500"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 313 | EXPECT_EQ(root_windows[0], modal->GetNativeView()->GetRootWindow()); |
| 314 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 315 | generator_1st.ClickLeftButton(); |
| 316 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 317 | } |
| 318 | |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 319 | TEST_F(RootWindowControllerTest, ModalContainer) { |
| 320 | UpdateDisplay("600x600"); |
| 321 | Shell* shell = Shell::GetInstance(); |
| 322 | internal::RootWindowController* controller = |
| 323 | shell->GetPrimaryRootWindowController(); |
| 324 | EXPECT_EQ(user::LOGGED_IN_USER, |
[email protected] | 945f9cae | 2012-12-12 09:54:29 | [diff] [blame] | 325 | shell->system_tray_delegate()->GetUserLoginStatus()); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 326 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 327 | internal::kShellWindowId_SystemModalContainer)->layout_manager(), |
| 328 | controller->GetSystemModalLayoutManager(NULL)); |
| 329 | |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 330 | views::Widget* session_modal_widget = |
| 331 | CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
| 332 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 333 | internal::kShellWindowId_SystemModalContainer)->layout_manager(), |
| 334 | controller->GetSystemModalLayoutManager( |
| 335 | session_modal_widget->GetNativeView())); |
| 336 | |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 337 | shell->session_state_delegate()->LockScreen(); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 338 | EXPECT_EQ(user::LOGGED_IN_LOCKED, |
[email protected] | 945f9cae | 2012-12-12 09:54:29 | [diff] [blame] | 339 | shell->system_tray_delegate()->GetUserLoginStatus()); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 340 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 341 | internal::kShellWindowId_LockSystemModalContainer)->layout_manager(), |
| 342 | controller->GetSystemModalLayoutManager(NULL)); |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 343 | |
| 344 | aura::Window* lock_container = |
| 345 | Shell::GetContainer(controller->root_window(), |
| 346 | internal::kShellWindowId_LockScreenContainer); |
| 347 | views::Widget* lock_modal_widget = |
| 348 | CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container); |
| 349 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 350 | internal::kShellWindowId_LockSystemModalContainer)->layout_manager(), |
| 351 | controller->GetSystemModalLayoutManager( |
| 352 | lock_modal_widget->GetNativeView())); |
| 353 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 354 | internal::kShellWindowId_SystemModalContainer)->layout_manager(), |
| 355 | controller->GetSystemModalLayoutManager( |
| 356 | session_modal_widget->GetNativeView())); |
| 357 | |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 358 | shell->session_state_delegate()->UnlockScreen(); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 359 | } |
| 360 | |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 361 | TEST_F(RootWindowControllerTest, ModalContainerNotLoggedInLoggedIn) { |
| 362 | UpdateDisplay("600x600"); |
| 363 | Shell* shell = Shell::GetInstance(); |
| 364 | |
| 365 | // Configure login screen environment. |
| 366 | SetUserLoggedIn(false); |
| 367 | EXPECT_EQ(user::LOGGED_IN_NONE, |
[email protected] | 945f9cae | 2012-12-12 09:54:29 | [diff] [blame] | 368 | shell->system_tray_delegate()->GetUserLoginStatus()); |
[email protected] | c8d19f8 | 2013-05-18 09:09:41 | [diff] [blame] | 369 | EXPECT_EQ(0, shell->session_state_delegate()->NumberOfLoggedInUsers()); |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 370 | EXPECT_FALSE(shell->session_state_delegate()->IsActiveUserSessionStarted()); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 371 | |
| 372 | internal::RootWindowController* controller = |
| 373 | shell->GetPrimaryRootWindowController(); |
| 374 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 375 | internal::kShellWindowId_LockSystemModalContainer)->layout_manager(), |
| 376 | controller->GetSystemModalLayoutManager(NULL)); |
| 377 | |
| 378 | aura::Window* lock_container = |
| 379 | Shell::GetContainer(controller->root_window(), |
| 380 | internal::kShellWindowId_LockScreenContainer); |
| 381 | views::Widget* login_modal_widget = |
| 382 | CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container); |
| 383 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 384 | internal::kShellWindowId_LockSystemModalContainer)->layout_manager(), |
| 385 | controller->GetSystemModalLayoutManager( |
| 386 | login_modal_widget->GetNativeView())); |
| 387 | login_modal_widget->Close(); |
| 388 | |
| 389 | // Configure user session environment. |
| 390 | SetUserLoggedIn(true); |
| 391 | SetSessionStarted(true); |
| 392 | EXPECT_EQ(user::LOGGED_IN_USER, |
[email protected] | 945f9cae | 2012-12-12 09:54:29 | [diff] [blame] | 393 | shell->system_tray_delegate()->GetUserLoginStatus()); |
[email protected] | c8d19f8 | 2013-05-18 09:09:41 | [diff] [blame] | 394 | EXPECT_EQ(1, shell->session_state_delegate()->NumberOfLoggedInUsers()); |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 395 | EXPECT_TRUE(shell->session_state_delegate()->IsActiveUserSessionStarted()); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 396 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 397 | internal::kShellWindowId_SystemModalContainer)->layout_manager(), |
| 398 | controller->GetSystemModalLayoutManager(NULL)); |
| 399 | |
| 400 | views::Widget* session_modal_widget = |
| 401 | CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
| 402 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 403 | internal::kShellWindowId_SystemModalContainer)->layout_manager(), |
| 404 | controller->GetSystemModalLayoutManager( |
| 405 | session_modal_widget->GetNativeView())); |
| 406 | } |
| 407 | |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 408 | TEST_F(RootWindowControllerTest, ModalContainerBlockedSession) { |
| 409 | UpdateDisplay("600x600"); |
| 410 | Shell* shell = Shell::GetInstance(); |
| 411 | internal::RootWindowController* controller = |
| 412 | shell->GetPrimaryRootWindowController(); |
| 413 | aura::Window* lock_container = |
| 414 | Shell::GetContainer(controller->root_window(), |
| 415 | internal::kShellWindowId_LockScreenContainer); |
| 416 | for (int block_reason = FIRST_BLOCK_REASON; |
| 417 | block_reason < NUMBER_OF_BLOCK_REASONS; |
| 418 | ++block_reason) { |
| 419 | views::Widget* session_modal_widget = |
| 420 | CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
| 421 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 422 | internal::kShellWindowId_SystemModalContainer)->layout_manager(), |
| 423 | controller->GetSystemModalLayoutManager( |
| 424 | session_modal_widget->GetNativeView())); |
| 425 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 426 | internal::kShellWindowId_SystemModalContainer)->layout_manager(), |
| 427 | controller->GetSystemModalLayoutManager(NULL)); |
| 428 | session_modal_widget->Close(); |
| 429 | |
| 430 | BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 431 | |
| 432 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 433 | internal::kShellWindowId_LockSystemModalContainer)->layout_manager(), |
| 434 | controller->GetSystemModalLayoutManager(NULL)); |
| 435 | |
| 436 | views::Widget* lock_modal_widget = |
| 437 | CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), |
| 438 | lock_container); |
| 439 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 440 | internal::kShellWindowId_LockSystemModalContainer)->layout_manager(), |
| 441 | controller->GetSystemModalLayoutManager( |
| 442 | lock_modal_widget->GetNativeView())); |
| 443 | |
| 444 | session_modal_widget = |
| 445 | CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
| 446 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 447 | internal::kShellWindowId_SystemModalContainer)->layout_manager(), |
| 448 | controller->GetSystemModalLayoutManager( |
| 449 | session_modal_widget->GetNativeView())); |
| 450 | session_modal_widget->Close(); |
| 451 | |
| 452 | lock_modal_widget->Close(); |
| 453 | UnblockUserSession(); |
| 454 | } |
| 455 | } |
| 456 | |
[email protected] | e3bc88e | 2013-09-06 06:22:06 | [diff] [blame] | 457 | TEST_F(RootWindowControllerTest, GetTopmostFullscreenWindow) { |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 458 | UpdateDisplay("600x600"); |
| 459 | internal::RootWindowController* controller = |
| 460 | Shell::GetInstance()->GetPrimaryRootWindowController(); |
| 461 | |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 462 | Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 463 | w1->Maximize(); |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 464 | Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
| 465 | w2->SetFullscreen(true); |
| 466 | // |w3| is a transient child of |w2|. |
| 467 | Widget* w3 = Widget::CreateWindowWithParentAndBounds(NULL, |
| 468 | w2->GetNativeWindow(), gfx::Rect(0, 0, 100, 100)); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 469 | |
[email protected] | e3bc88e | 2013-09-06 06:22:06 | [diff] [blame] | 470 | // Test that GetTopmostFullscreenWindow() finds the fullscreen window when one |
| 471 | // of its transient children is active. |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 472 | w3->Activate(); |
[email protected] | e3bc88e | 2013-09-06 06:22:06 | [diff] [blame] | 473 | EXPECT_EQ(w2->GetNativeWindow(), controller->GetTopmostFullscreenWindow()); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 474 | |
[email protected] | 2a64b0a | 2013-07-23 23:15:54 | [diff] [blame] | 475 | // Since there's only one desktop workspace, it always returns the same |
| 476 | // fullscreen window. |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 477 | w1->Activate(); |
[email protected] | e3bc88e | 2013-09-06 06:22:06 | [diff] [blame] | 478 | EXPECT_EQ(w2->GetNativeWindow(), controller->GetTopmostFullscreenWindow()); |
| 479 | } |
| 480 | |
| 481 | TEST_F(RootWindowControllerTest, MultipleFullscreenWindows) { |
| 482 | UpdateDisplay("600x600"); |
| 483 | internal::RootWindowController* controller = |
| 484 | Shell::GetInstance()->GetPrimaryRootWindowController(); |
| 485 | |
| 486 | Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
| 487 | w1->Maximize(); |
| 488 | Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
| 489 | w2->SetFullscreen(true); |
| 490 | Widget* w3 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
| 491 | w3->SetFullscreen(true); |
| 492 | |
| 493 | // Test that GetTopmostFullscreenWindow() finds the active fullscreen window. |
| 494 | w2->Activate(); |
| 495 | EXPECT_EQ(w2->GetNativeWindow(), controller->GetTopmostFullscreenWindow()); |
| 496 | w3->Activate(); |
| 497 | EXPECT_EQ(w3->GetNativeWindow(), controller->GetTopmostFullscreenWindow()); |
| 498 | |
| 499 | // If the active window is not fullscreen, it still returns the topmost |
| 500 | // fullscreen window, which is the last active one. |
| 501 | w1->Activate(); |
| 502 | EXPECT_EQ(w3->GetNativeWindow(), controller->GetTopmostFullscreenWindow()); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 503 | } |
| 504 | |
[email protected] | 82ced235 | 2013-07-19 20:49:06 | [diff] [blame] | 505 | // Test that user session window can't be focused if user session blocked by |
| 506 | // some overlapping UI. |
| 507 | TEST_F(RootWindowControllerTest, FocusBlockedWindow) { |
| 508 | UpdateDisplay("600x600"); |
| 509 | internal::RootWindowController* controller = |
| 510 | Shell::GetInstance()->GetPrimaryRootWindowController(); |
| 511 | aura::Window* lock_container = |
| 512 | Shell::GetContainer(controller->root_window(), |
| 513 | internal::kShellWindowId_LockScreenContainer); |
| 514 | aura::Window* lock_window = Widget::CreateWindowWithParentAndBounds(NULL, |
| 515 | lock_container, gfx::Rect(0, 0, 100, 100))->GetNativeView(); |
| 516 | lock_window->Show(); |
| 517 | aura::Window* session_window = |
| 518 | CreateTestWidget(gfx::Rect(0, 0, 100, 100))->GetNativeView(); |
| 519 | session_window->Show(); |
| 520 | |
[email protected] | a44afbbd | 2013-07-24 21:49:35 | [diff] [blame] | 521 | for (int block_reason = FIRST_BLOCK_REASON; |
| 522 | block_reason < NUMBER_OF_BLOCK_REASONS; |
| 523 | ++block_reason) { |
| 524 | BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 525 | lock_window->Focus(); |
| 526 | EXPECT_TRUE(lock_window->HasFocus()); |
| 527 | session_window->Focus(); |
| 528 | EXPECT_FALSE(session_window->HasFocus()); |
| 529 | UnblockUserSession(); |
| 530 | } |
[email protected] | 82ced235 | 2013-07-19 20:49:06 | [diff] [blame] | 531 | } |
| 532 | |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 533 | // Tracks whether OnWindowDestroying() has been invoked. |
| 534 | class DestroyedWindowObserver : public aura::WindowObserver { |
| 535 | public: |
| 536 | DestroyedWindowObserver() : destroyed_(false), window_(NULL) {} |
| 537 | virtual ~DestroyedWindowObserver() { |
| 538 | Shutdown(); |
| 539 | } |
| 540 | |
| 541 | void SetWindow(Window* window) { |
| 542 | window_ = window; |
| 543 | window->AddObserver(this); |
| 544 | } |
| 545 | |
| 546 | bool destroyed() const { return destroyed_; } |
| 547 | |
| 548 | // WindowObserver overrides: |
| 549 | virtual void OnWindowDestroying(Window* window) OVERRIDE { |
| 550 | destroyed_ = true; |
| 551 | Shutdown(); |
| 552 | } |
| 553 | |
| 554 | private: |
| 555 | void Shutdown() { |
| 556 | if (!window_) |
| 557 | return; |
| 558 | window_->RemoveObserver(this); |
| 559 | window_ = NULL; |
| 560 | } |
| 561 | |
| 562 | bool destroyed_; |
| 563 | Window* window_; |
| 564 | |
| 565 | DISALLOW_COPY_AND_ASSIGN(DestroyedWindowObserver); |
| 566 | }; |
| 567 | |
| 568 | // Verifies shutdown doesn't delete windows that are not owned by the parent. |
| 569 | TEST_F(RootWindowControllerTest, DontDeleteWindowsNotOwnedByParent) { |
| 570 | DestroyedWindowObserver observer1; |
| 571 | aura::test::TestWindowDelegate delegate1; |
| 572 | aura::Window* window1 = new aura::Window(&delegate1); |
| 573 | window1->SetType(aura::client::WINDOW_TYPE_CONTROL); |
| 574 | window1->set_owned_by_parent(false); |
| 575 | observer1.SetWindow(window1); |
| 576 | window1->Init(ui::LAYER_NOT_DRAWN); |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame^] | 577 | aura::client::ParentWindowWithContext( |
| 578 | window1, Shell::GetInstance()->GetPrimaryRootWindow(), gfx::Rect()); |
[email protected] | 0fbfa97 | 2013-10-02 19:23:33 | [diff] [blame] | 579 | |
| 580 | DestroyedWindowObserver observer2; |
| 581 | aura::Window* window2 = new aura::Window(NULL); |
| 582 | window2->set_owned_by_parent(false); |
| 583 | observer2.SetWindow(window2); |
| 584 | window2->Init(ui::LAYER_NOT_DRAWN); |
| 585 | Shell::GetInstance()->GetPrimaryRootWindow()->AddChild(window2); |
| 586 | |
| 587 | Shell::GetInstance()->GetPrimaryRootWindowController()->CloseChildWindows(); |
| 588 | |
| 589 | ASSERT_FALSE(observer1.destroyed()); |
| 590 | delete window1; |
| 591 | |
| 592 | ASSERT_FALSE(observer2.destroyed()); |
| 593 | delete window2; |
| 594 | } |
| 595 | |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 596 | typedef test::NoSessionAshTestBase NoSessionRootWindowControllerTest; |
| 597 | |
| 598 | // Make sure that an event handler exists for entire display area. |
| 599 | TEST_F(NoSessionRootWindowControllerTest, Event) { |
| 600 | aura::RootWindow* root = Shell::GetPrimaryRootWindow(); |
| 601 | const gfx::Size size = root->bounds().size(); |
| 602 | aura::Window* event_target = root->GetEventHandlerForPoint(gfx::Point(0, 0)); |
| 603 | EXPECT_TRUE(event_target); |
| 604 | EXPECT_EQ(event_target, |
| 605 | root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1))); |
| 606 | EXPECT_EQ(event_target, |
| 607 | root->GetEventHandlerForPoint(gfx::Point(size.width() - 1, 0))); |
| 608 | EXPECT_EQ(event_target, |
| 609 | root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1))); |
| 610 | EXPECT_EQ(event_target, |
| 611 | root->GetEventHandlerForPoint( |
| 612 | gfx::Point(size.width() - 1, size.height() - 1))); |
| 613 | } |
| 614 | |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 615 | class VirtualKeyboardRootWindowControllerTest : public test::AshTestBase { |
| 616 | public: |
| 617 | VirtualKeyboardRootWindowControllerTest() {}; |
| 618 | virtual ~VirtualKeyboardRootWindowControllerTest() {}; |
| 619 | |
| 620 | virtual void SetUp() OVERRIDE { |
| 621 | CommandLine::ForCurrentProcess()->AppendSwitch( |
| 622 | keyboard::switches::kEnableVirtualKeyboard); |
| 623 | test::AshTestBase::SetUp(); |
| 624 | } |
| 625 | |
| 626 | private: |
| 627 | DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest); |
| 628 | }; |
| 629 | |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 630 | // Test for http://crbug.com/297858. Virtual keyboard container should only show |
| 631 | // on primary root window. |
| 632 | TEST_F(VirtualKeyboardRootWindowControllerTest, |
| 633 | VirtualKeyboardOnPrimaryRootWindowOnly) { |
| 634 | if (!SupportsMultipleDisplays()) |
| 635 | return; |
| 636 | |
| 637 | UpdateDisplay("500x500,500x500"); |
| 638 | |
| 639 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 640 | aura::RootWindow* primary_root_window = Shell::GetPrimaryRootWindow(); |
| 641 | aura::RootWindow* secondary_root_window = |
| 642 | root_windows[0] == primary_root_window ? |
| 643 | root_windows[1] : root_windows[0]; |
| 644 | |
| 645 | ASSERT_TRUE(Shell::GetContainer( |
| 646 | primary_root_window, |
| 647 | internal::kShellWindowId_VirtualKeyboardContainer)); |
| 648 | ASSERT_FALSE(Shell::GetContainer( |
| 649 | secondary_root_window, |
| 650 | internal::kShellWindowId_VirtualKeyboardContainer)); |
| 651 | } |
| 652 | |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 653 | // Test for http://crbug.com/263599. Virtual keyboard should be able to receive |
| 654 | // events at blocked user session. |
| 655 | TEST_F(VirtualKeyboardRootWindowControllerTest, |
| 656 | ClickVirtualKeyboardInBlockedWindow) { |
[email protected] | b6ba05d90 | 2013-10-04 21:38:45 | [diff] [blame] | 657 | aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 658 | aura::Window* keyboard_container = Shell::GetContainer(root_window, |
| 659 | internal::kShellWindowId_VirtualKeyboardContainer); |
| 660 | ASSERT_TRUE(keyboard_container); |
| 661 | keyboard_container->Show(); |
| 662 | |
| 663 | ClickTestWindow* main_delegate = new ClickTestWindow(); |
| 664 | scoped_ptr<aura::Window> keyboard_window( |
| 665 | main_delegate->CreateTestWindowWithParent(keyboard_container)); |
| 666 | keyboard_container->layout_manager()->OnWindowResized(); |
| 667 | keyboard_window->Show(); |
| 668 | aura::test::EventGenerator event_generator(root_window, |
| 669 | keyboard_window.get()); |
| 670 | event_generator.ClickLeftButton(); |
| 671 | int expected_mouse_presses = 1; |
| 672 | EXPECT_EQ(expected_mouse_presses, main_delegate->mouse_presses()); |
| 673 | |
| 674 | for (int block_reason = FIRST_BLOCK_REASON; |
| 675 | block_reason < NUMBER_OF_BLOCK_REASONS; |
| 676 | ++block_reason) { |
| 677 | BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 678 | event_generator.ClickLeftButton(); |
| 679 | expected_mouse_presses++; |
| 680 | EXPECT_EQ(expected_mouse_presses, main_delegate->mouse_presses()); |
| 681 | UnblockUserSession(); |
| 682 | } |
| 683 | } |
| 684 | |
[email protected] | 45c6667 | 2013-10-01 22:48:56 | [diff] [blame] | 685 | // Test for http://crbug.com/299787. RootWindowController should delete |
| 686 | // the old container since the keyboard controller creates a new window in |
| 687 | // GetWindowContainer(). |
| 688 | TEST_F(VirtualKeyboardRootWindowControllerTest, |
| 689 | DeleteOldContainerOnVirtualKeyboardInit) { |
| 690 | aura::RootWindow* root_window = ash::Shell::GetPrimaryRootWindow(); |
| 691 | aura::Window* keyboard_container = Shell::GetContainer(root_window, |
| 692 | internal::kShellWindowId_VirtualKeyboardContainer); |
| 693 | ASSERT_TRUE(keyboard_container); |
| 694 | // Track the keyboard container window. |
| 695 | aura::WindowTracker tracker; |
| 696 | tracker.Add(keyboard_container); |
| 697 | // Mock a login state change to reinitialize the keyboard. |
| 698 | ash::Shell::GetInstance()->OnLoginStateChanged(user::LOGGED_IN_OWNER); |
| 699 | // keyboard_container should no longer be present. |
| 700 | EXPECT_FALSE(tracker.Contains(keyboard_container)); |
| 701 | } |
| 702 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 703 | } // namespace test |
| 704 | } // namespace ash |