Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / graphics / ImageLayerChromiumTest.cpp
blob2e6f45d28ba966c2041a70083f70a7b69d830a55
1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
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 ANY
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 ON
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.
25 #include "config.h"
26 #include "platform/graphics/Image.h"
28 #include "platform/graphics/GraphicsLayer.h"
29 #include "third_party/skia/include/core/SkImage.h"
30 #include "third_party/skia/include/core/SkSurface.h"
31 #include "wtf/PassOwnPtr.h"
32 #include <gtest/gtest.h>
34 namespace blink {
36 namespace {
38 class MockGraphicsLayerClient : public GraphicsLayerClient {
39 public:
40 void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const IntRect&) override { }
41 String debugName(const GraphicsLayer*) override { return String(); }
44 class TestImage : public Image {
45 public:
46 static PassRefPtr<TestImage> create(const IntSize& size, bool isOpaque)
48 return adoptRef(new TestImage(size, isOpaque));
51 TestImage(const IntSize& size, bool isOpaque)
52 : Image(0)
53 , m_size(size)
55 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRaster(SkImageInfo::MakeN32(
56 size.width(), size.height(), isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType)));
57 if (!surface)
58 return;
60 surface->getCanvas()->clear(SK_ColorTRANSPARENT);
61 m_image = adoptRef(surface->newImageSnapshot());
64 bool isBitmapImage() const override
66 return true;
69 bool currentFrameKnownToBeOpaque() override
71 return m_image->isOpaque();
74 IntSize size() const override
76 return m_size;
79 PassRefPtr<SkImage> imageForCurrentFrame() override
81 return m_image;
84 // Stub implementations of pure virtual Image functions.
85 void destroyDecodedData(bool) override
89 void draw(SkCanvas*, const SkPaint&, const FloatRect&, const FloatRect&, RespectImageOrientationEnum, ImageClampingMode) override
93 private:
94 IntSize m_size;
95 RefPtr<SkImage> m_image;
98 class GraphicsLayerForTesting : public GraphicsLayer {
99 public:
100 explicit GraphicsLayerForTesting(GraphicsLayerClient* client)
101 : GraphicsLayer(client) { }
103 WebLayer* contentsLayer() const { return GraphicsLayer::contentsLayer(); }
106 } // anonymous namespace
108 TEST(ImageLayerChromiumTest, imageLayerContentReset)
110 MockGraphicsLayerClient client;
111 OwnPtr<GraphicsLayerForTesting> graphicsLayer = adoptPtr(new GraphicsLayerForTesting(&client));
112 ASSERT_TRUE(graphicsLayer.get());
114 ASSERT_FALSE(graphicsLayer->hasContentsLayer());
115 ASSERT_FALSE(graphicsLayer->contentsLayer());
117 RefPtr<Image> image = TestImage::create(IntSize(100, 100), false);
118 ASSERT_TRUE(image.get());
120 graphicsLayer->setContentsToImage(image.get());
121 ASSERT_TRUE(graphicsLayer->hasContentsLayer());
122 ASSERT_TRUE(graphicsLayer->contentsLayer());
124 graphicsLayer->setContentsToImage(0);
125 ASSERT_FALSE(graphicsLayer->hasContentsLayer());
126 ASSERT_FALSE(graphicsLayer->contentsLayer());
129 TEST(ImageLayerChromiumTest, opaqueImages)
131 MockGraphicsLayerClient client;
132 OwnPtr<GraphicsLayerForTesting> graphicsLayer = adoptPtr(new GraphicsLayerForTesting(&client));
133 ASSERT_TRUE(graphicsLayer.get());
135 RefPtr<Image> opaqueImage = TestImage::create(IntSize(100, 100), true /* opaque */);
136 ASSERT_TRUE(opaqueImage.get());
137 RefPtr<Image> nonOpaqueImage = TestImage::create(IntSize(100, 100), false /* opaque */);
138 ASSERT_TRUE(nonOpaqueImage.get());
140 ASSERT_FALSE(graphicsLayer->contentsLayer());
142 graphicsLayer->setContentsToImage(opaqueImage.get());
143 ASSERT_TRUE(graphicsLayer->contentsLayer()->opaque());
145 graphicsLayer->setContentsToImage(nonOpaqueImage.get());
146 ASSERT_FALSE(graphicsLayer->contentsLayer()->opaque());
149 } // namespace blink