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/base/layout.h" 12 #include "ui/gfx/image/image.h" 13 #include "third_party/skia/include/core/SkColor.h" 14 15 namespace gfx { 16 namespace test { 17 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 27 28 std::vector<ui::ScaleFactor> Get1xAnd2xScaleFactors(); 29 30 // Create a bitmap of |width|x|height|. 31 const SkBitmap CreateBitmap(int width, int height); 32 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); 36 37 // Returns PNG encoded bytes for a bitmap of |edge_size|x|edge_size|. 38 scoped_refptr<base::RefCountedMemory> CreatePNGBytes(int edge_size); 39 40 // TODO(rohitrao): Remove the no-argument version of CreateImage(). 41 gfx::Image CreateImage(); 42 gfx::Image CreateImage(int width, int height); 43 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); 47 48 bool IsEqual(const SkBitmap& bitmap1, const SkBitmap& bitmap2); 49 50 bool IsEqual(const scoped_refptr<base::RefCountedMemory>& bytes, 51 const SkBitmap& bitmap); 52 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); 56 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); 69 70 bool IsEmpty(const gfx::Image& image); 71 72 PlatformImage CreatePlatformImage(); 73 74 gfx::Image::RepresentationType GetPlatformRepresentationType(); 75 76 PlatformImage ToPlatformType(const gfx::Image& image); 77 PlatformImage CopyPlatformType(const gfx::Image& image); 78 79 SkColor GetPlatformImageColor(PlatformImage image, int x, int y); 80 void CheckColors(SkColor color1, SkColor color2); 81 void CheckIsTransparent(SkColor color); 82 83 bool IsPlatformImageValid(PlatformImage image); 84 85 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2); 86 87 } // namespace test 88 } // namespace gfx 89 90 #endif // UI_GFX_IMAGE_IMAGE_UNITTEST_UTIL_H_ 91