| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/snapshots/snapshot_cache.h" | 5 #import "ios/chrome/browser/snapshots/snapshot_cache.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 base::scoped_nsobject<NSMutableArray> testSessions_; | 211 base::scoped_nsobject<NSMutableArray> testSessions_; |
| 212 base::scoped_nsobject<NSMutableArray> testImages_; | 212 base::scoped_nsobject<NSMutableArray> testImages_; |
| 213 }; | 213 }; |
| 214 | 214 |
| 215 // This test simply put all the snapshots in the cache and then gets them back | 215 // This test simply put all the snapshots in the cache and then gets them back |
| 216 // As the snapshots are kept in memory, the same pointer can be retrieved. | 216 // As the snapshots are kept in memory, the same pointer can be retrieved. |
| 217 // This test also checks that images are correctly removed from the disk. | 217 // This test also checks that images are correctly removed from the disk. |
| 218 TEST_F(SnapshotCacheTest, Cache) { | 218 TEST_F(SnapshotCacheTest, Cache) { |
| 219 SnapshotCache* cache = GetSnapshotCache(); | 219 SnapshotCache* cache = GetSnapshotCache(); |
| 220 | 220 |
| 221 if (![cache inMemoryCacheIsEnabled]) | |
| 222 return; | |
| 223 | |
| 224 NSUInteger expectedCacheSize = kSessionCount; | 221 NSUInteger expectedCacheSize = kSessionCount; |
| 225 if ([cache usesLRUCache]) | 222 if ([cache usesLRUCache]) |
| 226 expectedCacheSize = MIN(kSessionCount, [cache lruCacheMaxSize]); | 223 expectedCacheSize = MIN(kSessionCount, [cache lruCacheMaxSize]); |
| 227 | 224 |
| 228 // Put all images in the cache. | 225 // Put all images in the cache. |
| 229 for (NSUInteger i = 0; i < expectedCacheSize; ++i) { | 226 for (NSUInteger i = 0; i < expectedCacheSize; ++i) { |
| 230 UIImage* image = [testImages_ objectAtIndex:i]; | 227 UIImage* image = [testImages_ objectAtIndex:i]; |
| 231 NSString* sessionID = [testSessions_ objectAtIndex:i]; | 228 NSString* sessionID = [testSessions_ objectAtIndex:i]; |
| 232 [cache setImage:image withSessionID:sessionID]; | 229 [cache setImage:image withSessionID:sessionID]; |
| 233 } | 230 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 | 351 |
| 355 NSString* firstPinnedID = [testSessions_ objectAtIndex:4]; | 352 NSString* firstPinnedID = [testSessions_ objectAtIndex:4]; |
| 356 NSString* secondPinnedID = [testSessions_ objectAtIndex:6]; | 353 NSString* secondPinnedID = [testSessions_ objectAtIndex:6]; |
| 357 NSMutableSet* set = [NSMutableSet set]; | 354 NSMutableSet* set = [NSMutableSet set]; |
| 358 [set addObject:firstPinnedID]; | 355 [set addObject:firstPinnedID]; |
| 359 [set addObject:secondPinnedID]; | 356 [set addObject:secondPinnedID]; |
| 360 cache.pinnedIDs = set; | 357 cache.pinnedIDs = set; |
| 361 | 358 |
| 362 TriggerMemoryWarning(); | 359 TriggerMemoryWarning(); |
| 363 | 360 |
| 364 if ([cache inMemoryCacheIsEnabled]) { | 361 EXPECT_EQ(YES, [cache hasImageInMemory:firstPinnedID]); |
| 365 EXPECT_EQ(YES, [cache hasImageInMemory:firstPinnedID]); | 362 EXPECT_EQ(YES, [cache hasImageInMemory:secondPinnedID]); |
| 366 EXPECT_EQ(YES, [cache hasImageInMemory:secondPinnedID]); | |
| 367 } else { | |
| 368 EXPECT_EQ(NO, [cache hasImageInMemory:firstPinnedID]); | |
| 369 EXPECT_EQ(NO, [cache hasImageInMemory:secondPinnedID]); | |
| 370 } | |
| 371 | 363 |
| 372 NSString* notPinnedID = [testSessions_ objectAtIndex:2]; | 364 NSString* notPinnedID = [testSessions_ objectAtIndex:2]; |
| 373 EXPECT_FALSE([cache hasImageInMemory:notPinnedID]); | 365 EXPECT_FALSE([cache hasImageInMemory:notPinnedID]); |
| 374 | 366 |
| 375 // Wait for the final image to be pulled off disk. | 367 // Wait for the final image to be pulled off disk. |
| 376 FlushRunLoops(); | 368 FlushRunLoops(); |
| 377 } | 369 } |
| 378 | 370 |
| 379 // Tests that createGreyCache creates the grey snapshots in the background, | 371 // Tests that createGreyCache creates the grey snapshots in the background, |
| 380 // from color images in the in-memory cache. When the grey images are all | 372 // from color images in the in-memory cache. When the grey images are all |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 EXPECT_TRUE(base::PathExists(retinaFile)); | 561 EXPECT_TRUE(base::PathExists(retinaFile)); |
| 570 | 562 |
| 571 // Delete the image. | 563 // Delete the image. |
| 572 [cache removeImageWithSessionID:kSession]; | 564 [cache removeImageWithSessionID:kSession]; |
| 573 FlushRunLoops(); // ensure the file is removed. | 565 FlushRunLoops(); // ensure the file is removed. |
| 574 | 566 |
| 575 EXPECT_FALSE(base::PathExists(retinaFile)); | 567 EXPECT_FALSE(base::PathExists(retinaFile)); |
| 576 } | 568 } |
| 577 | 569 |
| 578 } // namespace | 570 } // namespace |
| OLD | NEW |