[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] | 2e236a5 | 2012-06-27 22:21:47 | [diff] [blame] | 7 | #include "ash/display/display_controller.h" |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 8 | #include "ash/session_state_delegate.h" |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 9 | #include "ash/shelf/shelf_layout_manager.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 10 | #include "ash/shell.h" |
| 11 | #include "ash/shell_window_ids.h" |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 12 | #include "ash/system/tray/system_tray_delegate.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 13 | #include "ash/test/ash_test_base.h" |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 14 | #include "ash/wm/system_modal_container_layout_manager.h" |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 15 | #include "ash/wm/window_properties.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 16 | #include "ash/wm/window_util.h" |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 17 | #include "ui/aura/client/focus_change_observer.h" |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 18 | #include "ui/aura/client/focus_client.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 19 | #include "ui/aura/env.h" |
| 20 | #include "ui/aura/root_window.h" |
| 21 | #include "ui/aura/test/event_generator.h" |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 22 | #include "ui/aura/test/test_window_delegate.h" |
| 23 | #include "ui/aura/test/test_windows.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 24 | #include "ui/aura/window.h" |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 25 | #include "ui/aura/window_tracker.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 26 | #include "ui/views/controls/menu/menu_controller.h" |
| 27 | #include "ui/views/widget/widget.h" |
| 28 | #include "ui/views/widget/widget_delegate.h" |
| 29 | |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 30 | using aura::Window; |
| 31 | using views::Widget; |
| 32 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 33 | namespace ash { |
| 34 | namespace { |
| 35 | |
| 36 | class TestDelegate : public views::WidgetDelegateView { |
| 37 | public: |
| 38 | explicit TestDelegate(bool system_modal) : system_modal_(system_modal) {} |
| 39 | virtual ~TestDelegate() {} |
| 40 | |
| 41 | // Overridden from views::WidgetDelegate: |
| 42 | virtual views::View* GetContentsView() OVERRIDE { |
| 43 | return this; |
| 44 | } |
| 45 | |
| 46 | virtual ui::ModalType GetModalType() const OVERRIDE { |
| 47 | return system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE; |
| 48 | } |
| 49 | |
| 50 | private: |
| 51 | bool system_modal_; |
| 52 | DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
| 53 | }; |
| 54 | |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 55 | class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate, |
| 56 | public aura::client::FocusChangeObserver { |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 57 | public: |
| 58 | DeleteOnBlurDelegate() : window_(NULL) {} |
| 59 | virtual ~DeleteOnBlurDelegate() {} |
| 60 | |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 61 | void SetWindow(aura::Window* window) { |
| 62 | window_ = window; |
| 63 | aura::client::SetFocusChangeObserver(window_, this); |
| 64 | } |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 65 | |
[email protected] | 869f635 | 2012-12-06 20:47:17 | [diff] [blame] | 66 | private: |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 67 | // aura::test::TestWindowDelegate overrides: |
| 68 | virtual bool CanFocus() OVERRIDE { |
| 69 | return true; |
| 70 | } |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 71 | |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 72 | // aura::client::FocusChangeObserver implementation: |
| 73 | virtual void OnWindowFocused(aura::Window* gained_focus, |
| 74 | aura::Window* lost_focus) OVERRIDE { |
| 75 | if (window_ == lost_focus) |
| 76 | delete window_; |
[email protected] | 869f635 | 2012-12-06 20:47:17 | [diff] [blame] | 77 | } |
| 78 | |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 79 | aura::Window* window_; |
| 80 | |
| 81 | DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate); |
| 82 | }; |
| 83 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 84 | } // namespace |
| 85 | |
| 86 | namespace test { |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 87 | |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 88 | class RootWindowControllerTest : public test::AshTestBase { |
| 89 | public: |
| 90 | views::Widget* CreateTestWidget(const gfx::Rect& bounds) { |
| 91 | views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 92 | NULL, CurrentContext(), bounds); |
| 93 | widget->Show(); |
| 94 | return widget; |
| 95 | } |
| 96 | |
| 97 | views::Widget* CreateModalWidget(const gfx::Rect& bounds) { |
| 98 | views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 99 | new TestDelegate(true), CurrentContext(), bounds); |
| 100 | widget->Show(); |
| 101 | return widget; |
| 102 | } |
| 103 | |
| 104 | views::Widget* CreateModalWidgetWithParent(const gfx::Rect& bounds, |
| 105 | gfx::NativeWindow parent) { |
| 106 | views::Widget* widget = |
| 107 | views::Widget::CreateWindowWithParentAndBounds(new TestDelegate(true), |
| 108 | parent, |
| 109 | bounds); |
| 110 | widget->Show(); |
| 111 | return widget; |
| 112 | } |
| 113 | |
| 114 | aura::Window* GetModalContainer(aura::RootWindow* root_window) { |
| 115 | return Shell::GetContainer( |
| 116 | root_window, |
| 117 | ash::internal::kShellWindowId_SystemModalContainer); |
| 118 | } |
| 119 | }; |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 120 | |
[email protected] | e75642a | 2013-06-12 17:21:18 | [diff] [blame^] | 121 | TEST_F(RootWindowControllerTest, MoveWindows_Basic) { |
| 122 | if (!SupportsMultipleDisplays()) |
| 123 | return; |
[email protected] | 1c3f700 | 2013-01-21 18:46:05 | [diff] [blame] | 124 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 125 | UpdateDisplay("600x600,500x500"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 126 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 127 | internal::RootWindowController* controller = |
| 128 | Shell::GetPrimaryRootWindowController(); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 129 | internal::ShelfLayoutManager* shelf_layout_manager = |
| 130 | controller->GetShelfLayoutManager(); |
| 131 | shelf_layout_manager->SetAutoHideBehavior( |
| 132 | ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 133 | |
| 134 | views::Widget* normal = CreateTestWidget(gfx::Rect(650, 10, 100, 100)); |
| 135 | EXPECT_EQ(root_windows[1], normal->GetNativeView()->GetRootWindow()); |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 136 | EXPECT_EQ("650,10 100x100", normal->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 137 | EXPECT_EQ("50,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 138 | normal->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 139 | |
| 140 | views::Widget* maximized = CreateTestWidget(gfx::Rect(700, 10, 100, 100)); |
| 141 | maximized->Maximize(); |
| 142 | EXPECT_EQ(root_windows[1], maximized->GetNativeView()->GetRootWindow()); |
[email protected] | 8c0ec43 | 2013-05-10 04:33:39 | [diff] [blame] | 143 | EXPECT_EQ("600,0 500x452", maximized->GetWindowBoundsInScreen().ToString()); |
| 144 | EXPECT_EQ("0,0 500x452", |
| 145 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 146 | |
| 147 | views::Widget* minimized = CreateTestWidget(gfx::Rect(800, 10, 100, 100)); |
| 148 | minimized->Minimize(); |
| 149 | EXPECT_EQ(root_windows[1], minimized->GetNativeView()->GetRootWindow()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 150 | EXPECT_EQ("800,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 151 | minimized->GetWindowBoundsInScreen().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 152 | |
| 153 | views::Widget* fullscreen = CreateTestWidget(gfx::Rect(900, 10, 100, 100)); |
| 154 | fullscreen->SetFullscreen(true); |
| 155 | EXPECT_EQ(root_windows[1], fullscreen->GetNativeView()->GetRootWindow()); |
[email protected] | 1a01538 | 2012-12-01 19:44:59 | [diff] [blame] | 156 | |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 157 | EXPECT_EQ("600,0 500x500", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 158 | fullscreen->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 159 | EXPECT_EQ("0,0 500x500", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 160 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 161 | |
[email protected] | 8f2f15141 | 2013-01-26 03:58:37 | [diff] [blame] | 162 | views::Widget* unparented_control = new Widget; |
| 163 | Widget::InitParams params; |
| 164 | params.bounds = gfx::Rect(650, 10, 100, 100); |
| 165 | params.context = CurrentContext(); |
| 166 | params.type = Widget::InitParams::TYPE_CONTROL; |
| 167 | unparented_control->Init(params); |
| 168 | EXPECT_EQ(root_windows[1], |
| 169 | unparented_control->GetNativeView()->GetRootWindow()); |
| 170 | EXPECT_EQ(internal::kShellWindowId_UnparentedControlContainer, |
| 171 | unparented_control->GetNativeView()->parent()->id()); |
| 172 | |
[email protected] | 95db9c1 | 2013-01-31 11:47:44 | [diff] [blame] | 173 | aura::Window* panel = CreateTestWindowInShellWithDelegateAndType( |
| 174 | NULL, aura::client::WINDOW_TYPE_PANEL, 0, gfx::Rect(700, 100, 100, 100)); |
| 175 | EXPECT_EQ(root_windows[1], panel->GetRootWindow()); |
| 176 | EXPECT_EQ(internal::kShellWindowId_PanelContainer, panel->parent()->id()); |
| 177 | |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 178 | // Make sure a window that will delete itself when losing focus |
| 179 | // will not crash. |
| 180 | aura::WindowTracker tracker; |
| 181 | DeleteOnBlurDelegate delete_on_blur_delegate; |
[email protected] | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 182 | aura::Window* d2 = CreateTestWindowInShellWithDelegate( |
| 183 | &delete_on_blur_delegate, 0, gfx::Rect(50, 50, 100, 100)); |
[email protected] | 792b9b1 | 2012-12-11 03:53:27 | [diff] [blame] | 184 | delete_on_blur_delegate.SetWindow(d2); |
[email protected] | 550543e | 2013-01-11 22:43:44 | [diff] [blame] | 185 | aura::client::GetFocusClient(root_windows[0])->FocusWindow(d2); |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 186 | tracker.Add(d2); |
| 187 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 188 | UpdateDisplay("600x600"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 189 | |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 190 | // d2 must have been deleted. |
| 191 | EXPECT_FALSE(tracker.Contains(d2)); |
| 192 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 193 | EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow()); |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 194 | EXPECT_EQ("50,10 100x100", normal->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 195 | EXPECT_EQ("50,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 196 | normal->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 197 | |
[email protected] | eefd51b2 | 2012-09-25 20:26:24 | [diff] [blame] | 198 | // Maximized area on primary display has 3px (given as |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 199 | // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom. |
| 200 | EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow()); |
[email protected] | 7b675df61 | 2012-09-16 18:33:20 | [diff] [blame] | 201 | EXPECT_EQ("0,0 600x597", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 202 | maximized->GetWindowBoundsInScreen().ToString()); |
[email protected] | 7b675df61 | 2012-09-16 18:33:20 | [diff] [blame] | 203 | EXPECT_EQ("0,0 600x597", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 204 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 205 | |
| 206 | EXPECT_EQ(root_windows[0], minimized->GetNativeView()->GetRootWindow()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 207 | EXPECT_EQ("200,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 208 | minimized->GetWindowBoundsInScreen().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 209 | |
| 210 | EXPECT_EQ(root_windows[0], fullscreen->GetNativeView()->GetRootWindow()); |
| 211 | EXPECT_TRUE(fullscreen->IsFullscreen()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 212 | EXPECT_EQ("0,0 600x600", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 213 | fullscreen->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 214 | EXPECT_EQ("0,0 600x600", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 215 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 216 | |
| 217 | // Test if the restore bounds are correctly updated. |
| 218 | wm::RestoreWindow(maximized->GetNativeView()); |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 219 | EXPECT_EQ("100,10 100x100", maximized->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 220 | EXPECT_EQ("100,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 221 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 222 | |
| 223 | fullscreen->SetFullscreen(false); |
| 224 | EXPECT_EQ("300,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 225 | fullscreen->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 226 | EXPECT_EQ("300,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 227 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | 8f2f15141 | 2013-01-26 03:58:37 | [diff] [blame] | 228 | |
| 229 | // Test if the unparented widget has moved. |
| 230 | EXPECT_EQ(root_windows[0], |
| 231 | unparented_control->GetNativeView()->GetRootWindow()); |
| 232 | EXPECT_EQ(internal::kShellWindowId_UnparentedControlContainer, |
| 233 | unparented_control->GetNativeView()->parent()->id()); |
[email protected] | 95db9c1 | 2013-01-31 11:47:44 | [diff] [blame] | 234 | |
| 235 | // Test if the panel has moved. |
| 236 | EXPECT_EQ(root_windows[0], panel->GetRootWindow()); |
| 237 | EXPECT_EQ(internal::kShellWindowId_PanelContainer, panel->parent()->id()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 238 | } |
| 239 | |
[email protected] | e75642a | 2013-06-12 17:21:18 | [diff] [blame^] | 240 | TEST_F(RootWindowControllerTest, MoveWindows_Modal) { |
| 241 | if (!SupportsMultipleDisplays()) |
| 242 | return; |
[email protected] | 1c3f700 | 2013-01-21 18:46:05 | [diff] [blame] | 243 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 244 | UpdateDisplay("500x500,500x500"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 245 | |
| 246 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 247 | // Emulate virtual screen coordinate system. |
| 248 | root_windows[0]->SetBounds(gfx::Rect(0, 0, 500, 500)); |
| 249 | root_windows[1]->SetBounds(gfx::Rect(500, 0, 500, 500)); |
| 250 | |
| 251 | views::Widget* normal = CreateTestWidget(gfx::Rect(300, 10, 100, 100)); |
| 252 | EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow()); |
| 253 | EXPECT_TRUE(wm::IsActiveWindow(normal->GetNativeView())); |
| 254 | |
| 255 | views::Widget* modal = CreateModalWidget(gfx::Rect(650, 10, 100, 100)); |
| 256 | EXPECT_EQ(root_windows[1], modal->GetNativeView()->GetRootWindow()); |
| 257 | EXPECT_TRUE(GetModalContainer(root_windows[1])->Contains( |
| 258 | modal->GetNativeView())); |
| 259 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 260 | |
| 261 | aura::test::EventGenerator generator_1st(root_windows[0]); |
| 262 | generator_1st.ClickLeftButton(); |
| 263 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 264 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 265 | UpdateDisplay("500x500"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 266 | EXPECT_EQ(root_windows[0], modal->GetNativeView()->GetRootWindow()); |
| 267 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 268 | generator_1st.ClickLeftButton(); |
| 269 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 270 | } |
| 271 | |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 272 | TEST_F(RootWindowControllerTest, ModalContainer) { |
| 273 | UpdateDisplay("600x600"); |
| 274 | Shell* shell = Shell::GetInstance(); |
| 275 | internal::RootWindowController* controller = |
| 276 | shell->GetPrimaryRootWindowController(); |
| 277 | EXPECT_EQ(user::LOGGED_IN_USER, |
[email protected] | 945f9cae | 2012-12-12 09:54:29 | [diff] [blame] | 278 | shell->system_tray_delegate()->GetUserLoginStatus()); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 279 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 280 | internal::kShellWindowId_SystemModalContainer)->layout_manager(), |
| 281 | controller->GetSystemModalLayoutManager(NULL)); |
| 282 | |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 283 | views::Widget* session_modal_widget = |
| 284 | CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
| 285 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 286 | internal::kShellWindowId_SystemModalContainer)->layout_manager(), |
| 287 | controller->GetSystemModalLayoutManager( |
| 288 | session_modal_widget->GetNativeView())); |
| 289 | |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 290 | shell->session_state_delegate()->LockScreen(); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 291 | EXPECT_EQ(user::LOGGED_IN_LOCKED, |
[email protected] | 945f9cae | 2012-12-12 09:54:29 | [diff] [blame] | 292 | shell->system_tray_delegate()->GetUserLoginStatus()); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 293 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 294 | internal::kShellWindowId_LockSystemModalContainer)->layout_manager(), |
| 295 | controller->GetSystemModalLayoutManager(NULL)); |
[email protected] | 3b162e1 | 2012-11-09 11:52:35 | [diff] [blame] | 296 | |
| 297 | aura::Window* lock_container = |
| 298 | Shell::GetContainer(controller->root_window(), |
| 299 | internal::kShellWindowId_LockScreenContainer); |
| 300 | views::Widget* lock_modal_widget = |
| 301 | CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container); |
| 302 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 303 | internal::kShellWindowId_LockSystemModalContainer)->layout_manager(), |
| 304 | controller->GetSystemModalLayoutManager( |
| 305 | lock_modal_widget->GetNativeView())); |
| 306 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 307 | internal::kShellWindowId_SystemModalContainer)->layout_manager(), |
| 308 | controller->GetSystemModalLayoutManager( |
| 309 | session_modal_widget->GetNativeView())); |
| 310 | |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 311 | shell->session_state_delegate()->UnlockScreen(); |
[email protected] | 8674b31 | 2012-10-12 19:02:44 | [diff] [blame] | 312 | } |
| 313 | |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 314 | TEST_F(RootWindowControllerTest, ModalContainerNotLoggedInLoggedIn) { |
| 315 | UpdateDisplay("600x600"); |
| 316 | Shell* shell = Shell::GetInstance(); |
| 317 | |
| 318 | // Configure login screen environment. |
| 319 | SetUserLoggedIn(false); |
| 320 | EXPECT_EQ(user::LOGGED_IN_NONE, |
[email protected] | 945f9cae | 2012-12-12 09:54:29 | [diff] [blame] | 321 | shell->system_tray_delegate()->GetUserLoginStatus()); |
[email protected] | c8d19f8 | 2013-05-18 09:09:41 | [diff] [blame] | 322 | EXPECT_EQ(0, shell->session_state_delegate()->NumberOfLoggedInUsers()); |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 323 | EXPECT_FALSE(shell->session_state_delegate()->IsActiveUserSessionStarted()); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 324 | |
| 325 | internal::RootWindowController* controller = |
| 326 | shell->GetPrimaryRootWindowController(); |
| 327 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 328 | internal::kShellWindowId_LockSystemModalContainer)->layout_manager(), |
| 329 | controller->GetSystemModalLayoutManager(NULL)); |
| 330 | |
| 331 | aura::Window* lock_container = |
| 332 | Shell::GetContainer(controller->root_window(), |
| 333 | internal::kShellWindowId_LockScreenContainer); |
| 334 | views::Widget* login_modal_widget = |
| 335 | CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container); |
| 336 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 337 | internal::kShellWindowId_LockSystemModalContainer)->layout_manager(), |
| 338 | controller->GetSystemModalLayoutManager( |
| 339 | login_modal_widget->GetNativeView())); |
| 340 | login_modal_widget->Close(); |
| 341 | |
| 342 | // Configure user session environment. |
| 343 | SetUserLoggedIn(true); |
| 344 | SetSessionStarted(true); |
| 345 | EXPECT_EQ(user::LOGGED_IN_USER, |
[email protected] | 945f9cae | 2012-12-12 09:54:29 | [diff] [blame] | 346 | shell->system_tray_delegate()->GetUserLoginStatus()); |
[email protected] | c8d19f8 | 2013-05-18 09:09:41 | [diff] [blame] | 347 | EXPECT_EQ(1, shell->session_state_delegate()->NumberOfLoggedInUsers()); |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 348 | EXPECT_TRUE(shell->session_state_delegate()->IsActiveUserSessionStarted()); |
[email protected] | 1b21992 | 2012-11-13 21:16:43 | [diff] [blame] | 349 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 350 | internal::kShellWindowId_SystemModalContainer)->layout_manager(), |
| 351 | controller->GetSystemModalLayoutManager(NULL)); |
| 352 | |
| 353 | views::Widget* session_modal_widget = |
| 354 | CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
| 355 | EXPECT_EQ(Shell::GetContainer(controller->root_window(), |
| 356 | internal::kShellWindowId_SystemModalContainer)->layout_manager(), |
| 357 | controller->GetSystemModalLayoutManager( |
| 358 | session_modal_widget->GetNativeView())); |
| 359 | } |
| 360 | |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 361 | // Test that GetFullscreenWindow() returns a fullscreen window only if the |
| 362 | // fullscreen window is in the active workspace. |
| 363 | TEST_F(RootWindowControllerTest, GetFullscreenWindow) { |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 364 | UpdateDisplay("600x600"); |
| 365 | internal::RootWindowController* controller = |
| 366 | Shell::GetInstance()->GetPrimaryRootWindowController(); |
| 367 | |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 368 | Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 369 | w1->Maximize(); |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 370 | Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100)); |
| 371 | w2->SetFullscreen(true); |
| 372 | // |w3| is a transient child of |w2|. |
| 373 | Widget* w3 = Widget::CreateWindowWithParentAndBounds(NULL, |
| 374 | w2->GetNativeWindow(), gfx::Rect(0, 0, 100, 100)); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 375 | |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 376 | // Test that GetFullscreenWindow() finds the fullscreen window when one of |
| 377 | // its transient children is active. |
| 378 | w3->Activate(); |
| 379 | EXPECT_EQ(w2->GetNativeWindow(), controller->GetFullscreenWindow()); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 380 | |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 381 | // Activate the maximized window's workspace. GetFullscreenWindow() should |
| 382 | // fail because the fullscreen window's workspace is no longer active. |
| 383 | w1->Activate(); |
| 384 | EXPECT_FALSE(controller->GetFullscreenWindow()); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 385 | |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 386 | // If the fullscreen window is active, GetFullscreenWindow() should find it. |
| 387 | w2->Activate(); |
| 388 | EXPECT_EQ(w2->GetNativeWindow(), controller->GetFullscreenWindow()); |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 389 | } |
| 390 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 391 | } // namespace test |
| 392 | } // namespace ash |