This source file includes following definitions.
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
#include "config.h"
#include "painting/PaintAggregator.h"
#include <gtest/gtest.h>
using namespace WebCore;
using namespace blink;
namespace {
TEST(PaintAggregator, InitialState)
{
PaintAggregator greg;
EXPECT_FALSE(greg.hasPendingUpdate());
}
TEST(PaintAggregator, SingleInvalidation)
{
PaintAggregator greg;
IntRect rect(2, 4, 10, 16);
greg.invalidateRect(rect);
EXPECT_TRUE(greg.hasPendingUpdate());
PaintAggregator::PendingUpdate update;
greg.popPendingUpdate(&update);
EXPECT_TRUE(update.scrollRect.isEmpty());
ASSERT_EQ(1U, update.paintRects.size());
EXPECT_EQ(rect, update.paintRects[0]);
}
TEST(PaintAggregator, DoubleDisjointInvalidation)
{
PaintAggregator greg;
IntRect r1(2, 4, 2, 40);
IntRect r2(4, 2, 40, 2);
greg.invalidateRect(r1);
greg.invalidateRect(r2);
IntRect expectedBounds = unionRect(r1, r2);
EXPECT_TRUE(greg.hasPendingUpdate());
PaintAggregator::PendingUpdate update;
greg.popPendingUpdate(&update);
EXPECT_TRUE(update.scrollRect.isEmpty());
EXPECT_EQ(2U, update.paintRects.size());
EXPECT_EQ(expectedBounds, update.calculatePaintBounds());
}
TEST(PaintAggregator, DisjointInvalidationsCombined)
{
PaintAggregator greg;
IntRect r1(2, 4, 2, 1000);
IntRect r2(5, 2, 2, 1000);
greg.invalidateRect(r1);
greg.invalidateRect(r2);
IntRect expectedBounds = unionRect(r1, r2);
EXPECT_TRUE(greg.hasPendingUpdate());
PaintAggregator::PendingUpdate update;
greg.popPendingUpdate(&update);
EXPECT_TRUE(update.scrollRect.isEmpty());
ASSERT_EQ(1U, update.paintRects.size());
EXPECT_EQ(expectedBounds, update.paintRects[0]);
}
TEST(PaintAggregator, SingleScroll)
{
PaintAggregator greg;
IntRect rect(1, 2, 3, 4);
IntPoint delta(1, 0);
greg.scrollRect(delta.x(), delta.y(), rect);
EXPECT_TRUE(greg.hasPendingUpdate());
PaintAggregator::PendingUpdate update;
greg.popPendingUpdate(&update);
EXPECT_TRUE(update.paintRects.isEmpty());
EXPECT_FALSE(update.scrollRect.isEmpty());
EXPECT_EQ(rect, update.scrollRect);
EXPECT_EQ(delta.x(), update.scrollDelta.x());
EXPECT_EQ(delta.y(), update.scrollDelta.y());
IntRect resultingDamage = update.calculateScrollDamage();
IntRect expectedDamage(1, 2, 1, 4);
EXPECT_EQ(expectedDamage, resultingDamage);
}
TEST(PaintAggregator, DoubleOverlappingScroll)
{
PaintAggregator greg;
IntRect rect(1, 2, 3, 4);
IntPoint delta1(1, 0);
IntPoint delta2(1, 0);
greg.scrollRect(delta1.x(), delta1.y(), rect);
greg.scrollRect(delta2.x(), delta2.y(), rect);
EXPECT_TRUE(greg.hasPendingUpdate());
PaintAggregator::PendingUpdate update;
greg.popPendingUpdate(&update);
EXPECT_TRUE(update.paintRects.isEmpty());
EXPECT_FALSE(update.scrollRect.isEmpty());
EXPECT_EQ(rect, update.scrollRect);
IntPoint expectedDelta(delta1.x() + delta2.x(),
delta1.y() + delta2.y());
EXPECT_EQ(expectedDelta.x(), update.scrollDelta.x());
EXPECT_EQ(expectedDelta.y(), update.scrollDelta.y());
IntRect resultingDamage = update.calculateScrollDamage();
IntRect expectedDamage(1, 2, 2, 4);
EXPECT_EQ(expectedDamage, resultingDamage);
}
TEST(PaintAggregator, NegatingScroll)
{
PaintAggregator greg;
IntRect rect(1, 2, 3, 4);
IntPoint delta1(1, 0);
IntPoint delta2(-1, 0);
greg.scrollRect(delta1.x(), delta1.y(), rect);
greg.scrollRect(delta2.x(), delta2.y(), rect);
EXPECT_FALSE(greg.hasPendingUpdate());
}
TEST(PaintAggregator, DiagonalScroll)
{
PaintAggregator greg;
IntRect rect(1, 2, 3, 4);
IntPoint delta(1, 1);
greg.scrollRect(delta.x(), delta.y(), rect);
EXPECT_TRUE(greg.hasPendingUpdate());
PaintAggregator::PendingUpdate update;
greg.popPendingUpdate(&update);
EXPECT_TRUE(update.scrollRect.isEmpty());
ASSERT_EQ(1U, update.paintRects.size());
EXPECT_EQ(rect, update.paintRects[0]);
}
TEST(PaintAggregator, ContainedPaintAfterScroll)
{
PaintAggregator greg;
IntRect scrollRect(0, 0, 10, 10);
greg.scrollRect(2, 0, scrollRect);
IntRect paintRect(4, 4, 2, 2);
greg.invalidateRect(paintRect);
EXPECT_TRUE(greg.hasPendingUpdate());
PaintAggregator::PendingUpdate update;
greg.popPendingUpdate(&update);
EXPECT_FALSE(update.scrollRect.isEmpty());
EXPECT_EQ(1U, update.paintRects.size());
EXPECT_EQ(scrollRect, update.scrollRect);
EXPECT_EQ(paintRect, update.paintRects[0]);
}
TEST(PaintAggregator, ContainedPaintBeforeScroll)
{
PaintAggregator greg;
IntRect paintRect(4, 4, 2, 2);
greg.invalidateRect(paintRect);
IntRect scrollRect(0, 0, 10, 10);
greg.scrollRect(2, 0, scrollRect);
EXPECT_TRUE(greg.hasPendingUpdate());
PaintAggregator::PendingUpdate update;
greg.popPendingUpdate(&update);
EXPECT_FALSE(update.scrollRect.isEmpty());
EXPECT_EQ(1U, update.paintRects.size());
paintRect.move(2, 0);
EXPECT_EQ(scrollRect, update.scrollRect);
EXPECT_EQ(paintRect, update.paintRects[0]);
}
TEST(PaintAggregator, ContainedPaintsBeforeAndAfterScroll)
{
PaintAggregator greg;
IntRect paintRect1(4, 4, 2, 2);
greg.invalidateRect(paintRect1);
IntRect scrollRect(0, 0, 10, 10);
greg.scrollRect(2, 0, scrollRect);
IntRect paintRect2(6, 4, 2, 2);
greg.invalidateRect(paintRect2);
IntRect expectedPaintRect = paintRect2;
EXPECT_TRUE(greg.hasPendingUpdate());
PaintAggregator::PendingUpdate update;
greg.popPendingUpdate(&update);
EXPECT_FALSE(update.scrollRect.isEmpty());
EXPECT_EQ(1U, update.paintRects.size());
EXPECT_EQ(scrollRect, update.scrollRect);
EXPECT_EQ(expectedPaintRect, update.paintRects[0]);
}
TEST(PaintAggregator, LargeContainedPaintAfterScroll)
{
PaintAggregator greg;
IntRect scrollRect(0, 0, 10, 10);
greg.scrollRect(0, 1, scrollRect);
IntRect paintRect(0, 0, 10, 9);
greg.invalidateRect(paintRect);
EXPECT_TRUE(greg.hasPendingUpdate());
PaintAggregator::PendingUpdate update;
greg.popPendingUpdate(&update);
EXPECT_TRUE(update.scrollRect.isEmpty());
EXPECT_EQ(1U, update.paintRects.size());
EXPECT_EQ(scrollRect, update.paintRects[0]);
}
TEST(PaintAggregator, LargeContainedPaintBeforeScroll)
{
PaintAggregator greg;
IntRect paintRect(0, 0, 10, 9);
greg.invalidateRect(paintRect);
IntRect scrollRect(0, 0, 10, 10);
greg.scrollRect(0, 1, scrollRect);
EXPECT_TRUE(greg.hasPendingUpdate());
PaintAggregator::PendingUpdate update;
greg.popPendingUpdate(&update);
EXPECT_TRUE(update.scrollRect.isEmpty());
EXPECT_EQ(1U, update.paintRects.size());
EXPECT_EQ(scrollRect, update.paintRects[0]);
}
TEST(PaintAggregator, OverlappingPaintBeforeScroll)
{
PaintAggregator greg;
IntRect paintRect(4, 4, 10, 2);
greg.invalidateRect(paintRect);
IntRect scrollRect(0, 0, 10, 10);
greg.scrollRect(2, 0, scrollRect);
IntRect expectedPaintRect = unionRect(scrollRect, paintRect);
EXPECT_TRUE(greg.hasPendingUpdate());
PaintAggregator::PendingUpdate update;
greg.popPendingUpdate(&update);
EXPECT_TRUE(update.scrollRect.isEmpty());
EXPECT_EQ(1U, update.paintRects.size());
EXPECT_EQ(expectedPaintRect, update.paintRects[0]);
}
TEST(PaintAggregator, OverlappingPaintAfterScroll)
{
PaintAggregator greg;
IntRect scrollRect(0, 0, 10, 10);
greg.scrollRect(2, 0, scrollRect);
IntRect paintRect(4, 4, 10, 2);
greg.invalidateRect(paintRect);
IntRect expectedPaintRect = unionRect(scrollRect, paintRect);
EXPECT_TRUE(greg.hasPendingUpdate());
PaintAggregator::PendingUpdate update;
greg.popPendingUpdate(&update);
EXPECT_TRUE(update.scrollRect.isEmpty());
EXPECT_EQ(1U, update.paintRects.size());
EXPECT_EQ(expectedPaintRect, update.paintRects[0]);
}
TEST(PaintAggregator, DisjointPaintBeforeScroll)
{
PaintAggregator greg;
IntRect paintRect(4, 4, 10, 2);
greg.invalidateRect(paintRect);
IntRect scrollRect(0, 0, 2, 10);
greg.scrollRect(2, 0, scrollRect);
EXPECT_TRUE(greg.hasPendingUpdate());
PaintAggregator::PendingUpdate update;
greg.popPendingUpdate(&update);
EXPECT_FALSE(update.scrollRect.isEmpty());
EXPECT_EQ(1U, update.paintRects.size());
EXPECT_EQ(paintRect, update.paintRects[0]);
EXPECT_EQ(scrollRect, update.scrollRect);
}
TEST(PaintAggregator, DisjointPaintAfterScroll)
{
PaintAggregator greg;
IntRect scrollRect(0, 0, 2, 10);
greg.scrollRect(2, 0, scrollRect);
IntRect paintRect(4, 4, 10, 2);
greg.invalidateRect(paintRect);
EXPECT_TRUE(greg.hasPendingUpdate());
PaintAggregator::PendingUpdate update;
greg.popPendingUpdate(&update);
EXPECT_FALSE(update.scrollRect.isEmpty());
EXPECT_EQ(1U, update.paintRects.size());
EXPECT_EQ(paintRect, update.paintRects[0]);
EXPECT_EQ(scrollRect, update.scrollRect);
}
TEST(PaintAggregator, ContainedPaintTrimmedByScroll)
{
PaintAggregator greg;
IntRect paintRect(4, 4, 6, 6);
greg.invalidateRect(paintRect);
IntRect scrollRect(0, 0, 10, 10);
greg.scrollRect(2, 0, scrollRect);
IntRect expectedPaintRect(6, 4, 4, 6);
EXPECT_TRUE(greg.hasPendingUpdate());
PaintAggregator::PendingUpdate update;
greg.popPendingUpdate(&update);
EXPECT_FALSE(update.scrollRect.isEmpty());
EXPECT_EQ(1U, update.paintRects.size());
EXPECT_EQ(expectedPaintRect, update.paintRects[0]);
EXPECT_EQ(scrollRect, update.scrollRect);
}
TEST(PaintAggregator, ContainedPaintEliminatedByScroll)
{
PaintAggregator greg;
IntRect paintRect(4, 4, 6, 6);
greg.invalidateRect(paintRect);
IntRect scrollRect(0, 0, 10, 10);
greg.scrollRect(6, 0, scrollRect);
EXPECT_TRUE(greg.hasPendingUpdate());
PaintAggregator::PendingUpdate update;
greg.popPendingUpdate(&update);
EXPECT_FALSE(update.scrollRect.isEmpty());
EXPECT_TRUE(update.paintRects.isEmpty());
EXPECT_EQ(scrollRect, update.scrollRect);
}
TEST(PaintAggregator, ContainedPaintAfterScrollTrimmedByScrollDamage)
{
PaintAggregator greg;
IntRect scrollRect(0, 0, 10, 10);
greg.scrollRect(4, 0, scrollRect);
IntRect paintRect(2, 0, 4, 10);
greg.invalidateRect(paintRect);
IntRect expectedScrollDamage(0, 0, 4, 10);
IntRect expectedPaintRect(4, 0, 2, 10);
EXPECT_TRUE(greg.hasPendingUpdate());
PaintAggregator::PendingUpdate update;
greg.popPendingUpdate(&update);
EXPECT_FALSE(update.scrollRect.isEmpty());
EXPECT_EQ(1U, update.paintRects.size());
EXPECT_EQ(scrollRect, update.scrollRect);
EXPECT_EQ(expectedScrollDamage, update.calculateScrollDamage());
EXPECT_EQ(expectedPaintRect, update.paintRects[0]);
}
TEST(PaintAggregator, ContainedPaintAfterScrollEliminatedByScrollDamage)
{
PaintAggregator greg;
IntRect scrollRect(0, 0, 10, 10);
greg.scrollRect(4, 0, scrollRect);
IntRect paintRect(2, 0, 2, 10);
greg.invalidateRect(paintRect);
IntRect expectedScrollDamage(0, 0, 4, 10);
EXPECT_TRUE(greg.hasPendingUpdate());
PaintAggregator::PendingUpdate update;
greg.popPendingUpdate(&update);
EXPECT_FALSE(update.scrollRect.isEmpty());
EXPECT_TRUE(update.paintRects.isEmpty());
EXPECT_EQ(scrollRect, update.scrollRect);
EXPECT_EQ(expectedScrollDamage, update.calculateScrollDamage());
}
}