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

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: style 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 23 matching lines...) Expand all
119 ASSERT_NE(emptyImage->imageForCurrentFrame( 119 ASSERT_NE(emptyImage->imageForCurrentFrame(
120 ColorBehavior::transformToTargetForTesting()), 120 ColorBehavior::transformToTargetForTesting()),
121 imageElement->cachedImage()->getImage()->imageForCurrentFrame( 121 imageElement->cachedImage()->getImage()->imageForCurrentFrame(
122 ColorBehavior::transformToTargetForTesting())); 122 ColorBehavior::transformToTargetForTesting()));
123 } 123 }
124 124
125 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a 125 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a
126 // reference to the original Image if the HTMLImageElement src is changed. 126 // reference to the original Image if the HTMLImageElement src is changed.
127 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) { 127 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) {
128 HTMLImageElement* image = HTMLImageElement::create(*Document::create()); 128 HTMLImageElement* image = HTMLImageElement::create(*Document::create());
129 ImageResource* originalImageResource = 129 ImageResourceContent* originalImageResource =
130 ImageResource::create(StaticBitmapImage::create(m_image).get()); 130 ImageResourceContent::create(StaticBitmapImage::create(m_image).get());
131 image->setImageResource(originalImageResource); 131 image->setImageResource(originalImageResource);
132 132
133 const ImageBitmapOptions defaultOptions; 133 const ImageBitmapOptions defaultOptions;
134 Optional<IntRect> cropRect = 134 Optional<IntRect> cropRect =
135 IntRect(0, 0, m_image->width(), m_image->height()); 135 IntRect(0, 0, m_image->width(), m_image->height());
136 ImageBitmap* imageBitmap = ImageBitmap::create( 136 ImageBitmap* imageBitmap = ImageBitmap::create(
137 image, cropRect, &(image->document()), defaultOptions); 137 image, cropRect, &(image->document()), defaultOptions);
138 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame( 138 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(
139 ColorBehavior::transformToTargetForTesting()), 139 ColorBehavior::transformToTargetForTesting()),
140 originalImageResource->getImage()->imageForCurrentFrame( 140 originalImageResource->getImage()->imageForCurrentFrame(
141 ColorBehavior::transformToTargetForTesting())); 141 ColorBehavior::transformToTargetForTesting()));
142 142
143 ImageResource* newImageResource = 143 ImageResourceContent* newImageResource =
144 ImageResource::create(StaticBitmapImage::create(m_image2).get()); 144 ImageResourceContent::create(StaticBitmapImage::create(m_image2).get());
145 image->setImageResource(newImageResource); 145 image->setImageResource(newImageResource);
146 146
147 // The ImageBitmap should contain the same data as the original cached image 147 // The ImageBitmap should contain the same data as the original cached image
148 { 148 {
149 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame( 149 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(
150 ColorBehavior::transformToTargetForTesting()), 150 ColorBehavior::transformToTargetForTesting()),
151 originalImageResource->getImage()->imageForCurrentFrame( 151 originalImageResource->getImage()->imageForCurrentFrame(
152 ColorBehavior::transformToTargetForTesting())); 152 ColorBehavior::transformToTargetForTesting()));
153 SkImage* image1 = 153 SkImage* image1 =
154 imageBitmap->bitmapImage() 154 imageBitmap->bitmapImage()
(...skipping 21 matching lines...) Expand all
176 SkImage* image2 = 176 SkImage* image2 =
177 newImageResource->getImage() 177 newImageResource->getImage()
178 ->imageForCurrentFrame(ColorBehavior::transformToTargetForTesting()) 178 ->imageForCurrentFrame(ColorBehavior::transformToTargetForTesting())
179 .get(); 179 .get();
180 ASSERT_NE(image2, nullptr); 180 ASSERT_NE(image2, nullptr);
181 ASSERT_NE(image1, image2); 181 ASSERT_NE(image1, image2);
182 } 182 }
183 } 183 }
184 184
185 } // namespace blink 185 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/FrameSerializer.cpp ('k') | third_party/WebKit/Source/core/html/HTMLImageElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698