| OLD | NEW |
| 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_manager.h" | 5 #include "ash/display/display_manager.h" |
| 6 | 6 |
| 7 #include "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
| 8 #include "ash/display/display_layout_store.h" | 8 #include "ash/display/display_layout_store.h" |
| 9 #include "ash/screen_util.h" | 9 #include "ash/screen_util.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 display_manager()->SetOverscanInsets(display2_id, gfx::Insets(0, 0, 0, 0)); | 377 display_manager()->SetOverscanInsets(display2_id, gfx::Insets(0, 0, 0, 0)); |
| 378 EXPECT_EQ(1u, changed().size()); | 378 EXPECT_EQ(1u, changed().size()); |
| 379 EXPECT_EQ(display2_id, changed()[0].id()); | 379 EXPECT_EQ(display2_id, changed()[0].id()); |
| 380 } | 380 } |
| 381 | 381 |
| 382 TEST_F(DisplayManagerTest, TestDeviceScaleOnlyChange) { | 382 TEST_F(DisplayManagerTest, TestDeviceScaleOnlyChange) { |
| 383 if (!SupportsHostWindowResize()) | 383 if (!SupportsHostWindowResize()) |
| 384 return; | 384 return; |
| 385 | 385 |
| 386 UpdateDisplay("1000x600"); | 386 UpdateDisplay("1000x600"); |
| 387 aura::WindowEventDispatcher* dispatcher = | 387 aura::WindowTreeHost* host = Shell::GetPrimaryRootWindow()->GetHost(); |
| 388 Shell::GetPrimaryRootWindow()->GetDispatcher(); | 388 EXPECT_EQ(1, host->compositor()->device_scale_factor()); |
| 389 EXPECT_EQ(1, dispatcher->host()->compositor()->device_scale_factor()); | |
| 390 EXPECT_EQ("1000x600", | 389 EXPECT_EQ("1000x600", |
| 391 Shell::GetPrimaryRootWindow()->bounds().size().ToString()); | 390 Shell::GetPrimaryRootWindow()->bounds().size().ToString()); |
| 392 UpdateDisplay("1000x600*2"); | 391 UpdateDisplay("1000x600*2"); |
| 393 EXPECT_EQ(2, dispatcher->host()->compositor()->device_scale_factor()); | 392 EXPECT_EQ(2, host->compositor()->device_scale_factor()); |
| 394 EXPECT_EQ("500x300", | 393 EXPECT_EQ("500x300", |
| 395 Shell::GetPrimaryRootWindow()->bounds().size().ToString()); | 394 Shell::GetPrimaryRootWindow()->bounds().size().ToString()); |
| 396 } | 395 } |
| 397 | 396 |
| 398 DisplayInfo CreateDisplayInfo(int64 id, const gfx::Rect& bounds) { | 397 DisplayInfo CreateDisplayInfo(int64 id, const gfx::Rect& bounds) { |
| 399 DisplayInfo info(id, ToDisplayName(id), false); | 398 DisplayInfo info(id, ToDisplayName(id), false); |
| 400 info.SetBounds(bounds); | 399 info.SetBounds(bounds); |
| 401 return info; | 400 return info; |
| 402 } | 401 } |
| 403 | 402 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | 584 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 586 | 585 |
| 587 // Connect another display which will become primary. | 586 // Connect another display which will become primary. |
| 588 const DisplayInfo external_display_info = | 587 const DisplayInfo external_display_info = |
| 589 CreateDisplayInfo(10, gfx::Rect(1, 1, 100, 100)); | 588 CreateDisplayInfo(10, gfx::Rect(1, 1, 100, 100)); |
| 590 display_info_list.push_back(external_display_info); | 589 display_info_list.push_back(external_display_info); |
| 591 display_manager()->OnNativeDisplaysChanged(display_info_list); | 590 display_manager()->OnNativeDisplaysChanged(display_info_list); |
| 592 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | 591 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 593 EXPECT_EQ("1,1 100x100", | 592 EXPECT_EQ("1,1 100x100", |
| 594 GetDisplayInfoForId(10).bounds_in_native().ToString()); | 593 GetDisplayInfoForId(10).bounds_in_native().ToString()); |
| 595 EXPECT_EQ("100x100", ash::Shell::GetPrimaryRootWindow()->GetDispatcher()-> | 594 EXPECT_EQ("100x100", ash::Shell::GetPrimaryRootWindow()->GetHost()-> |
| 596 host()->GetBounds().size().ToString()); | 595 GetBounds().size().ToString()); |
| 597 } | 596 } |
| 598 | 597 |
| 599 #if defined(OS_WIN) | 598 #if defined(OS_WIN) |
| 600 // Tests that rely on the actual host size/location does not work on windows. | 599 // Tests that rely on the actual host size/location does not work on windows. |
| 601 #define MAYBE_EnsurePointerInDisplays DISABLED_EnsurePointerInDisplays | 600 #define MAYBE_EnsurePointerInDisplays DISABLED_EnsurePointerInDisplays |
| 602 #define MAYBE_EnsurePointerInDisplays_2ndOnLeft DISABLED_EnsurePointerInDisplays
_2ndOnLeft | 601 #define MAYBE_EnsurePointerInDisplays_2ndOnLeft DISABLED_EnsurePointerInDisplays
_2ndOnLeft |
| 603 #else | 602 #else |
| 604 #define MAYBE_EnsurePointerInDisplays EnsurePointerInDisplays | 603 #define MAYBE_EnsurePointerInDisplays EnsurePointerInDisplays |
| 605 #define MAYBE_EnsurePointerInDisplays_2ndOnLeft EnsurePointerInDisplays_2ndOnLef
t | 604 #define MAYBE_EnsurePointerInDisplays_2ndOnLeft EnsurePointerInDisplays_2ndOnLef
t |
| 606 #endif | 605 #endif |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 class TestDisplayObserver : public gfx::DisplayObserver { | 1006 class TestDisplayObserver : public gfx::DisplayObserver { |
| 1008 public: | 1007 public: |
| 1009 TestDisplayObserver() : changed_(false) {} | 1008 TestDisplayObserver() : changed_(false) {} |
| 1010 virtual ~TestDisplayObserver() {} | 1009 virtual ~TestDisplayObserver() {} |
| 1011 | 1010 |
| 1012 // gfx::DisplayObserver overrides: | 1011 // gfx::DisplayObserver overrides: |
| 1013 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE { | 1012 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE { |
| 1014 } | 1013 } |
| 1015 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE { | 1014 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE { |
| 1016 // Mirror window should already be delete before restoring | 1015 // Mirror window should already be delete before restoring |
| 1017 // the external dispay. | 1016 // the external display. |
| 1018 EXPECT_FALSE(test_api.GetDispatcher()); | 1017 EXPECT_FALSE(test_api.GetHost()); |
| 1019 changed_ = true; | 1018 changed_ = true; |
| 1020 } | 1019 } |
| 1021 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE { | 1020 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE { |
| 1022 // Mirror window should not be created until the external display | 1021 // Mirror window should not be created until the external display |
| 1023 // is removed. | 1022 // is removed. |
| 1024 EXPECT_FALSE(test_api.GetDispatcher()); | 1023 EXPECT_FALSE(test_api.GetHost()); |
| 1025 changed_ = true; | 1024 changed_ = true; |
| 1026 } | 1025 } |
| 1027 | 1026 |
| 1028 bool changed_and_reset() { | 1027 bool changed_and_reset() { |
| 1029 bool changed = changed_; | 1028 bool changed = changed_; |
| 1030 changed_ = false; | 1029 changed_ = false; |
| 1031 return changed; | 1030 return changed; |
| 1032 } | 1031 } |
| 1033 | 1032 |
| 1034 private: | 1033 private: |
| 1035 test::MirrorWindowTestApi test_api; | 1034 test::MirrorWindowTestApi test_api; |
| 1036 bool changed_; | 1035 bool changed_; |
| 1037 | 1036 |
| 1038 DISALLOW_COPY_AND_ASSIGN(TestDisplayObserver); | 1037 DISALLOW_COPY_AND_ASSIGN(TestDisplayObserver); |
| 1039 }; | 1038 }; |
| 1040 | 1039 |
| 1041 TEST_F(DisplayManagerTest, SoftwareMirroring) { | 1040 TEST_F(DisplayManagerTest, SoftwareMirroring) { |
| 1042 if (!SupportsMultipleDisplays()) | 1041 if (!SupportsMultipleDisplays()) |
| 1043 return; | 1042 return; |
| 1044 | 1043 |
| 1045 UpdateDisplay("300x400,400x500"); | 1044 UpdateDisplay("300x400,400x500"); |
| 1046 | 1045 |
| 1047 test::MirrorWindowTestApi test_api; | 1046 test::MirrorWindowTestApi test_api; |
| 1048 EXPECT_EQ(NULL, test_api.GetDispatcher()); | 1047 EXPECT_EQ(NULL, test_api.GetHost()); |
| 1049 | 1048 |
| 1050 TestDisplayObserver display_observer; | 1049 TestDisplayObserver display_observer; |
| 1051 Shell::GetScreen()->AddObserver(&display_observer); | 1050 Shell::GetScreen()->AddObserver(&display_observer); |
| 1052 | 1051 |
| 1053 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 1052 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 1054 display_manager->SetSecondDisplayMode(DisplayManager::MIRRORING); | 1053 display_manager->SetSecondDisplayMode(DisplayManager::MIRRORING); |
| 1055 display_manager->UpdateDisplays(); | 1054 display_manager->UpdateDisplays(); |
| 1056 EXPECT_TRUE(display_observer.changed_and_reset()); | 1055 EXPECT_TRUE(display_observer.changed_and_reset()); |
| 1057 EXPECT_EQ(1U, display_manager->GetNumDisplays()); | 1056 EXPECT_EQ(1U, display_manager->GetNumDisplays()); |
| 1058 EXPECT_EQ("0,0 300x400", | 1057 EXPECT_EQ("0,0 300x400", |
| 1059 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString()); | 1058 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString()); |
| 1060 EXPECT_EQ("400x500", | 1059 EXPECT_EQ("400x500", test_api.GetHost()->GetBounds().size().ToString()); |
| 1061 test_api.GetDispatcher()->host()->GetBounds().size().ToString()); | |
| 1062 EXPECT_EQ("300x400", | 1060 EXPECT_EQ("300x400", |
| 1063 test_api.GetDispatcher()->window()->bounds().size().ToString()); | 1061 test_api.GetHost()->window()->bounds().size().ToString()); |
| 1064 EXPECT_TRUE(display_manager->IsMirrored()); | 1062 EXPECT_TRUE(display_manager->IsMirrored()); |
| 1065 | 1063 |
| 1066 display_manager->SetMirrorMode(false); | 1064 display_manager->SetMirrorMode(false); |
| 1067 EXPECT_TRUE(display_observer.changed_and_reset()); | 1065 EXPECT_TRUE(display_observer.changed_and_reset()); |
| 1068 EXPECT_EQ(NULL, test_api.GetDispatcher()); | 1066 EXPECT_EQ(NULL, test_api.GetHost()); |
| 1069 EXPECT_EQ(2U, display_manager->GetNumDisplays()); | 1067 EXPECT_EQ(2U, display_manager->GetNumDisplays()); |
| 1070 EXPECT_FALSE(display_manager->IsMirrored()); | 1068 EXPECT_FALSE(display_manager->IsMirrored()); |
| 1071 | 1069 |
| 1072 // Make sure the mirror window has the pixel size of the | 1070 // Make sure the mirror window has the pixel size of the |
| 1073 // source display. | 1071 // source display. |
| 1074 display_manager->SetMirrorMode(true); | 1072 display_manager->SetMirrorMode(true); |
| 1075 EXPECT_TRUE(display_observer.changed_and_reset()); | 1073 EXPECT_TRUE(display_observer.changed_and_reset()); |
| 1076 | 1074 |
| 1077 UpdateDisplay("300x400@0.5,400x500"); | 1075 UpdateDisplay("300x400@0.5,400x500"); |
| 1078 EXPECT_FALSE(display_observer.changed_and_reset()); | 1076 EXPECT_FALSE(display_observer.changed_and_reset()); |
| 1079 EXPECT_EQ("300x400", | 1077 EXPECT_EQ("300x400", |
| 1080 test_api.GetDispatcher()->window()->bounds().size().ToString()); | 1078 test_api.GetHost()->window()->bounds().size().ToString()); |
| 1081 | 1079 |
| 1082 UpdateDisplay("310x410*2,400x500"); | 1080 UpdateDisplay("310x410*2,400x500"); |
| 1083 EXPECT_FALSE(display_observer.changed_and_reset()); | 1081 EXPECT_FALSE(display_observer.changed_and_reset()); |
| 1084 EXPECT_EQ("310x410", | 1082 EXPECT_EQ("310x410", |
| 1085 test_api.GetDispatcher()->window()->bounds().size().ToString()); | 1083 test_api.GetHost()->window()->bounds().size().ToString()); |
| 1086 | 1084 |
| 1087 UpdateDisplay("320x420/r,400x500"); | 1085 UpdateDisplay("320x420/r,400x500"); |
| 1088 EXPECT_FALSE(display_observer.changed_and_reset()); | 1086 EXPECT_FALSE(display_observer.changed_and_reset()); |
| 1089 EXPECT_EQ("320x420", | 1087 EXPECT_EQ("320x420", |
| 1090 test_api.GetDispatcher()->window()->bounds().size().ToString()); | 1088 test_api.GetHost()->window()->bounds().size().ToString()); |
| 1091 | 1089 |
| 1092 UpdateDisplay("330x440/r,400x500"); | 1090 UpdateDisplay("330x440/r,400x500"); |
| 1093 EXPECT_FALSE(display_observer.changed_and_reset()); | 1091 EXPECT_FALSE(display_observer.changed_and_reset()); |
| 1094 EXPECT_EQ("330x440", | 1092 EXPECT_EQ("330x440", |
| 1095 test_api.GetDispatcher()->window()->bounds().size().ToString()); | 1093 test_api.GetHost()->window()->bounds().size().ToString()); |
| 1096 | 1094 |
| 1097 // Overscan insets are ignored. | 1095 // Overscan insets are ignored. |
| 1098 UpdateDisplay("400x600/o,600x800/o"); | 1096 UpdateDisplay("400x600/o,600x800/o"); |
| 1099 EXPECT_FALSE(display_observer.changed_and_reset()); | 1097 EXPECT_FALSE(display_observer.changed_and_reset()); |
| 1100 EXPECT_EQ("400x600", | 1098 EXPECT_EQ("400x600", |
| 1101 test_api.GetDispatcher()->window()->bounds().size().ToString()); | 1099 test_api.GetHost()->window()->bounds().size().ToString()); |
| 1102 | 1100 |
| 1103 Shell::GetScreen()->RemoveObserver(&display_observer); | 1101 Shell::GetScreen()->RemoveObserver(&display_observer); |
| 1104 } | 1102 } |
| 1105 | 1103 |
| 1106 TEST_F(DisplayManagerTest, MirroredLayout) { | 1104 TEST_F(DisplayManagerTest, MirroredLayout) { |
| 1107 if (!SupportsMultipleDisplays()) | 1105 if (!SupportsMultipleDisplays()) |
| 1108 return; | 1106 return; |
| 1109 | 1107 |
| 1110 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 1108 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 1111 UpdateDisplay("500x500,400x400"); | 1109 UpdateDisplay("500x500,400x400"); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1161 #else | 1159 #else |
| 1162 #define MAYBE_UpdateDisplayWithHostOrigin UpdateDisplayWithHostOrigin | 1160 #define MAYBE_UpdateDisplayWithHostOrigin UpdateDisplayWithHostOrigin |
| 1163 #endif | 1161 #endif |
| 1164 | 1162 |
| 1165 TEST_F(DisplayManagerTest, MAYBE_UpdateDisplayWithHostOrigin) { | 1163 TEST_F(DisplayManagerTest, MAYBE_UpdateDisplayWithHostOrigin) { |
| 1166 UpdateDisplay("100x200,300x400"); | 1164 UpdateDisplay("100x200,300x400"); |
| 1167 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); | 1165 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); |
| 1168 aura::Window::Windows root_windows = | 1166 aura::Window::Windows root_windows = |
| 1169 Shell::GetInstance()->GetAllRootWindows(); | 1167 Shell::GetInstance()->GetAllRootWindows(); |
| 1170 ASSERT_EQ(2U, root_windows.size()); | 1168 ASSERT_EQ(2U, root_windows.size()); |
| 1171 aura::WindowEventDispatcher* dispatcher0 = root_windows[0]->GetDispatcher(); | 1169 aura::WindowTreeHost* host0 = root_windows[0]->GetHost(); |
| 1172 aura::WindowEventDispatcher* dispatcher1 = root_windows[1]->GetDispatcher(); | 1170 aura::WindowTreeHost* host1 = root_windows[1]->GetHost(); |
| 1173 | 1171 |
| 1174 EXPECT_EQ("1,1", dispatcher0->host()->GetBounds().origin().ToString()); | 1172 EXPECT_EQ("1,1", host0->GetBounds().origin().ToString()); |
| 1175 EXPECT_EQ("100x200", dispatcher0->host()->GetBounds().size().ToString()); | 1173 EXPECT_EQ("100x200", host0->GetBounds().size().ToString()); |
| 1176 // UpdateDisplay set the origin if it's not set. | 1174 // UpdateDisplay set the origin if it's not set. |
| 1177 EXPECT_NE("1,1", dispatcher1->host()->GetBounds().origin().ToString()); | 1175 EXPECT_NE("1,1", host1->GetBounds().origin().ToString()); |
| 1178 EXPECT_EQ("300x400", dispatcher1->host()->GetBounds().size().ToString()); | 1176 EXPECT_EQ("300x400", host1->GetBounds().size().ToString()); |
| 1179 | 1177 |
| 1180 UpdateDisplay("100x200,200+300-300x400"); | 1178 UpdateDisplay("100x200,200+300-300x400"); |
| 1181 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); | 1179 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); |
| 1182 EXPECT_EQ("0,0", dispatcher0->host()->GetBounds().origin().ToString()); | 1180 EXPECT_EQ("0,0", host0->GetBounds().origin().ToString()); |
| 1183 EXPECT_EQ("100x200", dispatcher0->host()->GetBounds().size().ToString()); | 1181 EXPECT_EQ("100x200", host0->GetBounds().size().ToString()); |
| 1184 EXPECT_EQ("200,300", dispatcher1->host()->GetBounds().origin().ToString()); | 1182 EXPECT_EQ("200,300", host1->GetBounds().origin().ToString()); |
| 1185 EXPECT_EQ("300x400", dispatcher1->host()->GetBounds().size().ToString()); | 1183 EXPECT_EQ("300x400", host1->GetBounds().size().ToString()); |
| 1186 | 1184 |
| 1187 UpdateDisplay("400+500-200x300,300x400"); | 1185 UpdateDisplay("400+500-200x300,300x400"); |
| 1188 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); | 1186 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); |
| 1189 EXPECT_EQ("400,500", dispatcher0->host()->GetBounds().origin().ToString()); | 1187 EXPECT_EQ("400,500", host0->GetBounds().origin().ToString()); |
| 1190 EXPECT_EQ("200x300", dispatcher0->host()->GetBounds().size().ToString()); | 1188 EXPECT_EQ("200x300", host0->GetBounds().size().ToString()); |
| 1191 EXPECT_EQ("0,0", dispatcher1->host()->GetBounds().origin().ToString()); | 1189 EXPECT_EQ("0,0", host1->GetBounds().origin().ToString()); |
| 1192 EXPECT_EQ("300x400", dispatcher1->host()->GetBounds().size().ToString()); | 1190 EXPECT_EQ("300x400", host1->GetBounds().size().ToString()); |
| 1193 | 1191 |
| 1194 UpdateDisplay("100+200-100x200,300+500-200x300"); | 1192 UpdateDisplay("100+200-100x200,300+500-200x300"); |
| 1195 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); | 1193 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); |
| 1196 EXPECT_EQ("100,200", dispatcher0->host()->GetBounds().origin().ToString()); | 1194 EXPECT_EQ("100,200", host0->GetBounds().origin().ToString()); |
| 1197 EXPECT_EQ("100x200", dispatcher0->host()->GetBounds().size().ToString()); | 1195 EXPECT_EQ("100x200", host0->GetBounds().size().ToString()); |
| 1198 EXPECT_EQ("300,500", dispatcher1->host()->GetBounds().origin().ToString()); | 1196 EXPECT_EQ("300,500", host1->GetBounds().origin().ToString()); |
| 1199 EXPECT_EQ("200x300", dispatcher1->host()->GetBounds().size().ToString()); | 1197 EXPECT_EQ("200x300", host1->GetBounds().size().ToString()); |
| 1200 } | 1198 } |
| 1201 | 1199 |
| 1202 | 1200 |
| 1203 class ScreenShutdownTest : public test::AshTestBase { | 1201 class ScreenShutdownTest : public test::AshTestBase { |
| 1204 public: | 1202 public: |
| 1205 ScreenShutdownTest() { | 1203 ScreenShutdownTest() { |
| 1206 } | 1204 } |
| 1207 virtual ~ScreenShutdownTest() {} | 1205 virtual ~ScreenShutdownTest() {} |
| 1208 | 1206 |
| 1209 virtual void TearDown() OVERRIDE { | 1207 virtual void TearDown() OVERRIDE { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1227 }; | 1225 }; |
| 1228 | 1226 |
| 1229 TEST_F(ScreenShutdownTest, ScreenAfterShutdown) { | 1227 TEST_F(ScreenShutdownTest, ScreenAfterShutdown) { |
| 1230 if (!SupportsMultipleDisplays()) | 1228 if (!SupportsMultipleDisplays()) |
| 1231 return; | 1229 return; |
| 1232 UpdateDisplay("500x300,800x400"); | 1230 UpdateDisplay("500x300,800x400"); |
| 1233 } | 1231 } |
| 1234 | 1232 |
| 1235 } // namespace internal | 1233 } // namespace internal |
| 1236 } // namespace ash | 1234 } // namespace ash |
| OLD | NEW |