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