Avi Drissman | 3e1a26c | 2022-09-15 20:26:03 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors |
danakj | 99437fc | 2021-03-05 21:27:04 | [diff] [blame] | 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 "ui/gfx/image/image_skia_operations.h" |
| 6 | |
Ian Vollick | d0ef987fa | 2023-08-28 16:32:55 | [diff] [blame] | 7 | #include <vector> |
| 8 | |
| 9 | #include "build/blink_buildflags.h" |
danakj | 99437fc | 2021-03-05 21:27:04 | [diff] [blame] | 10 | #include "testing/gtest/include/gtest/gtest.h" |
David Sanders | 03ee601f | 2022-02-22 02:23:00 | [diff] [blame] | 11 | #include "ui/gfx/geometry/size.h" |
danakj | 99437fc | 2021-03-05 21:27:04 | [diff] [blame] | 12 | #include "ui/gfx/image/image_skia.h" |
David Sanders | 03ee601f | 2022-02-22 02:23:00 | [diff] [blame] | 13 | #include "ui/gfx/image/image_skia_rep.h" |
danakj | 99437fc | 2021-03-05 21:27:04 | [diff] [blame] | 14 | |
Ian Vollick | d0ef987fa | 2023-08-28 16:32:55 | [diff] [blame] | 15 | #if BUILDFLAG(IS_IOS) |
| 16 | #include "ui/base/resource/resource_scale_factor.h" |
| 17 | #endif // BUILDFLAG(IS_IOS) |
| 18 | |
danakj | 99437fc | 2021-03-05 21:27:04 | [diff] [blame] | 19 | namespace gfx { |
| 20 | namespace { |
| 21 | |
| 22 | TEST(ImageSkiaOperationsTest, ResizeFailure) { |
Ian Vollick | d0ef987fa | 2023-08-28 16:32:55 | [diff] [blame] | 23 | #if BUILDFLAG(IS_IOS) |
| 24 | // Ensure we have supported scale factors. iOS may not support k100Percent |
| 25 | // like other platforms, so we force support for 100 and 200 percent here. |
Ian Vollick | d0ef987fa | 2023-08-28 16:32:55 | [diff] [blame] | 26 | ui::test::ScopedSetSupportedResourceScaleFactors scoped_supported( |
Henrique Ferreiro | 597a7a4 | 2023-09-19 11:07:26 | [diff] [blame] | 27 | {ui::k100Percent, ui::k200Percent}); |
Ian Vollick | d0ef987fa | 2023-08-28 16:32:55 | [diff] [blame] | 28 | #endif // BUILDFLAG(IS_IOS) |
| 29 | |
danakj | 99437fc | 2021-03-05 21:27:04 | [diff] [blame] | 30 | ImageSkia image(ImageSkiaRep(gfx::Size(10, 10), 1.f)); |
| 31 | |
| 32 | // Try to resize to empty. This isn't a valid resize and fails gracefully. |
| 33 | ImageSkia resized = ImageSkiaOperations::CreateResizedImage( |
| 34 | image, skia::ImageOperations::RESIZE_BEST, gfx::Size()); |
| 35 | EXPECT_TRUE(resized.GetRepresentation(1.0f).is_null()); |
| 36 | } |
| 37 | |
| 38 | } // namespace |
| 39 | } // namespace gfx |