From 0a2213cb329d26aa05c517390e194847a6e237f3 Mon Sep 17 00:00:00 2001 From: onevcat Date: Fri, 27 Oct 2023 22:52:33 +0900 Subject: [PATCH] Add tests for AVAsset provider cacheKey --- .../ImageDataProviderTests.swift | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Tests/KingfisherTests/ImageDataProviderTests.swift b/Tests/KingfisherTests/ImageDataProviderTests.swift index ce1d62b7b..a5ff26965 100644 --- a/Tests/KingfisherTests/ImageDataProviderTests.swift +++ b/Tests/KingfisherTests/ImageDataProviderTests.swift @@ -93,6 +93,29 @@ class ImageDataProviderTests: XCTestCase { XCTAssertTrue(called) } + func testAVAssetImageDataProviderCacheKeyVariesForRemote() { + let remoteURL1 = URL(string: "https://example.com/1/hello.mp4")! + let remoteURL2 = URL(string: "https://example.com/2/hello.mp4")! + + let provider1 = AVAssetImageDataProvider(assetURL: remoteURL1, seconds: 10) + XCTAssertEqual(provider1.cacheKey, "https://example.com/1/hello.mp4_10.0") + + let provider2 = AVAssetImageDataProvider(assetURL: remoteURL2, seconds: 10) + XCTAssertNotEqual(provider1.cacheKey, provider2.cacheKey) + } + + // AVAssetImageDataProvider fix for appending to #1825 + func testAVAssetImageDataProviderCacheKeyConsistForDifferentAppSandbox() { + let localURL1 = URL(string: "file:///Users/onevcat/Library/Developer/CoreSimulator/Devices/ABC/data/Containers/Bundle/Application/DEF/Kingfisher-Demo.app/video/hello.mp4")! + let localURL2 = URL(string: "file:///Users/onevcat/Library/Developer/CoreSimulator/Devices/ABC/data/Containers/Bundle/Application/XYZ/Kingfisher-Demo.app/video/hello.mp4")! + + let provider1 = AVAssetImageDataProvider(assetURL: localURL1, seconds: 10) + XCTAssertEqual(provider1.cacheKey, "\(URL.localFileCacheKeyPrefix)/Kingfisher-Demo.app/video/hello.mp4_10.0") + + let provider2 = AVAssetImageDataProvider(assetURL: localURL2, seconds: 10) + XCTAssertEqual(provider1.cacheKey, provider2.cacheKey) + } + #if swift(>=5.5) #if canImport(_Concurrency) @available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)