blob: e7a68e57b25c8015d5e66fcb65ccd02bda1cf5d8 [file] [log] [blame]
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +01001// 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 Murdochca12bfa2013-07-23 11:17:05 +01005#include "chrome/browser/extensions/api/system_display/display_info_provider.h"
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +01006
7#include "ash/display/display_controller.h"
8#include "ash/display/display_manager.h"
Ben Murdochca12bfa2013-07-23 11:17:05 +01009#include "ash/screen_ash.h"
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010010#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
18namespace extensions {
19namespace {
20
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010021void BindRequestDisplayInfoResult(DisplayInfo* target, bool success) {
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010022 ASSERT_TRUE(success);
Ben Murdochbb1529c2013-08-08 10:24:53 +010023 *target = DisplayInfoProvider::Get()->display_info();
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010024}
25
26void 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
34class DisplayInfoProviderChromeosTest : public ash::test::AshTestBase {
35 public:
36 DisplayInfoProviderChromeosTest() {}
37
38 virtual ~DisplayInfoProviderChromeosTest() {}
39
40 protected:
41 void CallRequestDisplayInfo(DisplayInfo* result) {
Ben Murdochbb1529c2013-08-08 10:24:53 +010042 DisplayInfoProvider::Get()->RequestInfo(
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010043 base::Bind(&BindRequestDisplayInfoResult, result));
44 RunAllPendingInMessageLoop();
45 }
46
47 void CallSetDisplayUnitInfo(
48 const std::string& display_id,
Ben Murdochca12bfa2013-07-23 11:17:05 +010049 const api::system_display::DisplayProperties& info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010050 bool* success,
51 std::string* error) {
Ben Murdochbb1529c2013-08-08 10:24:53 +010052 DisplayInfoProvider::Get()->SetInfo(display_id, info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010053 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 Murdochca12bfa2013-07-23 11:17:05 +010072 const api::system_display::Insets& insets) const {
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010073 // 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 Murdochca12bfa2013-07-23 11:17:05 +010079 const api::system_display::Bounds& bounds) const {
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010080 // 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
88TEST_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
128TEST_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
174TEST_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
206TEST_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
256TEST_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
301TEST_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
332TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginLeftExact) {
333 UpdateDisplay("1200x600,520x400");
334
Ben Murdochca12bfa2013-07-23 11:17:05 +0100335 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
336 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100337 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 Murdochca12bfa2013-07-23 11:17:05 +0100342 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100343 &success, &error);
344
345 ASSERT_TRUE(success);
346 ASSERT_TRUE(error.empty());
347
Ben Murdochca12bfa2013-07-23 11:17:05 +0100348 EXPECT_EQ("-520,50 520x400", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100349}
350
351TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginRightExact) {
352 UpdateDisplay("1200x600,520x400");
353
Ben Murdochca12bfa2013-07-23 11:17:05 +0100354 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
355 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100356 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 Murdochca12bfa2013-07-23 11:17:05 +0100361 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100362 &success, &error);
363
364 ASSERT_TRUE(success);
365 ASSERT_TRUE(error.empty());
366
Ben Murdochca12bfa2013-07-23 11:17:05 +0100367 EXPECT_EQ("1200,100 520x400", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100368}
369
370TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginTopExact) {
371 UpdateDisplay("1200x600,520x400");
372
Ben Murdochca12bfa2013-07-23 11:17:05 +0100373 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
374 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100375 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 Murdochca12bfa2013-07-23 11:17:05 +0100380 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100381 &success, &error);
382
383 ASSERT_TRUE(success);
384 ASSERT_TRUE(error.empty());
385
Ben Murdochca12bfa2013-07-23 11:17:05 +0100386 EXPECT_EQ("1100,-400 520x400", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100387}
388
389TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginBottomExact) {
390 UpdateDisplay("1200x600,520x400");
391
Ben Murdochca12bfa2013-07-23 11:17:05 +0100392 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
393 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100394 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 Murdochca12bfa2013-07-23 11:17:05 +0100399 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100400 &success, &error);
401
402 ASSERT_TRUE(success);
403 ASSERT_TRUE(error.empty());
404
Ben Murdochca12bfa2013-07-23 11:17:05 +0100405 EXPECT_EQ("-350,600 520x400", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100406}
407
408TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginSameCenter) {
409 UpdateDisplay("1200x600,520x400");
410
Ben Murdochca12bfa2013-07-23 11:17:05 +0100411 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
412 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100413 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 Murdochca12bfa2013-07-23 11:17:05 +0100418 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100419 &success, &error);
420
421 ASSERT_TRUE(success);
422 ASSERT_TRUE(error.empty());
423
Ben Murdochca12bfa2013-07-23 11:17:05 +0100424 EXPECT_EQ("1200,100 520x400", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100425}
426
427TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginLeftOutside) {
428 UpdateDisplay("1200x600,520x400");
429
Ben Murdochca12bfa2013-07-23 11:17:05 +0100430 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
431 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100432 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 Murdochca12bfa2013-07-23 11:17:05 +0100437 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100438 &success, &error);
439
440 ASSERT_TRUE(success);
441 ASSERT_TRUE(error.empty());
442
Ben Murdochca12bfa2013-07-23 11:17:05 +0100443 EXPECT_EQ("-520,100 520x400", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100444}
445
446TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginTopOutside) {
447 UpdateDisplay("1200x600,520x400");
448
Ben Murdochca12bfa2013-07-23 11:17:05 +0100449 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
450 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100451 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 Murdochca12bfa2013-07-23 11:17:05 +0100456 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100457 &success, &error);
458
459 ASSERT_TRUE(success);
460 ASSERT_TRUE(error.empty());
461
Ben Murdochca12bfa2013-07-23 11:17:05 +0100462 EXPECT_EQ("-360,-400 520x400", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100463}
464
465TEST_F(DisplayInfoProviderChromeosTest,
466 SetBoundsOriginLeftButSharesBottomSide) {
467 UpdateDisplay("1200x600,1000x100");
468
Ben Murdochca12bfa2013-07-23 11:17:05 +0100469 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
470 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100471 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 Murdochca12bfa2013-07-23 11:17:05 +0100476 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100477 &success, &error);
478
479 ASSERT_TRUE(success);
480 ASSERT_TRUE(error.empty());
481
Ben Murdochca12bfa2013-07-23 11:17:05 +0100482 EXPECT_EQ("-650,600 1000x100", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100483}
484
485TEST_F(DisplayInfoProviderChromeosTest,
486 SetBoundsOriginRightButSharesTopSide) {
487 UpdateDisplay("1200x600,1000x100");
488
Ben Murdochca12bfa2013-07-23 11:17:05 +0100489 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
490 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100491 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 Murdochca12bfa2013-07-23 11:17:05 +0100496 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100497 &success, &error);
498
499 ASSERT_TRUE(success);
500 ASSERT_TRUE(error.empty());
501
Ben Murdochca12bfa2013-07-23 11:17:05 +0100502 EXPECT_EQ("850,-100 1000x100", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100503}
504
505TEST_F(DisplayInfoProviderChromeosTest,
506 SetBoundsOriginTopButSharesLeftSide) {
507 UpdateDisplay("1200x600,1000x100/l");
508
Ben Murdochca12bfa2013-07-23 11:17:05 +0100509 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
510 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100511 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 Murdochca12bfa2013-07-23 11:17:05 +0100516 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100517 &success, &error);
518
519 ASSERT_TRUE(success);
520 ASSERT_TRUE(error.empty());
521
Ben Murdochca12bfa2013-07-23 11:17:05 +0100522 EXPECT_EQ("-100,-650 100x1000", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100523}
524
525TEST_F(DisplayInfoProviderChromeosTest,
526 SetBoundsOriginBottomButSharesRightSide) {
527 UpdateDisplay("1200x600,1000x100/l");
528
Ben Murdochca12bfa2013-07-23 11:17:05 +0100529 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
530 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100531 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 Murdochca12bfa2013-07-23 11:17:05 +0100536 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100537 &success, &error);
538
539 ASSERT_TRUE(success);
540 ASSERT_TRUE(error.empty());
541
Ben Murdochca12bfa2013-07-23 11:17:05 +0100542 EXPECT_EQ("1200,450 100x1000", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100543}
544
545TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginPrimaryHiDPI) {
546 UpdateDisplay("1200x600*2,500x500");
547
Ben Murdochca12bfa2013-07-23 11:17:05 +0100548 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
549 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100550 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 Murdochca12bfa2013-07-23 11:17:05 +0100555 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100556 &success, &error);
557
558 ASSERT_TRUE(success);
559 ASSERT_TRUE(error.empty());
560
Ben Murdochca12bfa2013-07-23 11:17:05 +0100561 EXPECT_EQ("600,-100 500x500", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100562}
563
564TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginSecondaryHiDPI) {
565 UpdateDisplay("1200x600,600x1000*2");
566
Ben Murdochca12bfa2013-07-23 11:17:05 +0100567 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
568 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100569 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 Murdochca12bfa2013-07-23 11:17:05 +0100574 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100575 &success, &error);
576
577 ASSERT_TRUE(success);
578 ASSERT_TRUE(error.empty());
579
Ben Murdochca12bfa2013-07-23 11:17:05 +0100580 EXPECT_EQ("450,-500 300x500", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100581}
582
583TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginOutOfBounds) {
584 UpdateDisplay("1200x600,600x1000*2");
585
Ben Murdochca12bfa2013-07-23 11:17:05 +0100586 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
587 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100588 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 Murdochca12bfa2013-07-23 11:17:05 +0100593 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100594 &success, &error);
595
596 ASSERT_FALSE(success);
597 ASSERT_EQ("Bounds origin x out of bounds.", error);
598
Ben Murdochca12bfa2013-07-23 11:17:05 +0100599 EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100600}
601
602TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginOutOfBoundsNegative) {
603 UpdateDisplay("1200x600,600x1000*2");
604
Ben Murdochca12bfa2013-07-23 11:17:05 +0100605 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
606 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100607 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 Murdochca12bfa2013-07-23 11:17:05 +0100612 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100613 &success, &error);
614
615 ASSERT_FALSE(success);
616 ASSERT_EQ("Bounds origin y out of bounds.", error);
617
Ben Murdochca12bfa2013-07-23 11:17:05 +0100618 EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100619}
620
621TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginMaxValues) {
622 UpdateDisplay("1200x4600,600x1000*2");
623
Ben Murdochca12bfa2013-07-23 11:17:05 +0100624 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
625 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100626 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 Murdochca12bfa2013-07-23 11:17:05 +0100631 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100632 &success, &error);
633
634 ASSERT_TRUE(success);
635 EXPECT_TRUE(error.empty());
636
Ben Murdochca12bfa2013-07-23 11:17:05 +0100637 EXPECT_EQ("1200,10 300x500", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100638}
639
640TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginOnPrimary) {
641 UpdateDisplay("1200x600,600x1000*2");
642
Ben Murdochca12bfa2013-07-23 11:17:05 +0100643 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
644 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100645 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 Murdochca12bfa2013-07-23 11:17:05 +0100650 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100651 &success, &error);
652
653 ASSERT_FALSE(success);
654 ASSERT_EQ("Bounds origin not allowed for the primary display.", error);
655
Ben Murdochca12bfa2013-07-23 11:17:05 +0100656 EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100657 // The operation failed because the primary property would be set before
658 // setting bounds. The primary display shouldn't have been changed, though.
Ben Murdochca12bfa2013-07-23 11:17:05 +0100659 EXPECT_NE(ash::DisplayController::GetPrimaryDisplay().id(), secondary.id());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100660}
661
662TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginWithMirroring) {
663 UpdateDisplay("1200x600,600x1000*2");
664
Ben Murdochca12bfa2013-07-23 11:17:05 +0100665 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100666 const gfx::Display& primary = GetDisplayController()->GetPrimaryDisplay();
667
Ben Murdochca12bfa2013-07-23 11:17:05 +0100668 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100669 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 Murdochca12bfa2013-07-23 11:17:05 +0100675 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100676 &success, &error);
677
678 ASSERT_FALSE(success);
679 ASSERT_EQ("No other parameter should be set alongside mirroringSourceId.",
680 error);
681}
682
683TEST_F(DisplayInfoProviderChromeosTest, SetRotation) {
684 UpdateDisplay("1200x600,600x1000*2");
685
Ben Murdochca12bfa2013-07-23 11:17:05 +0100686 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
687 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100688 info.rotation.reset(new int(90));
689
690 bool success = false;
691 std::string error;
Ben Murdochca12bfa2013-07-23 11:17:05 +0100692 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100693 &success, &error);
694
695 ASSERT_TRUE(success);
696 EXPECT_TRUE(error.empty());
697
Ben Murdochca12bfa2013-07-23 11:17:05 +0100698 EXPECT_EQ("1200,0 500x300", secondary.bounds().ToString());
699 EXPECT_EQ(gfx::Display::ROTATE_90, secondary.rotation());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100700
701 info.rotation.reset(new int(270));
Ben Murdochca12bfa2013-07-23 11:17:05 +0100702 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100703 &success, &error);
704
705 ASSERT_TRUE(success);
706 EXPECT_TRUE(error.empty());
707
Ben Murdochca12bfa2013-07-23 11:17:05 +0100708 EXPECT_EQ("1200,0 500x300", secondary.bounds().ToString());
709 EXPECT_EQ(gfx::Display::ROTATE_270, secondary.rotation());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100710
711 info.rotation.reset(new int(180));
712 // Switch primary display.
713 info.is_primary.reset(new bool(true));
Ben Murdochca12bfa2013-07-23 11:17:05 +0100714 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100715 &success, &error);
716
717 ASSERT_TRUE(success);
718 EXPECT_TRUE(error.empty());
719
Ben Murdochca12bfa2013-07-23 11:17:05 +0100720 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)7d4cd472013-06-19 11:58:07 +0100723
724 info.rotation.reset(new int(0));
Ben Murdochca12bfa2013-07-23 11:17:05 +0100725 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100726 &success, &error);
727
728 ASSERT_TRUE(success);
729 EXPECT_TRUE(error.empty());
730
Ben Murdochca12bfa2013-07-23 11:17:05 +0100731 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)7d4cd472013-06-19 11:58:07 +0100734}
735
736TEST_F(DisplayInfoProviderChromeosTest, SetInvalidRotation) {
737 UpdateDisplay("1200x600,600x1000*2");
738
Ben Murdochca12bfa2013-07-23 11:17:05 +0100739 const gfx::Display& secondary = ash::ScreenAsh::GetSecondaryDisplay();
740 api::system_display::DisplayProperties info;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100741 info.rotation.reset(new int(91));
742
743 bool success = false;
744 std::string error;
Ben Murdochca12bfa2013-07-23 11:17:05 +0100745 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100746 &success, &error);
747
748 ASSERT_FALSE(success);
749 EXPECT_EQ("Invalid rotation.", error);
750}
751
752TEST_F(DisplayInfoProviderChromeosTest, SetNegativeOverscan) {
753 UpdateDisplay("1200x600,600x1000*2");
754
Ben Murdochca12bfa2013-07-23 11:17:05 +0100755 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)7d4cd472013-06-19 11:58:07 +0100758 info.overscan->left= -10;
759
760 bool success = false;
761 std::string error;
Ben Murdochca12bfa2013-07-23 11:17:05 +0100762 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100763 &success, &error);
764
765 ASSERT_FALSE(success);
766 EXPECT_EQ("Negative overscan not allowed.", error);
767
Ben Murdochca12bfa2013-07-23 11:17:05 +0100768 EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100769
770 info.overscan->left= 0;
771 info.overscan->right = -200;
772
Ben Murdochca12bfa2013-07-23 11:17:05 +0100773 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100774 &success, &error);
775
776 ASSERT_FALSE(success);
777 EXPECT_EQ("Negative overscan not allowed.", error);
778
Ben Murdochca12bfa2013-07-23 11:17:05 +0100779 EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100780
781 info.overscan->right= 0;
782 info.overscan->top = -300;
783
Ben Murdochca12bfa2013-07-23 11:17:05 +0100784 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100785 &success, &error);
786
787 ASSERT_FALSE(success);
788 EXPECT_EQ("Negative overscan not allowed.", error);
789
Ben Murdochca12bfa2013-07-23 11:17:05 +0100790 EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100791
792 info.overscan->right= 0;
793 info.overscan->top = -1000;
794
Ben Murdochca12bfa2013-07-23 11:17:05 +0100795 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100796 &success, &error);
797
798 ASSERT_FALSE(success);
799 EXPECT_EQ("Negative overscan not allowed.", error);
800
Ben Murdochca12bfa2013-07-23 11:17:05 +0100801 EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100802
803 info.overscan->right= 0;
804 info.overscan->top = 0;
805
Ben Murdochca12bfa2013-07-23 11:17:05 +0100806 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100807 &success, &error);
808
809 ASSERT_TRUE(success);
810 EXPECT_TRUE(error.empty());
811
Ben Murdochca12bfa2013-07-23 11:17:05 +0100812 EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100813}
814
815TEST_F(DisplayInfoProviderChromeosTest, SetOverscanLargerThanHorizontalBounds) {
816 UpdateDisplay("1200x600,600x1000*2");
817
Ben Murdochca12bfa2013-07-23 11:17:05 +0100818 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)7d4cd472013-06-19 11:58:07 +0100821 // 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 Murdochca12bfa2013-07-23 11:17:05 +0100829 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100830 &success, &error);
831
832 ASSERT_FALSE(success);
833 EXPECT_EQ("Horizontal overscan is more than half of the screen width.",
834 error);
835}
836
837TEST_F(DisplayInfoProviderChromeosTest, SetOverscanLargerThanVerticalBounds) {
838 UpdateDisplay("1200x600,600x1000");
839
Ben Murdochca12bfa2013-07-23 11:17:05 +0100840 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)7d4cd472013-06-19 11:58:07 +0100843 // 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 Murdochca12bfa2013-07-23 11:17:05 +0100851 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100852 &success, &error);
853
854 ASSERT_FALSE(success);
855 EXPECT_EQ("Vertical overscan is more than half of the screen height.",
856 error);
857}
858
859TEST_F(DisplayInfoProviderChromeosTest, SetOverscan) {
860 UpdateDisplay("1200x600,600x1000*2");
861
Ben Murdochca12bfa2013-07-23 11:17:05 +0100862 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)7d4cd472013-06-19 11:58:07 +0100865 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 Murdochca12bfa2013-07-23 11:17:05 +0100872 CallSetDisplayUnitInfo(base::Int64ToString(secondary.id()), info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100873 &success, &error);
874
875 ASSERT_TRUE(success);
876 EXPECT_TRUE(error.empty());
877
Ben Murdochca12bfa2013-07-23 11:17:05 +0100878 EXPECT_EQ("1200,0 150x250", secondary.bounds().ToString());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100879 const gfx::Insets overscan =
Ben Murdochca12bfa2013-07-23 11:17:05 +0100880 GetDisplayManager()->GetOverscanInsets(secondary.id());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100881
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
888TEST_F(DisplayInfoProviderChromeosTest, SetOverscanForInternal) {
889 UpdateDisplay("1200x600,600x1000*2");
890 const int64 internal_display_id =
891 ash::test::DisplayManagerTestApi(GetDisplayManager()).
892 SetFirstDisplayAsInternalDisplay();
893
Ben Murdochca12bfa2013-07-23 11:17:05 +0100894 api::system_display::DisplayProperties info;
895 info.overscan.reset(new api::system_display::Insets);
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100896 // 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