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

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

Issue 2057283002: Fix canvas-related crash caused by bad object teardown sequence (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test crash Created 4 years, 6 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 // 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 "modules/canvas2d/CanvasRenderingContext2D.h" 5 #include "modules/canvas2d/CanvasRenderingContext2D.h"
6 6
7 #include "core/fetch/MemoryCache.h" 7 #include "core/fetch/MemoryCache.h"
8 #include "core/frame/FrameView.h" 8 #include "core/frame/FrameView.h"
9 #include "core/frame/ImageBitmap.h" 9 #include "core/frame/ImageBitmap.h"
10 #include "core/html/HTMLCanvasElement.h" 10 #include "core/html/HTMLCanvasElement.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 DummyPageHolder& page() const { return *m_dummyPageHolder; } 78 DummyPageHolder& page() const { return *m_dummyPageHolder; }
79 HTMLDocument& document() const { return *m_document; } 79 HTMLDocument& document() const { return *m_document; }
80 HTMLCanvasElement& canvasElement() const { return *m_canvasElement; } 80 HTMLCanvasElement& canvasElement() const { return *m_canvasElement; }
81 CanvasRenderingContext2D* context2d() const { return static_cast<CanvasRende ringContext2D*>(canvasElement().renderingContext()); } 81 CanvasRenderingContext2D* context2d() const { return static_cast<CanvasRende ringContext2D*>(canvasElement().renderingContext()); }
82 intptr_t getGlobalGPUMemoryUsage() const { return ImageBuffer::getGlobalGPUM emoryUsage(); } 82 intptr_t getGlobalGPUMemoryUsage() const { return ImageBuffer::getGlobalGPUM emoryUsage(); }
83 intptr_t getCurrentGPUMemoryUsage() const { return canvasElement().buffer()- >getGPUMemoryUsage(); } 83 intptr_t getCurrentGPUMemoryUsage() const { return canvasElement().buffer()- >getGPUMemoryUsage(); }
84 84
85 void createContext(OpacityMode); 85 void createContext(OpacityMode);
86 void TearDown(); 86 void TearDown();
87 void unrefCanvas();
87 88
88 private: 89 private:
89 OwnPtr<DummyPageHolder> m_dummyPageHolder; 90 OwnPtr<DummyPageHolder> m_dummyPageHolder;
90 Persistent<HTMLDocument> m_document; 91 Persistent<HTMLDocument> m_document;
91 Persistent<HTMLCanvasElement> m_canvasElement; 92 Persistent<HTMLCanvasElement> m_canvasElement;
92 Persistent<MemoryCache> m_globalMemoryCache; 93 Persistent<MemoryCache> m_globalMemoryCache;
93 94
94 class WrapGradients final : public GarbageCollectedFinalized<WrapGradients> { 95 class WrapGradients final : public GarbageCollectedFinalized<WrapGradients> {
95 public: 96 public:
96 static WrapGradients* create() 97 static WrapGradients* create()
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 // Tear down the first image buffer that resides in current canvas element 713 // Tear down the first image buffer that resides in current canvas element
713 canvasElement().setSize(IntSize(20, 20)); 714 canvasElement().setSize(IntSize(20, 20));
714 Mock::VerifyAndClearExpectations(fakeAccelerateSurfacePtr); 715 Mock::VerifyAndClearExpectations(fakeAccelerateSurfacePtr);
715 EXPECT_EQ(400, getGlobalGPUMemoryUsage()); 716 EXPECT_EQ(400, getGlobalGPUMemoryUsage());
716 717
717 // Tear down the second image buffer 718 // Tear down the second image buffer
718 imageBuffer2.reset(); 719 imageBuffer2.reset();
719 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); 720 EXPECT_EQ(0, getGlobalGPUMemoryUsage());
720 } 721 }
721 722
723 TEST_F(CanvasRenderingContext2DTest, CanvasDisposedBeforeContext)
724 {
725 createContext(NonOpaque);
726 context2d()->fillRect(0, 0, 1, 1); // results in task observer registration
727
728 context2d()->detachCanvas();
729
730 // This is the only method that is callable after detachCanvas
731 // Test passes by not crashing.
732 context2d()->didProcessTask();
733
734 // Test passes by not crashing during teardown
735 }
736
737 TEST_F(CanvasRenderingContext2DTest, ContextDisposedBeforeCanvas)
738 {
739 createContext(NonOpaque);
740
741 canvasElement().detachContext();
742 // Passes by not crashing later during teardown
743 }
744
722 } // namespace blink 745 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698