OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 14 matching lines...) Expand all Loading... |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 | 32 |
33 #include "core/platform/DragImage.h" | 33 #include "core/platform/DragImage.h" |
34 | 34 |
| 35 #include "core/platform/graphics/Image.h" |
| 36 #include "core/platform/graphics/IntSize.h" |
| 37 #include "core/platform/graphics/skia/NativeImageSkia.h" |
| 38 #include "third_party/skia/include/core/SkBitmap.h" |
| 39 #include "wtf/OwnPtr.h" |
| 40 #include "wtf/PassOwnPtr.h" |
| 41 #include "wtf/PassRefPtr.h" |
| 42 #include "wtf/RefPtr.h" |
| 43 |
35 #include <gtest/gtest.h> | 44 #include <gtest/gtest.h> |
36 #include "core/platform/graphics/Image.h" | |
37 #include "core/platform/graphics/skia/NativeImageSkia.h" | |
38 #include <wtf/PassOwnPtr.h> | |
39 | 45 |
40 using namespace WebCore; | 46 using namespace WebCore; |
41 | 47 |
42 namespace { | 48 namespace { |
43 | 49 |
44 class TestImage : public Image { | 50 class TestImage : public Image { |
45 public: | 51 public: |
46 | 52 |
47 static PassRefPtr<TestImage> create(const IntSize& size) | 53 static PassRefPtr<TestImage> create(const IntSize& size) |
48 { | 54 { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 99 |
94 private: | 100 private: |
95 | 101 |
96 IntSize m_size; | 102 IntSize m_size; |
97 | 103 |
98 RefPtr<NativeImageSkia> m_nativeImage; | 104 RefPtr<NativeImageSkia> m_nativeImage; |
99 }; | 105 }; |
100 | 106 |
101 TEST(DragImageTest, NullHandling) | 107 TEST(DragImageTest, NullHandling) |
102 { | 108 { |
103 EXPECT_FALSE(createDragImageFromImage(0)); | 109 EXPECT_FALSE(DragImage::create(0)); |
104 | 110 |
105 deleteDragImage(0); | 111 RefPtr<TestImage> nullTestImage(TestImage::create(IntSize())); |
106 EXPECT_TRUE(dragImageSize(0).isZero()); | 112 EXPECT_FALSE(DragImage::create(nullTestImage.get())); |
107 EXPECT_FALSE(scaleDragImage(0, FloatSize(0.5, 0.5))); | |
108 EXPECT_FALSE(dissolveDragImageToFraction(0, 0.5)); | |
109 EXPECT_FALSE(createDragImageFromImage(0)); | |
110 EXPECT_FALSE(createDragImageIconForCachedImage(0)); | |
111 } | 113 } |
112 | 114 |
113 TEST(DragImageTest, NonNullHandling) | 115 TEST(DragImageTest, NonNullHandling) |
114 { | 116 { |
115 RefPtr<TestImage> testImage(TestImage::create(IntSize(2, 2))); | 117 RefPtr<TestImage> testImage(TestImage::create(IntSize(2, 2))); |
116 DragImageRef dragImage = createDragImageFromImage(testImage.get()); | 118 OwnPtr<DragImage> dragImage = DragImage::create(testImage.get()); |
117 ASSERT_TRUE(dragImage); | 119 ASSERT_TRUE(dragImage); |
118 | 120 |
119 dragImage = scaleDragImage(dragImage, FloatSize(0.5, 0.5)); | 121 dragImage->scale(0.5, 0.5); |
120 ASSERT_TRUE(dragImage); | 122 IntSize size = dragImage->size(); |
121 IntSize size = dragImageSize(dragImage); | |
122 EXPECT_EQ(1, size.width()); | 123 EXPECT_EQ(1, size.width()); |
123 EXPECT_EQ(1, size.height()); | 124 EXPECT_EQ(1, size.height()); |
124 | 125 |
125 dragImage = dissolveDragImageToFraction(dragImage, 0.5); | 126 dragImage->dissolveToFraction(0.5); |
126 ASSERT_TRUE(dragImage); | |
127 | |
128 deleteDragImage(dragImage); | |
129 } | 127 } |
130 | 128 |
131 TEST(DragImageTest, CreateDragImage) | 129 TEST(DragImageTest, CreateDragImage) |
132 { | 130 { |
133 { | 131 { |
134 // Tests that the DrageImage implementation doesn't choke on null values | 132 // Tests that the DrageImage implementation doesn't choke on null values |
135 // of nativeImageForCurrentFrame(). | 133 // of nativeImageForCurrentFrame(). |
136 RefPtr<TestImage> testImage(TestImage::create(IntSize())); | 134 RefPtr<TestImage> testImage(TestImage::create(IntSize())); |
137 EXPECT_FALSE(createDragImageFromImage(testImage.get())); | 135 EXPECT_FALSE(DragImage::create(testImage.get())); |
138 } | 136 } |
139 | 137 |
140 { | 138 { |
141 // Tests that the drag image is a deep copy. | 139 // Tests that the drag image is a deep copy. |
142 RefPtr<TestImage> testImage(TestImage::create(IntSize(1, 1))); | 140 RefPtr<TestImage> testImage(TestImage::create(IntSize(1, 1))); |
143 DragImageRef dragImage = createDragImageFromImage(testImage.get()); | 141 OwnPtr<DragImage> dragImage = DragImage::create(testImage.get()); |
144 ASSERT_TRUE(dragImage); | 142 ASSERT_TRUE(dragImage); |
145 SkAutoLockPixels lock1(*dragImage->bitmap), lock2(testImage->nativeImage
ForCurrentFrame()->bitmap()); | 143 SkAutoLockPixels lock1(dragImage->bitmap()), lock2(testImage->nativeImag
eForCurrentFrame()->bitmap()); |
146 EXPECT_NE(dragImage->bitmap->getPixels(), testImage->nativeImageForCurre
ntFrame()->bitmap().getPixels()); | 144 EXPECT_NE(dragImage->bitmap().getPixels(), testImage->nativeImageForCurr
entFrame()->bitmap().getPixels()); |
147 } | 145 } |
148 } | 146 } |
149 | 147 |
150 } // anonymous namespace | 148 } // anonymous namespace |
OLD | NEW |