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

Side by Side Diff: Source/web/tests/ImageLayerChromiumTest.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
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2011 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 <gtest/gtest.h>
28 #include "platform/graphics/GraphicsLayer.h"
29 #include "platform/graphics/Image.h"
30 #include "platform/graphics/skia/NativeImageSkia.h"
31 #include "public/platform/WebImageLayer.h"
32 #include "wtf/PassOwnPtr.h"
33
34 using namespace WebCore;
35
36 namespace {
37
38 class MockGraphicsLayerClient : public GraphicsLayerClient {
39 public:
40 virtual void notifyAnimationStarted(const GraphicsLayer*, double monotonicTi me) OVERRIDE { }
41 virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsL ayerPaintingPhase, const IntRect& inClip) OVERRIDE { }
42 virtual String debugName(const GraphicsLayer*) OVERRIDE { return String(); }
43 };
44
45 class TestImage : public Image {
46 public:
47
48 static PassRefPtr<TestImage> create(const IntSize& size, bool isOpaque)
49 {
50 return adoptRef(new TestImage(size, isOpaque));
51 }
52
53 explicit TestImage(const IntSize& size, bool isOpaque)
54 : Image(0)
55 , m_size(size)
56 {
57 m_nativeImage = NativeImageSkia::create();
58 EXPECT_TRUE(m_nativeImage->bitmap().allocN32Pixels(size.width(), size.he ight(), isOpaque));
59 }
60
61 virtual bool isBitmapImage() const OVERRIDE
62 {
63 return true;
64 }
65
66 virtual bool currentFrameKnownToBeOpaque() OVERRIDE
67 {
68 return m_nativeImage->bitmap().isOpaque();
69 }
70
71 virtual IntSize size() const OVERRIDE
72 {
73 return m_size;
74 }
75
76 virtual PassRefPtr<NativeImageSkia> nativeImageForCurrentFrame() OVERRIDE
77 {
78 if (m_size.isZero())
79 return nullptr;
80
81 return m_nativeImage;
82 }
83
84 // Stub implementations of pure virtual Image functions.
85 virtual void destroyDecodedData(bool) OVERRIDE
86 {
87 }
88
89 virtual void draw(GraphicsContext*, const FloatRect&, const FloatRect&, Comp ositeOperator, blink::WebBlendMode) OVERRIDE
90 {
91 }
92
93 private:
94
95 IntSize m_size;
96
97 RefPtr<NativeImageSkia> m_nativeImage;
98 };
99
100 class GraphicsLayerForTesting : public GraphicsLayer {
101 public:
102 explicit GraphicsLayerForTesting(GraphicsLayerClient* client)
103 : GraphicsLayer(client) { };
104
105 virtual blink::WebLayer* contentsLayer() const { return GraphicsLayer::conte ntsLayer(); }
106 };
107
108 TEST(ImageLayerChromiumTest, opaqueImages)
109 {
110 MockGraphicsLayerClient client;
111 OwnPtr<GraphicsLayerForTesting> graphicsLayer = adoptPtr(new GraphicsLayerFo rTesting(&client));
112 ASSERT_TRUE(graphicsLayer.get());
113
114 RefPtr<Image> opaqueImage = TestImage::create(IntSize(100, 100), true /* opa que */);
115 ASSERT_TRUE(opaqueImage.get());
116 RefPtr<Image> nonOpaqueImage = TestImage::create(IntSize(100, 100), false /* opaque */);
117 ASSERT_TRUE(nonOpaqueImage.get());
118
119 ASSERT_FALSE(graphicsLayer->contentsLayer());
120
121 graphicsLayer->setContentsToImage(opaqueImage.get());
122 ASSERT_TRUE(graphicsLayer->contentsLayer()->opaque());
123
124 graphicsLayer->setContentsToImage(nonOpaqueImage.get());
125 ASSERT_FALSE(graphicsLayer->contentsLayer()->opaque());
126 }
127
128 } // namespace
OLDNEW
« no previous file with comments | « Source/web/tests/ImageFilterBuilderTest.cpp ('k') | Source/web/tests/OpaqueRectTrackingContentLayerDelegateTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698