summaryrefslogtreecommitdiff
path: root/Source/WebKit/chromium/tests/Canvas2DLayerManagerTest.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2012-10-15 16:08:57 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2012-10-15 16:08:57 +0200
commit5466563f4b5b6b86523e3f89bb7f77e5b5270c78 (patch)
tree8caccf7cd03a15207cde3ba282c88bf132482a91 /Source/WebKit/chromium/tests/Canvas2DLayerManagerTest.cpp
parent33b26980cb24288b5a9f2590ccf32a949281bb79 (diff)
downloadqtwebkit-5466563f4b5b6b86523e3f89bb7f77e5b5270c78.tar.gz
Imported WebKit commit 0dc6cd75e1d4836eaffbb520be96fac4847cc9d2 (http://svn.webkit.org/repository/webkit/trunk@131300)
WebKit update which introduces the QtWebKitWidgets module that contains the WK1 widgets based API. (In fact it renames QtWebKit to QtWebKitWidgets while we're working on completing the entire split as part of https://bugs.webkit.org/show_bug.cgi?id=99314
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