WIP: add video thumbnails
This commit is contained in:
@@ -91,6 +91,32 @@ final class ClipboardCacheServiceTests: XCTestCase {
|
||||
XCTAssertNotNil(cacheService.previewThumbnail(for: pdfItem(path: path)))
|
||||
}
|
||||
|
||||
func testPreviewThumbnailUsesDecryptedVideoTemporaryCopyAndCachesResult() throws {
|
||||
let baseURL = try makeTempDirectory()
|
||||
let videoData = Data([0, 0, 0, 24, 102, 116, 121, 112, 109, 112, 52, 50])
|
||||
var providerURLs: [URL] = []
|
||||
let cacheService = ClipboardCacheService(
|
||||
baseURL: baseURL,
|
||||
encryptionService: fixedEncryptionService(),
|
||||
videoThumbnailProvider: { url in
|
||||
providerURLs.append(url)
|
||||
XCTAssertEqual(url.pathExtension, "mp4")
|
||||
XCTAssertEqual(try? Data(contentsOf: url), videoData)
|
||||
return self.makeImage(color: .systemIndigo)
|
||||
}
|
||||
)
|
||||
let path = try XCTUnwrap(cacheService.cacheVideo(videoData, id: UUID(), fileExtension: "mp4"))
|
||||
let item = videoItem(path: path)
|
||||
|
||||
let thumbnail = cacheService.previewThumbnail(for: item)
|
||||
let cachedThumbnail = cacheService.previewThumbnail(for: item)
|
||||
|
||||
XCTAssertNotNil(thumbnail)
|
||||
XCTAssertNotNil(cachedThumbnail)
|
||||
XCTAssertEqual(providerURLs.count, 1)
|
||||
XCTAssertFalse(FileManager.default.fileExists(atPath: try XCTUnwrap(providerURLs.first).path))
|
||||
}
|
||||
|
||||
func testPDFCacheFilesAreEncryptedAndReadable() throws {
|
||||
let baseURL = try makeTempDirectory()
|
||||
let cacheService = ClipboardCacheService(baseURL: baseURL, encryptionService: fixedEncryptionService())
|
||||
@@ -389,7 +415,7 @@ final class ClipboardCacheServiceTests: XCTestCase {
|
||||
}
|
||||
|
||||
private func makeImage(color: NSColor) -> NSImage {
|
||||
let size = NSSize(width: 24, height: 24)
|
||||
let size = NSSize(width: 64, height: 40)
|
||||
let image = NSImage(size: size)
|
||||
image.lockFocus()
|
||||
color.setFill()
|
||||
|
||||
@@ -1386,6 +1386,39 @@ final class ClipboardPanelViewTests: XCTestCase {
|
||||
XCTAssertEqual(fixture.view.debugCardPreviewStyles, ["video-preview"])
|
||||
}
|
||||
|
||||
func testVideoCardsUseMediaPreviewWhenThumbnailExists() throws {
|
||||
let cacheService = ClipboardCacheService(
|
||||
baseURL: makeTempDirectory(),
|
||||
encryptionService: ClipboardEncryptionService(keyProvider: { nil }),
|
||||
videoThumbnailProvider: { _ in self.sampleImage() }
|
||||
)
|
||||
let fixture = makePanelFixture(cacheService: cacheService)
|
||||
let id = UUID()
|
||||
let path = try XCTUnwrap(cacheService.cacheVideo(Data([0, 1, 2, 3]), id: id, fileExtension: "mp4"))
|
||||
let item = ClipboardItem(
|
||||
id: id,
|
||||
kind: .video,
|
||||
displayText: "Video (24 KB)",
|
||||
payload: path,
|
||||
payloadHash: fixture.store.hashString("video-thumbnail"),
|
||||
createdAt: Date(),
|
||||
lastUsedAt: Date(),
|
||||
useCount: 0,
|
||||
sourceApp: "QuickTime Player",
|
||||
imagePath: nil,
|
||||
thumbnailPath: nil
|
||||
)
|
||||
|
||||
fixture.store.upsert(item)
|
||||
fixture.viewModel.sortMode = .videos
|
||||
drainMainQueue()
|
||||
fixture.window.contentView?.layoutSubtreeIfNeeded()
|
||||
|
||||
XCTAssertEqual(fixture.view.debugCardAccessibilityLabels, ["Video: Video (24 KB)"])
|
||||
XCTAssertEqual(fixture.view.debugCardPreviewSummaries, ["Video (24 KB)|Video clip|MP4"])
|
||||
XCTAssertEqual(fixture.view.debugCardPreviewStyles, ["video-media-preview"])
|
||||
}
|
||||
|
||||
func testColorCardsUseSwatchPreview() {
|
||||
let fixture = makePanelFixture()
|
||||
let item = makeItem(
|
||||
@@ -1433,9 +1466,9 @@ final class ClipboardPanelViewTests: XCTestCase {
|
||||
return (fixture.window, fixture.view)
|
||||
}
|
||||
|
||||
private func makePanelFixture() -> PanelFixture {
|
||||
private func makePanelFixture(cacheService: ClipboardCacheService? = nil) -> PanelFixture {
|
||||
let settings = makeSettings()
|
||||
let cacheService = ClipboardCacheService()
|
||||
let cacheService = cacheService ?? ClipboardCacheService()
|
||||
let store = makeStore(settings: settings, cacheService: cacheService)
|
||||
let viewModel = ClipboardPanelViewModel(store: store, settings: settings, cacheService: cacheService)
|
||||
let previewProbe = PreviewProbe()
|
||||
|
||||
Reference in New Issue
Block a user