| 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 <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 #include <X11/Xregion.h> | 8 #include <X11/Xregion.h> |
| 9 #include <X11/extensions/shape.h> | 9 #include <X11/extensions/shape.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 // Get rid of X11 macros which conflict with gtest. | 16 // Get rid of X11 macros which conflict with gtest. |
| 17 #undef Bool | 17 #undef Bool |
| 18 #undef None | 18 #undef None |
| 19 | 19 |
| 20 #include "base/macros.h" | 20 #include "base/macros.h" |
| 21 #include "base/path_service.h" | |
| 22 #include "third_party/skia/include/core/SkRect.h" | 21 #include "third_party/skia/include/core/SkRect.h" |
| 23 #include "third_party/skia/include/core/SkRegion.h" | 22 #include "third_party/skia/include/core/SkRegion.h" |
| 24 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" |
| 25 #include "ui/aura/window_tree_host.h" | 24 #include "ui/aura/window_tree_host.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | |
| 27 #include "ui/base/ui_base_paths.h" | |
| 28 #include "ui/events/platform/x11/x11_event_source.h" | 25 #include "ui/events/platform/x11/x11_event_source.h" |
| 29 #include "ui/gfx/path.h" | 26 #include "ui/gfx/path.h" |
| 30 #include "ui/gfx/path_x11.h" | 27 #include "ui/gfx/path_x11.h" |
| 31 #include "ui/gfx/x/x11_atom_cache.h" | 28 #include "ui/gfx/x/x11_atom_cache.h" |
| 32 #include "ui/gl/test/gl_surface_test_support.h" | 29 #include "ui/views/test/views_interactive_ui_test_base.h" |
| 33 #include "ui/views/test/views_test_base.h" | |
| 34 #include "ui/views/test/x11_property_change_waiter.h" | 30 #include "ui/views/test/x11_property_change_waiter.h" |
| 35 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 31 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 36 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" | 32 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" |
| 37 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
| 38 | 34 |
| 39 namespace views { | 35 namespace views { |
| 40 | 36 |
| 41 namespace { | 37 namespace { |
| 42 | 38 |
| 43 // Waits till |window| is minimized. | 39 // Waits till |window| is minimized. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 return false; | 99 return false; |
| 104 } | 100 } |
| 105 | 101 |
| 106 std::vector<XID> expected_windows_; | 102 std::vector<XID> expected_windows_; |
| 107 | 103 |
| 108 DISALLOW_COPY_AND_ASSIGN(StackingClientListWaiter); | 104 DISALLOW_COPY_AND_ASSIGN(StackingClientListWaiter); |
| 109 }; | 105 }; |
| 110 | 106 |
| 111 } // namespace | 107 } // namespace |
| 112 | 108 |
| 113 class X11TopmostWindowFinderTest : public ViewsTestBase { | 109 class X11TopmostWindowFinderTest : public ViewsInteractiveUITestBase { |
| 114 public: | 110 public: |
| 115 X11TopmostWindowFinderTest() { | 111 X11TopmostWindowFinderTest() { |
| 116 } | 112 } |
| 117 | 113 |
| 118 ~X11TopmostWindowFinderTest() override {} | 114 ~X11TopmostWindowFinderTest() override {} |
| 119 | 115 |
| 120 // Creates and shows a Widget with |bounds|. The caller takes ownership of | 116 // Creates and shows a Widget with |bounds|. The caller takes ownership of |
| 121 // the returned widget. | 117 // the returned widget. |
| 122 std::unique_ptr<Widget> CreateAndShowWidget(const gfx::Rect& bounds) { | 118 std::unique_ptr<Widget> CreateAndShowWidget(const gfx::Rect& bounds) { |
| 123 std::unique_ptr<Widget> toplevel(new Widget); | 119 std::unique_ptr<Widget> toplevel(new Widget); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 int screen_x, | 182 int screen_x, |
| 187 int screen_y, | 183 int screen_y, |
| 188 aura::Window* ignore_window) { | 184 aura::Window* ignore_window) { |
| 189 std::set<aura::Window*> ignore; | 185 std::set<aura::Window*> ignore; |
| 190 ignore.insert(ignore_window); | 186 ignore.insert(ignore_window); |
| 191 X11TopmostWindowFinder finder; | 187 X11TopmostWindowFinder finder; |
| 192 return finder.FindLocalProcessWindowAt(gfx::Point(screen_x, screen_y), | 188 return finder.FindLocalProcessWindowAt(gfx::Point(screen_x, screen_y), |
| 193 ignore); | 189 ignore); |
| 194 } | 190 } |
| 195 | 191 |
| 196 static void SetUpTestCase() { | 192 // ViewsInteractiveUITestBase: |
| 197 gl::GLSurfaceTestSupport::InitializeOneOff(); | |
| 198 ui::RegisterPathProvider(); | |
| 199 base::FilePath ui_test_pak_path; | |
| 200 ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); | |
| 201 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); | |
| 202 } | |
| 203 | |
| 204 // ViewsTestBase: | |
| 205 void SetUp() override { | 193 void SetUp() override { |
| 206 ViewsTestBase::SetUp(); | 194 ViewsInteractiveUITestBase::SetUp(); |
| 207 | 195 |
| 208 // Make X11 synchronous for our display connection. This does not force the | 196 // Make X11 synchronous for our display connection. This does not force the |
| 209 // window manager to behave synchronously. | 197 // window manager to behave synchronously. |
| 210 XSynchronize(xdisplay(), True); | 198 XSynchronize(xdisplay(), True); |
| 211 | 199 |
| 212 // Ensure that the X11DesktopHandler exists. The X11DesktopHandler is | 200 // Ensure that the X11DesktopHandler exists. The X11DesktopHandler is |
| 213 // necessary to properly track menu windows. | 201 // necessary to properly track menu windows. |
| 214 X11DesktopHandler::get(); | 202 X11DesktopHandler::get(); |
| 215 } | 203 } |
| 216 | 204 |
| 217 void TearDown() override { | 205 void TearDown() override { |
| 218 XSynchronize(xdisplay(), False); | 206 XSynchronize(xdisplay(), False); |
| 219 ViewsTestBase::TearDown(); | 207 ViewsInteractiveUITestBase::TearDown(); |
| 220 } | 208 } |
| 221 | 209 |
| 222 private: | 210 private: |
| 223 DISALLOW_COPY_AND_ASSIGN(X11TopmostWindowFinderTest); | 211 DISALLOW_COPY_AND_ASSIGN(X11TopmostWindowFinderTest); |
| 224 }; | 212 }; |
| 225 | 213 |
| 226 TEST_F(X11TopmostWindowFinderTest, Basic) { | 214 TEST_F(X11TopmostWindowFinderTest, Basic) { |
| 227 // Avoid positioning test windows at 0x0 because window managers often have a | 215 // Avoid positioning test windows at 0x0 because window managers often have a |
| 228 // panel/launcher along one of the screen edges and do not allow windows to | 216 // panel/launcher along one of the screen edges and do not allow windows to |
| 229 // position themselves to overlap the panel/launcher. | 217 // position themselves to overlap the panel/launcher. |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 | 417 |
| 430 EXPECT_EQ(xid, FindTopmostXWindowAt(110, 110)); | 418 EXPECT_EQ(xid, FindTopmostXWindowAt(110, 110)); |
| 431 EXPECT_EQ(menu_xid, FindTopmostXWindowAt(150, 120)); | 419 EXPECT_EQ(menu_xid, FindTopmostXWindowAt(150, 120)); |
| 432 EXPECT_EQ(menu_xid, FindTopmostXWindowAt(210, 120)); | 420 EXPECT_EQ(menu_xid, FindTopmostXWindowAt(210, 120)); |
| 433 | 421 |
| 434 XDestroyWindow(xdisplay(), xid); | 422 XDestroyWindow(xdisplay(), xid); |
| 435 XDestroyWindow(xdisplay(), menu_xid); | 423 XDestroyWindow(xdisplay(), menu_xid); |
| 436 } | 424 } |
| 437 | 425 |
| 438 } // namespace views | 426 } // namespace views |
| OLD | NEW |