diff options
Diffstat (limited to 'Source/WebKit/chromium/tests')
41 files changed, 2061 insertions, 439 deletions
diff --git a/Source/WebKit/chromium/tests/CCActiveAnimationTest.cpp b/Source/WebKit/chromium/tests/CCActiveAnimationTest.cpp index a1ab770b7..af9fde1d5 100644 --- a/Source/WebKit/chromium/tests/CCActiveAnimationTest.cpp +++ b/Source/WebKit/chromium/tests/CCActiveAnimationTest.cpp @@ -69,6 +69,16 @@ TEST(CCActiveAnimationTest, TrimTimeInfiniteIterations) EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(1.5)); } +TEST(CCActiveAnimationTest, TrimTimeAlternating) +{ + OwnPtr<CCActiveAnimation> anim(createActiveAnimation(-1)); + anim->setAlternatesDirection(true); + EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0)); + EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(0.5)); + EXPECT_EQ(1, anim->trimTimeToCurrentIteration(1)); + EXPECT_EQ(0.75, anim->trimTimeToCurrentIteration(1.25)); +} + TEST(CCActiveAnimationTest, TrimTimeStartTime) { OwnPtr<CCActiveAnimation> anim(createActiveAnimation(1)); diff --git a/Source/WebKit/chromium/tests/CCLayerAnimationControllerTest.cpp b/Source/WebKit/chromium/tests/CCLayerAnimationControllerTest.cpp index fa95a2ac5..1d5409f98 100644 --- a/Source/WebKit/chromium/tests/CCLayerAnimationControllerTest.cpp +++ b/Source/WebKit/chromium/tests/CCLayerAnimationControllerTest.cpp @@ -86,34 +86,45 @@ TEST(CCLayerAnimationControllerTest, createOpacityAnimation) EXPECT_EQ(1, curve->getValue(duration)); } -TEST(CCLayerAnimationControllerTest, ignoreUnsupportedAnimationDirections) +TEST(CCLayerAnimationControllerTest, createTransformAnimation) { FakeLayerAnimationControllerClient dummy; OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::create(&dummy)); const double duration = 1; - WebCore::KeyframeValueList values(AnimatedPropertyOpacity); - values.insert(new FloatAnimationValue(0, 0)); - values.insert(new FloatAnimationValue(duration, 1)); + WebCore::KeyframeValueList values(AnimatedPropertyWebkitTransform); + + TransformOperations operations1; + operations1.operations().append(TranslateTransformOperation::create(Length(2, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X)); + values.insert(new TransformAnimationValue(0, &operations1)); + + TransformOperations operations2; + operations2.operations().append(TranslateTransformOperation::create(Length(4, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X)); + values.insert(new TransformAnimationValue(duration, &operations2)); RefPtr<Animation> animation = Animation::create(); animation->setDuration(duration); IntSize boxSize; + controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0); - animation->setDirection(Animation::AnimationDirectionAlternate); - EXPECT_FALSE(controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0)); + EXPECT_TRUE(controller->hasActiveAnimation()); - animation->setDirection(Animation::AnimationDirectionAlternateReverse); - EXPECT_FALSE(controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0)); + CCActiveAnimation* activeAnimation = controller->getActiveAnimation(0, CCActiveAnimation::Transform); + EXPECT_TRUE(activeAnimation); - animation->setDirection(Animation::AnimationDirectionReverse); - EXPECT_FALSE(controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0)); + EXPECT_EQ(1, activeAnimation->iterations()); + EXPECT_EQ(CCActiveAnimation::Transform, activeAnimation->targetProperty()); + + EXPECT_EQ(CCAnimationCurve::Transform, activeAnimation->curve()->type()); - animation->setDirection(Animation::AnimationDirectionNormal); - EXPECT_TRUE(controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0)); + const CCTransformAnimationCurve* curve = activeAnimation->curve()->toTransformAnimationCurve(); + EXPECT_TRUE(curve); + + expectTranslateX(2, curve->getValue(0, boxSize)); + expectTranslateX(4, curve->getValue(duration, boxSize)); } -TEST(CCLayerAnimationControllerTest, createTransformAnimation) +TEST(CCLayerAnimationControllerTest, createReversedAnimation) { FakeLayerAnimationControllerClient dummy; OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::create(&dummy)); @@ -130,6 +141,7 @@ TEST(CCLayerAnimationControllerTest, createTransformAnimation) RefPtr<Animation> animation = Animation::create(); animation->setDuration(duration); + animation->setDirection(Animation::AnimationDirectionReverse); IntSize boxSize; controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0); @@ -147,10 +159,92 @@ TEST(CCLayerAnimationControllerTest, createTransformAnimation) const CCTransformAnimationCurve* curve = activeAnimation->curve()->toTransformAnimationCurve(); EXPECT_TRUE(curve); + expectTranslateX(4, curve->getValue(0, boxSize)); + expectTranslateX(2, curve->getValue(duration, boxSize)); +} + +TEST(CCLayerAnimationControllerTest, createAlternatingAnimation) +{ + FakeLayerAnimationControllerClient dummy; + OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::create(&dummy)); + const double duration = 1; + WebCore::KeyframeValueList values(AnimatedPropertyWebkitTransform); + + TransformOperations operations1; + operations1.operations().append(TranslateTransformOperation::create(Length(2, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X)); + values.insert(new TransformAnimationValue(0, &operations1)); + + TransformOperations operations2; + operations2.operations().append(TranslateTransformOperation::create(Length(4, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X)); + values.insert(new TransformAnimationValue(duration, &operations2)); + + RefPtr<Animation> animation = Animation::create(); + animation->setDuration(duration); + animation->setDirection(Animation::AnimationDirectionAlternate); + animation->setIterationCount(2); + + IntSize boxSize; + controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0); + + EXPECT_TRUE(controller->hasActiveAnimation()); + + CCActiveAnimation* activeAnimation = controller->getActiveAnimation(0, CCActiveAnimation::Transform); + EXPECT_TRUE(activeAnimation); + EXPECT_TRUE(activeAnimation->alternatesDirection()); + + EXPECT_EQ(2, activeAnimation->iterations()); + EXPECT_EQ(CCActiveAnimation::Transform, activeAnimation->targetProperty()); + + EXPECT_EQ(CCAnimationCurve::Transform, activeAnimation->curve()->type()); + + const CCTransformAnimationCurve* curve = activeAnimation->curve()->toTransformAnimationCurve(); + EXPECT_TRUE(curve); + expectTranslateX(2, curve->getValue(0, boxSize)); expectTranslateX(4, curve->getValue(duration, boxSize)); } +TEST(CCLayerAnimationControllerTest, createReversedAlternatingAnimation) +{ + FakeLayerAnimationControllerClient dummy; + OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::create(&dummy)); + const double duration = 1; + WebCore::KeyframeValueList values(AnimatedPropertyWebkitTransform); + + TransformOperations operations1; + operations1.operations().append(TranslateTransformOperation::create(Length(2, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X)); + values.insert(new TransformAnimationValue(0, &operations1)); + + TransformOperations operations2; + operations2.operations().append(TranslateTransformOperation::create(Length(4, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X)); + values.insert(new TransformAnimationValue(duration, &operations2)); + + RefPtr<Animation> animation = Animation::create(); + animation->setDuration(duration); + animation->setDirection(Animation::AnimationDirectionAlternateReverse); + animation->setIterationCount(2); + + IntSize boxSize; + controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0); + + EXPECT_TRUE(controller->hasActiveAnimation()); + + CCActiveAnimation* activeAnimation = controller->getActiveAnimation(0, CCActiveAnimation::Transform); + EXPECT_TRUE(activeAnimation); + EXPECT_TRUE(activeAnimation->alternatesDirection()); + + EXPECT_EQ(2, activeAnimation->iterations()); + EXPECT_EQ(CCActiveAnimation::Transform, activeAnimation->targetProperty()); + + EXPECT_EQ(CCAnimationCurve::Transform, activeAnimation->curve()->type()); + + const CCTransformAnimationCurve* curve = activeAnimation->curve()->toTransformAnimationCurve(); + EXPECT_TRUE(curve); + + expectTranslateX(4, curve->getValue(0, boxSize)); + expectTranslateX(2, curve->getValue(duration, boxSize)); +} + TEST(CCLayerAnimationControllerTest, syncNewAnimation) { FakeLayerAnimationControllerClient dummyImpl; diff --git a/Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp b/Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp index 51a032618..d243aee4a 100644 --- a/Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp +++ b/Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp @@ -1172,7 +1172,7 @@ TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicIsNotClippedBe EXPECT_INT_RECT_EQ(expected, actual); } -TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveIsClipped) +TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveWhenClippedByW) { // Test the calculateVisibleRect() function works correctly when projecting a surface // onto a layer, but the layer is partially behind the camera (not just behind the @@ -1190,7 +1190,7 @@ TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveIsClipped) // center of the layer. layerToSurfaceTransform.makeIdentity(); layerToSurfaceTransform.applyPerspective(1); - layerToSurfaceTransform.translate3d(0, 0, 1); + layerToSurfaceTransform.translate3d(-1, 0, 1); layerToSurfaceTransform.rotate3d(0, 45, 0); // Sanity check that this transform does indeed cause w < 0 when applying the @@ -1199,7 +1199,7 @@ TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveIsClipped) CCMathUtil::mapQuad(layerToSurfaceTransform, FloatQuad(FloatRect(layerContentRect)), clipped); ASSERT_TRUE(clipped); - int expectedXPosition = -10; + int expectedXPosition = 0; int expectedWidth = 10; IntRect actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform); EXPECT_EQ(expectedXPosition, actual.x()); diff --git a/Source/WebKit/chromium/tests/CCLayerTreeHostImplTest.cpp b/Source/WebKit/chromium/tests/CCLayerTreeHostImplTest.cpp index ff2497085..58668d0ef 100644 --- a/Source/WebKit/chromium/tests/CCLayerTreeHostImplTest.cpp +++ b/Source/WebKit/chromium/tests/CCLayerTreeHostImplTest.cpp @@ -28,6 +28,7 @@ #include "CCAnimationTestCommon.h" #include "CCLayerTestCommon.h" +#include "CCTiledLayerTestCommon.h" #include "FakeWebGraphicsContext3D.h" #include "GraphicsContext3DPrivate.h" #include "LayerRendererChromium.h" @@ -59,6 +60,8 @@ public: { CCSettings settings; m_hostImpl = CCLayerTreeHostImpl::create(settings, this); + m_hostImpl->initializeLayerRenderer(createContext(), adoptPtr(new FakeTextureUploader)); + m_hostImpl->setViewportSize(IntSize(10, 10)); } virtual void didLoseContextOnImplThread() OVERRIDE { } @@ -254,8 +257,6 @@ TEST_F(CCLayerTreeHostImplTest, nonFastScrollableRegionBasic) TEST_F(CCLayerTreeHostImplTest, nonFastScrollableRegionWithOffset) { - m_hostImpl->initializeLayerRenderer(createContext()); - OwnPtr<CCLayerImpl> root = CCLayerImpl::create(0); root->setScrollable(true); root->setScrollPosition(IntPoint(0, 0)); @@ -440,49 +441,51 @@ private: TEST_F(CCLayerTreeHostImplTest, didDrawNotCalledOnHiddenLayer) { - m_hostImpl->initializeLayerRenderer(createContext()); - - // Ensure visibleLayerRect for root layer is empty - m_hostImpl->setViewportSize(IntSize(0, 0)); - + // The root layer is always drawn, so run this test on a child layer that + // will be masked out by the root layer's bounds. m_hostImpl->setRootLayer(DidDrawCheckLayer::create(0)); DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLayer()); + root->setMasksToBounds(true); + + root->addChild(DidDrawCheckLayer::create(1)); + DidDrawCheckLayer* layer = static_cast<DidDrawCheckLayer*>(root->children()[0].get()); + // Ensure visibleLayerRect for layer is empty + layer->setPosition(FloatPoint(100, 100)); + layer->setBounds(IntSize(10, 10)); + layer->setContentBounds(IntSize(10, 10)); CCLayerTreeHostImpl::FrameData frame; - EXPECT_FALSE(root->willDrawCalled()); - EXPECT_FALSE(root->didDrawCalled()); + EXPECT_FALSE(layer->willDrawCalled()); + EXPECT_FALSE(layer->didDrawCalled()); EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); m_hostImpl->drawLayers(frame); m_hostImpl->didDrawAllLayers(frame); - EXPECT_FALSE(root->willDrawCalled()); - EXPECT_FALSE(root->didDrawCalled()); + EXPECT_FALSE(layer->willDrawCalled()); + EXPECT_FALSE(layer->didDrawCalled()); - EXPECT_TRUE(root->visibleLayerRect().isEmpty()); + EXPECT_TRUE(layer->visibleLayerRect().isEmpty()); - // Ensure visibleLayerRect for root layer is not empty - m_hostImpl->setViewportSize(IntSize(10, 10)); + // Ensure visibleLayerRect for layer layer is not empty + layer->setPosition(FloatPoint(0, 0)); - EXPECT_FALSE(root->willDrawCalled()); - EXPECT_FALSE(root->didDrawCalled()); + EXPECT_FALSE(layer->willDrawCalled()); + EXPECT_FALSE(layer->didDrawCalled()); EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); m_hostImpl->drawLayers(frame); m_hostImpl->didDrawAllLayers(frame); - EXPECT_TRUE(root->willDrawCalled()); - EXPECT_TRUE(root->didDrawCalled()); + EXPECT_TRUE(layer->willDrawCalled()); + EXPECT_TRUE(layer->didDrawCalled()); - EXPECT_FALSE(root->visibleLayerRect().isEmpty()); + EXPECT_FALSE(layer->visibleLayerRect().isEmpty()); } TEST_F(CCLayerTreeHostImplTest, didDrawCalledOnAllLayers) { - m_hostImpl->initializeLayerRenderer(createContext()); - m_hostImpl->setViewportSize(IntSize(10, 10)); - m_hostImpl->setRootLayer(DidDrawCheckLayer::create(0)); DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLayer()); @@ -533,9 +536,6 @@ private: TEST_F(CCLayerTreeHostImplTest, prepareToDrawFailsWhenAnimationUsesCheckerboard) { - m_hostImpl->initializeLayerRenderer(createContext()); - m_hostImpl->setViewportSize(IntSize(10, 10)); - // When the texture is not missing, we draw as usual. m_hostImpl->setRootLayer(DidDrawCheckLayer::create(0)); DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLayer()); @@ -660,8 +660,6 @@ private: // https://bugs.webkit.org/show_bug.cgi?id=75783 TEST_F(CCLayerTreeHostImplTest, blendingOffWhenDrawingOpaqueLayers) { - m_hostImpl->initializeLayerRenderer(createContext()); - m_hostImpl->setViewportSize(IntSize(10, 10)); { OwnPtr<CCLayerImpl> root = CCLayerImpl::create(0); @@ -878,7 +876,7 @@ TEST_F(CCLayerTreeHostImplTest, blendingOffWhenDrawingOpaqueLayers) TEST_F(CCLayerTreeHostImplTest, viewportCovered) { - m_hostImpl->initializeLayerRenderer(createContext()); + m_hostImpl->initializeLayerRenderer(createContext(), adoptPtr(new FakeTextureUploader)); m_hostImpl->setBackgroundColor(Color::gray); IntSize viewportSize(1000, 1000); @@ -989,8 +987,7 @@ TEST_F(CCLayerTreeHostImplTest, reshapeNotCalledUntilDraw) { ReshapeTrackerContext* reshapeTracker = new ReshapeTrackerContext(); RefPtr<GraphicsContext3D> context = GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(reshapeTracker), GraphicsContext3D::RenderDirectlyToHostWindow); - m_hostImpl->initializeLayerRenderer(context); - m_hostImpl->setViewportSize(IntSize(10, 10)); + m_hostImpl->initializeLayerRenderer(context, adoptPtr(new FakeTextureUploader)); CCLayerImpl* root = new FakeDrawableCCLayerImpl(1); root->setAnchorPoint(FloatPoint(0, 0)); @@ -1039,7 +1036,7 @@ TEST_F(CCLayerTreeHostImplTest, partialSwapReceivesDamageRect) CCSettings settings; settings.partialSwapEnabled = true; OwnPtr<CCLayerTreeHostImpl> layerTreeHostImpl = CCLayerTreeHostImpl::create(settings, this); - layerTreeHostImpl->initializeLayerRenderer(context); + layerTreeHostImpl->initializeLayerRenderer(context, adoptPtr(new FakeTextureUploader())); layerTreeHostImpl->setViewportSize(IntSize(500, 500)); CCLayerImpl* root = new FakeDrawableCCLayerImpl(1); @@ -1125,9 +1122,6 @@ private: TEST_F(CCLayerTreeHostImplTest, contextLostAndRestoredNotificationSentToAllLayers) { - m_hostImpl->initializeLayerRenderer(createContext()); - m_hostImpl->setViewportSize(IntSize(10, 10)); - m_hostImpl->setRootLayer(ContextLostNotificationCheckLayer::create(0)); ContextLostNotificationCheckLayer* root = static_cast<ContextLostNotificationCheckLayer*>(m_hostImpl->rootLayer()); @@ -1141,7 +1135,7 @@ TEST_F(CCLayerTreeHostImplTest, contextLostAndRestoredNotificationSentToAllLayer EXPECT_FALSE(layer1->didLoseContextCalled()); EXPECT_FALSE(layer2->didLoseContextCalled()); - m_hostImpl->initializeLayerRenderer(createContext()); + m_hostImpl->initializeLayerRenderer(createContext(), adoptPtr(new FakeTextureUploader)); EXPECT_TRUE(root->didLoseContextCalled()); EXPECT_TRUE(layer1->didLoseContextCalled()); @@ -1156,7 +1150,7 @@ public: TEST_F(CCLayerTreeHostImplTest, finishAllRenderingAfterContextLost) { // The context initialization will fail, but we should still be able to call finishAllRendering() without any ill effects. - m_hostImpl->initializeLayerRenderer(GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new FakeWebGraphicsContext3DMakeCurrentFails), GraphicsContext3D::RenderDirectlyToHostWindow)); + m_hostImpl->initializeLayerRenderer(GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new FakeWebGraphicsContext3DMakeCurrentFails), GraphicsContext3D::RenderDirectlyToHostWindow), adoptPtr(new FakeTextureUploader)); m_hostImpl->finishAllRendering(); } @@ -1172,9 +1166,6 @@ private: TEST_F(CCLayerTreeHostImplTest, scrollbarLayerLostContext) { - m_hostImpl->initializeLayerRenderer(createContext()); - m_hostImpl->setViewportSize(IntSize(10, 10)); - m_hostImpl->setRootLayer(ScrollbarLayerFakePaint::create(0)); ScrollbarLayerFakePaint* scrollbar = static_cast<ScrollbarLayerFakePaint*>(m_hostImpl->rootLayer()); scrollbar->setBounds(IntSize(1, 1)); @@ -1189,7 +1180,7 @@ TEST_F(CCLayerTreeHostImplTest, scrollbarLayerLostContext) // Scrollbar layer should always generate quads, even after lost context EXPECT_GT(renderPass->quadList().size(), 0u); m_hostImpl->didDrawAllLayers(frame); - m_hostImpl->initializeLayerRenderer(createContext()); + m_hostImpl->initializeLayerRenderer(createContext(), adoptPtr(new FakeTextureUploader)); } } @@ -1322,9 +1313,6 @@ private: TEST_F(CCLayerTreeHostImplTest, dontUseOldResourcesAfterLostContext) { - m_hostImpl->initializeLayerRenderer(createContext()); - m_hostImpl->setViewportSize(IntSize(10, 10)); - OwnPtr<CCLayerImpl> rootLayer(CCLayerImpl::create(0)); rootLayer->setBounds(IntSize(10, 10)); rootLayer->setAnchorPoint(FloatPoint(0, 0)); @@ -1367,7 +1355,7 @@ TEST_F(CCLayerTreeHostImplTest, dontUseOldResourcesAfterLostContext) // Lose the context, replacing it with a StrictWebGraphicsContext3D, that // will warn if any resource from the previous context gets used. - m_hostImpl->initializeLayerRenderer(StrictWebGraphicsContext3D::createGraphicsContext()); + m_hostImpl->initializeLayerRenderer(StrictWebGraphicsContext3D::createGraphicsContext(), adoptPtr(new FakeTextureUploader)); EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); m_hostImpl->drawLayers(frame); m_hostImpl->didDrawAllLayers(frame); diff --git a/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp b/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp index f2382b359..44f87c6a9 100644 --- a/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp +++ b/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp @@ -788,7 +788,12 @@ private: int m_numDraws; }; +#if OS(WINDOWS) +// http://webkit.org/b/74623 +TEST_F(CCLayerTreeHostTestSetNeedsCommit2, FLAKY_runMultiThread) +#else TEST_F(CCLayerTreeHostTestSetNeedsCommit2, runMultiThread) +#endif { runTestThreaded(); } @@ -840,6 +845,62 @@ TEST_F(CCLayerTreeHostTestSetNeedsRedraw, runMultiThread) runTestThreaded(); } +// If the layerTreeHost says it can't draw, then we should not try to draw. +// FIXME: Make this run in single threaded mode too. http://crbug.com/127481 +class CCLayerTreeHostTestCanDrawBlocksDrawing : public CCLayerTreeHostTestThreadOnly { +public: + CCLayerTreeHostTestCanDrawBlocksDrawing() + : m_numCommits(0) + { + } + + virtual void beginTest() + { + } + + virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl) + { + // Only the initial draw should bring us here. + EXPECT_TRUE(impl->canDraw()); + EXPECT_EQ(0, impl->sourceFrameNumber()); + } + + virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl* impl) + { + if (m_numCommits >= 1) { + // After the first commit, we should not be able to draw. + EXPECT_FALSE(impl->canDraw()); + } + } + + virtual void didCommitAndDrawFrame() + { + m_numCommits++; + if (m_numCommits == 1) { + // Make the viewport empty so the host says it can't draw. + m_layerTreeHost->setViewportSize(IntSize(0, 0)); + + OwnArrayPtr<char> pixels(adoptArrayPtr(new char[4])); + m_layerTreeHost->compositeAndReadback(static_cast<void*>(pixels.get()), IntRect(0, 0, 1, 1)); + } else if (m_numCommits == 2) { + m_layerTreeHost->setNeedsCommit(); + m_layerTreeHost->finishAllRendering(); + endTest(); + } + } + + virtual void afterTest() + { + } + +private: + int m_numCommits; +}; + +TEST_F(CCLayerTreeHostTestCanDrawBlocksDrawing, runMultiThread) +{ + runTestThreaded(); +} // beginLayerWrite should prevent draws from executing until a commit occurs class CCLayerTreeHostTestWriteLayersRedraw : public CCLayerTreeHostTestThreadOnly { @@ -1096,7 +1157,12 @@ private: int m_numAnimates; }; +#if OS(WINDOWS) +// http://webkit.org/b/74623 +TEST_F(CCLayerTreeHostTestTickAnimationWhileBackgrounded, FLAKY_runMultiThread) +#else TEST_F(CCLayerTreeHostTestTickAnimationWhileBackgrounded, runMultiThread) +#endif { runTestThreaded(); } @@ -1134,7 +1200,12 @@ public: private: }; +#if OS(WINDOWS) +// http://webkit.org/b/74623 +TEST_F(CCLayerTreeHostTestAddAnimationWithTimingFunction, FLAKY_runMultiThread) +#else TEST_F(CCLayerTreeHostTestAddAnimationWithTimingFunction, runMultiThread) +#endif { runTestThreaded(); } @@ -1168,7 +1239,12 @@ public: } }; +#if OS(WINDOWS) +// http://webkit.org/b/74623 +TEST_F(CCLayerTreeHostTestDoNotSkipLayersWithAnimatedOpacity, FLAKY_runMultiThread) +#else TEST_F(CCLayerTreeHostTestDoNotSkipLayersWithAnimatedOpacity, runMultiThread) +#endif { runTestThreaded(); } @@ -1340,11 +1416,11 @@ public: virtual void beginCommitOnCCThread(CCLayerTreeHostImpl* impl) { LayerChromium* root = m_layerTreeHost->rootLayer(); - if (!m_layerTreeHost->frameNumber()) + if (!impl->sourceFrameNumber()) EXPECT_EQ(root->scrollPosition(), m_initialScroll); - else if (m_layerTreeHost->frameNumber() == 1) + else if (impl->sourceFrameNumber() == 1) EXPECT_EQ(root->scrollPosition(), m_initialScroll + m_scrollAmount + m_scrollAmount); - else if (m_layerTreeHost->frameNumber() == 2) + else if (impl->sourceFrameNumber() == 2) EXPECT_EQ(root->scrollPosition(), m_initialScroll + m_scrollAmount + m_scrollAmount); } @@ -1711,10 +1787,10 @@ public: { CompositorFakeWebGraphicsContext3DWithTextureTracking* context = static_cast<CompositorFakeWebGraphicsContext3DWithTextureTracking*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(impl->context())); - switch (impl->frameNumber()) { + switch (impl->sourceFrameNumber()) { case 0: // Number of textures should be one. - EXPECT_EQ(1, context->numTextures()); + ASSERT_EQ(1, context->numTextures()); // Number of textures used for commit should be one. EXPECT_EQ(1, context->numUsedTextures()); // Verify that used texture is correct. @@ -1725,7 +1801,7 @@ public: case 1: // Number of textures should be two as the first texture // is used by impl thread and cannot by used for update. - EXPECT_EQ(2, context->numTextures()); + ASSERT_EQ(2, context->numTextures()); // Number of textures used for commit should still be one. EXPECT_EQ(1, context->numUsedTextures()); // First texture should not have been used. @@ -1748,7 +1824,7 @@ public: // Number of textures used for draw should always be one. EXPECT_EQ(1, context->numUsedTextures()); - if (impl->frameNumber() < 2) { + if (impl->sourceFrameNumber() < 1) { context->resetUsedTextures(); postSetNeedsAnimateAndCommitToMainThread(); postSetNeedsRedrawToMainThread(); @@ -1815,10 +1891,10 @@ public: { CompositorFakeWebGraphicsContext3DWithTextureTracking* context = static_cast<CompositorFakeWebGraphicsContext3DWithTextureTracking*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(impl->context())); - switch (impl->frameNumber()) { + switch (impl->sourceFrameNumber()) { case 0: // Number of textures should be two. - EXPECT_EQ(2, context->numTextures()); + ASSERT_EQ(2, context->numTextures()); // Number of textures used for commit should be two. EXPECT_EQ(2, context->numUsedTextures()); // Verify that used textures are correct. @@ -1830,7 +1906,7 @@ public: case 1: // Number of textures should be four as the first two // textures are used by the impl thread. - EXPECT_EQ(4, context->numTextures()); + ASSERT_EQ(4, context->numTextures()); // Number of textures used for commit should still be two. EXPECT_EQ(2, context->numUsedTextures()); // First two textures should not have been used. @@ -1846,7 +1922,7 @@ public: // Number of textures should be three as we allow one // partial update and the first two textures are used by // the impl thread. - EXPECT_EQ(3, context->numTextures()); + ASSERT_EQ(3, context->numTextures()); // Number of textures used for commit should still be two. EXPECT_EQ(2, context->numUsedTextures()); // First texture should have been used. @@ -1886,12 +1962,12 @@ public: // Number of textures used for drawing should two except for frame 4 // where the viewport only contains one layer. - if (impl->frameNumber() == 4) + if (impl->sourceFrameNumber() == 3) EXPECT_EQ(1, context->numUsedTextures()); else EXPECT_EQ(2, context->numUsedTextures()); - if (impl->frameNumber() < 5) { + if (impl->sourceFrameNumber() < 4) { context->resetUsedTextures(); postSetNeedsAnimateAndCommitToMainThread(); postSetNeedsRedrawToMainThread(); diff --git a/Source/WebKit/chromium/tests/CCMathUtilTest.cpp b/Source/WebKit/chromium/tests/CCMathUtilTest.cpp index db0a4e53f..3909677a5 100644 --- a/Source/WebKit/chromium/tests/CCMathUtilTest.cpp +++ b/Source/WebKit/chromium/tests/CCMathUtilTest.cpp @@ -99,4 +99,21 @@ TEST(CCMathUtilTest, verifyBackfaceVisibilityForPerspective) EXPECT_TRUE(layerSpaceToProjectionPlane.isBackFaceVisible()); } +TEST(CCMathUtilTest, verifyProjectionOfPerpendicularPlane) +{ + // In this case, the m33() element of the transform becomes zero, which could cause a + // divide-by-zero when projecting points/quads. + + TransformationMatrix transform; + transform.makeIdentity(); + transform.setM33(0); + + FloatRect rect = FloatRect(0, 0, 1, 1); + FloatRect projectedRect = CCMathUtil::projectClippedRect(transform, rect); + + EXPECT_EQ(0, projectedRect.x()); + EXPECT_EQ(0, projectedRect.y()); + EXPECT_TRUE(projectedRect.isEmpty()); +} + } // namespace diff --git a/Source/WebKit/chromium/tests/CCOcclusionTrackerTest.cpp b/Source/WebKit/chromium/tests/CCOcclusionTrackerTest.cpp index 73b4d8273..891c305b0 100644 --- a/Source/WebKit/chromium/tests/CCOcclusionTrackerTest.cpp +++ b/Source/WebKit/chromium/tests/CCOcclusionTrackerTest.cpp @@ -172,6 +172,7 @@ protected: m_renderSurfaceLayerListChromium.clear(); m_renderSurfaceLayerListImpl.clear(); m_replicaLayers.clear(); + m_maskLayers.clear(); CCLayerTreeHost::setNeedsFilterContext(false); } @@ -233,6 +234,15 @@ protected: return layerPtr; } + typename Types::LayerType* createMaskLayer(typename Types::LayerType* owningLayer, const IntSize& bounds) + { + typename Types::ContentLayerPtrType layer(Types::createContentLayer()); + typename Types::ContentLayerType* layerPtr = layer.get(); + setProperties(layerPtr, identityMatrix, FloatPoint(), bounds); + setMask(owningLayer, layer.release()); + return layerPtr; + } + typename Types::ContentLayerType* createDrawingSurface(typename Types::LayerType* parent, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds, bool opaque) { typename Types::ContentLayerType* layer = createDrawingLayer(parent, transform, position, bounds, opaque); @@ -360,6 +370,17 @@ private: owningLayer->setReplicaLayer(layer); } + void setMask(LayerChromium* owningLayer, PassRefPtr<LayerChromium> layer) + { + owningLayer->setMaskLayer(layer.get()); + m_maskLayers.append(layer); + } + + void setMask(CCLayerImpl* owningLayer, PassOwnPtr<CCLayerImpl> layer) + { + owningLayer->setMaskLayer(layer); + } + // These hold ownership of the layers for the duration of the test. typename Types::LayerPtrType m_root; Vector<RefPtr<LayerChromium> > m_renderSurfaceLayerListChromium; @@ -368,6 +389,7 @@ private: typename Types::LayerIterator m_layerIterator; typename Types::LayerType* m_lastLayerVisited; Vector<RefPtr<LayerChromium> > m_replicaLayers; + Vector<RefPtr<LayerChromium> > m_maskLayers; }; #define RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \ @@ -1330,6 +1352,38 @@ protected: ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestReplicaWithClipping); template<class Types, bool opaqueLayers> +class CCOcclusionTrackerTestReplicaWithMask : public CCOcclusionTrackerTest<Types, opaqueLayers> { +protected: + void runMyTest() + { + typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 200)); + typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 100), IntSize(50, 50), true); + typename Types::LayerType* replica = this->createReplicaLayer(surface, this->identityMatrix, FloatPoint(50, 50), IntSize()); + this->createMaskLayer(replica, IntSize(10, 10)); + this->calcDrawEtc(parent); + + TestCCOcclusionTrackerWithScissor<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000)); + occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000)); + + this->visitLayer(surface, occlusion); + + EXPECT_EQ_RECT(IntRect(0, 100, 50, 50), occlusion.occlusionInScreenSpace().bounds()); + EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size()); + EXPECT_EQ_RECT(IntRect(0, 0, 50, 50), occlusion.occlusionInTargetSurface().bounds()); + EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size()); + + this->visitContributingSurface(surface, occlusion); + this->enterLayer(parent, occlusion); + + // The replica should not be occluding the parent, since it has a mask applied to it. + EXPECT_EQ_RECT(IntRect(0, 100, 50, 50), occlusion.occlusionInTargetSurface().bounds()); + EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size()); + } +}; + +ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestReplicaWithMask); + +template<class Types, bool opaqueLayers> class CCOcclusionTrackerTestLayerScissorRectOutsideChild : public CCOcclusionTrackerTest<Types, opaqueLayers> { protected: void runMyTest() diff --git a/Source/WebKit/chromium/tests/CCQuadCullerTest.cpp b/Source/WebKit/chromium/tests/CCQuadCullerTest.cpp index 991cddc46..634a25c7a 100644 --- a/Source/WebKit/chromium/tests/CCQuadCullerTest.cpp +++ b/Source/WebKit/chromium/tests/CCQuadCullerTest.cpp @@ -91,7 +91,7 @@ static PassOwnPtr<CCTiledLayerImpl> makeLayer(CCTiledLayerImpl* parent, const Tr static void appendQuads(CCQuadList& quadList, Vector<OwnPtr<CCSharedQuadState> >& sharedStateList, CCTiledLayerImpl* layer, CCLayerIteratorType& it, CCOcclusionTrackerImpl& occlusionTracker) { occlusionTracker.enterLayer(it); - CCQuadCuller quadCuller(quadList, layer, &occlusionTracker); + CCQuadCuller quadCuller(quadList, layer, &occlusionTracker, false); OwnPtr<CCSharedQuadState> sharedQuadState = layer->createSharedQuadState(); bool hadMissingTiles = false; layer->appendQuads(quadCuller, sharedQuadState.get(), hadMissingTiles); diff --git a/Source/WebKit/chromium/tests/CCTiledLayerTestCommon.h b/Source/WebKit/chromium/tests/CCTiledLayerTestCommon.h index c028ea725..4eb875b1e 100644 --- a/Source/WebKit/chromium/tests/CCTiledLayerTestCommon.h +++ b/Source/WebKit/chromium/tests/CCTiledLayerTestCommon.h @@ -161,6 +161,9 @@ public: class FakeTextureUploader : public WebCore::TextureUploader { public: + virtual bool isBusy() { return false; } + virtual void beginUploads() { } + virtual void endUploads() { } virtual void uploadTexture(WebCore::GraphicsContext3D* context, WebCore::LayerTextureUpdater::Texture* texture, WebCore::TextureAllocator* allocator, const WebCore::IntRect sourceRect, const WebCore::IntRect destRect) { texture->updateRect(context, allocator, sourceRect, destRect); } }; diff --git a/Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp b/Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp index f464dcbbc..b42485b71 100644 --- a/Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp +++ b/Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp @@ -90,6 +90,9 @@ public: class MockTextureUploader : public TextureUploader { public: + MOCK_METHOD0(isBusy, bool()); + MOCK_METHOD0(beginUploads, void()); + MOCK_METHOD0(endUploads, void()); MOCK_METHOD5(uploadTexture, void(GraphicsContext3D*, LayerTextureUpdater::Texture*, TextureAllocator*, const IntRect, const IntRect)); }; diff --git a/Source/WebKit/chromium/tests/EventListenerTest.cpp b/Source/WebKit/chromium/tests/EventListenerTest.cpp new file mode 100644 index 000000000..799ac4007 --- /dev/null +++ b/Source/WebKit/chromium/tests/EventListenerTest.cpp @@ -0,0 +1,251 @@ +/* + * Copyright (C) 2012 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#include "FrameTestHelpers.h" +#include "WebDOMEvent.h" +#include "WebDOMEventListener.h" +#include "WebDOMMutationEvent.h" +#include "WebDocument.h" +#include "WebElement.h" +#include "WebFrame.h" +#include "WebScriptSource.h" +#include "WebView.h" +#include <gtest/gtest.h> +#include <webkit/support/webkit_support.h> + +using namespace WebKit; + +namespace { + +class TestWebDOMEventListener : public WebDOMEventListener { +public: + TestWebDOMEventListener() { } + virtual ~TestWebDOMEventListener() { } + + virtual void handleEvent(const WebDOMEvent& event) OVERRIDE + { + m_events.push_back(event); + } + + size_t eventCount() const { return m_events.size(); } + + WebDOMEvent eventAt(int index) const { return m_events.at(index); } + + void clearEvents() { m_events.clear(); } + +private: + std::vector<WebDOMEvent> m_events; +}; + +class WebDOMEventListenerTest : public testing::Test { +public: + WebDOMEventListenerTest() + : m_webView(0) + { + } + + virtual void SetUp() OVERRIDE + { + std::string baseURL("http://www.example.com/"); + std::string fileName("listener/mutation_event_listener.html"); + bool executeScript = true; + FrameTestHelpers::registerMockedURLLoad(baseURL, fileName); + m_webView = FrameTestHelpers::createWebViewAndLoad(baseURL + fileName, executeScript); + } + + virtual void TearDown() OVERRIDE + { + m_webView->close(); + webkit_support::UnregisterAllMockedURLs(); + } + + WebFrame* mainFrame() const + { + return m_webView->mainFrame(); + } + + WebDocument document() const + { + return mainFrame()->document(); + } + + void executeScript(const char* code) + { + mainFrame()->executeScript(WebScriptSource(WebString::fromUTF8(code))); + } + + + static WebString GetNodeID(const WebNode& node) + { + if (node.nodeType() != WebNode::ElementNode) + return WebString(); + WebElement element = node.toConst<WebElement>(); + return element.getAttribute("id"); + } + +protected: + WebView* m_webView; +}; + + +// Tests that the right mutation events are fired when a node is added/removed. +// Note that the DOMSubtreeModified event is fairly vage, it only tells you +// something changed for the target node. +TEST_F(WebDOMEventListenerTest, NodeAddedRemovedMutationEvent) +{ + TestWebDOMEventListener eventListener; + document().addEventListener("DOMSubtreeModified", &eventListener, false); + + // Test adding a node. + executeScript("addElement('newNode')"); + ASSERT_EQ(1U, eventListener.eventCount()); + WebDOMEvent event = eventListener.eventAt(0); + ASSERT_TRUE(event.isMutationEvent()); + // No need to check any of the MutationEvent, WebKit does not set any. + EXPECT_EQ("DIV", event.target().nodeName()); + EXPECT_EQ("topDiv", GetNodeID(event.target())); + eventListener.clearEvents(); + + // Test removing a node. + executeScript("removeNode('div1')"); + ASSERT_EQ(1U, eventListener.eventCount()); + event = eventListener.eventAt(0); + ASSERT_TRUE(event.isMutationEvent()); + EXPECT_EQ("DIV", event.target().nodeName()); + EXPECT_EQ("topDiv", GetNodeID(event.target())); +} + +// Tests the right mutation event is fired when a text node is modified. +TEST_F(WebDOMEventListenerTest, TextNodeModifiedMutationEvent) +{ + TestWebDOMEventListener eventListener; + document().addEventListener("DOMSubtreeModified", &eventListener, false); + executeScript("changeText('div2', 'Hello')"); + ASSERT_EQ(1U, eventListener.eventCount()); + WebDOMEvent event = eventListener.eventAt(0); + ASSERT_TRUE(event.isMutationEvent()); + ASSERT_EQ(WebNode::TextNode, event.target().nodeType()); +} + +// Tests the right mutation events are fired when an attribute is added/removed. +TEST_F(WebDOMEventListenerTest, AttributeMutationEvent) +{ + TestWebDOMEventListener eventListener; + document().addEventListener("DOMSubtreeModified", &eventListener, false); + executeScript("document.getElementById('div2').setAttribute('myAttr'," + "'some value')"); + ASSERT_EQ(1U, eventListener.eventCount()); + WebDOMEvent event = eventListener.eventAt(0); + ASSERT_TRUE(event.isMutationEvent()); + EXPECT_EQ("DIV", event.target().nodeName()); + EXPECT_EQ("div2", GetNodeID(event.target())); + eventListener.clearEvents(); + + executeScript("document.getElementById('div2').removeAttribute('myAttr')"); + ASSERT_EQ(1U, eventListener.eventCount()); + event = eventListener.eventAt(0); + ASSERT_TRUE(event.isMutationEvent()); + EXPECT_EQ("DIV", event.target().nodeName()); + EXPECT_EQ("div2", GetNodeID(event.target())); +} + +// Tests destroying WebDOMEventListener and triggering events, we shouldn't +// crash. +TEST_F(WebDOMEventListenerTest, FireEventDeletedListener) +{ + TestWebDOMEventListener* eventListener = new TestWebDOMEventListener(); + document().addEventListener("DOMSubtreeModified", eventListener, false); + delete eventListener; + executeScript("addElement('newNode')"); // That should fire an event. +} + +// Tests registering several events on the same WebDOMEventListener and +// triggering events. +TEST_F(WebDOMEventListenerTest, SameListenerMultipleEvents) +{ + TestWebDOMEventListener eventListener; + const WebString kDOMSubtreeModifiedType("DOMSubtreeModified"); + const WebString kDOMNodeRemovedType("DOMNodeRemoved"); + document().addEventListener(kDOMSubtreeModifiedType, &eventListener, false); + WebElement div1Elem = document().getElementById("div1"); + div1Elem.addEventListener(kDOMNodeRemovedType, &eventListener, false); + + // Trigger a DOMSubtreeModified event by adding a node. + executeScript("addElement('newNode')"); + ASSERT_EQ(1U, eventListener.eventCount()); + WebDOMEvent event = eventListener.eventAt(0); + ASSERT_TRUE(event.isMutationEvent()); + EXPECT_EQ("DIV", event.target().nodeName()); + EXPECT_EQ("topDiv", GetNodeID(event.target())); + eventListener.clearEvents(); + + // Trigger for both event listener by removing the div1 node. + executeScript("removeNode('div1')"); + ASSERT_EQ(2U, eventListener.eventCount()); + // Not sure if the order of the events is important. Assuming no specific + // order. + WebString type1 = eventListener.eventAt(0).type(); + WebString type2 = eventListener.eventAt(1).type(); + EXPECT_TRUE(type1 == kDOMSubtreeModifiedType || type1 == kDOMNodeRemovedType); + EXPECT_TRUE(type2 == kDOMSubtreeModifiedType || type2 == kDOMNodeRemovedType); + EXPECT_TRUE(type1 != type2); +} + +// Tests removing event listeners. +TEST_F(WebDOMEventListenerTest, RemoveEventListener) +{ + TestWebDOMEventListener eventListener; + const WebString kDOMSubtreeModifiedType("DOMSubtreeModified"); + // Adding twice the same listener for the same event, should be supported. + document().addEventListener(kDOMSubtreeModifiedType, &eventListener, false); + document().addEventListener(kDOMSubtreeModifiedType, &eventListener, false); + + // Add a node, that should trigger 2 events. + executeScript("addElement('newNode')"); + EXPECT_EQ(2U, eventListener.eventCount()); + eventListener.clearEvents(); + + // Remove one listener and trigger an event again. + document().removeEventListener( + kDOMSubtreeModifiedType, &eventListener, false); + executeScript("addElement('newerNode')"); + EXPECT_EQ(1U, eventListener.eventCount()); + eventListener.clearEvents(); + + // Remove the last listener and trigger yet another event. + document().removeEventListener( + kDOMSubtreeModifiedType, &eventListener, false); + executeScript("addElement('newererNode')"); + EXPECT_EQ(0U, eventListener.eventCount()); +} + +} // namespace diff --git a/Source/WebKit/chromium/tests/FrameLoaderClientImplTest.cpp b/Source/WebKit/chromium/tests/FrameLoaderClientImplTest.cpp new file mode 100644 index 000000000..8fc9e42b2 --- /dev/null +++ b/Source/WebKit/chromium/tests/FrameLoaderClientImplTest.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2011, 2012 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#include "FrameLoaderClientImpl.h" + +#include "KURL.h" +#include "WebFrameClient.h" +#include "WebFrameImpl.h" +#include "WebView.h" + +#include <gtest/gtest.h> +#include <wtf/text/WTFString.h> + +using namespace WebKit; + +namespace { + +class TestWebFrameClient : public WebFrameClient { +public: + bool userAgent(const WebURL& url, WebString* userAgent) OVERRIDE + { + if (m_userAgentOverride.isEmpty()) + return false; + + *userAgent = m_userAgentOverride; + return true; + } + + void setUserAgentOverride(const WebString& userAgent) + { + m_userAgentOverride = userAgent; + } + +private: + WebString m_userAgentOverride; +}; + +class FrameLoaderClientImplTest : public testing::Test { +public: + void SetUp() + { + m_webView = WebView::create(0); + m_webView->initializeMainFrame(&m_webFrameClient); + WebFrameImpl* frame = static_cast<WebFrameImpl*>(m_webView->mainFrame()); + m_frameLoaderClientImpl = static_cast<FrameLoaderClientImpl*>(frame->frame()->loader()->client()); + } + + void TearDown() + { + m_webView->close(); + } + + void setUserAgentOverride(const WebString& userAgent) + { + return m_webFrameClient.setUserAgentOverride(userAgent); + } + + const WebString userAgent() + { + // The test always returns the same user agent, regardless of the URL passed in. + WebCore::KURL dummyURL(WebCore::ParsedURLString, "about:blank"); + WTF::CString userAgent = m_frameLoaderClientImpl->userAgent(dummyURL).utf8(); + return WebString::fromUTF8(userAgent.data(), userAgent.length()); + } + +protected: + TestWebFrameClient m_webFrameClient; + FrameLoaderClientImpl* m_frameLoaderClientImpl; + WebView* m_webView; +}; + +TEST_F(FrameLoaderClientImplTest, UserAgentOverride) +{ + const WebString defaultUserAgent = userAgent(); + const WebString override = WebString::fromUTF8("dummy override"); + + // Override the user agent and make sure we get it back. + setUserAgentOverride(override); + EXPECT_TRUE(override.equals(userAgent())); + + // Remove the override and make sure we get the original back. + setUserAgentOverride(WebString()); + EXPECT_TRUE(defaultUserAgent.equals(userAgent())); +} + +} // namespace diff --git a/Source/WebKit/chromium/tests/IDBLevelDBCodingTest.cpp b/Source/WebKit/chromium/tests/IDBLevelDBCodingTest.cpp index 60331051f..eb9962d58 100644 --- a/Source/WebKit/chromium/tests/IDBLevelDBCodingTest.cpp +++ b/Source/WebKit/chromium/tests/IDBLevelDBCodingTest.cpp @@ -83,6 +83,20 @@ TEST(IDBLevelDBCodingTest, EncodeByte) EXPECT_EQ(expected, encodeByte(c)); } +TEST(IDBLevelDBCodingTest, EncodeBool) +{ + { + Vector<char> expected; + expected.append(1); + EXPECT_EQ(expected, encodeBool(true)); + } + { + Vector<char> expected; + expected.append(0); + EXPECT_EQ(expected, encodeBool(false)); + } +} + TEST(IDBLevelDBCodingTest, MaxIDBKey) { Vector<char> maxKey = maxIDBKey(); @@ -126,6 +140,20 @@ TEST(IDBLevelDBCodingTest, EncodeInt) EXPECT_EQ(static_cast<size_t>(4), encodeInt(0xffffffff).size()); } +TEST(IDBLevelDBCodingTest, DecodeBool) +{ + { + Vector<char> encoded; + encoded.append(1); + EXPECT_TRUE(decodeBool(encoded.data(), encoded.data() + encoded.size())); + } + { + Vector<char> encoded; + encoded.append(0); + EXPECT_FALSE(decodeBool(encoded.data(), encoded.data() + encoded.size())); + } +} + TEST(IDBLevelDBCodingTest, DecodeInt) { Vector<int64_t> testCases; diff --git a/Source/WebKit/chromium/tests/LayerRendererChromiumTest.cpp b/Source/WebKit/chromium/tests/LayerRendererChromiumTest.cpp index ddab17564..69d0ff5ff 100644 --- a/Source/WebKit/chromium/tests/LayerRendererChromiumTest.cpp +++ b/Source/WebKit/chromium/tests/LayerRendererChromiumTest.cpp @@ -25,6 +25,7 @@ #include "config.h" #include "LayerRendererChromium.h" +#include "CCTiledLayerTestCommon.h" #include "FakeWebGraphicsContext3D.h" #include "GraphicsContext3D.h" #include "GraphicsContext3DPrivate.h" @@ -35,6 +36,7 @@ using namespace WebCore; using namespace WebKit; +using namespace WebKitTests; class FrameCountingMemoryAllocationSettingContext : public FakeWebGraphicsContext3D { public: @@ -91,7 +93,7 @@ private: class FakeLayerRendererChromium : public LayerRendererChromium { public: - FakeLayerRendererChromium(LayerRendererChromiumClient* client, PassRefPtr<GraphicsContext3D> context) : LayerRendererChromium(client, context) { } + FakeLayerRendererChromium(LayerRendererChromiumClient* client, PassRefPtr<GraphicsContext3D> context, PassOwnPtr<TextureUploader> uploader) : LayerRendererChromium(client, context, uploader) { } // LayerRendererChromium methods. @@ -107,7 +109,7 @@ protected: , m_suggestHaveBackbufferNo(1, false) , m_context(GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new FrameCountingMemoryAllocationSettingContext()), GraphicsContext3D::RenderDirectlyToHostWindow)) , m_mockContext(*static_cast<FrameCountingMemoryAllocationSettingContext*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(m_context.get()))) - , m_layerRendererChromium(&m_mockClient, m_context.release()) + , m_layerRendererChromium(&m_mockClient, m_context.release(), adoptPtr(new FakeTextureUploader())) { } @@ -271,7 +273,7 @@ public: TEST(LayerRendererChromiumTest2, initializationDoesNotMakeSynchronousCalls) { FakeLayerRendererChromiumClient mockClient; - FakeLayerRendererChromium layerRendererChromium(&mockClient, GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new ForbidSynchronousCallContext), GraphicsContext3D::RenderDirectlyToHostWindow)); + FakeLayerRendererChromium layerRendererChromium(&mockClient, GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new ForbidSynchronousCallContext), GraphicsContext3D::RenderDirectlyToHostWindow), adoptPtr(new FakeTextureUploader())); EXPECT_TRUE(layerRendererChromium.initialize()); } diff --git a/Source/WebKit/chromium/tests/LinkHighlightTest.cpp b/Source/WebKit/chromium/tests/LinkHighlightTest.cpp new file mode 100644 index 000000000..edcfd4a63 --- /dev/null +++ b/Source/WebKit/chromium/tests/LinkHighlightTest.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2012 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#include "LinkHighlight.h" + +#include "AnimationIdVendor.h" +#include "GraphicsLayerChromium.h" +#include "GraphicsLayerClient.h" +#include "IntRect.h" +#include "Path.h" +#include "TransformationMatrix.h" +#include <gtest/gtest.h> +#include <wtf/PassOwnPtr.h> + +using namespace WebCore; + +namespace { + +class MockGraphicsLayerClient : public GraphicsLayerClient { +public: + virtual void notifyAnimationStarted(const GraphicsLayer*, double time) OVERRIDE { } + virtual void notifySyncRequired(const GraphicsLayer*) OVERRIDE { } + virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const IntRect& inClip) OVERRIDE { } + virtual bool showDebugBorders(const GraphicsLayer*) const OVERRIDE { return false; } + virtual bool showRepaintCounter(const GraphicsLayer*) const OVERRIDE { return false; } +}; + +TEST(LinkHighlightTest, verifyLinkHighlightLayer) +{ + Path highlightPath; + highlightPath.addRect(FloatRect(5, 6, 12, 8)); + IntRect pathBoundingRect = enclosingIntRect(highlightPath.boundingRect()); + + RefPtr<LinkHighlight> highlight = LinkHighlight::create(0, highlightPath, AnimationIdVendor::LinkHighlightAnimationId, AnimationIdVendor::getNextGroupId()); + ASSERT_TRUE(highlight.get()); + ContentLayerChromium* contentLayer = highlight->contentLayer(); + ASSERT_TRUE(contentLayer); + + EXPECT_EQ(pathBoundingRect.size(), contentLayer->bounds()); + EXPECT_TRUE(contentLayer->transform().isIdentityOrTranslation()); + EXPECT_TRUE(contentLayer->transform().isIntegerTranslation()); + + TransformationMatrix::DecomposedType decomposition; + EXPECT_TRUE(contentLayer->transform().decompose(decomposition)); + + FloatPoint expectedTranslation(pathBoundingRect.x() + pathBoundingRect.width() / 2, pathBoundingRect.y() + pathBoundingRect.height() / 2); + EXPECT_EQ(FloatPoint(decomposition.translateX, decomposition.translateY), expectedTranslation); +} + +TEST(LinkHighlightTest, verifyGraphicsLayerChromiumEmbedding) +{ + MockGraphicsLayerClient client; + OwnPtr<GraphicsLayerChromium> graphicsLayer = static_pointer_cast<GraphicsLayerChromium>(GraphicsLayer::create(&client)); + ASSERT_TRUE(graphicsLayer.get()); + + Path highlightPath; + highlightPath.addRect(FloatRect(5, 5, 10, 8)); + + // Neither of the following operations should crash. + graphicsLayer->addLinkHighlight(highlightPath); + graphicsLayer->didFinishLinkHighlight(); +} + +} // namespace diff --git a/Source/WebKit/chromium/tests/ListenerLeakTest.cpp b/Source/WebKit/chromium/tests/ListenerLeakTest.cpp new file mode 100644 index 000000000..5e321c70d --- /dev/null +++ b/Source/WebKit/chromium/tests/ListenerLeakTest.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2012 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#include "FrameTestHelpers.h" +#include "WebView.h" +#include <gtest/gtest.h> +#include <v8/include/v8-profiler.h> +#include <v8/include/v8.h> +#include <webkit/support/webkit_support.h> + +using namespace WebKit; + +namespace { + +const v8::HeapGraphNode* GetProperty(const v8::HeapGraphNode* node, v8::HeapGraphEdge::Type type, const char* name) +{ + for (int i = 0, count = node->GetChildrenCount(); i < count; ++i) { + const v8::HeapGraphEdge* prop = node->GetChild(i); + if (prop->GetType() == type) { + v8::String::AsciiValue propName(prop->GetName()); + if (!strcmp(name, *propName)) + return prop->GetToNode(); + } + } + return 0; +} + +int GetNumObjects(const char* constructor) +{ + v8::HandleScope scope; + const v8::HeapSnapshot* snapshot = v8::HeapProfiler::TakeSnapshot(v8::String::New(""), v8::HeapSnapshot::kFull); + if (!snapshot) + return -1; + int count = 0; + for (int i = 0; i < snapshot->GetNodesCount(); ++i) { + const v8::HeapGraphNode* node = snapshot->GetNode(i); + if (node->GetType() != v8::HeapGraphNode::kObject) + continue; + v8::String::AsciiValue nodeName(node->GetName()); + if (!strcmp(constructor, *nodeName)) { + const v8::HeapGraphNode* constructorProp = GetProperty(node, v8::HeapGraphEdge::kProperty, "constructor"); + // Skip an Object instance named after the constructor. + if (constructorProp) { + v8::String::AsciiValue constructorName(constructorProp->GetName()); + if (!strcmp(constructor, *constructorName)) + continue; + } + ++count; + } + } + return count; +} + + +class ListenerLeakTest : public testing::Test { +public: + ListenerLeakTest() : m_webView(0) { } + + void RunTest(const std::string& filename) + { + std::string baseURL("http://www.example.com/"); + std::string fileName(filename); + bool executeScript = true; + FrameTestHelpers::registerMockedURLLoad(baseURL, fileName); + m_webView = FrameTestHelpers::createWebViewAndLoad(baseURL + fileName, executeScript); + } + + virtual void TearDown() OVERRIDE + { + if (m_webView) + m_webView->close(); + webkit_support::UnregisterAllMockedURLs(); + } + +protected: + WebView* m_webView; +}; + + +// This test tries to create a reference cycle between node and its listener. +// See http://crbug/17400. +TEST_F(ListenerLeakTest, ReferenceCycle) +{ + RunTest("listener/listener_leak1.html"); + ASSERT_EQ(0, GetNumObjects("EventListenerLeakTestObject1")); +} + +// This test sets node onclick many times to expose a possible memory +// leak where all listeners get referenced by the node. +TEST_F(ListenerLeakTest, HiddenReferences) +{ + RunTest("listener/listener_leak2.html"); + ASSERT_EQ(1, GetNumObjects("EventListenerLeakTestObject2")); +} + +} // namespace diff --git a/Source/WebKit/chromium/tests/MockCCQuadCuller.h b/Source/WebKit/chromium/tests/MockCCQuadCuller.h index d9cd31326..385507e2c 100644 --- a/Source/WebKit/chromium/tests/MockCCQuadCuller.h +++ b/Source/WebKit/chromium/tests/MockCCQuadCuller.h @@ -35,12 +35,12 @@ namespace WebCore { class MockCCQuadCuller : public WebCore::CCQuadCuller { public: MockCCQuadCuller() - : CCQuadCuller(m_quadListStorage, 0, 0) + : CCQuadCuller(m_quadListStorage, 0, 0, false) , m_activeQuadList(m_quadListStorage) { } explicit MockCCQuadCuller(CCQuadList& externalQuadList) - : CCQuadCuller(externalQuadList, 0, 0) + : CCQuadCuller(externalQuadList, 0, 0, false) , m_activeQuadList(externalQuadList) { } diff --git a/Source/WebKit/chromium/tests/RegionTest.cpp b/Source/WebKit/chromium/tests/RegionTest.cpp index d202ab40c..105d1c3ed 100644 --- a/Source/WebKit/chromium/tests/RegionTest.cpp +++ b/Source/WebKit/chromium/tests/RegionTest.cpp @@ -124,4 +124,271 @@ TEST(RegionTest, emptySpan) EXPECT_FALSE(rects[i].isEmpty()); } +#define TEST_NO_INTERSECT(a, b) \ +{ \ + Region ar = a; \ + Region br = b; \ + EXPECT_FALSE(ar.intersects(br)); \ + EXPECT_FALSE(br.intersects(ar)); \ +} + +#define TEST_INTERSECT(a, b) \ +{ \ + Region ar = a; \ + Region br = b; \ + EXPECT_TRUE(ar.intersects(br)); \ + EXPECT_TRUE(br.intersects(ar)); \ +} + +TEST(RegionTest, intersectsRegion) +{ + Region r; + + TEST_NO_INTERSECT(IntRect(), IntRect()); + TEST_NO_INTERSECT(IntRect(), IntRect(0, 0, 1, 1)); + TEST_NO_INTERSECT(IntRect(), IntRect(1, 1, 1, 1)); + + r.unite(IntRect(0, 0, 1, 1)); + TEST_NO_INTERSECT(r, IntRect()); + TEST_INTERSECT(r, IntRect(0, 0, 1, 1)); + TEST_INTERSECT(r, IntRect(0, 0, 2, 2)); + TEST_INTERSECT(r, IntRect(-1, 0, 2, 2)); + TEST_INTERSECT(r, IntRect(-1, -1, 2, 2)); + TEST_INTERSECT(r, IntRect(0, -1, 2, 2)); + TEST_INTERSECT(r, IntRect(-1, -1, 3, 3)); + + r.unite(IntRect(0, 0, 3, 3)); + r.unite(IntRect(10, 0, 3, 3)); + r.unite(IntRect(0, 10, 13, 3)); + TEST_NO_INTERSECT(r, IntRect()); + TEST_INTERSECT(r, IntRect(1, 1, 1, 1)); + TEST_INTERSECT(r, IntRect(0, 0, 2, 2)); + TEST_INTERSECT(r, IntRect(1, 0, 2, 2)); + TEST_INTERSECT(r, IntRect(1, 1, 2, 2)); + TEST_INTERSECT(r, IntRect(0, 1, 2, 2)); + TEST_INTERSECT(r, IntRect(0, 0, 3, 3)); + TEST_INTERSECT(r, IntRect(-1, -1, 2, 2)); + TEST_INTERSECT(r, IntRect(2, -1, 2, 2)); + TEST_INTERSECT(r, IntRect(2, 2, 2, 2)); + TEST_INTERSECT(r, IntRect(-1, 2, 2, 2)); + + TEST_INTERSECT(r, IntRect(11, 1, 1, 1)); + TEST_INTERSECT(r, IntRect(10, 0, 2, 2)); + TEST_INTERSECT(r, IntRect(11, 0, 2, 2)); + TEST_INTERSECT(r, IntRect(11, 1, 2, 2)); + TEST_INTERSECT(r, IntRect(10, 1, 2, 2)); + TEST_INTERSECT(r, IntRect(10, 0, 3, 3)); + TEST_INTERSECT(r, IntRect(9, -1, 2, 2)); + TEST_INTERSECT(r, IntRect(12, -1, 2, 2)); + TEST_INTERSECT(r, IntRect(12, 2, 2, 2)); + TEST_INTERSECT(r, IntRect(9, 2, 2, 2)); + + TEST_INTERSECT(r, IntRect(0, -1, 13, 5)); + TEST_INTERSECT(r, IntRect(1, -1, 11, 5)); + TEST_INTERSECT(r, IntRect(2, -1, 9, 5)); + TEST_INTERSECT(r, IntRect(2, -1, 8, 5)); + TEST_INTERSECT(r, IntRect(3, -1, 8, 5)); + TEST_NO_INTERSECT(r, IntRect(3, -1, 7, 5)); + + TEST_INTERSECT(r, IntRect(0, 1, 13, 1)); + TEST_INTERSECT(r, IntRect(1, 1, 11, 1)); + TEST_INTERSECT(r, IntRect(2, 1, 9, 1)); + TEST_INTERSECT(r, IntRect(2, 1, 8, 1)); + TEST_INTERSECT(r, IntRect(3, 1, 8, 1)); + TEST_NO_INTERSECT(r, IntRect(3, 1, 7, 1)); + + TEST_INTERSECT(r, IntRect(0, 0, 13, 13)); + TEST_INTERSECT(r, IntRect(0, 1, 13, 11)); + TEST_INTERSECT(r, IntRect(0, 2, 13, 9)); + TEST_INTERSECT(r, IntRect(0, 2, 13, 8)); + TEST_INTERSECT(r, IntRect(0, 3, 13, 8)); + TEST_NO_INTERSECT(r, IntRect(0, 3, 13, 7)); +} + +TEST(RegionTest, ReadPastFullSpanVectorInIntersectsTest) +{ + Region r; + + // This region has enough spans to fill its allocated Vector exactly. + r.unite(IntRect(400, 300, 1, 800)); + r.unite(IntRect(785, 585, 1, 1)); + r.unite(IntRect(787, 585, 1, 1)); + r.unite(IntRect(0, 587, 16, 162)); + r.unite(IntRect(26, 590, 300, 150)); + r.unite(IntRect(196, 750, 1, 1)); + r.unite(IntRect(0, 766, 1, 1)); + r.unite(IntRect(0, 782, 1, 1)); + r.unite(IntRect(745, 798, 1, 1)); + r.unite(IntRect(795, 882, 10, 585)); + r.unite(IntRect(100, 1499, 586, 1)); + r.unite(IntRect(100, 1500, 585, 784)); + // This query rect goes past the bottom of the Region, causing the + // test to reach the last span and try go past it. It should not read + // memory off the end of the span Vector. + TEST_NO_INTERSECT(r, IntRect(0, 2184, 1, 150)); +} + +#define TEST_NO_CONTAINS(a, b) \ +{ \ + Region ar = a; \ + Region br = b; \ + EXPECT_FALSE(ar.contains(br)); \ +} + +#define TEST_CONTAINS(a, b) \ +{ \ + Region ar = a; \ + Region br = b; \ + EXPECT_TRUE(ar.contains(br)); \ +} + +TEST(RegionTest, containsRegion) +{ + TEST_CONTAINS(IntRect(), IntRect()); + TEST_NO_CONTAINS(IntRect(), IntRect(0, 0, 1, 1)); + TEST_NO_CONTAINS(IntRect(), IntRect(1, 1, 1, 1)); + + TEST_NO_CONTAINS(IntRect(10, 10, 1, 1), IntRect(11, 10, 1, 1)); + TEST_NO_CONTAINS(IntRect(10, 10, 1, 1), IntRect(10, 11, 1, 1)); + TEST_NO_CONTAINS(IntRect(10, 10, 1, 1), IntRect(9, 10, 1, 1)); + TEST_NO_CONTAINS(IntRect(10, 10, 1, 1), IntRect(10, 9, 1, 1)); + TEST_NO_CONTAINS(IntRect(10, 10, 1, 1), IntRect(9, 9, 2, 2)); + TEST_NO_CONTAINS(IntRect(10, 10, 1, 1), IntRect(10, 9, 2, 2)); + TEST_NO_CONTAINS(IntRect(10, 10, 1, 1), IntRect(9, 10, 2, 2)); + TEST_NO_CONTAINS(IntRect(10, 10, 1, 1), IntRect(10, 10, 2, 2)); + TEST_NO_CONTAINS(IntRect(10, 10, 1, 1), IntRect(9, 9, 3, 3)); + + Region hLines; + for (int i = 10; i < 20; i += 2) + hLines.unite(IntRect(i, 10, 1, 10)); + + TEST_CONTAINS(IntRect(10, 10, 9, 10), hLines); + TEST_NO_CONTAINS(IntRect(10, 10, 9, 9), hLines); + TEST_NO_CONTAINS(IntRect(10, 11, 9, 9), hLines); + TEST_NO_CONTAINS(IntRect(10, 10, 8, 10), hLines); + TEST_NO_CONTAINS(IntRect(11, 10, 8, 10), hLines); + + Region vLines; + for (int i = 10; i < 20; i += 2) + vLines.unite(IntRect(10, i, 10, 1)); + + TEST_CONTAINS(IntRect(10, 10, 10, 9), vLines); + TEST_NO_CONTAINS(IntRect(10, 10, 9, 9), vLines); + TEST_NO_CONTAINS(IntRect(11, 10, 9, 9), vLines); + TEST_NO_CONTAINS(IntRect(10, 10, 10, 8), vLines); + TEST_NO_CONTAINS(IntRect(10, 11, 10, 8), vLines); + + Region grid; + for (int i = 10; i < 20; i += 2) + for (int j = 10; j < 20; j += 2) + grid.unite(IntRect(i, j, 1, 1)); + + TEST_CONTAINS(IntRect(10, 10, 9, 9), grid); + TEST_NO_CONTAINS(IntRect(10, 10, 9, 8), grid); + TEST_NO_CONTAINS(IntRect(10, 11, 9, 8), grid); + TEST_NO_CONTAINS(IntRect(10, 10, 8, 9), grid); + TEST_NO_CONTAINS(IntRect(11, 10, 8, 9), grid); + + TEST_CONTAINS(hLines, hLines); + TEST_CONTAINS(vLines, vLines); + TEST_NO_CONTAINS(vLines, hLines); + TEST_NO_CONTAINS(hLines, vLines); + TEST_CONTAINS(grid, grid); + TEST_CONTAINS(hLines, grid); + TEST_CONTAINS(vLines, grid); + TEST_NO_CONTAINS(grid, hLines); + TEST_NO_CONTAINS(grid, vLines); + + for (int i = 10; i < 20; i += 2) + TEST_CONTAINS(hLines, IntRect(i, 10, 1, 10)); + + for (int i = 10; i < 20; i += 2) + TEST_CONTAINS(vLines, IntRect(10, i, 10, 1)); + + for (int i = 10; i < 20; i += 2) + for (int j = 10; j < 20; j += 2) + TEST_CONTAINS(grid, IntRect(i, j, 1, 1)); + + Region container; + container.unite(IntRect(0, 0, 40, 20)); + container.unite(IntRect(0, 20, 41, 20)); + TEST_CONTAINS(container, IntRect(5, 5, 30, 30)); + + container = Region(); + container.unite(IntRect(0, 0, 10, 10)); + container.unite(IntRect(0, 30, 10, 10)); + container.unite(IntRect(30, 30, 10, 10)); + container.unite(IntRect(30, 0, 10, 10)); + TEST_NO_CONTAINS(container, IntRect(5, 5, 30, 30)); + + container = Region(); + container.unite(IntRect(0, 0, 10, 10)); + container.unite(IntRect(0, 30, 10, 10)); + container.unite(IntRect(30, 0, 10, 40)); + TEST_NO_CONTAINS(container, IntRect(5, 5, 30, 30)); + + container = Region(); + container.unite(IntRect(30, 0, 10, 10)); + container.unite(IntRect(30, 30, 10, 10)); + container.unite(IntRect(0, 0, 10, 40)); + TEST_NO_CONTAINS(container, IntRect(5, 5, 30, 30)); + + container = Region(); + container.unite(IntRect(0, 0, 10, 40)); + container.unite(IntRect(30, 0, 10, 40)); + TEST_NO_CONTAINS(container, IntRect(5, 5, 30, 30)); + + container = Region(); + container.unite(IntRect(0, 0, 40, 40)); + TEST_NO_CONTAINS(container, IntRect(10, -1, 20, 10)); + + container = Region(); + container.unite(IntRect(0, 0, 40, 40)); + TEST_NO_CONTAINS(container, IntRect(10, 31, 20, 10)); + + container = Region(); + container.unite(IntRect(0, 0, 40, 20)); + container.unite(IntRect(0, 20, 41, 20)); + TEST_NO_CONTAINS(container, IntRect(-1, 10, 10, 20)); + + container = Region(); + container.unite(IntRect(0, 0, 40, 20)); + container.unite(IntRect(0, 20, 41, 20)); + TEST_NO_CONTAINS(container, IntRect(31, 10, 10, 20)); + + container = Region(); + container.unite(IntRect(0, 0, 40, 40)); + container.subtract(IntRect(0, 20, 60, 0)); + TEST_NO_CONTAINS(container, IntRect(31, 10, 10, 20)); +} + +TEST(RegionTest, unite) +{ + Region r; + Region r2; + + // A rect uniting a contained rect does not change the region. + r2 = r = IntRect(0, 0, 50, 50); + r2.unite(IntRect(20, 20, 10, 10)); + EXPECT_EQ(r, r2); + + // A rect uniting a containing rect gives back the containing rect. + r = IntRect(0, 0, 50, 50); + r.unite(IntRect(0, 0, 100, 100)); + EXPECT_EQ(Region(IntRect(0, 0, 100, 100)), r); + + // A complex region uniting a contained rect does not change the region. + r = IntRect(0, 0, 50, 50); + r.unite(IntRect(100, 0, 50, 50)); + r2 = r; + r2.unite(IntRect(20, 20, 10, 10)); + EXPECT_EQ(r, r2); + + // A complex region uniting a containing rect gives back the containing rect. + r = IntRect(0, 0, 50, 50); + r.unite(IntRect(100, 0, 50, 50)); + r. unite(IntRect(0, 0, 500, 500)); + EXPECT_EQ(Region(IntRect(0, 0, 500, 500)), r); +} + } // namespace diff --git a/Source/WebKit/chromium/tests/TextureLayerChromiumTest.cpp b/Source/WebKit/chromium/tests/TextureLayerChromiumTest.cpp new file mode 100644 index 000000000..b60017fd9 --- /dev/null +++ b/Source/WebKit/chromium/tests/TextureLayerChromiumTest.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2012 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#include "TextureLayerChromium.h" + +#include "FakeCCLayerTreeHostClient.h" +#include "WebCompositor.h" +#include "cc/CCLayerTreeHost.h" +#include <gmock/gmock.h> +#include <gtest/gtest.h> + +using namespace WebCore; +using ::testing::Mock; +using ::testing::_; +using ::testing::AtLeast; +using ::testing::AnyNumber; + +namespace { + +class MockCCLayerTreeHost : public CCLayerTreeHost { +public: + MockCCLayerTreeHost() + : CCLayerTreeHost(&m_fakeClient, CCSettings()) + { + initialize(); + } + + MOCK_METHOD0(acquireLayerTextures, void()); + +private: + FakeCCLayerTreeHostClient m_fakeClient; +}; + + +class TextureLayerChromiumTest : public testing::Test { +protected: + virtual void SetUp() + { + // Initialize without threading support. + WebKit::WebCompositor::initialize(0); + m_layerTreeHost = adoptPtr(new MockCCLayerTreeHost); + } + + virtual void TearDown() + { + Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); + EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); + + m_layerTreeHost->setRootLayer(0); + m_layerTreeHost.clear(); + WebKit::WebCompositor::shutdown(); + } + + OwnPtr<MockCCLayerTreeHost> m_layerTreeHost; +}; + +TEST_F(TextureLayerChromiumTest, syncImplWhenChangingTextureId) +{ + RefPtr<TextureLayerChromium> testLayer = TextureLayerChromium::create(0); + ASSERT_TRUE(testLayer); + + EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); + m_layerTreeHost->setRootLayer(testLayer); + Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); + EXPECT_EQ(testLayer->layerTreeHost(), m_layerTreeHost.get()); + + EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); + testLayer->setTextureId(1); + Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); + + EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1)); + testLayer->setTextureId(2); + Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); + + EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1)); + testLayer->setTextureId(0); + Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); +} + +TEST_F(TextureLayerChromiumTest, syncImplWhenRemovingFromTree) +{ + RefPtr<LayerChromium> rootLayer = LayerChromium::create(); + ASSERT_TRUE(rootLayer); + RefPtr<LayerChromium> childLayer = LayerChromium::create(); + ASSERT_TRUE(childLayer); + rootLayer->addChild(childLayer); + RefPtr<TextureLayerChromium> testLayer = TextureLayerChromium::create(0); + ASSERT_TRUE(testLayer); + testLayer->setTextureId(0); + childLayer->addChild(testLayer); + + EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); + m_layerTreeHost->setRootLayer(rootLayer); + Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); + + EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); + testLayer->removeFromParent(); + Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); + + EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); + childLayer->addChild(testLayer); + Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); + + EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); + testLayer->setTextureId(1); + Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); + + EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1)); + testLayer->removeFromParent(); + Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); +} + +} // anonymous namespace diff --git a/Source/WebKit/chromium/tests/ThrottledTextureUploaderTest.cpp b/Source/WebKit/chromium/tests/ThrottledTextureUploaderTest.cpp new file mode 100644 index 000000000..4b0dfd059 --- /dev/null +++ b/Source/WebKit/chromium/tests/ThrottledTextureUploaderTest.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2012 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#include "ThrottledTextureUploader.h" + +#include "FakeWebGraphicsContext3D.h" +#include "GraphicsContext3DPrivate.h" + +#include <gmock/gmock.h> +#include <gtest/gtest.h> +#include <wtf/RefPtr.h> + +using namespace WebCore; +using namespace WebKit; + +namespace { + +class FakeWebGraphicsContext3DWithQueryTesting : public FakeWebGraphicsContext3D { +public: + FakeWebGraphicsContext3DWithQueryTesting() : m_resultAvailable(0) + { + } + + virtual void getQueryObjectuivEXT(WebGLId, GC3Denum type, GC3Duint* value) + { + switch (type) { + case Extensions3DChromium::QUERY_RESULT_AVAILABLE_EXT: + *value = m_resultAvailable; + break; + default: + *value = 0; + break; + } + } + + void setResultAvailable(unsigned resultAvailable) { m_resultAvailable = resultAvailable; } + +private: + unsigned m_resultAvailable; +}; + +TEST(ThrottledTextureUploaderTest, IsBusy) +{ + GraphicsContext3D::Attributes attrs; + RefPtr<GraphicsContext3D> context = GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new FakeWebGraphicsContext3DWithQueryTesting()), GraphicsContext3D::RenderDirectlyToHostWindow); + FakeWebGraphicsContext3DWithQueryTesting& fakeContext = *static_cast<FakeWebGraphicsContext3DWithQueryTesting*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(context.get())); + OwnPtr<ThrottledTextureUploader> uploader = ThrottledTextureUploader::create(context, 2); + + fakeContext.setResultAvailable(0); + EXPECT_FALSE(uploader->isBusy()); + uploader->beginUploads(); + uploader->endUploads(); + EXPECT_FALSE(uploader->isBusy()); + uploader->beginUploads(); + uploader->endUploads(); + EXPECT_TRUE(uploader->isBusy()); + + fakeContext.setResultAvailable(1); + EXPECT_FALSE(uploader->isBusy()); + uploader->beginUploads(); + uploader->endUploads(); + EXPECT_FALSE(uploader->isBusy()); + uploader->beginUploads(); + uploader->endUploads(); + EXPECT_FALSE(uploader->isBusy()); + uploader->beginUploads(); + uploader->endUploads(); +} + +} // namespace diff --git a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp b/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp index 5b7cb0df7..c9125a852 100644 --- a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp +++ b/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp @@ -957,7 +957,7 @@ TEST(TiledLayerChromiumTest, partialUpdates) } ccLayerTreeHost->commitComplete(); - // Partail update of 6 checkerboard tiles. + // Partial update of 6 checkerboard tiles. layer->invalidateRect(IntRect(50, 50, 200, 100)); { DebugScopedSetImplThread implThread; @@ -975,6 +975,20 @@ TEST(TiledLayerChromiumTest, partialUpdates) } ccLayerTreeHost->commitComplete(); + // Partial update of 4 tiles. + layer->invalidateRect(IntRect(50, 50, 100, 100)); + { + DebugScopedSetImplThread implThread; + OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(0))); + ccLayerTreeHost->updateLayers(updater); + updater.update(0, &allocator, &copier, &uploader, 4); + EXPECT_EQ(4, layer->fakeLayerTextureUpdater()->updateCount()); + EXPECT_FALSE(updater.hasMoreUpdates()); + layer->fakeLayerTextureUpdater()->clearUpdateCount(); + layer->pushPropertiesTo(layerImpl.get()); + } + ccLayerTreeHost->commitComplete(); + ccLayerTreeHost->setRootLayer(0); ccLayerTreeHost.clear(); WebKit::WebCompositor::shutdown(); diff --git a/Source/WebKit/chromium/tests/TilingDataTest.cpp b/Source/WebKit/chromium/tests/TilingDataTest.cpp index 47c0361ea..060bc7767 100755 --- a/Source/WebKit/chromium/tests/TilingDataTest.cpp +++ b/Source/WebKit/chromium/tests/TilingDataTest.cpp @@ -30,6 +30,7 @@ #include "config.h" +#include "IntSize.h" #include "TilingData.h" #include <wtf/Assertions.h> @@ -41,8 +42,8 @@ namespace { class TestTiling : public TilingData { public: - TestTiling(int maxTextureSize, int totalSizeX, int totalSizeY, bool hasBorderTexels) - : TilingData(maxTextureSize, totalSizeX, totalSizeY, hasBorderTexels) + TestTiling(IntSize maxTextureSize, IntSize totalSize, bool hasBorderTexels) + : TilingData(maxTextureSize, totalSize, hasBorderTexels) { } @@ -62,402 +63,413 @@ public: TEST(TilingDataTest, numTiles_NoTiling) { - EXPECT_EQ(1, TestTiling(16, 16, 16, false).numTiles()); - EXPECT_EQ(1, TestTiling(16, 15, 15, true).numTiles()); - EXPECT_EQ(1, TestTiling(16, 16, 16, true).numTiles()); - EXPECT_EQ(1, TestTiling(16, 1, 16, false).numTiles()); - EXPECT_EQ(1, TestTiling(15, 15, 15, true).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(16, 16), IntSize(16, 16), false).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(16, 16), IntSize(15, 15), true).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(16, 16), IntSize(16, 16), true).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(16, 16), IntSize(1, 16), false).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(15, 15), IntSize(15, 15), true).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(32, 16), IntSize(32, 16), false).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(32, 16), IntSize(32, 16), true).numTiles()); } TEST(TilingDataTest, numTiles_TilingNoBorders) { - EXPECT_EQ(0, TestTiling(0, 0, 0, false).numTiles()); - EXPECT_EQ(0, TestTiling(0, 4, 0, false).numTiles()); - EXPECT_EQ(0, TestTiling(0, 0, 4, false).numTiles()); - EXPECT_EQ(0, TestTiling(4, 4, 0, false).numTiles()); - EXPECT_EQ(0, TestTiling(4, 0, 4, false).numTiles()); - EXPECT_EQ(0, TestTiling(-8, 1, 1, false).numTiles()); - EXPECT_EQ(0, TestTiling(-1, 1, 1, false).numTiles()); - EXPECT_EQ(0, TestTiling(0, 1, 1, false).numTiles()); - - EXPECT_EQ(1, TestTiling(1, 1, 1, false).numTiles()); - EXPECT_EQ(2, TestTiling(1, 1, 2, false).numTiles()); - EXPECT_EQ(2, TestTiling(1, 2, 1, false).numTiles()); - EXPECT_EQ(1, TestTiling(2, 1, 1, false).numTiles()); - EXPECT_EQ(1, TestTiling(2, 1, 2, false).numTiles()); - EXPECT_EQ(1, TestTiling(2, 2, 1, false).numTiles()); - EXPECT_EQ(1, TestTiling(2, 2, 2, false).numTiles()); - EXPECT_EQ(1, TestTiling(3, 3, 3, false).numTiles()); - - EXPECT_EQ(1, TestTiling(4, 1, 4, false).numTiles()); - EXPECT_EQ(1, TestTiling(4, 2, 4, false).numTiles()); - EXPECT_EQ(1, TestTiling(4, 3, 4, false).numTiles()); - EXPECT_EQ(1, TestTiling(4, 4, 4, false).numTiles()); - EXPECT_EQ(2, TestTiling(4, 5, 4, false).numTiles()); - EXPECT_EQ(2, TestTiling(4, 6, 4, false).numTiles()); - EXPECT_EQ(2, TestTiling(4, 7, 4, false).numTiles()); - EXPECT_EQ(2, TestTiling(4, 8, 4, false).numTiles()); - EXPECT_EQ(3, TestTiling(4, 9, 4, false).numTiles()); - EXPECT_EQ(3, TestTiling(4, 10, 4, false).numTiles()); - EXPECT_EQ(3, TestTiling(4, 11, 4, false).numTiles()); - - EXPECT_EQ(1, TestTiling(5, 1, 5, false).numTiles()); - EXPECT_EQ(1, TestTiling(5, 2, 5, false).numTiles()); - EXPECT_EQ(1, TestTiling(5, 3, 5, false).numTiles()); - EXPECT_EQ(1, TestTiling(5, 4, 5, false).numTiles()); - EXPECT_EQ(1, TestTiling(5, 5, 5, false).numTiles()); - EXPECT_EQ(2, TestTiling(5, 6, 5, false).numTiles()); - EXPECT_EQ(2, TestTiling(5, 7, 5, false).numTiles()); - EXPECT_EQ(2, TestTiling(5, 8, 5, false).numTiles()); - EXPECT_EQ(2, TestTiling(5, 9, 5, false).numTiles()); - EXPECT_EQ(2, TestTiling(5, 10, 5, false).numTiles()); - EXPECT_EQ(3, TestTiling(5, 11, 5, false).numTiles()); - - EXPECT_EQ(1, TestTiling(16, 16, 16, false).numTiles()); - EXPECT_EQ(1, TestTiling(17, 16, 16, false).numTiles()); - EXPECT_EQ(4, TestTiling(15, 16, 16, false).numTiles()); - EXPECT_EQ(4, TestTiling(8, 16, 16, false).numTiles()); - EXPECT_EQ(6, TestTiling(8, 17, 16, false).numTiles()); + EXPECT_EQ(0, TestTiling(IntSize(0, 0), IntSize(0, 0), false).numTiles()); + EXPECT_EQ(0, TestTiling(IntSize(0, 0), IntSize(4, 0), false).numTiles()); + EXPECT_EQ(0, TestTiling(IntSize(0, 0), IntSize(0, 4), false).numTiles()); + EXPECT_EQ(0, TestTiling(IntSize(4, 4), IntSize(4, 0), false).numTiles()); + EXPECT_EQ(0, TestTiling(IntSize(4, 4), IntSize(0, 4), false).numTiles()); + EXPECT_EQ(0, TestTiling(IntSize(-8, -8), IntSize(1, 1), false).numTiles()); + EXPECT_EQ(0, TestTiling(IntSize(-1, -1), IntSize(1, 1), false).numTiles()); + EXPECT_EQ(0, TestTiling(IntSize(0, 0), IntSize(1, 1), false).numTiles()); + + EXPECT_EQ(1, TestTiling(IntSize(1, 1), IntSize(1, 1), false).numTiles()); + EXPECT_EQ(2, TestTiling(IntSize(1, 1), IntSize(1, 2), false).numTiles()); + EXPECT_EQ(2, TestTiling(IntSize(1, 1), IntSize(2, 1), false).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(2, 2), IntSize(1, 1), false).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(2, 2), IntSize(1, 2), false).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(2, 2), IntSize(2, 1), false).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(2, 2), IntSize(2, 2), false).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(3, 3), false).numTiles()); + + EXPECT_EQ(1, TestTiling(IntSize(4, 4), IntSize(1, 4), false).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(4, 4), IntSize(2, 4), false).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(4, 4), IntSize(3, 4), false).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(4, 4), IntSize(4, 4), false).numTiles()); + EXPECT_EQ(2, TestTiling(IntSize(4, 4), IntSize(5, 4), false).numTiles()); + EXPECT_EQ(2, TestTiling(IntSize(4, 4), IntSize(6, 4), false).numTiles()); + EXPECT_EQ(2, TestTiling(IntSize(4, 4), IntSize(7, 4), false).numTiles()); + EXPECT_EQ(2, TestTiling(IntSize(4, 4), IntSize(8, 4), false).numTiles()); + EXPECT_EQ(3, TestTiling(IntSize(4, 4), IntSize(9, 4), false).numTiles()); + EXPECT_EQ(3, TestTiling(IntSize(4, 4), IntSize(10, 4), false).numTiles()); + EXPECT_EQ(3, TestTiling(IntSize(4, 4), IntSize(11, 4), false).numTiles()); + + EXPECT_EQ(1, TestTiling(IntSize(5, 5), IntSize(1, 5), false).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(5, 5), IntSize(2, 5), false).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(5, 5), IntSize(3, 5), false).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(5, 5), IntSize(4, 5), false).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(5, 5), IntSize(5, 5), false).numTiles()); + EXPECT_EQ(2, TestTiling(IntSize(5, 5), IntSize(6, 5), false).numTiles()); + EXPECT_EQ(2, TestTiling(IntSize(5, 5), IntSize(7, 5), false).numTiles()); + EXPECT_EQ(2, TestTiling(IntSize(5, 5), IntSize(8, 5), false).numTiles()); + EXPECT_EQ(2, TestTiling(IntSize(5, 5), IntSize(9, 5), false).numTiles()); + EXPECT_EQ(2, TestTiling(IntSize(5, 5), IntSize(10, 5), false).numTiles()); + EXPECT_EQ(3, TestTiling(IntSize(5, 5), IntSize(11, 5), false).numTiles()); + + EXPECT_EQ(1, TestTiling(IntSize(16, 16), IntSize(16, 16), false).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(17, 17), IntSize(16, 16), false).numTiles()); + EXPECT_EQ(4, TestTiling(IntSize(15, 15), IntSize(16, 16), false).numTiles()); + EXPECT_EQ(4, TestTiling(IntSize(8, 8), IntSize(16, 16), false).numTiles()); + EXPECT_EQ(6, TestTiling(IntSize(8, 8), IntSize(17, 16), false).numTiles()); + + EXPECT_EQ(8, TestTiling(IntSize(5, 8), IntSize(17, 16), false).numTiles()); } TEST(TilingDataTest, numTiles_TilingWithBorders) { - EXPECT_EQ(0, TestTiling(0, 0, 0, true).numTiles()); - EXPECT_EQ(0, TestTiling(0, 4, 0, true).numTiles()); - EXPECT_EQ(0, TestTiling(0, 0, 4, true).numTiles()); - EXPECT_EQ(0, TestTiling(4, 4, 0, true).numTiles()); - EXPECT_EQ(0, TestTiling(4, 0, 4, true).numTiles()); - EXPECT_EQ(0, TestTiling(-8, 1, 1, true).numTiles()); - EXPECT_EQ(0, TestTiling(-1, 1, 1, true).numTiles()); - EXPECT_EQ(0, TestTiling(0, 1, 1, true).numTiles()); - - EXPECT_EQ(1, TestTiling(1, 1, 1, true).numTiles()); - EXPECT_EQ(0, TestTiling(1, 1, 2, true).numTiles()); - EXPECT_EQ(0, TestTiling(1, 2, 1, true).numTiles()); - EXPECT_EQ(1, TestTiling(2, 1, 1, true).numTiles()); - EXPECT_EQ(1, TestTiling(2, 1, 2, true).numTiles()); - EXPECT_EQ(1, TestTiling(2, 2, 1, true).numTiles()); - EXPECT_EQ(1, TestTiling(2, 2, 2, true).numTiles()); - - EXPECT_EQ(1, TestTiling(3, 1, 3, true).numTiles()); - EXPECT_EQ(1, TestTiling(3, 2, 3, true).numTiles()); - EXPECT_EQ(1, TestTiling(3, 3, 3, true).numTiles()); - EXPECT_EQ(2, TestTiling(3, 4, 3, true).numTiles()); - EXPECT_EQ(3, TestTiling(3, 5, 3, true).numTiles()); - EXPECT_EQ(4, TestTiling(3, 6, 3, true).numTiles()); - EXPECT_EQ(5, TestTiling(3, 7, 3, true).numTiles()); - - EXPECT_EQ(1, TestTiling(4, 1, 4, true).numTiles()); - EXPECT_EQ(1, TestTiling(4, 2, 4, true).numTiles()); - EXPECT_EQ(1, TestTiling(4, 3, 4, true).numTiles()); - EXPECT_EQ(1, TestTiling(4, 4, 4, true).numTiles()); - EXPECT_EQ(2, TestTiling(4, 5, 4, true).numTiles()); - EXPECT_EQ(2, TestTiling(4, 6, 4, true).numTiles()); - EXPECT_EQ(3, TestTiling(4, 7, 4, true).numTiles()); - EXPECT_EQ(3, TestTiling(4, 8, 4, true).numTiles()); - EXPECT_EQ(4, TestTiling(4, 9, 4, true).numTiles()); - EXPECT_EQ(4, TestTiling(4, 10, 4, true).numTiles()); - EXPECT_EQ(5, TestTiling(4, 11, 4, true).numTiles()); - - EXPECT_EQ(1, TestTiling(5, 1, 5, true).numTiles()); - EXPECT_EQ(1, TestTiling(5, 2, 5, true).numTiles()); - EXPECT_EQ(1, TestTiling(5, 3, 5, true).numTiles()); - EXPECT_EQ(1, TestTiling(5, 4, 5, true).numTiles()); - EXPECT_EQ(1, TestTiling(5, 5, 5, true).numTiles()); - EXPECT_EQ(2, TestTiling(5, 6, 5, true).numTiles()); - EXPECT_EQ(2, TestTiling(5, 7, 5, true).numTiles()); - EXPECT_EQ(2, TestTiling(5, 8, 5, true).numTiles()); - EXPECT_EQ(3, TestTiling(5, 9, 5, true).numTiles()); - EXPECT_EQ(3, TestTiling(5, 10, 5, true).numTiles()); - EXPECT_EQ(3, TestTiling(5, 11, 5, true).numTiles()); + EXPECT_EQ(0, TestTiling(IntSize(0, 0), IntSize(0, 0), true).numTiles()); + EXPECT_EQ(0, TestTiling(IntSize(0, 0), IntSize(4, 0), true).numTiles()); + EXPECT_EQ(0, TestTiling(IntSize(0, 0), IntSize(0, 4), true).numTiles()); + EXPECT_EQ(0, TestTiling(IntSize(4, 4), IntSize(4, 0), true).numTiles()); + EXPECT_EQ(0, TestTiling(IntSize(4, 4), IntSize(0, 4), true).numTiles()); + EXPECT_EQ(0, TestTiling(IntSize(-8, -8), IntSize(1, 1), true).numTiles()); + EXPECT_EQ(0, TestTiling(IntSize(-1, -1), IntSize(1, 1), true).numTiles()); + EXPECT_EQ(0, TestTiling(IntSize(0, 0), IntSize(1, 1), true).numTiles()); + + EXPECT_EQ(1, TestTiling(IntSize(1, 1), IntSize(1, 1), true).numTiles()); + EXPECT_EQ(0, TestTiling(IntSize(1, 1), IntSize(1, 2), true).numTiles()); + EXPECT_EQ(0, TestTiling(IntSize(1, 1), IntSize(2, 1), true).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(2, 2), IntSize(1, 1), true).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(2, 2), IntSize(1, 2), true).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(2, 2), IntSize(2, 1), true).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(2, 2), IntSize(2, 2), true).numTiles()); + + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(1, 3), true).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(2, 3), true).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(3, 3), true).numTiles()); + EXPECT_EQ(2, TestTiling(IntSize(3, 3), IntSize(4, 3), true).numTiles()); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(5, 3), true).numTiles()); + EXPECT_EQ(4, TestTiling(IntSize(3, 3), IntSize(6, 3), true).numTiles()); + EXPECT_EQ(5, TestTiling(IntSize(3, 3), IntSize(7, 3), true).numTiles()); + + EXPECT_EQ(1, TestTiling(IntSize(4, 4), IntSize(1, 4), true).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(4, 4), IntSize(2, 4), true).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(4, 4), IntSize(3, 4), true).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(4, 4), IntSize(4, 4), true).numTiles()); + EXPECT_EQ(2, TestTiling(IntSize(4, 4), IntSize(5, 4), true).numTiles()); + EXPECT_EQ(2, TestTiling(IntSize(4, 4), IntSize(6, 4), true).numTiles()); + EXPECT_EQ(3, TestTiling(IntSize(4, 4), IntSize(7, 4), true).numTiles()); + EXPECT_EQ(3, TestTiling(IntSize(4, 4), IntSize(8, 4), true).numTiles()); + EXPECT_EQ(4, TestTiling(IntSize(4, 4), IntSize(9, 4), true).numTiles()); + EXPECT_EQ(4, TestTiling(IntSize(4, 4), IntSize(10, 4), true).numTiles()); + EXPECT_EQ(5, TestTiling(IntSize(4, 4), IntSize(11, 4), true).numTiles()); + + EXPECT_EQ(1, TestTiling(IntSize(5, 5), IntSize(1, 5), true).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(5, 5), IntSize(2, 5), true).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(5, 5), IntSize(3, 5), true).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(5, 5), IntSize(4, 5), true).numTiles()); + EXPECT_EQ(1, TestTiling(IntSize(5, 5), IntSize(5, 5), true).numTiles()); + EXPECT_EQ(2, TestTiling(IntSize(5, 5), IntSize(6, 5), true).numTiles()); + EXPECT_EQ(2, TestTiling(IntSize(5, 5), IntSize(7, 5), true).numTiles()); + EXPECT_EQ(2, TestTiling(IntSize(5, 5), IntSize(8, 5), true).numTiles()); + EXPECT_EQ(3, TestTiling(IntSize(5, 5), IntSize(9, 5), true).numTiles()); + EXPECT_EQ(3, TestTiling(IntSize(5, 5), IntSize(10, 5), true).numTiles()); + EXPECT_EQ(3, TestTiling(IntSize(5, 5), IntSize(11, 5), true).numTiles()); + + EXPECT_EQ(30, TestTiling(IntSize(8, 5), IntSize(16, 32), true).numTiles()); } TEST(TilingDataTest, tileXIndexFromSrcCoord) { - EXPECT_EQ(0, TestTiling(3, 10, 10, false).tileXIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(3, 10, 10, false).tileXIndexFromSrcCoord(1)); - EXPECT_EQ(0, TestTiling(3, 10, 10, false).tileXIndexFromSrcCoord(2)); - EXPECT_EQ(1, TestTiling(3, 10, 10, false).tileXIndexFromSrcCoord(3)); - EXPECT_EQ(1, TestTiling(3, 10, 10, false).tileXIndexFromSrcCoord(4)); - EXPECT_EQ(1, TestTiling(3, 10, 10, false).tileXIndexFromSrcCoord(5)); - EXPECT_EQ(2, TestTiling(3, 10, 10, false).tileXIndexFromSrcCoord(6)); - EXPECT_EQ(2, TestTiling(3, 10, 10, false).tileXIndexFromSrcCoord(7)); - EXPECT_EQ(2, TestTiling(3, 10, 10, false).tileXIndexFromSrcCoord(8)); - EXPECT_EQ(3, TestTiling(3, 10, 10, false).tileXIndexFromSrcCoord(9)); - EXPECT_EQ(3, TestTiling(3, 10, 10, false).tileXIndexFromSrcCoord(10)); - EXPECT_EQ(3, TestTiling(3, 10, 10, false).tileXIndexFromSrcCoord(11)); - - EXPECT_EQ(0, TestTiling(3, 10, 10, true).tileXIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(3, 10, 10, true).tileXIndexFromSrcCoord(1)); - EXPECT_EQ(1, TestTiling(3, 10, 10, true).tileXIndexFromSrcCoord(2)); - EXPECT_EQ(2, TestTiling(3, 10, 10, true).tileXIndexFromSrcCoord(3)); - EXPECT_EQ(3, TestTiling(3, 10, 10, true).tileXIndexFromSrcCoord(4)); - EXPECT_EQ(4, TestTiling(3, 10, 10, true).tileXIndexFromSrcCoord(5)); - EXPECT_EQ(5, TestTiling(3, 10, 10, true).tileXIndexFromSrcCoord(6)); - EXPECT_EQ(6, TestTiling(3, 10, 10, true).tileXIndexFromSrcCoord(7)); - EXPECT_EQ(7, TestTiling(3, 10, 10, true).tileXIndexFromSrcCoord(8)); - EXPECT_EQ(7, TestTiling(3, 10, 10, true).tileXIndexFromSrcCoord(9)); - EXPECT_EQ(7, TestTiling(3, 10, 10, true).tileXIndexFromSrcCoord(10)); - EXPECT_EQ(7, TestTiling(3, 10, 10, true).tileXIndexFromSrcCoord(11)); - - EXPECT_EQ(0, TestTiling(1, 1, 1, false).tileXIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(2, 2, 2, false).tileXIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(2, 2, 2, false).tileXIndexFromSrcCoord(1)); - EXPECT_EQ(0, TestTiling(3, 3, 3, false).tileXIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(3, 3, 3, false).tileXIndexFromSrcCoord(1)); - EXPECT_EQ(0, TestTiling(3, 3, 3, false).tileXIndexFromSrcCoord(2)); - - EXPECT_EQ(0, TestTiling(3, 4, 3, false).tileXIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(3, 4, 3, false).tileXIndexFromSrcCoord(1)); - EXPECT_EQ(0, TestTiling(3, 4, 3, false).tileXIndexFromSrcCoord(2)); - EXPECT_EQ(1, TestTiling(3, 4, 3, false).tileXIndexFromSrcCoord(3)); - - EXPECT_EQ(0, TestTiling(1, 1, 1, true).tileXIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(2, 2, 2, true).tileXIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(2, 2, 2, true).tileXIndexFromSrcCoord(1)); - EXPECT_EQ(0, TestTiling(3, 3, 3, true).tileXIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(3, 3, 3, true).tileXIndexFromSrcCoord(1)); - EXPECT_EQ(0, TestTiling(3, 3, 3, true).tileXIndexFromSrcCoord(2)); - - EXPECT_EQ(0, TestTiling(3, 4, 3, true).tileXIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(3, 4, 3, true).tileXIndexFromSrcCoord(1)); - EXPECT_EQ(1, TestTiling(3, 4, 3, true).tileXIndexFromSrcCoord(2)); - EXPECT_EQ(1, TestTiling(3, 4, 3, true).tileXIndexFromSrcCoord(3)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileXIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileXIndexFromSrcCoord(1)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileXIndexFromSrcCoord(2)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileXIndexFromSrcCoord(3)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileXIndexFromSrcCoord(4)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileXIndexFromSrcCoord(5)); + EXPECT_EQ(2, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileXIndexFromSrcCoord(6)); + EXPECT_EQ(2, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileXIndexFromSrcCoord(7)); + EXPECT_EQ(2, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileXIndexFromSrcCoord(8)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileXIndexFromSrcCoord(9)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileXIndexFromSrcCoord(10)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileXIndexFromSrcCoord(11)); + + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileXIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileXIndexFromSrcCoord(1)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileXIndexFromSrcCoord(2)); + EXPECT_EQ(2, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileXIndexFromSrcCoord(3)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileXIndexFromSrcCoord(4)); + EXPECT_EQ(4, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileXIndexFromSrcCoord(5)); + EXPECT_EQ(5, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileXIndexFromSrcCoord(6)); + EXPECT_EQ(6, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileXIndexFromSrcCoord(7)); + EXPECT_EQ(7, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileXIndexFromSrcCoord(8)); + EXPECT_EQ(7, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileXIndexFromSrcCoord(9)); + EXPECT_EQ(7, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileXIndexFromSrcCoord(10)); + EXPECT_EQ(7, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileXIndexFromSrcCoord(11)); + + EXPECT_EQ(0, TestTiling(IntSize(1, 1), IntSize(1, 1), false).tileXIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(2, 2), IntSize(2, 2), false).tileXIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(2, 2), IntSize(2, 2), false).tileXIndexFromSrcCoord(1)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 3), false).tileXIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 3), false).tileXIndexFromSrcCoord(1)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 3), false).tileXIndexFromSrcCoord(2)); + + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(4, 3), false).tileXIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(4, 3), false).tileXIndexFromSrcCoord(1)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(4, 3), false).tileXIndexFromSrcCoord(2)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(4, 3), false).tileXIndexFromSrcCoord(3)); + + EXPECT_EQ(0, TestTiling(IntSize(1, 1), IntSize(1, 1), true).tileXIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(2, 2), IntSize(2, 2), true).tileXIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(2, 2), IntSize(2, 2), true).tileXIndexFromSrcCoord(1)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 3), true).tileXIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 3), true).tileXIndexFromSrcCoord(1)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 3), true).tileXIndexFromSrcCoord(2)); + + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(4, 3), true).tileXIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(4, 3), true).tileXIndexFromSrcCoord(1)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(4, 3), true).tileXIndexFromSrcCoord(2)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(4, 3), true).tileXIndexFromSrcCoord(3)); } TEST(TilingDataTest, tileYIndexFromSrcCoord) { - EXPECT_EQ(0, TestTiling(3, 10, 10, false).tileYIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(3, 10, 10, false).tileYIndexFromSrcCoord(1)); - EXPECT_EQ(0, TestTiling(3, 10, 10, false).tileYIndexFromSrcCoord(2)); - EXPECT_EQ(1, TestTiling(3, 10, 10, false).tileYIndexFromSrcCoord(3)); - EXPECT_EQ(1, TestTiling(3, 10, 10, false).tileYIndexFromSrcCoord(4)); - EXPECT_EQ(1, TestTiling(3, 10, 10, false).tileYIndexFromSrcCoord(5)); - EXPECT_EQ(2, TestTiling(3, 10, 10, false).tileYIndexFromSrcCoord(6)); - EXPECT_EQ(2, TestTiling(3, 10, 10, false).tileYIndexFromSrcCoord(7)); - EXPECT_EQ(2, TestTiling(3, 10, 10, false).tileYIndexFromSrcCoord(8)); - EXPECT_EQ(3, TestTiling(3, 10, 10, false).tileYIndexFromSrcCoord(9)); - EXPECT_EQ(3, TestTiling(3, 10, 10, false).tileYIndexFromSrcCoord(10)); - EXPECT_EQ(3, TestTiling(3, 10, 10, false).tileYIndexFromSrcCoord(11)); - - EXPECT_EQ(0, TestTiling(3, 10, 10, true).tileYIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(3, 10, 10, true).tileYIndexFromSrcCoord(1)); - EXPECT_EQ(1, TestTiling(3, 10, 10, true).tileYIndexFromSrcCoord(2)); - EXPECT_EQ(2, TestTiling(3, 10, 10, true).tileYIndexFromSrcCoord(3)); - EXPECT_EQ(3, TestTiling(3, 10, 10, true).tileYIndexFromSrcCoord(4)); - EXPECT_EQ(4, TestTiling(3, 10, 10, true).tileYIndexFromSrcCoord(5)); - EXPECT_EQ(5, TestTiling(3, 10, 10, true).tileYIndexFromSrcCoord(6)); - EXPECT_EQ(6, TestTiling(3, 10, 10, true).tileYIndexFromSrcCoord(7)); - EXPECT_EQ(7, TestTiling(3, 10, 10, true).tileYIndexFromSrcCoord(8)); - EXPECT_EQ(7, TestTiling(3, 10, 10, true).tileYIndexFromSrcCoord(9)); - EXPECT_EQ(7, TestTiling(3, 10, 10, true).tileYIndexFromSrcCoord(10)); - EXPECT_EQ(7, TestTiling(3, 10, 10, true).tileYIndexFromSrcCoord(11)); - - EXPECT_EQ(0, TestTiling(1, 1, 1, false).tileYIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(2, 2, 2, false).tileYIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(2, 2, 2, false).tileYIndexFromSrcCoord(1)); - EXPECT_EQ(0, TestTiling(3, 3, 3, false).tileYIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(3, 3, 3, false).tileYIndexFromSrcCoord(1)); - EXPECT_EQ(0, TestTiling(3, 3, 3, false).tileYIndexFromSrcCoord(2)); - - EXPECT_EQ(0, TestTiling(3, 3, 4, false).tileYIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(3, 3, 4, false).tileYIndexFromSrcCoord(1)); - EXPECT_EQ(0, TestTiling(3, 3, 4, false).tileYIndexFromSrcCoord(2)); - EXPECT_EQ(1, TestTiling(3, 3, 4, false).tileYIndexFromSrcCoord(3)); - - EXPECT_EQ(0, TestTiling(1, 1, 1, true).tileYIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(2, 2, 2, true).tileYIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(2, 2, 2, true).tileYIndexFromSrcCoord(1)); - EXPECT_EQ(0, TestTiling(3, 3, 3, true).tileYIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(3, 3, 3, true).tileYIndexFromSrcCoord(1)); - EXPECT_EQ(0, TestTiling(3, 3, 3, true).tileYIndexFromSrcCoord(2)); - - EXPECT_EQ(0, TestTiling(3, 3, 4, true).tileYIndexFromSrcCoord(0)); - EXPECT_EQ(0, TestTiling(3, 3, 4, true).tileYIndexFromSrcCoord(1)); - EXPECT_EQ(1, TestTiling(3, 3, 4, true).tileYIndexFromSrcCoord(2)); - EXPECT_EQ(1, TestTiling(3, 3, 4, true).tileYIndexFromSrcCoord(3)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileYIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileYIndexFromSrcCoord(1)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileYIndexFromSrcCoord(2)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileYIndexFromSrcCoord(3)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileYIndexFromSrcCoord(4)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileYIndexFromSrcCoord(5)); + EXPECT_EQ(2, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileYIndexFromSrcCoord(6)); + EXPECT_EQ(2, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileYIndexFromSrcCoord(7)); + EXPECT_EQ(2, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileYIndexFromSrcCoord(8)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileYIndexFromSrcCoord(9)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileYIndexFromSrcCoord(10)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(10, 10), false).tileYIndexFromSrcCoord(11)); + + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileYIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileYIndexFromSrcCoord(1)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileYIndexFromSrcCoord(2)); + EXPECT_EQ(2, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileYIndexFromSrcCoord(3)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileYIndexFromSrcCoord(4)); + EXPECT_EQ(4, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileYIndexFromSrcCoord(5)); + EXPECT_EQ(5, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileYIndexFromSrcCoord(6)); + EXPECT_EQ(6, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileYIndexFromSrcCoord(7)); + EXPECT_EQ(7, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileYIndexFromSrcCoord(8)); + EXPECT_EQ(7, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileYIndexFromSrcCoord(9)); + EXPECT_EQ(7, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileYIndexFromSrcCoord(10)); + EXPECT_EQ(7, TestTiling(IntSize(3, 3), IntSize(10, 10), true).tileYIndexFromSrcCoord(11)); + + EXPECT_EQ(0, TestTiling(IntSize(1, 1), IntSize(1, 1), false).tileYIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(2, 2), IntSize(2, 2), false).tileYIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(2, 2), IntSize(2, 2), false).tileYIndexFromSrcCoord(1)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 3), false).tileYIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 3), false).tileYIndexFromSrcCoord(1)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 3), false).tileYIndexFromSrcCoord(2)); + + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 4), false).tileYIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 4), false).tileYIndexFromSrcCoord(1)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 4), false).tileYIndexFromSrcCoord(2)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(3, 4), false).tileYIndexFromSrcCoord(3)); + + EXPECT_EQ(0, TestTiling(IntSize(1, 1), IntSize(1, 1), true).tileYIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(2, 2), IntSize(2, 2), true).tileYIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(2, 2), IntSize(2, 2), true).tileYIndexFromSrcCoord(1)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 3), true).tileYIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 3), true).tileYIndexFromSrcCoord(1)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 3), true).tileYIndexFromSrcCoord(2)); + + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 4), true).tileYIndexFromSrcCoord(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 4), true).tileYIndexFromSrcCoord(1)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(3, 4), true).tileYIndexFromSrcCoord(2)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(3, 4), true).tileYIndexFromSrcCoord(3)); } TEST(TilingDataTest, tileSizeX) { - EXPECT_EQ(5, TestTiling(5, 5, 5, false).tileSizeX(0)); - EXPECT_EQ(5, TestTiling(5, 5, 5, true).tileSizeX(0)); - - EXPECT_EQ(5, TestTiling(5, 6, 6, false).tileSizeX(0)); - EXPECT_EQ(1, TestTiling(5, 6, 6, false).tileSizeX(1)); - EXPECT_EQ(4, TestTiling(5, 6, 6, true).tileSizeX(0)); - EXPECT_EQ(2, TestTiling(5, 6, 6, true).tileSizeX(1)); - - EXPECT_EQ(5, TestTiling(5, 8, 8, false).tileSizeX(0)); - EXPECT_EQ(3, TestTiling(5, 8, 8, false).tileSizeX(1)); - EXPECT_EQ(4, TestTiling(5, 8, 8, true).tileSizeX(0)); - EXPECT_EQ(4, TestTiling(5, 8, 8, true).tileSizeX(1)); - - EXPECT_EQ(5, TestTiling(5, 10, 10, false).tileSizeX(0)); - EXPECT_EQ(5, TestTiling(5, 10, 10, false).tileSizeX(1)); - EXPECT_EQ(4, TestTiling(5, 10, 10, true).tileSizeX(0)); - EXPECT_EQ(3, TestTiling(5, 10, 10, true).tileSizeX(1)); - EXPECT_EQ(3, TestTiling(5, 10, 10, true).tileSizeX(2)); - - EXPECT_EQ(4, TestTiling(5, 11, 11, true).tileSizeX(2)); - EXPECT_EQ(3, TestTiling(5, 12, 12, true).tileSizeX(2)); + EXPECT_EQ(5, TestTiling(IntSize(5, 5), IntSize(5, 5), false).tileSizeX(0)); + EXPECT_EQ(5, TestTiling(IntSize(5, 5), IntSize(5, 5), true).tileSizeX(0)); + + EXPECT_EQ(5, TestTiling(IntSize(5, 5), IntSize(6, 6), false).tileSizeX(0)); + EXPECT_EQ(1, TestTiling(IntSize(5, 5), IntSize(6, 6), false).tileSizeX(1)); + EXPECT_EQ(4, TestTiling(IntSize(5, 5), IntSize(6, 6), true).tileSizeX(0)); + EXPECT_EQ(2, TestTiling(IntSize(5, 5), IntSize(6, 6), true).tileSizeX(1)); + + EXPECT_EQ(5, TestTiling(IntSize(5, 5), IntSize(8, 8), false).tileSizeX(0)); + EXPECT_EQ(3, TestTiling(IntSize(5, 5), IntSize(8, 8), false).tileSizeX(1)); + EXPECT_EQ(4, TestTiling(IntSize(5, 5), IntSize(8, 8), true).tileSizeX(0)); + EXPECT_EQ(4, TestTiling(IntSize(5, 5), IntSize(8, 8), true).tileSizeX(1)); + + EXPECT_EQ(5, TestTiling(IntSize(5, 5), IntSize(10, 10), false).tileSizeX(0)); + EXPECT_EQ(5, TestTiling(IntSize(5, 5), IntSize(10, 10), false).tileSizeX(1)); + EXPECT_EQ(4, TestTiling(IntSize(5, 5), IntSize(10, 10), true).tileSizeX(0)); + EXPECT_EQ(3, TestTiling(IntSize(5, 5), IntSize(10, 10), true).tileSizeX(1)); + EXPECT_EQ(3, TestTiling(IntSize(5, 5), IntSize(10, 10), true).tileSizeX(2)); + + EXPECT_EQ(4, TestTiling(IntSize(5, 5), IntSize(11, 11), true).tileSizeX(2)); + EXPECT_EQ(3, TestTiling(IntSize(5, 5), IntSize(12, 12), true).tileSizeX(2)); + + EXPECT_EQ(3, TestTiling(IntSize(5, 9), IntSize(12, 17), true).tileSizeX(2)); } + TEST(TilingDataTest, tileSizeY) { - EXPECT_EQ(5, TestTiling(5, 5, 5, false).tileSizeY(0)); - EXPECT_EQ(5, TestTiling(5, 5, 5, true).tileSizeY(0)); - - EXPECT_EQ(5, TestTiling(5, 6, 6, false).tileSizeY(0)); - EXPECT_EQ(1, TestTiling(5, 6, 6, false).tileSizeY(1)); - EXPECT_EQ(4, TestTiling(5, 6, 6, true).tileSizeY(0)); - EXPECT_EQ(2, TestTiling(5, 6, 6, true).tileSizeY(1)); - - EXPECT_EQ(5, TestTiling(5, 8, 8, false).tileSizeY(0)); - EXPECT_EQ(3, TestTiling(5, 8, 8, false).tileSizeY(1)); - EXPECT_EQ(4, TestTiling(5, 8, 8, true).tileSizeY(0)); - EXPECT_EQ(4, TestTiling(5, 8, 8, true).tileSizeY(1)); - - EXPECT_EQ(5, TestTiling(5, 10, 10, false).tileSizeY(0)); - EXPECT_EQ(5, TestTiling(5, 10, 10, false).tileSizeY(1)); - EXPECT_EQ(4, TestTiling(5, 10, 10, true).tileSizeY(0)); - EXPECT_EQ(3, TestTiling(5, 10, 10, true).tileSizeY(1)); - EXPECT_EQ(3, TestTiling(5, 10, 10, true).tileSizeY(2)); - - EXPECT_EQ(4, TestTiling(5, 11, 11, true).tileSizeY(2)); - EXPECT_EQ(3, TestTiling(5, 12, 12, true).tileSizeY(2)); + EXPECT_EQ(5, TestTiling(IntSize(5, 5), IntSize(5, 5), false).tileSizeY(0)); + EXPECT_EQ(5, TestTiling(IntSize(5, 5), IntSize(5, 5), true).tileSizeY(0)); + + EXPECT_EQ(5, TestTiling(IntSize(5, 5), IntSize(6, 6), false).tileSizeY(0)); + EXPECT_EQ(1, TestTiling(IntSize(5, 5), IntSize(6, 6), false).tileSizeY(1)); + EXPECT_EQ(4, TestTiling(IntSize(5, 5), IntSize(6, 6), true).tileSizeY(0)); + EXPECT_EQ(2, TestTiling(IntSize(5, 5), IntSize(6, 6), true).tileSizeY(1)); + + EXPECT_EQ(5, TestTiling(IntSize(5, 5), IntSize(8, 8), false).tileSizeY(0)); + EXPECT_EQ(3, TestTiling(IntSize(5, 5), IntSize(8, 8), false).tileSizeY(1)); + EXPECT_EQ(4, TestTiling(IntSize(5, 5), IntSize(8, 8), true).tileSizeY(0)); + EXPECT_EQ(4, TestTiling(IntSize(5, 5), IntSize(8, 8), true).tileSizeY(1)); + + EXPECT_EQ(5, TestTiling(IntSize(5, 5), IntSize(10, 10), false).tileSizeY(0)); + EXPECT_EQ(5, TestTiling(IntSize(5, 5), IntSize(10, 10), false).tileSizeY(1)); + EXPECT_EQ(4, TestTiling(IntSize(5, 5), IntSize(10, 10), true).tileSizeY(0)); + EXPECT_EQ(3, TestTiling(IntSize(5, 5), IntSize(10, 10), true).tileSizeY(1)); + EXPECT_EQ(3, TestTiling(IntSize(5, 5), IntSize(10, 10), true).tileSizeY(2)); + + EXPECT_EQ(4, TestTiling(IntSize(5, 5), IntSize(11, 11), true).tileSizeY(2)); + EXPECT_EQ(3, TestTiling(IntSize(5, 5), IntSize(12, 12), true).tileSizeY(2)); + + EXPECT_EQ(3, TestTiling(IntSize(9, 5), IntSize(17, 12), true).tileSizeY(2)); } TEST(TilingDataTest, tileSizeX_and_tilePositionX) { // Single tile cases: - EXPECT_EQ(1, TestTiling(3, 1, 1, false).tileSizeX(0)); - EXPECT_EQ(0, TestTiling(3, 1, 1, false).tilePositionX(0)); - EXPECT_EQ(1, TestTiling(3, 1, 100, false).tileSizeX(0)); - EXPECT_EQ(0, TestTiling(3, 1, 100, false).tilePositionX(0)); - EXPECT_EQ(3, TestTiling(3, 3, 1, false).tileSizeX(0)); - EXPECT_EQ(0, TestTiling(3, 3, 1, false).tilePositionX(0)); - EXPECT_EQ(3, TestTiling(3, 3, 100, false).tileSizeX(0)); - EXPECT_EQ(0, TestTiling(3, 3, 100, false).tilePositionX(0)); - EXPECT_EQ(1, TestTiling(3, 1, 1, true).tileSizeX(0)); - EXPECT_EQ(0, TestTiling(3, 1, 1, true).tilePositionX(0)); - EXPECT_EQ(1, TestTiling(3, 1, 100, true).tileSizeX(0)); - EXPECT_EQ(0, TestTiling(3, 1, 100, true).tilePositionX(0)); - EXPECT_EQ(3, TestTiling(3, 3, 1, true).tileSizeX(0)); - EXPECT_EQ(0, TestTiling(3, 3, 1, true).tilePositionX(0)); - EXPECT_EQ(3, TestTiling(3, 3, 100, true).tileSizeX(0)); - EXPECT_EQ(0, TestTiling(3, 3, 100, true).tilePositionX(0)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(1, 1), false).tileSizeX(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(1, 1), false).tilePositionX(0)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(1, 100), false).tileSizeX(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(1, 100), false).tilePositionX(0)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(3, 1), false).tileSizeX(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 1), false).tilePositionX(0)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(3, 100), false).tileSizeX(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 100), false).tilePositionX(0)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(1, 1), true).tileSizeX(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(1, 1), true).tilePositionX(0)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(1, 100), true).tileSizeX(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(1, 100), true).tilePositionX(0)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(3, 1), true).tileSizeX(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 1), true).tilePositionX(0)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(3, 100), true).tileSizeX(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(3, 100), true).tilePositionX(0)); // Multiple tiles: // no border // positions 0, 3 - EXPECT_EQ(2, TestTiling(3, 6, 1, false).numTiles()); - EXPECT_EQ(3, TestTiling(3, 6, 1, false).tileSizeX(0)); - EXPECT_EQ(3, TestTiling(3, 6, 1, false).tileSizeX(1)); - EXPECT_EQ(0, TestTiling(3, 6, 1, false).tilePositionX(0)); - EXPECT_EQ(3, TestTiling(3, 6, 1, false).tilePositionX(1)); - EXPECT_EQ(3, TestTiling(3, 6, 100, false).tileSizeX(0)); - EXPECT_EQ(3, TestTiling(3, 6, 100, false).tileSizeX(1)); - EXPECT_EQ(0, TestTiling(3, 6, 100, false).tilePositionX(0)); - EXPECT_EQ(3, TestTiling(3, 6, 100, false).tilePositionX(1)); + EXPECT_EQ(2, TestTiling(IntSize(3, 3), IntSize(6, 1), false).numTiles()); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(6, 1), false).tileSizeX(0)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(6, 1), false).tileSizeX(1)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(6, 1), false).tilePositionX(0)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(6, 1), false).tilePositionX(1)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(6, 100), false).tileSizeX(0)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(6, 100), false).tileSizeX(1)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(6, 100), false).tilePositionX(0)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(6, 100), false).tilePositionX(1)); // Multiple tiles: // with border // positions 0, 2, 3, 4 - EXPECT_EQ(4, TestTiling(3, 6, 1, true).numTiles()); - EXPECT_EQ(2, TestTiling(3, 6, 1, true).tileSizeX(0)); - EXPECT_EQ(1, TestTiling(3, 6, 1, true).tileSizeX(1)); - EXPECT_EQ(1, TestTiling(3, 6, 1, true).tileSizeX(2)); - EXPECT_EQ(2, TestTiling(3, 6, 1, true).tileSizeX(3)); - EXPECT_EQ(0, TestTiling(3, 6, 1, true).tilePositionX(0)); - EXPECT_EQ(2, TestTiling(3, 6, 1, true).tilePositionX(1)); - EXPECT_EQ(3, TestTiling(3, 6, 1, true).tilePositionX(2)); - EXPECT_EQ(4, TestTiling(3, 6, 1, true).tilePositionX(3)); - EXPECT_EQ(2, TestTiling(3, 6, 100, true).tileSizeX(0)); - EXPECT_EQ(1, TestTiling(3, 6, 100, true).tileSizeX(1)); - EXPECT_EQ(1, TestTiling(3, 6, 100, true).tileSizeX(2)); - EXPECT_EQ(2, TestTiling(3, 6, 100, true).tileSizeX(3)); - EXPECT_EQ(0, TestTiling(3, 6, 100, true).tilePositionX(0)); - EXPECT_EQ(2, TestTiling(3, 6, 100, true).tilePositionX(1)); - EXPECT_EQ(3, TestTiling(3, 6, 100, true).tilePositionX(2)); - EXPECT_EQ(4, TestTiling(3, 6, 100, true).tilePositionX(3)); + EXPECT_EQ(4, TestTiling(IntSize(3, 3), IntSize(6, 1), true).numTiles()); + EXPECT_EQ(2, TestTiling(IntSize(3, 3), IntSize(6, 1), true).tileSizeX(0)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(6, 1), true).tileSizeX(1)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(6, 1), true).tileSizeX(2)); + EXPECT_EQ(2, TestTiling(IntSize(3, 3), IntSize(6, 1), true).tileSizeX(3)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(6, 1), true).tilePositionX(0)); + EXPECT_EQ(2, TestTiling(IntSize(3, 3), IntSize(6, 1), true).tilePositionX(1)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(6, 1), true).tilePositionX(2)); + EXPECT_EQ(4, TestTiling(IntSize(3, 3), IntSize(6, 1), true).tilePositionX(3)); + EXPECT_EQ(2, TestTiling(IntSize(3, 7), IntSize(6, 100), true).tileSizeX(0)); + EXPECT_EQ(1, TestTiling(IntSize(3, 7), IntSize(6, 100), true).tileSizeX(1)); + EXPECT_EQ(1, TestTiling(IntSize(3, 7), IntSize(6, 100), true).tileSizeX(2)); + EXPECT_EQ(2, TestTiling(IntSize(3, 7), IntSize(6, 100), true).tileSizeX(3)); + EXPECT_EQ(0, TestTiling(IntSize(3, 7), IntSize(6, 100), true).tilePositionX(0)); + EXPECT_EQ(2, TestTiling(IntSize(3, 7), IntSize(6, 100), true).tilePositionX(1)); + EXPECT_EQ(3, TestTiling(IntSize(3, 7), IntSize(6, 100), true).tilePositionX(2)); + EXPECT_EQ(4, TestTiling(IntSize(3, 7), IntSize(6, 100), true).tilePositionX(3)); } TEST(TilingDataTest, tileSizeY_and_tilePositionY) { // Single tile cases: - EXPECT_EQ(1, TestTiling(3, 1, 1, false).tileSizeY(0)); - EXPECT_EQ(0, TestTiling(3, 1, 1, false).tilePositionY(0)); - EXPECT_EQ(1, TestTiling(3, 100, 1, false).tileSizeY(0)); - EXPECT_EQ(0, TestTiling(3, 100, 1, false).tilePositionY(0)); - EXPECT_EQ(3, TestTiling(3, 1, 3, false).tileSizeY(0)); - EXPECT_EQ(0, TestTiling(3, 1, 3, false).tilePositionY(0)); - EXPECT_EQ(3, TestTiling(3, 100, 3, false).tileSizeY(0)); - EXPECT_EQ(0, TestTiling(3, 100, 3, false).tilePositionY(0)); - EXPECT_EQ(1, TestTiling(3, 1, 1, true).tileSizeY(0)); - EXPECT_EQ(0, TestTiling(3, 1, 1, true).tilePositionY(0)); - EXPECT_EQ(1, TestTiling(3, 100, 1, true).tileSizeY(0)); - EXPECT_EQ(0, TestTiling(3, 100, 1, true).tilePositionY(0)); - EXPECT_EQ(3, TestTiling(3, 1, 3, true).tileSizeY(0)); - EXPECT_EQ(0, TestTiling(3, 1, 3, true).tilePositionY(0)); - EXPECT_EQ(3, TestTiling(3, 100, 3, true).tileSizeY(0)); - EXPECT_EQ(0, TestTiling(3, 100, 3, true).tilePositionY(0)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(1, 1), false).tileSizeY(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(1, 1), false).tilePositionY(0)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(100, 1), false).tileSizeY(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(100, 1), false).tilePositionY(0)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(1, 3), false).tileSizeY(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(1, 3), false).tilePositionY(0)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(100, 3), false).tileSizeY(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(100, 3), false).tilePositionY(0)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(1, 1), true).tileSizeY(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(1, 1), true).tilePositionY(0)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(100, 1), true).tileSizeY(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(100, 1), true).tilePositionY(0)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(1, 3), true).tileSizeY(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(1, 3), true).tilePositionY(0)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(100, 3), true).tileSizeY(0)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(100, 3), true).tilePositionY(0)); // Multiple tiles: // no border // positions 0, 3 - EXPECT_EQ(2, TestTiling(3, 1, 6, false).numTiles()); - EXPECT_EQ(3, TestTiling(3, 1, 6, false).tileSizeY(0)); - EXPECT_EQ(3, TestTiling(3, 1, 6, false).tileSizeY(1)); - EXPECT_EQ(0, TestTiling(3, 1, 6, false).tilePositionY(0)); - EXPECT_EQ(3, TestTiling(3, 1, 6, false).tilePositionY(1)); - EXPECT_EQ(3, TestTiling(3, 100, 6, false).tileSizeY(0)); - EXPECT_EQ(3, TestTiling(3, 100, 6, false).tileSizeY(1)); - EXPECT_EQ(0, TestTiling(3, 100, 6, false).tilePositionY(0)); - EXPECT_EQ(3, TestTiling(3, 100, 6, false).tilePositionY(1)); + EXPECT_EQ(2, TestTiling(IntSize(3, 3), IntSize(1, 6), false).numTiles()); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(1, 6), false).tileSizeY(0)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(1, 6), false).tileSizeY(1)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(1, 6), false).tilePositionY(0)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(1, 6), false).tilePositionY(1)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(100, 6), false).tileSizeY(0)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(100, 6), false).tileSizeY(1)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(100, 6), false).tilePositionY(0)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(100, 6), false).tilePositionY(1)); // Multiple tiles: // with border // positions 0, 2, 3, 4 - EXPECT_EQ(4, TestTiling(3, 1, 6, true).numTiles()); - EXPECT_EQ(2, TestTiling(3, 1, 6, true).tileSizeY(0)); - EXPECT_EQ(1, TestTiling(3, 1, 6, true).tileSizeY(1)); - EXPECT_EQ(1, TestTiling(3, 1, 6, true).tileSizeY(2)); - EXPECT_EQ(2, TestTiling(3, 1, 6, true).tileSizeY(3)); - EXPECT_EQ(0, TestTiling(3, 1, 6, true).tilePositionY(0)); - EXPECT_EQ(2, TestTiling(3, 1, 6, true).tilePositionY(1)); - EXPECT_EQ(3, TestTiling(3, 1, 6, true).tilePositionY(2)); - EXPECT_EQ(4, TestTiling(3, 1, 6, true).tilePositionY(3)); - EXPECT_EQ(2, TestTiling(3, 100, 6, true).tileSizeY(0)); - EXPECT_EQ(1, TestTiling(3, 100, 6, true).tileSizeY(1)); - EXPECT_EQ(1, TestTiling(3, 100, 6, true).tileSizeY(2)); - EXPECT_EQ(2, TestTiling(3, 100, 6, true).tileSizeY(3)); - EXPECT_EQ(0, TestTiling(3, 100, 6, true).tilePositionY(0)); - EXPECT_EQ(2, TestTiling(3, 100, 6, true).tilePositionY(1)); - EXPECT_EQ(3, TestTiling(3, 100, 6, true).tilePositionY(2)); - EXPECT_EQ(4, TestTiling(3, 100, 6, true).tilePositionY(3)); + EXPECT_EQ(4, TestTiling(IntSize(3, 3), IntSize(1, 6), true).numTiles()); + EXPECT_EQ(2, TestTiling(IntSize(3, 3), IntSize(1, 6), true).tileSizeY(0)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(1, 6), true).tileSizeY(1)); + EXPECT_EQ(1, TestTiling(IntSize(3, 3), IntSize(1, 6), true).tileSizeY(2)); + EXPECT_EQ(2, TestTiling(IntSize(3, 3), IntSize(1, 6), true).tileSizeY(3)); + EXPECT_EQ(0, TestTiling(IntSize(3, 3), IntSize(1, 6), true).tilePositionY(0)); + EXPECT_EQ(2, TestTiling(IntSize(3, 3), IntSize(1, 6), true).tilePositionY(1)); + EXPECT_EQ(3, TestTiling(IntSize(3, 3), IntSize(1, 6), true).tilePositionY(2)); + EXPECT_EQ(4, TestTiling(IntSize(3, 3), IntSize(1, 6), true).tilePositionY(3)); + EXPECT_EQ(2, TestTiling(IntSize(7, 3), IntSize(100, 6), true).tileSizeY(0)); + EXPECT_EQ(1, TestTiling(IntSize(7, 3), IntSize(100, 6), true).tileSizeY(1)); + EXPECT_EQ(1, TestTiling(IntSize(7, 3), IntSize(100, 6), true).tileSizeY(2)); + EXPECT_EQ(2, TestTiling(IntSize(7, 3), IntSize(100, 6), true).tileSizeY(3)); + EXPECT_EQ(0, TestTiling(IntSize(7, 3), IntSize(100, 6), true).tilePositionY(0)); + EXPECT_EQ(2, TestTiling(IntSize(7, 3), IntSize(100, 6), true).tilePositionY(1)); + EXPECT_EQ(3, TestTiling(IntSize(7, 3), IntSize(100, 6), true).tilePositionY(2)); + EXPECT_EQ(4, TestTiling(IntSize(7, 3), IntSize(100, 6), true).tilePositionY(3)); } TEST(TilingDataTest, setTotalSize) { - TestTiling data(5, 5, 5, false); - EXPECT_EQ(5, data.totalSizeX()); - EXPECT_EQ(5, data.totalSizeY()); + TestTiling data(IntSize(5, 5), IntSize(5, 5), false); + EXPECT_EQ(5, data.totalSize().width()); + EXPECT_EQ(5, data.totalSize().height()); EXPECT_EQ(1, data.numTilesX()); EXPECT_EQ(5, data.tileSizeX(0)); EXPECT_EQ(1, data.numTilesY()); EXPECT_EQ(5, data.tileSizeY(0)); - data.setTotalSize(6, 5); - EXPECT_EQ(6, data.totalSizeX()); - EXPECT_EQ(5, data.totalSizeY()); + data.setTotalSize(IntSize(6, 5)); + EXPECT_EQ(6, data.totalSize().width()); + EXPECT_EQ(5, data.totalSize().height()); EXPECT_EQ(2, data.numTilesX()); EXPECT_EQ(5, data.tileSizeX(0)); EXPECT_EQ(1, data.tileSizeX(1)); EXPECT_EQ(1, data.numTilesY()); EXPECT_EQ(5, data.tileSizeY(0)); - data.setTotalSize(5, 12); - EXPECT_EQ(5, data.totalSizeX()); - EXPECT_EQ(12, data.totalSizeY()); + data.setTotalSize(IntSize(5, 12)); + EXPECT_EQ(5, data.totalSize().width()); + EXPECT_EQ(12, data.totalSize().height()); EXPECT_EQ(1, data.numTilesX()); EXPECT_EQ(5, data.tileSizeX(0)); EXPECT_EQ(3, data.numTilesY()); @@ -468,75 +480,85 @@ TEST(TilingDataTest, setTotalSize) TEST(TilingDataTest, setMaxTextureSizeNoBorders) { - TestTiling data(8, 16, 32, false); + TestTiling data(IntSize(8, 8), IntSize(16, 32), false); EXPECT_EQ(2, data.numTilesX()); EXPECT_EQ(4, data.numTilesY()); - data.setMaxTextureSize(32); - EXPECT_EQ(32, data.maxTextureSize()); + data.setMaxTextureSize(IntSize(32, 32)); + EXPECT_EQ(IntSize(32, 32), data.maxTextureSize()); EXPECT_EQ(1, data.numTilesX()); EXPECT_EQ(1, data.numTilesY()); - data.setMaxTextureSize(2); - EXPECT_EQ(2, data.maxTextureSize()); + data.setMaxTextureSize(IntSize(2, 2)); + EXPECT_EQ(IntSize(2, 2), data.maxTextureSize()); EXPECT_EQ(8, data.numTilesX()); EXPECT_EQ(16, data.numTilesY()); - data.setMaxTextureSize(5); - EXPECT_EQ(5, data.maxTextureSize()); + data.setMaxTextureSize(IntSize(5, 5)); + EXPECT_EQ(IntSize(5, 5), data.maxTextureSize()); EXPECT_EQ(4, data.numTilesX()); EXPECT_EQ(7, data.numTilesY()); + + data.setMaxTextureSize(IntSize(8, 5)); + EXPECT_EQ(IntSize(8, 5), data.maxTextureSize()); + EXPECT_EQ(2, data.numTilesX()); + EXPECT_EQ(7, data.numTilesY()); } TEST(TilingDataTest, setMaxTextureSizeBorders) { - TestTiling data(8, 16, 32, true); + TestTiling data(IntSize(8, 8), IntSize(16, 32), true); EXPECT_EQ(3, data.numTilesX()); EXPECT_EQ(5, data.numTilesY()); - data.setMaxTextureSize(32); - EXPECT_EQ(32, data.maxTextureSize()); + data.setMaxTextureSize(IntSize(32, 32)); + EXPECT_EQ(IntSize(32, 32), data.maxTextureSize()); EXPECT_EQ(1, data.numTilesX()); EXPECT_EQ(1, data.numTilesY()); - data.setMaxTextureSize(2); - EXPECT_EQ(2, data.maxTextureSize()); + data.setMaxTextureSize(IntSize(2, 2)); + EXPECT_EQ(IntSize(2, 2), data.maxTextureSize()); EXPECT_EQ(0, data.numTilesX()); EXPECT_EQ(0, data.numTilesY()); - data.setMaxTextureSize(5); - EXPECT_EQ(5, data.maxTextureSize()); + data.setMaxTextureSize(IntSize(5, 5)); + EXPECT_EQ(IntSize(5, 5), data.maxTextureSize()); EXPECT_EQ(5, data.numTilesX()); EXPECT_EQ(10, data.numTilesY()); + + data.setMaxTextureSize(IntSize(8, 5)); + EXPECT_EQ(IntSize(8, 5), data.maxTextureSize()); + EXPECT_EQ(3, data.numTilesX()); + EXPECT_EQ(10, data.numTilesY()); } TEST(TilingDataTest, assignment) { { - TestTiling source(8, 16, 32, true); + TestTiling source(IntSize(8, 8), IntSize(16, 32), true); TestTiling dest = source; EXPECT_EQ(source.borderTexels(), dest.borderTexels()); EXPECT_EQ(source.maxTextureSize(), dest.maxTextureSize()); EXPECT_EQ(source.numTilesX(), dest.numTilesX()); EXPECT_EQ(source.numTilesY(), dest.numTilesY()); - EXPECT_EQ(source.totalSizeX(), dest.totalSizeX()); - EXPECT_EQ(source.totalSizeY(), dest.totalSizeY()); + EXPECT_EQ(source.totalSize().width(), dest.totalSize().width()); + EXPECT_EQ(source.totalSize().height(), dest.totalSize().height()); } { - TestTiling source(3, 6, 100, false); + TestTiling source(IntSize(7, 3), IntSize(6, 100), false); TestTiling dest(source); EXPECT_EQ(source.borderTexels(), dest.borderTexels()); EXPECT_EQ(source.maxTextureSize(), dest.maxTextureSize()); EXPECT_EQ(source.numTilesX(), dest.numTilesX()); EXPECT_EQ(source.numTilesY(), dest.numTilesY()); - EXPECT_EQ(source.totalSizeX(), dest.totalSizeX()); - EXPECT_EQ(source.totalSizeY(), dest.totalSizeY()); + EXPECT_EQ(source.totalSize().width(), dest.totalSize().width()); + EXPECT_EQ(source.totalSize().height(), dest.totalSize().height()); } } TEST(TilingDataTest, setBorderTexels) { - TestTiling data(8, 16, 32, false); + TestTiling data(IntSize(8, 8), IntSize(16, 32), false); EXPECT_EQ(2, data.numTilesX()); EXPECT_EQ(4, data.numTilesY()); diff --git a/Source/WebKit/chromium/tests/WebFrameTest.cpp b/Source/WebKit/chromium/tests/WebFrameTest.cpp index b8bc2e3c4..2fe01bf16 100644 --- a/Source/WebKit/chromium/tests/WebFrameTest.cpp +++ b/Source/WebKit/chromium/tests/WebFrameTest.cpp @@ -40,6 +40,7 @@ #include "WebRange.h" #include "WebScriptSource.h" #include "WebSearchableFormData.h" +#include "WebSecurityOrigin.h" #include "WebSecurityPolicy.h" #include "WebSettings.h" #include "WebViewClient.h" @@ -136,22 +137,71 @@ TEST_F(WebFrameTest, FormWithNullFrame) WebSearchableFormData searchableDataForm(forms[0]); } +TEST_F(WebFrameTest, ChromePageJavascript) +{ + registerMockedChromeURLLoad("history.html"); + + // Pass true to enable JavaScript. + WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_chromeURL + "history.html", true); + + // Try to run JS against the chrome-style URL. + FrameTestHelpers::loadFrame(webView->mainFrame(), "javascript:document.body.appendChild(document.createTextNode('Clobbered'))"); + + // Required to see any updates in contentAsText. + webView->layout(); + + // Now retrieve the frame's text and ensure it was modified by running javascript. + std::string content = webView->mainFrame()->contentAsText(1024).utf8(); + EXPECT_NE(std::string::npos, content.find("Clobbered")); +} + TEST_F(WebFrameTest, ChromePageNoJavascript) { registerMockedChromeURLLoad("history.html"); + /// Pass true to enable JavaScript. WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_chromeURL + "history.html", true); - // Try to run JS against the chrome-style URL. + // Try to run JS against the chrome-style URL after prohibiting it. WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs("chrome"); FrameTestHelpers::loadFrame(webView->mainFrame(), "javascript:document.body.appendChild(document.createTextNode('Clobbered'))"); - // Now retrieve the frames text and see if it was clobbered. + // Required to see any updates in contentAsText. + webView->layout(); + + // Now retrieve the frame's text and ensure it wasn't modified by running javascript. std::string content = webView->mainFrame()->contentAsText(1024).utf8(); - EXPECT_NE(std::string::npos, content.find("Simulated Chromium History Page")); EXPECT_EQ(std::string::npos, content.find("Clobbered")); } +TEST_F(WebFrameTest, DispatchMessageEventWithOriginCheck) +{ + registerMockedHttpURLLoad("postmessage_test.html"); + + // Pass true to enable JavaScript. + WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "postmessage_test.html", true); + + // Send a message with the correct origin. + WebSecurityOrigin correctOrigin(WebSecurityOrigin::create(GURL(m_baseURL))); + WebDOMEvent event = webView->mainFrame()->document().createEvent("MessageEvent"); + WebDOMMessageEvent message = event.to<WebDOMMessageEvent>(); + WebSerializedScriptValue data(WebSerializedScriptValue::fromString("foo")); + message.initMessageEvent("message", false, false, data, "http://origin.com", 0, ""); + webView->mainFrame()->dispatchMessageEventWithOriginCheck(correctOrigin, message); + + // Send another message with incorrect origin. + WebSecurityOrigin incorrectOrigin(WebSecurityOrigin::create(GURL(m_chromeURL))); + webView->mainFrame()->dispatchMessageEventWithOriginCheck(incorrectOrigin, message); + + // Required to see any updates in contentAsText. + webView->layout(); + + // Verify that only the first addition is in the body of the page. + std::string content = webView->mainFrame()->contentAsText(1024).utf8(); + EXPECT_NE(std::string::npos, content.find("Message 1.")); + EXPECT_EQ(std::string::npos, content.find("Message 2.")); +} + #if ENABLE(VIEWPORT) class FixedLayoutTestWebViewClient : public WebViewClient { diff --git a/Source/WebKit/chromium/tests/WebViewTest.cpp b/Source/WebKit/chromium/tests/WebViewTest.cpp index 00d8a832d..460c62bd2 100644 --- a/Source/WebKit/chromium/tests/WebViewTest.cpp +++ b/Source/WebKit/chromium/tests/WebViewTest.cpp @@ -110,6 +110,8 @@ protected: int expectedWidth, int expectedHeight, HorizontalScrollbarState expectedHorizontalState, VerticalScrollbarState expectedVerticalState); + void testTextInputType(WebTextInputType expectedType, const std::string& htmlFile); + std::string m_baseURL; }; @@ -245,4 +247,44 @@ TEST_F(WebViewTest, AutoResizeMaxSize) expectedWidth, expectedHeight, NoHorizontalScrollbar, NoVerticalScrollbar); } +void WebViewTest::testTextInputType(WebTextInputType expectedType, const std::string& htmlFile) +{ + FrameTestHelpers::registerMockedURLLoad(m_baseURL, htmlFile); + WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + htmlFile); + webView->setInitialFocus(false); + EXPECT_EQ(expectedType, webView->textInputType()); + webView->close(); +} + +// Disabled for https://bugs.webkit.org/show_bug.cgi?id=78746#c29 +TEST_F(WebViewTest, DISABLED_TextInputType) +{ + testTextInputType(WebTextInputTypeText, "input_field_default.html"); + testTextInputType(WebTextInputTypePassword, "input_field_password.html"); + testTextInputType(WebTextInputTypeEmail, "input_field_email.html"); + testTextInputType(WebTextInputTypeSearch, "input_field_search.html"); + testTextInputType(WebTextInputTypeNumber, "input_field_number.html"); + testTextInputType(WebTextInputTypeTelephone, "input_field_tel.html"); + testTextInputType(WebTextInputTypeURL, "input_field_url.html"); +#if ENABLE(INPUT_TYPE_DATE) + testTextInputType(WebTextInputTypeDate, "input_field_date.html"); +#endif +#if ENABLE(INPUT_TYPE_DATETIME) + testTextInputType(WebTextInputTypeDateTime, "input_field_datetime.html"); +#endif +#if ENABLE(INPUT_TYPE_DATETIMELOCAL) + testTextInputType(WebTextInputTypeDateTimeLocal, "input_field_datetimelocal.html"); +#endif +#if ENABLE(INPUT_TYPE_MONTH) + testTextInputType(WebTextInputTypeMonth, "input_field_month.html"); +#endif +#if ENABLE(INPUT_TYPE_TIME) + testTextInputType(WebTextInputTypeTime, "input_field_time.html"); +#endif +#if ENABLE(INPUT_TYPE_WEEK) + testTextInputType(WebTextInputTypeWeek, "input_field_week.html"); +#endif + +} + } diff --git a/Source/WebKit/chromium/tests/data/input_field_date.html b/Source/WebKit/chromium/tests/data/input_field_date.html new file mode 100644 index 000000000..72aba6db6 --- /dev/null +++ b/Source/WebKit/chromium/tests/data/input_field_date.html @@ -0,0 +1 @@ +<input type="date" /> diff --git a/Source/WebKit/chromium/tests/data/input_field_datetime.html b/Source/WebKit/chromium/tests/data/input_field_datetime.html new file mode 100644 index 000000000..fa9c5481b --- /dev/null +++ b/Source/WebKit/chromium/tests/data/input_field_datetime.html @@ -0,0 +1 @@ +<input type="datetime" /> diff --git a/Source/WebKit/chromium/tests/data/input_field_datetimelocal.html b/Source/WebKit/chromium/tests/data/input_field_datetimelocal.html new file mode 100644 index 000000000..42f8422bf --- /dev/null +++ b/Source/WebKit/chromium/tests/data/input_field_datetimelocal.html @@ -0,0 +1 @@ +<input type="datetime-local" /> diff --git a/Source/WebKit/chromium/tests/data/input_field_default.html b/Source/WebKit/chromium/tests/data/input_field_default.html new file mode 100644 index 000000000..4cf679efe --- /dev/null +++ b/Source/WebKit/chromium/tests/data/input_field_default.html @@ -0,0 +1 @@ +<input /> diff --git a/Source/WebKit/chromium/tests/data/input_field_email.html b/Source/WebKit/chromium/tests/data/input_field_email.html new file mode 100644 index 000000000..d12a5aab8 --- /dev/null +++ b/Source/WebKit/chromium/tests/data/input_field_email.html @@ -0,0 +1 @@ +<input type="email" /> diff --git a/Source/WebKit/chromium/tests/data/input_field_month.html b/Source/WebKit/chromium/tests/data/input_field_month.html new file mode 100644 index 000000000..f787e4f64 --- /dev/null +++ b/Source/WebKit/chromium/tests/data/input_field_month.html @@ -0,0 +1 @@ +<input type="month" /> diff --git a/Source/WebKit/chromium/tests/data/input_field_number.html b/Source/WebKit/chromium/tests/data/input_field_number.html new file mode 100644 index 000000000..2cfc5bdfa --- /dev/null +++ b/Source/WebKit/chromium/tests/data/input_field_number.html @@ -0,0 +1 @@ +<input type="number" /> diff --git a/Source/WebKit/chromium/tests/data/input_field_password.html b/Source/WebKit/chromium/tests/data/input_field_password.html new file mode 100644 index 000000000..98ed14c93 --- /dev/null +++ b/Source/WebKit/chromium/tests/data/input_field_password.html @@ -0,0 +1 @@ +<input type="password" /> diff --git a/Source/WebKit/chromium/tests/data/input_field_search.html b/Source/WebKit/chromium/tests/data/input_field_search.html new file mode 100644 index 000000000..7f360e6bc --- /dev/null +++ b/Source/WebKit/chromium/tests/data/input_field_search.html @@ -0,0 +1 @@ +<input type="search" /> diff --git a/Source/WebKit/chromium/tests/data/input_field_tel.html b/Source/WebKit/chromium/tests/data/input_field_tel.html new file mode 100644 index 000000000..3dcaae033 --- /dev/null +++ b/Source/WebKit/chromium/tests/data/input_field_tel.html @@ -0,0 +1 @@ +<input type="tel" /> diff --git a/Source/WebKit/chromium/tests/data/input_field_time.html b/Source/WebKit/chromium/tests/data/input_field_time.html new file mode 100644 index 000000000..b74734bd4 --- /dev/null +++ b/Source/WebKit/chromium/tests/data/input_field_time.html @@ -0,0 +1 @@ +<input type="time" /> diff --git a/Source/WebKit/chromium/tests/data/input_field_url.html b/Source/WebKit/chromium/tests/data/input_field_url.html new file mode 100644 index 000000000..bf2716bc6 --- /dev/null +++ b/Source/WebKit/chromium/tests/data/input_field_url.html @@ -0,0 +1 @@ +<input type="url" /> diff --git a/Source/WebKit/chromium/tests/data/input_field_week.html b/Source/WebKit/chromium/tests/data/input_field_week.html new file mode 100644 index 000000000..f4290cdb9 --- /dev/null +++ b/Source/WebKit/chromium/tests/data/input_field_week.html @@ -0,0 +1 @@ +<input type="week" /> diff --git a/Source/WebKit/chromium/tests/data/listener/listener_leak1.html b/Source/WebKit/chromium/tests/data/listener/listener_leak1.html new file mode 100644 index 000000000..ef0e0ec6e --- /dev/null +++ b/Source/WebKit/chromium/tests/data/listener/listener_leak1.html @@ -0,0 +1,38 @@ +<!DOCTYPE html> +<html> +<head><title>Event Listener Leak Test 1</title></head> +<body onload="leak()"> +<script> +if (typeof(gc) == "undefined") gc = function() {}; + +function EventListenerLeakTestObject1() {} + +function createListener(node) { + var foo = new EventListenerLeakTestObject1(); + return function(evt) { + // This closure references |node| and an instance of leak object. + node.foo = foo; + }; +} + +function doLeak() { + for (var i = 0; i < 10000; i++) { + var node = document.createElement('span'); + node.onclick = createListener(node); + } +} + +function leak() { + doLeak(); + gc(); + gc(); +} +</script> + +<p>This page leaks memory.</p> + +<!-- Allow leaking manually. --> +<input type="button" value="Leak More" onclick="leak()"> + +</body> +</html> diff --git a/Source/WebKit/chromium/tests/data/listener/listener_leak2.html b/Source/WebKit/chromium/tests/data/listener/listener_leak2.html new file mode 100644 index 000000000..14df25a34 --- /dev/null +++ b/Source/WebKit/chromium/tests/data/listener/listener_leak2.html @@ -0,0 +1,40 @@ +<!DOCTYPE html> +<html> +<head><title>Event Listener Leak Test 2</title></head> +<body onload="leak()"> +<script> +if (typeof(gc) == "undefined") gc = function() {}; + +var node = null; + +function EventListenerLeakTestObject2() {} + +function createListener(node) { + var foo = new EventListenerLeakTestObject2(); + return function(evt) { + // This closure references |node| and an instance of leak object. + node.foo = foo; + }; +} + +function doLeak() { + if (!node) node = document.createElement('span'); + for (var i = 0; i < 10000; i++) { + node.onclick = createListener(node); + } +} + +function leak() { + doLeak(); + gc(); + gc(); +} +</script> + +<p>This page leaks memory.</p> + +<!-- Allow leaking manually. --> +<input type="button" value="Leak More" onclick="leak()"> + +</body> +</html> diff --git a/Source/WebKit/chromium/tests/data/listener/mutation_event_listener.html b/Source/WebKit/chromium/tests/data/listener/mutation_event_listener.html new file mode 100644 index 000000000..231a4f1e8 --- /dev/null +++ b/Source/WebKit/chromium/tests/data/listener/mutation_event_listener.html @@ -0,0 +1,38 @@ +<!DOCTYPE html> +<html> +<head> +<script> +function removeNode(id) { + var node = document.getElementById(id); + node.parentNode.removeChild(node); + } + +function addElement(id) { + var elem = document.createElement("div"); + elem.setAttribute("id", id); + var text = document.createTextNode("Added node id=" + id); + elem.appendChild(text); + document.getElementById("topDiv").appendChild(elem); + } + +function changeText(id, newText) { + var node = document.getElementById(id); + node.childNodes[0].nodeValue = newText; +} +</script> +</head> + +<body> + +<div id="topDiv"> + <div id="div1">Div #1</div> + <div id="div2">Div #2</div> + <div id="div3">Div #3</div> +</div> + +<button onclick="removeNode('div1')">Remove node</button><br> +<button onclick="addElement('bidule')">Add node</button><br> +<button onclick="changeText('div2', 'Bijour')">Change text</button><br> + +</body> +</html> diff --git a/Source/WebKit/chromium/tests/data/postmessage_test.html b/Source/WebKit/chromium/tests/data/postmessage_test.html new file mode 100644 index 000000000..75cb8efec --- /dev/null +++ b/Source/WebKit/chromium/tests/data/postmessage_test.html @@ -0,0 +1,16 @@ +<html> +<head> +<title>PostMessage Test</title> +<script> +var messagesReceived = 0; +window.addEventListener("message", messageReceived, false); +function messageReceived(event) { + messagesReceived++; + document.body.appendChild(document.createTextNode('Message ' + messagesReceived + '.')); +} +</script> +</head> +<body> +Test page. +</body> +</html> |