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 "ui/views/widget/native_widget_aura.h" | 5 #include "ui/views/widget/native_widget_aura.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" | 12 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "ui/aura/client/aura_constants.h" | 14 #include "ui/aura/client/aura_constants.h" |
15 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
16 #include "ui/aura/layout_manager.h" | 16 #include "ui/aura/layout_manager.h" |
17 #include "ui/aura/test/aura_test_base.h" | 17 #include "ui/aura/test/aura_test_base.h" |
18 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
19 #include "ui/aura/window_observer.h" | 19 #include "ui/aura/window_observer.h" |
20 #include "ui/aura/window_tree_host.h" | 20 #include "ui/aura/window_tree_host.h" |
21 #include "ui/events/event.h" | 21 #include "ui/events/event.h" |
22 #include "ui/events/event_utils.h" | 22 #include "ui/events/event_utils.h" |
23 #include "ui/views/layout/fill_layout.h" | 23 #include "ui/views/layout/fill_layout.h" |
24 #include "ui/views/test/widget_test.h" | 24 #include "ui/views/test/widget_test.h" |
25 #include "ui/views/widget/root_view.h" | 25 #include "ui/views/widget/root_view.h" |
26 #include "ui/views/widget/widget_delegate.h" | 26 #include "ui/views/widget/widget_delegate.h" |
27 #include "ui/wm/core/base_focus_rules.h" | 27 #include "ui/wm/core/base_focus_rules.h" |
28 #include "ui/wm/core/default_activation_client.h" | 28 #include "ui/wm/core/default_activation_client.h" |
29 #include "ui/wm/core/focus_controller.h" | 29 #include "ui/wm/core/focus_controller.h" |
30 #include "ui/wm/core/transient_window_manager.h" | |
30 | 31 |
31 namespace views { | 32 namespace views { |
32 namespace { | 33 namespace { |
33 | 34 |
34 NativeWidgetAura* Init(aura::Window* parent, Widget* widget) { | 35 NativeWidgetAura* Init(aura::Window* parent, Widget* widget) { |
35 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 36 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
36 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 37 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
37 params.parent = parent; | 38 params.parent = parent; |
38 widget->Init(params); | 39 widget->Init(params); |
39 return static_cast<NativeWidgetAura*>(widget->native_widget()); | 40 return static_cast<NativeWidgetAura*>(widget->native_widget()); |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
644 views::test::TestInitialFocusWidgetDelegate delegate(root_window()); | 645 views::test::TestInitialFocusWidgetDelegate delegate(root_window()); |
645 delegate.GetWidget()->Show(); | 646 delegate.GetWidget()->Show(); |
646 EXPECT_FALSE(delegate.view()->HasFocus()); | 647 EXPECT_FALSE(delegate.view()->HasFocus()); |
647 | 648 |
648 test_focus_rules()->set_can_activate(true); | 649 test_focus_rules()->set_can_activate(true); |
649 views::test::TestInitialFocusWidgetDelegate delegate2(root_window()); | 650 views::test::TestInitialFocusWidgetDelegate delegate2(root_window()); |
650 delegate2.GetWidget()->Show(); | 651 delegate2.GetWidget()->Show(); |
651 EXPECT_TRUE(delegate2.view()->HasFocus()); | 652 EXPECT_TRUE(delegate2.view()->HasFocus()); |
652 } | 653 } |
653 | 654 |
655 // Tests that the transient child bubble window is only visible if the parent is | |
656 // visible. | |
657 TEST_F(NativeWidgetAuraTest, VisibilityOfChildBubbleWindow) { | |
658 // Create a parent window. | |
659 Widget* parent = new Widget; | |
sky
2017/05/08 21:24:29
Is this leaked? Was you're using WIDGET_OWNS_NATIV
Qiang(Joe) Xu
2017/05/08 22:00:40
changed to std::unique_ptr
| |
660 Widget::InitParams parent_params(Widget::InitParams::TYPE_WINDOW); | |
661 parent_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
662 parent_params.context = root_window(); | |
663 parent->Init(parent_params); | |
664 parent->SetBounds(gfx::Rect(0, 0, 480, 320)); | |
665 parent->Show(); | |
sky
2017/05/08 21:24:29
Isn't the bug scenario in the bug where the parent
Qiang(Joe) Xu
2017/05/08 22:00:40
In the last, I tested when parent is hidden. But t
| |
666 | |
667 // Add a child bubble window to the above parent window. | |
668 Widget* child = new Widget; | |
669 Widget::InitParams child_params(Widget::InitParams::TYPE_BUBBLE); | |
670 child_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
671 child_params.parent = parent->GetNativeWindow(); | |
672 child->Init(child_params); | |
673 child->SetBounds(gfx::Rect(0, 0, 200, 200)); | |
674 child->Show(); | |
675 | |
676 // Check that the child bubble window is added as the transient child. | |
677 wm::TransientWindowManager* manager = | |
678 wm::TransientWindowManager::Get(child->GetNativeWindow()); | |
679 ASSERT_EQ(parent->GetNativeWindow(), manager->transient_parent()); | |
680 ASSERT_TRUE(parent->IsVisible()); | |
681 ASSERT_TRUE(child->IsVisible()); | |
682 | |
683 // Hide the parent window should make the transient child bubble invisible. | |
684 parent->Hide(); | |
685 EXPECT_FALSE(parent->IsVisible()); | |
686 EXPECT_FALSE(child->IsVisible()); | |
687 | |
688 // Show the parent window should make the transient child bubble visible. | |
689 parent->Show(); | |
690 EXPECT_TRUE(parent->IsVisible()); | |
691 EXPECT_TRUE(child->IsVisible()); | |
692 } | |
693 | |
654 } // namespace | 694 } // namespace |
655 } // namespace views | 695 } // namespace views |
OLD | NEW |