fix(file-provider): Remove unused thumbnail wrapper
Signed-off-by: Claudio Cambra <[email protected]> Assisted-by: Codex:GPT-6 Signed-off-by: Claudio Cambra <[email protected]>
This commit is contained in:
2 files changed
+26
-15
No files matched your search
-6
@@ -386,12 +386,6 @@ public extension Item {
|
||||
return (localPath, fpItem, nil)
|
||||
}
|
||||
|
||||
func fetchThumbnail(size: CGSize, domain: NSFileProviderDomain? = nil, progress: Progress = .init()) async -> (Data?, Error?) {
|
||||
await NetworkOperationCancellation(log: logger.log).run(progress: progress) { @Sendable cancellation in
|
||||
await self.performFetchThumbnail(size: size, domain: domain, progress: progress, cancellation: cancellation)
|
||||
}
|
||||
}
|
||||
|
||||
internal func performFetchThumbnail(
|
||||
size: CGSize,
|
||||
domain: NSFileProviderDomain?,
|
||||
|
||||
+26
-9
@@ -1115,27 +1115,38 @@ final class ItemFetchTests: NextcloudFileProviderKitTestCase {
|
||||
|
||||
func testCancellingThumbnailCancelsNetworkTask() async throws {
|
||||
let (item, remoteInterface, _) = makeFetchItem(preview: true)
|
||||
let progress = Progress()
|
||||
let session = URLSession(configuration: .ephemeral)
|
||||
defer { session.invalidateAndCancel() }
|
||||
let (networkTask, networkCompletion) = try observedNetworkTask(
|
||||
in: session,
|
||||
url: XCTUnwrap(URL(string: "https://example.invalid/preview"))
|
||||
)
|
||||
let (started, continuation) = AsyncStream<Void>.makeStream()
|
||||
defer { continuation.finish() }
|
||||
remoteInterface.thumbnailHandler = { _, taskHandler in
|
||||
taskHandler(networkTask)
|
||||
progress.cancel()
|
||||
continuation.yield(())
|
||||
let cancelled = await waitForCancellation()
|
||||
XCTAssertTrue(cancelled, "Cancellation did not reach the operation.")
|
||||
}
|
||||
let batch = makeThumbnailBatch(identifiers: [item.itemIdentifier], remoteInterface: remoteInterface)
|
||||
defer { batch.progress.cancel() }
|
||||
let startedValue = try await nextTestValue(from: started)
|
||||
_ = try XCTUnwrap(startedValue)
|
||||
batch.progress.cancel()
|
||||
|
||||
let (data, error) = await item.fetchThumbnail(size: CGSize(width: 32, height: 32), progress: progress)
|
||||
|
||||
XCTAssertNil(data)
|
||||
XCTAssertEqual((error as? CocoaError)?.code, .userCancelled)
|
||||
let thumbnailValue = try await nextTestValue(from: batch.thumbnails)
|
||||
let thumbnail = try XCTUnwrap(thumbnailValue)
|
||||
XCTAssertEqual(thumbnail.identifier, item.itemIdentifier)
|
||||
XCTAssertNil(thumbnail.data)
|
||||
XCTAssertEqual((thumbnail.error as? CocoaError)?.code, .userCancelled)
|
||||
let nextThumbnail = try await nextTestValue(from: batch.thumbnails)
|
||||
XCTAssertNil(nextThumbnail)
|
||||
let completion = try await nextTestValue(from: batch.completion)
|
||||
XCTAssertEqual((completion.flatMap(\.self) as? CocoaError)?.code, .userCancelled)
|
||||
let networkError = try await nextTestValue(from: networkCompletion)
|
||||
XCTAssertEqual(networkError, NSURLErrorCancelled)
|
||||
XCTAssertNil(progress.cancellationHandler)
|
||||
XCTAssertNil(batch.progress.cancellationHandler)
|
||||
}
|
||||
|
||||
func testCancelledProgressDoesNotStartThumbnailDownload() async {
|
||||
@@ -1144,7 +1155,10 @@ final class ItemFetchTests: NextcloudFileProviderKitTestCase {
|
||||
progress.cancel()
|
||||
remoteInterface.thumbnailHandler = { _, _ in XCTFail("Cancelled thumbnail must not start a transfer") }
|
||||
|
||||
let (data, error) = await item.fetchThumbnail(size: CGSize(width: 32, height: 32), progress: progress)
|
||||
let (data, error) = await item.performFetchThumbnail(
|
||||
size: CGSize(width: 32, height: 32), domain: nil, progress: progress,
|
||||
cancellation: NetworkOperationCancellation(log: FileProviderLogMock())
|
||||
)
|
||||
|
||||
XCTAssertNil(data)
|
||||
XCTAssertEqual((error as? CocoaError)?.code, .userCancelled)
|
||||
@@ -1156,7 +1170,10 @@ final class ItemFetchTests: NextcloudFileProviderKitTestCase {
|
||||
remoteInterface.thumbnailData = Data("Late thumbnail response".utf8)
|
||||
remoteInterface.thumbnailCompletionHandler = { progress.cancel() }
|
||||
|
||||
let (data, error) = await item.fetchThumbnail(size: CGSize(width: 32, height: 32), progress: progress)
|
||||
let (data, error) = await item.performFetchThumbnail(
|
||||
size: CGSize(width: 32, height: 32), domain: nil, progress: progress,
|
||||
cancellation: NetworkOperationCancellation(log: FileProviderLogMock())
|
||||
)
|
||||
|
||||
XCTAssertNil(data)
|
||||
XCTAssertEqual((error as? CocoaError)?.code, .userCancelled)
|
||||
|
||||
Reference in new issue
Block a user