media_notification_background_ash_impl_unittest.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2020 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 "components/media_message_center/media_notification_background_ash_impl.h"
  5. #include "base/i18n/rtl.h"
  6. #include "testing/gtest/include/gtest/gtest.h"
  7. #include "third_party/skia/include/core/SkBitmap.h"
  8. #include "ui/gfx/geometry/rect.h"
  9. namespace media_message_center {
  10. class MediaNotificationBackgroundAshImplTest : public testing::Test {
  11. public:
  12. MediaNotificationBackgroundAshImplTest() = default;
  13. ~MediaNotificationBackgroundAshImplTest() override = default;
  14. void SetUp() override {
  15. background_ = std::make_unique<MediaNotificationBackgroundAshImpl>();
  16. }
  17. void TearDown() override { background_.reset(); }
  18. gfx::ImageSkia CreateTestImage(int width, int height) {
  19. SkBitmap bitmap;
  20. bitmap.allocN32Pixels(width, height);
  21. return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
  22. }
  23. gfx::Rect GetArtworkBounds(gfx::Rect view_rect) {
  24. return background_->GetArtworkBounds(view_rect);
  25. }
  26. MediaNotificationBackgroundAshImpl* background() { return background_.get(); }
  27. private:
  28. std::unique_ptr<MediaNotificationBackgroundAshImpl> background_;
  29. };
  30. TEST_F(MediaNotificationBackgroundAshImplTest, ArtworkBoundsTest) {
  31. gfx::Rect parent_bounds(0, 0, 100, 100);
  32. background()->UpdateArtwork(CreateTestImage(120, 60));
  33. EXPECT_EQ(GetArtworkBounds(parent_bounds), gfx::Rect(-36, 4, 160, 80));
  34. background()->UpdateArtwork(CreateTestImage(40, 50));
  35. EXPECT_EQ(GetArtworkBounds(parent_bounds), gfx::Rect(4, -6, 80, 100));
  36. background()->UpdateArtwork(CreateTestImage(80, 120));
  37. EXPECT_EQ(GetArtworkBounds(parent_bounds), gfx::Rect(4, -16, 80, 120));
  38. base::i18n::SetRTLForTesting(true);
  39. background()->UpdateArtwork(CreateTestImage(80, 40));
  40. EXPECT_EQ(GetArtworkBounds(parent_bounds), gfx::Rect(-24, 4, 160, 80));
  41. }
  42. } // namespace media_message_center