summaryrefslogtreecommitdiffstats
path: root/ash/display/display_controller_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'ash/display/display_controller_unittest.cc')
-rw-r--r--ash/display/display_controller_unittest.cc196
1 files changed, 141 insertions, 55 deletions
diff --git a/ash/display/display_controller_unittest.cc b/ash/display/display_controller_unittest.cc
index d298eee..a753d1b 100644
--- a/ash/display/display_controller_unittest.cc
+++ b/ash/display/display_controller_unittest.cc
@@ -961,61 +961,6 @@ TEST_F(DisplayControllerTest, SwapPrimaryById) {
EXPECT_TRUE(primary_root->Contains(shelf_window));
}
-TEST_F(DisplayControllerTest, CursorDeviceScaleFactorSwapPrimary) {
- if (!SupportsMultipleDisplays())
- return;
-
- DisplayController* display_controller =
- Shell::GetInstance()->display_controller();
-
- UpdateDisplay("200x200,200x200*2");
- gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay();
- gfx::Display secondary_display = ScreenUtil::GetSecondaryDisplay();
-
- aura::Window* primary_root =
- display_controller->GetRootWindowForDisplayId(primary_display.id());
- aura::Window* secondary_root =
- display_controller->GetRootWindowForDisplayId(secondary_display.id());
- EXPECT_NE(primary_root, secondary_root);
-
- test::CursorManagerTestApi test_api(Shell::GetInstance()->cursor_manager());
-
- EXPECT_EQ(1.0f, primary_root->GetHost()->compositor()->
- device_scale_factor());
- primary_root->MoveCursorTo(gfx::Point(50, 50));
- EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
- EXPECT_EQ(2.0f, secondary_root->GetHost()->compositor()->
- device_scale_factor());
- secondary_root->MoveCursorTo(gfx::Point(50, 50));
- EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
-
- // Switch primary and secondary
- display_controller->SetPrimaryDisplay(secondary_display);
-
- // Cursor's device scale factor should be updated accroding to the swap of
- // primary and secondary.
- EXPECT_EQ(1.0f, secondary_root->GetHost()->compositor()->
- device_scale_factor());
- secondary_root->MoveCursorTo(gfx::Point(50, 50));
- EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
- primary_root->MoveCursorTo(gfx::Point(50, 50));
- EXPECT_EQ(2.0f, primary_root->GetHost()->compositor()->
- device_scale_factor());
- EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
-
- // Deleting 2nd display.
- UpdateDisplay("200x200");
- RunAllPendingInMessageLoop(); // RootWindow is deleted in a posted task.
-
- // Cursor's device scale factor should be updated even without moving cursor.
- EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
-
- primary_root->MoveCursorTo(gfx::Point(50, 50));
- EXPECT_EQ(1.0f, primary_root->GetHost()->compositor()->
- device_scale_factor());
- EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
-}
-
TEST_F(DisplayControllerTest, OverscanInsets) {
if (!SupportsMultipleDisplays())
return;
@@ -1374,4 +1319,145 @@ TEST_F(DisplayControllerTest, XWidowNameForRootWindow) {
}
#endif
+TEST_F(DisplayControllerTest, UpdateMouseLocationAfterDisplayChange) {
+ if (!SupportsMultipleDisplays())
+ return;
+
+ UpdateDisplay("200x200,300x300");
+ aura::Window::Windows root_windows = Shell::GetAllRootWindows();
+
+ aura::Env* env = aura::Env::GetInstance();
+
+ ui::test::EventGenerator generator(root_windows[0]);
+
+ // Set the initial position.
+ generator.MoveMouseToInHost(350, 150);
+ EXPECT_EQ("350,150", env->last_mouse_location().ToString());
+
+ // A mouse pointer will stay in the 2nd display.
+ UpdateDisplay("300x300,200x200");
+ EXPECT_EQ("450,50", env->last_mouse_location().ToString());
+
+ // A mouse pointer will be outside of displays and move to the
+ // center of 2nd display.
+ UpdateDisplay("300x300,100x100");
+ EXPECT_EQ("350,50", env->last_mouse_location().ToString());
+
+ // 2nd display was disconnected, and the cursor is
+ // now in the 1st display.
+ UpdateDisplay("400x400");
+ EXPECT_EQ("50,350", env->last_mouse_location().ToString());
+
+ // 1st display's resolution has changed, and the mouse pointer is
+ // now outside. Move the mouse pointer to the center of 1st display.
+ UpdateDisplay("300x300");
+ EXPECT_EQ("150,150", env->last_mouse_location().ToString());
+
+ // Move the mouse pointer to the bottom of 1st display.
+ generator.MoveMouseToInHost(150, 290);
+ EXPECT_EQ("150,290", env->last_mouse_location().ToString());
+
+ // The mouse pointer is now on 2nd display.
+ UpdateDisplay("300x280,200x200");
+ EXPECT_EQ("450,10", env->last_mouse_location().ToString());
+}
+
+TEST_F(DisplayControllerTest, UpdateMouseLocationAfterDisplayChange_2ndOnLeft) {
+ if (!SupportsMultipleDisplays())
+ return;
+
+ // Set the 2nd display on the left.
+ DisplayLayoutStore* layout_store =
+ Shell::GetInstance()->display_manager()->layout_store();
+ DisplayLayout layout = layout_store->default_display_layout();
+ layout.position = DisplayLayout::LEFT;
+ layout_store->SetDefaultDisplayLayout(layout);
+
+ UpdateDisplay("200x200,300x300");
+ aura::Window::Windows root_windows = Shell::GetAllRootWindows();
+
+ EXPECT_EQ("-300,0 300x300",
+ ScreenUtil::GetSecondaryDisplay().bounds().ToString());
+
+ aura::Env* env = aura::Env::GetInstance();
+
+ // Set the initial position.
+ root_windows[0]->MoveCursorTo(gfx::Point(-150, 250));
+ EXPECT_EQ("-150,250", env->last_mouse_location().ToString());
+
+ // A mouse pointer will stay in 2nd display.
+ UpdateDisplay("300x300,200x300");
+ EXPECT_EQ("-50,150", env->last_mouse_location().ToString());
+
+ // A mouse pointer will be outside of displays and move to the
+ // center of 2nd display.
+ UpdateDisplay("300x300,200x100");
+ EXPECT_EQ("-100,50", env->last_mouse_location().ToString());
+
+ // 2nd display was disconnected. Mouse pointer should move to
+ // 1st display.
+ UpdateDisplay("300x300");
+ EXPECT_EQ("150,150", env->last_mouse_location().ToString());
+}
+
+// Test that the cursor swaps displays and that its scale factor and rotation
+// are updated when the primary display is swapped.
+TEST_F(DisplayControllerTest,
+ UpdateMouseLocationAfterDisplayChange_SwapPrimary) {
+ if (!SupportsMultipleDisplays())
+ return;
+
+ UpdateDisplay("200x200,200x200*2/r");
+
+ aura::Env* env = aura::Env::GetInstance();
+ Shell* shell = Shell::GetInstance();
+ DisplayController* display_controller = shell->display_controller();
+ test::CursorManagerTestApi test_api(shell->cursor_manager());
+
+ display_controller->GetPrimaryRootWindow()->MoveCursorTo(gfx::Point(20, 50));
+
+ EXPECT_EQ("20,50", env->last_mouse_location().ToString());
+ EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
+ EXPECT_EQ(gfx::Display::ROTATE_0, test_api.GetCurrentCursorRotation());
+
+ display_controller->SwapPrimaryDisplay();
+
+ EXPECT_EQ("20,50", env->last_mouse_location().ToString());
+ EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
+ EXPECT_EQ(gfx::Display::ROTATE_90, test_api.GetCurrentCursorRotation());
+}
+
+// Test that the cursor moves to the other display and that its scale factor
+// and rotation are updated when the primary display is disconnected.
+TEST_F(DisplayControllerTest,
+ UpdateMouseLocationAfterDisplayChange_PrimaryDisconnected) {
+ if (!SupportsMultipleDisplays())
+ return;
+
+ aura::Env* env = aura::Env::GetInstance();
+ Shell* shell = Shell::GetInstance();
+ DisplayController* display_controller = shell->display_controller();
+ test::CursorManagerTestApi test_api(shell->cursor_manager());
+
+ UpdateDisplay("300x300*2/r,200x200");
+ // Swap the primary display to make it possible to remove the primary display
+ // via UpdateDisplay().
+ display_controller->SwapPrimaryDisplay();
+ int primary_display_id = display_controller->GetPrimaryDisplayId();
+
+ display_controller->GetPrimaryRootWindow()->MoveCursorTo(gfx::Point(20, 50));
+
+ EXPECT_EQ("20,50", env->last_mouse_location().ToString());
+ EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
+ EXPECT_EQ(gfx::Display::ROTATE_0, test_api.GetCurrentCursorRotation());
+
+ UpdateDisplay("300x300*2/r");
+ ASSERT_NE(primary_display_id, display_controller->GetPrimaryDisplayId());
+
+ // Cursor should be centered on the remaining display.
+ EXPECT_EQ("75,75", env->last_mouse_location().ToString());
+ EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
+ EXPECT_EQ(gfx::Display::ROTATE_90, test_api.GetCurrentCursorRotation());
+}
+
} // namespace ash