WIP: add video clip support
This commit is contained in:
@@ -119,6 +119,20 @@ final class ClipboardCacheServiceTests: XCTestCase {
|
||||
XCTAssertEqual(try posixPermissions(URL(fileURLWithPath: path)), 0o600)
|
||||
}
|
||||
|
||||
func testVideoCacheFilesAreEncryptedAndReadable() throws {
|
||||
let baseURL = try makeTempDirectory()
|
||||
let cacheService = ClipboardCacheService(baseURL: baseURL, encryptionService: fixedEncryptionService())
|
||||
let videoData = Data([0, 0, 0, 24, 102, 116, 121, 112, 109, 112, 52, 50])
|
||||
|
||||
let path = try XCTUnwrap(cacheService.cacheVideo(videoData, id: UUID(), fileExtension: "mp4"))
|
||||
let rawVideo = try Data(contentsOf: URL(fileURLWithPath: path))
|
||||
|
||||
XCTAssertTrue(ClipboardEncryptionService.isProtected(rawVideo))
|
||||
XCTAssertNotEqual(rawVideo, videoData)
|
||||
XCTAssertEqual(cacheService.data(for: path), videoData)
|
||||
XCTAssertEqual(try posixPermissions(URL(fileURLWithPath: path)), 0o600)
|
||||
}
|
||||
|
||||
func testRichTextCacheFilesAreEncryptedAndReadable() throws {
|
||||
let baseURL = try makeTempDirectory()
|
||||
let cacheService = ClipboardCacheService(baseURL: baseURL, encryptionService: fixedEncryptionService())
|
||||
@@ -178,6 +192,19 @@ final class ClipboardCacheServiceTests: XCTestCase {
|
||||
XCTAssertEqual(try posixPermissions(previewURL), 0o600)
|
||||
}
|
||||
|
||||
func testTemporaryReadableURLWorksForVideo() throws {
|
||||
let baseURL = try makeTempDirectory()
|
||||
let cacheService = ClipboardCacheService(baseURL: baseURL, encryptionService: fixedEncryptionService())
|
||||
let videoData = Data([0, 0, 0, 24, 102, 116, 121, 112, 109, 112, 52, 50])
|
||||
let path = try XCTUnwrap(cacheService.cacheVideo(videoData, id: UUID(), fileExtension: "mp4"))
|
||||
|
||||
let previewURL = try XCTUnwrap(cacheService.temporaryReadableURL(for: videoItem(path: path)))
|
||||
|
||||
XCTAssertEqual(try Data(contentsOf: previewURL), videoData)
|
||||
XCTAssertEqual(previewURL.pathExtension, "mp4")
|
||||
XCTAssertEqual(try posixPermissions(previewURL), 0o600)
|
||||
}
|
||||
|
||||
func testTemporaryReadableURLWorksForRichText() throws {
|
||||
let baseURL = try makeTempDirectory()
|
||||
let cacheService = ClipboardCacheService(baseURL: baseURL, encryptionService: fixedEncryptionService())
|
||||
@@ -325,6 +352,22 @@ final class ClipboardCacheServiceTests: XCTestCase {
|
||||
)
|
||||
}
|
||||
|
||||
private func videoItem(path: String) -> ClipboardItem {
|
||||
ClipboardItem(
|
||||
id: UUID(),
|
||||
kind: .video,
|
||||
displayText: "Video",
|
||||
payload: path,
|
||||
payloadHash: "hash",
|
||||
createdAt: Date(),
|
||||
lastUsedAt: Date(),
|
||||
useCount: 0,
|
||||
sourceApp: nil,
|
||||
imagePath: nil,
|
||||
thumbnailPath: nil
|
||||
)
|
||||
}
|
||||
|
||||
private func richTextItem(path: String) -> ClipboardItem {
|
||||
ClipboardItem(
|
||||
id: UUID(),
|
||||
|
||||
Reference in New Issue
Block a user