| OLD | NEW |
| 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 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 85 |
| 86 protected: | 86 protected: |
| 87 void useMockImageDecoderFactory() | 87 void useMockImageDecoderFactory() |
| 88 { | 88 { |
| 89 m_generator->setImageDecoderFactory(MockImageDecoderFactory::create(this
, fullSize())); | 89 m_generator->setImageDecoderFactory(MockImageDecoderFactory::create(this
, fullSize())); |
| 90 } | 90 } |
| 91 | 91 |
| 92 PassOwnPtr<ScaledImageFragment> createCompleteImage(const SkISize& size) | 92 PassOwnPtr<ScaledImageFragment> createCompleteImage(const SkISize& size) |
| 93 { | 93 { |
| 94 SkBitmap bitmap; | 94 SkBitmap bitmap; |
| 95 bitmap.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height(
)); | 95 if (!bitmap.allocN32Pixels(size.width(), size.height())) |
| 96 bitmap.allocPixels(); | 96 return nullptr; |
| 97 return ScaledImageFragment::createComplete(size, 0, bitmap); | 97 return ScaledImageFragment::createComplete(size, 0, bitmap); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void addNewData() | 100 void addNewData() |
| 101 { | 101 { |
| 102 m_data->append("g", 1); | 102 m_data->append("g", 1); |
| 103 m_generator->setData(m_data, false); | 103 m_generator->setData(m_data, false); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void setFrameStatus(ImageFrame::Status status) { m_status = m_nextFrameStat
us = status; } | 106 void setFrameStatus(ImageFrame::Status status) { m_status = m_nextFrameStat
us = status; } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 123 RefPtr<SharedBuffer> m_data; | 123 RefPtr<SharedBuffer> m_data; |
| 124 RefPtr<ImageFrameGenerator> m_generator; | 124 RefPtr<ImageFrameGenerator> m_generator; |
| 125 int m_decodersDestroyed; | 125 int m_decodersDestroyed; |
| 126 int m_frameBufferRequestCount; | 126 int m_frameBufferRequestCount; |
| 127 ImageFrame::Status m_status; | 127 ImageFrame::Status m_status; |
| 128 ImageFrame::Status m_nextFrameStatus; | 128 ImageFrame::Status m_nextFrameStatus; |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 TEST_F(ImageFrameGeneratorTest, cacheHit) | 131 TEST_F(ImageFrameGeneratorTest, cacheHit) |
| 132 { | 132 { |
| 133 OwnPtr<ScaledImageFragment> completeImageTemp = createCompleteImage(fullSize
()); |
| 134 ASSERT_TRUE(completeImageTemp); |
| 133 const ScaledImageFragment* fullImage = ImageDecodingStore::instance()->inser
tAndLockCache( | 135 const ScaledImageFragment* fullImage = ImageDecodingStore::instance()->inser
tAndLockCache( |
| 134 m_generator.get(), createCompleteImage(fullSize())); | 136 m_generator.get(), completeImageTemp.release()); |
| 135 EXPECT_EQ(fullSize(), fullImage->scaledSize()); | 137 EXPECT_EQ(fullSize(), fullImage->scaledSize()); |
| 136 ImageDecodingStore::instance()->unlockCache(m_generator.get(), fullImage); | 138 ImageDecodingStore::instance()->unlockCache(m_generator.get(), fullImage); |
| 137 | 139 |
| 138 const ScaledImageFragment* tempImage = m_generator->decodeAndScale(fullSize(
)); | 140 const ScaledImageFragment* tempImage = m_generator->decodeAndScale(fullSize(
)); |
| 139 EXPECT_EQ(fullImage, tempImage); | 141 EXPECT_EQ(fullImage, tempImage); |
| 140 EXPECT_EQ(fullSize(), tempImage->scaledSize()); | 142 EXPECT_EQ(fullSize(), tempImage->scaledSize()); |
| 141 EXPECT_TRUE(m_generator->hasAlpha(0)); | 143 EXPECT_TRUE(m_generator->hasAlpha(0)); |
| 142 ImageDecodingStore::instance()->unlockCache(m_generator.get(), tempImage); | 144 ImageDecodingStore::instance()->unlockCache(m_generator.get(), tempImage); |
| 143 EXPECT_EQ(0, m_frameBufferRequestCount); | 145 EXPECT_EQ(0, m_frameBufferRequestCount); |
| 144 } | 146 } |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 // We have tested failures of all stages. This time all allocations | 326 // We have tested failures of all stages. This time all allocations |
| 325 // were successful. | 327 // were successful. |
| 326 EXPECT_TRUE(image); | 328 EXPECT_TRUE(image); |
| 327 break; | 329 break; |
| 328 } | 330 } |
| 329 EXPECT_FALSE(image); | 331 EXPECT_FALSE(image); |
| 330 } | 332 } |
| 331 } | 333 } |
| 332 | 334 |
| 333 } // namespace WebCore | 335 } // namespace WebCore |
| OLD | NEW |