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