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

Side by Side Diff: ui/views/widget/desktop_aura/desktop_screen_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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/desktop_screen_x11.h" 5 #include "ui/views/widget/desktop_aura/desktop_screen_x11.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h"
10 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/aura/client/aura_constants.h" 9 #include "ui/aura/client/aura_constants.h"
12 #include "ui/aura/test/event_generator.h" 10 #include "ui/aura/test/event_generator.h"
13 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
14 #include "ui/aura/window_event_dispatcher.h" 12 #include "ui/aura/window_event_dispatcher.h"
15 #include "ui/aura/window_tree_host.h"
16 #include "ui/base/hit_test.h" 13 #include "ui/base/hit_test.h"
17 #include "ui/base/x/x11_util.h" 14 #include "ui/base/x/x11_util.h"
18 #include "ui/events/platform/platform_event_dispatcher.h"
19 #include "ui/events/platform/platform_event_source.h"
20 #include "ui/gfx/display_observer.h" 15 #include "ui/gfx/display_observer.h"
21 #include "ui/gfx/x/x11_atom_cache.h"
22 #include "ui/gfx/x/x11_types.h" 16 #include "ui/gfx/x/x11_types.h"
23 #include "ui/views/test/views_test_base.h" 17 #include "ui/views/test/views_test_base.h"
24 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 18 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
25 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" 19 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
26 20
27 namespace { 21 namespace {
28 22
29 // Class which allows for the designation of non-client component targets of 23 // Class which allows for the designation of non-client component targets of
30 // hit tests. 24 // hit tests.
31 class TestDesktopNativeWidgetAura : public views::DesktopNativeWidgetAura { 25 class TestDesktopNativeWidgetAura : public views::DesktopNativeWidgetAura {
(...skipping 18 matching lines...) Expand all
50 DISALLOW_COPY_AND_ASSIGN(TestDesktopNativeWidgetAura); 44 DISALLOW_COPY_AND_ASSIGN(TestDesktopNativeWidgetAura);
51 }; 45 };
52 46
53 } // namespace 47 } // namespace
54 48
55 namespace views { 49 namespace views {
56 50
57 const int64 kFirstDisplay = 5321829; 51 const int64 kFirstDisplay = 5321829;
58 const int64 kSecondDisplay = 928310; 52 const int64 kSecondDisplay = 928310;
59 53
60 // Class which waits till the X11 window associated with the widget passed into
61 // the constructor is activated. We cannot listen for the widget's activation
62 // because the _NET_ACTIVE_WINDOW property is changed after the widget is
63 // activated.
64 class ActivationWaiter : public ui::PlatformEventDispatcher {
65 public:
66 explicit ActivationWaiter(views::Widget* widget)
67 : x_root_window_(DefaultRootWindow(gfx::GetXDisplay())),
68 widget_xid_(0),
69 active_(false) {
70 const char* kAtomToCache[] = {
71 "_NET_ACTIVE_WINDOW",
72 NULL
73 };
74 atom_cache_.reset(new ui::X11AtomCache(gfx::GetXDisplay(), kAtomToCache));
75 widget_xid_ = widget->GetNativeWindow()->GetHost()->
76 GetAcceleratedWidget();
77 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
78 }
79
80 virtual ~ActivationWaiter() {
81 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
82 }
83
84 // Blocks till |widget_xid_| becomes active.
85 void Wait() {
86 if (active_)
87 return;
88 base::RunLoop run_loop;
89 quit_closure_ = run_loop.QuitClosure();
90 run_loop.Run();
91 }
92
93 // ui::PlatformEventDispatcher:
94 virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE {
95 return event->type == PropertyNotify &&
96 event->xproperty.window == x_root_window_;
97 }
98
99 virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE {
100 ::Window xid;
101 CHECK_EQ(PropertyNotify, event->type);
102 CHECK_EQ(x_root_window_, event->xproperty.window);
103
104 if (event->xproperty.atom == atom_cache_->GetAtom("_NET_ACTIVE_WINDOW") &&
105 ui::GetXIDProperty(x_root_window_, "_NET_ACTIVE_WINDOW", &xid) &&
106 xid == widget_xid_) {
107 active_ = true;
108 if (!quit_closure_.is_null())
109 quit_closure_.Run();
110 }
111 return ui::POST_DISPATCH_NONE;
112 }
113
114 private:
115 scoped_ptr<ui::X11AtomCache> atom_cache_;
116 ::Window x_root_window_;
117 ::Window widget_xid_;
118
119 bool active_;
120 base::Closure quit_closure_;
121
122 DISALLOW_COPY_AND_ASSIGN(ActivationWaiter);
123 };
124
125 class DesktopScreenX11Test : public views::ViewsTestBase, 54 class DesktopScreenX11Test : public views::ViewsTestBase,
126 public gfx::DisplayObserver { 55 public gfx::DisplayObserver {
127 public: 56 public:
128 DesktopScreenX11Test() {} 57 DesktopScreenX11Test() {}
129 virtual ~DesktopScreenX11Test() {} 58 virtual ~DesktopScreenX11Test() {}
130 59
131 // Overridden from testing::Test: 60 // Overridden from testing::Test:
132 virtual void SetUp() OVERRIDE { 61 virtual void SetUp() OVERRIDE {
133 ViewsTestBase::SetUp(); 62 ViewsTestBase::SetUp();
134 // Initialize the world to the single monitor case. 63 // Initialize the world to the single monitor case.
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 displays.push_back(gfx::Display(kFirstDisplay, 234 displays.push_back(gfx::Display(kFirstDisplay,
306 gfx::Rect(640, 0, 1024, 768))); 235 gfx::Rect(640, 0, 1024, 768)));
307 displays.push_back(gfx::Display(kSecondDisplay, gfx::Rect(0, 0, 640, 480))); 236 displays.push_back(gfx::Display(kSecondDisplay, gfx::Rect(0, 0, 640, 480)));
308 screen()->ProcessDisplayChange(displays); 237 screen()->ProcessDisplayChange(displays);
309 238
310 // The first display in the list is always the primary, even if other 239 // The first display in the list is always the primary, even if other
311 // displays are to the left in screen layout. 240 // displays are to the left in screen layout.
312 EXPECT_EQ(kFirstDisplay, screen()->GetPrimaryDisplay().id()); 241 EXPECT_EQ(kFirstDisplay, screen()->GetPrimaryDisplay().id());
313 } 242 }
314 243
315 TEST_F(DesktopScreenX11Test, GetWindowAtScreenPoint) {
316 if (!ui::WmSupportsHint(ui::GetAtom("_NET_ACTIVE_WINDOW")))
317 return;
318
319 Widget* window_one = BuildTopLevelDesktopWidget(gfx::Rect(110, 110, 10, 10),
320 false);
321 Widget* window_two = BuildTopLevelDesktopWidget(gfx::Rect(150, 150, 10, 10),
322 false);
323 Widget* window_three =
324 BuildTopLevelDesktopWidget(gfx::Rect(115, 115, 20, 20), false);
325
326 window_three->Show();
327 window_two->Show();
328 window_one->Show();
329
330 // Make sure the internal state of DesktopWindowTreeHostX11 is set up
331 // correctly.
332 ASSERT_EQ(3u, DesktopWindowTreeHostX11::GetAllOpenWindows().size());
333
334 EXPECT_EQ(window_one->GetNativeWindow(),
335 screen()->GetWindowAtScreenPoint(gfx::Point(117, 117)));
336 EXPECT_EQ(window_two->GetNativeWindow(),
337 screen()->GetWindowAtScreenPoint(gfx::Point(155, 155)));
338 EXPECT_EQ(NULL,
339 screen()->GetWindowAtScreenPoint(gfx::Point(200, 200)));
340
341 // Bring the third window in front. It overlaps with the first window.
342 // Hit-testing on the intersecting region should give the third window.
343 ActivationWaiter activation_waiter(window_three);
344 window_three->Activate();
345 activation_waiter.Wait();
346
347 EXPECT_EQ(window_three->GetNativeWindow(),
348 screen()->GetWindowAtScreenPoint(gfx::Point(117, 117)));
349
350 window_one->CloseNow();
351 window_two->CloseNow();
352 window_three->CloseNow();
353 }
354
355 TEST_F(DesktopScreenX11Test, GetDisplayNearestWindow) { 244 TEST_F(DesktopScreenX11Test, GetDisplayNearestWindow) {
356 // Set up a two monitor situation. 245 // Set up a two monitor situation.
357 std::vector<gfx::Display> displays; 246 std::vector<gfx::Display> displays;
358 displays.push_back(gfx::Display(kFirstDisplay, gfx::Rect(0, 0, 640, 480))); 247 displays.push_back(gfx::Display(kFirstDisplay, gfx::Rect(0, 0, 640, 480)));
359 displays.push_back(gfx::Display(kSecondDisplay, 248 displays.push_back(gfx::Display(kSecondDisplay,
360 gfx::Rect(640, 0, 1024, 768))); 249 gfx::Rect(640, 0, 1024, 768)));
361 screen()->ProcessDisplayChange(displays); 250 screen()->ProcessDisplayChange(displays);
362 251
363 Widget* window_one = BuildTopLevelDesktopWidget(gfx::Rect(10, 10, 10, 10), 252 Widget* window_one = BuildTopLevelDesktopWidget(gfx::Rect(10, 10, 10, 10),
364 false); 253 false);
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 screen()->ProcessDisplayChange(displays); 438 screen()->ProcessDisplayChange(displays);
550 EXPECT_EQ(2u, changed_display_.size()); 439 EXPECT_EQ(2u, changed_display_.size());
551 440
552 displays[0].set_device_scale_factor(1.f); 441 displays[0].set_device_scale_factor(1.f);
553 displays[1].set_device_scale_factor(1.f); 442 displays[1].set_device_scale_factor(1.f);
554 screen()->ProcessDisplayChange(displays); 443 screen()->ProcessDisplayChange(displays);
555 EXPECT_EQ(4u, changed_display_.size()); 444 EXPECT_EQ(4u, changed_display_.size());
556 } 445 }
557 446
558 } // namespace views 447 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/views.gyp ('k') | ui/views/widget/desktop_aura/desktop_window_tree_host_x11_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698