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 914eb25c96afe6519be63ea56bc3ea6a89224397..64cb48ffb248931a3190e888e0753237f4f440f8 100644 |
--- a/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridgeTest.cpp |
+++ b/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridgeTest.cpp |
@@ -27,6 +27,7 @@ |
#include "SkSurface.h" |
#include "platform/graphics/ImageBuffer.h" |
+#include "platform/graphics/UnacceleratedImageBufferSurface.h" |
#include "platform/graphics/test/MockWebGraphicsContext3D.h" |
#include "public/platform/Platform.h" |
#include "public/platform/WebExternalBitmap.h" |
@@ -42,9 +43,12 @@ |
#include "third_party/skia/include/gpu/gl/SkNullGLContext.h" |
#include "wtf/RefPtr.h" |
+using testing::AnyNumber; |
+using testing::AtLeast; |
using testing::InSequence; |
using testing::Return; |
using testing::Test; |
+using testing::_; |
namespace blink { |
@@ -441,6 +445,16 @@ private: |
WebWaitableEvent* m_doneEvent; |
}; |
+class MockImageBuffer : public ImageBuffer { |
+public: |
+ MockImageBuffer() |
+ : ImageBuffer(adoptPtr(new UnacceleratedImageBufferSurface(IntSize(1, 1)))) { } |
+ |
+ MOCK_CONST_METHOD1(resetCanvas, void(SkCanvas*)); |
+ |
+ virtual ~MockImageBuffer() { } |
+}; |
+ |
TEST_F(Canvas2DLayerBridgeTest, HibernationLifeCycle) |
{ |
MockCanvasContext mainMock; |
@@ -487,6 +501,59 @@ TEST_F(Canvas2DLayerBridgeTest, HibernationLifeCycle) |
::testing::Mock::VerifyAndClearExpectations(&mainMock); |
} |
+TEST_F(Canvas2DLayerBridgeTest, HibernationLifeCycleWithDeferredRenderingDisabled) |
+{ |
+ 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; |
+ OwnPtr<WebWaitableEvent> bridgeCreatedEvent = adoptPtr(Platform::current()->createWaitableEvent()); |
+ testThread->taskRunner()->postTask(BLINK_FROM_HERE, new CreateBridgeTask(&bridge, &mainMock, this, bridgeCreatedEvent.get())); |
+ bridgeCreatedEvent->wait(); |
+ bridge->disableDeferral(); |
+ MockImageBuffer mockImageBuffer; |
+ EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AnyNumber()); |
+ bridge->setImageBuffer(&mockImageBuffer); |
+ |
+ // 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<WebWaitableEvent> hibernationStartedEvent = adoptPtr(Platform::current()->createWaitableEvent()); |
+ EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::HibernationScheduled)); |
+ EXPECT_CALL(*mockLoggerPtr, didStartHibernating()) |
+ .WillOnce(testing::Invoke(hibernationStartedEvent.get(), &WebWaitableEvent::signal)); |
+ testThread->taskRunner()->postTask(BLINK_FROM_HERE, new SetIsHiddenTask(bridge.get(), true)); |
+ hibernationStartedEvent->wait(); |
+ ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); |
+ ::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer); |
+ EXPECT_FALSE(bridge->isAccelerated()); |
+ EXPECT_TRUE(bridge->isHibernating()); |
+ |
+ // Test exiting hibernation |
+ OwnPtr<WebWaitableEvent> hibernationEndedEvent = adoptPtr(Platform::current()->createWaitableEvent()); |
+ EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::HibernationEndedNormally)); |
+ EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AtLeast(1)); // Because deferred rendering is disabled |
+ testThread->taskRunner()->postTask(BLINK_FROM_HERE, new SetIsHiddenTask(bridge.get(), false, hibernationEndedEvent.get())); |
+ hibernationEndedEvent->wait(); |
+ ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); |
+ ::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer); |
+ EXPECT_TRUE(bridge->isAccelerated()); |
+ EXPECT_FALSE(bridge->isHibernating()); |
+ |
+ // Tear down the bridge on the thread so that 'bridge' can go out of scope |
+ // without crashing due to thread checks |
+ OwnPtr<WebWaitableEvent> bridgeDestroyedEvent = adoptPtr(Platform::current()->createWaitableEvent()); |
+ testThread->taskRunner()->postTask(BLINK_FROM_HERE, new DestroyBridgeTask(&bridge, bridgeDestroyedEvent.get())); |
+ bridgeDestroyedEvent->wait(); |
+ |
+ ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
+} |
+ |
class RenderingTask : public WebTaskRunner::Task { |
public: |
RenderingTask(Canvas2DLayerBridge* bridge, WebWaitableEvent* doneEvent) |
@@ -563,6 +630,69 @@ TEST_F(Canvas2DLayerBridgeTest, BackgroundRenderingWhileHibernating) |
::testing::Mock::VerifyAndClearExpectations(&mainMock); |
} |
+TEST_F(Canvas2DLayerBridgeTest, BackgroundRenderingWhileHibernatingWithDeferredRenderingDisabled) |
+{ |
+ 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; |
+ OwnPtr<WebWaitableEvent> bridgeCreatedEvent = adoptPtr(Platform::current()->createWaitableEvent()); |
+ testThread->taskRunner()->postTask(BLINK_FROM_HERE, new CreateBridgeTask(&bridge, &mainMock, this, bridgeCreatedEvent.get())); |
+ bridgeCreatedEvent->wait(); |
+ MockImageBuffer mockImageBuffer; |
+ EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AnyNumber()); |
+ bridge->setImageBuffer(&mockImageBuffer); |
+ bridge->disableDeferral(); |
+ |
+ |
+ // 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<WebWaitableEvent> hibernationStartedEvent = adoptPtr(Platform::current()->createWaitableEvent()); |
+ EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::HibernationScheduled)); |
+ EXPECT_CALL(*mockLoggerPtr, didStartHibernating()) |
+ .WillOnce(testing::Invoke(hibernationStartedEvent.get(), &WebWaitableEvent::signal)); |
+ testThread->taskRunner()->postTask(BLINK_FROM_HERE, new SetIsHiddenTask(bridge.get(), true)); |
+ hibernationStartedEvent->wait(); |
+ ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); |
+ ::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer); |
+ EXPECT_FALSE(bridge->isAccelerated()); |
+ EXPECT_TRUE(bridge->isHibernating()); |
+ |
+ // Rendering in the background -> temp switch to SW |
+ EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::HibernationEndedWithSwitchToBackgroundRendering)); |
+ EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AtLeast(1)); |
+ OwnPtr<WebWaitableEvent> switchEvent = adoptPtr(Platform::current()->createWaitableEvent()); |
+ testThread->taskRunner()->postTask(BLINK_FROM_HERE, new RenderingTask(bridge.get(), switchEvent.get())); |
+ switchEvent->wait(); |
+ ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); |
+ ::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer); |
+ EXPECT_FALSE(bridge->isAccelerated()); |
+ EXPECT_FALSE(bridge->isHibernating()); |
+ |
+ // Unhide |
+ EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AtLeast(1)); |
+ OwnPtr<WebWaitableEvent> unhideEvent = adoptPtr(Platform::current()->createWaitableEvent()); |
+ testThread->taskRunner()->postTask(BLINK_FROM_HERE, new SetIsHiddenTask(bridge.get(), false, unhideEvent.get())); |
+ unhideEvent->wait(); |
+ ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); |
+ ::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer); |
+ EXPECT_TRUE(bridge->isAccelerated()); // Becoming visible causes switch back to GPU |
+ EXPECT_FALSE(bridge->isHibernating()); |
+ |
+ // Tear down the bridge on the thread so that 'bridge' can go out of scope |
+ // without crashing due to thread checks |
+ EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AnyNumber()); |
+ OwnPtr<WebWaitableEvent> bridgeDestroyedEvent = adoptPtr(Platform::current()->createWaitableEvent()); |
+ testThread->taskRunner()->postTask(BLINK_FROM_HERE, new DestroyBridgeTask(&bridge, bridgeDestroyedEvent.get())); |
+ bridgeDestroyedEvent->wait(); |
+} |
+ |
TEST_F(Canvas2DLayerBridgeTest, TeardownWhileHibernating) |
{ |
MockCanvasContext mainMock; |