dip_unittest.cc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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
  3. // found in the LICENSE file.
  4. #include <algorithm>
  5. #include <vector>
  6. #include "ash/public/cpp/shelf_config.h"
  7. #include "ash/shelf/shelf.h"
  8. #include "ash/shelf/shelf_widget.h"
  9. #include "ash/shell.h"
  10. #include "ash/test/ash_test_base.h"
  11. #include "ash/wm/window_properties.h"
  12. #include "ash/wm/window_util.h"
  13. #include "base/command_line.h"
  14. #include "ui/aura/window.h"
  15. #include "ui/aura/window_event_dispatcher.h"
  16. #include "ui/compositor/layer.h"
  17. #include "ui/display/display.h"
  18. #include "ui/display/manager/display_manager.h"
  19. #include "ui/display/screen.h"
  20. #include "ui/gfx/geometry/insets.h"
  21. #include "ui/views/widget/widget.h"
  22. namespace ash {
  23. using DIPTest = AshTestBase;
  24. // Test if the WM sets correct work area under different density.
  25. TEST_F(DIPTest, WorkArea) {
  26. UpdateDisplay("1000x900*1.0f");
  27. aura::Window* root = Shell::GetPrimaryRootWindow();
  28. const display::Display display =
  29. display::Screen::GetScreen()->GetDisplayNearestWindow(root);
  30. const int shelf_inset = 900 - ShelfConfig::Get()->shelf_size();
  31. EXPECT_EQ("0,0 1000x900", display.bounds().ToString());
  32. gfx::Rect work_area = display.work_area();
  33. EXPECT_EQ(gfx::Rect(0, 0, 1000, shelf_inset).ToString(),
  34. work_area.ToString());
  35. EXPECT_EQ(
  36. gfx::Insets::TLBR(0, 0, ShelfConfig::Get()->shelf_size(), 0).ToString(),
  37. display.bounds().InsetsFrom(work_area).ToString());
  38. UpdateDisplay("2000x1800*2.0f");
  39. display::Screen* screen = display::Screen::GetScreen();
  40. const display::Display display_2x = screen->GetDisplayNearestWindow(root);
  41. const display::ManagedDisplayInfo display_info_2x =
  42. Shell::Get()->display_manager()->GetDisplayInfo(display_2x.id());
  43. // The |bounds_in_pixel()| should report bounds in pixel coordinate.
  44. EXPECT_EQ("1,1 2000x1800", display_info_2x.bounds_in_native().ToString());
  45. // Aura and views coordinates are in DIP, so they their bounds do not change.
  46. EXPECT_EQ("0,0 1000x900", display_2x.bounds().ToString());
  47. work_area = display_2x.work_area();
  48. EXPECT_EQ(gfx::Rect(0, 0, 1000, shelf_inset).ToString(),
  49. work_area.ToString());
  50. EXPECT_EQ(
  51. gfx::Insets::TLBR(0, 0, ShelfConfig::Get()->shelf_size(), 0).ToString(),
  52. display_2x.bounds().InsetsFrom(work_area).ToString());
  53. // Sanity check if the workarea's inset hight is same as
  54. // the shelf's height.
  55. Shelf* shelf = GetPrimaryShelf();
  56. EXPECT_EQ(display_2x.bounds().InsetsFrom(work_area).height(),
  57. shelf->shelf_widget()->GetNativeView()->layer()->bounds().height());
  58. }
  59. } // namespace ash