OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 #include "core/frame/ImageBitmap.h" | |
7 | |
8 #include "bindings/core/v8/UnionTypesCore.h" | |
9 #include "core/dom/Document.h" | |
10 #include "core/fetch/MemoryCache.h" | |
11 #include "core/html/HTMLCanvasElement.h" | |
12 #include "modules/canvas2d/CanvasRenderingContext2D.h" | |
13 #include "platform/heap/Handle.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 | |
16 namespace blink { | |
17 | |
18 class ImageBitmapModuleTest : public ::testing::Test { | |
19 protected: | |
20 virtual void SetUp() | |
21 { | |
22 // Save the global memory cache to restore it upon teardown. | |
23 m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create()
); | |
24 } | |
25 virtual void TearDown() | |
26 { | |
27 // Garbage collection is required prior to switching out the | |
28 // test's memory cache; image resources are released, evicting | |
29 // them from the cache. | |
30 Heap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSwee
p, BlinkGC::ForcedGC); | |
31 | |
32 replaceMemoryCacheForTesting(m_globalMemoryCache.release()); | |
33 } | |
34 | |
35 Persistent<MemoryCache> m_globalMemoryCache; | |
36 }; | |
37 | |
38 // Verifies that ImageBitmaps constructed from ImageBitmaps hold onto their own
Image. | |
39 TEST_F(ImageBitmapModuleTest, ImageResourceLifetime) | |
40 { | |
41 RefPtrWillBeRawPtr<HTMLCanvasElement> canvasElement = HTMLCanvasElement::cre
ate(*Document::create().get()); | |
42 canvasElement->setHeight(40); | |
43 canvasElement->setWidth(40); | |
44 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapDerived = nullptr; | |
45 { | |
46 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapFromCanvas = ImageBitmap::cre
ate(canvasElement.get(), IntRect(0, 0, canvasElement->width(), canvasElement->he
ight())); | |
47 imageBitmapDerived = ImageBitmap::create(imageBitmapFromCanvas.get(), In
tRect(0, 0, 20, 20)); | |
48 } | |
49 CanvasContextCreationAttributes attributes; | |
50 CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(c
anvasElement->getCanvasRenderingContext("2d", attributes)); | |
51 TrackExceptionState exceptionState; | |
52 CanvasImageSourceUnion imageSource; | |
53 imageSource.setImageBitmap(imageBitmapDerived); | |
54 context->drawImage(imageSource, 0, 0, exceptionState); | |
55 } | |
56 | |
57 } // namespace | |
OLD | NEW |