cac8015eb16611923547a2e1d8719c079b3f2523
[platform/framework/web/crosswalk.git] / src / ui / gfx / image / image_unittest_util.h
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.
4
5 // Because the unit tests for gfx::Image are spread across multiple
6 // implementation files, this header contains the reusable components.
7
8 #ifndef UI_GFX_IMAGE_IMAGE_UNITTEST_UTIL_H_
9 #define UI_GFX_IMAGE_IMAGE_UNITTEST_UTIL_H_
10
11 #include "ui/gfx/image/image.h"
12 #include "third_party/skia/include/core/SkColor.h"
13
14 namespace gfx {
15 namespace test {
16
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
24
25 std::vector<float> Get1xAnd2xScales();
26
27 // Create a bitmap of |width|x|height|.
28 const SkBitmap CreateBitmap(int width, int height);
29
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);
33
34 // Returns PNG encoded bytes for a bitmap of |edge_size|x|edge_size|.
35 scoped_refptr<base::RefCountedMemory> CreatePNGBytes(int edge_size);
36
37 // TODO(rohitrao): Remove the no-argument version of CreateImage().
38 gfx::Image CreateImage();
39 gfx::Image CreateImage(int width, int height);
40
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);
44
45 bool IsEqual(const SkBitmap& bitmap1, const SkBitmap& bitmap2);
46
47 bool IsEqual(const scoped_refptr<base::RefCountedMemory>& bytes,
48              const SkBitmap& bitmap);
49
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);
53
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);
66
67 bool IsEmpty(const gfx::Image& image);
68
69 PlatformImage CreatePlatformImage();
70
71 gfx::Image::RepresentationType GetPlatformRepresentationType();
72
73 PlatformImage ToPlatformType(const gfx::Image& image);
74 PlatformImage CopyPlatformType(const gfx::Image& image);
75
76 SkColor GetPlatformImageColor(PlatformImage image, int x, int y);
77 void CheckColors(SkColor color1, SkColor color2);
78 void CheckIsTransparent(SkColor color);
79
80 bool IsPlatformImageValid(PlatformImage image);
81
82 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2);
83
84 }  // namespace test
85 }  // namespace gfx
86
87 #endif  // UI_GFX_IMAGE_IMAGE_UNITTEST_UTIL_H_