• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #elif defined(TOOLKIT_GTK)
22 typedef GdkPixbuf* PlatformImage;
23 #else
24 typedef gfx::ImageSkia PlatformImage;
25 #endif
26 
27 std::vector<float> Get1xAnd2xScales();
28 
29 // Create a bitmap of |width|x|height|.
30 const SkBitmap CreateBitmap(int width, int height);
31 
32 // Creates an ImageSkia of |width|x|height| DIP with bitmap data for an
33 // arbitrary scale factor.
34 gfx::ImageSkia CreateImageSkia(int width, int height);
35 
36 // Returns PNG encoded bytes for a bitmap of |edge_size|x|edge_size|.
37 scoped_refptr<base::RefCountedMemory> CreatePNGBytes(int edge_size);
38 
39 // TODO(rohitrao): Remove the no-argument version of CreateImage().
40 gfx::Image CreateImage();
41 gfx::Image CreateImage(int width, int height);
42 
43 // Returns true if the images are equal. Converts the images to ImageSkia to
44 // compare them.
45 bool IsEqual(const gfx::Image& image1, const gfx::Image& image2);
46 
47 bool IsEqual(const SkBitmap& bitmap1, const SkBitmap& bitmap2);
48 
49 bool IsEqual(const scoped_refptr<base::RefCountedMemory>& bytes,
50              const SkBitmap& bitmap);
51 
52 // An image which was not successfully decoded to PNG should be a red bitmap.
53 // Fails if the bitmap is not red.
54 void CheckImageIndicatesPNGDecodeFailure(const gfx::Image& image);
55 
56 // Returns true if the structure of |image_skia| matches the structure
57 // described by |width|, |height|, and |scale_factors|.
58 // The structure matches if:
59 // - |image_skia| is non null.
60 // - |image_skia| has ImageSkiaReps of |scale_factors|.
61 // - Each of the ImageSkiaReps has a pixel size of |image_skia|.size() *
62 //   scale_factor.
63 bool ImageSkiaStructureMatches(
64     const gfx::ImageSkia& image_skia,
65     int width,
66     int height,
67     const std::vector<float>& scale_factors);
68 
69 bool IsEmpty(const gfx::Image& image);
70 
71 PlatformImage CreatePlatformImage();
72 
73 gfx::Image::RepresentationType GetPlatformRepresentationType();
74 
75 PlatformImage ToPlatformType(const gfx::Image& image);
76 PlatformImage CopyPlatformType(const gfx::Image& image);
77 
78 SkColor GetPlatformImageColor(PlatformImage image, int x, int y);
79 void CheckColors(SkColor color1, SkColor color2);
80 void CheckIsTransparent(SkColor color);
81 
82 bool IsPlatformImageValid(PlatformImage image);
83 
84 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2);
85 
86 }  // namespace test
87 }  // namespace gfx
88 
89 #endif  // UI_GFX_IMAGE_IMAGE_UNITTEST_UTIL_H_
90