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

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 ShouldWindowContentsBeTransparent 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
« no previous file with comments | « ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 3638 matching lines...) Expand 10 before | Expand all | Expand 10 after
3698 3704
3699 EXPECT_FALSE(!!IsWindow(owner_hwnd)); 3705 EXPECT_FALSE(!!IsWindow(owner_hwnd));
3700 EXPECT_FALSE(!!IsWindow(owned_hwnd)); 3706 EXPECT_FALSE(!!IsWindow(owned_hwnd));
3701 EXPECT_TRUE(!!IsWindowEnabled(top_hwnd)); 3707 EXPECT_TRUE(!!IsWindowEnabled(top_hwnd));
3702 3708
3703 top_level_widget.CloseNow(); 3709 top_level_widget.CloseNow();
3704 } 3710 }
3705 3711
3706 #endif // defined(OS_WIN) 3712 #endif // defined(OS_WIN)
3707 3713
3714 #if !defined(OS_CHROMEOS)
3715 namespace {
3716
3717 // An observer that registers the transparent flag of a widget on creation.
3718 class WidgetTransparencyObserver : public WidgetObserver {
3719 public:
3720 WidgetTransparencyObserver() : count_(0), transparent_(false) {}
3721 ~WidgetTransparencyObserver() override {}
3722
3723 bool transparent() { return transparent_; }
3724
3725 // WidgetObserver:
3726 void OnWidgetCreated(Widget* widget) override {
3727 EXPECT_EQ(count_, 0);
3728 EXPECT_TRUE(widget->GetNativeWindow());
3729
3730 ++count_;
3731 transparent_ =
3732 WidgetTest::IsNativeWindowTransparent(widget->GetNativeWindow());
3733
3734 #if defined(USE_X11)
3735 EXPECT_TRUE(transparent_);
3736 #endif
3737 }
3738
3739 private:
3740 int count_;
3741 bool transparent_;
3742
3743 DISALLOW_COPY_AND_ASSIGN(WidgetTransparencyObserver);
3744 };
3745
3746 } // namespace
3747
3748 // Test to ensure that the aura Window remains transparent after its creation
3749 // has finished if transparent visuals are enabled.
3750 TEST_F(WidgetTest, Transparency_DesktopWidget) {
3751 #if defined(USE_X11)
3752 // On Linux, transparent visuals is currently not activated by default.
3753 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
3754 command_line->AppendSwitch(switches::kEnableTransparentVisuals);
3755
3756 int depth = 0;
3757 ui::ChooseVisualForWindow(NULL, &depth);
3758
sadrul 2016/06/14 14:32:13 nite: remove the empty line here.
Julien Isorce Samsung 2016/06/14 15:22:28 Acknowledged.
3759 EXPECT_EQ(depth, 32);
3760 #endif
3761
3762 Widget::InitParams init_params =
3763 CreateParams(Widget::InitParams::TYPE_WINDOW);
3764 init_params.show_state = ui::SHOW_STATE_NORMAL;
3765 init_params.bounds = gfx::Rect(0, 0, 500, 500);
3766 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
3767 Widget widget;
3768 WidgetTransparencyObserver widget_observer;
3769 init_params.native_widget =
3770 CreatePlatformDesktopNativeWidgetImpl(init_params, &widget, nullptr);
3771 widget.AddObserver(&widget_observer);
3772 widget.Init(init_params);
3773
3774 EXPECT_EQ(widget_observer.transparent(),
3775 IsNativeWindowTransparent(widget.GetNativeWindow()));
3776 EXPECT_EQ(widget_observer.transparent(),
3777 widget.ShouldWindowContentsBeTransparent());
sadrul 2016/06/14 14:32:13 You can just check if the Widget is transparent he
Julien Isorce Samsung 2016/06/14 15:22:28 That is true I could just reduce and keep: IsNativ
3778
3779 #if defined(USE_X11)
3780 EXPECT_TRUE(widget_observer.transparent());
sadrul 2016/06/14 14:32:13 Can you explain this expectation? Why should a Wid
Julien Isorce Samsung 2016/06/14 15:22:28 The function name is miss-leading, WidgetTranspare
3781 #endif
3782 }
3783 #endif // !defined(OS_CHROMEOS)
3784
3708 } // namespace test 3785 } // namespace test
3709 } // namespace views 3786 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698