Index: ui/views/widget/widget_unittest.cc |
diff --git a/ui/views/widget/widget_unittest.cc b/ui/views/widget/widget_unittest.cc |
index 95fc77e0acd3fda26940cc855991f4f6d59d608a..b85e3fc89e28f568b55446491e621f247803026b 100644 |
--- a/ui/views/widget/widget_unittest.cc |
+++ b/ui/views/widget/widget_unittest.cc |
@@ -7,7 +7,6 @@ |
#include <set> |
#include "base/bind.h" |
-#include "base/environment.h" |
#include "base/macros.h" |
#include "base/message_loop/message_loop.h" |
#include "base/run_loop.h" |
@@ -48,11 +47,6 @@ |
#include "base/mac/mac_util.h" |
#endif |
-#if defined(USE_X11) && !defined(OS_CHROMEOS) |
-#include "ui/base/x/x11_util_internal.h" // nogncheck |
-#include "ui/gfx/x/x11_switches.h" // nogncheck |
-#endif |
- |
namespace views { |
namespace test { |
@@ -3743,17 +3737,6 @@ void InitializeWidgetForOpacity( |
Widget& widget, |
Widget::InitParams init_params, |
const Widget::InitParams::WindowOpacity opacity) { |
-#if defined(USE_X11) |
- // testing/xvfb.py runs xvfb and xcompmgr. |
- std::unique_ptr<base::Environment> env(base::Environment::Create()); |
- bool has_compositing_manager = env->HasVar("_CHROMIUM_INSIDE_XVFB"); |
- int depth = 0; |
- ui::ChooseVisualForWindow(has_compositing_manager, NULL, &depth); |
- |
- if (has_compositing_manager) |
- EXPECT_EQ(depth, 32); |
-#endif |
- |
init_params.opacity = opacity; |
init_params.show_state = ui::SHOW_STATE_NORMAL; |
init_params.bounds = gfx::Rect(0, 0, 500, 500); |
@@ -3761,32 +3744,79 @@ void InitializeWidgetForOpacity( |
init_params.native_widget = |
CreatePlatformDesktopNativeWidgetImpl(init_params, &widget, nullptr); |
widget.Init(init_params); |
+} |
+ |
+class CompositingWidgetTest : public views::test::WidgetTest { |
+ public: |
+ CompositingWidgetTest() |
+ : widget_types_{Widget::InitParams::TYPE_WINDOW, |
+ Widget::InitParams::TYPE_PANEL, |
+ Widget::InitParams::TYPE_WINDOW_FRAMELESS, |
+ Widget::InitParams::TYPE_CONTROL, |
+ Widget::InitParams::TYPE_POPUP, |
+ Widget::InitParams::TYPE_MENU, |
+ Widget::InitParams::TYPE_TOOLTIP, |
+ Widget::InitParams::TYPE_BUBBLE, |
+ Widget::InitParams::TYPE_DRAG} {} |
+ ~CompositingWidgetTest() override {} |
+ |
+ void CheckAllWidgetsForOpacity( |
+ const Widget::InitParams::WindowOpacity opacity) { |
+ for (const auto& widget_type : widget_types_) { |
+#if defined(OS_MACOSX) |
+ // Tooltips are native on Mac. See BridgedNativeWidget::Init. |
+ if (widget_type == Widget::InitParams::TYPE_TOOLTIP) |
+ continue; |
+#elif defined(OS_WIN) |
+ // Other widget types would require to create a parent window and the |
+ // the purpose of this test is mainly X11 in the first place. |
+ if (widget_type != Widget::InitParams::TYPE_WINDOW) |
+ continue; |
+#endif |
+ Widget widget; |
+ InitializeWidgetForOpacity(widget, CreateParams(widget_type), opacity); |
+ |
+ // Use NativeWidgetAura directly. |
+ if (IsMus() && |
+ (widget_type == Widget::InitParams::TYPE_WINDOW_FRAMELESS || |
+ widget_type == Widget::InitParams::TYPE_CONTROL)) |
+ continue; |
+ |
+ EXPECT_EQ(IsNativeWindowTransparent(widget.GetNativeWindow()), |
+ widget.ShouldWindowContentsBeTransparent()); |
+ |
+ // When using the Mandoline UI Service, the translucency does not rely on |
+ // the widget type. |
+ if (IsMus()) |
+ continue; |
#if defined(USE_X11) |
- if (has_compositing_manager) |
- EXPECT_TRUE(widget.IsTranslucentWindowOpacitySupported()); |
+ if (HasCompositingManager() && |
+ (widget_type == Widget::InitParams::TYPE_DRAG || |
+ widget_type == Widget::InitParams::TYPE_WINDOW)) { |
+ EXPECT_TRUE(widget.IsTranslucentWindowOpacitySupported()); |
+ } else { |
+ EXPECT_FALSE(widget.IsTranslucentWindowOpacitySupported()); |
+ } |
#endif |
-} |
+ } |
+ } |
+ |
+ protected: |
+ const std::vector<Widget::InitParams::Type> widget_types_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(CompositingWidgetTest); |
+}; |
} // namespace |
// Test opacity when compositing is enabled. |
-TEST_F(WidgetTest, Transparency_DesktopWidgetInferOpacity) { |
- Widget widget; |
- InitializeWidgetForOpacity(widget, |
- CreateParams(Widget::InitParams::TYPE_WINDOW), |
- Widget::InitParams::INFER_OPACITY); |
- EXPECT_EQ(IsNativeWindowTransparent(widget.GetNativeWindow()), |
- widget.ShouldWindowContentsBeTransparent()); |
+TEST_F(CompositingWidgetTest, Transparency_DesktopWidgetInferOpacity) { |
+ CheckAllWidgetsForOpacity(Widget::InitParams::INFER_OPACITY); |
} |
-TEST_F(WidgetTest, Transparency_DesktopWidgetOpaque) { |
- Widget widget; |
- InitializeWidgetForOpacity(widget, |
- CreateParams(Widget::InitParams::TYPE_WINDOW), |
- Widget::InitParams::OPAQUE_WINDOW); |
- EXPECT_EQ(IsNativeWindowTransparent(widget.GetNativeWindow()), |
- widget.ShouldWindowContentsBeTransparent()); |
+TEST_F(CompositingWidgetTest, Transparency_DesktopWidgetOpaque) { |
+ CheckAllWidgetsForOpacity(Widget::InitParams::OPAQUE_WINDOW); |
} |
// Failing on Mac. http://cbrug.com/623421 |
@@ -3797,13 +3827,8 @@ TEST_F(WidgetTest, Transparency_DesktopWidgetOpaque) { |
#define MAYBE_Transparency_DesktopWidgetTranslucent \ |
Transparency_DesktopWidgetTranslucent |
#endif |
-TEST_F(WidgetTest, MAYBE_Transparency_DesktopWidgetTranslucent) { |
- Widget widget; |
- InitializeWidgetForOpacity(widget, |
- CreateParams(Widget::InitParams::TYPE_WINDOW), |
- Widget::InitParams::TRANSLUCENT_WINDOW); |
- EXPECT_EQ(IsNativeWindowTransparent(widget.GetNativeWindow()), |
- widget.ShouldWindowContentsBeTransparent()); |
+TEST_F(CompositingWidgetTest, MAYBE_Transparency_DesktopWidgetTranslucent) { |
+ CheckAllWidgetsForOpacity(Widget::InitParams::TRANSLUCENT_WINDOW); |
} |
#endif // !defined(OS_CHROMEOS) |