Add the Flutter video editing application with project management, media import, timeline editing, preview, AI assistance, diagnostics and settings. Include shared UI and native host packages, platform runners, application tests and release tooling. Provide usage and contribution guides, the MIT license and third-party notices. Exclude local credentials, build outputs and validation data.
207 lines
8.8 KiB
Swift
207 lines
8.8 KiB
Swift
import Cocoa
|
|
import FlutterMacOS
|
|
import XCTest
|
|
@testable import cutdex
|
|
|
|
class RunnerTests: XCTestCase {
|
|
|
|
func testFileDropPolicyUsesFlutterRulesForEveryDestination() throws {
|
|
let timeline = try XCTUnwrap(NativeFileDropPolicy(arguments: [
|
|
"allowedExtensions": ["mp4", "wav"], "maximumFileCount": 1,
|
|
]))
|
|
XCTAssertTrue(timeline.accepts([URL(fileURLWithPath: "/source.WAV")]))
|
|
XCTAssertTrue(timeline.accepts([URL(fileURLWithPath: "/source.mp4")]))
|
|
XCTAssertFalse(timeline.accepts([URL(fileURLWithPath: "/source.png")]))
|
|
XCTAssertFalse(timeline.accepts([
|
|
URL(fileURLWithPath: "/a.wav"), URL(fileURLWithPath: "/b.mp4"),
|
|
]))
|
|
XCTAssertFalse(timeline.accepts([]))
|
|
let library = try XCTUnwrap(NativeFileDropPolicy(arguments: [
|
|
"allowedExtensions": ["mp4", "wav", "png"], "maximumFileCount": NSNull(),
|
|
]))
|
|
XCTAssertTrue(library.accepts([
|
|
URL(fileURLWithPath: "/a.png"), URL(fileURLWithPath: "/b.wav"),
|
|
]))
|
|
XCTAssertFalse(library.accepts([
|
|
URL(fileURLWithPath: "/a.png"), URL(fileURLWithPath: "/notes.pdf"),
|
|
]))
|
|
let attachments = try XCTUnwrap(NativeFileDropPolicy(arguments: [
|
|
"allowedExtensions": NSNull(), "maximumFileCount": NSNull(),
|
|
]))
|
|
XCTAssertTrue(attachments.accepts([
|
|
URL(fileURLWithPath: "/notes.pdf"), URL(fileURLWithPath: "/README"),
|
|
]))
|
|
XCTAssertFalse(attachments.accepts([try XCTUnwrap(URL(string: "https://example.com/a.wav"))]))
|
|
}
|
|
|
|
func testFileDropPolicyRejectsMissingAndMalformedRules() throws {
|
|
XCTAssertNil(NativeFileDropPolicy(arguments: [:]))
|
|
for extensions: Any in ["wav", [1], [""]] {
|
|
XCTAssertNil(NativeFileDropPolicy(arguments: [
|
|
"allowedExtensions": extensions, "maximumFileCount": 1,
|
|
]))
|
|
}
|
|
for count: Any in [0, -1, 1.5, true, "1"] {
|
|
XCTAssertNil(NativeFileDropPolicy(arguments: [
|
|
"allowedExtensions": ["wav"], "maximumFileCount": count,
|
|
]))
|
|
}
|
|
let empty = try XCTUnwrap(NativeFileDropPolicy(arguments: [
|
|
"allowedExtensions": [String](), "maximumFileCount": NSNull(),
|
|
]))
|
|
XCTAssertFalse(empty.accepts([URL(fileURLWithPath: "/source.wav")]))
|
|
}
|
|
|
|
@MainActor
|
|
func testHeaderControlGestureBlocksNativeMovementUntilRelease() throws {
|
|
let window = MainFlutterWindow(contentRect: NSRect(x: 100, y: 100, width: 1200, height: 800),
|
|
styleMask: [.titled, .closable, .resizable], backing: .buffered, defer: false)
|
|
window.isReleasedWhenClosed = false
|
|
defer { window.close() }
|
|
let target = HeaderEventView()
|
|
let controller = NSViewController()
|
|
controller.view = target
|
|
window.contentViewController = controller
|
|
window.setEditorChrome(true)
|
|
func send(_ type: NSEvent.EventType, x: CGFloat, top: CGFloat, clicks: Int = 1) throws {
|
|
let content = try XCTUnwrap(window.contentView)
|
|
let point = NSPoint(x: x, y: content.isFlipped ? top : content.bounds.height - top)
|
|
window.sendEvent(try XCTUnwrap(NSEvent.mouseEvent(with: type,
|
|
location: content.convert(point, to: nil), modifierFlags: [], timestamp: 0,
|
|
windowNumber: window.windowNumber, context: nil, eventNumber: 0,
|
|
clickCount: clicks, pressure: 1)))
|
|
}
|
|
for x in [CGFloat(104), 140, 176, 1136, 1172] {
|
|
target.movableDuringEvents = []
|
|
try send(.leftMouseDown, x: x, top: 20, clicks: 2)
|
|
try send(.leftMouseDragged, x: 600, top: 100)
|
|
try send(.leftMouseUp, x: 600, top: 100)
|
|
XCTAssertEqual(target.movableDuringEvents, [false, false, false])
|
|
// Integrated chrome permits movement only during explicit header drags.
|
|
XCTAssertFalse(window.isMovable)
|
|
}
|
|
try send(.leftMouseDown, x: 104, top: 20)
|
|
window.resignKey()
|
|
XCTAssertFalse(window.isMovable)
|
|
window.isMovable = false
|
|
try send(.leftMouseDown, x: 104, top: 20)
|
|
try send(.leftMouseUp, x: 104, top: 20)
|
|
XCTAssertFalse(window.isMovable)
|
|
}
|
|
|
|
@MainActor
|
|
func testHomeRetainsIntegratedChromeAndRestoresNativeCloseAction() throws {
|
|
let window = CloseTrackingWindow(contentRect: NSRect(x: 100, y: 100, width: 1200, height: 800),
|
|
styleMask: [.titled, .closable, .miniaturizable, .resizable], backing: .buffered, defer: false)
|
|
window.isReleasedWhenClosed = false
|
|
defer { window.close() }
|
|
let button = try XCTUnwrap(window.standardWindowButton(.closeButton))
|
|
let originalTarget = button.target
|
|
let originalAction = button.action
|
|
window.setEditorChrome(true, closeReturnsHome: false)
|
|
XCTAssertTrue(button.target === originalTarget)
|
|
XCTAssertEqual(button.action, originalAction)
|
|
window.setEditorChrome(true, closeReturnsHome: true)
|
|
button.performClick(nil)
|
|
XCTAssertEqual(window.homeRequestCount, 1)
|
|
window.setEditorChrome(true, closeReturnsHome: false)
|
|
XCTAssertTrue(button.target === originalTarget)
|
|
XCTAssertEqual(button.action, originalAction)
|
|
XCTAssertTrue(window.editorChromeEnabled)
|
|
XCTAssertEqual(window.titleVisibility, .hidden)
|
|
let content = try XCTUnwrap(window.contentView)
|
|
let rect = content.convert(button.bounds, from: button)
|
|
XCTAssertEqual(rect.midX, 19, accuracy: 0.5)
|
|
let top = content.isFlipped ? rect.midY : content.bounds.height - rect.midY
|
|
XCTAssertEqual(top, 20, accuracy: 0.5)
|
|
}
|
|
|
|
@MainActor
|
|
func testClosingIntegratedEditorRequestsFlutterHome() throws {
|
|
let window = CloseTrackingWindow(contentRect: NSRect(x: 100, y: 100, width: 1200, height: 800),
|
|
styleMask: [.titled, .closable, .miniaturizable, .resizable], backing: .buffered, defer: false)
|
|
window.isReleasedWhenClosed = false
|
|
defer { window.close() }
|
|
|
|
window.setEditorChrome(true)
|
|
let closeButton = try XCTUnwrap(window.standardWindowButton(.closeButton))
|
|
closeButton.performClick(nil)
|
|
XCTAssertEqual(window.homeRequestCount, 1)
|
|
|
|
window.performClose(nil)
|
|
XCTAssertEqual(window.homeRequestCount, 2)
|
|
XCTAssertTrue(window.editorChromeEnabled)
|
|
}
|
|
|
|
@MainActor
|
|
func testEditorChromePreservesNativeButtonsAndRestoresWindowStyle() throws {
|
|
let window = MainFlutterWindow(contentRect: NSRect(x: 100, y: 100, width: 1200, height: 800),
|
|
styleMask: [.titled, .closable, .miniaturizable, .resizable], backing: .buffered, defer: false)
|
|
window.isReleasedWhenClosed = false
|
|
defer { window.close() }
|
|
let originalFrame = window.frame
|
|
let originalMask = window.styleMask
|
|
let buttons = try [NSWindow.ButtonType.closeButton, .miniaturizeButton, .zoomButton].map {
|
|
try XCTUnwrap(window.standardWindowButton($0))
|
|
}
|
|
window.setEditorChrome(true)
|
|
XCTAssertEqual(window.frame, originalFrame)
|
|
XCTAssertEqual(window.titleVisibility, .hidden)
|
|
XCTAssertTrue(window.titlebarAppearsTransparent)
|
|
XCTAssertTrue(window.styleMask.contains(.fullSizeContentView))
|
|
XCTAssertTrue(window.standardWindowButton(.closeButton) === buttons[0])
|
|
XCTAssertTrue(window.standardWindowButton(.miniaturizeButton) === buttons[1])
|
|
XCTAssertTrue(window.standardWindowButton(.zoomButton) === buttons[2])
|
|
for width in [1200.0, 640.0, 1000.0] {
|
|
window.setFrame(NSRect(x: 100, y: 100, width: width, height: 800), display: true)
|
|
window.positionEditorWindowButtons()
|
|
let content = try XCTUnwrap(window.contentView)
|
|
for (index, button) in buttons.enumerated() {
|
|
let rect = content.convert(button.bounds, from: button)
|
|
XCTAssertEqual(rect.midX, 19 + Double(index) * 20, accuracy: 0.5)
|
|
let top = content.isFlipped ? rect.midY : content.bounds.height - rect.midY
|
|
XCTAssertEqual(top, 20, accuracy: 0.5)
|
|
XCTAssertFalse(button.isHidden)
|
|
XCTAssertNotNil(button.action)
|
|
}
|
|
}
|
|
let resizedFrame = window.frame
|
|
window.setEditorChrome(false)
|
|
XCTAssertEqual(window.frame, resizedFrame)
|
|
XCTAssertEqual(window.styleMask, originalMask)
|
|
XCTAssertEqual(window.titleVisibility, .visible)
|
|
XCTAssertFalse(window.titlebarAppearsTransparent)
|
|
window.setEditorChrome(true)
|
|
window.setEditorChrome(true)
|
|
XCTAssertTrue(window.editorChromeEnabled)
|
|
}
|
|
|
|
@MainActor
|
|
func testDropsRegisterOnlyExistingFileReferences() {
|
|
let controller = FlutterViewController()
|
|
for region in ["project", "timeline", "composer"] {
|
|
let target = NativeFileDropView(controller: controller,
|
|
channelName: "cutdex/\(region)_file_drop", hidesSourceImage: region == "timeline")
|
|
XCTAssertEqual(Set(target.registeredDraggedTypes), Set([.fileURL]))
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
@MainActor
|
|
private final class HeaderEventView: NSView {
|
|
var movableDuringEvents: [Bool] = []
|
|
override func mouseDown(with event: NSEvent) { movableDuringEvents.append(window!.isMovable) }
|
|
override func mouseDragged(with event: NSEvent) { movableDuringEvents.append(window!.isMovable) }
|
|
override func mouseUp(with event: NSEvent) { movableDuringEvents.append(window!.isMovable) }
|
|
}
|
|
|
|
@MainActor
|
|
private final class CloseTrackingWindow: MainFlutterWindow {
|
|
private(set) var homeRequestCount = 0
|
|
|
|
override func requestEditorHome() {
|
|
homeRequestCount += 1
|
|
}
|
|
}
|