Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp

Issue 2469873002: [ImageResource 4] Split ImageResource into Resource and Image parts (Closed)
Patch Set: Rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, 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
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 "core/frame/ImageBitmap.h" 31 #include "core/frame/ImageBitmap.h"
32 32
33 #include "SkPixelRef.h" // FIXME: qualify this skia header file. 33 #include "SkPixelRef.h" // FIXME: qualify this skia header file.
34 #include "core/dom/Document.h" 34 #include "core/dom/Document.h"
35 #include "core/fetch/ImageResource.h" 35 #include "core/fetch/ImageResourceContent.h"
36 #include "core/fetch/MemoryCache.h" 36 #include "core/fetch/MemoryCache.h"
37 #include "core/html/HTMLCanvasElement.h" 37 #include "core/html/HTMLCanvasElement.h"
38 #include "core/html/HTMLImageElement.h" 38 #include "core/html/HTMLImageElement.h"
39 #include "core/html/HTMLVideoElement.h" 39 #include "core/html/HTMLVideoElement.h"
40 #include "platform/graphics/StaticBitmapImage.h" 40 #include "platform/graphics/StaticBitmapImage.h"
41 #include "platform/graphics/skia/SkiaUtils.h" 41 #include "platform/graphics/skia/SkiaUtils.h"
42 #include "platform/heap/Handle.h" 42 #include "platform/heap/Handle.h"
43 #include "platform/network/ResourceRequest.h" 43 #include "platform/network/ResourceRequest.h"
44 #include "testing/gtest/include/gtest/gtest.h" 44 #include "testing/gtest/include/gtest/gtest.h"
45 #include "third_party/skia/include/core/SkCanvas.h" 45 #include "third_party/skia/include/core/SkCanvas.h"
(...skipping 28 matching lines...) Expand all
74 } 74 }
75 75
76 sk_sp<SkImage> m_image, m_image2; 76 sk_sp<SkImage> m_image, m_image2;
77 Persistent<MemoryCache> m_globalMemoryCache; 77 Persistent<MemoryCache> m_globalMemoryCache;
78 }; 78 };
79 79
80 TEST_F(ImageBitmapTest, ImageResourceConsistency) { 80 TEST_F(ImageBitmapTest, ImageResourceConsistency) {
81 const ImageBitmapOptions defaultOptions; 81 const ImageBitmapOptions defaultOptions;
82 HTMLImageElement* imageElement = 82 HTMLImageElement* imageElement =
83 HTMLImageElement::create(*Document::create()); 83 HTMLImageElement::create(*Document::create());
84 ImageResource* image = 84 ImageResourceContent* image =
85 ImageResource::create(StaticBitmapImage::create(m_image).get()); 85 ImageResourceContent::create(StaticBitmapImage::create(m_image).get());
86 imageElement->setImageResource(image); 86 imageElement->setImageResource(image);
87 87
88 Optional<IntRect> cropRect = 88 Optional<IntRect> cropRect =
89 IntRect(0, 0, m_image->width(), m_image->height()); 89 IntRect(0, 0, m_image->width(), m_image->height());
90 ImageBitmap* imageBitmapNoCrop = ImageBitmap::create( 90 ImageBitmap* imageBitmapNoCrop = ImageBitmap::create(
91 imageElement, cropRect, &(imageElement->document()), defaultOptions); 91 imageElement, cropRect, &(imageElement->document()), defaultOptions);
92 cropRect = IntRect(m_image->width() / 2, m_image->height() / 2, 92 cropRect = IntRect(m_image->width() / 2, m_image->height() / 2,
93 m_image->width() / 2, m_image->height() / 2); 93 m_image->width() / 2, m_image->height() / 2);
94 ImageBitmap* imageBitmapInteriorCrop = ImageBitmap::create( 94 ImageBitmap* imageBitmapInteriorCrop = ImageBitmap::create(
95 imageElement, cropRect, &(imageElement->document()), defaultOptions); 95 imageElement, cropRect, &(imageElement->document()), defaultOptions);
(...skipping 15 matching lines...) Expand all
111 111
112 StaticBitmapImage* emptyImage = imageBitmapOutsideCrop->bitmapImage(); 112 StaticBitmapImage* emptyImage = imageBitmapOutsideCrop->bitmapImage();
113 ASSERT_NE(emptyImage->imageForCurrentFrame(), 113 ASSERT_NE(emptyImage->imageForCurrentFrame(),
114 imageElement->cachedImage()->getImage()->imageForCurrentFrame()); 114 imageElement->cachedImage()->getImage()->imageForCurrentFrame());
115 } 115 }
116 116
117 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a 117 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a
118 // reference to the original Image if the HTMLImageElement src is changed. 118 // reference to the original Image if the HTMLImageElement src is changed.
119 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) { 119 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) {
120 HTMLImageElement* image = HTMLImageElement::create(*Document::create()); 120 HTMLImageElement* image = HTMLImageElement::create(*Document::create());
121 ImageResource* originalImageResource = 121 ImageResourceContent* originalImageResource =
122 ImageResource::create(StaticBitmapImage::create(m_image).get()); 122 ImageResourceContent::create(StaticBitmapImage::create(m_image).get());
123 image->setImageResource(originalImageResource); 123 image->setImageResource(originalImageResource);
124 124
125 const ImageBitmapOptions defaultOptions; 125 const ImageBitmapOptions defaultOptions;
126 Optional<IntRect> cropRect = 126 Optional<IntRect> cropRect =
127 IntRect(0, 0, m_image->width(), m_image->height()); 127 IntRect(0, 0, m_image->width(), m_image->height());
128 ImageBitmap* imageBitmap = ImageBitmap::create( 128 ImageBitmap* imageBitmap = ImageBitmap::create(
129 image, cropRect, &(image->document()), defaultOptions); 129 image, cropRect, &(image->document()), defaultOptions);
130 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), 130 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(),
131 originalImageResource->getImage()->imageForCurrentFrame()); 131 originalImageResource->getImage()->imageForCurrentFrame());
132 132
133 ImageResource* newImageResource = 133 ImageResourceContent* newImageResource =
134 ImageResource::create(StaticBitmapImage::create(m_image2).get()); 134 ImageResourceContent::create(StaticBitmapImage::create(m_image2).get());
135 image->setImageResource(newImageResource); 135 image->setImageResource(newImageResource);
136 136
137 // The ImageBitmap should contain the same data as the original cached image 137 // The ImageBitmap should contain the same data as the original cached image
138 { 138 {
139 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), 139 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(),
140 originalImageResource->getImage()->imageForCurrentFrame()); 140 originalImageResource->getImage()->imageForCurrentFrame());
141 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get(); 141 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get();
142 ASSERT_NE(image1, nullptr); 142 ASSERT_NE(image1, nullptr);
143 SkImage* image2 = 143 SkImage* image2 =
144 originalImageResource->getImage()->imageForCurrentFrame().get(); 144 originalImageResource->getImage()->imageForCurrentFrame().get();
145 ASSERT_NE(image2, nullptr); 145 ASSERT_NE(image2, nullptr);
146 ASSERT_EQ(image1, image2); 146 ASSERT_EQ(image1, image2);
147 } 147 }
148 148
149 { 149 {
150 ASSERT_NE(imageBitmap->bitmapImage()->imageForCurrentFrame(), 150 ASSERT_NE(imageBitmap->bitmapImage()->imageForCurrentFrame(),
151 newImageResource->getImage()->imageForCurrentFrame()); 151 newImageResource->getImage()->imageForCurrentFrame());
152 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get(); 152 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get();
153 ASSERT_NE(image1, nullptr); 153 ASSERT_NE(image1, nullptr);
154 SkImage* image2 = 154 SkImage* image2 =
155 newImageResource->getImage()->imageForCurrentFrame().get(); 155 newImageResource->getImage()->imageForCurrentFrame().get();
156 ASSERT_NE(image2, nullptr); 156 ASSERT_NE(image2, nullptr);
157 ASSERT_NE(image1, image2); 157 ASSERT_NE(image1, image2);
158 } 158 }
159 } 159 }
160 160
161 } // namespace blink 161 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698