| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/wm/system_modal_container_layout_manager.h" | 5 #include "ash/wm/system_modal_container_layout_manager.h" |
| 6 | 6 |
| 7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_delegate.h" | 9 #include "ash/shell_delegate.h" |
| 10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 bool AllRootWindowsHaveModalBackgrounds() { | 51 bool AllRootWindowsHaveModalBackgrounds() { |
| 52 return AllRootWindowsHaveModalBackgroundsForContainer( | 52 return AllRootWindowsHaveModalBackgroundsForContainer( |
| 53 internal::kShellWindowId_SystemModalContainer); | 53 internal::kShellWindowId_SystemModalContainer); |
| 54 } | 54 } |
| 55 | 55 |
| 56 class TestWindow : public views::WidgetDelegateView { | 56 class TestWindow : public views::WidgetDelegateView { |
| 57 public: | 57 public: |
| 58 explicit TestWindow(bool modal) : modal_(modal) {} | 58 explicit TestWindow(bool modal) : modal_(modal) {} |
| 59 virtual ~TestWindow() {} | 59 virtual ~TestWindow() {} |
| 60 | 60 |
| 61 static aura::Window* OpenTestWindow(aura::Window* parent, bool modal) { | |
| 62 views::Widget* widget = | |
| 63 views::Widget::CreateWindowWithParent(new TestWindow(modal), parent); | |
| 64 widget->Show(); | |
| 65 return widget->GetNativeView(); | |
| 66 } | |
| 67 | |
| 68 // The window needs be closed from widget in order for | 61 // The window needs be closed from widget in order for |
| 69 // aura::client::kModalKey property to be reset. | 62 // aura::client::kModalKey property to be reset. |
| 70 static void CloseTestWindow(aura::Window* window) { | 63 static void CloseTestWindow(aura::Window* window) { |
| 71 views::Widget::GetWidgetForNativeWindow(window)->Close(); | 64 views::Widget::GetWidgetForNativeWindow(window)->Close(); |
| 72 } | 65 } |
| 73 | 66 |
| 74 // Overridden from views::View: | 67 // Overridden from views::View: |
| 75 virtual gfx::Size GetPreferredSize() OVERRIDE { | 68 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 76 return gfx::Size(50, 50); | 69 return gfx::Size(50, 50); |
| 77 } | 70 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 89 | 82 |
| 90 DISALLOW_COPY_AND_ASSIGN(TestWindow); | 83 DISALLOW_COPY_AND_ASSIGN(TestWindow); |
| 91 }; | 84 }; |
| 92 | 85 |
| 93 class EventTestWindow : public TestWindow { | 86 class EventTestWindow : public TestWindow { |
| 94 public: | 87 public: |
| 95 explicit EventTestWindow(bool modal) : TestWindow(modal), | 88 explicit EventTestWindow(bool modal) : TestWindow(modal), |
| 96 mouse_presses_(0) {} | 89 mouse_presses_(0) {} |
| 97 virtual ~EventTestWindow() {} | 90 virtual ~EventTestWindow() {} |
| 98 | 91 |
| 99 aura::Window* OpenTestWindow(aura::Window* parent) { | 92 aura::Window* OpenTestWindowWithContext(aura::RootWindow* context) { |
| 93 views::Widget* widget = |
| 94 views::Widget::CreateWindowWithContext(this, context); |
| 95 widget->Show(); |
| 96 return widget->GetNativeView(); |
| 97 } |
| 98 |
| 99 aura::Window* OpenTestWindowWithParent(aura::Window* parent) { |
| 100 DCHECK(parent); |
| 100 views::Widget* widget = | 101 views::Widget* widget = |
| 101 views::Widget::CreateWindowWithParent(this, parent); | 102 views::Widget::CreateWindowWithParent(this, parent); |
| 102 widget->Show(); | 103 widget->Show(); |
| 103 return widget->GetNativeView(); | 104 return widget->GetNativeView(); |
| 104 } | 105 } |
| 105 | 106 |
| 106 // Overridden from views::View: | 107 // Overridden from views::View: |
| 107 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE { | 108 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE { |
| 108 mouse_presses_++; | 109 mouse_presses_++; |
| 109 return false; | 110 return false; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 129 } | 130 } |
| 130 | 131 |
| 131 private: | 132 private: |
| 132 bool destroyed_; | 133 bool destroyed_; |
| 133 | 134 |
| 134 DISALLOW_COPY_AND_ASSIGN(TransientWindowObserver); | 135 DISALLOW_COPY_AND_ASSIGN(TransientWindowObserver); |
| 135 }; | 136 }; |
| 136 | 137 |
| 137 } // namespace | 138 } // namespace |
| 138 | 139 |
| 139 typedef AshTestBase SystemModalContainerLayoutManagerTest; | 140 class SystemModalContainerLayoutManagerTest : public AshTestBase { |
| 141 public: |
| 142 aura::Window* OpenToplevelTestWindow(bool modal) { |
| 143 views::Widget* widget = views::Widget::CreateWindowWithContext( |
| 144 new TestWindow(modal), CurrentContext()); |
| 145 widget->Show(); |
| 146 return widget->GetNativeView(); |
| 147 } |
| 148 |
| 149 aura::Window* OpenTestWindowWithParent(aura::Window* parent, bool modal) { |
| 150 views::Widget* widget = |
| 151 views::Widget::CreateWindowWithParent(new TestWindow(modal), parent); |
| 152 widget->Show(); |
| 153 return widget->GetNativeView(); |
| 154 } |
| 155 }; |
| 140 | 156 |
| 141 TEST_F(SystemModalContainerLayoutManagerTest, NonModalTransient) { | 157 TEST_F(SystemModalContainerLayoutManagerTest, NonModalTransient) { |
| 142 scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false)); | 158 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
| 143 aura::Window* transient = TestWindow::OpenTestWindow(parent.get(), false); | 159 aura::Window* transient = OpenTestWindowWithParent(parent.get(), false); |
| 144 TransientWindowObserver destruction_observer; | 160 TransientWindowObserver destruction_observer; |
| 145 transient->AddObserver(&destruction_observer); | 161 transient->AddObserver(&destruction_observer); |
| 146 | 162 |
| 147 EXPECT_EQ(parent.get(), transient->transient_parent()); | 163 EXPECT_EQ(parent.get(), transient->transient_parent()); |
| 148 EXPECT_EQ(parent->parent(), transient->parent()); | 164 EXPECT_EQ(parent->parent(), transient->parent()); |
| 149 | 165 |
| 150 // The transient should be destroyed with its parent. | 166 // The transient should be destroyed with its parent. |
| 151 parent.reset(); | 167 parent.reset(); |
| 152 EXPECT_TRUE(destruction_observer.destroyed()); | 168 EXPECT_TRUE(destruction_observer.destroyed()); |
| 153 } | 169 } |
| 154 | 170 |
| 155 TEST_F(SystemModalContainerLayoutManagerTest, ModalTransient) { | 171 TEST_F(SystemModalContainerLayoutManagerTest, ModalTransient) { |
| 156 scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false)); | 172 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
| 157 // parent should be active. | 173 // parent should be active. |
| 158 EXPECT_TRUE(wm::IsActiveWindow(parent.get())); | 174 EXPECT_TRUE(wm::IsActiveWindow(parent.get())); |
| 159 aura::Window* t1 = TestWindow::OpenTestWindow(parent.get(), true); | 175 aura::Window* t1 = OpenTestWindowWithParent(parent.get(), true); |
| 160 | 176 |
| 161 TransientWindowObserver do1; | 177 TransientWindowObserver do1; |
| 162 t1->AddObserver(&do1); | 178 t1->AddObserver(&do1); |
| 163 | 179 |
| 164 EXPECT_EQ(parent.get(), t1->transient_parent()); | 180 EXPECT_EQ(parent.get(), t1->transient_parent()); |
| 165 EXPECT_EQ(GetModalContainer(), t1->parent()); | 181 EXPECT_EQ(GetModalContainer(), t1->parent()); |
| 166 | 182 |
| 167 // t1 should now be active. | 183 // t1 should now be active. |
| 168 EXPECT_TRUE(wm::IsActiveWindow(t1)); | 184 EXPECT_TRUE(wm::IsActiveWindow(t1)); |
| 169 | 185 |
| 170 // Attempting to click the parent should result in no activation change. | 186 // Attempting to click the parent should result in no activation change. |
| 171 aura::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), parent.get()); | 187 aura::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), parent.get()); |
| 172 e1.ClickLeftButton(); | 188 e1.ClickLeftButton(); |
| 173 EXPECT_TRUE(wm::IsActiveWindow(t1)); | 189 EXPECT_TRUE(wm::IsActiveWindow(t1)); |
| 174 | 190 |
| 175 // Now open another modal transient parented to the original modal transient. | 191 // Now open another modal transient parented to the original modal transient. |
| 176 aura::Window* t2 = TestWindow::OpenTestWindow(t1, true); | 192 aura::Window* t2 = OpenTestWindowWithParent(t1, true); |
| 177 TransientWindowObserver do2; | 193 TransientWindowObserver do2; |
| 178 t2->AddObserver(&do2); | 194 t2->AddObserver(&do2); |
| 179 | 195 |
| 180 EXPECT_TRUE(wm::IsActiveWindow(t2)); | 196 EXPECT_TRUE(wm::IsActiveWindow(t2)); |
| 181 | 197 |
| 182 EXPECT_EQ(t1, t2->transient_parent()); | 198 EXPECT_EQ(t1, t2->transient_parent()); |
| 183 EXPECT_EQ(GetModalContainer(), t2->parent()); | 199 EXPECT_EQ(GetModalContainer(), t2->parent()); |
| 184 | 200 |
| 185 // t2 should still be active, even after clicking on t1. | 201 // t2 should still be active, even after clicking on t1. |
| 186 aura::test::EventGenerator e2(Shell::GetPrimaryRootWindow(), t1); | 202 aura::test::EventGenerator e2(Shell::GetPrimaryRootWindow(), t1); |
| 187 e2.ClickLeftButton(); | 203 e2.ClickLeftButton(); |
| 188 EXPECT_TRUE(wm::IsActiveWindow(t2)); | 204 EXPECT_TRUE(wm::IsActiveWindow(t2)); |
| 189 | 205 |
| 190 // Both transients should be destroyed with parent. | 206 // Both transients should be destroyed with parent. |
| 191 parent.reset(); | 207 parent.reset(); |
| 192 EXPECT_TRUE(do1.destroyed()); | 208 EXPECT_TRUE(do1.destroyed()); |
| 193 EXPECT_TRUE(do2.destroyed()); | 209 EXPECT_TRUE(do2.destroyed()); |
| 194 } | 210 } |
| 195 | 211 |
| 196 TEST_F(SystemModalContainerLayoutManagerTest, ModalNonTransient) { | 212 TEST_F(SystemModalContainerLayoutManagerTest, ModalNonTransient) { |
| 197 scoped_ptr<aura::Window> t1(TestWindow::OpenTestWindow(NULL, true)); | 213 scoped_ptr<aura::Window> t1(OpenToplevelTestWindow(true)); |
| 198 // parent should be active. | 214 // parent should be active. |
| 199 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); | 215 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); |
| 200 TransientWindowObserver do1; | 216 TransientWindowObserver do1; |
| 201 t1->AddObserver(&do1); | 217 t1->AddObserver(&do1); |
| 202 | 218 |
| 203 EXPECT_EQ(NULL, t1->transient_parent()); | 219 EXPECT_EQ(NULL, t1->transient_parent()); |
| 204 EXPECT_EQ(GetModalContainer(), t1->parent()); | 220 EXPECT_EQ(GetModalContainer(), t1->parent()); |
| 205 | 221 |
| 206 // t1 should now be active. | 222 // t1 should now be active. |
| 207 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); | 223 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); |
| 208 | 224 |
| 209 // Attempting to click the parent should result in no activation change. | 225 // Attempting to click the parent should result in no activation change. |
| 210 aura::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), | 226 aura::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), |
| 211 Shell::GetPrimaryRootWindow()); | 227 Shell::GetPrimaryRootWindow()); |
| 212 e1.ClickLeftButton(); | 228 e1.ClickLeftButton(); |
| 213 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); | 229 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); |
| 214 | 230 |
| 215 // Now open another modal transient parented to the original modal transient. | 231 // Now open another modal transient parented to the original modal transient. |
| 216 aura::Window* t2 = TestWindow::OpenTestWindow(t1.get(), true); | 232 aura::Window* t2 = OpenTestWindowWithParent(t1.get(), true); |
| 217 TransientWindowObserver do2; | 233 TransientWindowObserver do2; |
| 218 t2->AddObserver(&do2); | 234 t2->AddObserver(&do2); |
| 219 | 235 |
| 220 EXPECT_TRUE(wm::IsActiveWindow(t2)); | 236 EXPECT_TRUE(wm::IsActiveWindow(t2)); |
| 221 | 237 |
| 222 EXPECT_EQ(t1, t2->transient_parent()); | 238 EXPECT_EQ(t1, t2->transient_parent()); |
| 223 EXPECT_EQ(GetModalContainer(), t2->parent()); | 239 EXPECT_EQ(GetModalContainer(), t2->parent()); |
| 224 | 240 |
| 225 // t2 should still be active, even after clicking on t1. | 241 // t2 should still be active, even after clicking on t1. |
| 226 aura::test::EventGenerator e2(Shell::GetPrimaryRootWindow(), t1.get()); | 242 aura::test::EventGenerator e2(Shell::GetPrimaryRootWindow(), t1.get()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 237 #if defined(OS_MACOSX) | 253 #if defined(OS_MACOSX) |
| 238 #define MAYBE_CanActivateAfterEndModalSession \ | 254 #define MAYBE_CanActivateAfterEndModalSession \ |
| 239 DISABLED_CanActivateAfterEndModalSession | 255 DISABLED_CanActivateAfterEndModalSession |
| 240 #else | 256 #else |
| 241 #define MAYBE_CanActivateAfterEndModalSession CanActivateAfterEndModalSession | 257 #define MAYBE_CanActivateAfterEndModalSession CanActivateAfterEndModalSession |
| 242 #endif | 258 #endif |
| 243 // Tests that we can activate an unrelated window after a modal window is closed | 259 // Tests that we can activate an unrelated window after a modal window is closed |
| 244 // for a window. | 260 // for a window. |
| 245 TEST_F(SystemModalContainerLayoutManagerTest, | 261 TEST_F(SystemModalContainerLayoutManagerTest, |
| 246 MAYBE_CanActivateAfterEndModalSession) { | 262 MAYBE_CanActivateAfterEndModalSession) { |
| 247 scoped_ptr<aura::Window> unrelated(TestWindow::OpenTestWindow(NULL, false)); | 263 scoped_ptr<aura::Window> unrelated(OpenToplevelTestWindow(false)); |
| 248 unrelated->SetBounds(gfx::Rect(100, 100, 50, 50)); | 264 unrelated->SetBounds(gfx::Rect(100, 100, 50, 50)); |
| 249 scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false)); | 265 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
| 250 // parent should be active. | 266 // parent should be active. |
| 251 EXPECT_TRUE(wm::IsActiveWindow(parent.get())); | 267 EXPECT_TRUE(wm::IsActiveWindow(parent.get())); |
| 252 | 268 |
| 253 scoped_ptr<aura::Window> transient( | 269 scoped_ptr<aura::Window> transient( |
| 254 TestWindow::OpenTestWindow(parent.get(), true)); | 270 OpenTestWindowWithParent(parent.get(), true)); |
| 255 // t1 should now be active. | 271 // t1 should now be active. |
| 256 EXPECT_TRUE(wm::IsActiveWindow(transient.get())); | 272 EXPECT_TRUE(wm::IsActiveWindow(transient.get())); |
| 257 | 273 |
| 258 // Attempting to click the parent should result in no activation change. | 274 // Attempting to click the parent should result in no activation change. |
| 259 aura::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), parent.get()); | 275 aura::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), parent.get()); |
| 260 e1.ClickLeftButton(); | 276 e1.ClickLeftButton(); |
| 261 EXPECT_TRUE(wm::IsActiveWindow(transient.get())); | 277 EXPECT_TRUE(wm::IsActiveWindow(transient.get())); |
| 262 | 278 |
| 263 // Now close the transient. | 279 // Now close the transient. |
| 264 transient->Hide(); | 280 transient->Hide(); |
| 265 TestWindow::CloseTestWindow(transient.release()); | 281 TestWindow::CloseTestWindow(transient.release()); |
| 266 | 282 |
| 267 MessageLoopForUI::current()->RunUntilIdle(); | 283 MessageLoopForUI::current()->RunUntilIdle(); |
| 268 | 284 |
| 269 // parent should now be active again. | 285 // parent should now be active again. |
| 270 EXPECT_TRUE(wm::IsActiveWindow(parent.get())); | 286 EXPECT_TRUE(wm::IsActiveWindow(parent.get())); |
| 271 | 287 |
| 272 // Attempting to click unrelated should activate it. | 288 // Attempting to click unrelated should activate it. |
| 273 aura::test::EventGenerator e2(Shell::GetPrimaryRootWindow(), unrelated.get()); | 289 aura::test::EventGenerator e2(Shell::GetPrimaryRootWindow(), unrelated.get()); |
| 274 e2.ClickLeftButton(); | 290 e2.ClickLeftButton(); |
| 275 EXPECT_TRUE(wm::IsActiveWindow(unrelated.get())); | 291 EXPECT_TRUE(wm::IsActiveWindow(unrelated.get())); |
| 276 } | 292 } |
| 277 | 293 |
| 278 TEST_F(SystemModalContainerLayoutManagerTest, EventFocusContainers) { | 294 TEST_F(SystemModalContainerLayoutManagerTest, EventFocusContainers) { |
| 279 // Create a normal window and attempt to receive a click event. | 295 // Create a normal window and attempt to receive a click event. |
| 280 EventTestWindow* main_delegate = new EventTestWindow(false); | 296 EventTestWindow* main_delegate = new EventTestWindow(false); |
| 281 scoped_ptr<aura::Window> main(main_delegate->OpenTestWindow(NULL)); | 297 scoped_ptr<aura::Window> main( |
| 298 main_delegate->OpenTestWindowWithContext(CurrentContext())); |
| 282 EXPECT_TRUE(wm::IsActiveWindow(main.get())); | 299 EXPECT_TRUE(wm::IsActiveWindow(main.get())); |
| 283 aura::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), main.get()); | 300 aura::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), main.get()); |
| 284 e1.ClickLeftButton(); | 301 e1.ClickLeftButton(); |
| 285 EXPECT_EQ(1, main_delegate->mouse_presses()); | 302 EXPECT_EQ(1, main_delegate->mouse_presses()); |
| 286 | 303 |
| 287 // Create a modal window for the main window and verify that the main window | 304 // Create a modal window for the main window and verify that the main window |
| 288 // no longer receives mouse events. | 305 // no longer receives mouse events. |
| 289 EventTestWindow* transient_delegate = new EventTestWindow(true); | 306 EventTestWindow* transient_delegate = new EventTestWindow(true); |
| 290 aura::Window* transient = transient_delegate->OpenTestWindow(main.get()); | 307 aura::Window* transient = |
| 308 transient_delegate->OpenTestWindowWithParent(main.get()); |
| 291 EXPECT_TRUE(wm::IsActiveWindow(transient)); | 309 EXPECT_TRUE(wm::IsActiveWindow(transient)); |
| 292 e1.ClickLeftButton(); | 310 e1.ClickLeftButton(); |
| 293 EXPECT_EQ(1, transient_delegate->mouse_presses()); | 311 EXPECT_EQ(1, transient_delegate->mouse_presses()); |
| 294 | 312 |
| 295 // Create a window in the lock screen container and ensure that it receives | 313 // Create a window in the lock screen container and ensure that it receives |
| 296 // the mouse event instead of the modal window (crbug.com/110920). | 314 // the mouse event instead of the modal window (crbug.com/110920). |
| 297 Shell::GetInstance()->delegate()->LockScreen(); | 315 Shell::GetInstance()->delegate()->LockScreen(); |
| 298 EventTestWindow* lock_delegate = new EventTestWindow(false); | 316 EventTestWindow* lock_delegate = new EventTestWindow(false); |
| 299 scoped_ptr<aura::Window> lock(lock_delegate->OpenTestWindow( | 317 scoped_ptr<aura::Window> lock(lock_delegate->OpenTestWindowWithParent( |
| 300 Shell::GetPrimaryRootWindowController()->GetContainer( | 318 Shell::GetPrimaryRootWindowController()->GetContainer( |
| 301 ash::internal::kShellWindowId_LockScreenContainer))); | 319 ash::internal::kShellWindowId_LockScreenContainer))); |
| 302 EXPECT_TRUE(wm::IsActiveWindow(lock.get())); | 320 EXPECT_TRUE(wm::IsActiveWindow(lock.get())); |
| 303 e1.ClickLeftButton(); | 321 e1.ClickLeftButton(); |
| 304 EXPECT_EQ(1, lock_delegate->mouse_presses()); | 322 EXPECT_EQ(1, lock_delegate->mouse_presses()); |
| 305 | 323 |
| 306 // Make sure that a modal container created by the lock screen can still | 324 // Make sure that a modal container created by the lock screen can still |
| 307 // receive mouse events. | 325 // receive mouse events. |
| 308 EventTestWindow* lock_modal_delegate = new EventTestWindow(true); | 326 EventTestWindow* lock_modal_delegate = new EventTestWindow(true); |
| 309 aura::Window* lock_modal = lock_modal_delegate->OpenTestWindow(lock.get()); | 327 aura::Window* lock_modal = |
| 328 lock_modal_delegate->OpenTestWindowWithParent(lock.get()); |
| 310 EXPECT_TRUE(wm::IsActiveWindow(lock_modal)); | 329 EXPECT_TRUE(wm::IsActiveWindow(lock_modal)); |
| 311 e1.ClickLeftButton(); | 330 e1.ClickLeftButton(); |
| 312 EXPECT_EQ(1, lock_modal_delegate->mouse_presses()); | 331 EXPECT_EQ(1, lock_modal_delegate->mouse_presses()); |
| 313 | 332 |
| 314 // Verify that none of the other containers received any more mouse presses. | 333 // Verify that none of the other containers received any more mouse presses. |
| 315 EXPECT_EQ(1, main_delegate->mouse_presses()); | 334 EXPECT_EQ(1, main_delegate->mouse_presses()); |
| 316 EXPECT_EQ(1, transient_delegate->mouse_presses()); | 335 EXPECT_EQ(1, transient_delegate->mouse_presses()); |
| 317 EXPECT_EQ(1, lock_delegate->mouse_presses()); | 336 EXPECT_EQ(1, lock_delegate->mouse_presses()); |
| 318 EXPECT_EQ(1, lock_modal_delegate->mouse_presses()); | 337 EXPECT_EQ(1, lock_modal_delegate->mouse_presses()); |
| 319 | 338 |
| 320 Shell::GetInstance()->delegate()->UnlockScreen(); | 339 Shell::GetInstance()->delegate()->UnlockScreen(); |
| 321 } | 340 } |
| 322 | 341 |
| 323 // Makes sure we don't crash if a modal window is shown while the parent window | 342 // Makes sure we don't crash if a modal window is shown while the parent window |
| 324 // is hidden. | 343 // is hidden. |
| 325 TEST_F(SystemModalContainerLayoutManagerTest, ShowModalWhileHidden) { | 344 TEST_F(SystemModalContainerLayoutManagerTest, ShowModalWhileHidden) { |
| 326 // Hide the lock screen. | 345 // Hide the lock screen. |
| 327 Shell::GetPrimaryRootWindowController()->GetContainer( | 346 Shell::GetPrimaryRootWindowController()->GetContainer( |
| 328 internal::kShellWindowId_SystemModalContainer)->layer()->SetOpacity(0); | 347 internal::kShellWindowId_SystemModalContainer)->layer()->SetOpacity(0); |
| 329 | 348 |
| 330 // Create a modal window. | 349 // Create a modal window. |
| 331 scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false)); | 350 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
| 332 scoped_ptr<aura::Window> modal_window( | 351 scoped_ptr<aura::Window> modal_window( |
| 333 TestWindow::OpenTestWindow(parent.get(), true)); | 352 OpenTestWindowWithParent(parent.get(), true)); |
| 334 parent->Show(); | 353 parent->Show(); |
| 335 modal_window->Show(); | 354 modal_window->Show(); |
| 336 } | 355 } |
| 337 | 356 |
| 338 // Verifies we generate a capture lost when showing a modal window. | 357 // Verifies we generate a capture lost when showing a modal window. |
| 339 TEST_F(SystemModalContainerLayoutManagerTest, ChangeCapture) { | 358 TEST_F(SystemModalContainerLayoutManagerTest, ChangeCapture) { |
| 340 views::Widget* widget = | 359 views::Widget* widget = views::Widget::CreateWindowWithContext( |
| 341 views::Widget::CreateWindowWithParent(new TestWindow(false), NULL); | 360 new TestWindow(false), CurrentContext()); |
| 342 scoped_ptr<aura::Window> widget_window(widget->GetNativeView()); | 361 scoped_ptr<aura::Window> widget_window(widget->GetNativeView()); |
| 343 views::test::CaptureTrackingView* view = new views::test::CaptureTrackingView; | 362 views::test::CaptureTrackingView* view = new views::test::CaptureTrackingView; |
| 344 widget->GetContentsView()->AddChildView(view); | 363 widget->GetContentsView()->AddChildView(view); |
| 345 view->SetBoundsRect(widget->GetContentsView()->bounds()); | 364 view->SetBoundsRect(widget->GetContentsView()->bounds()); |
| 346 widget->Show(); | 365 widget->Show(); |
| 347 | 366 |
| 348 gfx::Point center(view->width() / 2, view->height() / 2); | 367 gfx::Point center(view->width() / 2, view->height() / 2); |
| 349 views::View::ConvertPointToScreen(view, ¢er); | 368 views::View::ConvertPointToScreen(view, ¢er); |
| 350 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), center); | 369 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), center); |
| 351 generator.PressLeftButton(); | 370 generator.PressLeftButton(); |
| 352 EXPECT_TRUE(view->got_press()); | 371 EXPECT_TRUE(view->got_press()); |
| 353 scoped_ptr<aura::Window> modal_window( | 372 scoped_ptr<aura::Window> modal_window( |
| 354 TestWindow::OpenTestWindow(widget->GetNativeView(), true)); | 373 OpenTestWindowWithParent(widget->GetNativeView(), true)); |
| 355 modal_window->Show(); | 374 modal_window->Show(); |
| 356 EXPECT_TRUE(view->got_capture_lost()); | 375 EXPECT_TRUE(view->got_capture_lost()); |
| 357 } | 376 } |
| 358 | 377 |
| 359 // Verifies that the window gets moved into the visible screen area upon screen | 378 // Verifies that the window gets moved into the visible screen area upon screen |
| 360 // resize. | 379 // resize. |
| 361 TEST_F(SystemModalContainerLayoutManagerTest, KeepVisible) { | 380 TEST_F(SystemModalContainerLayoutManagerTest, KeepVisible) { |
| 362 GetModalContainer()->SetBounds(gfx::Rect(0, 0, 1024, 768)); | 381 GetModalContainer()->SetBounds(gfx::Rect(0, 0, 1024, 768)); |
| 363 scoped_ptr<aura::Window> main(TestWindow::OpenTestWindow(GetModalContainer(), | 382 scoped_ptr<aura::Window> main(OpenTestWindowWithParent(GetModalContainer(), |
| 364 true)); | 383 true)); |
| 365 main->SetBounds(gfx::Rect(924, 668, 100, 100)); | 384 main->SetBounds(gfx::Rect(924, 668, 100, 100)); |
| 366 // We set now the bounds of the root window to something new which will | 385 // We set now the bounds of the root window to something new which will |
| 367 // Then trigger the repos operation. | 386 // Then trigger the repos operation. |
| 368 GetModalContainer()->SetBounds(gfx::Rect(0, 0, 800, 600)); | 387 GetModalContainer()->SetBounds(gfx::Rect(0, 0, 800, 600)); |
| 369 | 388 |
| 370 gfx::Rect bounds = main->bounds(); | 389 gfx::Rect bounds = main->bounds(); |
| 371 EXPECT_EQ(bounds, gfx::Rect(700, 500, 100, 100)); | 390 EXPECT_EQ(bounds, gfx::Rect(700, 500, 100, 100)); |
| 372 } | 391 } |
| 373 | 392 |
| 374 TEST_F(SystemModalContainerLayoutManagerTest, ShowNormalBackgroundOrLocked) { | 393 TEST_F(SystemModalContainerLayoutManagerTest, ShowNormalBackgroundOrLocked) { |
| 375 scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false)); | 394 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
| 376 scoped_ptr<aura::Window> modal_window( | 395 scoped_ptr<aura::Window> modal_window( |
| 377 TestWindow::OpenTestWindow(parent.get(), true)); | 396 OpenTestWindowWithParent(parent.get(), true)); |
| 378 parent->Show(); | 397 parent->Show(); |
| 379 modal_window->Show(); | 398 modal_window->Show(); |
| 380 | 399 |
| 381 // Normal system modal window. Shows normal system modal background and not | 400 // Normal system modal window. Shows normal system modal background and not |
| 382 // locked. | 401 // locked. |
| 383 EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); | 402 EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); |
| 384 EXPECT_FALSE(AllRootWindowsHaveLockedModalBackgrounds()); | 403 EXPECT_FALSE(AllRootWindowsHaveLockedModalBackgrounds()); |
| 385 | 404 |
| 386 TestWindow::CloseTestWindow(modal_window.release()); | 405 TestWindow::CloseTestWindow(modal_window.release()); |
| 387 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); | 406 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); |
| 388 EXPECT_FALSE(AllRootWindowsHaveLockedModalBackgrounds()); | 407 EXPECT_FALSE(AllRootWindowsHaveLockedModalBackgrounds()); |
| 389 | 408 |
| 390 // Normal system modal window while locked. Shows locked system modal | 409 // Normal system modal window while locked. Shows locked system modal |
| 391 // background. | 410 // background. |
| 392 Shell::GetInstance()->delegate()->LockScreen(); | 411 Shell::GetInstance()->delegate()->LockScreen(); |
| 393 scoped_ptr<aura::Window> lock_parent(TestWindow::OpenTestWindow( | 412 scoped_ptr<aura::Window> lock_parent(OpenTestWindowWithParent( |
| 394 Shell::GetPrimaryRootWindowController()->GetContainer( | 413 Shell::GetPrimaryRootWindowController()->GetContainer( |
| 395 ash::internal::kShellWindowId_LockScreenContainer), | 414 ash::internal::kShellWindowId_LockScreenContainer), |
| 396 false)); | 415 false)); |
| 397 scoped_ptr<aura::Window> lock_modal_window(TestWindow::OpenTestWindow( | 416 scoped_ptr<aura::Window> lock_modal_window(OpenTestWindowWithParent( |
| 398 lock_parent.get(), true)); | 417 lock_parent.get(), true)); |
| 399 lock_parent->Show(); | 418 lock_parent->Show(); |
| 400 lock_modal_window->Show(); | 419 lock_modal_window->Show(); |
| 401 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); | 420 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); |
| 402 EXPECT_TRUE(AllRootWindowsHaveLockedModalBackgrounds()); | 421 EXPECT_TRUE(AllRootWindowsHaveLockedModalBackgrounds()); |
| 403 TestWindow::CloseTestWindow(lock_modal_window.release()); | 422 TestWindow::CloseTestWindow(lock_modal_window.release()); |
| 404 | 423 |
| 405 // Normal system modal window while locked, but it belongs to the normal | 424 // Normal system modal window while locked, but it belongs to the normal |
| 406 // window. Shouldn't show locked system modal background, but normal. | 425 // window. Shouldn't show locked system modal background, but normal. |
| 407 scoped_ptr<aura::Window> modal_window2( | 426 scoped_ptr<aura::Window> modal_window2( |
| 408 TestWindow::OpenTestWindow(parent.get(), true)); | 427 OpenTestWindowWithParent(parent.get(), true)); |
| 409 modal_window2->Show(); | 428 modal_window2->Show(); |
| 410 EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); | 429 EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); |
| 411 EXPECT_FALSE(AllRootWindowsHaveLockedModalBackgrounds()); | 430 EXPECT_FALSE(AllRootWindowsHaveLockedModalBackgrounds()); |
| 412 TestWindow::CloseTestWindow(modal_window2.release()); | 431 TestWindow::CloseTestWindow(modal_window2.release()); |
| 413 | 432 |
| 414 // Here we should check the behavior of the locked system modal dialog when | 433 // Here we should check the behavior of the locked system modal dialog when |
| 415 // unlocked, but such case isn't handled very well right now. | 434 // unlocked, but such case isn't handled very well right now. |
| 416 // See crbug.com/157660 | 435 // See crbug.com/157660 |
| 417 // TODO(mukai): add the test case when the bug is fixed. | 436 // TODO(mukai): add the test case when the bug is fixed. |
| 418 } | 437 } |
| 419 | 438 |
| 420 TEST_F(SystemModalContainerLayoutManagerTest, MultiDisplays) { | 439 TEST_F(SystemModalContainerLayoutManagerTest, MultiDisplays) { |
| 421 UpdateDisplay("500x500,500x500"); | 440 UpdateDisplay("500x500,500x500"); |
| 422 | 441 |
| 423 scoped_ptr<aura::Window> normal(TestWindow::OpenTestWindow(NULL, false)); | 442 scoped_ptr<aura::Window> normal(OpenToplevelTestWindow(false)); |
| 424 normal->SetBounds(gfx::Rect(100, 100, 50, 50)); | 443 normal->SetBounds(gfx::Rect(100, 100, 50, 50)); |
| 425 | 444 |
| 426 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 445 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 427 EXPECT_EQ(2U, root_windows.size()); | 446 EXPECT_EQ(2U, root_windows.size()); |
| 428 aura::Window* container1 = Shell::GetContainer( | 447 aura::Window* container1 = Shell::GetContainer( |
| 429 root_windows[0], ash::internal::kShellWindowId_SystemModalContainer); | 448 root_windows[0], ash::internal::kShellWindowId_SystemModalContainer); |
| 430 aura::Window* container2 = Shell::GetContainer( | 449 aura::Window* container2 = Shell::GetContainer( |
| 431 root_windows[1], ash::internal::kShellWindowId_SystemModalContainer); | 450 root_windows[1], ash::internal::kShellWindowId_SystemModalContainer); |
| 432 | 451 |
| 433 scoped_ptr<aura::Window> modal1( | 452 scoped_ptr<aura::Window> modal1( |
| 434 TestWindow::OpenTestWindow(container1, true)); | 453 OpenTestWindowWithParent(container1, true)); |
| 435 EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); | 454 EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); |
| 436 EXPECT_TRUE(wm::IsActiveWindow(modal1.get())); | 455 EXPECT_TRUE(wm::IsActiveWindow(modal1.get())); |
| 437 | 456 |
| 438 scoped_ptr<aura::Window> modal11( | 457 scoped_ptr<aura::Window> modal11( |
| 439 TestWindow::OpenTestWindow(container1, true)); | 458 OpenTestWindowWithParent(container1, true)); |
| 440 EXPECT_TRUE(wm::IsActiveWindow(modal11.get())); | 459 EXPECT_TRUE(wm::IsActiveWindow(modal11.get())); |
| 441 | 460 |
| 442 scoped_ptr<aura::Window> modal2( | 461 scoped_ptr<aura::Window> modal2( |
| 443 TestWindow::OpenTestWindow(container2, true)); | 462 OpenTestWindowWithParent(container2, true)); |
| 444 EXPECT_TRUE(wm::IsActiveWindow(modal2.get())); | 463 EXPECT_TRUE(wm::IsActiveWindow(modal2.get())); |
| 445 | 464 |
| 446 // Sanity check if they're on the correct containers. | 465 // Sanity check if they're on the correct containers. |
| 447 EXPECT_EQ(container1, modal1->parent()); | 466 EXPECT_EQ(container1, modal1->parent()); |
| 448 EXPECT_EQ(container1, modal11->parent()); | 467 EXPECT_EQ(container1, modal11->parent()); |
| 449 EXPECT_EQ(container2, modal2->parent()); | 468 EXPECT_EQ(container2, modal2->parent()); |
| 450 | 469 |
| 451 TestWindow::CloseTestWindow(modal2.release()); | 470 TestWindow::CloseTestWindow(modal2.release()); |
| 452 EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); | 471 EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); |
| 453 EXPECT_TRUE(wm::IsActiveWindow(modal11.get())); | 472 EXPECT_TRUE(wm::IsActiveWindow(modal11.get())); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 466 | 485 |
| 467 // No more modal screen. | 486 // No more modal screen. |
| 468 modal1->Hide(); | 487 modal1->Hide(); |
| 469 TestWindow::CloseTestWindow(modal1.release()); | 488 TestWindow::CloseTestWindow(modal1.release()); |
| 470 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); | 489 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); |
| 471 EXPECT_TRUE(wm::IsActiveWindow(normal.get())); | 490 EXPECT_TRUE(wm::IsActiveWindow(normal.get())); |
| 472 } | 491 } |
| 473 | 492 |
| 474 } // namespace test | 493 } // namespace test |
| 475 } // namespace ash | 494 } // namespace ash |
| OLD | NEW |