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 14namespace gfx { 15namespace test { 16 17#if defined(OS_IOS) 18typedef UIImage* PlatformImage; 19#elif defined(OS_MACOSX) 20typedef NSImage* PlatformImage; 21#else 22typedef gfx::ImageSkia PlatformImage; 23#endif 24 25std::vector<float> Get1xAnd2xScales(); 26 27// Create a bitmap of |width|x|height|. 28const 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. 32gfx::ImageSkia CreateImageSkia(int width, int height); 33 34// Returns PNG encoded bytes for a bitmap of |edge_size|x|edge_size|. 35scoped_refptr<base::RefCountedMemory> CreatePNGBytes(int edge_size); 36 37// TODO(rohitrao): Remove the no-argument version of CreateImage(). 38gfx::Image CreateImage(); 39gfx::Image CreateImage(int width, int height); 40 41// Returns true if the images are equal. Converts the images to ImageSkia to 42// compare them. 43bool IsEqual(const gfx::Image& image1, const gfx::Image& image2); 44 45bool IsEqual(const SkBitmap& bitmap1, const SkBitmap& bitmap2); 46 47bool 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. 52void 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. 61bool ImageSkiaStructureMatches( 62 const gfx::ImageSkia& image_skia, 63 int width, 64 int height, 65 const std::vector<float>& scale_factors); 66 67bool IsEmpty(const gfx::Image& image); 68 69PlatformImage CreatePlatformImage(); 70 71gfx::Image::RepresentationType GetPlatformRepresentationType(); 72 73PlatformImage ToPlatformType(const gfx::Image& image); 74PlatformImage CopyPlatformType(const gfx::Image& image); 75 76SkColor GetPlatformImageColor(PlatformImage image, int x, int y); 77void CheckColors(SkColor color1, SkColor color2); 78void CheckIsTransparent(SkColor color); 79 80bool IsPlatformImageValid(PlatformImage image); 81 82bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2); 83 84} // namespace test 85} // namespace gfx 86 87#endif // UI_GFX_IMAGE_IMAGE_UNITTEST_UTIL_H_ 88