OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/views/widget/desktop_aura/x11_topmost_window_finder.h" | 5 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 #include <X11/extensions/shape.h> | 9 #include <X11/extensions/shape.h> |
10 #include <X11/Xlib.h> | 10 #include <X11/Xlib.h> |
11 #include <X11/Xregion.h> | 11 #include <X11/Xregion.h> |
12 | 12 |
13 // Get rid of X11 macros which conflict with gtest. | 13 // Get rid of X11 macros which conflict with gtest. |
14 #undef Bool | 14 #undef Bool |
15 #undef None | 15 #undef None |
16 | 16 |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/path_service.h" |
18 #include "third_party/skia/include/core/SkRect.h" | 19 #include "third_party/skia/include/core/SkRect.h" |
19 #include "third_party/skia/include/core/SkRegion.h" | 20 #include "third_party/skia/include/core/SkRegion.h" |
20 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
21 #include "ui/aura/window_tree_host.h" | 22 #include "ui/aura/window_tree_host.h" |
| 23 #include "ui/base/resource/resource_bundle.h" |
| 24 #include "ui/base/ui_base_paths.h" |
22 #include "ui/events/platform/x11/x11_event_source.h" | 25 #include "ui/events/platform/x11/x11_event_source.h" |
23 #include "ui/gfx/path.h" | 26 #include "ui/gfx/path.h" |
24 #include "ui/gfx/path_x11.h" | 27 #include "ui/gfx/path_x11.h" |
25 #include "ui/gfx/x/x11_atom_cache.h" | 28 #include "ui/gfx/x/x11_atom_cache.h" |
| 29 #include "ui/gl/gl_surface.h" |
26 #include "ui/views/test/views_test_base.h" | 30 #include "ui/views/test/views_test_base.h" |
27 #include "ui/views/test/x11_property_change_waiter.h" | 31 #include "ui/views/test/x11_property_change_waiter.h" |
28 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 32 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
29 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" | 33 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" |
30 #include "ui/views/widget/widget.h" | 34 #include "ui/views/widget/widget.h" |
31 | 35 |
32 namespace views { | 36 namespace views { |
33 | 37 |
34 namespace { | 38 namespace { |
35 | 39 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 int screen_x, | 189 int screen_x, |
186 int screen_y, | 190 int screen_y, |
187 aura::Window* ignore_window) { | 191 aura::Window* ignore_window) { |
188 std::set<aura::Window*> ignore; | 192 std::set<aura::Window*> ignore; |
189 ignore.insert(ignore_window); | 193 ignore.insert(ignore_window); |
190 X11TopmostWindowFinder finder; | 194 X11TopmostWindowFinder finder; |
191 return finder.FindLocalProcessWindowAt(gfx::Point(screen_x, screen_y), | 195 return finder.FindLocalProcessWindowAt(gfx::Point(screen_x, screen_y), |
192 ignore); | 196 ignore); |
193 } | 197 } |
194 | 198 |
| 199 static void SetUpTestCase() { |
| 200 gfx::GLSurface::InitializeOneOffForTests(); |
| 201 ui::RegisterPathProvider(); |
| 202 base::FilePath ui_test_pak_path; |
| 203 ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); |
| 204 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); |
| 205 } |
| 206 |
195 // ViewsTestBase: | 207 // ViewsTestBase: |
196 virtual void SetUp() OVERRIDE { | 208 virtual void SetUp() OVERRIDE { |
197 ViewsTestBase::SetUp(); | 209 ViewsTestBase::SetUp(); |
198 | 210 |
199 // Make X11 synchronous for our display connection. This does not force the | 211 // Make X11 synchronous for our display connection. This does not force the |
200 // window manager to behave synchronously. | 212 // window manager to behave synchronously. |
201 XSynchronize(xdisplay(), True); | 213 XSynchronize(xdisplay(), True); |
202 | 214 |
203 // Ensure that the X11DesktopHandler exists. The X11DesktopHandler is | 215 // Ensure that the X11DesktopHandler exists. The X11DesktopHandler is |
204 // necessary to properly track menu windows. | 216 // necessary to properly track menu windows. |
205 X11DesktopHandler::get(); | 217 X11DesktopHandler::get(); |
206 } | 218 } |
207 | 219 |
208 virtual void TearDown() OVERRIDE { | 220 virtual void TearDown() OVERRIDE { |
209 XSynchronize(xdisplay(), False); | 221 XSynchronize(xdisplay(), False); |
210 ViewsTestBase::TearDown(); | 222 ViewsTestBase::TearDown(); |
211 } | 223 } |
212 | 224 |
213 private: | 225 private: |
214 DISALLOW_COPY_AND_ASSIGN(X11TopmostWindowFinderTest); | 226 DISALLOW_COPY_AND_ASSIGN(X11TopmostWindowFinderTest); |
215 }; | 227 }; |
216 | 228 |
217 // Flaky on Linux. http://crbug.com/388241 | 229 TEST_F(X11TopmostWindowFinderTest, Basic) { |
218 TEST_F(X11TopmostWindowFinderTest, DISABLED_Basic) { | |
219 // Avoid positioning test windows at 0x0 because window managers often have a | 230 // Avoid positioning test windows at 0x0 because window managers often have a |
220 // panel/launcher along one of the screen edges and do not allow windows to | 231 // panel/launcher along one of the screen edges and do not allow windows to |
221 // position themselves to overlap the panel/launcher. | 232 // position themselves to overlap the panel/launcher. |
222 scoped_ptr<Widget> widget1( | 233 scoped_ptr<Widget> widget1( |
223 CreateAndShowWidget(gfx::Rect(100, 100, 200, 100))); | 234 CreateAndShowWidget(gfx::Rect(100, 100, 200, 100))); |
224 aura::Window* window1 = widget1->GetNativeWindow(); | 235 aura::Window* window1 = widget1->GetNativeWindow(); |
225 XID xid1 = window1->GetHost()->GetAcceleratedWidget(); | 236 XID xid1 = window1->GetHost()->GetAcceleratedWidget(); |
226 | 237 |
227 XID xid2 = CreateAndShowXWindow(gfx::Rect(200, 100, 100, 200)); | 238 XID xid2 = CreateAndShowXWindow(gfx::Rect(200, 100, 100, 200)); |
228 | 239 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 FindTopmostLocalProcessWindowWithIgnore(250, 250, window3)); | 273 FindTopmostLocalProcessWindowWithIgnore(250, 250, window3)); |
263 EXPECT_EQ(NULL, | 274 EXPECT_EQ(NULL, |
264 FindTopmostLocalProcessWindowWithIgnore(150, 250, window3)); | 275 FindTopmostLocalProcessWindowWithIgnore(150, 250, window3)); |
265 EXPECT_EQ(window1, | 276 EXPECT_EQ(window1, |
266 FindTopmostLocalProcessWindowWithIgnore(150, 195, window3)); | 277 FindTopmostLocalProcessWindowWithIgnore(150, 195, window3)); |
267 | 278 |
268 XDestroyWindow(xdisplay(), xid2); | 279 XDestroyWindow(xdisplay(), xid2); |
269 } | 280 } |
270 | 281 |
271 // Test that the minimized state is properly handled. | 282 // Test that the minimized state is properly handled. |
272 // Flaky on Linux. http://crbug.com/388241 | 283 TEST_F(X11TopmostWindowFinderTest, Minimized) { |
273 TEST_F(X11TopmostWindowFinderTest, DISABLED_Minimized) { | |
274 scoped_ptr<Widget> widget1( | 284 scoped_ptr<Widget> widget1( |
275 CreateAndShowWidget(gfx::Rect(100, 100, 100, 100))); | 285 CreateAndShowWidget(gfx::Rect(100, 100, 100, 100))); |
276 aura::Window* window1 = widget1->GetNativeWindow(); | 286 aura::Window* window1 = widget1->GetNativeWindow(); |
277 XID xid1 = window1->GetHost()->GetAcceleratedWidget(); | 287 XID xid1 = window1->GetHost()->GetAcceleratedWidget(); |
278 XID xid2 = CreateAndShowXWindow(gfx::Rect(300, 100, 100, 100)); | 288 XID xid2 = CreateAndShowXWindow(gfx::Rect(300, 100, 100, 100)); |
279 | 289 |
280 XID xids[] = { xid1, xid2 }; | 290 XID xids[] = { xid1, xid2 }; |
281 StackingClientListWaiter stack_waiter(xids, arraysize(xids)); | 291 StackingClientListWaiter stack_waiter(xids, arraysize(xids)); |
282 stack_waiter.Wait(); | 292 stack_waiter.Wait(); |
283 ui::X11EventSource::GetInstance()->DispatchXEvents(); | 293 ui::X11EventSource::GetInstance()->DispatchXEvents(); |
(...skipping 15 matching lines...) Expand all Loading... |
299 XIconifyWindow(xdisplay(), xid2, 0); | 309 XIconifyWindow(xdisplay(), xid2, 0); |
300 minimize_waiter.Wait(); | 310 minimize_waiter.Wait(); |
301 } | 311 } |
302 EXPECT_NE(xid1, FindTopmostXWindowAt(350, 150)); | 312 EXPECT_NE(xid1, FindTopmostXWindowAt(350, 150)); |
303 EXPECT_NE(xid2, FindTopmostXWindowAt(350, 150)); | 313 EXPECT_NE(xid2, FindTopmostXWindowAt(350, 150)); |
304 | 314 |
305 XDestroyWindow(xdisplay(), xid2); | 315 XDestroyWindow(xdisplay(), xid2); |
306 } | 316 } |
307 | 317 |
308 // Test that non-rectangular windows are properly handled. | 318 // Test that non-rectangular windows are properly handled. |
309 // Flaky on Linux. http://crbug.com/388241 | 319 TEST_F(X11TopmostWindowFinderTest, NonRectangular) { |
310 TEST_F(X11TopmostWindowFinderTest, DISABLED_NonRectangular) { | |
311 if (!ui::IsShapeExtensionAvailable()) | 320 if (!ui::IsShapeExtensionAvailable()) |
312 return; | 321 return; |
313 | 322 |
314 scoped_ptr<Widget> widget1( | 323 scoped_ptr<Widget> widget1( |
315 CreateAndShowWidget(gfx::Rect(100, 100, 100, 100))); | 324 CreateAndShowWidget(gfx::Rect(100, 100, 100, 100))); |
316 XID xid1 = widget1->GetNativeWindow()->GetHost()->GetAcceleratedWidget(); | 325 XID xid1 = widget1->GetNativeWindow()->GetHost()->GetAcceleratedWidget(); |
317 SkRegion* skregion1 = new SkRegion; | 326 SkRegion* skregion1 = new SkRegion; |
318 skregion1->op(SkIRect::MakeXYWH(0, 10, 10, 90), SkRegion::kUnion_Op); | 327 skregion1->op(SkIRect::MakeXYWH(0, 10, 10, 90), SkRegion::kUnion_Op); |
319 skregion1->op(SkIRect::MakeXYWH(10, 0, 90, 100), SkRegion::kUnion_Op); | 328 skregion1->op(SkIRect::MakeXYWH(10, 0, 90, 100), SkRegion::kUnion_Op); |
320 // Widget takes ownership of |skregion1|. | 329 // Widget takes ownership of |skregion1|. |
(...skipping 21 matching lines...) Expand all Loading... |
342 // because the code path is different. | 351 // because the code path is different. |
343 EXPECT_EQ(xid2, FindTopmostXWindowAt(305, 120)); | 352 EXPECT_EQ(xid2, FindTopmostXWindowAt(305, 120)); |
344 EXPECT_NE(xid1, FindTopmostXWindowAt(305, 105)); | 353 EXPECT_NE(xid1, FindTopmostXWindowAt(305, 105)); |
345 EXPECT_NE(xid2, FindTopmostXWindowAt(305, 105)); | 354 EXPECT_NE(xid2, FindTopmostXWindowAt(305, 105)); |
346 | 355 |
347 XDestroyWindow(xdisplay(), xid2); | 356 XDestroyWindow(xdisplay(), xid2); |
348 } | 357 } |
349 | 358 |
350 // Test that the TopmostWindowFinder finds windows which belong to menus | 359 // Test that the TopmostWindowFinder finds windows which belong to menus |
351 // (which may or may not belong to Chrome). | 360 // (which may or may not belong to Chrome). |
352 // Flaky on Linux. http://crbug.com/388241 | 361 TEST_F(X11TopmostWindowFinderTest, Menu) { |
353 TEST_F(X11TopmostWindowFinderTest, DISABLED_Menu) { | |
354 XID xid = CreateAndShowXWindow(gfx::Rect(100, 100, 100, 100)); | 362 XID xid = CreateAndShowXWindow(gfx::Rect(100, 100, 100, 100)); |
355 | 363 |
356 XID root = DefaultRootWindow(xdisplay()); | 364 XID root = DefaultRootWindow(xdisplay()); |
357 XSetWindowAttributes swa; | 365 XSetWindowAttributes swa; |
358 swa.override_redirect = True; | 366 swa.override_redirect = True; |
359 XID menu_xid = XCreateWindow(xdisplay(), | 367 XID menu_xid = XCreateWindow(xdisplay(), |
360 root, | 368 root, |
361 0, 0, 1, 1, | 369 0, 0, 1, 1, |
362 0, // border width | 370 0, // border width |
363 CopyFromParent, // depth | 371 CopyFromParent, // depth |
(...skipping 20 matching lines...) Expand all Loading... |
384 | 392 |
385 EXPECT_EQ(xid, FindTopmostXWindowAt(110, 110)); | 393 EXPECT_EQ(xid, FindTopmostXWindowAt(110, 110)); |
386 EXPECT_EQ(menu_xid, FindTopmostXWindowAt(150, 120)); | 394 EXPECT_EQ(menu_xid, FindTopmostXWindowAt(150, 120)); |
387 EXPECT_EQ(menu_xid, FindTopmostXWindowAt(210, 120)); | 395 EXPECT_EQ(menu_xid, FindTopmostXWindowAt(210, 120)); |
388 | 396 |
389 XDestroyWindow(xdisplay(), xid); | 397 XDestroyWindow(xdisplay(), xid); |
390 XDestroyWindow(xdisplay(), menu_xid); | 398 XDestroyWindow(xdisplay(), menu_xid); |
391 } | 399 } |
392 | 400 |
393 } // namespace views | 401 } // namespace views |
OLD | NEW |