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

Unified Diff: third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridgeTest.cpp

Issue 1736333002: Fix a race condition in canvas hibernation when visibility is toggled repeatedly (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridgeTest.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridgeTest.cpp b/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridgeTest.cpp
index 1fa37962f7d15cd98f82c9da81627d31533fd58d..31dc743056f90ea059ab659566517e9718459c6d 100644
--- a/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridgeTest.cpp
+++ b/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridgeTest.cpp
@@ -502,6 +502,54 @@ TEST_F(Canvas2DLayerBridgeTest, HibernationLifeCycle)
::testing::Mock::VerifyAndClearExpectations(&mainMock);
}
+TEST_F(Canvas2DLayerBridgeTest, HibernationReEntry)
+{
+ MockCanvasContext mainMock;
+ OwnPtr<WebThread> testThread = adoptPtr(Platform::current()->createThread("TestThread"));
+
+ // The Canvas2DLayerBridge has to be created on the thread that will use it
+ // to avoid WeakPtr thread check issues.
+ Canvas2DLayerBridgePtr bridge;
+ postAndWaitCreateBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge, &mainMock, this);
+
+ // Register an alternate Logger for tracking hibernation events
+ OwnPtr<MockLogger> mockLogger = adoptPtr(new MockLogger);
+ MockLogger* mockLoggerPtr = mockLogger.get();
+ bridge->setLoggerForTesting(mockLogger.release());
+
+ // Test entering hibernation
+ OwnPtr<WaitableEvent> hibernationStartedEvent = adoptPtr(new WaitableEvent());
+ EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::HibernationScheduled));
+ EXPECT_CALL(*mockLoggerPtr, didStartHibernating())
+ .WillOnce(testing::Invoke(hibernationStartedEvent.get(), &WaitableEvent::signal));
+ postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), true);
+ // Toggle visibility before the idle tasks that enters hibernation gets a
+ // chance to run.
+ postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), false);
+ postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), true);
+
+ hibernationStartedEvent->wait();
+ ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr);
+ EXPECT_FALSE(bridge->isAccelerated());
+ EXPECT_TRUE(bridge->isHibernating());
+ EXPECT_TRUE(bridge->checkSurfaceValid());
+
+ // Test exiting hibernation
+ EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::HibernationEndedNormally));
+ postAndWaitSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), false);
+ ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr);
+ EXPECT_TRUE(bridge->isAccelerated());
+ EXPECT_FALSE(bridge->isHibernating());
+ EXPECT_TRUE(bridge->checkSurfaceValid());
+
+ // Tear down the bridge on the thread so that 'bridge' can go out of scope
+ // without crashing due to thread checks
+ postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge);
+
+ ::testing::Mock::VerifyAndClearExpectations(&mainMock);
+
+}
+
TEST_F(Canvas2DLayerBridgeTest, HibernationLifeCycleWithDeferredRenderingDisabled)
{
MockCanvasContext mainMock;

Powered by Google App Engine
This is Rietveld 408576698