blob: c90c1513b346523a8f411a349bdfecb6923fadc1 [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2021 The Chromium Authors
danakj99437fc2021-03-05 21:27:042// 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 Vollickd0ef987fa2023-08-28 16:32:557#include <vector>
8
9#include "build/blink_buildflags.h"
danakj99437fc2021-03-05 21:27:0410#include "testing/gtest/include/gtest/gtest.h"
David Sanders03ee601f2022-02-22 02:23:0011#include "ui/gfx/geometry/size.h"
danakj99437fc2021-03-05 21:27:0412#include "ui/gfx/image/image_skia.h"
David Sanders03ee601f2022-02-22 02:23:0013#include "ui/gfx/image/image_skia_rep.h"
danakj99437fc2021-03-05 21:27:0414
Ian Vollickd0ef987fa2023-08-28 16:32:5515#if BUILDFLAG(IS_IOS)
16#include "ui/base/resource/resource_scale_factor.h"
17#endif // BUILDFLAG(IS_IOS)
18
danakj99437fc2021-03-05 21:27:0419namespace gfx {
20namespace {
21
22TEST(ImageSkiaOperationsTest, ResizeFailure) {
Ian Vollickd0ef987fa2023-08-28 16:32:5523#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 Vollickd0ef987fa2023-08-28 16:32:5526 ui::test::ScopedSetSupportedResourceScaleFactors scoped_supported(
Henrique Ferreiro597a7a42023-09-19 11:07:2627 {ui::k100Percent, ui::k200Percent});
Ian Vollickd0ef987fa2023-08-28 16:32:5528#endif // BUILDFLAG(IS_IOS)
29
danakj99437fc2021-03-05 21:27:0430 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