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) { ...@@ -1192,21 +1192,16 @@ bool IsX11WindowFullScreen(XID window) {
// If _NET_WM_STATE_FULLSCREEN is in _NET_SUPPORTED, use the presence or // 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 // absence of _NET_WM_STATE_FULLSCREEN in _NET_WM_STATE to determine
// whether we're fullscreen. // whether we're fullscreen.
std::vector<Atom> supported_atoms; Atom fullscreen_atom = GetAtom("_NET_WM_STATE_FULLSCREEN");
if (GetAtomArrayProperty(GetX11RootWindow(), if (WmSupportsHint(fullscreen_atom)) {
"_NET_SUPPORTED", std::vector<Atom> atom_properties;
&supported_atoms)) { if (GetAtomArrayProperty(window,
Atom atom = GetAtom("_NET_WM_STATE_FULLSCREEN"); "_NET_WM_STATE",
&atom_properties)) {
if (std::find(supported_atoms.begin(), supported_atoms.end(), atom) return std::find(atom_properties.begin(),
!= supported_atoms.end()) { atom_properties.end(),
std::vector<Atom> atom_properties; fullscreen_atom) !=
if (GetAtomArrayProperty(window, atom_properties.end();
"_NET_WM_STATE",
&atom_properties)) {
return std::find(atom_properties.begin(), atom_properties.end(), atom)
!= atom_properties.end();
}
} }
} }
...@@ -1226,6 +1221,18 @@ bool IsX11WindowFullScreen(XID window) { ...@@ -1226,6 +1221,18 @@ bool IsX11WindowFullScreen(XID window) {
return window_rect.size() == gfx::Size(width, height); 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 { const unsigned char* XRefcountedMemory::front() const {
return x11_data_; return x11_data_;
} }
......
...@@ -179,7 +179,7 @@ UI_BASE_EXPORT bool SetStringProperty(XID window, ...@@ -179,7 +179,7 @@ UI_BASE_EXPORT bool SetStringProperty(XID window,
const std::string& value); const std::string& value);
// Gets the X atom for default display corresponding to atom_name. // 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. // Sets the WM_CLASS attribute for a given X11 window.
UI_BASE_EXPORT void SetWindowClassHint(XDisplay* display, UI_BASE_EXPORT void SetWindowClassHint(XDisplay* display,
...@@ -262,9 +262,12 @@ UI_BASE_EXPORT WindowManagerName GuessWindowManager(); ...@@ -262,9 +262,12 @@ UI_BASE_EXPORT WindowManagerName GuessWindowManager();
// to set your own error handlers. // to set your own error handlers.
UI_BASE_EXPORT void SetDefaultX11ErrorHandlers(); 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); 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 // 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 // object takes ownership over the passed in memory and will free it with the
// X11 allocator when done. // X11 allocator when done.
......
...@@ -30,12 +30,21 @@ TEST_F(DesktopNativeWidgetAuraTest, CreateWithParentNotInRootWindow) { ...@@ -30,12 +30,21 @@ TEST_F(DesktopNativeWidgetAuraTest, CreateWithParentNotInRootWindow) {
widget.Init(params); 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. // bounds after the widget is resized.
TEST_F(DesktopNativeWidgetAuraTest, DesktopAuraWindowSizeTest) { TEST_F(DesktopNativeWidgetAuraTest, DesktopAuraWindowSizeTest) {
Widget widget; 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 = Widget::InitParams init_params =
CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
#endif
init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
init_params.native_widget = new DesktopNativeWidgetAura(&widget); init_params.native_widget = new DesktopNativeWidgetAura(&widget);
widget.Init(init_params); widget.Init(init_params);
......
...@@ -313,6 +313,9 @@ TEST_F(DesktopScreenX11Test, GetPrimaryDisplay) { ...@@ -313,6 +313,9 @@ TEST_F(DesktopScreenX11Test, GetPrimaryDisplay) {
} }
TEST_F(DesktopScreenX11Test, GetWindowAtScreenPoint) { TEST_F(DesktopScreenX11Test, GetWindowAtScreenPoint) {
if (!ui::WmSupportsHint(ui::GetAtom("_NET_ACTIVE_WINDOW")))
return;
Widget* window_one = BuildTopLevelDesktopWidget(gfx::Rect(110, 110, 10, 10), Widget* window_one = BuildTopLevelDesktopWidget(gfx::Rect(110, 110, 10, 10),
false); false);
Widget* window_two = BuildTopLevelDesktopWidget(gfx::Rect(150, 150, 10, 10), Widget* window_two = BuildTopLevelDesktopWidget(gfx::Rect(150, 150, 10, 10),
...@@ -375,6 +378,9 @@ TEST_F(DesktopScreenX11Test, GetDisplayNearestWindow) { ...@@ -375,6 +378,9 @@ TEST_F(DesktopScreenX11Test, GetDisplayNearestWindow) {
// Tests that the window is maximized in response to a double click event. // Tests that the window is maximized in response to a double click event.
TEST_F(DesktopScreenX11Test, DoubleClickHeaderMaximizes) { 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* widget = BuildTopLevelDesktopWidget(gfx::Rect(0, 0, 100, 100), true);
widget->Show(); widget->Show();
TestDesktopNativeWidgetAura* native_widget = TestDesktopNativeWidgetAura* native_widget =
......
...@@ -157,7 +157,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 ...@@ -157,7 +157,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
// Overridden frm ui::EventSource // Overridden frm ui::EventSource
virtual ui::EventProcessor* GetEventProcessor() OVERRIDE; virtual ui::EventProcessor* GetEventProcessor() OVERRIDE;
private: private:
// Initializes our X11 surface to draw on. This method performs all // Initializes our X11 surface to draw on. This method performs all
// initialization related to talking to the X11 server. // initialization related to talking to the X11 server.
void InitX11Window(const Widget::InitParams& params); void InitX11Window(const Widget::InitParams& params);
......
...@@ -262,45 +262,53 @@ TEST_F(DesktopWindowTreeHostX11Test, Shape) { ...@@ -262,45 +262,53 @@ TEST_F(DesktopWindowTreeHostX11Test, Shape) {
XID xid1 = widget1->GetNativeWindow()->GetHost()->GetAcceleratedWidget(); XID xid1 = widget1->GetNativeWindow()->GetHost()->GetAcceleratedWidget();
std::vector<gfx::Rect> shape_rects = GetShapeRects(xid1); std::vector<gfx::Rect> shape_rects = GetShapeRects(xid1);
ASSERT_FALSE(shape_rects.empty()); ASSERT_FALSE(shape_rects.empty());
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 85, 5));
EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 95, 5)); // The widget was supposed to be 100x100, but the WM might have ignored this
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 15)); // suggestion.
EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 105, 15)); 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. // Changing widget's size should update the shape.
widget1->SetBounds(gfx::Rect(100, 100, 200, 200)); widget1->SetBounds(gfx::Rect(100, 100, 200, 200));
ui::X11EventSource::GetInstance()->DispatchXEvents(); ui::X11EventSource::GetInstance()->DispatchXEvents();
shape_rects = GetShapeRects(xid1); if (widget1->GetWindowBoundsInScreen().width() == 200) {
ASSERT_FALSE(shape_rects.empty()); shape_rects = GetShapeRects(xid1);
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 85, 5)); ASSERT_FALSE(shape_rects.empty());
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 5)); EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 85, 5));
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 185, 5)); EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 5));
EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 195, 5)); EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 185, 5));
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 195, 15)); EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 195, 5));
EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 205, 15)); 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();
} }
// xvfb does not support Xrandr so we cannot check the maximized window's if (ui::WmSupportsHint(ui::GetAtom("_NET_WM_STATE_MAXIMIZED_VERT"))) {
// bounds. // The shape should be changed to a rectangle which fills the entire screen
gfx::Rect maximized_bounds; // when |widget1| is maximized.
ui::GetWindowRect(xid1, &maximized_bounds); {
MaximizeWaiter waiter(xid1);
shape_rects = GetShapeRects(xid1); widget1->Maximize();
ASSERT_FALSE(shape_rects.empty()); waiter.Wait();
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, }
maximized_bounds.width() - 1,
5)); // xvfb does not support Xrandr so we cannot check the maximized window's
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, // bounds.
maximized_bounds.width() - 1, gfx::Rect maximized_bounds;
15)); 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(). // 2) Test setting the window shape via Widget::SetShape().
gfx::Path shape2; 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