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

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

Issue 1327653004: Have uses of MockImageResourceClient leak less. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Clean up MockImageResourceClient somewhat Created 5 years, 3 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
« no previous file with comments | « Source/core/fetch/ResourceFetcherTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 RefPtrWillBePersistent<HTMLImageElement> imageExteriorCrop = HTMLImageElemen t::create(*Document::create().get()); 122 RefPtrWillBePersistent<HTMLImageElement> imageExteriorCrop = HTMLImageElemen t::create(*Document::create().get());
123 ResourcePtr<ImageResource> cachedImageExteriorCrop = new ImageResource(Resou rceRequest("http://foo.com/3"), 123 ResourcePtr<ImageResource> cachedImageExteriorCrop = new ImageResource(Resou rceRequest("http://foo.com/3"),
124 StaticBitmapImage::create(m_image).get()); 124 StaticBitmapImage::create(m_image).get());
125 imageExteriorCrop->setImageResource(cachedImageExteriorCrop.get()); 125 imageExteriorCrop->setImageResource(cachedImageExteriorCrop.get());
126 126
127 RefPtrWillBePersistent<HTMLImageElement> imageOutsideCrop = HTMLImageElement ::create(*Document::create().get()); 127 RefPtrWillBePersistent<HTMLImageElement> imageOutsideCrop = HTMLImageElement ::create(*Document::create().get());
128 ResourcePtr<ImageResource> cachedImageOutsideCrop = new ImageResource(Resour ceRequest("http://foo.com/4"), 128 ResourcePtr<ImageResource> cachedImageOutsideCrop = new ImageResource(Resour ceRequest("http://foo.com/4"),
129 StaticBitmapImage::create(m_image).get()); 129 StaticBitmapImage::create(m_image).get());
130 imageOutsideCrop->setImageResource(cachedImageOutsideCrop.get()); 130 imageOutsideCrop->setImageResource(cachedImageOutsideCrop.get());
131 131
132 MockImageResourceClient mockClient1, mockClient2, mockClient3, mockClient4; 132 MockImageResourceClient mockClient1(cachedImageNoCrop);
133 cachedImageNoCrop->addClient(&mockClient1); 133 MockImageResourceClient mockClient2(cachedImageInteriorCrop);
134 cachedImageInteriorCrop->addClient(&mockClient2); 134 MockImageResourceClient mockClient3(cachedImageExteriorCrop);
135 cachedImageExteriorCrop->addClient(&mockClient3); 135 MockImageResourceClient mockClient4(cachedImageOutsideCrop);
136 cachedImageOutsideCrop->addClient(&mockClient4);
137 136
138 memoryCache()->add(cachedImageNoCrop.get()); 137 memoryCache()->add(cachedImageNoCrop.get());
139 memoryCache()->add(cachedImageInteriorCrop.get()); 138 memoryCache()->add(cachedImageInteriorCrop.get());
140 memoryCache()->add(cachedImageExteriorCrop.get()); 139 memoryCache()->add(cachedImageExteriorCrop.get());
141 memoryCache()->add(cachedImageOutsideCrop.get()); 140 memoryCache()->add(cachedImageOutsideCrop.get());
142 memoryCache()->updateDecodedResource(cachedImageNoCrop.get(), UpdateForPrope rtyChange); 141 memoryCache()->updateDecodedResource(cachedImageNoCrop.get(), UpdateForPrope rtyChange);
143 memoryCache()->updateDecodedResource(cachedImageInteriorCrop.get(), UpdateFo rPropertyChange); 142 memoryCache()->updateDecodedResource(cachedImageInteriorCrop.get(), UpdateFo rPropertyChange);
144 memoryCache()->updateDecodedResource(cachedImageExteriorCrop.get(), UpdateFo rPropertyChange); 143 memoryCache()->updateDecodedResource(cachedImageExteriorCrop.get(), UpdateFo rPropertyChange);
145 memoryCache()->updateDecodedResource(cachedImageOutsideCrop.get(), UpdateFor PropertyChange); 144 memoryCache()->updateDecodedResource(cachedImageOutsideCrop.get(), UpdateFor PropertyChange);
146 145
(...skipping 27 matching lines...) Expand all
174 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith Sweep, Heap::ForcedGC); 173 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith Sweep, Heap::ForcedGC);
175 174
176 // CacheLiveResourcePriroity should return to CacheLiveResourcePriorityLow w hen no ImageBitmaps reference the image. 175 // CacheLiveResourcePriroity should return to CacheLiveResourcePriorityLow w hen no ImageBitmaps reference the image.
177 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCacheLi veResourcePriorityLow); 176 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCacheLi veResourcePriorityLow);
178 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityLow); 177 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityLow);
179 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), MemoryCa cheLiveResourcePriorityLow); 178 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), MemoryCa cheLiveResourcePriorityLow);
180 179
181 // There is still an ImageBitmap that references this image. 180 // There is still an ImageBitmap that references this image.
182 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityHigh); 181 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityHigh);
183 imageBitmapInteriorCrop = nullptr; 182 imageBitmapInteriorCrop = nullptr;
184
185 cachedImageNoCrop->removeClient(&mockClient1);
186 cachedImageInteriorCrop->removeClient(&mockClient2);
187 cachedImageExteriorCrop->removeClient(&mockClient3);
188 cachedImageOutsideCrop->removeClient(&mockClient4);
189 } 183 }
190 184
191 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a referenc e to the original Image if the HTMLImageElement src is changed. 185 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a referenc e to the original Image if the HTMLImageElement src is changed.
192 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) 186 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged)
193 { 187 {
194 RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*Docum ent::create().get()); 188 RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*Docum ent::create().get());
195 ResourcePtr<ImageResource> originalImageResource = new ImageResource( 189 ResourcePtr<ImageResource> originalImageResource = new ImageResource(
196 StaticBitmapImage::create(m_image).get()); 190 StaticBitmapImage::create(m_image).get());
197 image->setImageResource(originalImageResource.get()); 191 image->setImageResource(originalImageResource.get());
198 192
(...skipping 12 matching lines...) Expand all
211 ASSERT_TRUE(originalImageResource->image()->deprecatedBitmapForCurrentFrame( &bitmap2)); 205 ASSERT_TRUE(originalImageResource->image()->deprecatedBitmapForCurrentFrame( &bitmap2));
212 ASSERT_EQ(bitmap1.pixelRef()->pixels(), bitmap2.pixelRef()->pixels()); 206 ASSERT_EQ(bitmap1.pixelRef()->pixels(), bitmap2.pixelRef()->pixels());
213 207
214 ASSERT_NE(imageBitmap->bitmapImage().get(), newImageResource->image()); 208 ASSERT_NE(imageBitmap->bitmapImage().get(), newImageResource->image());
215 ASSERT_TRUE(imageBitmap->bitmapImage()->deprecatedBitmapForCurrentFrame(&bit map1)); 209 ASSERT_TRUE(imageBitmap->bitmapImage()->deprecatedBitmapForCurrentFrame(&bit map1));
216 ASSERT_TRUE(newImageResource->image()->deprecatedBitmapForCurrentFrame(&bitm ap2)); 210 ASSERT_TRUE(newImageResource->image()->deprecatedBitmapForCurrentFrame(&bitm ap2));
217 ASSERT_NE(bitmap1.pixelRef()->pixels(), bitmap2.pixelRef()->pixels()); 211 ASSERT_NE(bitmap1.pixelRef()->pixels(), bitmap2.pixelRef()->pixels());
218 } 212 }
219 213
220 } // namespace 214 } // namespace
OLDNEW
« no previous file with comments | « Source/core/fetch/ResourceFetcherTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698