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

Side by Side Diff: chrome/browser/chromeos/display/display_preferences_unittest.cc

Issue 2540383002: Updates display manager and display preferences to handle touch calibration data. (Closed)
Patch Set: Merge with ToT Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/display/display_preferences.h" 5 #include "chrome/browser/chromeos/display/display_preferences.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 using ash::ResolutionNotificationController; 44 using ash::ResolutionNotificationController;
45 45
46 namespace chromeos { 46 namespace chromeos {
47 namespace { 47 namespace {
48 const char kPrimaryIdKey[] = "primary-id"; 48 const char kPrimaryIdKey[] = "primary-id";
49 const char kMirroredKey[] = "mirrored"; 49 const char kMirroredKey[] = "mirrored";
50 const char kPositionKey[] = "position"; 50 const char kPositionKey[] = "position";
51 const char kOffsetKey[] = "offset"; 51 const char kOffsetKey[] = "offset";
52 const char kPlacementDisplayIdKey[] = "placement.display_id"; 52 const char kPlacementDisplayIdKey[] = "placement.display_id";
53 const char kPlacementParentDisplayIdKey[] = "placement.parent_display_id"; 53 const char kPlacementParentDisplayIdKey[] = "placement.parent_display_id";
54 const char kTouchCalibrationWidth[] = "touch_calibration_width";
55 const char kTouchCalibrationHeight[] = "touch_calibration_height";
56 const char kTouchCalibrationPointPairs[] = "touch_calibration_point_pairs";
54 57
55 // The mean acceleration due to gravity on Earth in m/s^2. 58 // The mean acceleration due to gravity on Earth in m/s^2.
56 const float kMeanGravity = -9.80665f; 59 const float kMeanGravity = -9.80665f;
57 60
58 bool IsRotationLocked() { 61 bool IsRotationLocked() {
59 return ash::Shell::GetInstance() 62 return ash::Shell::GetInstance()
60 ->screen_orientation_controller() 63 ->screen_orientation_controller()
61 ->rotation_locked(); 64 ->rotation_locked();
62 } 65 }
63 66
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 EXPECT_NE(dummy_id, display::Screen::GetScreen()->GetPrimaryDisplay().id()); 303 EXPECT_NE(dummy_id, display::Screen::GetScreen()->GetPrimaryDisplay().id());
301 304
302 window_tree_host_manager->SetOverscanInsets(id1, gfx::Insets(10, 11, 12, 13)); 305 window_tree_host_manager->SetOverscanInsets(id1, gfx::Insets(10, 11, 12, 13));
303 display_manager()->SetDisplayRotation(id1, display::Display::ROTATE_90, 306 display_manager()->SetDisplayRotation(id1, display::Display::ROTATE_90,
304 display::Display::ROTATION_SOURCE_USER); 307 display::Display::ROTATION_SOURCE_USER);
305 EXPECT_TRUE(display::test::DisplayManagerTestApi(display_manager()) 308 EXPECT_TRUE(display::test::DisplayManagerTestApi(display_manager())
306 .SetDisplayUIScale(id1, 1.25f)); 309 .SetDisplayUIScale(id1, 1.25f));
307 EXPECT_FALSE(display::test::DisplayManagerTestApi(display_manager()) 310 EXPECT_FALSE(display::test::DisplayManagerTestApi(display_manager())
308 .SetDisplayUIScale(id2, 1.25f)); 311 .SetDisplayUIScale(id2, 1.25f));
309 312
313 // Set touch calibration data for display |id2|.
314 display::TouchCalibrationData::CalibrationPointPairQuad point_pair_quad = {
315 {std::make_pair(gfx::Point(10, 10), gfx::Point(11, 12)),
316 std::make_pair(gfx::Point(190, 10), gfx::Point(195, 8)),
317 std::make_pair(gfx::Point(10, 90), gfx::Point(12, 94)),
318 std::make_pair(gfx::Point(190, 90), gfx::Point(189, 88))}};
319 gfx::Size touch_size(200, 150);
320 display_manager()->SetTouchCalibrationData(id2, point_pair_quad, touch_size);
321
310 const base::DictionaryValue* displays = 322 const base::DictionaryValue* displays =
311 local_state()->GetDictionary(prefs::kSecondaryDisplays); 323 local_state()->GetDictionary(prefs::kSecondaryDisplays);
312 const base::DictionaryValue* layout_value = nullptr; 324 const base::DictionaryValue* layout_value = nullptr;
313 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); 325 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2);
314 std::string dummy_key = 326 std::string dummy_key =
315 base::Int64ToString(id1) + "," + base::Int64ToString(dummy_id); 327 base::Int64ToString(id1) + "," + base::Int64ToString(dummy_id);
316 EXPECT_TRUE(displays->GetDictionary(dummy_key, &layout_value)); 328 EXPECT_TRUE(displays->GetDictionary(dummy_key, &layout_value));
317 329
318 display::DisplayLayout stored_layout; 330 display::DisplayLayout stored_layout;
319 EXPECT_TRUE(ash::JsonToDisplayLayout(*layout_value, &stored_layout)); 331 EXPECT_TRUE(ash::JsonToDisplayLayout(*layout_value, &stored_layout));
(...skipping 27 matching lines...) Expand all
347 int top = 0, left = 0, bottom = 0, right = 0; 359 int top = 0, left = 0, bottom = 0, right = 0;
348 EXPECT_TRUE(property->GetInteger("insets_top", &top)); 360 EXPECT_TRUE(property->GetInteger("insets_top", &top));
349 EXPECT_TRUE(property->GetInteger("insets_left", &left)); 361 EXPECT_TRUE(property->GetInteger("insets_left", &left));
350 EXPECT_TRUE(property->GetInteger("insets_bottom", &bottom)); 362 EXPECT_TRUE(property->GetInteger("insets_bottom", &bottom));
351 EXPECT_TRUE(property->GetInteger("insets_right", &right)); 363 EXPECT_TRUE(property->GetInteger("insets_right", &right));
352 EXPECT_EQ(10, top); 364 EXPECT_EQ(10, top);
353 EXPECT_EQ(11, left); 365 EXPECT_EQ(11, left);
354 EXPECT_EQ(12, bottom); 366 EXPECT_EQ(12, bottom);
355 EXPECT_EQ(13, right); 367 EXPECT_EQ(13, right);
356 368
369 std::string touch_str;
370 EXPECT_FALSE(property->GetString(kTouchCalibrationPointPairs, &touch_str));
371 EXPECT_FALSE(property->GetInteger(kTouchCalibrationWidth, &width));
372 EXPECT_FALSE(property->GetInteger(kTouchCalibrationHeight, &height));
373
357 std::string color_profile; 374 std::string color_profile;
358 EXPECT_TRUE(property->GetString("color_profile_name", &color_profile)); 375 EXPECT_TRUE(property->GetString("color_profile_name", &color_profile));
359 EXPECT_EQ("dynamic", color_profile); 376 EXPECT_EQ("dynamic", color_profile);
360 377
361 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); 378 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property));
362 EXPECT_TRUE(property->GetInteger("rotation", &rotation)); 379 EXPECT_TRUE(property->GetInteger("rotation", &rotation));
363 EXPECT_TRUE(property->GetInteger("ui-scale", &ui_scale)); 380 EXPECT_TRUE(property->GetInteger("ui-scale", &ui_scale));
364 EXPECT_EQ(0, rotation); 381 EXPECT_EQ(0, rotation);
365 // ui_scale works only on 2x scale factor/1st display. 382 // ui_scale works only on 2x scale factor/1st display.
366 EXPECT_EQ(1000, ui_scale); 383 EXPECT_EQ(1000, ui_scale);
367 EXPECT_FALSE(property->GetInteger("insets_top", &top)); 384 EXPECT_FALSE(property->GetInteger("insets_top", &top));
368 EXPECT_FALSE(property->GetInteger("insets_left", &left)); 385 EXPECT_FALSE(property->GetInteger("insets_left", &left));
369 EXPECT_FALSE(property->GetInteger("insets_bottom", &bottom)); 386 EXPECT_FALSE(property->GetInteger("insets_bottom", &bottom));
370 EXPECT_FALSE(property->GetInteger("insets_right", &right)); 387 EXPECT_FALSE(property->GetInteger("insets_right", &right));
371 388
389 display::TouchCalibrationData::CalibrationPointPairQuad stored_pair_quad;
390
391 EXPECT_TRUE(property->GetString(kTouchCalibrationPointPairs, &touch_str));
392 EXPECT_TRUE(ParseTouchCalibrationStringForTest(touch_str, &stored_pair_quad));
393
394 for (std::size_t row = 0; row < point_pair_quad.size(); row++) {
395 EXPECT_EQ(point_pair_quad[row].first.x(), stored_pair_quad[row].first.x());
396 EXPECT_EQ(point_pair_quad[row].first.y(), stored_pair_quad[row].first.y());
397 EXPECT_EQ(point_pair_quad[row].second.x(),
398 stored_pair_quad[row].second.x());
399 EXPECT_EQ(point_pair_quad[row].second.y(),
400 stored_pair_quad[row].second.y());
401 }
402 width = height = 0;
403 EXPECT_TRUE(property->GetInteger(kTouchCalibrationWidth, &width));
404 EXPECT_TRUE(property->GetInteger(kTouchCalibrationHeight, &height));
405 EXPECT_EQ(width, touch_size.width());
406 EXPECT_EQ(height, touch_size.height());
407
372 // |id2| doesn't have the color_profile because it doesn't have 'dynamic' in 408 // |id2| doesn't have the color_profile because it doesn't have 'dynamic' in
373 // its available list. 409 // its available list.
374 EXPECT_FALSE(property->GetString("color_profile_name", &color_profile)); 410 EXPECT_FALSE(property->GetString("color_profile_name", &color_profile));
375 411
376 // Resolution is saved only when the resolution is set 412 // Resolution is saved only when the resolution is set
377 // by DisplayManager::SetDisplayMode 413 // by DisplayManager::SetDisplayMode
378 width = 0; 414 width = 0;
379 height = 0; 415 height = 0;
380 EXPECT_FALSE(property->GetInteger("width", &width)); 416 EXPECT_FALSE(property->GetInteger("width", &width));
381 EXPECT_FALSE(property->GetInteger("height", &height)); 417 EXPECT_FALSE(property->GetInteger("height", &height));
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 // by mirroring. 502 // by mirroring.
467 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); 503 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property));
468 EXPECT_TRUE(property->GetInteger("width", &width)); 504 EXPECT_TRUE(property->GetInteger("width", &width));
469 EXPECT_TRUE(property->GetInteger("height", &height)); 505 EXPECT_TRUE(property->GetInteger("height", &height));
470 EXPECT_EQ(300, width); 506 EXPECT_EQ(300, width);
471 EXPECT_EQ(200, height); 507 EXPECT_EQ(200, height);
472 508
473 // Set new display's selected resolution. 509 // Set new display's selected resolution.
474 display_manager()->RegisterDisplayProperty( 510 display_manager()->RegisterDisplayProperty(
475 id2 + 1, display::Display::ROTATE_0, 1.0f, nullptr, gfx::Size(500, 400), 511 id2 + 1, display::Display::ROTATE_0, 1.0f, nullptr, gfx::Size(500, 400),
476 1.0f, ui::COLOR_PROFILE_STANDARD); 512 1.0f, ui::COLOR_PROFILE_STANDARD, nullptr);
477 513
478 UpdateDisplay("200x200*2, 600x500#600x500|500x400"); 514 UpdateDisplay("200x200*2, 600x500#600x500|500x400");
479 515
480 // Update key as the 2nd display gets new id. 516 // Update key as the 2nd display gets new id.
481 id2 = display_manager()->GetSecondaryDisplay().id(); 517 id2 = display_manager()->GetSecondaryDisplay().id();
482 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); 518 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2);
483 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); 519 EXPECT_TRUE(displays->GetDictionary(key, &layout_value));
484 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); 520 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position));
485 EXPECT_EQ("right", position); 521 EXPECT_EQ("right", position);
486 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); 522 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset));
487 EXPECT_EQ(0, offset); 523 EXPECT_EQ(0, offset);
488 mirrored = true; 524 mirrored = true;
489 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); 525 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored));
490 EXPECT_FALSE(mirrored); 526 EXPECT_FALSE(mirrored);
491 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); 527 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str));
492 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); 528 EXPECT_EQ(base::Int64ToString(id1), primary_id_str);
493 529
494 // Best resolution should not be saved. 530 // Best resolution should not be saved.
495 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); 531 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property));
496 EXPECT_FALSE(property->GetInteger("width", &width)); 532 EXPECT_FALSE(property->GetInteger("width", &width));
497 EXPECT_FALSE(property->GetInteger("height", &height)); 533 EXPECT_FALSE(property->GetInteger("height", &height));
498 534
499 // Set yet another new display's selected resolution. 535 // Set yet another new display's selected resolution.
500 display_manager()->RegisterDisplayProperty( 536 display_manager()->RegisterDisplayProperty(
501 id2 + 1, display::Display::ROTATE_0, 1.0f, nullptr, gfx::Size(500, 400), 537 id2 + 1, display::Display::ROTATE_0, 1.0f, nullptr, gfx::Size(500, 400),
502 1.0f, ui::COLOR_PROFILE_STANDARD); 538 1.0f, ui::COLOR_PROFILE_STANDARD, nullptr);
503 // Disconnect 2nd display first to generate new id for external display. 539 // Disconnect 2nd display first to generate new id for external display.
504 UpdateDisplay("200x200*2"); 540 UpdateDisplay("200x200*2");
505 UpdateDisplay("200x200*2, 500x400#600x500|500x400%60.0f"); 541 UpdateDisplay("200x200*2, 500x400#600x500|500x400%60.0f");
506 // Update key as the 2nd display gets new id. 542 // Update key as the 2nd display gets new id.
507 id2 = display_manager()->GetSecondaryDisplay().id(); 543 id2 = display_manager()->GetSecondaryDisplay().id();
508 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); 544 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2);
509 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); 545 EXPECT_TRUE(displays->GetDictionary(key, &layout_value));
510 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); 546 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position));
511 EXPECT_EQ("right", position); 547 EXPECT_EQ("right", position);
512 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); 548 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset));
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 1154
1119 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), 1155 EXPECT_EQ(gfx::Rect(0, 0, 200, 200),
1120 display_manager()->GetDisplayForId(list[0]).bounds()); 1156 display_manager()->GetDisplayForId(list[0]).bounds());
1121 EXPECT_EQ(gfx::Rect(-200, 0, 200, 200), 1157 EXPECT_EQ(gfx::Rect(-200, 0, 200, 200),
1122 display_manager()->GetDisplayForId(list[1]).bounds()); 1158 display_manager()->GetDisplayForId(list[1]).bounds());
1123 EXPECT_EQ(gfx::Rect(-100, 200, 300, 300), 1159 EXPECT_EQ(gfx::Rect(-100, 200, 300, 300),
1124 display_manager()->GetDisplayForId(list[2]).bounds()); 1160 display_manager()->GetDisplayForId(list[2]).bounds());
1125 } 1161 }
1126 1162
1127 } // namespace chromeos 1163 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/display/display_preferences.cc ('k') | ui/display/manager/display_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698