Jeffrey Young | d285481 | 2023-04-22 00:43:00 | [diff] [blame] | 1 | // Copyright 2023 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ash/wallpaper/wallpaper_utils/wallpaper_resolution.h" |
| 6 | |
| 7 | #include "ash/public/cpp/wallpaper/wallpaper_types.h" |
| 8 | #include "ash/test/ash_test_base.h" |
| 9 | #include "base/strings/stringprintf.h" |
| 10 | #include "testing/gtest/include/gtest/gtest.h" |
| 11 | |
| 12 | namespace ash { |
| 13 | |
| 14 | using GetMaxDisplaySizeTest = AshTestBase; |
| 15 | |
| 16 | TEST_F(GetMaxDisplaySizeTest, DeviceScaleFactorIgnored) { |
| 17 | // Device scale factor shouldn't affect the native size. |
| 18 | UpdateDisplay("1000x300*2"); |
| 19 | EXPECT_EQ("1000x300", GetMaxDisplaySizeInNative().ToString()); |
| 20 | } |
| 21 | |
| 22 | TEST_F(GetMaxDisplaySizeTest, RotatedDisplayReturnsRotatedSize) { |
| 23 | UpdateDisplay("1000x300*2/r"); |
| 24 | EXPECT_EQ("300x1000", GetMaxDisplaySizeInNative().ToString()); |
| 25 | } |
| 26 | |
| 27 | TEST_F(GetMaxDisplaySizeTest, UiScalingIgnored) { |
| 28 | UpdateDisplay("1000x300*2@1.5"); |
| 29 | EXPECT_EQ("1000x300", GetMaxDisplaySizeInNative().ToString()); |
| 30 | } |
| 31 | |
| 32 | TEST_F(GetMaxDisplaySizeTest, FirstDisplayLarger) { |
| 33 | UpdateDisplay("400x300,200x100"); |
| 34 | EXPECT_EQ("400x300", GetMaxDisplaySizeInNative().ToString()); |
| 35 | } |
| 36 | |
| 37 | TEST_F(GetMaxDisplaySizeTest, SecondDisplayLarger) { |
| 38 | UpdateDisplay("400x300,500x600"); |
| 39 | EXPECT_EQ("500x600", GetMaxDisplaySizeInNative().ToString()); |
| 40 | } |
| 41 | |
| 42 | TEST_F(GetMaxDisplaySizeTest, MaximumDimensionDifferentDisplays) { |
| 43 | UpdateDisplay("400x300,100x500"); |
| 44 | EXPECT_EQ("400x500", GetMaxDisplaySizeInNative().ToString()); |
| 45 | } |
| 46 | |
| 47 | using GetAppropriateResolutionTest = AshTestBase; |
| 48 | |
| 49 | TEST_F(GetAppropriateResolutionTest, SmallResolutionIfBothDimensionsSmall) { |
| 50 | UpdateDisplay(base::StringPrintf("%ix%i", kSmallWallpaperMaxWidth, |
| 51 | kSmallWallpaperMaxHeight)); |
| 52 | EXPECT_EQ(WallpaperResolution::kSmall, GetAppropriateResolution()); |
| 53 | } |
| 54 | |
| 55 | TEST_F(GetAppropriateResolutionTest, LargeResolutionIfEitherLarge) { |
| 56 | const std::vector<gfx::Size> sizes = { |
| 57 | {kSmallWallpaperMaxWidth + 1, kSmallWallpaperMaxHeight}, |
| 58 | {kSmallWallpaperMaxWidth, kSmallWallpaperMaxHeight + 1}}; |
| 59 | |
| 60 | for (const auto& size : sizes) { |
| 61 | UpdateDisplay(base::StringPrintf("%ix%i", size.width(), size.height())); |
| 62 | EXPECT_EQ(WallpaperResolution::kLarge, GetAppropriateResolution()); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | } // namespace ash |