| Index: ui/base/test/ios/ui_image_test_utils.mm
|
| diff --git a/ui/base/test/ios/ui_image_test_utils.mm b/ui/base/test/ios/ui_image_test_utils.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c9c773c7d6f8309639cfa4a7d35afc56be3a109b
|
| --- /dev/null
|
| +++ b/ui/base/test/ios/ui_image_test_utils.mm
|
| @@ -0,0 +1,52 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "ui/base/test/ios/ui_image_test_utils.h"
|
| +
|
| +#include "base/logging.h"
|
| +
|
| +namespace ui {
|
| +namespace test {
|
| +namespace uiimage_utils {
|
| +
|
| +UIImage* UIImageWithSizeAndSolidColor(CGSize const& size, UIColor* color) {
|
| + UIGraphicsBeginImageContext(size);
|
| + CGContextRef context = UIGraphicsGetCurrentContext();
|
| + CGContextSetFillColorWithColor(context, [color CGColor]);
|
| + CGContextFillRect(context, CGRectMake(0, 0, size.width, size.height));
|
| + UIImage* imageWithSolidColor = UIGraphicsGetImageFromCurrentImageContext();
|
| + UIGraphicsEndImageContext();
|
| + return imageWithSolidColor;
|
| +}
|
| +
|
| +bool UIImagesAreEqual(UIImage* image1, UIImage* image2) {
|
| + if (image1 == image2)
|
| + return true;
|
| + DCHECK(image1.CGImage);
|
| + DCHECK(image2.CGImage);
|
| +
|
| + bool imagesAreEqual = false;
|
| +
|
| + CFDataRef dataRef1 =
|
| + CGDataProviderCopyData(CGImageGetDataProvider(image1.CGImage));
|
| + CFDataRef dataRef2 =
|
| + CGDataProviderCopyData(CGImageGetDataProvider(image2.CGImage));
|
| + CFIndex length1 = CFDataGetLength(dataRef1);
|
| + CFIndex length2 = CFDataGetLength(dataRef2);
|
| + if (length1 == length2) {
|
| + const UInt8* ptr1 = CFDataGetBytePtr(dataRef1);
|
| + const UInt8* ptr2 = CFDataGetBytePtr(dataRef2);
|
| + // memcmp returns 0 if length is 0.
|
| + if (memcmp(ptr1, ptr2, length1) == 0)
|
| + imagesAreEqual = true;
|
| + }
|
| + CFRelease(dataRef1);
|
| + CFRelease(dataRef2);
|
| +
|
| + return imagesAreEqual;
|
| +}
|
| +
|
| +} // namespace uiimage_utils
|
| +} // namespace test
|
| +} // namespace ui
|
|
|