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

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

Issue 2736943003: Start to decouple display::Display from ws::PlatformDisplay. (Closed)
Patch Set: Fix comments. Created 3 years, 9 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
« no previous file with comments | « services/ui/ws/display_manager.cc ('k') | services/ui/ws/platform_display.h » ('j') | 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "services/ui/common/types.h" 11 #include "services/ui/common/types.h"
12 #include "services/ui/common/util.h" 12 #include "services/ui/common/util.h"
13 #include "services/ui/display/viewport_metrics.h" 13 #include "services/ui/display/viewport_metrics.h"
14 #include "services/ui/public/interfaces/window_tree.mojom.h" 14 #include "services/ui/public/interfaces/window_tree.mojom.h"
15 #include "services/ui/ws/display_manager.h" 15 #include "services/ui/ws/display_manager.h"
16 #include "services/ui/ws/ids.h" 16 #include "services/ui/ws/ids.h"
17 #include "services/ui/ws/platform_display.h" 17 #include "services/ui/ws/platform_display.h"
18 #include "services/ui/ws/platform_display_factory.h" 18 #include "services/ui/ws/platform_display_factory.h"
19 #include "services/ui/ws/server_window.h" 19 #include "services/ui/ws/server_window.h"
20 #include "services/ui/ws/test_utils.h" 20 #include "services/ui/ws/test_utils.h"
21 #include "services/ui/ws/window_manager_display_root.h" 21 #include "services/ui/ws/window_manager_display_root.h"
22 #include "services/ui/ws/window_manager_state.h" 22 #include "services/ui/ws/window_manager_state.h"
23 #include "services/ui/ws/window_server.h" 23 #include "services/ui/ws/window_server.h"
24 #include "services/ui/ws/window_server_delegate.h" 24 #include "services/ui/ws/window_server_delegate.h"
25 #include "services/ui/ws/window_tree.h" 25 #include "services/ui/ws/window_tree.h"
26 #include "services/ui/ws/window_tree_binding.h" 26 #include "services/ui/ws/window_tree_binding.h"
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/display/display.h"
28 #include "ui/events/event.h" 29 #include "ui/events/event.h"
29 #include "ui/gfx/geometry/rect.h" 30 #include "ui/gfx/geometry/rect.h"
30 31
31 using display::ViewportMetrics;
32
33 namespace ui { 32 namespace ui {
34 namespace ws { 33 namespace ws {
35 namespace test { 34 namespace test {
36 namespace { 35 namespace {
37 36
38 const UserId kTestId1 = "2"; 37 const UserId kTestId1 = "2";
39 const UserId kTestId2 = "21"; 38 const UserId kTestId2 = "21";
40 39
41 ClientWindowId ClientWindowIdForFirstRoot(WindowTree* tree) { 40 ClientWindowId ClientWindowIdForFirstRoot(WindowTree* tree) {
42 if (tree->roots().empty()) 41 if (tree->roots().empty())
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 private: 115 private:
117 WindowServerTestHelper ws_test_helper_; 116 WindowServerTestHelper ws_test_helper_;
118 TestScreenManager screen_manager_; 117 TestScreenManager screen_manager_;
119 118
120 DISALLOW_COPY_AND_ASSIGN(DisplayTest); 119 DISALLOW_COPY_AND_ASSIGN(DisplayTest);
121 }; 120 };
122 121
123 TEST_F(DisplayTest, CreateDisplay) { 122 TEST_F(DisplayTest, CreateDisplay) {
124 AddWindowManager(window_server(), kTestId1); 123 AddWindowManager(window_server(), kTestId1);
125 const int64_t display_id = 124 const int64_t display_id =
126 screen_manager().AddDisplay(MakeViewportMetrics(0, 0, 1024, 768, 1.0f)); 125 screen_manager().AddDisplay(MakeDisplay(0, 0, 1024, 768, 1.0f));
127 126
128 ASSERT_EQ(1u, display_manager()->displays().size()); 127 ASSERT_EQ(1u, display_manager()->displays().size());
129 Display* display = display_manager()->GetDisplayById(display_id); 128 Display* display = display_manager()->GetDisplayById(display_id);
130 129
131 // Display should have root window with correct size. 130 // Display should have root window with correct size.
132 ASSERT_NE(nullptr, display->root_window()); 131 ASSERT_NE(nullptr, display->root_window());
133 EXPECT_EQ("0,0 1024x768", display->root_window()->bounds().ToString()); 132 EXPECT_EQ("0,0 1024x768", display->root_window()->bounds().ToString());
134 133
135 // Display should have a WM root window with the correct size too. 134 // Display should have a WM root window with the correct size too.
136 EXPECT_EQ(1u, display->num_window_manager_states()); 135 EXPECT_EQ(1u, display->num_window_manager_states());
137 WindowManagerDisplayRoot* root1 = 136 WindowManagerDisplayRoot* root1 =
138 display->GetWindowManagerDisplayRootForUser(kTestId1); 137 display->GetWindowManagerDisplayRootForUser(kTestId1);
139 ASSERT_NE(nullptr, root1); 138 ASSERT_NE(nullptr, root1);
140 ASSERT_NE(nullptr, root1->root()); 139 ASSERT_NE(nullptr, root1->root());
141 EXPECT_EQ("0,0 1024x768", root1->root()->bounds().ToString()); 140 EXPECT_EQ("0,0 1024x768", root1->root()->bounds().ToString());
142 } 141 }
143 142
144 TEST_F(DisplayTest, CreateDisplayBeforeWM) { 143 TEST_F(DisplayTest, CreateDisplayBeforeWM) {
145 // Add one display, no WM exists yet. 144 // Add one display, no WM exists yet.
146 const int64_t display_id = 145 const int64_t display_id =
147 screen_manager().AddDisplay(MakeViewportMetrics(0, 0, 1024, 768, 1.0f)); 146 screen_manager().AddDisplay(MakeDisplay(0, 0, 1024, 768, 1.0f));
148 EXPECT_EQ(1u, display_manager()->displays().size()); 147 EXPECT_EQ(1u, display_manager()->displays().size());
149 148
150 Display* display = display_manager()->GetDisplayById(display_id); 149 Display* display = display_manager()->GetDisplayById(display_id);
151 150
152 // Display should have root window with correct size. 151 // Display should have root window with correct size.
153 ASSERT_NE(nullptr, display->root_window()); 152 ASSERT_NE(nullptr, display->root_window());
154 EXPECT_EQ("0,0 1024x768", display->root_window()->bounds().ToString()); 153 EXPECT_EQ("0,0 1024x768", display->root_window()->bounds().ToString());
155 154
156 // There should be no WM state for display yet. 155 // There should be no WM state for display yet.
157 EXPECT_EQ(0u, display->num_window_manager_states()); 156 EXPECT_EQ(0u, display->num_window_manager_states());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 ASSERT_NE(nullptr, root2); 189 ASSERT_NE(nullptr, root2);
191 190
192 // Verify the two WMs have different roots but with the same bounds. 191 // Verify the two WMs have different roots but with the same bounds.
193 EXPECT_NE(root1, root2); 192 EXPECT_NE(root1, root2);
194 EXPECT_NE(root1->root(), root2->root()); 193 EXPECT_NE(root1->root(), root2->root());
195 EXPECT_EQ(root1->root()->bounds(), root2->root()->bounds()); 194 EXPECT_EQ(root1->root()->bounds(), root2->root()->bounds());
196 } 195 }
197 196
198 TEST_F(DisplayTest, CreateDisplayWithDeviceScaleFactor) { 197 TEST_F(DisplayTest, CreateDisplayWithDeviceScaleFactor) {
199 // The display bounds should be the pixel_size / device_scale_factor. 198 // The display bounds should be the pixel_size / device_scale_factor.
200 const ViewportMetrics metrics = MakeViewportMetrics(0, 0, 1024, 768, 2.0f); 199 display::Display display = MakeDisplay(0, 0, 1024, 768, 2.0f);
201 EXPECT_EQ("0,0 512x384", metrics.bounds.ToString()); 200 EXPECT_EQ("0,0 512x384", display.bounds().ToString());
202 EXPECT_EQ("1024x768", metrics.pixel_size.ToString());
203 201
204 const int64_t display_id = screen_manager().AddDisplay(metrics); 202 const int64_t display_id = screen_manager().AddDisplay(display);
205 Display* display = display_manager()->GetDisplayById(display_id); 203 display.set_id(display_id);
204 Display* ws_display = display_manager()->GetDisplayById(display_id);
206 205
207 // The root ServerWindow bounds should be in PP. 206 // The root ServerWindow bounds should be in PP.
208 EXPECT_EQ("0,0 1024x768", display->root_window()->bounds().ToString()); 207 EXPECT_EQ("0,0 1024x768", ws_display->root_window()->bounds().ToString());
209 208
210 ViewportMetrics modified_metrics = metrics; 209 // Modify the display work area to be 48 DIPs smaller.
211 modified_metrics.work_area.set_height(metrics.work_area.height() - 48); 210 display::Display modified_display = display;
212 screen_manager().ModifyDisplay(display_id, modified_metrics); 211 gfx::Rect modified_work_area = display.work_area();
212 modified_work_area.set_height(modified_work_area.height() - 48);
213 modified_display.set_work_area(modified_work_area);
214 screen_manager().ModifyDisplay(modified_display);
215
216 // The display work area should have changed.
217 EXPECT_EQ("0,0 512x336", ws_display->GetDisplay().work_area().ToString());
213 218
214 // The root ServerWindow should still be in PP after updating the work area. 219 // The root ServerWindow should still be in PP after updating the work area.
215 EXPECT_EQ("0,0 1024x768", display->root_window()->bounds().ToString()); 220 EXPECT_EQ("0,0 1024x768", ws_display->root_window()->bounds().ToString());
216 } 221 }
217 222
218 TEST_F(DisplayTest, Destruction) { 223 TEST_F(DisplayTest, Destruction) {
219 AddWindowManager(window_server(), kTestId1); 224 AddWindowManager(window_server(), kTestId1);
220 225
221 int64_t display_id = screen_manager().AddDisplay(); 226 int64_t display_id = screen_manager().AddDisplay();
222 227
223 // Add a second WM. 228 // Add a second WM.
224 AddWindowManager(window_server(), kTestId2); 229 AddWindowManager(window_server(), kTestId2);
225 ASSERT_EQ(1u, display_manager()->displays().size()); 230 ASSERT_EQ(1u, display_manager()->displays().size());
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 ASSERT_EQ(0u, tree_client->tracker()->changes()->size()); 422 ASSERT_EQ(0u, tree_client->tracker()->changes()->size());
418 423
419 // The window should be destroyed when the client says so. 424 // The window should be destroyed when the client says so.
420 ASSERT_TRUE(tree->DeleteWindow(secondary_root_id)); 425 ASSERT_TRUE(tree->DeleteWindow(secondary_root_id));
421 EXPECT_TRUE(secondary_root_destroyed); 426 EXPECT_TRUE(secondary_root_destroyed);
422 } 427 }
423 428
424 } // namespace test 429 } // namespace test
425 } // namespace ws 430 } // namespace ws
426 } // namespace ui 431 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/display_manager.cc ('k') | services/ui/ws/platform_display.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698