| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 5 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "ui/aura/client/aura_constants.h" | 8 #include "ui/aura/client/aura_constants.h" |
| 9 #include "ui/aura/client/cursor_client.h" | 9 #include "ui/aura/client/cursor_client.h" |
| 10 #include "ui/aura/client/window_tree_client.h" | 10 #include "ui/aura/client/window_tree_client.h" |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 run_loop.Run(); | 241 run_loop.Run(); |
| 242 } | 242 } |
| 243 | 243 |
| 244 // This class provides functionality to create fullscreen and top level popup | 244 // This class provides functionality to create fullscreen and top level popup |
| 245 // windows. It additionally tests whether the destruction of these windows | 245 // windows. It additionally tests whether the destruction of these windows |
| 246 // occurs correctly in desktop AURA without crashing. | 246 // occurs correctly in desktop AURA without crashing. |
| 247 // It provides facilities to test the following cases:- | 247 // It provides facilities to test the following cases:- |
| 248 // 1. Child window destroyed which should lead to the destruction of the | 248 // 1. Child window destroyed which should lead to the destruction of the |
| 249 // parent. | 249 // parent. |
| 250 // 2. Parent window destroyed which should lead to the child being destroyed. | 250 // 2. Parent window destroyed which should lead to the child being destroyed. |
| 251 class DesktopAuraTopLevelWindowTest | 251 class DesktopAuraTopLevelWindowTest : public aura::WindowObserver { |
| 252 : public views::TestViewsDelegate, | |
| 253 public aura::WindowObserver { | |
| 254 public: | 252 public: |
| 255 DesktopAuraTopLevelWindowTest() | 253 DesktopAuraTopLevelWindowTest() |
| 256 : top_level_widget_(NULL), | 254 : top_level_widget_(NULL), |
| 257 owned_window_(NULL), | 255 owned_window_(NULL), |
| 258 owner_destroyed_(false), | 256 owner_destroyed_(false), |
| 259 owned_window_destroyed_(false), | 257 owned_window_destroyed_(false), |
| 260 use_async_mode_(true) {} | 258 use_async_mode_(true) {} |
| 261 | 259 |
| 262 ~DesktopAuraTopLevelWindowTest() override { | 260 ~DesktopAuraTopLevelWindowTest() override { |
| 263 EXPECT_TRUE(owner_destroyed_); | 261 EXPECT_TRUE(owner_destroyed_); |
| 264 EXPECT_TRUE(owned_window_destroyed_); | 262 EXPECT_TRUE(owned_window_destroyed_); |
| 265 top_level_widget_ = NULL; | 263 top_level_widget_ = NULL; |
| 266 owned_window_ = NULL; | 264 owned_window_ = NULL; |
| 267 } | 265 } |
| 268 | 266 |
| 269 // views::TestViewsDelegate overrides. | |
| 270 void OnBeforeWidgetInit(Widget::InitParams* params, | |
| 271 internal::NativeWidgetDelegate* delegate) override { | |
| 272 if (!params->native_widget) | |
| 273 params->native_widget = new views::DesktopNativeWidgetAura(delegate); | |
| 274 } | |
| 275 | |
| 276 void CreateTopLevelWindow(const gfx::Rect& bounds, bool fullscreen) { | 267 void CreateTopLevelWindow(const gfx::Rect& bounds, bool fullscreen) { |
| 277 Widget::InitParams init_params; | 268 Widget::InitParams init_params; |
| 278 init_params.type = Widget::InitParams::TYPE_WINDOW; | 269 init_params.type = Widget::InitParams::TYPE_WINDOW; |
| 279 init_params.bounds = bounds; | 270 init_params.bounds = bounds; |
| 280 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 271 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 281 init_params.layer_type = ui::LAYER_NOT_DRAWN; | 272 init_params.layer_type = ui::LAYER_NOT_DRAWN; |
| 282 init_params.accept_events = fullscreen; | 273 init_params.accept_events = fullscreen; |
| 283 | 274 |
| 284 widget_.Init(init_params); | 275 widget_.Init(init_params); |
| 285 | 276 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 bool owner_destroyed_; | 346 bool owner_destroyed_; |
| 356 bool owned_window_destroyed_; | 347 bool owned_window_destroyed_; |
| 357 aura::test::TestWindowDelegate child_window_delegate_; | 348 aura::test::TestWindowDelegate child_window_delegate_; |
| 358 // This flag controls whether we need to wait for the destruction to complete | 349 // This flag controls whether we need to wait for the destruction to complete |
| 359 // before finishing the test. Defaults to true. | 350 // before finishing the test. Defaults to true. |
| 360 bool use_async_mode_; | 351 bool use_async_mode_; |
| 361 | 352 |
| 362 DISALLOW_COPY_AND_ASSIGN(DesktopAuraTopLevelWindowTest); | 353 DISALLOW_COPY_AND_ASSIGN(DesktopAuraTopLevelWindowTest); |
| 363 }; | 354 }; |
| 364 | 355 |
| 365 typedef WidgetTest DesktopAuraWidgetTest; | 356 class DesktopAuraWidgetTest : public WidgetTest { |
| 357 public: |
| 358 DesktopAuraWidgetTest() {} |
| 359 |
| 360 void SetUp() override { |
| 361 ViewsTestBase::SetUp(); |
| 362 views_delegate()->set_use_desktop_native_widgets(true); |
| 363 } |
| 364 |
| 365 private: |
| 366 DISALLOW_COPY_AND_ASSIGN(DesktopAuraWidgetTest); |
| 367 }; |
| 366 | 368 |
| 367 TEST_F(DesktopAuraWidgetTest, FullscreenWindowDestroyedBeforeOwnerTest) { | 369 TEST_F(DesktopAuraWidgetTest, FullscreenWindowDestroyedBeforeOwnerTest) { |
| 368 set_views_delegate(nullptr); | |
| 369 DesktopAuraTopLevelWindowTest fullscreen_window; | 370 DesktopAuraTopLevelWindowTest fullscreen_window; |
| 370 ASSERT_NO_FATAL_FAILURE(fullscreen_window.CreateTopLevelWindow( | 371 ASSERT_NO_FATAL_FAILURE(fullscreen_window.CreateTopLevelWindow( |
| 371 gfx::Rect(0, 0, 200, 200), true)); | 372 gfx::Rect(0, 0, 200, 200), true)); |
| 372 | 373 |
| 373 RunPendingMessages(); | 374 RunPendingMessages(); |
| 374 ASSERT_NO_FATAL_FAILURE(fullscreen_window.DestroyOwnedWindow()); | 375 ASSERT_NO_FATAL_FAILURE(fullscreen_window.DestroyOwnedWindow()); |
| 375 RunPendingMessages(); | 376 RunPendingMessages(); |
| 376 } | 377 } |
| 377 | 378 |
| 378 TEST_F(DesktopAuraWidgetTest, FullscreenWindowOwnerDestroyed) { | 379 TEST_F(DesktopAuraWidgetTest, FullscreenWindowOwnerDestroyed) { |
| 379 set_views_delegate(nullptr); | |
| 380 | |
| 381 DesktopAuraTopLevelWindowTest fullscreen_window; | 380 DesktopAuraTopLevelWindowTest fullscreen_window; |
| 382 ASSERT_NO_FATAL_FAILURE(fullscreen_window.CreateTopLevelWindow( | 381 ASSERT_NO_FATAL_FAILURE(fullscreen_window.CreateTopLevelWindow( |
| 383 gfx::Rect(0, 0, 200, 200), true)); | 382 gfx::Rect(0, 0, 200, 200), true)); |
| 384 | 383 |
| 385 RunPendingMessages(); | 384 RunPendingMessages(); |
| 386 ASSERT_NO_FATAL_FAILURE(fullscreen_window.DestroyOwnerWindow()); | 385 ASSERT_NO_FATAL_FAILURE(fullscreen_window.DestroyOwnerWindow()); |
| 387 RunPendingMessages(); | 386 RunPendingMessages(); |
| 388 } | 387 } |
| 389 | 388 |
| 390 TEST_F(DesktopAuraWidgetTest, TopLevelOwnedPopupTest) { | 389 TEST_F(DesktopAuraWidgetTest, TopLevelOwnedPopupTest) { |
| 391 set_views_delegate(nullptr); | |
| 392 DesktopAuraTopLevelWindowTest popup_window; | 390 DesktopAuraTopLevelWindowTest popup_window; |
| 393 ASSERT_NO_FATAL_FAILURE(popup_window.CreateTopLevelWindow( | 391 ASSERT_NO_FATAL_FAILURE(popup_window.CreateTopLevelWindow( |
| 394 gfx::Rect(0, 0, 200, 200), false)); | 392 gfx::Rect(0, 0, 200, 200), false)); |
| 395 | 393 |
| 396 RunPendingMessages(); | 394 RunPendingMessages(); |
| 397 ASSERT_NO_FATAL_FAILURE(popup_window.DestroyOwnedWindow()); | 395 ASSERT_NO_FATAL_FAILURE(popup_window.DestroyOwnedWindow()); |
| 398 RunPendingMessages(); | 396 RunPendingMessages(); |
| 399 } | 397 } |
| 400 | 398 |
| 401 // This test validates that when a top level owned popup Aura window is | 399 // This test validates that when a top level owned popup Aura window is |
| 402 // resized, the widget is resized as well. | 400 // resized, the widget is resized as well. |
| 403 TEST_F(DesktopAuraWidgetTest, TopLevelOwnedPopupResizeTest) { | 401 TEST_F(DesktopAuraWidgetTest, TopLevelOwnedPopupResizeTest) { |
| 404 set_views_delegate(nullptr); | |
| 405 DesktopAuraTopLevelWindowTest popup_window; | 402 DesktopAuraTopLevelWindowTest popup_window; |
| 406 | 403 |
| 407 popup_window.set_use_async_mode(false); | 404 popup_window.set_use_async_mode(false); |
| 408 | 405 |
| 409 ASSERT_NO_FATAL_FAILURE(popup_window.CreateTopLevelWindow( | 406 ASSERT_NO_FATAL_FAILURE(popup_window.CreateTopLevelWindow( |
| 410 gfx::Rect(0, 0, 200, 200), false)); | 407 gfx::Rect(0, 0, 200, 200), false)); |
| 411 | 408 |
| 412 gfx::Rect new_size(0, 0, 400, 400); | 409 gfx::Rect new_size(0, 0, 400, 400); |
| 413 popup_window.owned_window()->SetBounds(new_size); | 410 popup_window.owned_window()->SetBounds(new_size); |
| 414 | 411 |
| 415 EXPECT_EQ(popup_window.top_level_widget()->GetNativeView()->bounds().size(), | 412 EXPECT_EQ(popup_window.top_level_widget()->GetNativeView()->bounds().size(), |
| 416 new_size.size()); | 413 new_size.size()); |
| 417 | 414 |
| 418 ASSERT_NO_FATAL_FAILURE(popup_window.DestroyOwnedWindow()); | 415 ASSERT_NO_FATAL_FAILURE(popup_window.DestroyOwnedWindow()); |
| 419 } | 416 } |
| 420 | 417 |
| 421 // This test validates that when a top level owned popup Aura window is | 418 // This test validates that when a top level owned popup Aura window is |
| 422 // repositioned, the widget is repositioned as well. | 419 // repositioned, the widget is repositioned as well. |
| 423 TEST_F(DesktopAuraWidgetTest, TopLevelOwnedPopupRepositionTest) { | 420 TEST_F(DesktopAuraWidgetTest, TopLevelOwnedPopupRepositionTest) { |
| 424 set_views_delegate(nullptr); | |
| 425 DesktopAuraTopLevelWindowTest popup_window; | 421 DesktopAuraTopLevelWindowTest popup_window; |
| 426 | 422 |
| 427 popup_window.set_use_async_mode(false); | 423 popup_window.set_use_async_mode(false); |
| 428 | 424 |
| 429 ASSERT_NO_FATAL_FAILURE(popup_window.CreateTopLevelWindow( | 425 ASSERT_NO_FATAL_FAILURE(popup_window.CreateTopLevelWindow( |
| 430 gfx::Rect(0, 0, 200, 200), false)); | 426 gfx::Rect(0, 0, 200, 200), false)); |
| 431 | 427 |
| 432 gfx::Rect new_pos(10, 10, 400, 400); | 428 gfx::Rect new_pos(10, 10, 400, 400); |
| 433 popup_window.owned_window()->SetBoundsInScreen( | 429 popup_window.owned_window()->SetBoundsInScreen( |
| 434 new_pos, | 430 new_pos, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 RunCloseWidgetDuringDispatchTest(this, ui::ET_MOUSE_PRESSED); | 499 RunCloseWidgetDuringDispatchTest(this, ui::ET_MOUSE_PRESSED); |
| 504 } | 500 } |
| 505 | 501 |
| 506 // Verifies deleting the widget from a mouse released event doesn't crash. | 502 // Verifies deleting the widget from a mouse released event doesn't crash. |
| 507 TEST_F(DesktopAuraWidgetTest, CloseWidgetDuringMouseReleased) { | 503 TEST_F(DesktopAuraWidgetTest, CloseWidgetDuringMouseReleased) { |
| 508 RunCloseWidgetDuringDispatchTest(this, ui::ET_MOUSE_RELEASED); | 504 RunCloseWidgetDuringDispatchTest(this, ui::ET_MOUSE_RELEASED); |
| 509 } | 505 } |
| 510 | 506 |
| 511 } // namespace test | 507 } // namespace test |
| 512 } // namespace views | 508 } // namespace views |
| OLD | NEW |