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