1 // Copyright 2019 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 #include "ui/gfx/skia_util.h"
6 
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/skia/include/core/SkBitmap.h"
9 
10 namespace gfx {
11 
TEST(SkiaUtilTest,BitmapsAreEqual)12 TEST(SkiaUtilTest, BitmapsAreEqual) {
13   SkBitmap a, b;
14   EXPECT_TRUE(gfx::BitmapsAreEqual(a, b));  // Both bitmaps are null.
15 
16   a.allocN32Pixels(0, 0);
17   EXPECT_FALSE(gfx::BitmapsAreEqual(a, b));  // isNull() differs.
18   b.allocN32Pixels(10, 0);
19   EXPECT_FALSE(gfx::BitmapsAreEqual(a, b));  // Dimensions differ.
20   a.allocN32Pixels(0, 10);
21   EXPECT_FALSE(gfx::BitmapsAreEqual(a, b));  // Dimensions still differ.
22   b.allocN32Pixels(0, 10);
23   EXPECT_TRUE(gfx::BitmapsAreEqual(a, b));  // Dimensions equal (but empty).
24   a.allocN32Pixels(10, 10);
25   EXPECT_FALSE(gfx::BitmapsAreEqual(a, b));  // Dimensions differ.
26   b.allocN32Pixels(10, 10);
27   EXPECT_TRUE(gfx::BitmapsAreEqual(a, b));  // Dimensions equal (non-empty).
28 
29   a.eraseColor(SK_ColorRED);
30   EXPECT_FALSE(gfx::BitmapsAreEqual(a, b));  // Contents differ.
31   b.eraseColor(SK_ColorGREEN);
32   EXPECT_FALSE(gfx::BitmapsAreEqual(a, b));  // Contents still differ.
33   b.eraseColor(SK_ColorRED);
34   EXPECT_TRUE(gfx::BitmapsAreEqual(a, b));  // Contents equal.
35 
36   a.eraseColor(SK_ColorBLUE);
37   EXPECT_FALSE(gfx::BitmapsAreEqual(a, b));  // Contents differ.
38   b = a;
39   EXPECT_TRUE(gfx::BitmapsAreEqual(a, b));  // Generation ids equal.
40 
41   a.reset();
42   EXPECT_FALSE(gfx::BitmapsAreEqual(a, b));  // isNull() differs.
43   b.reset();
44   EXPECT_TRUE(gfx::BitmapsAreEqual(a, b));  // Both bitmaps are null.
45 }
46 
47 }  // namespace gfx
48