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" |
17 #include "ui/compositor/layer_animation_observer.h" | 18 #include "ui/compositor/layer_animation_observer.h" |
18 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 19 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
19 #include "ui/compositor/scoped_layer_animation_settings.h" | 20 #include "ui/compositor/scoped_layer_animation_settings.h" |
(...skipping 20 matching lines...) Expand all Loading... |
40 #include "ui/aura/window_tree_host.h" | 41 #include "ui/aura/window_tree_host.h" |
41 #include "ui/base/view_prop.h" | 42 #include "ui/base/view_prop.h" |
42 #include "ui/base/win/window_event_target.h" | 43 #include "ui/base/win/window_event_target.h" |
43 #include "ui/views/win/hwnd_util.h" | 44 #include "ui/views/win/hwnd_util.h" |
44 #endif | 45 #endif |
45 | 46 |
46 #if defined(OS_MACOSX) | 47 #if defined(OS_MACOSX) |
47 #include "base/mac/mac_util.h" | 48 #include "base/mac/mac_util.h" |
48 #endif | 49 #endif |
49 | 50 |
| 51 #if defined(USE_X11) && !defined(OS_CHROMEOS) |
| 52 #include "ui/base/x/x11_util_internal.h" // nogncheck |
| 53 #include "ui/gfx/x/x11_switches.h" // nogncheck |
| 54 #endif |
| 55 |
50 namespace views { | 56 namespace views { |
51 namespace test { | 57 namespace test { |
52 | 58 |
53 namespace { | 59 namespace { |
54 | 60 |
55 // TODO(tdanderson): This utility function is used in different unittest | 61 // TODO(tdanderson): This utility function is used in different unittest |
56 // files. Move to a common location to avoid | 62 // files. Move to a common location to avoid |
57 // repeated code. | 63 // repeated code. |
58 gfx::Point ConvertPointFromWidgetToView(View* view, const gfx::Point& p) { | 64 gfx::Point ConvertPointFromWidgetToView(View* view, const gfx::Point& p) { |
59 gfx::Point tmp(p); | 65 gfx::Point tmp(p); |
(...skipping 3649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3709 | 3715 |
3710 EXPECT_FALSE(!!IsWindow(owner_hwnd)); | 3716 EXPECT_FALSE(!!IsWindow(owner_hwnd)); |
3711 EXPECT_FALSE(!!IsWindow(owned_hwnd)); | 3717 EXPECT_FALSE(!!IsWindow(owned_hwnd)); |
3712 EXPECT_TRUE(!!IsWindowEnabled(top_hwnd)); | 3718 EXPECT_TRUE(!!IsWindowEnabled(top_hwnd)); |
3713 | 3719 |
3714 top_level_widget.CloseNow(); | 3720 top_level_widget.CloseNow(); |
3715 } | 3721 } |
3716 | 3722 |
3717 #endif // defined(OS_WIN) | 3723 #endif // defined(OS_WIN) |
3718 | 3724 |
| 3725 #if !defined(OS_CHROMEOS) |
| 3726 namespace { |
| 3727 |
| 3728 // An observer that registers the transparent flag of a widget on creation. |
| 3729 class WidgetTransparencyObserver : public WidgetObserver { |
| 3730 public: |
| 3731 WidgetTransparencyObserver() : transparent_(false) {} |
| 3732 ~WidgetTransparencyObserver() override {} |
| 3733 |
| 3734 bool transparent() { return transparent_; } |
| 3735 |
| 3736 // WidgetObserver: |
| 3737 void OnWidgetCreated(Widget* widget) override { |
| 3738 EXPECT_TRUE(widget->GetNativeWindow()); |
| 3739 transparent_ = |
| 3740 WidgetTest::IsNativeWindowTransparent(widget->GetNativeWindow()); |
| 3741 } |
| 3742 |
| 3743 private: |
| 3744 bool transparent_; |
| 3745 |
| 3746 DISALLOW_COPY_AND_ASSIGN(WidgetTransparencyObserver); |
| 3747 }; |
| 3748 |
| 3749 } // namespace |
| 3750 |
| 3751 // Test to ensure that the aura Window remains transparent after its creation |
| 3752 // has finished if transparent visuals are enabled. |
| 3753 TEST_F(WidgetTest, Transparency_DesktopWidget) { |
| 3754 #if defined(USE_X11) |
| 3755 // On Linux, transparent visuals is currently not activated by default. |
| 3756 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 3757 command_line->AppendSwitch(switches::kEnableTransparentVisuals); |
| 3758 |
| 3759 int depth = 0; |
| 3760 ui::ChooseVisualForWindow(NULL, &depth); |
| 3761 EXPECT_EQ(depth, 32); |
| 3762 #endif |
| 3763 |
| 3764 Widget::InitParams init_params = |
| 3765 CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 3766 init_params.show_state = ui::SHOW_STATE_NORMAL; |
| 3767 init_params.bounds = gfx::Rect(0, 0, 500, 500); |
| 3768 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 3769 Widget widget; |
| 3770 WidgetTransparencyObserver widget_observer; |
| 3771 init_params.native_widget = |
| 3772 CreatePlatformDesktopNativeWidgetImpl(init_params, &widget, nullptr); |
| 3773 widget.AddObserver(&widget_observer); |
| 3774 widget.Init(init_params); |
| 3775 widget.Show(); |
| 3776 |
| 3777 EXPECT_EQ(widget_observer.transparent(), |
| 3778 IsNativeWindowTransparent(widget.GetNativeWindow())); |
| 3779 EXPECT_EQ(widget_observer.transparent(), |
| 3780 widget.ShouldWindowContentsBeTransparent()); |
| 3781 |
| 3782 #if defined(USE_X11) |
| 3783 EXPECT_TRUE(widget_observer.transparent()); |
| 3784 #endif |
| 3785 } |
| 3786 #endif // !defined(OS_CHROMEOS) |
| 3787 |
3719 } // namespace test | 3788 } // namespace test |
3720 } // namespace views | 3789 } // namespace views |
OLD | NEW |