Commit 99829ce4 authored by estade@chromium.org's avatar estade@chromium.org

Fix some views unittests on desktop Linux.

BUG=369289

Review URL: https://codereview.chromium.org/291093012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274369 0039d316-1c4b-4281-b951-d872f2087c98
parent eb27eeab
......@@ -1192,21 +1192,16 @@ bool IsX11WindowFullScreen(XID window) {
// If _NET_WM_STATE_FULLSCREEN is in _NET_SUPPORTED, use the presence or
// absence of _NET_WM_STATE_FULLSCREEN in _NET_WM_STATE to determine
// whether we're fullscreen.
std::vector<Atom> supported_atoms;
if (GetAtomArrayProperty(GetX11RootWindow(),
"_NET_SUPPORTED",
&supported_atoms)) {
Atom atom = GetAtom("_NET_WM_STATE_FULLSCREEN");
if (std::find(supported_atoms.begin(), supported_atoms.end(), atom)
!= supported_atoms.end()) {
std::vector<Atom> atom_properties;
if (GetAtomArrayProperty(window,
"_NET_WM_STATE",
&atom_properties)) {
return std::find(atom_properties.begin(), atom_properties.end(), atom)
!= atom_properties.end();
}
Atom fullscreen_atom = GetAtom("_NET_WM_STATE_FULLSCREEN");
if (WmSupportsHint(fullscreen_atom)) {
std::vector<Atom> atom_properties;
if (GetAtomArrayProperty(window,
"_NET_WM_STATE",
&atom_properties)) {
return std::find(atom_properties.begin(),
atom_properties.end(),
fullscreen_atom) !=
atom_properties.end();
}
}
......@@ -1226,6 +1221,18 @@ bool IsX11WindowFullScreen(XID window) {
return window_rect.size() == gfx::Size(width, height);
}
bool WmSupportsHint(Atom atom) {
std::vector<Atom> supported_atoms;
if (!GetAtomArrayProperty(GetX11RootWindow(),
"_NET_SUPPORTED",
&supported_atoms)) {
return false;
}
return std::find(supported_atoms.begin(), supported_atoms.end(), atom) !=
supported_atoms.end();
}
const unsigned char* XRefcountedMemory::front() const {
return x11_data_;
}
......
......@@ -179,7 +179,7 @@ UI_BASE_EXPORT bool SetStringProperty(XID window,
const std::string& value);
// Gets the X atom for default display corresponding to atom_name.
Atom GetAtom(const char* atom_name);
UI_BASE_EXPORT Atom GetAtom(const char* atom_name);
// Sets the WM_CLASS attribute for a given X11 window.
UI_BASE_EXPORT void SetWindowClassHint(XDisplay* display,
......@@ -262,9 +262,12 @@ UI_BASE_EXPORT WindowManagerName GuessWindowManager();
// to set your own error handlers.
UI_BASE_EXPORT void SetDefaultX11ErrorHandlers();
// Return true if a given window is in full-screen mode.
// Returns true if a given window is in full-screen mode.
UI_BASE_EXPORT bool IsX11WindowFullScreen(XID window);
// Returns true if the window manager supports the given hint.
UI_BASE_EXPORT bool WmSupportsHint(Atom atom);
// Manages a piece of X11 allocated memory as a RefCountedMemory segment. This
// object takes ownership over the passed in memory and will free it with the
// X11 allocator when done.
......
......@@ -30,12 +30,21 @@ TEST_F(DesktopNativeWidgetAuraTest, CreateWithParentNotInRootWindow) {
widget.Init(params);
}
// Verifies that the AURA windows making up a widget instance have the correct
// Verifies that the Aura windows making up a widget instance have the correct
// bounds after the widget is resized.
TEST_F(DesktopNativeWidgetAuraTest, DesktopAuraWindowSizeTest) {
Widget widget;
// On Linux we test this with popup windows because the WM may ignore the size
// suggestion for normal windows.
#if defined(OS_LINUX)
Widget::InitParams init_params =
CreateParams(Widget::InitParams::TYPE_POPUP);
#else
Widget::InitParams init_params =
CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
#endif
init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
init_params.native_widget = new DesktopNativeWidgetAura(&widget);
widget.Init(init_params);
......
......@@ -313,6 +313,9 @@ TEST_F(DesktopScreenX11Test, GetPrimaryDisplay) {
}
TEST_F(DesktopScreenX11Test, GetWindowAtScreenPoint) {
if (!ui::WmSupportsHint(ui::GetAtom("_NET_ACTIVE_WINDOW")))
return;
Widget* window_one = BuildTopLevelDesktopWidget(gfx::Rect(110, 110, 10, 10),
false);
Widget* window_two = BuildTopLevelDesktopWidget(gfx::Rect(150, 150, 10, 10),
......@@ -375,6 +378,9 @@ TEST_F(DesktopScreenX11Test, GetDisplayNearestWindow) {
// Tests that the window is maximized in response to a double click event.
TEST_F(DesktopScreenX11Test, DoubleClickHeaderMaximizes) {
if (!ui::WmSupportsHint(ui::GetAtom("_NET_WM_STATE_MAXIMIZED_VERT")))
return;
Widget* widget = BuildTopLevelDesktopWidget(gfx::Rect(0, 0, 100, 100), true);
widget->Show();
TestDesktopNativeWidgetAura* native_widget =
......
......@@ -157,7 +157,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
// Overridden frm ui::EventSource
virtual ui::EventProcessor* GetEventProcessor() OVERRIDE;
private:
private:
// Initializes our X11 surface to draw on. This method performs all
// initialization related to talking to the X11 server.
void InitX11Window(const Widget::InitParams& params);
......
......@@ -262,45 +262,53 @@ TEST_F(DesktopWindowTreeHostX11Test, Shape) {
XID xid1 = widget1->GetNativeWindow()->GetHost()->GetAcceleratedWidget();
std::vector<gfx::Rect> shape_rects = GetShapeRects(xid1);
ASSERT_FALSE(shape_rects.empty());
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 85, 5));
EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 95, 5));
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 15));
EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 105, 15));
// The widget was supposed to be 100x100, but the WM might have ignored this
// suggestion.
int widget_width = widget1->GetWindowBoundsInScreen().width();
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, widget_width - 15, 5));
EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, widget_width - 5, 5));
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, widget_width - 5, 15));
EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, widget_width + 5, 15));
// Changing widget's size should update the shape.
widget1->SetBounds(gfx::Rect(100, 100, 200, 200));
ui::X11EventSource::GetInstance()->DispatchXEvents();
shape_rects = GetShapeRects(xid1);
ASSERT_FALSE(shape_rects.empty());
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 85, 5));
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 5));
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 185, 5));
EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 195, 5));
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 195, 15));
EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 205, 15));
// The shape should be changed to a rectangle which fills the entire screen
// when |widget1| is maximized.
{
MaximizeWaiter waiter(xid1);
widget1->Maximize();
waiter.Wait();
if (widget1->GetWindowBoundsInScreen().width() == 200) {
shape_rects = GetShapeRects(xid1);
ASSERT_FALSE(shape_rects.empty());
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 85, 5));
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 5));
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 185, 5));
EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 195, 5));
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 195, 15));
EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 205, 15));
}
// xvfb does not support Xrandr so we cannot check the maximized window's
// bounds.
gfx::Rect maximized_bounds;
ui::GetWindowRect(xid1, &maximized_bounds);
shape_rects = GetShapeRects(xid1);
ASSERT_FALSE(shape_rects.empty());
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects,
maximized_bounds.width() - 1,
5));
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects,
maximized_bounds.width() - 1,
15));
if (ui::WmSupportsHint(ui::GetAtom("_NET_WM_STATE_MAXIMIZED_VERT"))) {
// The shape should be changed to a rectangle which fills the entire screen
// when |widget1| is maximized.
{
MaximizeWaiter waiter(xid1);
widget1->Maximize();
waiter.Wait();
}
// xvfb does not support Xrandr so we cannot check the maximized window's
// bounds.
gfx::Rect maximized_bounds;
ui::GetWindowRect(xid1, &maximized_bounds);
shape_rects = GetShapeRects(xid1);
ASSERT_FALSE(shape_rects.empty());
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects,
maximized_bounds.width() - 1,
5));
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects,
maximized_bounds.width() - 1,
15));
}
// 2) Test setting the window shape via Widget::SetShape().
gfx::Path shape2;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment