Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: ui/views/widget/desktop_aura/desktop_window_tree_host_x11_unittest.cc

Issue 264713007: Add unittests for X11TopmostWindowFinder (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <vector> 5 #include <vector>
6 6
7 #include <X11/extensions/shape.h> 7 #include <X11/extensions/shape.h>
8 #include <X11/Xlib.h> 8 #include <X11/Xlib.h>
9 9
10 // Get rid of X11 macros which conflict with gtest. 10 // Get rid of X11 macros which conflict with gtest.
11 #undef Bool 11 #undef Bool
12 #undef None 12 #undef None
13 13
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/run_loop.h"
16 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
17 #include "ui/aura/window_tree_host.h" 16 #include "ui/aura/window_tree_host.h"
18 #include "ui/base/hit_test.h" 17 #include "ui/base/hit_test.h"
19 #include "ui/base/x/x11_util.h" 18 #include "ui/base/x/x11_util.h"
20 #include "ui/events/platform/platform_event_dispatcher.h"
21 #include "ui/events/platform/platform_event_source.h"
22 #include "ui/events/platform/scoped_event_dispatcher.h"
23 #include "ui/events/platform/x11/x11_event_source.h" 19 #include "ui/events/platform/x11/x11_event_source.h"
24 #include "ui/gfx/path.h" 20 #include "ui/gfx/path.h"
25 #include "ui/gfx/point.h" 21 #include "ui/gfx/point.h"
26 #include "ui/gfx/rect.h" 22 #include "ui/gfx/rect.h"
27 #include "ui/gfx/x/x11_atom_cache.h" 23 #include "ui/gfx/x/x11_atom_cache.h"
28 #include "ui/views/test/views_test_base.h" 24 #include "ui/views/test/views_test_base.h"
25 #include "ui/views/test/x11_property_change_waiter.h"
29 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 26 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
30 #include "ui/views/widget/widget_delegate.h" 27 #include "ui/views/widget/widget_delegate.h"
31 #include "ui/views/window/non_client_view.h" 28 #include "ui/views/window/non_client_view.h"
32 29
33 namespace views { 30 namespace views {
34 31
35 namespace { 32 namespace {
36 33
37 // Blocks till |window| becomes maximized. 34 // Blocks till |window| becomes maximized.
38 class MaximizeWaiter : public ui::PlatformEventDispatcher { 35 class MaximizeWaiter : public X11PropertyChangeWaiter {
39 public: 36 public:
40 explicit MaximizeWaiter(XID window) 37 explicit MaximizeWaiter(XID window)
41 : xwindow_(window), 38 : X11PropertyChangeWaiter(window, "_NET_WM_STATE") {
42 wait_(true) {
43 const char* kAtomsToCache[] = {
44 "_NET_WM_STATE",
45 "_NET_WM_STATE_MAXIMIZED_VERT",
46 NULL
47 };
48 atom_cache_.reset(new ui::X11AtomCache(gfx::GetXDisplay(), kAtomsToCache));
49 39
50 // Override the dispatcher so that we get events before 40 const char* kAtomsToCache[] = {
51 // DesktopWindowTreeHostX11 does. We must do this because 41 "_NET_WM_STATE_MAXIMIZED_VERT",
52 // DesktopWindowTreeHostX11 stops propagation. 42 NULL
53 dispatcher_ = ui::PlatformEventSource::GetInstance()-> 43 };
54 OverrideDispatcher(this).Pass(); 44 atom_cache_.reset(new ui::X11AtomCache(gfx::GetXDisplay(), kAtomsToCache));
55 } 45 }
56 46
57 virtual ~MaximizeWaiter() { 47 virtual ~MaximizeWaiter() {
58 } 48 }
59 49
60 void Wait() { 50 private:
61 if (wait_) { 51 // X11PropertyChangeWaiter:
62 base::RunLoop run_loop; 52 virtual bool ShouldKeepOnWaiting(const ui::PlatformEvent& event) OVERRIDE {
63 quit_closure_ = run_loop.QuitClosure(); 53 std::vector<Atom> wm_states;
64 run_loop.Run(); 54 if (ui::GetAtomArrayProperty(xwindow(), "_NET_WM_STATE", &wm_states)) {
65 } 55 std::vector<Atom>::iterator it = std::find(
66 dispatcher_.reset(); 56 wm_states.begin(),
67 } 57 wm_states.end(),
58 atom_cache_->GetAtom("_NET_WM_STATE_MAXIMIZED_VERT"));
59 return it == wm_states.end();
60 }
61 return true;
62 }
68 63
69 virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE { 64 scoped_ptr<ui::X11AtomCache> atom_cache_;
70 NOTREACHED();
71 return true;
72 }
73 65
74 virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE { 66 DISALLOW_COPY_AND_ASSIGN(MaximizeWaiter);
75 if (event->type != PropertyNotify ||
76 event->xproperty.window != xwindow_ ||
77 event->xproperty.atom != atom_cache_->GetAtom("_NET_WM_STATE")) {
78 return ui::POST_DISPATCH_PERFORM_DEFAULT;
79 }
80
81 std::vector<Atom> wm_states;
82 if (!ui::GetAtomArrayProperty(xwindow_, "_NET_WM_STATE", &wm_states))
83 return ui::POST_DISPATCH_PERFORM_DEFAULT;
84
85 std::vector<Atom>::iterator it = std::find(
86 wm_states.begin(),
87 wm_states.end(),
88 atom_cache_->GetAtom("_NET_WM_STATE_MAXIMIZED_VERT"));
89 if (it == wm_states.end())
90 return ui::POST_DISPATCH_PERFORM_DEFAULT;
91
92 wait_ = false;
93 if (!quit_closure_.is_null())
94 quit_closure_.Run();
95 return ui::POST_DISPATCH_PERFORM_DEFAULT;
96 }
97
98 // The window we are waiting to get maximized.
99 XID xwindow_;
100
101 // Whether Wait() should block.
102 bool wait_;
103
104 // Ends the run loop.
105 base::Closure quit_closure_;
106
107 scoped_ptr<ui::ScopedEventDispatcher> dispatcher_;
108
109 scoped_ptr<ui::X11AtomCache> atom_cache_;
110
111 DISALLOW_COPY_AND_ASSIGN(MaximizeWaiter);
112 }; 67 };
113 68
114 // A NonClientFrameView with a window mask with the bottom right corner cut out. 69 // A NonClientFrameView with a window mask with the bottom right corner cut out.
115 class ShapedNonClientFrameView : public NonClientFrameView { 70 class ShapedNonClientFrameView : public NonClientFrameView {
116 public: 71 public:
117 explicit ShapedNonClientFrameView() { 72 explicit ShapedNonClientFrameView() {
118 } 73 }
119 74
120 virtual ~ShapedNonClientFrameView() { 75 virtual ~ShapedNonClientFrameView() {
121 } 76 }
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 widget2->SetBounds(gfx::Rect(100, 100, 200, 200)); 292 widget2->SetBounds(gfx::Rect(100, 100, 200, 200));
338 shape_rects = GetShapeRects(xid2); 293 shape_rects = GetShapeRects(xid2);
339 ASSERT_FALSE(shape_rects.empty()); 294 ASSERT_FALSE(shape_rects.empty());
340 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 5, 5)); 295 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 5, 5));
341 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 15, 5)); 296 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 15, 5));
342 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 15)); 297 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 15));
343 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 105, 15)); 298 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 105, 15));
344 } 299 }
345 300
346 } // namespace views 301 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698