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

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

Issue 1532473002: Add a origin clean flag in ImageBitmap class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: StaticBitmapImage now has a second parameter for origin clean flag Created 4 years, 11 months 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 replaceMemoryCacheForTesting(m_globalMemoryCache.release()); 75 replaceMemoryCacheForTesting(m_globalMemoryCache.release());
76 } 76 }
77 77
78 RefPtr<SkImage> m_image, m_image2; 78 RefPtr<SkImage> m_image, m_image2;
79 Persistent<MemoryCache> m_globalMemoryCache; 79 Persistent<MemoryCache> m_globalMemoryCache;
80 }; 80 };
81 81
82 TEST_F(ImageBitmapTest, ImageResourceConsistency) 82 TEST_F(ImageBitmapTest, ImageResourceConsistency)
83 { 83 {
84 RefPtrWillBeRawPtr<HTMLImageElement> imageElement = HTMLImageElement::create (*Document::create().get()); 84 RefPtrWillBeRawPtr<HTMLImageElement> imageElement = HTMLImageElement::create (*Document::create().get());
85 imageElement->setImageResource(new ImageResource(StaticBitmapImage::create(m _image).get())); 85 imageElement->setImageResource(new ImageResource(StaticBitmapImage::create(m _image, true).get()));
86 86
87 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapNoCrop = ImageBitmap::create(imag eElement.get(), 87 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapNoCrop = ImageBitmap::create(imag eElement.get(),
88 IntRect(0, 0, m_image->width(), m_image->height())); 88 IntRect(0, 0, m_image->width(), m_image->height()),
89 &(imageElement->document()));
89 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapInteriorCrop = ImageBitmap::creat e(imageElement.get(), 90 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapInteriorCrop = ImageBitmap::creat e(imageElement.get(),
90 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width() / 2, m_image->height() / 2)); 91 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width() / 2, m_image->height() / 2),
92 &(imageElement->document()));
91 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapExteriorCrop = ImageBitmap::creat e(imageElement.get(), 93 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapExteriorCrop = ImageBitmap::creat e(imageElement.get(),
92 IntRect(-m_image->width() / 2, -m_image->height() / 2, m_image->width(), m_image->height())); 94 IntRect(-m_image->width() / 2, -m_image->height() / 2, m_image->width(), m_image->height()),
95 &(imageElement->document()));
93 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap::create (imageElement.get(), 96 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap::create (imageElement.get(),
94 IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_image ->height())); 97 IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_image ->height()),
98 &(imageElement->document()));
95 99
96 ASSERT_EQ(imageBitmapNoCrop->bitmapImage()->imageForCurrentFrame(), imageEle ment->cachedImage()->image()->imageForCurrentFrame()); 100 ASSERT_EQ(imageBitmapNoCrop->bitmapImage()->imageForCurrentFrame(), imageEle ment->cachedImage()->image()->imageForCurrentFrame());
97 ASSERT_NE(imageBitmapInteriorCrop->bitmapImage()->imageForCurrentFrame(), im ageElement->cachedImage()->image()->imageForCurrentFrame()); 101 ASSERT_NE(imageBitmapInteriorCrop->bitmapImage()->imageForCurrentFrame(), im ageElement->cachedImage()->image()->imageForCurrentFrame());
98 ASSERT_NE(imageBitmapExteriorCrop->bitmapImage()->imageForCurrentFrame(), im ageElement->cachedImage()->image()->imageForCurrentFrame()); 102 ASSERT_NE(imageBitmapExteriorCrop->bitmapImage()->imageForCurrentFrame(), im ageElement->cachedImage()->image()->imageForCurrentFrame());
99 103
100 StaticBitmapImage* emptyImage = imageBitmapOutsideCrop->bitmapImage(); 104 StaticBitmapImage* emptyImage = imageBitmapOutsideCrop->bitmapImage();
101 ASSERT_NE(emptyImage->imageForCurrentFrame(), imageElement->cachedImage()->i mage()->imageForCurrentFrame()); 105 ASSERT_NE(emptyImage->imageForCurrentFrame(), imageElement->cachedImage()->i mage()->imageForCurrentFrame());
102 } 106 }
103 107
104 // Verifies that HTMLImageElements are given an elevated CacheLiveResourcePriori ty when used to construct an ImageBitmap. 108 // Verifies that HTMLImageElements are given an elevated CacheLiveResourcePriori ty when used to construct an ImageBitmap.
105 // ImageBitmaps that have crop rects outside of the bounds of the HTMLImageEleme nt do not have elevated CacheLiveResourcePriority. 109 // ImageBitmaps that have crop rects outside of the bounds of the HTMLImageEleme nt do not have elevated CacheLiveResourcePriority.
106 TEST_F(ImageBitmapTest, ImageBitmapLiveResourcePriority) 110 TEST_F(ImageBitmapTest, ImageBitmapLiveResourcePriority)
107 { 111 {
108 RefPtrWillBePersistent<HTMLImageElement> imageNoCrop = HTMLImageElement::cre ate(*Document::create().get()); 112 RefPtrWillBePersistent<HTMLImageElement> imageNoCrop = HTMLImageElement::cre ate(*Document::create().get());
109 ResourcePtr<ImageResource> cachedImageNoCrop = new ImageResource(ResourceReq uest("http://foo.com/1"), 113 ResourcePtr<ImageResource> cachedImageNoCrop = new ImageResource(ResourceReq uest("http://foo.com/1"),
110 StaticBitmapImage::create(m_image).get()); 114 StaticBitmapImage::create(m_image, true).get());
111 imageNoCrop->setImageResource(cachedImageNoCrop.get()); 115 imageNoCrop->setImageResource(cachedImageNoCrop.get());
112 116
113 RefPtrWillBePersistent<HTMLImageElement> imageInteriorCrop = HTMLImageElemen t::create(*Document::create().get()); 117 RefPtrWillBePersistent<HTMLImageElement> imageInteriorCrop = HTMLImageElemen t::create(*Document::create().get());
114 ResourcePtr<ImageResource> cachedImageInteriorCrop = new ImageResource(Resou rceRequest("http://foo.com/2"), 118 ResourcePtr<ImageResource> cachedImageInteriorCrop = new ImageResource(Resou rceRequest("http://foo.com/2"),
115 StaticBitmapImage::create(m_image).get()); 119 StaticBitmapImage::create(m_image, true).get());
116 imageInteriorCrop->setImageResource(cachedImageInteriorCrop.get()); 120 imageInteriorCrop->setImageResource(cachedImageInteriorCrop.get());
117 121
118 RefPtrWillBePersistent<HTMLImageElement> imageExteriorCrop = HTMLImageElemen t::create(*Document::create().get()); 122 RefPtrWillBePersistent<HTMLImageElement> imageExteriorCrop = HTMLImageElemen t::create(*Document::create().get());
119 ResourcePtr<ImageResource> cachedImageExteriorCrop = new ImageResource(Resou rceRequest("http://foo.com/3"), 123 ResourcePtr<ImageResource> cachedImageExteriorCrop = new ImageResource(Resou rceRequest("http://foo.com/3"),
120 StaticBitmapImage::create(m_image).get()); 124 StaticBitmapImage::create(m_image, true).get());
121 imageExteriorCrop->setImageResource(cachedImageExteriorCrop.get()); 125 imageExteriorCrop->setImageResource(cachedImageExteriorCrop.get());
122 126
123 RefPtrWillBePersistent<HTMLImageElement> imageOutsideCrop = HTMLImageElement ::create(*Document::create().get()); 127 RefPtrWillBePersistent<HTMLImageElement> imageOutsideCrop = HTMLImageElement ::create(*Document::create().get());
124 ResourcePtr<ImageResource> cachedImageOutsideCrop = new ImageResource(Resour ceRequest("http://foo.com/4"), 128 ResourcePtr<ImageResource> cachedImageOutsideCrop = new ImageResource(Resour ceRequest("http://foo.com/4"),
125 StaticBitmapImage::create(m_image).get()); 129 StaticBitmapImage::create(m_image, true).get());
126 imageOutsideCrop->setImageResource(cachedImageOutsideCrop.get()); 130 imageOutsideCrop->setImageResource(cachedImageOutsideCrop.get());
127 131
128 MockImageResourceClient mockClient1(cachedImageNoCrop); 132 MockImageResourceClient mockClient1(cachedImageNoCrop);
129 MockImageResourceClient mockClient2(cachedImageInteriorCrop); 133 MockImageResourceClient mockClient2(cachedImageInteriorCrop);
130 MockImageResourceClient mockClient3(cachedImageExteriorCrop); 134 MockImageResourceClient mockClient3(cachedImageExteriorCrop);
131 MockImageResourceClient mockClient4(cachedImageOutsideCrop); 135 MockImageResourceClient mockClient4(cachedImageOutsideCrop);
132 136
133 memoryCache()->add(cachedImageNoCrop.get()); 137 memoryCache()->add(cachedImageNoCrop.get());
134 memoryCache()->add(cachedImageInteriorCrop.get()); 138 memoryCache()->add(cachedImageInteriorCrop.get());
135 memoryCache()->add(cachedImageExteriorCrop.get()); 139 memoryCache()->add(cachedImageExteriorCrop.get());
136 memoryCache()->add(cachedImageOutsideCrop.get()); 140 memoryCache()->add(cachedImageOutsideCrop.get());
137 memoryCache()->updateDecodedResource(cachedImageNoCrop.get(), UpdateForPrope rtyChange); 141 memoryCache()->updateDecodedResource(cachedImageNoCrop.get(), UpdateForPrope rtyChange);
138 memoryCache()->updateDecodedResource(cachedImageInteriorCrop.get(), UpdateFo rPropertyChange); 142 memoryCache()->updateDecodedResource(cachedImageInteriorCrop.get(), UpdateFo rPropertyChange);
139 memoryCache()->updateDecodedResource(cachedImageExteriorCrop.get(), UpdateFo rPropertyChange); 143 memoryCache()->updateDecodedResource(cachedImageExteriorCrop.get(), UpdateFo rPropertyChange);
140 memoryCache()->updateDecodedResource(cachedImageOutsideCrop.get(), UpdateFor PropertyChange); 144 memoryCache()->updateDecodedResource(cachedImageOutsideCrop.get(), UpdateFor PropertyChange);
141 145
142 // HTMLImageElements should default to CacheLiveResourcePriorityLow. 146 // HTMLImageElements should default to CacheLiveResourcePriorityLow.
143 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCacheLi veResourcePriorityLow); 147 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCacheLi veResourcePriorityLow);
144 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityLow); 148 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityLow);
145 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityLow); 149 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityLow);
146 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), MemoryCa cheLiveResourcePriorityLow); 150 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), MemoryCa cheLiveResourcePriorityLow);
147 151
148 RefPtrWillBePersistent<ImageBitmap> imageBitmapInteriorCrop = ImageBitmap::c reate(imageInteriorCrop.get(), 152 RefPtrWillBePersistent<ImageBitmap> imageBitmapInteriorCrop = ImageBitmap::c reate(imageInteriorCrop.get(),
149 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width(), m _image->height())); 153 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width(), m _image->height()),
154 &(imageInteriorCrop->document()));
150 { 155 {
151 RefPtrWillBePersistent<ImageBitmap> imageBitmapNoCrop = ImageBitmap::cre ate(imageNoCrop.get(), 156 RefPtrWillBePersistent<ImageBitmap> imageBitmapNoCrop = ImageBitmap::cre ate(imageNoCrop.get(),
152 IntRect(0, 0, m_image->width(), m_image->height())); 157 IntRect(0, 0, m_image->width(), m_image->height()),
158 &(imageNoCrop->document()));
153 RefPtrWillBePersistent<ImageBitmap> imageBitmapInteriorCrop2 = ImageBitm ap::create(imageInteriorCrop.get(), 159 RefPtrWillBePersistent<ImageBitmap> imageBitmapInteriorCrop2 = ImageBitm ap::create(imageInteriorCrop.get(),
154 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width( ), m_image->height())); 160 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width( ), m_image->height()),
161 &(imageInteriorCrop->document()));
155 RefPtrWillBePersistent<ImageBitmap> imageBitmapExteriorCrop = ImageBitma p::create(imageExteriorCrop.get(), 162 RefPtrWillBePersistent<ImageBitmap> imageBitmapExteriorCrop = ImageBitma p::create(imageExteriorCrop.get(),
156 IntRect(-m_image->width() / 2, -m_image->height() / 2, m_image->widt h(), m_image->height())); 163 IntRect(-m_image->width() / 2, -m_image->height() / 2, m_image->widt h(), m_image->height()),
164 &(imageExteriorCrop->document()));
157 RefPtrWillBePersistent<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap ::create(imageOutsideCrop.get(), 165 RefPtrWillBePersistent<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap ::create(imageOutsideCrop.get(),
158 IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_i mage->height())); 166 IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_i mage->height()),
167 &(imageOutsideCrop->document()));
159 168
160 // Images are not referenced by ImageBitmap anymore, so always CacheLive ResourcePriorityLow 169 // Images are not referenced by ImageBitmap anymore, so always CacheLive ResourcePriorityLow
161 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCac heLiveResourcePriorityLow); 170 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCac heLiveResourcePriorityLow);
162 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), Mem oryCacheLiveResourcePriorityLow); 171 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), Mem oryCacheLiveResourcePriorityLow);
163 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), Mem oryCacheLiveResourcePriorityLow); 172 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), Mem oryCacheLiveResourcePriorityLow);
164 173
165 // ImageBitmaps that do not contain any of the source image do not eleva te CacheLiveResourcePriority. 174 // ImageBitmaps that do not contain any of the source image do not eleva te CacheLiveResourcePriority.
166 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), Memo ryCacheLiveResourcePriorityLow); 175 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), Memo ryCacheLiveResourcePriorityLow);
167 } 176 }
168 // Force a garbage collection to sweep out the local ImageBitmaps. 177 // Force a garbage collection to sweep out the local ImageBitmaps.
169 Heap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, B linkGC::ForcedGC); 178 Heap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, B linkGC::ForcedGC);
170 179
171 // CacheLiveResourcePriroity should return to CacheLiveResourcePriorityLow w hen no ImageBitmaps reference the image. 180 // CacheLiveResourcePriroity should return to CacheLiveResourcePriorityLow w hen no ImageBitmaps reference the image.
172 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCacheLi veResourcePriorityLow); 181 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCacheLi veResourcePriorityLow);
173 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityLow); 182 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityLow);
174 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), MemoryCa cheLiveResourcePriorityLow); 183 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), MemoryCa cheLiveResourcePriorityLow);
175 184
176 // There is still an ImageBitmap that references this image. 185 // There is still an ImageBitmap that references this image.
177 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityLow); 186 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityLow);
178 imageBitmapInteriorCrop = nullptr; 187 imageBitmapInteriorCrop = nullptr;
179 } 188 }
180 189
181 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a referenc e to the original Image if the HTMLImageElement src is changed. 190 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a referenc e to the original Image if the HTMLImageElement src is changed.
182 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) 191 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged)
183 { 192 {
184 RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*Docum ent::create().get()); 193 RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*Docum ent::create().get());
185 ResourcePtr<ImageResource> originalImageResource = new ImageResource( 194 ResourcePtr<ImageResource> originalImageResource = new ImageResource(
186 StaticBitmapImage::create(m_image).get()); 195 StaticBitmapImage::create(m_image, true).get());
187 image->setImageResource(originalImageResource.get()); 196 image->setImageResource(originalImageResource.get());
188 197
189 RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image.get( ), 198 RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image.get( ),
190 IntRect(0, 0, m_image->width(), m_image->height())); 199 IntRect(0, 0, m_image->width(), m_image->height()),
200 &(image->document()));
191 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalImageR esource->image()->imageForCurrentFrame()); 201 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalImageR esource->image()->imageForCurrentFrame());
192 202
193 ResourcePtr<ImageResource> newImageResource = new ImageResource( 203 ResourcePtr<ImageResource> newImageResource = new ImageResource(
194 StaticBitmapImage::create(m_image2).get()); 204 StaticBitmapImage::create(m_image2, true).get());
195 image->setImageResource(newImageResource.get()); 205 image->setImageResource(newImageResource.get());
196 206
197 // The ImageBitmap should contain the same data as the original cached image 207 // The ImageBitmap should contain the same data as the original cached image
198 { 208 {
199 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalIm ageResource->image()->imageForCurrentFrame()); 209 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalIm ageResource->image()->imageForCurrentFrame());
200 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get (); 210 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get ();
201 ASSERT_NE(image1, nullptr); 211 ASSERT_NE(image1, nullptr);
202 SkImage* image2 = originalImageResource->image()->imageForCurrentFrame() .get(); 212 SkImage* image2 = originalImageResource->image()->imageForCurrentFrame() .get();
203 ASSERT_NE(image2, nullptr); 213 ASSERT_NE(image2, nullptr);
204 ASSERT_EQ(image1, image2); 214 ASSERT_EQ(image1, image2);
205 } 215 }
206 216
207 { 217 {
208 ASSERT_NE(imageBitmap->bitmapImage()->imageForCurrentFrame(), newImageRe source->image()->imageForCurrentFrame()); 218 ASSERT_NE(imageBitmap->bitmapImage()->imageForCurrentFrame(), newImageRe source->image()->imageForCurrentFrame());
209 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get (); 219 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get ();
210 ASSERT_NE(image1, nullptr); 220 ASSERT_NE(image1, nullptr);
211 SkImage* image2 = newImageResource->image()->imageForCurrentFrame().get( ); 221 SkImage* image2 = newImageResource->image()->imageForCurrentFrame().get( );
212 ASSERT_NE(image2, nullptr); 222 ASSERT_NE(image2, nullptr);
213 ASSERT_NE(image1, image2); 223 ASSERT_NE(image1, image2);
214 } 224 }
215 } 225 }
216 226
217 } // namespace 227 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698