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

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

Issue 289583002: Lock rotation when screen is manually rotated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Define sources for rotation Created 6 years, 7 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 (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" 26 #include "ui/aura/test/event_generator.h"
27 #include "ui/aura/window_tracker.h" 27 #include "ui/aura/window_tracker.h"
28 #include "ui/aura/window_tree_host.h" 28 #include "ui/aura/window_tree_host.h"
29 #include "ui/display/types/display_constants.h"
29 #include "ui/events/event_handler.h" 30 #include "ui/events/event_handler.h"
30 #include "ui/gfx/display.h" 31 #include "ui/gfx/display.h"
31 #include "ui/gfx/screen.h" 32 #include "ui/gfx/screen.h"
32 #include "ui/views/widget/widget.h" 33 #include "ui/views/widget/widget.h"
33 #include "ui/wm/public/activation_change_observer.h" 34 #include "ui/wm/public/activation_change_observer.h"
34 #include "ui/wm/public/activation_client.h" 35 #include "ui/wm/public/activation_client.h"
35 36
36 #if defined(USE_X11) 37 #if defined(USE_X11)
37 #include <X11/Xlib.h> 38 #include <X11/Xlib.h>
38 #include "ui/gfx/x/x11_types.h" 39 #include "ui/gfx/x/x11_types.h"
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 EXPECT_EQ("0,250 300x300", GetSecondaryDisplay().bounds().ToString()); 622 EXPECT_EQ("0,250 300x300", GetSecondaryDisplay().bounds().ToString());
622 623
623 // No change 624 // No change
624 UpdateDisplay("400x500*2,300x300"); 625 UpdateDisplay("400x500*2,300x300");
625 EXPECT_EQ(0, observer.CountAndReset()); 626 EXPECT_EQ(0, observer.CountAndReset());
626 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); 627 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
627 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); 628 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
628 629
629 // Rotation 630 // Rotation
630 int64 primary_id = GetPrimaryDisplay().id(); 631 int64 primary_id = GetPrimaryDisplay().id();
631 display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90); 632 display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90,
633 ui::USER);
632 EXPECT_EQ(1, observer.CountAndReset()); 634 EXPECT_EQ(1, observer.CountAndReset());
633 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); 635 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
634 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); 636 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
635 display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90); 637 display_manager->SetDisplayRotation(primary_id,
638 gfx::Display::ROTATE_90,
639 ui::USER);
636 EXPECT_EQ(0, observer.CountAndReset()); 640 EXPECT_EQ(0, observer.CountAndReset());
637 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); 641 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
638 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); 642 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
639 643
640 // UI scale is eanbled only on internal display. 644 // UI scale is eanbled only on internal display.
641 int64 secondary_id = GetSecondaryDisplay().id(); 645 int64 secondary_id = GetSecondaryDisplay().id();
642 gfx::Display::SetInternalDisplayId(secondary_id); 646 gfx::Display::SetInternalDisplayId(secondary_id);
643 display_manager->SetDisplayUIScale(secondary_id, 1.125f); 647 display_manager->SetDisplayUIScale(secondary_id, 1.125f);
644 EXPECT_EQ(1, observer.CountAndReset()); 648 EXPECT_EQ(1, observer.CountAndReset());
645 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); 649 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); 1039 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString());
1036 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); 1040 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString());
1037 EXPECT_EQ("120,0 150x200", 1041 EXPECT_EQ("120,0 150x200",
1038 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 1042 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
1039 generator1.MoveMouseToInHost(50, 40); 1043 generator1.MoveMouseToInHost(50, 40);
1040 EXPECT_EQ("50,40", event_handler.GetLocationAndReset()); 1044 EXPECT_EQ("50,40", event_handler.GetLocationAndReset());
1041 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display1.id())); 1045 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display1.id()));
1042 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id)); 1046 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id));
1043 1047
1044 display_manager->SetDisplayRotation(display1.id(), 1048 display_manager->SetDisplayRotation(display1.id(),
1045 gfx::Display::ROTATE_90); 1049 gfx::Display::ROTATE_90,
1050 ui::USER);
1046 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); 1051 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString());
1047 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); 1052 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString());
1048 EXPECT_EQ("200,0 150x200", 1053 EXPECT_EQ("200,0 150x200",
1049 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 1054 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
1050 generator1.MoveMouseToInHost(50, 40); 1055 generator1.MoveMouseToInHost(50, 40);
1051 EXPECT_EQ("40,69", event_handler.GetLocationAndReset()); 1056 EXPECT_EQ("40,69", event_handler.GetLocationAndReset());
1052 EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id())); 1057 EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id()));
1053 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id)); 1058 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id));
1054 1059
1055 DisplayLayout display_layout(DisplayLayout::BOTTOM, 50); 1060 DisplayLayout display_layout(DisplayLayout::BOTTOM, 50);
1056 display_manager->SetLayoutForCurrentDisplays(display_layout); 1061 display_manager->SetLayoutForCurrentDisplays(display_layout);
1057 EXPECT_EQ("50,120 150x200", 1062 EXPECT_EQ("50,120 150x200",
1058 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 1063 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
1059 1064
1060 display_manager->SetDisplayRotation(display2_id, 1065 display_manager->SetDisplayRotation(display2_id,
1061 gfx::Display::ROTATE_270); 1066 gfx::Display::ROTATE_270,
1067 ui::USER);
1062 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); 1068 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString());
1063 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); 1069 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString());
1064 EXPECT_EQ("50,120 200x150", 1070 EXPECT_EQ("50,120 200x150",
1065 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 1071 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
1066 EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id())); 1072 EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id()));
1067 EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); 1073 EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id));
1068 1074
1069 #if !defined(OS_WIN) 1075 #if !defined(OS_WIN)
1070 aura::test::EventGenerator generator2(root_windows[1]); 1076 aura::test::EventGenerator generator2(root_windows[1]);
1071 generator2.MoveMouseToInHost(50, 40); 1077 generator2.MoveMouseToInHost(50, 40);
1072 EXPECT_EQ("179,25", event_handler.GetLocationAndReset()); 1078 EXPECT_EQ("179,25", event_handler.GetLocationAndReset());
1073 display_manager->SetDisplayRotation(display1.id(), 1079 display_manager->SetDisplayRotation(display1.id(),
1074 gfx::Display::ROTATE_180); 1080 gfx::Display::ROTATE_180,
1081 ui::USER);
1075 1082
1076 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); 1083 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString());
1077 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); 1084 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString());
1078 // Dislay must share at least 100, so the x's offset becomes 20. 1085 // Dislay must share at least 100, so the x's offset becomes 20.
1079 EXPECT_EQ("20,200 200x150", 1086 EXPECT_EQ("20,200 200x150",
1080 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 1087 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
1081 EXPECT_EQ(gfx::Display::ROTATE_180, GetStoredRotation(display1.id())); 1088 EXPECT_EQ(gfx::Display::ROTATE_180, GetStoredRotation(display1.id()));
1082 EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); 1089 EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id));
1083 1090
1084 generator1.MoveMouseToInHost(50, 40); 1091 generator1.MoveMouseToInHost(50, 40);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); 1224 Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
1218 } 1225 }
1219 1226
1220 namespace { 1227 namespace {
1221 1228
1222 DisplayInfo CreateDisplayInfo(int64 id, 1229 DisplayInfo CreateDisplayInfo(int64 id,
1223 int y, 1230 int y,
1224 gfx::Display::Rotation rotation) { 1231 gfx::Display::Rotation rotation) {
1225 DisplayInfo info(id, "", false); 1232 DisplayInfo info(id, "", false);
1226 info.SetBounds(gfx::Rect(0, y, 500, 500)); 1233 info.SetBounds(gfx::Rect(0, y, 500, 500));
1227 info.set_rotation(rotation); 1234 info.SetRotation(rotation, ui::USER);
1228 return info; 1235 return info;
1229 } 1236 }
1230 1237
1231 } // namespace 1238 } // namespace
1232 1239
1233 // Make sure that the compositor based mirroring can switch 1240 // Make sure that the compositor based mirroring can switch
1234 // from/to dock mode. 1241 // from/to dock mode.
1235 TEST_F(DisplayControllerTest, DockToSingle) { 1242 TEST_F(DisplayControllerTest, DockToSingle) {
1236 if (!SupportsMultipleDisplays()) 1243 if (!SupportsMultipleDisplays())
1237 return; 1244 return;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetHost())); 1300 EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetHost()));
1294 1301
1295 // Switching back to single display. 1302 // Switching back to single display.
1296 UpdateDisplay("300x400"); 1303 UpdateDisplay("300x400");
1297 EXPECT_EQ("aura_root_0", GetXWindowName( 1304 EXPECT_EQ("aura_root_0", GetXWindowName(
1298 Shell::GetPrimaryRootWindow()->GetHost())); 1305 Shell::GetPrimaryRootWindow()->GetHost()));
1299 } 1306 }
1300 #endif 1307 #endif
1301 1308
1302 } // namespace ash 1309 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698