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

Side by Side Diff: ash/display/screen_position_controller_unittest.cc

Issue 2803933003: Adds ash_mus_unittests to FYI bot (Closed)
Patch Set: feedback Created 3 years, 8 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 | « ash/display/screen_ash_unittest.cc ('k') | ash/mus/bridge/wm_shell_mus.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/display/screen_position_controller.h" 5 #include "ash/display/screen_position_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "ash/public/cpp/shell_window_ids.h" 9 #include "ash/public/cpp/shell_window_ids.h"
10 #include "ash/screen_util.h" 10 #include "ash/screen_util.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/test/ash_test_base.h" 12 #include "ash/test/ash_test_base.h"
13 #include "ash/test/shell_test_api.h" 13 #include "ash/test/shell_test_api.h"
14 #include "ui/aura/env.h" 14 #include "ui/aura/env.h"
15 #include "ui/aura/test/test_window_delegate.h" 15 #include "ui/aura/test/test_window_delegate.h"
16 #include "ui/aura/window_tracker.h" 16 #include "ui/aura/window_tracker.h"
17 #include "ui/aura/window_tree_host.h" 17 #include "ui/aura/window_tree_host.h"
18 #include "ui/base/layout.h" 18 #include "ui/base/layout.h"
19 #include "ui/display/display_layout.h" 19 #include "ui/display/display_layout.h"
20 #include "ui/display/manager/display_manager.h" 20 #include "ui/display/manager/display_manager.h"
21 #include "ui/display/screen.h" 21 #include "ui/display/screen.h"
22 #include "ui/events/test/event_generator.h" 22 #include "ui/events/test/event_generator.h"
23 23
24 #if defined(OS_WIN)
25 // TODO(scottmg): RootWindow doesn't get resized immediately on Windows
26 // Ash. http://crbug.com/247916.
27 #define MAYBE_ConvertHostPointToScreen DISABLED_ConvertHostPointToScreen
28 #define MAYBE_ConvertHostPointToScreenHiDPI \
29 DISABLED_ConvertHostPointToScreenHiDPI
30 #define MAYBE_ConvertHostPointToScreenRotate \
31 DISABLED_ConvertHostPointToScreenRotate
32 #define MAYBE_ConvertHostPointToScreenUIScale \
33 DISABLED_ConvertHostPointToScreenUIScale
34 #define MAYBE_ConvertToScreenWhileRemovingSecondaryDisplay \
35 DISABLED_ConvertToScreenWhileRemovingSecondaryDisplay
36 #else
37 #define MAYBE_ConvertHostPointToScreen ConvertHostPointToScreen
38 #define MAYBE_ConvertHostPointToScreenHiDPI ConvertHostPointToScreenHiDPI
39 #define MAYBE_ConvertHostPointToScreenRotate ConvertHostPointToScreenRotate
40 #define MAYBE_ConvertHostPointToScreenUIScale ConvertHostPointToScreenUIScale
41 #define MAYBE_ConvertToScreenWhileRemovingSecondaryDisplay \
42 ConvertToScreenWhileRemovingSecondaryDisplay
43 #endif
44
45 namespace ash { 24 namespace ash {
46 namespace test { 25 namespace test {
47 26
48 namespace { 27 namespace {
49 28
50 ScreenPositionController* GetScreenPositionController() { 29 ScreenPositionController* GetScreenPositionController() {
51 ShellTestApi test_api(Shell::Get()); 30 ShellTestApi test_api(Shell::Get());
52 return test_api.screen_position_controller(); 31 return test_api.screen_position_controller();
53 } 32 }
54 33
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 protected: 69 protected:
91 std::unique_ptr<aura::Window> window_; 70 std::unique_ptr<aura::Window> window_;
92 aura::test::TestWindowDelegate window_delegate_; 71 aura::test::TestWindowDelegate window_delegate_;
93 72
94 private: 73 private:
95 DISALLOW_COPY_AND_ASSIGN(ScreenPositionControllerTest); 74 DISALLOW_COPY_AND_ASSIGN(ScreenPositionControllerTest);
96 }; 75 };
97 76
98 } // namespace 77 } // namespace
99 78
100 TEST_F(ScreenPositionControllerTest, MAYBE_ConvertHostPointToScreen) { 79 TEST_F(ScreenPositionControllerTest, ConvertHostPointToScreen) {
101 // Make sure that the point is in host coordinates. (crbug.com/521919) 80 // Make sure that the point is in host coordinates. (crbug.com/521919)
102 UpdateDisplay("100+100-200x200,100+300-200x200"); 81 UpdateDisplay("100+100-200x200,100+300-200x200");
103 // The point 150,210 should be in host coords, and detected as outside. 82 // The point 150,210 should be in host coords, and detected as outside.
104 EXPECT_EQ("350,10", ConvertHostPointToScreen(150, 210)); 83 EXPECT_EQ("350,10", ConvertHostPointToScreen(150, 210));
105 84
106 UpdateDisplay("100+100-200x200,100+500-200x200"); 85 UpdateDisplay("100+100-200x200,100+500-200x200");
107 86
108 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); 87 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
109 EXPECT_EQ( 88 EXPECT_EQ(
110 "100,100", 89 "100,100",
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 162
184 SetSecondaryDisplayLayout(display::DisplayPlacement::TOP); 163 SetSecondaryDisplayLayout(display::DisplayPlacement::TOP);
185 // The point is on the secondary display. 164 // The point is on the secondary display.
186 EXPECT_EQ("50,-150", ConvertHostPointToScreen(50, 50)); 165 EXPECT_EQ("50,-150", ConvertHostPointToScreen(50, 50));
187 // The point is out of the all root windows. 166 // The point is out of the all root windows.
188 EXPECT_EQ("250,50", ConvertHostPointToScreen(250, 250)); 167 EXPECT_EQ("250,50", ConvertHostPointToScreen(250, 250));
189 // The point is on the primary root window. 168 // The point is on the primary root window.
190 EXPECT_EQ("50,0", ConvertHostPointToScreen(50, -400)); 169 EXPECT_EQ("50,0", ConvertHostPointToScreen(50, -400));
191 } 170 }
192 171
193 TEST_F(ScreenPositionControllerTest, MAYBE_ConvertHostPointToScreenHiDPI) { 172 TEST_F(ScreenPositionControllerTest, ConvertHostPointToScreenHiDPI) {
194 UpdateDisplay("50+50-200x200*2,50+300-300x300"); 173 UpdateDisplay("50+50-200x200*2,50+300-300x300");
195 174
196 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); 175 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
197 EXPECT_EQ("50,50 200x200", 176 EXPECT_EQ("50,50 200x200",
198 root_windows[0]->GetHost()->GetBoundsInPixels().ToString()); 177 root_windows[0]->GetHost()->GetBoundsInPixels().ToString());
199 EXPECT_EQ("50,300 300x300", 178 EXPECT_EQ("50,300 300x300",
200 root_windows[1]->GetHost()->GetBoundsInPixels().ToString()); 179 root_windows[1]->GetHost()->GetBoundsInPixels().ToString());
201 180
202 // Put |window_| to the primary 2x display. 181 // Put |window_| to the primary 2x display.
203 window_->SetBoundsInScreen(gfx::Rect(20, 20, 50, 50), 182 window_->SetBoundsInScreen(gfx::Rect(20, 20, 50, 50),
(...skipping 10 matching lines...) Expand all
214 // so the screen position is (100,0) + (150,200). 193 // so the screen position is (100,0) + (150,200).
215 EXPECT_EQ("250,200", ConvertHostPointToScreen(150, 450)); 194 EXPECT_EQ("250,200", ConvertHostPointToScreen(150, 450));
216 195
217 // At the edge but still in the primary display. Remaining of the primary 196 // At the edge but still in the primary display. Remaining of the primary
218 // display is (50, 50) but adding ~100 since it's 2x-display. 197 // display is (50, 50) but adding ~100 since it's 2x-display.
219 EXPECT_EQ("79,79", ConvertHostPointToScreen(158, 158)); 198 EXPECT_EQ("79,79", ConvertHostPointToScreen(158, 158));
220 // At the edge of the secondary display. 199 // At the edge of the secondary display.
221 EXPECT_EQ("80,80", ConvertHostPointToScreen(160, 160)); 200 EXPECT_EQ("80,80", ConvertHostPointToScreen(160, 160));
222 } 201 }
223 202
224 TEST_F(ScreenPositionControllerTest, MAYBE_ConvertHostPointToScreenRotate) { 203 TEST_F(ScreenPositionControllerTest, ConvertHostPointToScreenRotate) {
225 // 1st display is rotated 90 clockise, and 2nd display is rotated 204 // 1st display is rotated 90 clockise, and 2nd display is rotated
226 // 270 clockwise. 205 // 270 clockwise.
227 UpdateDisplay("100+100-200x200/r,100+500-200x200/l"); 206 UpdateDisplay("100+100-200x200/r,100+500-200x200/l");
228 // Put |window_| to the 1st. 207 // Put |window_| to the 1st.
229 window_->SetBoundsInScreen(gfx::Rect(20, 20, 50, 50), 208 window_->SetBoundsInScreen(gfx::Rect(20, 20, 50, 50),
230 display::Screen::GetScreen()->GetPrimaryDisplay()); 209 display::Screen::GetScreen()->GetPrimaryDisplay());
231 210
232 // The point is on the 1st host. 211 // The point is on the 1st host.
233 EXPECT_EQ("70,149", ConvertHostPointToScreen(50, 70)); 212 EXPECT_EQ("70,149", ConvertHostPointToScreen(50, 70));
234 // The point is out of the host windows. 213 // The point is out of the host windows.
(...skipping 11 matching lines...) Expand all
246 // The point is on the 2nd host. (50,70) on 2n host - 225 // The point is on the 2nd host. (50,70) on 2n host -
247 // roatate 270 clockwise -> (129,50) -layout [+(200,0)] -> (329,50) 226 // roatate 270 clockwise -> (129,50) -layout [+(200,0)] -> (329,50)
248 EXPECT_EQ("329,50", ConvertHostPointToScreen(50, 70)); 227 EXPECT_EQ("329,50", ConvertHostPointToScreen(50, 70));
249 // The point is out of the host windows. 228 // The point is out of the host windows.
250 EXPECT_EQ("449,50", ConvertHostPointToScreen(50, -50)); 229 EXPECT_EQ("449,50", ConvertHostPointToScreen(50, -50));
251 // The point is on the 2nd host. Point on 2nd host (50,50) - 230 // The point is on the 2nd host. Point on 2nd host (50,50) -
252 // rotate 90 clockwise -> (50, 149) 231 // rotate 90 clockwise -> (50, 149)
253 EXPECT_EQ("50,149", ConvertHostPointToScreen(50, -350)); 232 EXPECT_EQ("50,149", ConvertHostPointToScreen(50, -350));
254 } 233 }
255 234
256 TEST_F(ScreenPositionControllerTest, MAYBE_ConvertHostPointToScreenUIScale) { 235 TEST_F(ScreenPositionControllerTest, ConvertHostPointToScreenUIScale) {
257 // 1st display is 2x density with 1.5 UI scale. 236 // 1st display is 2x density with 1.5 UI scale.
258 UpdateDisplay("100+100-200x200*2@1.5,100+500-200x200"); 237 UpdateDisplay("100+100-200x200*2@1.5,100+500-200x200");
259 // Put |window_| to the 1st. 238 // Put |window_| to the 1st.
260 window_->SetBoundsInScreen(gfx::Rect(20, 20, 50, 50), 239 window_->SetBoundsInScreen(gfx::Rect(20, 20, 50, 50),
261 display::Screen::GetScreen()->GetPrimaryDisplay()); 240 display::Screen::GetScreen()->GetPrimaryDisplay());
262 241
263 // The point is on the 1st host. 242 // The point is on the 1st host.
264 EXPECT_EQ("45,45", ConvertHostPointToScreen(60, 60)); 243 EXPECT_EQ("45,45", ConvertHostPointToScreen(60, 60));
265 // The point is out of the host windows. 244 // The point is out of the host windows.
266 EXPECT_EQ("45,225", ConvertHostPointToScreen(60, 300)); 245 EXPECT_EQ("45,225", ConvertHostPointToScreen(60, 300));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 DISALLOW_COPY_AND_ASSIGN(ConvertToScreenEventHandler); 293 DISALLOW_COPY_AND_ASSIGN(ConvertToScreenEventHandler);
315 }; 294 };
316 295
317 } // namespace 296 } // namespace
318 297
319 // Test that events are only dispatched when a ScreenPositionClient is available 298 // Test that events are only dispatched when a ScreenPositionClient is available
320 // to convert the event to screen coordinates. The ScreenPositionClient is 299 // to convert the event to screen coordinates. The ScreenPositionClient is
321 // detached from the root window prior to the root window being destroyed. Test 300 // detached from the root window prior to the root window being destroyed. Test
322 // that no events are dispatched at this time. 301 // that no events are dispatched at this time.
323 TEST_F(ScreenPositionControllerTest, 302 TEST_F(ScreenPositionControllerTest,
324 MAYBE_ConvertToScreenWhileRemovingSecondaryDisplay) { 303 ConvertToScreenWhileRemovingSecondaryDisplay) {
325 UpdateDisplay("600x600,600x600"); 304 UpdateDisplay("600x600,600x600");
326 RunAllPendingInMessageLoop(); 305 RunAllPendingInMessageLoop();
327 306
328 // Create a window on the secondary display. 307 // Create a window on the secondary display.
329 window_->SetBoundsInScreen(gfx::Rect(600, 0, 400, 400), 308 window_->SetBoundsInScreen(gfx::Rect(600, 0, 400, 400),
330 display_manager()->GetSecondaryDisplay()); 309 display_manager()->GetSecondaryDisplay());
331 310
332 // Move the mouse cursor over |window_|. Synthetic mouse moves are dispatched 311 // Move the mouse cursor over |window_|. Synthetic mouse moves are dispatched
333 // asynchronously when a window which contains the mouse cursor is destroyed. 312 // asynchronously when a window which contains the mouse cursor is destroyed.
334 // We want to check that none of these synthetic events are dispatched after 313 // We want to check that none of these synthetic events are dispatched after
(...skipping 20 matching lines...) Expand all
355 // destroyed. 334 // destroyed.
356 EXPECT_FALSE(tracker.Contains(root_windows[1])); 335 EXPECT_FALSE(tracker.Contains(root_windows[1]));
357 336
358 // Check that we could convert all of the mouse events we got to screen 337 // Check that we could convert all of the mouse events we got to screen
359 // coordinates. 338 // coordinates.
360 EXPECT_TRUE(event_handler->could_convert_to_screen()); 339 EXPECT_TRUE(event_handler->could_convert_to_screen());
361 } 340 }
362 341
363 } // namespace test 342 } // namespace test
364 } // namespace ash 343 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/screen_ash_unittest.cc ('k') | ash/mus/bridge/wm_shell_mus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698