| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/frame/ImageBitmap.h" | 6 #include "core/frame/ImageBitmap.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/UnionTypesCore.h" | 8 #include "bindings/core/v8/UnionTypesCore.h" |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/fetch/MemoryCache.h" | 10 #include "core/fetch/MemoryCache.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 virtual void SetUp() | 21 virtual void SetUp() |
| 22 { | 22 { |
| 23 // Save the global memory cache to restore it upon teardown. | 23 // Save the global memory cache to restore it upon teardown. |
| 24 m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create()
); | 24 m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create()
); |
| 25 } | 25 } |
| 26 virtual void TearDown() | 26 virtual void TearDown() |
| 27 { | 27 { |
| 28 // Garbage collection is required prior to switching out the | 28 // Garbage collection is required prior to switching out the |
| 29 // test's memory cache; image resources are released, evicting | 29 // test's memory cache; image resources are released, evicting |
| 30 // them from the cache. | 30 // them from the cache. |
| 31 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GC
WithSweep, Heap::ForcedGC); | 31 Heap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSwee
p, Heap::ForcedGC); |
| 32 | 32 |
| 33 replaceMemoryCacheForTesting(m_globalMemoryCache.release()); | 33 replaceMemoryCacheForTesting(m_globalMemoryCache.release()); |
| 34 } | 34 } |
| 35 | 35 |
| 36 Persistent<MemoryCache> m_globalMemoryCache; | 36 Persistent<MemoryCache> m_globalMemoryCache; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 // Verifies that ImageBitmaps constructed from ImageBitmaps hold onto their own
Image. | 39 // Verifies that ImageBitmaps constructed from ImageBitmaps hold onto their own
Image. |
| 40 TEST_F(ImageBitmapModuleTest, ImageResourceLifetime) | 40 TEST_F(ImageBitmapModuleTest, ImageResourceLifetime) |
| 41 { | 41 { |
| 42 RefPtrWillBeRawPtr<HTMLCanvasElement> canvasElement = HTMLCanvasElement::cre
ate(*Document::create().get()); | 42 RefPtrWillBeRawPtr<HTMLCanvasElement> canvasElement = HTMLCanvasElement::cre
ate(*Document::create().get()); |
| 43 canvasElement->setHeight(40); | 43 canvasElement->setHeight(40); |
| 44 canvasElement->setWidth(40); | 44 canvasElement->setWidth(40); |
| 45 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapDerived = nullptr; | 45 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapDerived = nullptr; |
| 46 { | 46 { |
| 47 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapFromCanvas = ImageBitmap::cre
ate(canvasElement.get(), IntRect(0, 0, canvasElement->width(), canvasElement->he
ight())); | 47 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapFromCanvas = ImageBitmap::cre
ate(canvasElement.get(), IntRect(0, 0, canvasElement->width(), canvasElement->he
ight())); |
| 48 imageBitmapDerived = ImageBitmap::create(imageBitmapFromCanvas.get(), In
tRect(0, 0, 20, 20)); | 48 imageBitmapDerived = ImageBitmap::create(imageBitmapFromCanvas.get(), In
tRect(0, 0, 20, 20)); |
| 49 } | 49 } |
| 50 CanvasContextCreationAttributes attributes; | 50 CanvasContextCreationAttributes attributes; |
| 51 CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(c
anvasElement->getCanvasRenderingContext("2d", attributes)); | 51 CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(c
anvasElement->getCanvasRenderingContext("2d", attributes)); |
| 52 TrackExceptionState exceptionState; | 52 TrackExceptionState exceptionState; |
| 53 CanvasImageSourceUnion imageSource; | 53 CanvasImageSourceUnion imageSource; |
| 54 imageSource.setImageBitmap(imageBitmapDerived); | 54 imageSource.setImageBitmap(imageBitmapDerived); |
| 55 context->drawImage(imageSource, 0, 0, exceptionState); | 55 context->drawImage(imageSource, 0, 0, exceptionState); |
| 56 } | 56 } |
| 57 | 57 |
| 58 } // namespace | 58 } // namespace |
| OLD | NEW |