@@ -21,7 +21,7 @@ class WebImageTests: XCTestCase {
21
21
let expectation = self . expectation ( description: " WebImage static url initializer " )
22
22
let imageUrl = URL ( string: " https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png " )
23
23
let imageView = WebImage ( url: imageUrl)
24
- let introspectView = imageView. onSuccess { image, cacheType in
24
+ let introspectView = imageView. onSuccess { image, data , cacheType in
25
25
#if os(iOS) || os(tvOS)
26
26
let displayImage = try ? imageView. inspect ( ) . group ( ) . image ( 0 ) . uiImage ( )
27
27
#else
@@ -43,7 +43,7 @@ class WebImageTests: XCTestCase {
43
43
let imageUrl = URL ( string: " https://apng.onevcat.com/assets/elephant.png " )
44
44
let binding = Binding < Bool > ( wrappedValue: true )
45
45
let imageView = WebImage ( url: imageUrl, isAnimating: binding)
46
- let introspectView = imageView. onSuccess { image, cacheType in
46
+ let introspectView = imageView. onSuccess { image, data , cacheType in
47
47
if let animatedImage = image as? SDAnimatedImage {
48
48
XCTAssertTrue ( imageView. isAnimating)
49
49
#if os(iOS) || os(tvOS)
@@ -73,7 +73,7 @@ class WebImageTests: XCTestCase {
73
73
let imageUrl = URL ( string: " https://raw.githubusercontent.com/ibireme/YYImage/master/Demo/YYImageDemo/mew_baseline.jpg " )
74
74
let imageView = WebImage ( url: imageUrl, options: [ . progressiveLoad] , context: [ . imageScaleFactor: 1 ] )
75
75
let introspectView = imageView
76
- . onSuccess { _, _ in
76
+ . onSuccess { _, _, _ in
77
77
expectation. fulfill ( )
78
78
}
79
79
. onFailure { _ in
@@ -111,7 +111,7 @@ class WebImageTests: XCTestCase {
111
111
}
112
112
113
113
func testWebImageOnSuccessWhenMemoryCacheHit( ) throws {
114
- let expectation = self . expectation ( description: " WebImage onSuccess when memory hit " )
114
+ let expectation = self . expectation ( description: " WebImage onSuccess when memory cache hit " )
115
115
let imageUrl = URL ( string: " https://foo.bar/buzz.png " )
116
116
let cacheKey = SDWebImageManager . shared. cacheKey ( for: imageUrl)
117
117
#if os(macOS)
@@ -121,7 +121,7 @@ class WebImageTests: XCTestCase {
121
121
#endif
122
122
SDImageCache . shared. storeImage ( toMemory: testImage, forKey: cacheKey)
123
123
let imageView = WebImage ( url: imageUrl)
124
- let introspectView = imageView. onSuccess { image, cacheType in
124
+ let introspectView = imageView. onSuccess { image, data , cacheType in
125
125
XCTAssert ( cacheType == . memory)
126
126
XCTAssertNotNil ( image)
127
127
XCTAssertEqual ( image, testImage)
@@ -133,12 +133,31 @@ class WebImageTests: XCTestCase {
133
133
ViewHosting . expel ( )
134
134
}
135
135
136
+ func testWebImageOnSuccessWhenCacheMiss( ) throws {
137
+ let expectation = self . expectation ( description: " WebImage onSuccess when cache miss " )
138
+ let imageUrl = URL ( string: " http://via.placeholder.com/100x100.png " )
139
+ let cacheKey = SDWebImageManager . shared. cacheKey ( for: imageUrl)
140
+ SDImageCache . shared. removeImageFromMemory ( forKey: cacheKey)
141
+ SDImageCache . shared. removeImageFromDisk ( forKey: cacheKey)
142
+ let imageView = WebImage ( url: imageUrl)
143
+ let introspectView = imageView. onSuccess { image, data, cacheType in
144
+ XCTAssert ( cacheType == . none)
145
+ XCTAssertNotNil ( image)
146
+ XCTAssertNotNil ( data)
147
+ expectation. fulfill ( )
148
+ }
149
+ _ = try introspectView. inspect ( )
150
+ ViewHosting . host ( view: introspectView)
151
+ self . waitForExpectations ( timeout: 5 , handler: nil )
152
+ ViewHosting . expel ( )
153
+ }
154
+
136
155
func testWebImageEXIFImage( ) throws {
137
156
let expectation = self . expectation ( description: " WebImage EXIF image url " )
138
157
// EXIF 5, Left Mirrored
139
158
let imageUrl = URL ( string: " https://raw.githubusercontent.com/recurser/exif-orientation-examples/master/Landscape_5.jpg " )
140
159
let imageView = WebImage ( url: imageUrl)
141
- let introspectView = imageView. onSuccess { image, cacheType in
160
+ let introspectView = imageView. onSuccess { image, data , cacheType in
142
161
let displayImage = try ? imageView. inspect ( ) . group ( ) . image ( 0 ) . cgImage ( )
143
162
let orientation = try ! imageView. inspect ( ) . group ( ) . image ( 0 ) . orientation ( )
144
163
XCTAssertNotNil ( displayImage)
0 commit comments