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

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

Issue 406413004: Cleanups for aura/test/event_generator.h (resolve TODOs) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix gn Created 6 years, 5 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) 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/display_controller.h" 5 #include "ash/display/display_controller.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/display/display_info.h" 8 #include "ash/display/display_info.h"
9 #include "ash/display/display_layout_store.h" 9 #include "ash/display/display_layout_store.h"
10 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
11 #include "ash/screen_util.h" 11 #include "ash/screen_util.h"
12 #include "ash/shelf/shelf.h" 12 #include "ash/shelf/shelf.h"
13 #include "ash/shelf/shelf_widget.h" 13 #include "ash/shelf/shelf_widget.h"
14 #include "ash/shell.h" 14 #include "ash/shell.h"
15 #include "ash/test/ash_test_base.h" 15 #include "ash/test/ash_test_base.h"
16 #include "ash/test/ash_test_helper.h" 16 #include "ash/test/ash_test_helper.h"
17 #include "ash/test/cursor_manager_test_api.h" 17 #include "ash/test/cursor_manager_test_api.h"
18 #include "ash/test/display_manager_test_api.h" 18 #include "ash/test/display_manager_test_api.h"
19 #include "ash/test/test_shell_delegate.h" 19 #include "ash/test/test_shell_delegate.h"
20 #include "ash/wm/window_state.h" 20 #include "ash/wm/window_state.h"
21 #include "ash/wm/wm_event.h" 21 #include "ash/wm/wm_event.h"
22 #include "base/command_line.h" 22 #include "base/command_line.h"
23 #include "ui/aura/client/focus_change_observer.h" 23 #include "ui/aura/client/focus_change_observer.h"
24 #include "ui/aura/client/focus_client.h" 24 #include "ui/aura/client/focus_client.h"
25 #include "ui/aura/env.h" 25 #include "ui/aura/env.h"
26 #include "ui/aura/test/event_generator.h"
27 #include "ui/aura/window_tracker.h" 26 #include "ui/aura/window_tracker.h"
28 #include "ui/aura/window_tree_host.h" 27 #include "ui/aura/window_tree_host.h"
29 #include "ui/events/event_handler.h" 28 #include "ui/events/event_handler.h"
29 #include "ui/events/test/event_generator.h"
30 #include "ui/gfx/display.h" 30 #include "ui/gfx/display.h"
31 #include "ui/gfx/screen.h" 31 #include "ui/gfx/screen.h"
32 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
33 #include "ui/wm/public/activation_change_observer.h" 33 #include "ui/wm/public/activation_change_observer.h"
34 #include "ui/wm/public/activation_client.h" 34 #include "ui/wm/public/activation_client.h"
35 35
36 #if defined(USE_X11) 36 #if defined(USE_X11)
37 #include <X11/Xlib.h> 37 #include <X11/Xlib.h>
38 #include "ui/gfx/x/x11_types.h" 38 #include "ui/gfx/x/x11_types.h"
39 #undef RootWindow 39 #undef RootWindow
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); 1014 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay();
1015 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 1015 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1016 1016
1017 display_controller->SetOverscanInsets(display1.id(), 1017 display_controller->SetOverscanInsets(display1.id(),
1018 gfx::Insets(10, 15, 20, 25)); 1018 gfx::Insets(10, 15, 20, 25));
1019 EXPECT_EQ("0,0 80x170", root_windows[0]->bounds().ToString()); 1019 EXPECT_EQ("0,0 80x170", root_windows[0]->bounds().ToString());
1020 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); 1020 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString());
1021 EXPECT_EQ("80,0 150x200", 1021 EXPECT_EQ("80,0 150x200",
1022 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 1022 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
1023 1023
1024 aura::test::EventGenerator generator(root_windows[0]); 1024 ui::test::EventGenerator generator(root_windows[0]);
1025 generator.MoveMouseToInHost(20, 25); 1025 generator.MoveMouseToInHost(20, 25);
1026 EXPECT_EQ("5,15", event_handler.GetLocationAndReset()); 1026 EXPECT_EQ("5,15", event_handler.GetLocationAndReset());
1027 1027
1028 display_controller->SetOverscanInsets(display1.id(), gfx::Insets()); 1028 display_controller->SetOverscanInsets(display1.id(), gfx::Insets());
1029 EXPECT_EQ("0,0 120x200", root_windows[0]->bounds().ToString()); 1029 EXPECT_EQ("0,0 120x200", root_windows[0]->bounds().ToString());
1030 EXPECT_EQ("120,0 150x200", 1030 EXPECT_EQ("120,0 150x200",
1031 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 1031 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
1032 1032
1033 generator.MoveMouseToInHost(30, 20); 1033 generator.MoveMouseToInHost(30, 20);
1034 EXPECT_EQ("30,20", event_handler.GetLocationAndReset()); 1034 EXPECT_EQ("30,20", event_handler.GetLocationAndReset());
(...skipping 21 matching lines...) Expand all
1056 return; 1056 return;
1057 1057
1058 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 1058 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
1059 TestEventHandler event_handler; 1059 TestEventHandler event_handler;
1060 Shell::GetInstance()->AddPreTargetHandler(&event_handler); 1060 Shell::GetInstance()->AddPreTargetHandler(&event_handler);
1061 1061
1062 UpdateDisplay("120x200,300x400*2"); 1062 UpdateDisplay("120x200,300x400*2");
1063 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); 1063 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay();
1064 int64 display2_id = ScreenUtil::GetSecondaryDisplay().id(); 1064 int64 display2_id = ScreenUtil::GetSecondaryDisplay().id();
1065 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 1065 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1066 aura::test::EventGenerator generator1(root_windows[0]); 1066 ui::test::EventGenerator generator1(root_windows[0]);
1067 1067
1068 TestObserver observer; 1068 TestObserver observer;
1069 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); 1069 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString());
1070 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); 1070 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString());
1071 EXPECT_EQ("120,0 150x200", 1071 EXPECT_EQ("120,0 150x200",
1072 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 1072 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
1073 generator1.MoveMouseToInHost(50, 40); 1073 generator1.MoveMouseToInHost(50, 40);
1074 EXPECT_EQ("50,40", event_handler.GetLocationAndReset()); 1074 EXPECT_EQ("50,40", event_handler.GetLocationAndReset());
1075 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display1.id())); 1075 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display1.id()));
1076 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id)); 1076 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id));
(...skipping 20 matching lines...) Expand all
1097 gfx::Display::ROTATE_270); 1097 gfx::Display::ROTATE_270);
1098 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); 1098 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString());
1099 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); 1099 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString());
1100 EXPECT_EQ("50,120 200x150", 1100 EXPECT_EQ("50,120 200x150",
1101 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 1101 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
1102 EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id())); 1102 EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id()));
1103 EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); 1103 EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id));
1104 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); 1104 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset());
1105 1105
1106 #if !defined(OS_WIN) 1106 #if !defined(OS_WIN)
1107 aura::test::EventGenerator generator2(root_windows[1]); 1107 ui::test::EventGenerator generator2(root_windows[1]);
1108 generator2.MoveMouseToInHost(50, 40); 1108 generator2.MoveMouseToInHost(50, 40);
1109 EXPECT_EQ("179,25", event_handler.GetLocationAndReset()); 1109 EXPECT_EQ("179,25", event_handler.GetLocationAndReset());
1110 display_manager->SetDisplayRotation(display1.id(), 1110 display_manager->SetDisplayRotation(display1.id(),
1111 gfx::Display::ROTATE_180); 1111 gfx::Display::ROTATE_180);
1112 1112
1113 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); 1113 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString());
1114 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); 1114 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString());
1115 // Dislay must share at least 100, so the x's offset becomes 20. 1115 // Dislay must share at least 100, so the x's offset becomes 20.
1116 EXPECT_EQ("20,200 200x150", 1116 EXPECT_EQ("20,200 200x150",
1117 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 1117 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
(...skipping 21 matching lines...) Expand all
1139 gfx::Display::SetInternalDisplayId(display1.id()); 1139 gfx::Display::SetInternalDisplayId(display1.id());
1140 1140
1141 gfx::Display display2 = ScreenUtil::GetSecondaryDisplay(); 1141 gfx::Display display2 = ScreenUtil::GetSecondaryDisplay();
1142 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 1142 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1143 EXPECT_EQ("0,0 450x300", display1.bounds().ToString()); 1143 EXPECT_EQ("0,0 450x300", display1.bounds().ToString());
1144 EXPECT_EQ("0,0 450x300", root_windows[0]->bounds().ToString()); 1144 EXPECT_EQ("0,0 450x300", root_windows[0]->bounds().ToString());
1145 EXPECT_EQ("450,0 500x300", display2.bounds().ToString()); 1145 EXPECT_EQ("450,0 500x300", display2.bounds().ToString());
1146 EXPECT_EQ(1.5f, GetStoredUIScale(display1.id())); 1146 EXPECT_EQ(1.5f, GetStoredUIScale(display1.id()));
1147 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); 1147 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id()));
1148 1148
1149 aura::test::EventGenerator generator(root_windows[0]); 1149 ui::test::EventGenerator generator(root_windows[0]);
1150 generator.MoveMouseToInHost(599, 200); 1150 generator.MoveMouseToInHost(599, 200);
1151 EXPECT_EQ("449,150", event_handler.GetLocationAndReset()); 1151 EXPECT_EQ("449,150", event_handler.GetLocationAndReset());
1152 1152
1153 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 1153 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
1154 display_manager->SetDisplayUIScale(display1.id(), 1.25f); 1154 display_manager->SetDisplayUIScale(display1.id(), 1.25f);
1155 display1 = Shell::GetScreen()->GetPrimaryDisplay(); 1155 display1 = Shell::GetScreen()->GetPrimaryDisplay();
1156 display2 = ScreenUtil::GetSecondaryDisplay(); 1156 display2 = ScreenUtil::GetSecondaryDisplay();
1157 EXPECT_EQ("0,0 375x250", display1.bounds().ToString()); 1157 EXPECT_EQ("0,0 375x250", display1.bounds().ToString());
1158 EXPECT_EQ("0,0 375x250", root_windows[0]->bounds().ToString()); 1158 EXPECT_EQ("0,0 375x250", root_windows[0]->bounds().ToString());
1159 EXPECT_EQ("375,0 500x300", display2.bounds().ToString()); 1159 EXPECT_EQ("375,0 500x300", display2.bounds().ToString());
1160 EXPECT_EQ(1.25f, GetStoredUIScale(display1.id())); 1160 EXPECT_EQ(1.25f, GetStoredUIScale(display1.id()));
1161 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); 1161 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id()));
1162 1162
1163 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); 1163 Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
1164 } 1164 }
1165 1165
1166 TEST_F(DisplayControllerTest, TouchScale) { 1166 TEST_F(DisplayControllerTest, TouchScale) {
1167 if (!SupportsMultipleDisplays()) 1167 if (!SupportsMultipleDisplays())
1168 return; 1168 return;
1169 1169
1170 TestEventHandler event_handler; 1170 TestEventHandler event_handler;
1171 Shell::GetInstance()->AddPreTargetHandler(&event_handler); 1171 Shell::GetInstance()->AddPreTargetHandler(&event_handler);
1172 1172
1173 UpdateDisplay("200x200*2"); 1173 UpdateDisplay("200x200*2");
1174 gfx::Display display = Shell::GetScreen()->GetPrimaryDisplay(); 1174 gfx::Display display = Shell::GetScreen()->GetPrimaryDisplay();
1175 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 1175 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1176 aura::Window* root_window = root_windows[0]; 1176 aura::Window* root_window = root_windows[0];
1177 aura::test::EventGenerator generator(root_window); 1177 ui::test::EventGenerator generator(root_window);
1178 1178
1179 generator.PressMoveAndReleaseTouchTo(50, 50); 1179 generator.PressMoveAndReleaseTouchTo(50, 50);
1180 // Default test touches have radius_x/y = 1.0, with device scale 1180 // Default test touches have radius_x/y = 1.0, with device scale
1181 // factor = 2, the scaled radius_x/y should be 0.5. 1181 // factor = 2, the scaled radius_x/y should be 0.5.
1182 EXPECT_EQ(0.5, event_handler.touch_radius_x()); 1182 EXPECT_EQ(0.5, event_handler.touch_radius_x());
1183 EXPECT_EQ(0.5, event_handler.touch_radius_y()); 1183 EXPECT_EQ(0.5, event_handler.touch_radius_y());
1184 1184
1185 generator.ScrollSequence(gfx::Point(0,0), 1185 generator.ScrollSequence(gfx::Point(0,0),
1186 base::TimeDelta::FromMilliseconds(100), 1186 base::TimeDelta::FromMilliseconds(100),
1187 10.0, 1.0, 5, 1); 1187 10.0, 1.0, 5, 1);
(...skipping 15 matching lines...) Expand all
1203 Shell::GetInstance()->AddPreTargetHandler(&event_handler); 1203 Shell::GetInstance()->AddPreTargetHandler(&event_handler);
1204 1204
1205 UpdateDisplay("600x400*2/r@1.5"); 1205 UpdateDisplay("600x400*2/r@1.5");
1206 1206
1207 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); 1207 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay();
1208 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 1208 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1209 EXPECT_EQ("0,0 300x450", display1.bounds().ToString()); 1209 EXPECT_EQ("0,0 300x450", display1.bounds().ToString());
1210 EXPECT_EQ("0,0 300x450", root_windows[0]->bounds().ToString()); 1210 EXPECT_EQ("0,0 300x450", root_windows[0]->bounds().ToString());
1211 EXPECT_EQ(1.5f, GetStoredUIScale(display1.id())); 1211 EXPECT_EQ(1.5f, GetStoredUIScale(display1.id()));
1212 1212
1213 aura::test::EventGenerator generator(root_windows[0]); 1213 ui::test::EventGenerator generator(root_windows[0]);
1214 generator.MoveMouseToInHost(0, 0); 1214 generator.MoveMouseToInHost(0, 0);
1215 EXPECT_EQ("0,449", event_handler.GetLocationAndReset()); 1215 EXPECT_EQ("0,449", event_handler.GetLocationAndReset());
1216 generator.MoveMouseToInHost(599, 0); 1216 generator.MoveMouseToInHost(599, 0);
1217 EXPECT_EQ("0,0", event_handler.GetLocationAndReset()); 1217 EXPECT_EQ("0,0", event_handler.GetLocationAndReset());
1218 generator.MoveMouseToInHost(599, 399); 1218 generator.MoveMouseToInHost(599, 399);
1219 EXPECT_EQ("299,0", event_handler.GetLocationAndReset()); 1219 EXPECT_EQ("299,0", event_handler.GetLocationAndReset());
1220 generator.MoveMouseToInHost(0, 399); 1220 generator.MoveMouseToInHost(0, 399);
1221 EXPECT_EQ("299,449", event_handler.GetLocationAndReset()); 1221 EXPECT_EQ("299,449", event_handler.GetLocationAndReset());
1222 1222
1223 UpdateDisplay("600x400*2/u@1.5"); 1223 UpdateDisplay("600x400*2/u@1.5");
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetHost())); 1331 EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetHost()));
1332 1332
1333 // Switching back to single display. 1333 // Switching back to single display.
1334 UpdateDisplay("300x400"); 1334 UpdateDisplay("300x400");
1335 EXPECT_EQ("aura_root_0", GetXWindowName( 1335 EXPECT_EQ("aura_root_0", GetXWindowName(
1336 Shell::GetPrimaryRootWindow()->GetHost())); 1336 Shell::GetPrimaryRootWindow()->GetHost()));
1337 } 1337 }
1338 #endif 1338 #endif
1339 1339
1340 } // namespace ash 1340 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698