Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: ui/views/widget/widget_unittest.cc

Issue 2008103002: If the window handle is destroyed because of an owner being destroyed, ensure any disabled windows … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/views/win/hwnd_message_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <set> 6 #include <set>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 3488 matching lines...) Expand 10 before | Expand all | Expand 10 after
3499 EXPECT_FALSE(removals_observer.DidRemoveView(child)); 3499 EXPECT_FALSE(removals_observer.DidRemoveView(child));
3500 3500
3501 // Moving the child to a different widget should call the removals observer. 3501 // Moving the child to a different widget should call the removals observer.
3502 WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget()); 3502 WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget());
3503 widget2->client_view()->AddChildView(child); 3503 widget2->client_view()->AddChildView(child);
3504 EXPECT_TRUE(removals_observer.DidRemoveView(child)); 3504 EXPECT_TRUE(removals_observer.DidRemoveView(child));
3505 3505
3506 widget->RemoveRemovalsObserver(&removals_observer); 3506 widget->RemoveRemovalsObserver(&removals_observer);
3507 } 3507 }
3508 3508
3509 #if defined(OS_WIN)
3510
3511 // Provides functionality to create a window modal dialog.
3512 class ModalDialogDelegate : public DialogDelegateView {
3513 public:
3514 explicit ModalDialogDelegate(ui::ModalType type) : type_(type) {}
3515 ~ModalDialogDelegate() override {}
3516
3517 // WidgetDelegate overrides.
3518 ui::ModalType GetModalType() const override { return type_; }
3519
3520 private:
3521 const ui::ModalType type_;
3522
3523 DISALLOW_COPY_AND_ASSIGN(ModalDialogDelegate);
3524 };
3525
3526 // Tests the case where an intervening owner popup window is destroyed out from
3527 // under the currently active modal top-level window. In this instance, the
3528 // remaining top-level windows should be re-enabled.
3529 TEST_F(WidgetTest, WindowModalOwnerDestroyedEnabledTest) {
3530 // top_level_widget owns owner_dialog_widget which owns owned_dialog_widget.
3531 Widget top_level_widget;
3532 Widget owner_dialog_widget;
3533 Widget owned_dialog_widget;
3534 // Create the top level widget.
3535 Widget::InitParams init_params =
3536 CreateParams(Widget::InitParams::TYPE_WINDOW);
3537 init_params.show_state = ui::SHOW_STATE_NORMAL;
3538 gfx::Rect initial_bounds(0, 0, 500, 500);
3539 init_params.bounds = initial_bounds;
3540 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
3541 init_params.native_widget = CreatePlatformDesktopNativeWidgetImpl(
3542 init_params, &top_level_widget, nullptr);
3543 top_level_widget.Init(init_params);
3544 top_level_widget.Show();
3545
3546 // Create the owner modal dialog.
3547 // owner_dialog_delegate instance will be destroyed when the dialog
3548 // is destroyed.
3549 ModalDialogDelegate* owner_dialog_delegate =
3550 new ModalDialogDelegate(ui::MODAL_TYPE_WINDOW);
3551
3552 init_params = CreateParams(Widget::InitParams::TYPE_WINDOW);
3553 init_params.show_state = ui::SHOW_STATE_NORMAL;
3554 init_params.bounds = gfx::Rect(100, 100, 200, 200);
3555 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
3556 init_params.delegate = owner_dialog_delegate;
3557 init_params.parent = top_level_widget.GetNativeView();
3558 init_params.native_widget = CreatePlatformDesktopNativeWidgetImpl(
3559 init_params, &owner_dialog_widget, nullptr);
3560 owner_dialog_widget.Init(init_params);
3561
3562 HWND owner_hwnd = HWNDForWidget(&owner_dialog_widget);
3563
3564 owner_dialog_widget.Show();
3565
3566 // Create the owned modal dialog.
3567 // As above, the owned_dialog_instance instance will be destroyed
3568 // when the dialog is destroyed.
3569 ModalDialogDelegate* owned_dialog_delegate =
3570 new ModalDialogDelegate(ui::MODAL_TYPE_WINDOW);
3571
3572 init_params = CreateParams(Widget::InitParams::TYPE_WINDOW);
3573 init_params.show_state = ui::SHOW_STATE_NORMAL;
3574 init_params.bounds = gfx::Rect(150, 150, 250, 250);
3575 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
3576 init_params.delegate = owned_dialog_delegate;
3577 init_params.parent = owner_dialog_widget.GetNativeView();
3578 init_params.native_widget = CreatePlatformDesktopNativeWidgetImpl(
3579 init_params, &owned_dialog_widget, nullptr);
3580 owned_dialog_widget.Init(init_params);
3581
3582 HWND owned_hwnd = HWNDForWidget(&owned_dialog_widget);
3583
3584 owned_dialog_widget.Show();
3585
3586 HWND top_hwnd = HWNDForWidget(&top_level_widget);
3587
3588 EXPECT_FALSE(!!IsWindowEnabled(owner_hwnd));
3589 EXPECT_FALSE(!!IsWindowEnabled(top_hwnd));
3590 EXPECT_TRUE(!!IsWindowEnabled(owned_hwnd));
3591
3592 owner_dialog_widget.CloseNow();
3593
3594 EXPECT_FALSE(!!IsWindow(owner_hwnd));
3595 EXPECT_FALSE(!!IsWindow(owned_hwnd));
3596 EXPECT_TRUE(!!IsWindowEnabled(top_hwnd));
3597
3598 top_level_widget.CloseNow();
3599 }
3600
3601 #endif // defined(OS_WIN)
3602
3509 } // namespace test 3603 } // namespace test
3510 } // namespace views 3604 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/win/hwnd_message_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698