base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / ui / gfx / image / image_unittest_util.h
blobcac8015eb16611923547a2e1d8719c079b3f2523
1 // Copyright (c) 2012 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.
5 // Because the unit tests for gfx::Image are spread across multiple
6 // implementation files, this header contains the reusable components.
8 #ifndef UI_GFX_IMAGE_IMAGE_UNITTEST_UTIL_H_
9 #define UI_GFX_IMAGE_IMAGE_UNITTEST_UTIL_H_
11 #include "ui/gfx/image/image.h"
12 #include "third_party/skia/include/core/SkColor.h"
14 namespace gfx {
15 namespace test {
17 #if defined(OS_IOS)
18 typedef UIImage* PlatformImage;
19 #elif defined(OS_MACOSX)
20 typedef NSImage* PlatformImage;
21 #else
22 typedef gfx::ImageSkia PlatformImage;
23 #endif
25 std::vector<float> Get1xAnd2xScales();
27 // Create a bitmap of |width|x|height|.
28 const SkBitmap CreateBitmap(int width, int height);
30 // Creates an ImageSkia of |width|x|height| DIP with bitmap data for an
31 // arbitrary scale factor.
32 gfx::ImageSkia CreateImageSkia(int width, int height);
34 // Returns PNG encoded bytes for a bitmap of |edge_size|x|edge_size|.
35 scoped_refptr<base::RefCountedMemory> CreatePNGBytes(int edge_size);
37 // TODO(rohitrao): Remove the no-argument version of CreateImage().
38 gfx::Image CreateImage();
39 gfx::Image CreateImage(int width, int height);
41 // Returns true if the images are equal. Converts the images to ImageSkia to
42 // compare them.
43 bool IsEqual(const gfx::Image& image1, const gfx::Image& image2);
45 bool IsEqual(const SkBitmap& bitmap1, const SkBitmap& bitmap2);
47 bool IsEqual(const scoped_refptr<base::RefCountedMemory>& bytes,
48 const SkBitmap& bitmap);
50 // An image which was not successfully decoded to PNG should be a red bitmap.
51 // Fails if the bitmap is not red.
52 void CheckImageIndicatesPNGDecodeFailure(const gfx::Image& image);
54 // Returns true if the structure of |image_skia| matches the structure
55 // described by |width|, |height|, and |scale_factors|.
56 // The structure matches if:
57 // - |image_skia| is non null.
58 // - |image_skia| has ImageSkiaReps of |scale_factors|.
59 // - Each of the ImageSkiaReps has a pixel size of |image_skia|.size() *
60 // scale_factor.
61 bool ImageSkiaStructureMatches(
62 const gfx::ImageSkia& image_skia,
63 int width,
64 int height,
65 const std::vector<float>& scale_factors);
67 bool IsEmpty(const gfx::Image& image);
69 PlatformImage CreatePlatformImage();
71 gfx::Image::RepresentationType GetPlatformRepresentationType();
73 PlatformImage ToPlatformType(const gfx::Image& image);
74 PlatformImage CopyPlatformType(const gfx::Image& image);
76 SkColor GetPlatformImageColor(PlatformImage image, int x, int y);
77 void CheckColors(SkColor color1, SkColor color2);
78 void CheckIsTransparent(SkColor color);
80 bool IsPlatformImageValid(PlatformImage image);
82 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2);
84 } // namespace test
85 } // namespace gfx
87 #endif // UI_GFX_IMAGE_IMAGE_UNITTEST_UTIL_H_