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" |
11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/mac/bind_objc_block.h" | 13 #include "base/mac/bind_objc_block.h" |
| 14 #include "base/mac/scoped_cftyperef.h" |
14 #include "base/mac/scoped_nsautorelease_pool.h" | 15 #include "base/mac/scoped_nsautorelease_pool.h" |
15 #include "base/mac/scoped_nsobject.h" | 16 #include "base/mac/scoped_nsobject.h" |
16 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
17 #include "base/strings/sys_string_conversions.h" | 18 #include "base/strings/sys_string_conversions.h" |
18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
19 #import "ios/chrome/browser/snapshots/snapshot_cache_internal.h" | 20 #import "ios/chrome/browser/snapshots/snapshot_cache_internal.h" |
20 #include "ios/web/public/test/test_web_thread_bundle.h" | 21 #include "ios/web/public/test/test_web_thread_bundle.h" |
21 #include "ios/web/public/web_thread.h" | 22 #include "ios/web/public/web_thread.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 #include "testing/gtest_mac.h" | 24 #include "testing/gtest_mac.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 } | 185 } |
185 | 186 |
186 if (byteOrder != kCGBitmapByteOrder32Host) { | 187 if (byteOrder != kCGBitmapByteOrder32Host) { |
187 int lastChannel = (CGImageGetBitsPerPixel(cgImage) == 24) ? 2 : 3; | 188 int lastChannel = (CGImageGetBitsPerPixel(cgImage) == 24) ? 2 : 3; |
188 *red = lastChannel - *red; | 189 *red = lastChannel - *red; |
189 *green = lastChannel - *green; | 190 *green = lastChannel - *green; |
190 *blue = lastChannel - *blue; | 191 *blue = lastChannel - *blue; |
191 } | 192 } |
192 } | 193 } |
193 | 194 |
194 const char* GetPixelData(CGImageRef cgImage) { | |
195 CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider(cgImage)); | |
196 return reinterpret_cast<const char*>(CFDataGetBytePtr(data)); | |
197 } | |
198 | |
199 void TriggerMemoryWarning() { | 195 void TriggerMemoryWarning() { |
200 // _performMemoryWarning is a private API and must not be compiled into | 196 // _performMemoryWarning is a private API and must not be compiled into |
201 // official builds. | 197 // official builds. |
202 #pragma clang diagnostic push | 198 #pragma clang diagnostic push |
203 #pragma clang diagnostic ignored "-Wundeclared-selector" | 199 #pragma clang diagnostic ignored "-Wundeclared-selector" |
204 [[UIApplication sharedApplication] | 200 [[UIApplication sharedApplication] |
205 performSelector:@selector(_performMemoryWarning)]; | 201 performSelector:@selector(_performMemoryWarning)]; |
206 #pragma clang diagnostic pop | 202 #pragma clang diagnostic pop |
207 } | 203 } |
208 | 204 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 NSString* sessionID = [testSessions_ objectAtIndex:i]; | 260 NSString* sessionID = [testSessions_ objectAtIndex:i]; |
265 | 261 |
266 base::FilePath path([SnapshotCache imagePathForSessionID:sessionID]); | 262 base::FilePath path([SnapshotCache imagePathForSessionID:sessionID]); |
267 EXPECT_TRUE(base::PathExists(path)); | 263 EXPECT_TRUE(base::PathExists(path)); |
268 | 264 |
269 // Check image colors by comparing the first pixel against the reference | 265 // Check image colors by comparing the first pixel against the reference |
270 // image. | 266 // image. |
271 UIImage* image = | 267 UIImage* image = |
272 [UIImage imageWithContentsOfFile:base::SysUTF8ToNSString(path.value())]; | 268 [UIImage imageWithContentsOfFile:base::SysUTF8ToNSString(path.value())]; |
273 CGImageRef cgImage = [image CGImage]; | 269 CGImageRef cgImage = [image CGImage]; |
274 const char* pixels = GetPixelData(cgImage); | 270 base::ScopedCFTypeRef<CFDataRef> pixelData( |
| 271 CGDataProviderCopyData(CGImageGetDataProvider(cgImage))); |
| 272 const char* pixels = |
| 273 reinterpret_cast<const char*>(CFDataGetBytePtr(pixelData)); |
275 EXPECT_TRUE(pixels); | 274 EXPECT_TRUE(pixels); |
276 | 275 |
277 UIImage* referenceImage = [testImages_ objectAtIndex:i]; | 276 UIImage* referenceImage = [testImages_ objectAtIndex:i]; |
278 CGImageRef referenceCgImage = [referenceImage CGImage]; | 277 CGImageRef referenceCgImage = [referenceImage CGImage]; |
279 const char* referencePixels = GetPixelData(referenceCgImage); | 278 base::ScopedCFTypeRef<CFDataRef> referenceData( |
| 279 CGDataProviderCopyData(CGImageGetDataProvider(referenceCgImage))); |
| 280 const char* referencePixels = |
| 281 reinterpret_cast<const char*>(CFDataGetBytePtr(referenceData)); |
280 EXPECT_TRUE(referencePixels); | 282 EXPECT_TRUE(referencePixels); |
281 | 283 |
282 if (pixels != nil && referencePixels != nil) { | 284 if (pixels != nil && referencePixels != nil) { |
283 // Color components may not be in the same order, | 285 // Color components may not be in the same order, |
284 // because of writing to disk and reloading. | 286 // because of writing to disk and reloading. |
285 int red, green, blue; | 287 int red, green, blue; |
286 ComputeColorComponents(cgImage, &red, &green, &blue); | 288 ComputeColorComponents(cgImage, &red, &green, &blue); |
287 | 289 |
288 int referenceRed, referenceGreen, referenceBlue; | 290 int referenceRed, referenceGreen, referenceBlue; |
289 ComputeColorComponents(referenceCgImage, &referenceRed, &referenceGreen, | 291 ComputeColorComponents(referenceCgImage, &referenceRed, &referenceGreen, |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 EXPECT_TRUE(base::PathExists(retinaFile)); | 563 EXPECT_TRUE(base::PathExists(retinaFile)); |
562 | 564 |
563 // Delete the image. | 565 // Delete the image. |
564 [cache removeImageWithSessionID:kSession]; | 566 [cache removeImageWithSessionID:kSession]; |
565 FlushRunLoops(); // ensure the file is removed. | 567 FlushRunLoops(); // ensure the file is removed. |
566 | 568 |
567 EXPECT_FALSE(base::PathExists(retinaFile)); | 569 EXPECT_FALSE(base::PathExists(retinaFile)); |
568 } | 570 } |
569 | 571 |
570 } // namespace | 572 } // namespace |
OLD | NEW |