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/command_line.h" | |
11 #include "base/macros.h" | 10 #include "base/macros.h" |
12 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
13 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
14 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
15 #include "build/build_config.h" | 14 #include "build/build_config.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "ui/base/hit_test.h" | 16 #include "ui/base/hit_test.h" |
18 #include "ui/base/ui_base_switches.h" | |
19 #include "ui/compositor/layer_animation_observer.h" | 17 #include "ui/compositor/layer_animation_observer.h" |
20 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 18 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
21 #include "ui/compositor/scoped_layer_animation_settings.h" | 19 #include "ui/compositor/scoped_layer_animation_settings.h" |
22 #include "ui/events/event_utils.h" | 20 #include "ui/events/event_utils.h" |
23 #include "ui/events/test/event_generator.h" | 21 #include "ui/events/test/event_generator.h" |
24 #include "ui/gfx/geometry/point.h" | 22 #include "ui/gfx/geometry/point.h" |
25 #include "ui/gfx/native_widget_types.h" | 23 #include "ui/gfx/native_widget_types.h" |
26 #include "ui/views/bubble/bubble_dialog_delegate.h" | 24 #include "ui/views/bubble/bubble_dialog_delegate.h" |
27 #include "ui/views/controls/textfield/textfield.h" | 25 #include "ui/views/controls/textfield/textfield.h" |
28 #include "ui/views/test/native_widget_factory.h" | 26 #include "ui/views/test/native_widget_factory.h" |
29 #include "ui/views/test/test_views.h" | 27 #include "ui/views/test/test_views.h" |
30 #include "ui/views/test/test_widget_observer.h" | 28 #include "ui/views/test/test_widget_observer.h" |
31 #include "ui/views/test/widget_test.h" | 29 #include "ui/views/test/widget_test.h" |
32 #include "ui/views/widget/native_widget_delegate.h" | 30 #include "ui/views/widget/native_widget_delegate.h" |
33 #include "ui/views/widget/native_widget_private.h" | 31 #include "ui/views/widget/native_widget_private.h" |
34 #include "ui/views/widget/root_view.h" | 32 #include "ui/views/widget/root_view.h" |
35 #include "ui/views/widget/widget_deletion_observer.h" | 33 #include "ui/views/widget/widget_deletion_observer.h" |
36 #include "ui/views/widget/widget_removals_observer.h" | 34 #include "ui/views/widget/widget_removals_observer.h" |
37 #include "ui/views/window/dialog_delegate.h" | 35 #include "ui/views/window/dialog_delegate.h" |
38 #include "ui/views/window/native_frame_view.h" | 36 #include "ui/views/window/native_frame_view.h" |
39 | 37 |
40 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
41 #include "ui/aura/window.h" | 39 #include "ui/aura/window.h" |
42 #include "ui/aura/window_tree_host.h" | 40 #include "ui/aura/window_tree_host.h" |
43 #include "ui/base/view_prop.h" | 41 #include "ui/base/view_prop.h" |
44 #include "ui/base/win/shell.h" | |
45 #include "ui/base/win/window_event_target.h" | 42 #include "ui/base/win/window_event_target.h" |
46 #include "ui/views/win/hwnd_util.h" | 43 #include "ui/views/win/hwnd_util.h" |
47 #endif | 44 #endif |
48 | 45 |
49 #if defined(OS_MACOSX) | 46 #if defined(OS_MACOSX) |
50 #include "base/mac/mac_util.h" | 47 #include "base/mac/mac_util.h" |
51 #endif | 48 #endif |
52 | 49 |
53 #if defined(USE_X11) && !defined(OS_CHROMEOS) | |
54 #include "ui/base/x/x11_util_internal.h" // nogncheck | |
55 #include "ui/gfx/x/x11_switches.h" // nogncheck | |
56 #endif | |
57 | |
58 namespace views { | 50 namespace views { |
59 namespace test { | 51 namespace test { |
60 | 52 |
61 namespace { | 53 namespace { |
62 | 54 |
63 // TODO(tdanderson): This utility function is used in different unittest | 55 // TODO(tdanderson): This utility function is used in different unittest |
64 // files. Move to a common location to avoid | 56 // files. Move to a common location to avoid |
65 // repeated code. | 57 // repeated code. |
66 gfx::Point ConvertPointFromWidgetToView(View* view, const gfx::Point& p) { | 58 gfx::Point ConvertPointFromWidgetToView(View* view, const gfx::Point& p) { |
67 gfx::Point tmp(p); | 59 gfx::Point tmp(p); |
(...skipping 3656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3724 | 3716 |
3725 EXPECT_FALSE(!!IsWindow(owner_hwnd)); | 3717 EXPECT_FALSE(!!IsWindow(owner_hwnd)); |
3726 EXPECT_FALSE(!!IsWindow(owned_hwnd)); | 3718 EXPECT_FALSE(!!IsWindow(owned_hwnd)); |
3727 EXPECT_TRUE(!!IsWindowEnabled(top_hwnd)); | 3719 EXPECT_TRUE(!!IsWindowEnabled(top_hwnd)); |
3728 | 3720 |
3729 top_level_widget.CloseNow(); | 3721 top_level_widget.CloseNow(); |
3730 } | 3722 } |
3731 | 3723 |
3732 #endif // defined(OS_WIN) | 3724 #endif // defined(OS_WIN) |
3733 | 3725 |
3734 #if !defined(OS_CHROMEOS) | |
3735 | |
3736 namespace { | |
3737 | |
3738 void InitializeWidgetForOpacity( | |
3739 Widget& widget, | |
3740 Widget::InitParams init_params, | |
3741 const Widget::InitParams::WindowOpacity opacity) { | |
3742 #if defined(USE_X11) | |
3743 // On Linux, transparent visuals is currently not activated by default. | |
3744 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
3745 command_line->AppendSwitch(switches::kEnableTransparentVisuals); | |
3746 | |
3747 int depth = 0; | |
3748 ui::ChooseVisualForWindow(NULL, &depth); | |
3749 EXPECT_EQ(depth, 32); | |
3750 #elif defined(OS_WIN) | |
3751 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
3752 EXPECT_FALSE(command_line->HasSwitch(switches::kDisableDwmComposition)); | |
3753 | |
3754 // TODO(j.isorce): find a way to activate compositing for unit tests on win. | |
3755 EXPECT_FALSE(ui::win::IsAeroGlassEnabled()); | |
3756 #endif | |
3757 | |
3758 init_params.opacity = opacity; | |
3759 init_params.show_state = ui::SHOW_STATE_NORMAL; | |
3760 init_params.bounds = gfx::Rect(0, 0, 500, 500); | |
3761 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
3762 init_params.native_widget = | |
3763 CreatePlatformDesktopNativeWidgetImpl(init_params, &widget, nullptr); | |
3764 widget.Init(init_params); | |
3765 | |
3766 #if defined(USE_X11) | |
3767 EXPECT_TRUE(widget.IsTranslucentWindowOpacitySupported()); | |
3768 #endif | |
3769 } | |
3770 | |
3771 } // namespace | |
3772 | |
3773 // Test opacity when compositing is enabled. | |
3774 TEST_F(WidgetTest, Transparency_DesktopWidgetInferOpacity) { | |
3775 Widget widget; | |
3776 InitializeWidgetForOpacity(widget, | |
3777 CreateParams(Widget::InitParams::TYPE_WINDOW), | |
3778 Widget::InitParams::INFER_OPACITY); | |
3779 EXPECT_EQ(IsNativeWindowTransparent(widget.GetNativeWindow()), | |
3780 widget.ShouldWindowContentsBeTransparent()); | |
3781 } | |
3782 | |
3783 TEST_F(WidgetTest, Transparency_DesktopWidgetOpaque) { | |
3784 Widget widget; | |
3785 InitializeWidgetForOpacity(widget, | |
3786 CreateParams(Widget::InitParams::TYPE_WINDOW), | |
3787 Widget::InitParams::OPAQUE_WINDOW); | |
3788 EXPECT_EQ(IsNativeWindowTransparent(widget.GetNativeWindow()), | |
3789 widget.ShouldWindowContentsBeTransparent()); | |
3790 } | |
3791 | |
3792 TEST_F(WidgetTest, Transparency_DesktopWidgetTranslucent) { | |
3793 Widget widget; | |
3794 InitializeWidgetForOpacity(widget, | |
3795 CreateParams(Widget::InitParams::TYPE_WINDOW), | |
3796 Widget::InitParams::TRANSLUCENT_WINDOW); | |
3797 EXPECT_EQ(IsNativeWindowTransparent(widget.GetNativeWindow()), | |
3798 widget.ShouldWindowContentsBeTransparent()); | |
3799 } | |
3800 | |
3801 #endif // !defined(OS_CHROMEOS) | |
3802 | |
3803 } // namespace test | 3726 } // namespace test |
3804 } // namespace views | 3727 } // namespace views |
OLD | NEW |