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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 | 370 |
371 SnapshotCache* cache = GetSnapshotCache(); | 371 SnapshotCache* cache = GetSnapshotCache(); |
372 | 372 |
373 NSString* firstPinnedID = [testSessions_ objectAtIndex:4]; | 373 NSString* firstPinnedID = [testSessions_ objectAtIndex:4]; |
374 NSString* secondPinnedID = [testSessions_ objectAtIndex:6]; | 374 NSString* secondPinnedID = [testSessions_ objectAtIndex:6]; |
375 NSMutableSet* set = [NSMutableSet set]; | 375 NSMutableSet* set = [NSMutableSet set]; |
376 [set addObject:firstPinnedID]; | 376 [set addObject:firstPinnedID]; |
377 [set addObject:secondPinnedID]; | 377 [set addObject:secondPinnedID]; |
378 cache.pinnedIDs = set; | 378 cache.pinnedIDs = set; |
379 | 379 |
380 [cache handleLowMemory]; | 380 if (!IsIPadIdiom()) |
| 381 [cache handleLowMemory]; |
381 | 382 |
382 BOOL expectedValue = YES; | 383 BOOL expectedValue = YES; |
383 if (IsIPadIdiom()) { | 384 if (IsIPadIdiom()) { |
384 expectedValue = NO; | 385 expectedValue = NO; |
385 } | 386 } |
386 EXPECT_EQ(expectedValue, [cache hasImageInMemory:firstPinnedID]); | 387 EXPECT_EQ(expectedValue, [cache hasImageInMemory:firstPinnedID]); |
387 EXPECT_EQ(expectedValue, [cache hasImageInMemory:secondPinnedID]); | 388 EXPECT_EQ(expectedValue, [cache hasImageInMemory:secondPinnedID]); |
388 | 389 |
389 NSString* notPinnedID = [testSessions_ objectAtIndex:2]; | 390 NSString* notPinnedID = [testSessions_ objectAtIndex:2]; |
390 EXPECT_FALSE([cache hasImageInMemory:notPinnedID]); | 391 EXPECT_FALSE([cache hasImageInMemory:notPinnedID]); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 } | 424 } |
424 | 425 |
425 // Same as previous test, except that all the color images are on disk, | 426 // Same as previous test, except that all the color images are on disk, |
426 // rather than in memory. | 427 // rather than in memory. |
427 // Disabled due to the greyImage crash. b/8048597 | 428 // Disabled due to the greyImage crash. b/8048597 |
428 TEST_F(SnapshotCacheTest, CreateGreyCacheFromDisk) { | 429 TEST_F(SnapshotCacheTest, CreateGreyCacheFromDisk) { |
429 LoadAllColorImagesIntoCache(true); | 430 LoadAllColorImagesIntoCache(true); |
430 | 431 |
431 // Remove color images from in-memory cache. | 432 // Remove color images from in-memory cache. |
432 SnapshotCache* cache = GetSnapshotCache(); | 433 SnapshotCache* cache = GetSnapshotCache(); |
433 [cache handleLowMemory]; | 434 |
| 435 if (!IsIPadIdiom()) |
| 436 [cache handleLowMemory]; |
434 | 437 |
435 // Request the creation of a grey image cache for all images. | 438 // Request the creation of a grey image cache for all images. |
436 [cache createGreyCache:testSessions_]; | 439 [cache createGreyCache:testSessions_]; |
437 | 440 |
438 // Wait for them to be put into the grey image cache. | 441 // Wait for them to be put into the grey image cache. |
439 WaitForGreyImagesInCache(kSessionCount); | 442 WaitForGreyImagesInCache(kSessionCount); |
440 | 443 |
441 __block NSUInteger numberOfCallbacks = 0; | 444 __block NSUInteger numberOfCallbacks = 0; |
442 for (NSUInteger i = 0; i < kSessionCount; ++i) { | 445 for (NSUInteger i = 0; i < kSessionCount; ++i) { |
443 NSString* sessionID = [testSessions_ objectAtIndex:i]; | 446 NSString* sessionID = [testSessions_ objectAtIndex:i]; |
(...skipping 20 matching lines...) Expand all Loading... |
464 [sessionIDs addObject:[testSessions_ objectAtIndex:0]]; | 467 [sessionIDs addObject:[testSessions_ objectAtIndex:0]]; |
465 [sessionIDs addObject:[testSessions_ objectAtIndex:1]]; | 468 [sessionIDs addObject:[testSessions_ objectAtIndex:1]]; |
466 [sessionIDs addObject:[testSessions_ objectAtIndex:2]]; | 469 [sessionIDs addObject:[testSessions_ objectAtIndex:2]]; |
467 | 470 |
468 SnapshotCache* cache = GetSnapshotCache(); | 471 SnapshotCache* cache = GetSnapshotCache(); |
469 | 472 |
470 // Put 3 images in the cache. | 473 // Put 3 images in the cache. |
471 LoadColorImagesIntoCache(kNumImages, true); | 474 LoadColorImagesIntoCache(kNumImages, true); |
472 // Make sure the color images are only on disk, to ensure the background | 475 // Make sure the color images are only on disk, to ensure the background |
473 // thread is slow enough to queue up the requests. | 476 // thread is slow enough to queue up the requests. |
474 [cache handleLowMemory]; | 477 if (!IsIPadIdiom()) |
| 478 [cache handleLowMemory]; |
475 | 479 |
476 // Enable the grey image cache. | 480 // Enable the grey image cache. |
477 [cache createGreyCache:sessionIDs]; | 481 [cache createGreyCache:sessionIDs]; |
478 | 482 |
479 // Request the grey versions | 483 // Request the grey versions |
480 __block BOOL firstCallbackCalled = NO; | 484 __block BOOL firstCallbackCalled = NO; |
481 __block BOOL secondCallbackCalled = NO; | 485 __block BOOL secondCallbackCalled = NO; |
482 __block BOOL thirdCallbackCalled = NO; | 486 __block BOOL thirdCallbackCalled = NO; |
483 [cache greyImageForSessionID:[testSessions_ objectAtIndex:0] | 487 [cache greyImageForSessionID:[testSessions_ objectAtIndex:0] |
484 callback:^(UIImage*) { | 488 callback:^(UIImage*) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 CGContextRef context = UIGraphicsGetCurrentContext(); | 539 CGContextRef context = UIGraphicsGetCurrentContext(); |
536 UIImage* image = GenerateRandomImage(context); | 540 UIImage* image = GenerateRandomImage(context); |
537 UIGraphicsEndImageContext(); | 541 UIGraphicsEndImageContext(); |
538 | 542 |
539 // Add the image to the cache then call handle low memory to ensure the image | 543 // Add the image to the cache then call handle low memory to ensure the image |
540 // is read from disk instead of the in-memory cache. | 544 // is read from disk instead of the in-memory cache. |
541 SnapshotCache* cache = GetSnapshotCache(); | 545 SnapshotCache* cache = GetSnapshotCache(); |
542 NSString* const kSession = @"foo"; | 546 NSString* const kSession = @"foo"; |
543 [cache setImage:image withSessionID:kSession]; | 547 [cache setImage:image withSessionID:kSession]; |
544 FlushRunLoops(); // ensure the file is written to disk. | 548 FlushRunLoops(); // ensure the file is written to disk. |
545 [cache handleLowMemory]; | 549 if (!IsIPadIdiom()) |
| 550 [cache handleLowMemory]; |
546 | 551 |
547 // Retrive the image and have the callback verify the size and scale. | 552 // Retrive the image and have the callback verify the size and scale. |
548 __block BOOL callbackComplete = NO; | 553 __block BOOL callbackComplete = NO; |
549 [cache retrieveImageForSessionID:kSession | 554 [cache retrieveImageForSessionID:kSession |
550 callback:^(UIImage* imageFromDisk) { | 555 callback:^(UIImage* imageFromDisk) { |
551 EXPECT_EQ(image.size.width, | 556 EXPECT_EQ(image.size.width, |
552 imageFromDisk.size.width); | 557 imageFromDisk.size.width); |
553 EXPECT_EQ(image.size.height, | 558 EXPECT_EQ(image.size.height, |
554 imageFromDisk.size.height); | 559 imageFromDisk.size.height); |
555 EXPECT_EQ(image.scale, imageFromDisk.scale); | 560 EXPECT_EQ(image.scale, imageFromDisk.scale); |
(...skipping 15 matching lines...) Expand all Loading... |
571 CGContextRef context = UIGraphicsGetCurrentContext(); | 576 CGContextRef context = UIGraphicsGetCurrentContext(); |
572 UIImage* image = GenerateRandomImage(context); | 577 UIImage* image = GenerateRandomImage(context); |
573 UIGraphicsEndImageContext(); | 578 UIGraphicsEndImageContext(); |
574 | 579 |
575 // Add the image to the cache then call handle low memory to ensure the image | 580 // Add the image to the cache then call handle low memory to ensure the image |
576 // is read from disk instead of the in-memory cache. | 581 // is read from disk instead of the in-memory cache. |
577 SnapshotCache* cache = GetSnapshotCache(); | 582 SnapshotCache* cache = GetSnapshotCache(); |
578 NSString* const kSession = @"foo"; | 583 NSString* const kSession = @"foo"; |
579 [cache setImage:image withSessionID:kSession]; | 584 [cache setImage:image withSessionID:kSession]; |
580 FlushRunLoops(); // ensure the file is written to disk. | 585 FlushRunLoops(); // ensure the file is written to disk. |
581 [cache handleLowMemory]; | 586 if (!IsIPadIdiom()) |
| 587 [cache handleLowMemory]; |
582 | 588 |
583 // Verify the file was writted with @2x in the file name. | 589 // Verify the file was writted with @2x in the file name. |
584 base::FilePath retinaFile = [SnapshotCache imagePathForSessionID:kSession]; | 590 base::FilePath retinaFile = [SnapshotCache imagePathForSessionID:kSession]; |
585 EXPECT_TRUE(base::PathExists(retinaFile)); | 591 EXPECT_TRUE(base::PathExists(retinaFile)); |
586 | 592 |
587 // Delete the image. | 593 // Delete the image. |
588 [cache removeImageWithSessionID:kSession]; | 594 [cache removeImageWithSessionID:kSession]; |
589 FlushRunLoops(); // ensure the file is removed. | 595 FlushRunLoops(); // ensure the file is removed. |
590 | 596 |
591 EXPECT_FALSE(base::PathExists(retinaFile)); | 597 EXPECT_FALSE(base::PathExists(retinaFile)); |
592 } | 598 } |
593 | 599 |
594 } // namespace | 600 } // namespace |
OLD | NEW |