Chromium Code Reviews| Index: blimp/engine/renderer/blimp_engine_picture_cache_unittest.cc |
| diff --git a/blimp/engine/renderer/blimp_engine_picture_cache_unittest.cc b/blimp/engine/renderer/blimp_engine_picture_cache_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..aa9787ac56299c127d5b196b082296c7db37d53d |
| --- /dev/null |
| +++ b/blimp/engine/renderer/blimp_engine_picture_cache_unittest.cc |
| @@ -0,0 +1,60 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "blimp/engine/renderer/blimp_engine_picture_cache.h" |
| + |
| +#include "blimp/test/support/compositor/picture_cache_test_support.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "third_party/skia/include/core/SkColor.h" |
| +#include "third_party/skia/include/core/SkPicture.h" |
| +#include "third_party/skia/include/core/SkRefCnt.h" |
| + |
| +namespace blimp { |
| +namespace engine { |
| +namespace { |
| + |
| +class BlimpEnginePictureCacheTest : public testing::Test { |
| + public: |
| + BlimpEnginePictureCacheTest() : cache_(nullptr) {} |
| + |
| + protected: |
| + BlimpEnginePictureCache cache_; |
|
Kevin M
2016/06/11 00:29:33
DISALLOW_COPY_AND_ASSIGN
nyquist
2016/06/14 01:37:57
Done.
|
| +}; |
| + |
| +MATCHER_P(PictureMatches, picture, "") { |
| + return SamePicture(picture, arg); |
| +} |
| + |
| +TEST_F(BlimpEnginePictureCacheTest, TwoCachedPicturesCanBeRetrieved) { |
| + EXPECT_TRUE(cache_.CalculateCacheUpdateAndFlush().empty()); |
| + |
| + sk_sp<const SkPicture> picture1 = CreateSkPicture(SK_ColorBLUE); |
| + cache_.MarkPictureForRegistration(picture1.get()); |
| + sk_sp<const SkPicture> picture2 = CreateSkPicture(SK_ColorRED); |
| + cache_.MarkPictureForRegistration(picture2.get()); |
| + |
| + cc::PictureCacheUpdate update = cache_.CalculateCacheUpdateAndFlush(); |
| + ASSERT_EQ(2U, update.size()); |
| + EXPECT_THAT(update, testing::UnorderedElementsAre(PictureMatches(picture1), |
| + PictureMatches(picture2))); |
| + |
| + EXPECT_TRUE(cache_.CalculateCacheUpdateAndFlush().empty()); |
| +} |
| + |
| +TEST_F(BlimpEnginePictureCacheTest, SamePictureOnlyReturnedOnce) { |
| + EXPECT_TRUE(cache_.CalculateCacheUpdateAndFlush().empty()); |
| + |
| + sk_sp<const SkPicture> picture = CreateSkPicture(SK_ColorBLUE); |
| + cache_.MarkPictureForRegistration(picture.get()); |
| + cache_.MarkPictureForRegistration(picture.get()); |
| + |
| + cc::PictureCacheUpdate update = cache_.CalculateCacheUpdateAndFlush(); |
| + ASSERT_EQ(1U, update.size()); |
| + EXPECT_THAT(update, testing::UnorderedElementsAre(PictureMatches(picture))); |
| +} |
| + |
| +} // namespace |
| +} // namespace engine |
| +} // namespace blimp |