Commit f08835e6 authored by Brandon Wylie's avatar Brandon Wylie Committed by Commit Bot

[IC] Add unit test for null callback behavior that was previously fixed

The bug was fixed, but I didn't add a unittest. This unittest will
cover the case fixed in 1351534.

Bug: 909735
Change-Id: Ie9337b301abcd7717c0719741d9e8d58adafade0
Reviewed-on: https://chromium-review.googlesource.com/c/1358922Reviewed-by: default avatarSky Malice <skym@chromium.org>
Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Commit-Queue: Brandon Wylie <wylieb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613380}
parent 1c18d077
...@@ -36,6 +36,7 @@ constexpr char kCachedImageFetcherEventHistogramName[] = ...@@ -36,6 +36,7 @@ constexpr char kCachedImageFetcherEventHistogramName[] =
constexpr char kImageUrl[] = "http://gstatic.img.com/foo.jpg"; constexpr char kImageUrl[] = "http://gstatic.img.com/foo.jpg";
constexpr char kImageUrlHashed[] = "3H7UODDH3WKDWK6FQ3IZT3LQMVBPYJ4M"; constexpr char kImageUrlHashed[] = "3H7UODDH3WKDWK6FQ3IZT3LQMVBPYJ4M";
constexpr char kImageData[] = "data"; constexpr char kImageData[] = "data";
const int kOverMaxCacheSize = 65 * 1024 * 1024;
} // namespace } // namespace
...@@ -97,6 +98,17 @@ class ImageCacheTest : public testing::Test { ...@@ -97,6 +98,17 @@ class ImageCacheTest : public testing::Test {
RunUntilIdle(); RunUntilIdle();
} }
void RunEvictionWhenFull(bool success) {
image_cache()->RunEvictionWhenFull();
if (success) {
db()->LoadCallback(true);
db()->UpdateCallback(true);
}
RunUntilIdle();
}
bool IsMetadataPresent(const std::string& key) { bool IsMetadataPresent(const std::string& key) {
return db_store_.find(key) != db_store_.end(); return db_store_.find(key) != db_store_.end();
} }
...@@ -291,6 +303,20 @@ TEST_F(ImageCacheTest, Eviction) { ...@@ -291,6 +303,20 @@ TEST_F(ImageCacheTest, Eviction) {
CachedImageFetcherEvent::kCacheStartupEvictionFinished, 1); CachedImageFetcherEvent::kCacheStartupEvictionFinished, 1);
} }
TEST_F(ImageCacheTest, EvictionWhenFull) {
PrepareImageCache();
InjectMetadata(kImageUrl, kOverMaxCacheSize);
clock()->SetNow(clock()->Now() + base::TimeDelta::FromDays(6));
RunEvictionWhenFull(/* success */ true);
// The data should be removed because it's over the allowed limit.
EXPECT_CALL(*this, DataCallback(""));
image_cache()->LoadImage(
false, kImageUrl,
base::BindOnce(&ImageCacheTest::DataCallback, base::Unretained(this)));
RunUntilIdle();
}
TEST_F(ImageCacheTest, EvictionTooSoon) { TEST_F(ImageCacheTest, EvictionTooSoon) {
PrepareImageCache(); PrepareImageCache();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment