system_nudge_unittest.cc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright 2022 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/system/tray/system_nudge.h"
  5. #include "ash/constants/notifier_catalogs.h"
  6. #include "ash/public/cpp/shelf_config.h"
  7. #include "ash/system/tray/system_nudge_label.h"
  8. #include "ash/test/ash_test_base.h"
  9. #include "ui/gfx/vector_icon_types.h"
  10. namespace ash {
  11. namespace {
  12. constexpr int kNudgeMargin = 8;
  13. constexpr int kIconSize = 20;
  14. constexpr int kIconLabelSpacing = 16;
  15. constexpr int kNudgePadding = 16;
  16. constexpr int kNudgeWidth = 120;
  17. constexpr char kNudgeName[] = "TestSystemNudge";
  18. gfx::VectorIcon kEmptyIcon;
  19. class TestSystemNudge : public SystemNudge {
  20. public:
  21. explicit TestSystemNudge(bool anchor_status_area)
  22. : SystemNudge(kNudgeName,
  23. NudgeCatalogName::kTestCatalogName,
  24. kIconSize,
  25. kIconLabelSpacing,
  26. kNudgePadding,
  27. anchor_status_area) {}
  28. gfx::Rect GetWidgetBounds() {
  29. return widget()->GetClientAreaBoundsInScreen();
  30. }
  31. private:
  32. std::unique_ptr<SystemNudgeLabel> CreateLabelView() const override {
  33. return std::make_unique<SystemNudgeLabel>(std::u16string(), kNudgeWidth);
  34. }
  35. const gfx::VectorIcon& GetIcon() const override { return kEmptyIcon; }
  36. std::u16string GetAccessibilityText() const override {
  37. return std::u16string();
  38. }
  39. };
  40. } // namespace
  41. using SystemNudgeTest = AshTestBase;
  42. TEST_F(SystemNudgeTest, NudgeDefaultOnLeftSide) {
  43. Shelf* shelf = GetPrimaryShelf();
  44. display::Display primary_display = GetPrimaryDisplay();
  45. gfx::Rect display_bounds = primary_display.bounds();
  46. int shelf_size = ShelfConfig::Get()->shelf_size();
  47. gfx::Rect nudge_bounds;
  48. TestSystemNudge nudge(/*anchor_status_area=*/false);
  49. nudge.Show();
  50. nudge_bounds = nudge.GetWidgetBounds();
  51. nudge_bounds.Outset(kNudgeMargin);
  52. EXPECT_EQ(nudge_bounds.x(), display_bounds.x());
  53. EXPECT_EQ(nudge_bounds.bottom(), display_bounds.bottom() - shelf_size);
  54. shelf->SetAlignment(ShelfAlignment::kBottomLocked);
  55. nudge_bounds = nudge.GetWidgetBounds();
  56. nudge_bounds.Outset(kNudgeMargin);
  57. EXPECT_EQ(nudge_bounds.x(), display_bounds.x());
  58. EXPECT_EQ(nudge_bounds.bottom(), display_bounds.bottom() - shelf_size);
  59. shelf->SetAlignment(ShelfAlignment::kRight);
  60. nudge_bounds = nudge.GetWidgetBounds();
  61. nudge_bounds.Outset(kNudgeMargin);
  62. EXPECT_EQ(nudge_bounds.x(), display_bounds.x());
  63. EXPECT_EQ(nudge_bounds.bottom(), display_bounds.bottom());
  64. shelf->SetAlignment(ShelfAlignment::kLeft);
  65. nudge_bounds = nudge.GetWidgetBounds();
  66. nudge_bounds.Outset(kNudgeMargin);
  67. EXPECT_EQ(nudge_bounds.x(), display_bounds.x() + shelf_size);
  68. EXPECT_EQ(nudge_bounds.bottom(), display_bounds.bottom());
  69. }
  70. TEST_F(SystemNudgeTest, NudgeAnchorStatusArea) {
  71. Shelf* shelf = GetPrimaryShelf();
  72. display::Display primary_display = GetPrimaryDisplay();
  73. gfx::Rect display_bounds = primary_display.bounds();
  74. int shelf_size = ShelfConfig::Get()->shelf_size();
  75. gfx::Rect nudge_bounds;
  76. TestSystemNudge nudge(/*anchor_status_area=*/true);
  77. nudge.Show();
  78. nudge_bounds = nudge.GetWidgetBounds();
  79. nudge_bounds.Outset(kNudgeMargin);
  80. EXPECT_EQ(nudge_bounds.right(), display_bounds.right());
  81. EXPECT_EQ(nudge_bounds.bottom(), display_bounds.bottom() - shelf_size);
  82. shelf->SetAlignment(ShelfAlignment::kBottomLocked);
  83. nudge_bounds = nudge.GetWidgetBounds();
  84. nudge_bounds.Outset(kNudgeMargin);
  85. EXPECT_EQ(nudge_bounds.right(), display_bounds.right());
  86. EXPECT_EQ(nudge_bounds.bottom(), display_bounds.bottom() - shelf_size);
  87. shelf->SetAlignment(ShelfAlignment::kRight);
  88. nudge_bounds = nudge.GetWidgetBounds();
  89. nudge_bounds.Outset(kNudgeMargin);
  90. EXPECT_EQ(nudge_bounds.right(), display_bounds.right() - shelf_size);
  91. EXPECT_EQ(nudge_bounds.bottom(), display_bounds.bottom());
  92. shelf->SetAlignment(ShelfAlignment::kLeft);
  93. nudge_bounds = nudge.GetWidgetBounds();
  94. nudge_bounds.Outset(kNudgeMargin);
  95. EXPECT_EQ(nudge_bounds.x(), display_bounds.x() + shelf_size);
  96. EXPECT_EQ(nudge_bounds.bottom(), display_bounds.bottom());
  97. }
  98. } // namespace ash