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

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

Issue 2280433004: Fix missing shadows for tooltip and menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Just rebase Created 4 years, 3 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
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 <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/environment.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/compositor/layer_animation_observer.h" 17 #include "ui/compositor/layer_animation_observer.h"
19 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 18 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
20 #include "ui/compositor/scoped_layer_animation_settings.h" 19 #include "ui/compositor/scoped_layer_animation_settings.h"
(...skipping 20 matching lines...) Expand all
41 #include "ui/aura/window_tree_host.h" 40 #include "ui/aura/window_tree_host.h"
42 #include "ui/base/view_prop.h" 41 #include "ui/base/view_prop.h"
43 #include "ui/base/win/window_event_target.h" 42 #include "ui/base/win/window_event_target.h"
44 #include "ui/views/win/hwnd_util.h" 43 #include "ui/views/win/hwnd_util.h"
45 #endif 44 #endif
46 45
47 #if defined(OS_MACOSX) 46 #if defined(OS_MACOSX)
48 #include "base/mac/mac_util.h" 47 #include "base/mac/mac_util.h"
49 #endif 48 #endif
50 49
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
56 namespace views { 50 namespace views {
57 namespace test { 51 namespace test {
58 52
59 namespace { 53 namespace {
60 54
61 // TODO(tdanderson): This utility function is used in different unittest 55 // TODO(tdanderson): This utility function is used in different unittest
62 // files. Move to a common location to avoid 56 // files. Move to a common location to avoid
63 // repeated code. 57 // repeated code.
64 gfx::Point ConvertPointFromWidgetToView(View* view, const gfx::Point& p) { 58 gfx::Point ConvertPointFromWidgetToView(View* view, const gfx::Point& p) {
65 gfx::Point tmp(p); 59 gfx::Point tmp(p);
(...skipping 3670 matching lines...) Expand 10 before | Expand all | Expand 10 after
3736 #endif // defined(OS_WIN) 3730 #endif // defined(OS_WIN)
3737 3731
3738 #if !defined(OS_CHROMEOS) 3732 #if !defined(OS_CHROMEOS)
3739 3733
3740 namespace { 3734 namespace {
3741 3735
3742 void InitializeWidgetForOpacity( 3736 void InitializeWidgetForOpacity(
3743 Widget& widget, 3737 Widget& widget,
3744 Widget::InitParams init_params, 3738 Widget::InitParams init_params,
3745 const Widget::InitParams::WindowOpacity opacity) { 3739 const Widget::InitParams::WindowOpacity opacity) {
3746 #if defined(USE_X11) 3740 init_params.child = false;
3747 // testing/xvfb.py runs xvfb and xcompmgr.
3748 std::unique_ptr<base::Environment> env(base::Environment::Create());
3749 bool has_compositing_manager = env->HasVar("_CHROMIUM_INSIDE_XVFB");
3750 int depth = 0;
3751 ui::ChooseVisualForWindow(has_compositing_manager, NULL, &depth);
3752
3753 if (has_compositing_manager)
3754 EXPECT_EQ(depth, 32);
3755 #endif
3756
3757 init_params.opacity = opacity; 3741 init_params.opacity = opacity;
3758 init_params.show_state = ui::SHOW_STATE_NORMAL; 3742 init_params.show_state = ui::SHOW_STATE_NORMAL;
3743 init_params.parent = nullptr;
sadrul 2016/09/02 19:53:24 Do you need to explicitly set child and parent her
Julien Isorce Samsung 2016/09/02 20:59:08 No I will remove it, all are initialized to 0.
3759 init_params.bounds = gfx::Rect(0, 0, 500, 500); 3744 init_params.bounds = gfx::Rect(0, 0, 500, 500);
3760 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 3745 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
3761 init_params.native_widget = 3746 init_params.native_widget =
3762 CreatePlatformDesktopNativeWidgetImpl(init_params, &widget, nullptr); 3747 CreatePlatformDesktopNativeWidgetImpl(init_params, &widget, nullptr);
3763 widget.Init(init_params); 3748 widget.Init(init_params);
3749 }
3750
3751 class CompositingWidgetTest : public views::test::WidgetTest {
3752 public:
3753 CompositingWidgetTest()
3754 : widget_types_{Widget::InitParams::TYPE_WINDOW,
3755 Widget::InitParams::TYPE_PANEL,
3756 Widget::InitParams::TYPE_WINDOW_FRAMELESS,
3757 Widget::InitParams::TYPE_CONTROL,
3758 Widget::InitParams::TYPE_POPUP,
3759 Widget::InitParams::TYPE_MENU,
3760 Widget::InitParams::TYPE_TOOLTIP,
3761 Widget::InitParams::TYPE_BUBBLE,
3762 Widget::InitParams::TYPE_DRAG} {}
3763 ~CompositingWidgetTest() override {}
3764
3765 void CheckAllWidgetsForOpacity(
3766 const Widget::InitParams::WindowOpacity opacity) {
3767 for (const auto& widget_type : widget_types_) {
3768 #if defined(OS_MACOSX)
3769 // Tooltips are native on Mac. See BridgedNativeWidget::Init.
3770 if (widget_type == Widget::InitParams::TYPE_TOOLTIP)
3771 continue;
3772 #elif defined(OS_WIN)
3773 // Other widget types would require to create a parent window and the
3774 // the purpose of this test is mainly X11 in the first place.
3775 if (widget_type != Widget::InitParams::TYPE_WINDOW)
3776 continue;
3777 #endif
3778 Widget widget;
3779 InitializeWidgetForOpacity(widget, CreateParams(widget_type), opacity);
3780
3781 // Use NativeWidgetAura directly.
3782 if (IsMus() &&
3783 (widget_type == Widget::InitParams::TYPE_WINDOW_FRAMELESS ||
3784 widget_type == Widget::InitParams::TYPE_CONTROL))
3785 continue;
3786
3787 EXPECT_EQ(IsNativeWindowTransparent(widget.GetNativeWindow()),
3788 widget.ShouldWindowContentsBeTransparent());
3789
3790 // When using the Mandoline UI Service, the translucency does not rely on
3791 // the widget type.
3792 if (IsMus())
3793 continue;
3764 3794
3765 #if defined(USE_X11) 3795 #if defined(USE_X11)
3766 if (has_compositing_manager) 3796 if (HasCompositingManager() &&
3767 EXPECT_TRUE(widget.IsTranslucentWindowOpacitySupported()); 3797 (widget_type == Widget::InitParams::TYPE_DRAG ||
3798 widget_type == Widget::InitParams::TYPE_WINDOW)) {
3799 EXPECT_TRUE(widget.IsTranslucentWindowOpacitySupported());
3800 } else {
3801 EXPECT_FALSE(widget.IsTranslucentWindowOpacitySupported());
3802 }
3768 #endif 3803 #endif
3769 } 3804 }
3805 }
3806
3807 protected:
sadrul 2016/09/02 19:53:24 private? Also, DISALLOW_COPY_AND_ASSIGN
Julien Isorce Samsung 2016/09/02 20:59:08 Done.
3808 const std::vector<Widget::InitParams::Type> widget_types_;
3809 };
3770 3810
3771 } // namespace 3811 } // namespace
3772 3812
3773 // Test opacity when compositing is enabled. 3813 // Test opacity when compositing is enabled.
3774 TEST_F(WidgetTest, Transparency_DesktopWidgetInferOpacity) { 3814 TEST_F(CompositingWidgetTest, Transparency_DesktopWidgetInferOpacity) {
3775 Widget widget; 3815 CheckAllWidgetsForOpacity(Widget::InitParams::INFER_OPACITY);
3776 InitializeWidgetForOpacity(widget,
3777 CreateParams(Widget::InitParams::TYPE_WINDOW),
3778 Widget::InitParams::INFER_OPACITY);
3779 EXPECT_EQ(IsNativeWindowTransparent(widget.GetNativeWindow()),
3780 widget.ShouldWindowContentsBeTransparent());
3781 } 3816 }
3782 3817
3783 TEST_F(WidgetTest, Transparency_DesktopWidgetOpaque) { 3818 TEST_F(CompositingWidgetTest, Transparency_DesktopWidgetOpaque) {
3784 Widget widget; 3819 CheckAllWidgetsForOpacity(Widget::InitParams::OPAQUE_WINDOW);
3785 InitializeWidgetForOpacity(widget,
3786 CreateParams(Widget::InitParams::TYPE_WINDOW),
3787 Widget::InitParams::OPAQUE_WINDOW);
3788 EXPECT_EQ(IsNativeWindowTransparent(widget.GetNativeWindow()),
3789 widget.ShouldWindowContentsBeTransparent());
3790 } 3820 }
3791 3821
3792 // Failing on Mac. http://cbrug.com/623421 3822 // Failing on Mac. http://cbrug.com/623421
3793 #if defined(OS_MACOSX) 3823 #if defined(OS_MACOSX)
3794 #define MAYBE_Transparency_DesktopWidgetTranslucent \ 3824 #define MAYBE_Transparency_DesktopWidgetTranslucent \
3795 DISABLED_Transparency_DesktopWidgetTranslucent 3825 DISABLED_Transparency_DesktopWidgetTranslucent
3796 #else 3826 #else
3797 #define MAYBE_Transparency_DesktopWidgetTranslucent \ 3827 #define MAYBE_Transparency_DesktopWidgetTranslucent \
3798 Transparency_DesktopWidgetTranslucent 3828 Transparency_DesktopWidgetTranslucent
3799 #endif 3829 #endif
3800 TEST_F(WidgetTest, MAYBE_Transparency_DesktopWidgetTranslucent) { 3830 TEST_F(CompositingWidgetTest, MAYBE_Transparency_DesktopWidgetTranslucent) {
3801 Widget widget; 3831 CheckAllWidgetsForOpacity(Widget::InitParams::TRANSLUCENT_WINDOW);
3802 InitializeWidgetForOpacity(widget,
3803 CreateParams(Widget::InitParams::TYPE_WINDOW),
3804 Widget::InitParams::TRANSLUCENT_WINDOW);
3805 EXPECT_EQ(IsNativeWindowTransparent(widget.GetNativeWindow()),
3806 widget.ShouldWindowContentsBeTransparent());
3807 } 3832 }
3808 3833
3809 #endif // !defined(OS_CHROMEOS) 3834 #endif // !defined(OS_CHROMEOS)
3810 3835
3811 } // namespace test 3836 } // namespace test
3812 } // namespace views 3837 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698