Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 5 | #include "chrome/browser/extensions/api/system_display/display_info_provider.h" |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 6 | |
| 7 | #include "ash/display/display_controller.h" |
| 8 | #include "ash/display/display_manager.h" |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 9 | #include "ash/screen_ash.h" |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 10 | #include "ash/shell.h" |
| 11 | #include "ash/test/ash_test_base.h" |
| 12 | #include "ash/test/display_manager_test_api.h" |
| 13 | #include "base/strings/string_number_conversions.h" |
| 14 | #include "base/strings/stringprintf.h" |
| 15 | #include "ui/gfx/display.h" |
| 16 | #include "ui/gfx/rect.h" |
| 17 | |
| 18 | namespace extensions { |
| 19 | namespace { |
| 20 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 21 | void BindRequestDisplayInfoResult(DisplayInfo* target, bool success) { |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 22 | ASSERT_TRUE(success); |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 23 | *target = DisplayInfoProvider::Get()->display_info(); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | void BindSetDisplayUnitInfoResult(bool* success, |
| 27 | std::string* error, |
| 28 | bool success_in, |
| 29 | const std::string& error_in) { |
| 30 | *success = success_in; |
| 31 | *error = error_in; |
| 32 | } |
| 33 | |
| 34 | class DisplayInfoProviderChromeosTest : public ash::test::AshTestBase { |
| 35 | public: |
| 36 | DisplayInfoProviderChromeosTest() {} |
| 37 | |
| 38 | virtual ~DisplayInfoProviderChromeosTest() {} |
| 39 | |
| 40 | protected: |
| 41 | void CallRequestDisplayInfo(DisplayInfo* result) { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 42 | DisplayInfoProvider::Get()->RequestInfo( |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 43 | base::Bind(&BindRequestDisplayInfoResult, result)); |
| 44 | RunAllPendingInMessageLoop(); |
| 45 | } |
| 46 | |
| 47 | void CallSetDisplayUnitInfo( |
| 48 | const std::string& display_id, |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 49 | const api::system_display::DisplayProperties& info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 50 | bool* success, |
| 51 | std::string* error) { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 52 | DisplayInfoProvider::Get()->SetInfo(display_id, info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 53 | base::Bind(&BindSetDisplayUnitInfoResult, success, error)); |
| 54 | RunAllPendingInMessageLoop(); |
| 55 | } |
| 56 | |
| 57 | bool DisplayExists(int64 display_id) const { |
| 58 | const gfx::Display& display = |
| 59 | GetDisplayManager()->GetDisplayForId(display_id); |
| 60 | return display.id() != gfx::Display::kInvalidDisplayID; |
| 61 | } |
| 62 | |
| 63 | ash::internal::DisplayManager* GetDisplayManager() const { |
| 64 | return ash::Shell::GetInstance()->display_manager(); |
| 65 | } |
| 66 | |
| 67 | ash::DisplayController* GetDisplayController() const { |
| 68 | return ash::Shell::GetInstance()->display_controller(); |
| 69 | } |
| 70 | |
| 71 | std::string SystemInfoDisplayInsetsToString( |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 72 | const api::system_display::Insets& insets) const { |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 73 | // Order to match gfx::Insets::ToString(). |
| 74 | return base::StringPrintf("%d,%d,%d,%d", |
| 75 | insets.top, insets.left, insets.bottom, insets.right); |
| 76 | } |
| 77 | |
| 78 | std::string SystemInfoDisplayBoundsToString( |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 79 | const api::system_display::Bounds& bounds) const { |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 80 | // Order to match gfx::Rect::ToString(). |
| 81 | return base::StringPrintf("%d,%d %dx%d", |
| 82 | bounds.left, bounds.top, bounds.width, bounds.height); |
| 83 | } |
| 84 | |
| 85 | DISALLOW_COPY_AND_ASSIGN(DisplayInfoProviderChromeosTest); |
| 86 | }; |
| 87 | |
| 88 | TEST_F(DisplayInfoProviderChromeosTest, GetBasic) { |
| 89 | UpdateDisplay("500x600,400x520"); |
| 90 | DisplayInfo result; |
| 91 | CallRequestDisplayInfo(&result); |
| 92 | |
| 93 | ASSERT_EQ(2u, result.size()); |
| 94 | |
| 95 | int64 display_id; |
| 96 | ASSERT_TRUE(base::StringToInt64(result[0]->id, &display_id)) |
| 97 | << "Display id must be convertable to integer: " << result[0]->id; |
| 98 | |
| 99 | ASSERT_TRUE(DisplayExists(display_id)) << display_id << " not found"; |
| 100 | EXPECT_EQ("0,0 500x600", SystemInfoDisplayBoundsToString(result[0]->bounds)); |
| 101 | EXPECT_EQ("0,0,0,0", SystemInfoDisplayInsetsToString(result[0]->overscan)); |
| 102 | EXPECT_EQ(0, result[0]->rotation); |
| 103 | EXPECT_TRUE(result[0]->is_primary); |
| 104 | EXPECT_EQ(96, result[0]->dpi_x); |
| 105 | EXPECT_EQ(96, result[0]->dpi_y); |
| 106 | EXPECT_TRUE(result[0]->mirroring_source_id.empty()); |
| 107 | EXPECT_TRUE(result[0]->is_enabled); |
| 108 | |
| 109 | ASSERT_TRUE(base::StringToInt64(result[1]->id, &display_id)) |
| 110 | << "Display id must be convertable to integer: " << result[0]->id; |
| 111 | |
| 112 | ASSERT_TRUE(DisplayExists(display_id)) << display_id << " not found"; |
| 113 | EXPECT_EQ(GetDisplayManager()->GetDisplayNameForId(display_id), |
| 114 | result[1]->name); |
| 115 | // The second display is positioned left of the primary display, whose width |
| 116 | // is 500. |
| 117 | EXPECT_EQ("500,0 400x520", |
| 118 | SystemInfoDisplayBoundsToString(result[1]->bounds)); |
| 119 | EXPECT_EQ("0,0,0,0", SystemInfoDisplayInsetsToString(result[1]->overscan)); |
| 120 | EXPECT_EQ(0, result[1]->rotation); |
| 121 | EXPECT_FALSE(result[1]->is_primary); |
| 122 | EXPECT_EQ(96, result[1]->dpi_x); |
| 123 | EXPECT_EQ(96, result[1]->dpi_y); |
| 124 | EXPECT_TRUE(result[1]->mirroring_source_id.empty()); |
| 125 | EXPECT_TRUE(result[1]->is_enabled); |
| 126 | } |
| 127 | |
| 128 | TEST_F(DisplayInfoProviderChromeosTest, GetRotation) { |
| 129 | UpdateDisplay("500x600/r"); |
| 130 | DisplayInfo result; |
| 131 | CallRequestDisplayInfo(&result); |
| 132 | |
| 133 | ASSERT_EQ(1u, result.size()); |
| 134 | |
| 135 | int64 display_id; |
| 136 | ASSERT_TRUE(base::StringToInt64(result[0]->id, &display_id)) |
| 137 | << "Display id must be convertable to integer: " << result[0]->id; |
| 138 | |
| 139 | ASSERT_TRUE(DisplayExists(display_id)) << display_id << " not found"; |
| 140 | EXPECT_EQ("0,0 600x500", SystemInfoDisplayBoundsToString(result[0]->bounds)); |
| 141 | EXPECT_EQ(90, result[0]->rotation); |
| 142 | |
| 143 | GetDisplayManager()->SetDisplayRotation(display_id, gfx::Display::ROTATE_270); |
| 144 | |
| 145 | CallRequestDisplayInfo(&result); |
| 146 | |
| 147 | ASSERT_EQ(1u, result.size()); |
| 148 | |
| 149 | EXPECT_EQ(base::Int64ToString(display_id), result[0]->id); |
| 150 | EXPECT_EQ("0,0 600x500", SystemInfoDisplayBoundsToString(result[0]->bounds)); |
| 151 | EXPECT_EQ(270, result[0]->rotation); |
| 152 | |
| 153 | GetDisplayManager()->SetDisplayRotation(display_id, gfx::Display::ROTATE_180); |
| 154 | |
| 155 | CallRequestDisplayInfo(&result); |
| 156 | |
| 157 | ASSERT_EQ(1u, result.size()); |
| 158 | |
| 159 | EXPECT_EQ(base::Int64ToString(display_id), result[0]->id); |
| 160 | EXPECT_EQ("0,0 500x600", SystemInfoDisplayBoundsToString(result[0]->bounds)); |
| 161 | EXPECT_EQ(180, result[0]->rotation); |
| 162 | |
| 163 | GetDisplayManager()->SetDisplayRotation(display_id, gfx::Display::ROTATE_0); |
| 164 | |
| 165 | CallRequestDisplayInfo(&result); |
| 166 | |
| 167 | ASSERT_EQ(1u, result.size()); |
| 168 | |
| 169 | EXPECT_EQ(base::Int64ToString(display_id), result[0]->id); |
| 170 | EXPECT_EQ("0,0 500x600", SystemInfoDisplayBoundsToString(result[0]->bounds)); |
| 171 | EXPECT_EQ(0, result[0]->rotation); |
| 172 | } |
| 173 | |
| 174 | TEST_F(DisplayInfoProviderChromeosTest, GetHiDPI) { |
| 175 | UpdateDisplay("500x600,400x520*2"); |
| 176 | DisplayInfo result; |
| 177 | CallRequestDisplayInfo(&result); |
| 178 | |
| 179 | ASSERT_EQ(2u, result.size()); |
| 180 | |
| 181 | EXPECT_EQ("0,0 500x600", SystemInfoDisplayBoundsToString(result[0]->bounds)); |
| 182 | EXPECT_EQ(96, result[0]->dpi_x); |
| 183 | EXPECT_EQ(96, result[0]->dpi_y); |
| 184 | |
| 185 | EXPECT_EQ("500,0 200x260", |
| 186 | SystemInfoDisplayBoundsToString(result[1]->bounds)); |
| 187 | EXPECT_EQ(2 * 96, result[1]->dpi_x); |
| 188 | EXPECT_EQ(2 * 96, result[1]->dpi_y); |
| 189 | |
| 190 | GetDisplayController()->SwapPrimaryDisplay(); |
| 191 | |
| 192 | CallRequestDisplayInfo(&result); |
| 193 | |
| 194 | ASSERT_EQ(2u, result.size()); |
| 195 | |
| 196 | EXPECT_EQ("-500,0 500x600", |
| 197 | SystemInfoDisplayBoundsToString(result[0]->bounds)); |
| 198 | EXPECT_EQ(96, result[0]->dpi_x); |
| 199 | EXPECT_EQ(96, result[0]->dpi_y); |
| 200 | |
| 201 | EXPECT_EQ("0,0 200x260", SystemInfoDisplayBoundsToString(result[1]->bounds)); |
| 202 | EXPECT_EQ(2 * 96, result[1]->dpi_x); |
| 203 | EXPECT_EQ(2 * 96, result[1]->dpi_y); |
| 204 | } |
| 205 | |
| 206 | TEST_F(DisplayInfoProviderChromeosTest, GetVisibleArea) { |
| 207 | UpdateDisplay("640x720*2/o, 400x520/o"); |
| 208 | DisplayInfo result; |
| 209 | CallRequestDisplayInfo(&result); |
| 210 | |
| 211 | ASSERT_EQ(2u, result.size()); |
| 212 | |
| 213 | int64 display_id; |
| 214 | ASSERT_TRUE(base::StringToInt64(result[1]->id, &display_id)) |
| 215 | << "Display id must be convertable to integer: " << result[1]->id; |
| 216 | ASSERT_TRUE(DisplayExists(display_id)) << display_id << " not found"; |
| 217 | |
| 218 | // Default overscan is 5%. |
| 219 | EXPECT_EQ("304,0 380x494", |
| 220 | SystemInfoDisplayBoundsToString(result[1]->bounds)); |
| 221 | EXPECT_EQ("13,10,13,10", |
| 222 | SystemInfoDisplayInsetsToString(result[1]->overscan)); |
| 223 | |
| 224 | GetDisplayManager()->SetOverscanInsets(display_id, |
| 225 | gfx::Insets(20, 30, 50, 60)); |
| 226 | CallRequestDisplayInfo(&result); |
| 227 | |
| 228 | ASSERT_EQ(2u, result.size()); |
| 229 | |
| 230 | EXPECT_EQ(base::Int64ToString(display_id), result[1]->id); |
| 231 | EXPECT_EQ("304,0 310x450", |
| 232 | SystemInfoDisplayBoundsToString(result[1]->bounds)); |
| 233 | EXPECT_EQ("20,30,50,60", |
| 234 | SystemInfoDisplayInsetsToString(result[1]->overscan)); |
| 235 | |
| 236 | // Set insets for the primary screen. Note that it has 2x scale. |
| 237 | ASSERT_TRUE(base::StringToInt64(result[0]->id, &display_id)) |
| 238 | << "Display id must be convertable to integer: " << result[0]->id; |
| 239 | ASSERT_TRUE(DisplayExists(display_id)) << display_id << " not found"; |
| 240 | |
| 241 | EXPECT_EQ("0,0 304x342", SystemInfoDisplayBoundsToString(result[0]->bounds)); |
| 242 | EXPECT_EQ("9,8,9,8", SystemInfoDisplayInsetsToString(result[0]->overscan)); |
| 243 | |
| 244 | GetDisplayManager()->SetOverscanInsets(display_id, |
| 245 | gfx::Insets(10, 20, 30, 40)); |
| 246 | CallRequestDisplayInfo(&result); |
| 247 | |
| 248 | ASSERT_EQ(2u, result.size()); |
| 249 | |
| 250 | EXPECT_EQ(base::Int64ToString(display_id), result[0]->id); |
| 251 | EXPECT_EQ("0,0 260x320", SystemInfoDisplayBoundsToString(result[0]->bounds)); |
| 252 | EXPECT_EQ("10,20,30,40", |
| 253 | SystemInfoDisplayInsetsToString(result[0]->overscan)); |
| 254 | } |
| 255 | |
| 256 | TEST_F(DisplayInfoProviderChromeosTest, GetMirroring) { |
| 257 | UpdateDisplay("600x600, 400x520/o"); |
| 258 | DisplayInfo result; |
| 259 | CallRequestDisplayInfo(&result); |
| 260 | |
| 261 | ASSERT_EQ(2u, result.size()); |
| 262 | |
| 263 | int64 display_id_primary; |
| 264 | ASSERT_TRUE(base::StringToInt64(result[0]->id, &display_id_primary)) |
| 265 | << "Display id must be convertable to integer: " << result[0]->id; |
| 266 | ASSERT_TRUE(DisplayExists(display_id_primary)) |
| 267 | << display_id_primary << " not found"; |
| 268 | |
| 269 | int64 display_id_secondary; |
| 270 | ASSERT_TRUE(base::StringToInt64(result[1]->id, &display_id_secondary)) |
| 271 | << "Display id must be convertable to integer: " << result[1]->id; |
| 272 | ASSERT_TRUE(DisplayExists(display_id_secondary)) |
| 273 | << display_id_secondary << " not found"; |
| 274 | |
| 275 | ASSERT_FALSE(GetDisplayManager()->IsMirrored()); |
| 276 | EXPECT_TRUE(result[0]->mirroring_source_id.empty()); |
| 277 | EXPECT_TRUE(result[1]->mirroring_source_id.empty()); |
| 278 | |
| 279 | GetDisplayManager()->SetMirrorMode(true); |
| 280 | ASSERT_TRUE(GetDisplayManager()->IsMirrored()); |
| 281 | |
| 282 | CallRequestDisplayInfo(&result); |
| 283 | |
| 284 | ASSERT_EQ(1u, result.size()); |
| 285 | EXPECT_EQ(base::Int64ToString(display_id_primary), result[0]->id); |
| 286 | EXPECT_EQ(base::Int64ToString(display_id_secondary), |
| 287 | result[0]->mirroring_source_id); |
| 288 | |
| 289 | GetDisplayManager()->SetMirrorMode(false); |
| 290 | ASSERT_FALSE(GetDisplayManager()->IsMirrored()); |
| 291 | |
| 292 | CallRequestDisplayInfo(&result); |
| 293 | |
| 294 | ASSERT_EQ(2u, result.size()); |
| 295 | EXPECT_EQ(base::Int64ToString(display_id_primary), result[0]->id); |
| 296 | EXPECT_TRUE(result[0]->mirroring_source_id.empty()); |
| 297 | EXPECT_EQ(base::Int64ToString(display_id_secondary), result[1]->id); |
| 298 | EXPECT_TRUE(result[1]->mirroring_source_id.empty()); |
| 299 | } |
| 300 | |
| 301 | TEST_F(DisplayInfoProviderChromeosTest, GetBounds) { |
| 302 | UpdateDisplay("600x600, 400x520"); |
| 303 | GetDisplayController()->SetLayoutForCurrentDisplays( |
| 304 | ash::DisplayLayout::FromInts(ash::DisplayLayout::LEFT, -40)); |
| 305 | |
| 306 | DisplayInfo result; |
| 307 | CallRequestDisplayInfo(&result); |
| 308 | ASSERT_EQ(2u, result.size()); |
| 309 | EXPECT_EQ("0,0 600x600", SystemInfoDisplayBoundsToString(result[0]->bounds)); |
| 310 | EXPECT_EQ("-400,-40 400x520", |
| 311 | SystemInfoDisplayBoundsToString(result[1]->bounds)); |
| 312 | |
| 313 | GetDisplayController()->SetLayoutForCurrentDisplays( |
| 314 | ash::DisplayLayout::FromInts(ash::DisplayLayout::TOP, 40)); |
| 315 | |
| 316 | CallRequestDisplayInfo(&result); |
| 317 | ASSERT_EQ(2u, result.size()); |
| 318 | EXPECT_EQ("0,0 600x600", SystemInfoDisplayBoundsToString(result[0]->bounds)); |
| 319 | EXPECT_EQ("40,-520 400x520", |
| 320 | SystemInfoDisplayBoundsToString(result[1]->bounds)); |
| 321 | |
| 322 | GetDisplayController()->SetLayoutForCurrentDisplays( |
| 323 | ash::DisplayLayout::FromInts(ash::DisplayLayout::BOTTOM, 80)); |
| 324 | |
| 325 | CallRequestDisplayInfo(&result); |
| 326 | ASSERT_EQ(2u, result.size()); |
| 327 | EXPECT_EQ("0,0 600x600", SystemInfoDisplayBoundsToString(result[0]->bounds)); |
| 328 | EXPECT_EQ("80,600 400x520", |
| 329 | SystemInfoDisplayBoundsToString(result[1]->bounds)); |
| 330 | } |
| 331 | |
| 332 | TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginLeftExact) { |
| 333 | UpdateDisplay("1200x600,520x400"); |
| 334 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 335 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 336 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 337 | info.bounds_origin_x.reset(new int(-520)); |
| 338 | info.bounds_origin_y.reset(new int(50)); |
| 339 | |
| 340 | bool success = false; |
| 341 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 342 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 343 | &success, &error); |
| 344 | |
| 345 | ASSERT_TRUE(success); |
| 346 | ASSERT_TRUE(error.empty()); |
| 347 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 348 | EXPECT_EQ("-520,50 520x400", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginRightExact) { |
| 352 | UpdateDisplay("1200x600,520x400"); |
| 353 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 354 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 355 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 356 | info.bounds_origin_x.reset(new int(1200)); |
| 357 | info.bounds_origin_y.reset(new int(100)); |
| 358 | |
| 359 | bool success = false; |
| 360 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 361 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 362 | &success, &error); |
| 363 | |
| 364 | ASSERT_TRUE(success); |
| 365 | ASSERT_TRUE(error.empty()); |
| 366 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 367 | EXPECT_EQ("1200,100 520x400", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginTopExact) { |
| 371 | UpdateDisplay("1200x600,520x400"); |
| 372 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 373 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 374 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 375 | info.bounds_origin_x.reset(new int(1100)); |
| 376 | info.bounds_origin_y.reset(new int(-400)); |
| 377 | |
| 378 | bool success = false; |
| 379 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 380 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 381 | &success, &error); |
| 382 | |
| 383 | ASSERT_TRUE(success); |
| 384 | ASSERT_TRUE(error.empty()); |
| 385 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 386 | EXPECT_EQ("1100,-400 520x400", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginBottomExact) { |
| 390 | UpdateDisplay("1200x600,520x400"); |
| 391 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 392 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 393 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 394 | info.bounds_origin_x.reset(new int(-350)); |
| 395 | info.bounds_origin_y.reset(new int(600)); |
| 396 | |
| 397 | bool success = false; |
| 398 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 399 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 400 | &success, &error); |
| 401 | |
| 402 | ASSERT_TRUE(success); |
| 403 | ASSERT_TRUE(error.empty()); |
| 404 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 405 | EXPECT_EQ("-350,600 520x400", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginSameCenter) { |
| 409 | UpdateDisplay("1200x600,520x400"); |
| 410 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 411 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 412 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 413 | info.bounds_origin_x.reset(new int(340)); |
| 414 | info.bounds_origin_y.reset(new int(100)); |
| 415 | |
| 416 | bool success = false; |
| 417 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 418 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 419 | &success, &error); |
| 420 | |
| 421 | ASSERT_TRUE(success); |
| 422 | ASSERT_TRUE(error.empty()); |
| 423 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 424 | EXPECT_EQ("1200,100 520x400", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginLeftOutside) { |
| 428 | UpdateDisplay("1200x600,520x400"); |
| 429 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 430 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 431 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 432 | info.bounds_origin_x.reset(new int(-1040)); |
| 433 | info.bounds_origin_y.reset(new int(100)); |
| 434 | |
| 435 | bool success = false; |
| 436 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 437 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 438 | &success, &error); |
| 439 | |
| 440 | ASSERT_TRUE(success); |
| 441 | ASSERT_TRUE(error.empty()); |
| 442 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 443 | EXPECT_EQ("-520,100 520x400", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginTopOutside) { |
| 447 | UpdateDisplay("1200x600,520x400"); |
| 448 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 449 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 450 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 451 | info.bounds_origin_x.reset(new int(-360)); |
| 452 | info.bounds_origin_y.reset(new int(-301)); |
| 453 | |
| 454 | bool success = false; |
| 455 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 456 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 457 | &success, &error); |
| 458 | |
| 459 | ASSERT_TRUE(success); |
| 460 | ASSERT_TRUE(error.empty()); |
| 461 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 462 | EXPECT_EQ("-360,-400 520x400", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | TEST_F(DisplayInfoProviderChromeosTest, |
| 466 | SetBoundsOriginLeftButSharesBottomSide) { |
| 467 | UpdateDisplay("1200x600,1000x100"); |
| 468 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 469 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 470 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 471 | info.bounds_origin_x.reset(new int(-650)); |
| 472 | info.bounds_origin_y.reset(new int(700)); |
| 473 | |
| 474 | bool success = false; |
| 475 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 476 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 477 | &success, &error); |
| 478 | |
| 479 | ASSERT_TRUE(success); |
| 480 | ASSERT_TRUE(error.empty()); |
| 481 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 482 | EXPECT_EQ("-650,600 1000x100", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | TEST_F(DisplayInfoProviderChromeosTest, |
| 486 | SetBoundsOriginRightButSharesTopSide) { |
| 487 | UpdateDisplay("1200x600,1000x100"); |
| 488 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 489 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 490 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 491 | info.bounds_origin_x.reset(new int(850)); |
| 492 | info.bounds_origin_y.reset(new int(-150)); |
| 493 | |
| 494 | bool success = false; |
| 495 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 496 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 497 | &success, &error); |
| 498 | |
| 499 | ASSERT_TRUE(success); |
| 500 | ASSERT_TRUE(error.empty()); |
| 501 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 502 | EXPECT_EQ("850,-100 1000x100", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | TEST_F(DisplayInfoProviderChromeosTest, |
| 506 | SetBoundsOriginTopButSharesLeftSide) { |
| 507 | UpdateDisplay("1200x600,1000x100/l"); |
| 508 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 509 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 510 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 511 | info.bounds_origin_x.reset(new int(-150)); |
| 512 | info.bounds_origin_y.reset(new int(-650)); |
| 513 | |
| 514 | bool success = false; |
| 515 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 516 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 517 | &success, &error); |
| 518 | |
| 519 | ASSERT_TRUE(success); |
| 520 | ASSERT_TRUE(error.empty()); |
| 521 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 522 | EXPECT_EQ("-100,-650 100x1000", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | TEST_F(DisplayInfoProviderChromeosTest, |
| 526 | SetBoundsOriginBottomButSharesRightSide) { |
| 527 | UpdateDisplay("1200x600,1000x100/l"); |
| 528 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 529 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 530 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 531 | info.bounds_origin_x.reset(new int(1350)); |
| 532 | info.bounds_origin_y.reset(new int(450)); |
| 533 | |
| 534 | bool success = false; |
| 535 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 536 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 537 | &success, &error); |
| 538 | |
| 539 | ASSERT_TRUE(success); |
| 540 | ASSERT_TRUE(error.empty()); |
| 541 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 542 | EXPECT_EQ("1200,450 100x1000", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginPrimaryHiDPI) { |
| 546 | UpdateDisplay("1200x600*2,500x500"); |
| 547 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 548 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 549 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 550 | info.bounds_origin_x.reset(new int(250)); |
| 551 | info.bounds_origin_y.reset(new int(-100)); |
| 552 | |
| 553 | bool success = false; |
| 554 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 555 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 556 | &success, &error); |
| 557 | |
| 558 | ASSERT_TRUE(success); |
| 559 | ASSERT_TRUE(error.empty()); |
| 560 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 561 | EXPECT_EQ("600,-100 500x500", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginSecondaryHiDPI) { |
| 565 | UpdateDisplay("1200x600,600x1000*2"); |
| 566 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 567 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 568 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 569 | info.bounds_origin_x.reset(new int(450)); |
| 570 | info.bounds_origin_y.reset(new int(-100)); |
| 571 | |
| 572 | bool success = false; |
| 573 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 574 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 575 | &success, &error); |
| 576 | |
| 577 | ASSERT_TRUE(success); |
| 578 | ASSERT_TRUE(error.empty()); |
| 579 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 580 | EXPECT_EQ("450,-500 300x500", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginOutOfBounds) { |
| 584 | UpdateDisplay("1200x600,600x1000*2"); |
| 585 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 586 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 587 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 588 | info.bounds_origin_x.reset(new int(0x200001)); |
| 589 | info.bounds_origin_y.reset(new int(-100)); |
| 590 | |
| 591 | bool success = false; |
| 592 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 593 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 594 | &success, &error); |
| 595 | |
| 596 | ASSERT_FALSE(success); |
| 597 | ASSERT_EQ("Bounds origin x out of bounds.", error); |
| 598 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 599 | EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginOutOfBoundsNegative) { |
| 603 | UpdateDisplay("1200x600,600x1000*2"); |
| 604 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 605 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 606 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 607 | info.bounds_origin_x.reset(new int(300)); |
| 608 | info.bounds_origin_y.reset(new int(-0x200001)); |
| 609 | |
| 610 | bool success = false; |
| 611 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 612 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 613 | &success, &error); |
| 614 | |
| 615 | ASSERT_FALSE(success); |
| 616 | ASSERT_EQ("Bounds origin y out of bounds.", error); |
| 617 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 618 | EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginMaxValues) { |
| 622 | UpdateDisplay("1200x4600,600x1000*2"); |
| 623 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 624 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 625 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 626 | info.bounds_origin_x.reset(new int(200000)); |
| 627 | info.bounds_origin_y.reset(new int(10)); |
| 628 | |
| 629 | bool success = false; |
| 630 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 631 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 632 | &success, &error); |
| 633 | |
| 634 | ASSERT_TRUE(success); |
| 635 | EXPECT_TRUE(error.empty()); |
| 636 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 637 | EXPECT_EQ("1200,10 300x500", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginOnPrimary) { |
| 641 | UpdateDisplay("1200x600,600x1000*2"); |
| 642 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 643 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 644 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 645 | info.bounds_origin_x.reset(new int(300)); |
| 646 | info.is_primary.reset(new bool(true)); |
| 647 | |
| 648 | bool success = false; |
| 649 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 650 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 651 | &success, &error); |
| 652 | |
| 653 | ASSERT_FALSE(success); |
| 654 | ASSERT_EQ("Bounds origin not allowed for the primary display.", error); |
| 655 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 656 | EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 657 | // The operation failed because the primary property would be set before |
| 658 | // setting bounds. The primary display shouldn't have been changed, though. |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 659 | EXPECT_NE(ash::DisplayController::GetPrimaryDisplay().id(), secondary.id()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginWithMirroring) { |
| 663 | UpdateDisplay("1200x600,600x1000*2"); |
| 664 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 665 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 666 | const gfx::Display& primary = GetDisplayController()->GetPrimaryDisplay(); |
| 667 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 668 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 669 | info.bounds_origin_x.reset(new int(300)); |
| 670 | info.mirroring_source_id.reset( |
| 671 | new std::string(base::Int64ToString(primary.id()))); |
| 672 | |
| 673 | bool success = false; |
| 674 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 675 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 676 | &success, &error); |
| 677 | |
| 678 | ASSERT_FALSE(success); |
| 679 | ASSERT_EQ("No other parameter should be set alongside mirroringSourceId.", |
| 680 | error); |
| 681 | } |
| 682 | |
| 683 | TEST_F(DisplayInfoProviderChromeosTest, SetRotation) { |
| 684 | UpdateDisplay("1200x600,600x1000*2"); |
| 685 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 686 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 687 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 688 | info.rotation.reset(new int(90)); |
| 689 | |
| 690 | bool success = false; |
| 691 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 692 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 693 | &success, &error); |
| 694 | |
| 695 | ASSERT_TRUE(success); |
| 696 | EXPECT_TRUE(error.empty()); |
| 697 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 698 | EXPECT_EQ("1200,0 500x300", secondary.bounds().ToString()); |
| 699 | EXPECT_EQ(gfx::Display::ROTATE_90, secondary.rotation()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 700 | |
| 701 | info.rotation.reset(new int(270)); |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 702 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 703 | &success, &error); |
| 704 | |
| 705 | ASSERT_TRUE(success); |
| 706 | EXPECT_TRUE(error.empty()); |
| 707 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 708 | EXPECT_EQ("1200,0 500x300", secondary.bounds().ToString()); |
| 709 | EXPECT_EQ(gfx::Display::ROTATE_270, secondary.rotation()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 710 | |
| 711 | info.rotation.reset(new int(180)); |
| 712 | // Switch primary display. |
| 713 | info.is_primary.reset(new bool(true)); |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 714 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 715 | &success, &error); |
| 716 | |
| 717 | ASSERT_TRUE(success); |
| 718 | EXPECT_TRUE(error.empty()); |
| 719 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 720 | EXPECT_EQ("0,0 300x500", secondary.bounds().ToString()); |
| 721 | EXPECT_EQ(gfx::Display::ROTATE_180, secondary.rotation()); |
| 722 | EXPECT_EQ(ash::DisplayController::GetPrimaryDisplay().id(), secondary.id()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 723 | |
| 724 | info.rotation.reset(new int(0)); |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 725 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 726 | &success, &error); |
| 727 | |
| 728 | ASSERT_TRUE(success); |
| 729 | EXPECT_TRUE(error.empty()); |
| 730 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 731 | EXPECT_EQ("0,0 300x500", secondary.bounds().ToString()); |
| 732 | EXPECT_EQ(gfx::Display::ROTATE_0, secondary.rotation()); |
| 733 | EXPECT_EQ(ash::DisplayController::GetPrimaryDisplay().id(), secondary.id()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | TEST_F(DisplayInfoProviderChromeosTest, SetInvalidRotation) { |
| 737 | UpdateDisplay("1200x600,600x1000*2"); |
| 738 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 739 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 740 | api::system_display::DisplayProperties info; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 741 | info.rotation.reset(new int(91)); |
| 742 | |
| 743 | bool success = false; |
| 744 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 745 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 746 | &success, &error); |
| 747 | |
| 748 | ASSERT_FALSE(success); |
| 749 | EXPECT_EQ("Invalid rotation.", error); |
| 750 | } |
| 751 | |
| 752 | TEST_F(DisplayInfoProviderChromeosTest, SetNegativeOverscan) { |
| 753 | UpdateDisplay("1200x600,600x1000*2"); |
| 754 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 755 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 756 | api::system_display::DisplayProperties info; |
| 757 | info.overscan.reset(new api::system_display::Insets); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 758 | info.overscan->left= -10; |
| 759 | |
| 760 | bool success = false; |
| 761 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 762 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 763 | &success, &error); |
| 764 | |
| 765 | ASSERT_FALSE(success); |
| 766 | EXPECT_EQ("Negative overscan not allowed.", error); |
| 767 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 768 | EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 769 | |
| 770 | info.overscan->left= 0; |
| 771 | info.overscan->right = -200; |
| 772 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 773 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 774 | &success, &error); |
| 775 | |
| 776 | ASSERT_FALSE(success); |
| 777 | EXPECT_EQ("Negative overscan not allowed.", error); |
| 778 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 779 | EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 780 | |
| 781 | info.overscan->right= 0; |
| 782 | info.overscan->top = -300; |
| 783 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 784 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 785 | &success, &error); |
| 786 | |
| 787 | ASSERT_FALSE(success); |
| 788 | EXPECT_EQ("Negative overscan not allowed.", error); |
| 789 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 790 | EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 791 | |
| 792 | info.overscan->right= 0; |
| 793 | info.overscan->top = -1000; |
| 794 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 795 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 796 | &success, &error); |
| 797 | |
| 798 | ASSERT_FALSE(success); |
| 799 | EXPECT_EQ("Negative overscan not allowed.", error); |
| 800 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 801 | EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 802 | |
| 803 | info.overscan->right= 0; |
| 804 | info.overscan->top = 0; |
| 805 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 806 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 807 | &success, &error); |
| 808 | |
| 809 | ASSERT_TRUE(success); |
| 810 | EXPECT_TRUE(error.empty()); |
| 811 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 812 | EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | TEST_F(DisplayInfoProviderChromeosTest, SetOverscanLargerThanHorizontalBounds) { |
| 816 | UpdateDisplay("1200x600,600x1000*2"); |
| 817 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 818 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 819 | api::system_display::DisplayProperties info; |
| 820 | info.overscan.reset(new api::system_display::Insets); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 821 | // Horizontal overscan is 151, which would make the bounds width 149. |
| 822 | info.overscan->left= 50; |
| 823 | info.overscan->top = 10; |
| 824 | info.overscan->right = 101; |
| 825 | info.overscan->bottom = 20; |
| 826 | |
| 827 | bool success = false; |
| 828 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 829 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 830 | &success, &error); |
| 831 | |
| 832 | ASSERT_FALSE(success); |
| 833 | EXPECT_EQ("Horizontal overscan is more than half of the screen width.", |
| 834 | error); |
| 835 | } |
| 836 | |
| 837 | TEST_F(DisplayInfoProviderChromeosTest, SetOverscanLargerThanVerticalBounds) { |
| 838 | UpdateDisplay("1200x600,600x1000"); |
| 839 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 840 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 841 | api::system_display::DisplayProperties info; |
| 842 | info.overscan.reset(new api::system_display::Insets); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 843 | // Vertical overscan is 501, which would make the bounds height 499. |
| 844 | info.overscan->left= 20; |
| 845 | info.overscan->top = 250; |
| 846 | info.overscan->right = 101; |
| 847 | info.overscan->bottom = 251; |
| 848 | |
| 849 | bool success = false; |
| 850 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 851 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 852 | &success, &error); |
| 853 | |
| 854 | ASSERT_FALSE(success); |
| 855 | EXPECT_EQ("Vertical overscan is more than half of the screen height.", |
| 856 | error); |
| 857 | } |
| 858 | |
| 859 | TEST_F(DisplayInfoProviderChromeosTest, SetOverscan) { |
| 860 | UpdateDisplay("1200x600,600x1000*2"); |
| 861 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 862 | const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay(); |
| 863 | api::system_display::DisplayProperties info; |
| 864 | info.overscan.reset(new api::system_display::Insets); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 865 | info.overscan->left= 20; |
| 866 | info.overscan->top = 199; |
| 867 | info.overscan->right = 130; |
| 868 | info.overscan->bottom = 51; |
| 869 | |
| 870 | bool success = false; |
| 871 | std::string error; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 872 | CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 873 | &success, &error); |
| 874 | |
| 875 | ASSERT_TRUE(success); |
| 876 | EXPECT_TRUE(error.empty()); |
| 877 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 878 | EXPECT_EQ("1200,0 150x250", secondary.bounds().ToString()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 879 | const gfx::Insets overscan = |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 880 | GetDisplayManager()->GetOverscanInsets(secondary.id()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 881 | |
| 882 | EXPECT_EQ(20, overscan.left()); |
| 883 | EXPECT_EQ(199, overscan.top()); |
| 884 | EXPECT_EQ(130, overscan.right()); |
| 885 | EXPECT_EQ(51, overscan.bottom()); |
| 886 | } |
| 887 | |
| 888 | TEST_F(DisplayInfoProviderChromeosTest, SetOverscanForInternal) { |
| 889 | UpdateDisplay("1200x600,600x1000*2"); |
| 890 | const int64 internal_display_id = |
| 891 | ash::test::DisplayManagerTestApi(GetDisplayManager()). |
| 892 | SetFirstDisplayAsInternalDisplay(); |
| 893 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 894 | api::system_display::DisplayProperties info; |
| 895 | info.overscan.reset(new api::system_display::Insets); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 896 | // Vertical overscan is 501, which would make the bounds height 499. |
| 897 | info.overscan->left= 20; |
| 898 | info.overscan->top = 20; |
| 899 | info.overscan->right = 20; |
| 900 | info.overscan->bottom = 20; |
| 901 | |
| 902 | bool success = false; |
| 903 | std::string error; |
| 904 | CallSetDisplayUnitInfo(base::Int64ToString(internal_display_id), info, |
| 905 | &success, &error); |
| 906 | |
| 907 | ASSERT_FALSE(success); |
| 908 | EXPECT_EQ("Overscan changes not allowed for the internal monitor.", |
| 909 | error); |
| 910 | } |
| 911 | |
| 912 | } // namespace |
| 913 | } // namespace extensions |