Chromium Code Reviews| Index: ios/chrome/browser/snapshots/snapshot_cache_unittest.mm |
| diff --git a/ios/chrome/browser/snapshots/snapshot_cache_unittest.mm b/ios/chrome/browser/snapshots/snapshot_cache_unittest.mm |
| index c77a9ae94f56d7d2b24d2c93758101c6001a9901..42b45cad54ce113cedf4d623ee5f639a8ae5e025 100644 |
| --- a/ios/chrome/browser/snapshots/snapshot_cache_unittest.mm |
| +++ b/ios/chrome/browser/snapshots/snapshot_cache_unittest.mm |
| @@ -16,6 +16,7 @@ |
| #include "base/run_loop.h" |
| #include "base/strings/sys_string_conversions.h" |
| #include "base/time/time.h" |
| +#include "ios/chrome/browser/experimental_flags.h" |
| #include "ios/chrome/browser/ui/ui_util.h" |
| #include "ios/web/public/test/test_web_thread_bundle.h" |
| #include "ios/web/public/web_thread.h" |
| @@ -40,11 +41,19 @@ static const NSUInteger kSnapshotPixelSize = 8; |
| @implementation SnapshotCache (TestingAdditions) |
|
sdefresne
2015/11/03 11:25:19
Please avoid adding methods to the class in the te
jbbegue
2015/11/03 13:37:19
Done.
|
| - (BOOL)hasImageInMemory:(NSString*)sessionID { |
| - return [imageDictionary_ objectForKey:sessionID] != nil; |
| + if (experimental_flags::IsLRUSnapshotCacheEnabled()) |
| + return [lruCache_ objectForKey:sessionID] != nil; |
| + else |
| + return [imageDictionary_ objectForKey:sessionID] != nil; |
| } |
| - (BOOL)hasGreyImageInMemory:(NSString*)sessionID { |
| return [greyImageDictionary_ objectForKey:sessionID] != nil; |
| } |
| + |
| +- (NSUInteger)lruCacheMaxSize { |
| + return [lruCache_ maxCacheSize]; |
| +} |
| + |
| @end |
| namespace { |
| @@ -235,8 +244,12 @@ TEST_F(SnapshotCacheTest, Cache) { |
| SnapshotCache* cache = GetSnapshotCache(); |
| + NSUInteger expectedCacheSize = kSessionCount; |
| + if (experimental_flags::IsLRUSnapshotCacheEnabled()) |
| + expectedCacheSize = MIN(kSessionCount, [cache lruCacheMaxSize]); |
| + |
| // Put all images in the cache. |
| - for (NSUInteger i = 0; i < kSessionCount; ++i) { |
| + for (NSUInteger i = 0; i < expectedCacheSize; ++i) { |
| UIImage* image = [testImages_ objectAtIndex:i]; |
| NSString* sessionID = [testSessions_ objectAtIndex:i]; |
| [cache setImage:image withSessionID:sessionID]; |
| @@ -244,7 +257,7 @@ TEST_F(SnapshotCacheTest, Cache) { |
| // Get images back. |
| __block NSUInteger numberOfCallbacks = 0; |
| - for (NSUInteger i = 0; i < kSessionCount; ++i) { |
| + for (NSUInteger i = 0; i < expectedCacheSize; ++i) { |
| NSString* sessionID = [testSessions_ objectAtIndex:i]; |
| UIImage* expectedImage = [testImages_ objectAtIndex:i]; |
| EXPECT_TRUE(expectedImage != nil); |
| @@ -256,7 +269,7 @@ TEST_F(SnapshotCacheTest, Cache) { |
| ++numberOfCallbacks; |
| }]; |
| } |
| - EXPECT_EQ(kSessionCount, numberOfCallbacks); |
| + EXPECT_EQ(MIN(expectedCacheSize, [cache lruCacheMaxSize]), numberOfCallbacks); |
| } |
| // This test puts all the snapshots in the cache and flushes them to disk. |