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

Side by Side Diff: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DTest.cpp

Issue 1455763002: Use union type in ImageBitmapFactories.idl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: better argument passing Created 5 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "modules/canvas2d/CanvasRenderingContext2D.h" 6 #include "modules/canvas2d/CanvasRenderingContext2D.h"
7 7
8 #include "core/fetch/MemoryCache.h"
8 #include "core/frame/FrameView.h" 9 #include "core/frame/FrameView.h"
9 #include "core/frame/ImageBitmap.h" 10 #include "core/frame/ImageBitmap.h"
10 #include "core/html/HTMLCanvasElement.h" 11 #include "core/html/HTMLCanvasElement.h"
11 #include "core/html/HTMLDocument.h" 12 #include "core/html/HTMLDocument.h"
12 #include "core/html/ImageData.h" 13 #include "core/html/ImageData.h"
13 #include "core/loader/EmptyClients.h" 14 #include "core/loader/EmptyClients.h"
14 #include "core/testing/DummyPageHolder.h" 15 #include "core/testing/DummyPageHolder.h"
15 #include "modules/canvas2d/CanvasGradient.h" 16 #include "modules/canvas2d/CanvasGradient.h"
16 #include "modules/canvas2d/CanvasPattern.h" 17 #include "modules/canvas2d/CanvasPattern.h"
17 #include "modules/webgl/WebGLRenderingContext.h" 18 #include "modules/webgl/WebGLRenderingContext.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 protected: 74 protected:
74 CanvasRenderingContext2DTest(); 75 CanvasRenderingContext2DTest();
75 void SetUp() override; 76 void SetUp() override;
76 77
77 DummyPageHolder& page() const { return *m_dummyPageHolder; } 78 DummyPageHolder& page() const { return *m_dummyPageHolder; }
78 HTMLDocument& document() const { return *m_document; } 79 HTMLDocument& document() const { return *m_document; }
79 HTMLCanvasElement& canvasElement() const { return *m_canvasElement; } 80 HTMLCanvasElement& canvasElement() const { return *m_canvasElement; }
80 CanvasRenderingContext2D* context2d() const { return static_cast<CanvasRende ringContext2D*>(canvasElement().renderingContext()); } 81 CanvasRenderingContext2D* context2d() const { return static_cast<CanvasRende ringContext2D*>(canvasElement().renderingContext()); }
81 82
82 void createContext(OpacityMode); 83 void createContext(OpacityMode);
84 void TearDown();
83 85
84 private: 86 private:
85 OwnPtr<DummyPageHolder> m_dummyPageHolder; 87 OwnPtr<DummyPageHolder> m_dummyPageHolder;
86 RefPtrWillBePersistent<HTMLDocument> m_document; 88 RefPtrWillBePersistent<HTMLDocument> m_document;
87 RefPtrWillBePersistent<HTMLCanvasElement> m_canvasElement; 89 RefPtrWillBePersistent<HTMLCanvasElement> m_canvasElement;
90 Persistent<MemoryCache> m_globalMemoryCache;
88 91
89 class WrapGradients final : public NoBaseWillBeGarbageCollectedFinalized<Wra pGradients> { 92 class WrapGradients final : public NoBaseWillBeGarbageCollectedFinalized<Wra pGradients> {
90 public: 93 public:
91 static PassOwnPtrWillBeRawPtr<WrapGradients> create() 94 static PassOwnPtrWillBeRawPtr<WrapGradients> create()
92 { 95 {
93 return adoptPtrWillBeNoop(new WrapGradients); 96 return adoptPtrWillBeNoop(new WrapGradients);
94 } 97 }
95 98
96 DEFINE_INLINE_TRACE() 99 DEFINE_INLINE_TRACE()
97 { 100 {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 EXPECT_FALSE(exceptionState.hadException()); 155 EXPECT_FALSE(exceptionState.hadException());
153 this->opaqueGradient().setCanvasGradient(opaqueGradient); 156 this->opaqueGradient().setCanvasGradient(opaqueGradient);
154 157
155 CanvasGradient* alphaGradient = CanvasGradient::create(FloatPoint(0, 0), Flo atPoint(10, 0)); 158 CanvasGradient* alphaGradient = CanvasGradient::create(FloatPoint(0, 0), Flo atPoint(10, 0));
156 alphaGradient->addColorStop(0, String("green"), exceptionState); 159 alphaGradient->addColorStop(0, String("green"), exceptionState);
157 EXPECT_FALSE(exceptionState.hadException()); 160 EXPECT_FALSE(exceptionState.hadException());
158 alphaGradient->addColorStop(1, String("rgba(0, 0, 255, 0.5)"), exceptionStat e); 161 alphaGradient->addColorStop(1, String("rgba(0, 0, 255, 0.5)"), exceptionStat e);
159 EXPECT_FALSE(exceptionState.hadException()); 162 EXPECT_FALSE(exceptionState.hadException());
160 StringOrCanvasGradientOrCanvasPattern wrappedAlphaGradient; 163 StringOrCanvasGradientOrCanvasPattern wrappedAlphaGradient;
161 this->alphaGradient().setCanvasGradient(alphaGradient); 164 this->alphaGradient().setCanvasGradient(alphaGradient);
165
166 m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create());
167 }
168
169 void CanvasRenderingContext2DTest::TearDown()
170 {
171 Heap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, B linkGC::ForcedGC);
172 replaceMemoryCacheForTesting(m_globalMemoryCache.release());
162 } 173 }
163 174
164 //============================================================================ 175 //============================================================================
165 176
166 class MockImageBufferSurfaceForOverwriteTesting : public UnacceleratedImageBuffe rSurface { 177 class MockImageBufferSurfaceForOverwriteTesting : public UnacceleratedImageBuffe rSurface {
167 public: 178 public:
168 MockImageBufferSurfaceForOverwriteTesting(const IntSize& size, OpacityMode m ode) : UnacceleratedImageBufferSurface(size, mode) { } 179 MockImageBufferSurfaceForOverwriteTesting(const IntSize& size, OpacityMode m ode) : UnacceleratedImageBufferSurface(size, mode) { }
169 ~MockImageBufferSurfaceForOverwriteTesting() override { } 180 ~MockImageBufferSurfaceForOverwriteTesting() override { }
170 bool isRecording() const override { return true; } // otherwise overwrites a re not tracked 181 bool isRecording() const override { return true; } // otherwise overwrites a re not tracked
171 182
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 canvasElement().createImageBufferUsingSurfaceForTesting(surface.release()); 604 canvasElement().createImageBufferUsingSurfaceForTesting(surface.release());
594 605
595 context2d()->fillRect(0, 0, 1, 1); // To have a non-empty dirty rect 606 context2d()->fillRect(0, 0, 1, 1); // To have a non-empty dirty rect
596 for (int i = 0; i < ExpensiveCanvasHeuristicParameters::ExpensiveRecordingSt ackDepth; ++i) { 607 for (int i = 0; i < ExpensiveCanvasHeuristicParameters::ExpensiveRecordingSt ackDepth; ++i) {
597 context2d()->save(); 608 context2d()->save();
598 context2d()->translate(1.0f, 0.0f); 609 context2d()->translate(1.0f, 0.0f);
599 } 610 }
600 canvasElement().doDeferredPaintInvalidation(); // To close the current frame 611 canvasElement().doDeferredPaintInvalidation(); // To close the current frame
601 } 612 }
602 613
614 TEST_F(CanvasRenderingContext2DTest, ImageResourceLifetime)
615 {
616 RefPtrWillBeRawPtr<HTMLCanvasElement> canvasElement = HTMLCanvasElement::cre ate(*Document::create().get());
617 canvasElement->setHeight(40);
618 canvasElement->setWidth(40);
619 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapDerived = nullptr;
620 {
621 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapFromCanvas = ImageBitmap::cre ate(canvasElement.get(), IntRect(0, 0, canvasElement->width(), canvasElement->he ight()));
622 imageBitmapDerived = ImageBitmap::create(imageBitmapFromCanvas.get(), In tRect(0, 0, 20, 20));
623 }
624 CanvasContextCreationAttributes attributes;
625 CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(c anvasElement->getCanvasRenderingContext("2d", attributes));
626 TrackExceptionState exceptionState;
627 CanvasImageSourceUnion imageSource;
628 imageSource.setImageBitmap(imageBitmapDerived);
629 context->drawImage(imageSource, 0, 0, exceptionState);
630 }
631
603 } // namespace blink 632 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698