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

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

Issue 1998653002: Make DesktopWindowTreeHostX11::ShouldWindowContentsBeTransparent() relies on argb visual flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and use USE_X11 instead of OS_LINUX Created 4 years, 6 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/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
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 3659 matching lines...) Expand 10 before | Expand all | Expand 10 after
3719 3725
3720 EXPECT_FALSE(!!IsWindow(owner_hwnd)); 3726 EXPECT_FALSE(!!IsWindow(owner_hwnd));
3721 EXPECT_FALSE(!!IsWindow(owned_hwnd)); 3727 EXPECT_FALSE(!!IsWindow(owned_hwnd));
3722 EXPECT_TRUE(!!IsWindowEnabled(top_hwnd)); 3728 EXPECT_TRUE(!!IsWindowEnabled(top_hwnd));
3723 3729
3724 top_level_widget.CloseNow(); 3730 top_level_widget.CloseNow();
3725 } 3731 }
3726 3732
3727 #endif // defined(OS_WIN) 3733 #endif // defined(OS_WIN)
3728 3734
3735 #if !defined(OS_CHROMEOS)
3736 namespace {
3737
3738 // An observer that registers the transparent flag of a widget on creation.
3739 class WidgetTransparencyObserver : public WidgetObserver {
3740 public:
3741 WidgetTransparencyObserver() : count_(0), transparent_(false) {}
3742 ~WidgetTransparencyObserver() override {}
3743
3744 bool transparent() { return transparent_; }
3745
3746 // WidgetObserver:
3747 void OnWidgetCreated(Widget* widget) override {
3748 EXPECT_EQ(count_, 0);
3749 EXPECT_TRUE(widget->GetNativeWindow());
3750
3751 ++count_;
3752 transparent_ =
3753 WidgetTest::IsNativeWindowTransparent(widget->GetNativeWindow());
3754
3755 #if defined(USE_X11)
3756 EXPECT_TRUE(transparent_);
3757 #endif
3758 }
3759
3760 private:
3761 int count_;
3762 bool transparent_;
3763
3764 DISALLOW_COPY_AND_ASSIGN(WidgetTransparencyObserver);
3765 };
3766
3767 } // namespace
3768
3769 // Test to ensure that the aura Window remains transparent after its creation
3770 // has finished if transparent visuals are enabled.
3771 TEST_F(WidgetTest, Transparency_DesktopWidget) {
3772 #if defined(USE_X11)
3773 // On Linux, transparent visuals is currently not activated by default.
3774 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
3775 command_line->AppendSwitch(switches::kEnableTransparentVisuals);
3776
3777 int depth = 0;
3778 ui::ChooseVisualForWindow(NULL, &depth);
3779
3780 EXPECT_EQ(depth, 32);
3781 #endif
3782
3783 Widget::InitParams init_params =
3784 CreateParams(Widget::InitParams::TYPE_WINDOW);
3785 init_params.show_state = ui::SHOW_STATE_NORMAL;
3786 init_params.bounds = gfx::Rect(0, 0, 500, 500);
3787 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
3788 Widget widget;
3789 WidgetTransparencyObserver widget_observer;
3790 init_params.native_widget =
3791 CreatePlatformDesktopNativeWidgetImpl(init_params, &widget, nullptr);
3792 widget.AddObserver(&widget_observer);
3793 widget.Init(init_params);
3794
3795 EXPECT_EQ(widget_observer.transparent(),
3796 IsNativeWindowTransparent(widget.GetNativeWindow()));
3797 EXPECT_EQ(widget_observer.transparent(),
3798 widget.ShouldWindowContentsBeTransparent());
3799
3800 #if defined(USE_X11)
3801 EXPECT_TRUE(widget_observer.transparent());
3802 #endif
3803 }
3804 #endif // !defined(OS_CHROMEOS)
3805
3729 } // namespace test 3806 } // namespace test
3730 } // namespace views 3807 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698