summaryrefslogtreecommitdiff
path: root/Source/WebKit/chromium/tests/Canvas2DLayerManagerTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit/chromium/tests/Canvas2DLayerManagerTest.cpp')
-rw-r--r--Source/WebKit/chromium/tests/Canvas2DLayerManagerTest.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/Source/WebKit/chromium/tests/Canvas2DLayerManagerTest.cpp b/Source/WebKit/chromium/tests/Canvas2DLayerManagerTest.cpp
index f9a136c35..79e57039a 100644
--- a/Source/WebKit/chromium/tests/Canvas2DLayerManagerTest.cpp
+++ b/Source/WebKit/chromium/tests/Canvas2DLayerManagerTest.cpp
@@ -30,6 +30,8 @@
#include "GraphicsContext3DPrivate.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+#include <public/Platform.h>
+#include <public/WebThread.h>
using namespace WebCore;
using testing::InSequence;
@@ -47,6 +49,15 @@ public:
{
}
+ virtual size_t storageAllocatedForRecording() OVERRIDE
+ {
+ // Because the fake layer has no canvas to query, just
+ // return status quo. Allocation changes that would normally be
+ // initiated by the canvas can be faked by invoking
+ // storageAllocatedForRecordingChanged directly from the test code.
+ return m_bytesAllocated;
+ }
+
void fakeFreeableBytes(size_t size)
{
m_freeableBytes = size;
@@ -65,6 +76,7 @@ public:
virtual void flush() OVERRIDE
{
+ flushedDrawCommands();
m_flushCount++;
}
@@ -133,6 +145,83 @@ protected:
EXPECT_EQ((size_t)11, layer.bytesAllocated()); // flush drops the layer from manager's tracking list
EXPECT_FALSE(manager.isInList(&layer));
}
+
+ void doDeferredFrameTestTask(FakeCanvas2DLayerBridge* layer, bool skipCommands)
+ {
+ EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
+ layer->contextAcquired();
+ layer->storageAllocatedForRecordingChanged(1);
+ EXPECT_TRUE(Canvas2DLayerManager::get().m_taskObserverActive);
+ if (skipCommands) {
+ layer->contextAcquired();
+ layer->storageAllocatedForRecordingChanged(0);
+ layer->skippedPendingDrawCommands();
+ }
+ WebKit::Platform::current()->currentThread()->exitRunLoop();
+ }
+
+ class DeferredFrameTestTask : public WebKit::WebThread::Task {
+ public:
+ DeferredFrameTestTask(Canvas2DLayerManagerTest* test, FakeCanvas2DLayerBridge* layer, bool skipCommands)
+ {
+ m_test = test;
+ m_layer = layer;
+ m_skipCommands = skipCommands;
+ }
+
+ virtual void run() OVERRIDE
+ {
+ m_test->doDeferredFrameTestTask(m_layer, m_skipCommands);
+ }
+ private:
+ Canvas2DLayerManagerTest* m_test;
+ FakeCanvas2DLayerBridge* m_layer;
+ bool m_skipCommands;
+ };
+
+ void deferredFrameTest()
+ {
+ Canvas2DLayerManager::get().init(10, 10);
+ FakeCanvas2DLayerBridge fakeLayer;
+ WebKit::Platform::current()->currentThread()->postTask(new DeferredFrameTestTask(this, &fakeLayer, true));
+ WebKit::Platform::current()->currentThread()->enterRunLoop();
+ // Verify that didProcessTask was called upon completion
+ EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
+ // Verify that no flush was performed because frame is fresh
+ EXPECT_EQ(0, fakeLayer.m_flushCount);
+
+ // Verify that no flushes are triggered as long as frame are fresh
+ WebKit::Platform::current()->currentThread()->postTask(new DeferredFrameTestTask(this, &fakeLayer, true));
+ WebKit::Platform::current()->currentThread()->enterRunLoop();
+ EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
+ EXPECT_EQ(0, fakeLayer.m_flushCount);
+
+ WebKit::Platform::current()->currentThread()->postTask(new DeferredFrameTestTask(this, &fakeLayer, true));
+ WebKit::Platform::current()->currentThread()->enterRunLoop();
+ EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
+ EXPECT_EQ(0, fakeLayer.m_flushCount);
+
+ // Verify that a flush is triggered every two frames when they are stale.
+ WebKit::Platform::current()->currentThread()->postTask(new DeferredFrameTestTask(this, &fakeLayer, false));
+ WebKit::Platform::current()->currentThread()->enterRunLoop();
+ EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
+ EXPECT_EQ(1, fakeLayer.m_flushCount);
+
+ WebKit::Platform::current()->currentThread()->postTask(new DeferredFrameTestTask(this, &fakeLayer, false));
+ WebKit::Platform::current()->currentThread()->enterRunLoop();
+ EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
+ EXPECT_EQ(1, fakeLayer.m_flushCount);
+
+ WebKit::Platform::current()->currentThread()->postTask(new DeferredFrameTestTask(this, &fakeLayer, false));
+ WebKit::Platform::current()->currentThread()->enterRunLoop();
+ EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
+ EXPECT_EQ(2, fakeLayer.m_flushCount);
+
+ WebKit::Platform::current()->currentThread()->postTask(new DeferredFrameTestTask(this, &fakeLayer, false));
+ WebKit::Platform::current()->currentThread()->enterRunLoop();
+ EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
+ EXPECT_EQ(2, fakeLayer.m_flushCount);
+ }
};
namespace {
@@ -152,5 +241,10 @@ TEST_F(Canvas2DLayerManagerTest, testFlushEviction)
flushEvictionTest();
}
+TEST_F(Canvas2DLayerManagerTest, testDeferredFrame)
+{
+ deferredFrameTest();
+}
+
} // namespace