Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: Source/web/tests/GraphicsLayerTest.cpp

Issue 216423011: Move remained platform tests from web/tests/ to platform/ (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/web/tests/FilterOperationsTest.cpp ('k') | Source/web/tests/ImageFilterBuilderTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25 #include "config.h"
26
27 #include "platform/graphics/GraphicsLayer.h"
28
29 #include "platform/scroll/ScrollableArea.h"
30 #include "platform/transforms/Matrix3DTransformOperation.h"
31 #include "platform/transforms/RotateTransformOperation.h"
32 #include "platform/transforms/TranslateTransformOperation.h"
33 #include "wtf/PassOwnPtr.h"
34
35 #include <gtest/gtest.h>
36 #include "public/platform/Platform.h"
37 #include "public/platform/WebCompositorSupport.h"
38 #include "public/platform/WebFloatAnimationCurve.h"
39 #include "public/platform/WebGraphicsContext3D.h"
40 #include "public/platform/WebLayer.h"
41 #include "public/platform/WebLayerTreeView.h"
42 #include "public/platform/WebUnitTestSupport.h"
43
44 using namespace WebCore;
45 using namespace blink;
46
47 namespace {
48
49 class MockGraphicsLayerClient : public GraphicsLayerClient {
50 public:
51 virtual void notifyAnimationStarted(const GraphicsLayer*, double monotonicTi me) OVERRIDE { }
52 virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsL ayerPaintingPhase, const IntRect& inClip) OVERRIDE { }
53 virtual String debugName(const GraphicsLayer*) OVERRIDE { return String(); }
54 };
55
56 class GraphicsLayerForTesting : public GraphicsLayer {
57 public:
58 explicit GraphicsLayerForTesting(GraphicsLayerClient* client)
59 : GraphicsLayer(client) { };
60
61 virtual blink::WebLayer* contentsLayer() const { return GraphicsLayer::conte ntsLayer(); }
62 };
63
64 class GraphicsLayerTest : public testing::Test {
65 public:
66 GraphicsLayerTest()
67 {
68 m_clipLayer = adoptPtr(new GraphicsLayerForTesting(&m_client));
69 m_graphicsLayer = adoptPtr(new GraphicsLayerForTesting(&m_client));
70 m_clipLayer->addChild(m_graphicsLayer.get());
71 m_graphicsLayer->platformLayer()->setScrollClipLayer(
72 m_clipLayer->platformLayer());
73 m_platformLayer = m_graphicsLayer->platformLayer();
74 m_layerTreeView = adoptPtr(Platform::current()->unitTestSupport()->creat eLayerTreeViewForTesting(WebUnitTestSupport::TestViewTypeUnitTest));
75 ASSERT(m_layerTreeView);
76 m_layerTreeView->setRootLayer(*m_clipLayer->platformLayer());
77 m_layerTreeView->registerViewportLayers(
78 m_clipLayer->platformLayer(), m_graphicsLayer->platformLayer(), 0);
79 m_layerTreeView->setViewportSize(WebSize(1, 1), WebSize(1, 1));
80 }
81
82 virtual ~GraphicsLayerTest()
83 {
84 m_graphicsLayer.clear();
85 m_layerTreeView.clear();
86 }
87
88 protected:
89 WebLayer* m_platformLayer;
90 OwnPtr<GraphicsLayerForTesting> m_graphicsLayer;
91 OwnPtr<GraphicsLayerForTesting> m_clipLayer;
92
93 private:
94 OwnPtr<WebLayerTreeView> m_layerTreeView;
95 MockGraphicsLayerClient m_client;
96 };
97
98 TEST_F(GraphicsLayerTest, updateLayerShouldFlattenTransformWithAnimations)
99 {
100 ASSERT_FALSE(m_platformLayer->hasActiveAnimation());
101
102 OwnPtr<WebFloatAnimationCurve> curve = adoptPtr(Platform::current()->composi torSupport()->createFloatAnimationCurve());
103 curve->add(WebFloatKeyframe(0.0, 0.0));
104 OwnPtr<WebAnimation> floatAnimation(adoptPtr(Platform::current()->compositor Support()->createAnimation(*curve, WebAnimation::TargetPropertyOpacity)));
105 int animationId = floatAnimation->id();
106 ASSERT_TRUE(m_platformLayer->addAnimation(floatAnimation.leakPtr()));
107
108 ASSERT_TRUE(m_platformLayer->hasActiveAnimation());
109
110 m_graphicsLayer->setShouldFlattenTransform(false);
111
112 m_platformLayer = m_graphicsLayer->platformLayer();
113 ASSERT_TRUE(m_platformLayer);
114
115 ASSERT_TRUE(m_platformLayer->hasActiveAnimation());
116 m_platformLayer->removeAnimation(animationId);
117 ASSERT_FALSE(m_platformLayer->hasActiveAnimation());
118
119 m_graphicsLayer->setShouldFlattenTransform(true);
120
121 m_platformLayer = m_graphicsLayer->platformLayer();
122 ASSERT_TRUE(m_platformLayer);
123
124 ASSERT_FALSE(m_platformLayer->hasActiveAnimation());
125 }
126
127 class FakeScrollableArea : public ScrollableArea {
128 public:
129 virtual bool isActive() const OVERRIDE { return false; }
130 virtual int scrollSize(ScrollbarOrientation) const OVERRIDE { return 100; }
131 virtual bool isScrollCornerVisible() const OVERRIDE { return false; }
132 virtual IntRect scrollCornerRect() const OVERRIDE { return IntRect(); }
133 virtual int visibleWidth() const OVERRIDE { return 10; }
134 virtual int visibleHeight() const OVERRIDE { return 10; }
135 virtual IntSize contentsSize() const OVERRIDE { return IntSize(100, 100); }
136 virtual bool scrollbarsCanBeActive() const OVERRIDE { return false; }
137 virtual IntRect scrollableAreaBoundingBox() const OVERRIDE { return IntRect( ); }
138 virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) OVERRIDE { }
139 virtual void invalidateScrollCornerRect(const IntRect&) OVERRIDE { }
140 virtual bool userInputScrollable(ScrollbarOrientation) const OVERRIDE { retu rn true; }
141 virtual bool shouldPlaceVerticalScrollbarOnLeft() const OVERRIDE { return fa lse; }
142 virtual int pageStep(ScrollbarOrientation) const OVERRIDE { return 0; }
143 virtual IntPoint minimumScrollPosition() const OVERRIDE { return IntPoint(); }
144 virtual IntPoint maximumScrollPosition() const OVERRIDE
145 {
146 return IntPoint(contentsSize().width() - visibleWidth(), contentsSize(). height() - visibleHeight());
147 }
148
149 virtual void setScrollOffset(const IntPoint& scrollOffset) OVERRIDE { m_scro llPosition = scrollOffset; }
150 virtual IntPoint scrollPosition() const OVERRIDE { return m_scrollPosition; }
151
152 private:
153 IntPoint m_scrollPosition;
154 };
155
156 TEST_F(GraphicsLayerTest, applyScrollToScrollableArea)
157 {
158 FakeScrollableArea scrollableArea;
159 m_graphicsLayer->setScrollableArea(&scrollableArea, false);
160
161 WebPoint scrollPosition(7, 9);
162 m_platformLayer->setScrollPosition(scrollPosition);
163 m_graphicsLayer->didScroll();
164
165 EXPECT_EQ(scrollPosition, WebPoint(scrollableArea.scrollPosition()));
166 }
167
168 } // namespace
OLDNEW
« no previous file with comments | « Source/web/tests/FilterOperationsTest.cpp ('k') | Source/web/tests/ImageFilterBuilderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698