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

Side by Side Diff: Source/platform/graphics/GraphicsLayerTest.cpp

Issue 1184673003: Fix unit test style in Source/platform/, part 2. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y 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 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 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 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 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */ 23 */
24 24
25 #include "config.h" 25 #include "config.h"
26
27 #include "platform/graphics/GraphicsLayer.h" 26 #include "platform/graphics/GraphicsLayer.h"
28 27
29 #include "platform/scroll/ScrollableArea.h" 28 #include "platform/scroll/ScrollableArea.h"
30 #include "platform/transforms/Matrix3DTransformOperation.h" 29 #include "platform/transforms/Matrix3DTransformOperation.h"
31 #include "platform/transforms/RotateTransformOperation.h" 30 #include "platform/transforms/RotateTransformOperation.h"
32 #include "platform/transforms/TranslateTransformOperation.h" 31 #include "platform/transforms/TranslateTransformOperation.h"
33 #include "public/platform/Platform.h" 32 #include "public/platform/Platform.h"
34 #include "public/platform/WebCompositorSupport.h" 33 #include "public/platform/WebCompositorSupport.h"
35 #include "public/platform/WebFloatAnimationCurve.h" 34 #include "public/platform/WebFloatAnimationCurve.h"
36 #include "public/platform/WebGraphicsContext3D.h" 35 #include "public/platform/WebGraphicsContext3D.h"
37 #include "public/platform/WebLayer.h" 36 #include "public/platform/WebLayer.h"
38 #include "public/platform/WebLayerTreeView.h" 37 #include "public/platform/WebLayerTreeView.h"
39 #include "public/platform/WebUnitTestSupport.h" 38 #include "public/platform/WebUnitTestSupport.h"
40 #include "wtf/PassOwnPtr.h" 39 #include "wtf/PassOwnPtr.h"
41
42 #include <gtest/gtest.h> 40 #include <gtest/gtest.h>
43 41
44 using namespace blink; 42 namespace blink {
45 43
46 namespace { 44 namespace {
47 45
48 class MockGraphicsLayerClient : public GraphicsLayerClient { 46 class MockGraphicsLayerClient : public GraphicsLayerClient {
49 public: 47 public:
50 virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsL ayerPaintingPhase, const IntRect& inClip) override { } 48 void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPain tingPhase, const IntRect& inClip) override { }
51 virtual String debugName(const GraphicsLayer*) override { return String(); } 49 String debugName(const GraphicsLayer*) override { return String(); }
52 }; 50 };
53 51
54 class GraphicsLayerForTesting : public GraphicsLayer { 52 class GraphicsLayerForTesting : public GraphicsLayer {
55 public: 53 public:
56 explicit GraphicsLayerForTesting(GraphicsLayerClient* client) 54 explicit GraphicsLayerForTesting(GraphicsLayerClient* client)
57 : GraphicsLayer(client) { }; 55 : GraphicsLayer(client) { };
58 56
59 virtual WebLayer* contentsLayer() const { return GraphicsLayer::contentsLaye r(); } 57 WebLayer* contentsLayer() const override { return GraphicsLayer::contentsLay er(); }
60 }; 58 };
61 59
60 } // anonymous namespace
61
62 class GraphicsLayerTest : public testing::Test { 62 class GraphicsLayerTest : public testing::Test {
63 public: 63 public:
64 GraphicsLayerTest() 64 GraphicsLayerTest()
65 { 65 {
66 m_clipLayer = adoptPtr(new GraphicsLayerForTesting(&m_client)); 66 m_clipLayer = adoptPtr(new GraphicsLayerForTesting(&m_client));
67 m_scrollElasticityLayer = adoptPtr(new GraphicsLayerForTesting(&m_client )); 67 m_scrollElasticityLayer = adoptPtr(new GraphicsLayerForTesting(&m_client ));
68 m_graphicsLayer = adoptPtr(new GraphicsLayerForTesting(&m_client)); 68 m_graphicsLayer = adoptPtr(new GraphicsLayerForTesting(&m_client));
69 m_clipLayer->addChild(m_scrollElasticityLayer.get()); 69 m_clipLayer->addChild(m_scrollElasticityLayer.get());
70 m_scrollElasticityLayer->addChild(m_graphicsLayer.get()); 70 m_scrollElasticityLayer->addChild(m_graphicsLayer.get());
71 m_graphicsLayer->platformLayer()->setScrollClipLayer( 71 m_graphicsLayer->platformLayer()->setScrollClipLayer(
72 m_clipLayer->platformLayer()); 72 m_clipLayer->platformLayer());
73 m_platformLayer = m_graphicsLayer->platformLayer(); 73 m_platformLayer = m_graphicsLayer->platformLayer();
74 m_layerTreeView = adoptPtr(Platform::current()->unitTestSupport()->creat eLayerTreeViewForTesting()); 74 m_layerTreeView = adoptPtr(Platform::current()->unitTestSupport()->creat eLayerTreeViewForTesting());
75 ASSERT(m_layerTreeView); 75 ASSERT(m_layerTreeView);
76 m_layerTreeView->setRootLayer(*m_clipLayer->platformLayer()); 76 m_layerTreeView->setRootLayer(*m_clipLayer->platformLayer());
77 m_layerTreeView->registerViewportLayers( 77 m_layerTreeView->registerViewportLayers(
78 m_scrollElasticityLayer->platformLayer(), m_clipLayer->platformLayer (), m_graphicsLayer->platformLayer(), 0); 78 m_scrollElasticityLayer->platformLayer(), m_clipLayer->platformLayer (), m_graphicsLayer->platformLayer(), 0);
79 m_layerTreeView->setViewportSize(WebSize(1, 1)); 79 m_layerTreeView->setViewportSize(WebSize(1, 1));
80 } 80 }
81 81
82 virtual ~GraphicsLayerTest() 82 ~GraphicsLayerTest() override
83 { 83 {
84 m_graphicsLayer.clear(); 84 m_graphicsLayer.clear();
85 m_layerTreeView.clear(); 85 m_layerTreeView.clear();
86 } 86 }
87 87
88 protected: 88 protected:
89 WebLayer* m_platformLayer; 89 WebLayer* m_platformLayer;
90 OwnPtr<GraphicsLayerForTesting> m_graphicsLayer; 90 OwnPtr<GraphicsLayerForTesting> m_graphicsLayer;
91 OwnPtr<GraphicsLayerForTesting> m_scrollElasticityLayer; 91 OwnPtr<GraphicsLayerForTesting> m_scrollElasticityLayer;
92 OwnPtr<GraphicsLayerForTesting> m_clipLayer; 92 OwnPtr<GraphicsLayerForTesting> m_clipLayer;
(...skipping 27 matching lines...) Expand all
120 m_graphicsLayer->setShouldFlattenTransform(true); 120 m_graphicsLayer->setShouldFlattenTransform(true);
121 121
122 m_platformLayer = m_graphicsLayer->platformLayer(); 122 m_platformLayer = m_graphicsLayer->platformLayer();
123 ASSERT_TRUE(m_platformLayer); 123 ASSERT_TRUE(m_platformLayer);
124 124
125 ASSERT_FALSE(m_platformLayer->hasActiveAnimation()); 125 ASSERT_FALSE(m_platformLayer->hasActiveAnimation());
126 } 126 }
127 127
128 class FakeScrollableArea : public ScrollableArea { 128 class FakeScrollableArea : public ScrollableArea {
129 public: 129 public:
130 virtual bool isActive() const override { return false; } 130 bool isActive() const override { return false; }
131 virtual int scrollSize(ScrollbarOrientation) const override { return 100; } 131 int scrollSize(ScrollbarOrientation) const override { return 100; }
132 virtual bool isScrollCornerVisible() const override { return false; } 132 bool isScrollCornerVisible() const override { return false; }
133 virtual IntRect scrollCornerRect() const override { return IntRect(); } 133 IntRect scrollCornerRect() const override { return IntRect(); }
134 virtual int visibleWidth() const override { return 10; } 134 int visibleWidth() const override { return 10; }
135 virtual int visibleHeight() const override { return 10; } 135 int visibleHeight() const override { return 10; }
136 virtual IntSize contentsSize() const override { return IntSize(100, 100); } 136 IntSize contentsSize() const override { return IntSize(100, 100); }
137 virtual bool scrollbarsCanBeActive() const override { return false; } 137 bool scrollbarsCanBeActive() const override { return false; }
138 virtual IntRect scrollableAreaBoundingBox() const override { return IntRect( ); } 138 IntRect scrollableAreaBoundingBox() const override { return IntRect(); }
139 virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) override { } 139 void invalidateScrollbarRect(Scrollbar*, const IntRect&) override { }
140 virtual void invalidateScrollCornerRect(const IntRect&) override { } 140 void invalidateScrollCornerRect(const IntRect&) override { }
141 virtual bool userInputScrollable(ScrollbarOrientation) const override { retu rn true; } 141 bool userInputScrollable(ScrollbarOrientation) const override { return true; }
142 virtual bool shouldPlaceVerticalScrollbarOnLeft() const override { return fa lse; } 142 bool shouldPlaceVerticalScrollbarOnLeft() const override { return false; }
143 virtual int pageStep(ScrollbarOrientation) const override { return 0; } 143 int pageStep(ScrollbarOrientation) const override { return 0; }
144 virtual IntPoint minimumScrollPosition() const override { return IntPoint(); } 144 IntPoint minimumScrollPosition() const override { return IntPoint(); }
145 virtual IntPoint maximumScrollPosition() const override 145 IntPoint maximumScrollPosition() const override
146 { 146 {
147 return IntPoint(contentsSize().width() - visibleWidth(), contentsSize(). height() - visibleHeight()); 147 return IntPoint(contentsSize().width() - visibleWidth(), contentsSize(). height() - visibleHeight());
148 } 148 }
149 149
150 virtual void setScrollOffset(const IntPoint& scrollOffset, ScrollType) overr ide { m_scrollPosition = scrollOffset; } 150 void setScrollOffset(const IntPoint& scrollOffset, ScrollType) override { m_ scrollPosition = scrollOffset; }
151 virtual void setScrollOffset(const DoublePoint& scrollOffset, ScrollType) ov erride { m_scrollPosition = scrollOffset; } 151 void setScrollOffset(const DoublePoint& scrollOffset, ScrollType) override { m_scrollPosition = scrollOffset; }
152 virtual DoublePoint scrollPositionDouble() const override { return m_scrollP osition; } 152 DoublePoint scrollPositionDouble() const override { return m_scrollPosition; }
153 virtual IntPoint scrollPosition() const override { return flooredIntPoint(m_ scrollPosition); } 153 IntPoint scrollPosition() const override { return flooredIntPoint(m_scrollPo sition); }
154 154
155 private: 155 private:
156 DoublePoint m_scrollPosition; 156 DoublePoint m_scrollPosition;
157 }; 157 };
158 158
159 TEST_F(GraphicsLayerTest, applyScrollToScrollableArea) 159 TEST_F(GraphicsLayerTest, applyScrollToScrollableArea)
160 { 160 {
161 FakeScrollableArea scrollableArea; 161 FakeScrollableArea scrollableArea;
162 m_graphicsLayer->setScrollableArea(&scrollableArea, false); 162 m_graphicsLayer->setScrollableArea(&scrollableArea, false);
163 163
164 WebDoublePoint scrollPosition(7, 9); 164 WebDoublePoint scrollPosition(7, 9);
165 m_platformLayer->setScrollPositionDouble(scrollPosition); 165 m_platformLayer->setScrollPositionDouble(scrollPosition);
166 m_graphicsLayer->didScroll(); 166 m_graphicsLayer->didScroll();
167 167
168 EXPECT_FLOAT_EQ(scrollPosition.x, scrollableArea.scrollPositionDouble().x()) ; 168 EXPECT_FLOAT_EQ(scrollPosition.x, scrollableArea.scrollPositionDouble().x()) ;
169 EXPECT_FLOAT_EQ(scrollPosition.y, scrollableArea.scrollPositionDouble().y()) ; 169 EXPECT_FLOAT_EQ(scrollPosition.y, scrollableArea.scrollPositionDouble().y()) ;
170 } 170 }
171 171
172 } // namespace 172 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698