display_util_unittest.cc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2014 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. #include "ash/display/display_util.h"
  5. #include "ash/root_window_controller.h"
  6. #include "ash/shell.h"
  7. #include "ash/test/ash_test_base.h"
  8. #include "base/strings/utf_string_conversions.h"
  9. namespace ash {
  10. using DisplayUtilTest = AshTestBase;
  11. TEST_F(DisplayUtilTest, RotatedDisplay) {
  12. {
  13. UpdateDisplay("10+10-500x400,600+10-1000x600/r");
  14. aura::Window::Windows root_windows = Shell::GetAllRootWindows();
  15. AshWindowTreeHost* host0 =
  16. RootWindowController::ForWindow(root_windows[0])->ash_host();
  17. AshWindowTreeHost* host1 =
  18. RootWindowController::ForWindow(root_windows[1])->ash_host();
  19. gfx::Rect rect0 = GetNativeEdgeBounds(host0, gfx::Rect(499, 10, 1, 300));
  20. gfx::Rect rect1 = GetNativeEdgeBounds(host1, gfx::Rect(500, 10, 1, 300));
  21. EXPECT_EQ(gfx::Rect(509, 20, 1, 300), rect0);
  22. EXPECT_EQ(gfx::Rect(1290, 10, 300, 1), rect1);
  23. }
  24. {
  25. UpdateDisplay("10+10-500x400,600+10-1000x600/l");
  26. aura::Window::Windows root_windows = Shell::GetAllRootWindows();
  27. AshWindowTreeHost* host0 =
  28. RootWindowController::ForWindow(root_windows[0])->ash_host();
  29. AshWindowTreeHost* host1 =
  30. RootWindowController::ForWindow(root_windows[1])->ash_host();
  31. gfx::Rect rect0 = GetNativeEdgeBounds(host0, gfx::Rect(499, 10, 1, 300));
  32. gfx::Rect rect1 = GetNativeEdgeBounds(host1, gfx::Rect(500, 10, 1, 300));
  33. EXPECT_EQ(gfx::Rect(509, 20, 1, 300), rect0);
  34. EXPECT_EQ(gfx::Rect(610, 609, 300, 1), rect1);
  35. }
  36. {
  37. UpdateDisplay("10+10-500x400,600+10-1000x600/u");
  38. aura::Window::Windows root_windows = Shell::GetAllRootWindows();
  39. AshWindowTreeHost* host0 =
  40. RootWindowController::ForWindow(root_windows[0])->ash_host();
  41. AshWindowTreeHost* host1 =
  42. RootWindowController::ForWindow(root_windows[1])->ash_host();
  43. gfx::Rect rect0 = GetNativeEdgeBounds(host0, gfx::Rect(499, 10, 1, 300));
  44. gfx::Rect rect1 = GetNativeEdgeBounds(host1, gfx::Rect(500, 10, 1, 300));
  45. EXPECT_EQ(gfx::Rect(509, 20, 1, 300), rect0);
  46. EXPECT_EQ(gfx::Rect(1599, 300, 1, 300), rect1);
  47. }
  48. {
  49. UpdateDisplay("10+10-500x400/r,600+10-1000x600");
  50. aura::Window::Windows root_windows = Shell::GetAllRootWindows();
  51. AshWindowTreeHost* host0 =
  52. RootWindowController::ForWindow(root_windows[0])->ash_host();
  53. AshWindowTreeHost* host1 =
  54. RootWindowController::ForWindow(root_windows[1])->ash_host();
  55. gfx::Rect rect0 = GetNativeEdgeBounds(host0, gfx::Rect(399, 10, 1, 300));
  56. gfx::Rect rect1 = GetNativeEdgeBounds(host1, gfx::Rect(400, 10, 1, 300));
  57. EXPECT_EQ(gfx::Rect(200, 409, 300, 1), rect0);
  58. EXPECT_EQ(gfx::Rect(600, 20, 1, 300), rect1);
  59. }
  60. {
  61. UpdateDisplay("10+10-500x400/l,600+10-1000x600");
  62. aura::Window::Windows root_windows = Shell::GetAllRootWindows();
  63. AshWindowTreeHost* host0 =
  64. RootWindowController::ForWindow(root_windows[0])->ash_host();
  65. AshWindowTreeHost* host1 =
  66. RootWindowController::ForWindow(root_windows[1])->ash_host();
  67. gfx::Rect rect0 = GetNativeEdgeBounds(host0, gfx::Rect(499, 10, 1, 300));
  68. gfx::Rect rect1 = GetNativeEdgeBounds(host1, gfx::Rect(500, 10, 1, 300));
  69. EXPECT_EQ(gfx::Rect(20, 10, 300, 1), rect0);
  70. EXPECT_EQ(gfx::Rect(600, 20, 1, 300), rect1);
  71. }
  72. {
  73. UpdateDisplay("10+10-500x400/u,600+10-1000x600");
  74. aura::Window::Windows root_windows = Shell::GetAllRootWindows();
  75. AshWindowTreeHost* host0 =
  76. RootWindowController::ForWindow(root_windows[0])->ash_host();
  77. AshWindowTreeHost* host1 =
  78. RootWindowController::ForWindow(root_windows[1])->ash_host();
  79. gfx::Rect rect0 = GetNativeEdgeBounds(host0, gfx::Rect(499, 10, 1, 300));
  80. gfx::Rect rect1 = GetNativeEdgeBounds(host1, gfx::Rect(500, 10, 1, 300));
  81. EXPECT_EQ(gfx::Rect(10, 100, 1, 300), rect0);
  82. EXPECT_EQ(gfx::Rect(600, 20, 1, 300), rect1);
  83. }
  84. }
  85. TEST_F(DisplayUtilTest, ConvertRefreshRateToString16) {
  86. // Decimal numbers are rounded to two digits.
  87. EXPECT_EQ(u"65.98", ConvertRefreshRateToString16(65.98379));
  88. EXPECT_EQ(u"65.99", ConvertRefreshRateToString16(65.98779));
  89. // Mantissa is removed for whole numbers.
  90. EXPECT_EQ(u"58", ConvertRefreshRateToString16(58.00000));
  91. EXPECT_EQ(u"58", ConvertRefreshRateToString16(57.99999));
  92. }
  93. } // namespace ash