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 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef MockImageDecoder_h 27 28 #include "core/platform/image-decoders/ImageDecoder.h" 29 #include "wtf/PassOwnPtr.h" 30 31 namespace WebCore { 32 33 class MockImageDecoderClient { 34 public: 35 virtual void decoderBeingDestroyed() = 0; 36 virtual void frameBufferRequested() = 0; 37 virtual ImageFrame::FrameStatus frameStatus() = 0; 38 virtual size_t frameCount() = 0; 39 virtual int repetitionCount() const = 0; 40 virtual float frameDuration() const = 0; 41 }; 42 43 class MockImageDecoder : public ImageDecoder { 44 public: 45 static PassOwnPtr<MockImageDecoder> create(MockImageDecoderClient* client) { return adoptPtr(new MockImageDecoder(client)); } 46 47 MockImageDecoder(MockImageDecoderClient* client) 48 : ImageDecoder(ImageSource::AlphaPremultiplied, ImageSource::GammaAndColorProfileApplied) 49 , m_client(client) 50 { } 51 52 ~MockImageDecoder() 53 { 54 m_client->decoderBeingDestroyed(); 55 } 56 57 virtual bool setSize(unsigned width, unsigned height) 58 { 59 ImageDecoder::setSize(width, height); 60 m_frameBufferCache.resize(1); 61 m_frameBufferCache[0].setSize(width, height); 62 return true; 63 } 64 65 virtual void setFrameHasAlpha(bool hasAlpha) { m_frameBufferCache[0].setHasAlpha(hasAlpha); } 66 67 virtual String filenameExtension() const 68 { 69 return "mock"; 70 } 71 72 virtual size_t frameCount() 73 { 74 return m_client->frameCount(); 75 } 76 77 virtual int repetitionCount() const 78 { 79 return m_client->repetitionCount(); 80 } 81 82 virtual ImageFrame* frameBufferAtIndex(size_t) 83 { 84 m_client->frameBufferRequested(); 85 86 m_frameBufferCache[0].setStatus(m_client->frameStatus()); 87 return &m_frameBufferCache[0]; 88 } 89 90 virtual bool frameIsCompleteAtIndex(size_t) const 91 { 92 return m_client->frameStatus() == ImageFrame::FrameComplete; 93 } 94 95 virtual float frameDurationAtIndex(size_t) const 96 { 97 return m_client->frameDuration(); 98 } 99 100 private: 101 MockImageDecoderClient* m_client; 102 }; 103 104 } // namespace WebCore 105 106 #endif // MockImageDecoder_h 107