Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ui / gfx / image / image_unittest_util.h
bloba2293c8688b6e03be942c8c3b0a81b14fc8aa0d8
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/base/layout.h"
12 #include "ui/gfx/image/image.h"
13 #include "third_party/skia/include/core/SkColor.h"
15 namespace gfx {
16 namespace test {
18 #if defined(OS_IOS)
19 typedef UIImage* PlatformImage;
20 #elif defined(OS_MACOSX)
21 typedef NSImage* PlatformImage;
22 #elif defined(TOOLKIT_GTK)
23 typedef GdkPixbuf* PlatformImage;
24 #else
25 typedef gfx::ImageSkia PlatformImage;
26 #endif
28 std::vector<ui::ScaleFactor> Get1xAnd2xScaleFactors();
30 // Create a bitmap of |width|x|height|.
31 const SkBitmap CreateBitmap(int width, int height);
33 // Creates an ImageSkia of |width|x|height| DIP with bitmap data for an
34 // arbitrary scale factor.
35 gfx::ImageSkia CreateImageSkia(int width, int height);
37 // Returns PNG encoded bytes for a bitmap of |edge_size|x|edge_size|.
38 scoped_refptr<base::RefCountedMemory> CreatePNGBytes(int edge_size);
40 // TODO(rohitrao): Remove the no-argument version of CreateImage().
41 gfx::Image CreateImage();
42 gfx::Image CreateImage(int width, int height);
44 // Returns true if the images are equal. Converts the images to ImageSkia to
45 // compare them.
46 bool IsEqual(const gfx::Image& image1, const gfx::Image& image2);
48 bool IsEqual(const SkBitmap& bitmap1, const SkBitmap& bitmap2);
50 bool IsEqual(const scoped_refptr<base::RefCountedMemory>& bytes,
51 const SkBitmap& bitmap);
53 // An image which was not successfully decoded to PNG should be a red bitmap.
54 // Fails if the bitmap is not red.
55 void CheckImageIndicatesPNGDecodeFailure(const gfx::Image& image);
57 // Returns true if the structure of |image_skia| matches the structure
58 // described by |width|, |height|, and |scale_factors|.
59 // The structure matches if:
60 // - |image_skia| is non null.
61 // - |image_skia| has ImageSkiaReps of |scale_factors|.
62 // - Each of the ImageSkiaReps has a pixel size of |image_skia|.size() *
63 // scale_factor.
64 bool ImageSkiaStructureMatches(
65 const gfx::ImageSkia& image_skia,
66 int width,
67 int height,
68 const std::vector<ui::ScaleFactor>& scale_factors);
70 bool IsEmpty(const gfx::Image& image);
72 PlatformImage CreatePlatformImage();
74 gfx::Image::RepresentationType GetPlatformRepresentationType();
76 PlatformImage ToPlatformType(const gfx::Image& image);
77 PlatformImage CopyPlatformType(const gfx::Image& image);
79 SkColor GetPlatformImageColor(PlatformImage image, int x, int y);
80 void CheckColors(SkColor color1, SkColor color2);
81 void CheckIsTransparent(SkColor color);
83 bool IsPlatformImageValid(PlatformImage image);
85 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2);
87 } // namespace test
88 } // namespace gfx
90 #endif // UI_GFX_IMAGE_IMAGE_UNITTEST_UTIL_H_