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

Side by Side Diff: ui/views/mus/window_manager_connection_unittest.cc

Issue 2463753003: Changes ScreenMusDelegate::GetWindowAtScreenPoint to return aura::Window (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « ui/views/mus/window_manager_connection.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/mus/window_manager_connection.h" 5 #include "ui/views/mus/window_manager_connection.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "services/ui/public/cpp/window.h" 8 #include "services/ui/public/cpp/window.h"
9 #include "services/ui/public/cpp/window_private.h" 9 #include "services/ui/public/cpp/window_private.h"
10 #include "services/ui/public/cpp/window_tree_client.h" 10 #include "services/ui/public/cpp/window_tree_client.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/views/mus/screen_mus.h" 12 #include "ui/views/mus/screen_mus.h"
13 #include "ui/views/mus/test_utils.h" 13 #include "ui/views/mus/test_utils.h"
14 #include "ui/views/test/scoped_views_test_helper.h" 14 #include "ui/views/test/scoped_views_test_helper.h"
15 15
16 namespace views { 16 namespace views {
17 namespace { 17 namespace {
18 18
19 class WindowManagerConnectionTest : public testing::Test { 19 class WindowManagerConnectionTest : public testing::Test {
20 public: 20 public:
21 WindowManagerConnectionTest() : message_loop_(base::MessageLoop::TYPE_UI) {} 21 WindowManagerConnectionTest() : message_loop_(base::MessageLoop::TYPE_UI) {}
22 ~WindowManagerConnectionTest() override {} 22 ~WindowManagerConnectionTest() override {}
23 23
24 WindowManagerConnection* connection() { 24 WindowManagerConnection* connection() {
25 return WindowManagerConnection::Get(); 25 return WindowManagerConnection::Get();
26 } 26 }
27 27
28 ScreenMusDelegate* screen_mus_delegate() { return connection(); } 28 ScreenMusDelegate* screen_mus_delegate() { return connection(); }
29 29
30 ui::Window* GetWindowAtScreenPoint(const gfx::Point& point) {
31 return test::WindowManagerConnectionTestApi(connection())
32 .GetUiWindowAtScreenPoint(point);
33 }
34
30 private: 35 private:
31 base::MessageLoop message_loop_; 36 base::MessageLoop message_loop_;
32 ScopedViewsTestHelper helper_; 37 ScopedViewsTestHelper helper_;
33 38
34 DISALLOW_COPY_AND_ASSIGN(WindowManagerConnectionTest); 39 DISALLOW_COPY_AND_ASSIGN(WindowManagerConnectionTest);
35 }; 40 };
36 41
37 TEST_F(WindowManagerConnectionTest, GetWindowAtScreenPointRecurse) { 42 TEST_F(WindowManagerConnectionTest, GetWindowAtScreenPointRecurse) {
38 ui::Window* one = connection()->client()->NewTopLevelWindow(nullptr); 43 ui::Window* one = connection()->client()->NewTopLevelWindow(nullptr);
39 one->SetBounds(gfx::Rect(0, 0, 100, 100)); 44 one->SetBounds(gfx::Rect(0, 0, 100, 100));
40 one->SetVisible(true); 45 one->SetVisible(true);
41 46
42 std::vector<display::Display> displays = 47 std::vector<display::Display> displays =
43 display::Screen::GetScreen()->GetAllDisplays(); 48 display::Screen::GetScreen()->GetAllDisplays();
44 ASSERT_GE(displays.size(), 1u); 49 ASSERT_GE(displays.size(), 1u);
45 ui::WindowPrivate(one).LocalSetDisplay(displays[0].id()); 50 ui::WindowPrivate(one).LocalSetDisplay(displays[0].id());
46 51
47 ui::Window* two = connection()->client()->NewWindow(); 52 ui::Window* two = connection()->client()->NewWindow();
48 one->AddChild(two); 53 one->AddChild(two);
49 two->SetBounds(gfx::Rect(10, 10, 80, 80)); 54 two->SetBounds(gfx::Rect(10, 10, 80, 80));
50 two->SetVisible(true); 55 two->SetVisible(true);
51 56
52 // Ensure that we recurse down to the second window. 57 // Ensure that we recurse down to the second window.
53 EXPECT_EQ(two, 58 EXPECT_EQ(two, GetWindowAtScreenPoint(gfx::Point(50, 50)));
54 screen_mus_delegate()->GetWindowAtScreenPoint(gfx::Point(50, 50)));
55 } 59 }
56 60
57 TEST_F(WindowManagerConnectionTest, GetWindowAtScreenPointRecurseButIgnore) { 61 TEST_F(WindowManagerConnectionTest, GetWindowAtScreenPointRecurseButIgnore) {
58 ui::Window* one = connection()->client()->NewTopLevelWindow(nullptr); 62 ui::Window* one = connection()->client()->NewTopLevelWindow(nullptr);
59 one->SetBounds(gfx::Rect(0, 0, 100, 100)); 63 one->SetBounds(gfx::Rect(0, 0, 100, 100));
60 one->SetVisible(true); 64 one->SetVisible(true);
61 65
62 std::vector<display::Display> displays = 66 std::vector<display::Display> displays =
63 display::Screen::GetScreen()->GetAllDisplays(); 67 display::Screen::GetScreen()->GetAllDisplays();
64 ASSERT_GE(displays.size(), 1u); 68 ASSERT_GE(displays.size(), 1u);
65 ui::WindowPrivate(one).LocalSetDisplay(displays[0].id()); 69 ui::WindowPrivate(one).LocalSetDisplay(displays[0].id());
66 70
67 ui::Window* two = connection()->client()->NewWindow(); 71 ui::Window* two = connection()->client()->NewWindow();
68 one->AddChild(two); 72 one->AddChild(two);
69 two->SetBounds(gfx::Rect(5, 5, 10, 10)); 73 two->SetBounds(gfx::Rect(5, 5, 10, 10));
70 two->SetVisible(true); 74 two->SetVisible(true);
71 75
72 // We'll recurse down, but we'll use the parent anyway because the children 76 // We'll recurse down, but we'll use the parent anyway because the children
73 // don't match the bounds. 77 // don't match the bounds.
74 EXPECT_EQ(one, 78 EXPECT_EQ(one, GetWindowAtScreenPoint(gfx::Point(50, 50)));
75 screen_mus_delegate()->GetWindowAtScreenPoint(gfx::Point(50, 50)));
76 } 79 }
77 80
78 TEST_F(WindowManagerConnectionTest, GetWindowAtScreenPointDisplayOffset) { 81 TEST_F(WindowManagerConnectionTest, GetWindowAtScreenPointDisplayOffset) {
79 ui::Window* one = connection()->client()->NewTopLevelWindow(nullptr); 82 ui::Window* one = connection()->client()->NewTopLevelWindow(nullptr);
80 one->SetBounds(gfx::Rect(5, 5, 5, 5)); 83 one->SetBounds(gfx::Rect(5, 5, 5, 5));
81 one->SetVisible(true); 84 one->SetVisible(true);
82 85
83 std::vector<display::Display> displays = 86 std::vector<display::Display> displays =
84 display::Screen::GetScreen()->GetAllDisplays(); 87 display::Screen::GetScreen()->GetAllDisplays();
85 ASSERT_GE(displays.size(), 1u); 88 ASSERT_GE(displays.size(), 1u);
86 ui::WindowPrivate(one).LocalSetDisplay(displays[0].id()); 89 ui::WindowPrivate(one).LocalSetDisplay(displays[0].id());
87 90
88 // Make the first display offset by 50. 91 // Make the first display offset by 50.
89 test::WindowManagerConnectionTestApi api(connection()); 92 test::WindowManagerConnectionTestApi api(connection());
90 api.screen()->display_list()->FindDisplayById(displays[0].id())-> 93 api.screen()->display_list()->FindDisplayById(displays[0].id())->
91 set_bounds(gfx::Rect(44, 44, 50, 50)); 94 set_bounds(gfx::Rect(44, 44, 50, 50));
92 95
93 EXPECT_EQ(one, 96 EXPECT_EQ(one, GetWindowAtScreenPoint(gfx::Point(50, 50)));
94 screen_mus_delegate()->GetWindowAtScreenPoint(gfx::Point(50, 50)));
95 } 97 }
96 98
97 TEST_F(WindowManagerConnectionTest, IgnoresHiddenWindows) { 99 TEST_F(WindowManagerConnectionTest, IgnoresHiddenWindows) {
98 // Hide the one window. 100 // Hide the one window.
99 ui::Window* one = connection()->client()->NewTopLevelWindow(nullptr); 101 ui::Window* one = connection()->client()->NewTopLevelWindow(nullptr);
100 one->SetBounds(gfx::Rect(0, 0, 100, 100)); 102 one->SetBounds(gfx::Rect(0, 0, 100, 100));
101 one->SetVisible(false); 103 one->SetVisible(false);
102 104
103 std::vector<display::Display> displays = 105 std::vector<display::Display> displays =
104 display::Screen::GetScreen()->GetAllDisplays(); 106 display::Screen::GetScreen()->GetAllDisplays();
105 ASSERT_GE(displays.size(), 1u); 107 ASSERT_GE(displays.size(), 1u);
106 ui::WindowPrivate(one).LocalSetDisplay(displays[0].id()); 108 ui::WindowPrivate(one).LocalSetDisplay(displays[0].id());
107 109
108 EXPECT_EQ(nullptr, 110 EXPECT_EQ(nullptr, GetWindowAtScreenPoint(gfx::Point(50, 50)));
109 screen_mus_delegate()->GetWindowAtScreenPoint(gfx::Point(50, 50)));
110 } 111 }
111 112
112 } // namespace 113 } // namespace
113 } // namespace views 114 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/window_manager_connection.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698