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

Side by Side Diff: services/ui/ws/window_finder_unittest.cc

Issue 2582823002: WIP: Surface Synchronization System
Patch Set: Only create ClientSurfaceEmbedder if window is visible. Trash it otherwise. Created 3 years, 11 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "services/ui/ws/window_finder.h" 5 #include "services/ui/ws/window_finder.h"
6 6
7 #include "services/ui/ws/server_window.h" 7 #include "services/ui/ws/server_window.h"
8 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h" 8 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h"
9 #include "services/ui/ws/server_window_compositor_frame_sink_manager_test_api.h" 9 #include "services/ui/ws/server_window_compositor_frame_sink_manager_test_api.h"
10 #include "services/ui/ws/test_server_window_delegate.h" 10 #include "services/ui/ws/test_server_window_delegate.h"
11 #include "services/ui/ws/window_finder.h" 11 #include "services/ui/ws/window_finder.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace ui { 14 namespace ui {
15 namespace ws { 15 namespace ws {
16 16
17 TEST(WindowFinderTest, FindDeepestVisibleWindow) { 17 TEST(WindowFinderTest, FindDeepestVisibleWindow) {
18 TestServerWindowDelegate window_delegate; 18 TestServerWindowDelegate window_delegate;
19 ServerWindow root(&window_delegate, WindowId(1, 2)); 19 ServerWindow root(&window_delegate, WindowId(1, 2));
20 window_delegate.set_root_window(&root); 20 window_delegate.set_root_window(&root);
21 root.SetVisible(true); 21 root.SetVisible(true);
22 root.SetBounds(gfx::Rect(0, 0, 100, 100)); 22 root.SetBounds(gfx::Rect(0, 0, 100, 100), cc::LocalFrameId());
23 23
24 ServerWindow child1(&window_delegate, WindowId(1, 3)); 24 ServerWindow child1(&window_delegate, WindowId(1, 3));
25 root.Add(&child1); 25 root.Add(&child1);
26 EnableHitTest(&child1); 26 EnableHitTest(&child1);
27 child1.SetVisible(true); 27 child1.SetVisible(true);
28 child1.SetBounds(gfx::Rect(10, 10, 20, 20)); 28 child1.SetBounds(gfx::Rect(10, 10, 20, 20), cc::LocalFrameId());
29 29
30 ServerWindow child2(&window_delegate, WindowId(1, 4)); 30 ServerWindow child2(&window_delegate, WindowId(1, 4));
31 root.Add(&child2); 31 root.Add(&child2);
32 EnableHitTest(&child2); 32 EnableHitTest(&child2);
33 child2.SetVisible(true); 33 child2.SetVisible(true);
34 child2.SetBounds(gfx::Rect(15, 15, 20, 20)); 34 child2.SetBounds(gfx::Rect(15, 15, 20, 20), cc::LocalFrameId());
35 35
36 gfx::Point local_point(16, 16); 36 gfx::Point local_point(16, 16);
37 EXPECT_EQ(&child2, FindDeepestVisibleWindowForEvents(&root, &local_point)); 37 EXPECT_EQ(&child2, FindDeepestVisibleWindowForEvents(&root, &local_point));
38 EXPECT_EQ(gfx::Point(1, 1), local_point); 38 EXPECT_EQ(gfx::Point(1, 1), local_point);
39 39
40 local_point.SetPoint(13, 14); 40 local_point.SetPoint(13, 14);
41 EXPECT_EQ(&child1, FindDeepestVisibleWindowForEvents(&root, &local_point)); 41 EXPECT_EQ(&child1, FindDeepestVisibleWindowForEvents(&root, &local_point));
42 EXPECT_EQ(gfx::Point(3, 4), local_point); 42 EXPECT_EQ(gfx::Point(3, 4), local_point);
43 43
44 local_point.SetPoint(13, 14); 44 local_point.SetPoint(13, 14);
45 child1.set_can_accept_events(false); 45 child1.set_can_accept_events(false);
46 EXPECT_EQ(nullptr, FindDeepestVisibleWindowForEvents(&root, &local_point)); 46 EXPECT_EQ(nullptr, FindDeepestVisibleWindowForEvents(&root, &local_point));
47 EXPECT_EQ(gfx::Point(13, 14), local_point); 47 EXPECT_EQ(gfx::Point(13, 14), local_point);
48 48
49 child2.set_extended_hit_test_region(gfx::Insets(10, 10, 10, 10)); 49 child2.set_extended_hit_test_region(gfx::Insets(10, 10, 10, 10));
50 local_point.SetPoint(13, 14); 50 local_point.SetPoint(13, 14);
51 EXPECT_EQ(&child2, FindDeepestVisibleWindowForEvents(&root, &local_point)); 51 EXPECT_EQ(&child2, FindDeepestVisibleWindowForEvents(&root, &local_point));
52 EXPECT_EQ(gfx::Point(-2, -1), local_point); 52 EXPECT_EQ(gfx::Point(-2, -1), local_point);
53 } 53 }
54 54
55 TEST(WindowFinderTest, FindDeepestVisibleWindowHitTestMask) { 55 TEST(WindowFinderTest, FindDeepestVisibleWindowHitTestMask) {
56 TestServerWindowDelegate window_delegate; 56 TestServerWindowDelegate window_delegate;
57 ServerWindow root(&window_delegate, WindowId(1, 2)); 57 ServerWindow root(&window_delegate, WindowId(1, 2));
58 window_delegate.set_root_window(&root); 58 window_delegate.set_root_window(&root);
59 EnableHitTest(&root); 59 EnableHitTest(&root);
60 root.SetVisible(true); 60 root.SetVisible(true);
61 root.SetBounds(gfx::Rect(0, 0, 100, 100)); 61 root.SetBounds(gfx::Rect(0, 0, 100, 100), cc::LocalFrameId());
62 62
63 ServerWindow child_with_mask(&window_delegate, WindowId(1, 4)); 63 ServerWindow child_with_mask(&window_delegate, WindowId(1, 4));
64 root.Add(&child_with_mask); 64 root.Add(&child_with_mask);
65 EnableHitTest(&child_with_mask); 65 EnableHitTest(&child_with_mask);
66 child_with_mask.SetVisible(true); 66 child_with_mask.SetVisible(true);
67 child_with_mask.SetBounds(gfx::Rect(10, 10, 20, 20)); 67 child_with_mask.SetBounds(gfx::Rect(10, 10, 20, 20), cc::LocalFrameId());
68 child_with_mask.SetHitTestMask(gfx::Rect(2, 2, 16, 16)); 68 child_with_mask.SetHitTestMask(gfx::Rect(2, 2, 16, 16));
69 69
70 // Test a point inside the window but outside the mask. 70 // Test a point inside the window but outside the mask.
71 gfx::Point point_outside_mask(11, 11); 71 gfx::Point point_outside_mask(11, 11);
72 EXPECT_EQ(&root, 72 EXPECT_EQ(&root,
73 FindDeepestVisibleWindowForEvents(&root, &point_outside_mask)); 73 FindDeepestVisibleWindowForEvents(&root, &point_outside_mask));
74 EXPECT_EQ(gfx::Point(11, 11), point_outside_mask); 74 EXPECT_EQ(gfx::Point(11, 11), point_outside_mask);
75 75
76 // Test a point inside the window and inside the mask. 76 // Test a point inside the window and inside the mask.
77 gfx::Point point_inside_mask(15, 15); 77 gfx::Point point_inside_mask(15, 15);
78 EXPECT_EQ(&child_with_mask, 78 EXPECT_EQ(&child_with_mask,
79 FindDeepestVisibleWindowForEvents(&root, &point_inside_mask)); 79 FindDeepestVisibleWindowForEvents(&root, &point_inside_mask));
80 EXPECT_EQ(gfx::Point(5, 5), point_inside_mask); 80 EXPECT_EQ(gfx::Point(5, 5), point_inside_mask);
81 } 81 }
82 82
83 TEST(WindowFinderTest, FindDeepestVisibleWindowForEventsOverNonTarget) { 83 TEST(WindowFinderTest, FindDeepestVisibleWindowForEventsOverNonTarget) {
84 TestServerWindowDelegate window_delegate; 84 TestServerWindowDelegate window_delegate;
85 ServerWindow root(&window_delegate, WindowId(1, 2)); 85 ServerWindow root(&window_delegate, WindowId(1, 2));
86 window_delegate.set_root_window(&root); 86 window_delegate.set_root_window(&root);
87 root.SetVisible(true); 87 root.SetVisible(true);
88 root.SetBounds(gfx::Rect(0, 0, 100, 100)); 88 root.SetBounds(gfx::Rect(0, 0, 100, 100), cc::LocalFrameId());
89 89
90 // Create two windows, |child1| and |child2|. The two overlap but |child2| is 90 // Create two windows, |child1| and |child2|. The two overlap but |child2| is
91 // not a valid event target. 91 // not a valid event target.
92 ServerWindow child1(&window_delegate, WindowId(1, 3)); 92 ServerWindow child1(&window_delegate, WindowId(1, 3));
93 root.Add(&child1); 93 root.Add(&child1);
94 EnableHitTest(&child1); 94 EnableHitTest(&child1);
95 child1.SetVisible(true); 95 child1.SetVisible(true);
96 child1.SetBounds(gfx::Rect(10, 10, 20, 20)); 96 child1.SetBounds(gfx::Rect(10, 10, 20, 20), cc::LocalFrameId());
97 97
98 ServerWindow child2(&window_delegate, WindowId(1, 4)); 98 ServerWindow child2(&window_delegate, WindowId(1, 4));
99 root.Add(&child2); 99 root.Add(&child2);
100 child2.SetVisible(true); 100 child2.SetVisible(true);
101 child2.SetBounds(gfx::Rect(15, 15, 20, 20)); 101 child2.SetBounds(gfx::Rect(15, 15, 20, 20), cc::LocalFrameId());
102 102
103 // |location_point| is over |child2| and |child1|, but as |child2| isn't a 103 // |location_point| is over |child2| and |child1|, but as |child2| isn't a
104 // valid event taret |child2| should be picked. 104 // valid event taret |child2| should be picked.
105 gfx::Point local_point(16, 16); 105 gfx::Point local_point(16, 16);
106 EXPECT_EQ(&child1, FindDeepestVisibleWindowForEvents(&root, &local_point)); 106 EXPECT_EQ(&child1, FindDeepestVisibleWindowForEvents(&root, &local_point));
107 EXPECT_EQ(gfx::Point(6, 6), local_point); 107 EXPECT_EQ(gfx::Point(6, 6), local_point);
108 } 108 }
109 109
110 } // namespace ws 110 } // namespace ws
111 } // namespace ui 111 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698