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 <algorithm> | 5 #include <algorithm> |
6 #include <memory> | 6 #include <memory> |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 3603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3614 EXPECT_FALSE(removals_observer.DidRemoveView(child)); | 3614 EXPECT_FALSE(removals_observer.DidRemoveView(child)); |
3615 | 3615 |
3616 // Moving the child to a different widget should call the removals observer. | 3616 // Moving the child to a different widget should call the removals observer. |
3617 WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget()); | 3617 WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget()); |
3618 widget2->client_view()->AddChildView(child); | 3618 widget2->client_view()->AddChildView(child); |
3619 EXPECT_TRUE(removals_observer.DidRemoveView(child)); | 3619 EXPECT_TRUE(removals_observer.DidRemoveView(child)); |
3620 | 3620 |
3621 widget->RemoveRemovalsObserver(&removals_observer); | 3621 widget->RemoveRemovalsObserver(&removals_observer); |
3622 } | 3622 } |
3623 | 3623 |
| 3624 #if defined(OS_WIN) |
| 3625 |
| 3626 // Provides functionality to create a window modal dialog. |
| 3627 class ModalDialogDelegate : public DialogDelegateView { |
| 3628 public: |
| 3629 explicit ModalDialogDelegate(ui::ModalType type) : type_(type) {} |
| 3630 ~ModalDialogDelegate() override {} |
| 3631 |
| 3632 // WidgetDelegate overrides. |
| 3633 ui::ModalType GetModalType() const override { return type_; } |
| 3634 |
| 3635 private: |
| 3636 const ui::ModalType type_; |
| 3637 |
| 3638 DISALLOW_COPY_AND_ASSIGN(ModalDialogDelegate); |
| 3639 }; |
| 3640 |
| 3641 // Tests the case where an intervening owner popup window is destroyed out from |
| 3642 // under the currently active modal top-level window. In this instance, the |
| 3643 // remaining top-level windows should be re-enabled. |
| 3644 TEST_F(WidgetTest, WindowModalOwnerDestroyedEnabledTest) { |
| 3645 // top_level_widget owns owner_dialog_widget which owns owned_dialog_widget. |
| 3646 Widget top_level_widget; |
| 3647 Widget owner_dialog_widget; |
| 3648 Widget owned_dialog_widget; |
| 3649 // Create the top level widget. |
| 3650 Widget::InitParams init_params = |
| 3651 CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 3652 init_params.show_state = ui::SHOW_STATE_NORMAL; |
| 3653 gfx::Rect initial_bounds(0, 0, 500, 500); |
| 3654 init_params.bounds = initial_bounds; |
| 3655 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 3656 init_params.native_widget = CreatePlatformDesktopNativeWidgetImpl( |
| 3657 init_params, &top_level_widget, nullptr); |
| 3658 top_level_widget.Init(init_params); |
| 3659 top_level_widget.Show(); |
| 3660 |
| 3661 // Create the owner modal dialog. |
| 3662 // owner_dialog_delegate instance will be destroyed when the dialog |
| 3663 // is destroyed. |
| 3664 ModalDialogDelegate* owner_dialog_delegate = |
| 3665 new ModalDialogDelegate(ui::MODAL_TYPE_WINDOW); |
| 3666 |
| 3667 init_params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 3668 init_params.show_state = ui::SHOW_STATE_NORMAL; |
| 3669 init_params.bounds = gfx::Rect(100, 100, 200, 200); |
| 3670 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 3671 init_params.delegate = owner_dialog_delegate; |
| 3672 init_params.parent = top_level_widget.GetNativeView(); |
| 3673 init_params.native_widget = CreatePlatformDesktopNativeWidgetImpl( |
| 3674 init_params, &owner_dialog_widget, nullptr); |
| 3675 owner_dialog_widget.Init(init_params); |
| 3676 |
| 3677 HWND owner_hwnd = HWNDForWidget(&owner_dialog_widget); |
| 3678 |
| 3679 owner_dialog_widget.Show(); |
| 3680 |
| 3681 // Create the owned modal dialog. |
| 3682 // As above, the owned_dialog_instance instance will be destroyed |
| 3683 // when the dialog is destroyed. |
| 3684 ModalDialogDelegate* owned_dialog_delegate = |
| 3685 new ModalDialogDelegate(ui::MODAL_TYPE_WINDOW); |
| 3686 |
| 3687 init_params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 3688 init_params.show_state = ui::SHOW_STATE_NORMAL; |
| 3689 init_params.bounds = gfx::Rect(150, 150, 250, 250); |
| 3690 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 3691 init_params.delegate = owned_dialog_delegate; |
| 3692 init_params.parent = owner_dialog_widget.GetNativeView(); |
| 3693 init_params.native_widget = CreatePlatformDesktopNativeWidgetImpl( |
| 3694 init_params, &owned_dialog_widget, nullptr); |
| 3695 owned_dialog_widget.Init(init_params); |
| 3696 |
| 3697 HWND owned_hwnd = HWNDForWidget(&owned_dialog_widget); |
| 3698 |
| 3699 owned_dialog_widget.Show(); |
| 3700 |
| 3701 HWND top_hwnd = HWNDForWidget(&top_level_widget); |
| 3702 |
| 3703 EXPECT_FALSE(!!IsWindowEnabled(owner_hwnd)); |
| 3704 EXPECT_FALSE(!!IsWindowEnabled(top_hwnd)); |
| 3705 EXPECT_TRUE(!!IsWindowEnabled(owned_hwnd)); |
| 3706 |
| 3707 owner_dialog_widget.CloseNow(); |
| 3708 |
| 3709 EXPECT_FALSE(!!IsWindow(owner_hwnd)); |
| 3710 EXPECT_FALSE(!!IsWindow(owned_hwnd)); |
| 3711 EXPECT_TRUE(!!IsWindowEnabled(top_hwnd)); |
| 3712 |
| 3713 top_level_widget.CloseNow(); |
| 3714 } |
| 3715 |
| 3716 #endif // defined(OS_WIN) |
| 3717 |
3624 } // namespace test | 3718 } // namespace test |
3625 } // namespace views | 3719 } // namespace views |
OLD | NEW |