Chromium Code Reviews| Index: components/wallpaper/pref_based_wallpaper_color_cache_unittest.cc |
| diff --git a/components/wallpaper/pref_based_wallpaper_color_cache_unittest.cc b/components/wallpaper/pref_based_wallpaper_color_cache_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..64a45793235bd47a415726283ebe7a1d558ecba3 |
| --- /dev/null |
| +++ b/components/wallpaper/pref_based_wallpaper_color_cache_unittest.cc |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2017 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 "components/wallpaper/pref_based_wallpaper_color_cache.h" |
| + |
| +#include <stdint.h> |
| + |
| +#include "components/prefs/testing_pref_service.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "third_party/skia/include/core/SkColor.h" |
| + |
| +namespace wallpaper { |
| + |
| +class PrefBasedWallpaperColorCacheTest : public testing::Test { |
| + public: |
| + PrefBasedWallpaperColorCacheTest(); |
| + ~PrefBasedWallpaperColorCacheTest() override; |
| + |
| + protected: |
| + PrefBasedWallpaperColorCache cache_; |
| + |
| + TestingPrefServiceSimple pref_service_; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(PrefBasedWallpaperColorCacheTest); |
| +}; |
| + |
| +PrefBasedWallpaperColorCacheTest::PrefBasedWallpaperColorCacheTest() |
| + : cache_(&pref_service_) { |
| + cache_.RegisterPrefs(pref_service_.registry()); |
| +} |
| + |
| +PrefBasedWallpaperColorCacheTest::~PrefBasedWallpaperColorCacheTest() {} |
| + |
| +TEST_F(PrefBasedWallpaperColorCacheTest, ValueNotInCache) { |
| + const uint32_t image_id = 10; |
| + SkColor color; |
| + EXPECT_FALSE(cache_.GetColor(image_id, &color)); |
| +} |
| + |
| +TEST_F(PrefBasedWallpaperColorCacheTest, ValueIsCached) { |
| + const uint32_t image_id = 10; |
| + cache_.SetColor(image_id, SK_ColorRED); |
| + |
| + SkColor color = SK_ColorBLACK; |
| + EXPECT_TRUE(cache_.GetColor(image_id, &color)); |
| + EXPECT_EQ(SK_ColorRED, color); |
| +} |
| + |
| +TEST_F(PrefBasedWallpaperColorCacheTest, CacheIsPurged) { |
| + const uint32_t image_1 = 1; |
| + const uint32_t image_2 = 2; |
| + |
| + cache_.SetColor(image_1, SK_ColorRED); |
| + cache_.SetColor(image_2, SK_ColorBLUE); |
| + |
| + SkColor color = SK_ColorBLACK; |
| + EXPECT_FALSE(cache_.GetColor(image_1, &color)); |
|
bshe
2017/03/28 21:33:26
why do you want to purge the cache? I imagine you
bruthig
2017/03/28 21:35:51
I don't plan to purge all entries in it. Some sho
bshe
2017/03/29 01:38:08
I see. Although from the unit test, it looks like
bruthig
2017/03/29 01:43:47
This test was written under the assumption the cac
|
| + EXPECT_TRUE(cache_.GetColor(image_2, &color)); |
| + EXPECT_EQ(SK_ColorRED, color); |
| +} |
| + |
| +TEST_F(PrefBasedWallpaperColorCacheTest, Foobar) { |
| + const uint32_t image_1 = 1; |
| + const uint32_t image_2 = 2; |
| + |
| + cache_.SetColor(image_1, SK_ColorRED); |
| + cache_.SetColor(image_2, SK_ColorBLUE); |
| +} |
| + |
| +} // namespace wallpaper |