Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970import CoreGraphicsimport Foundationimport RealityDriverSupportimport Testing
struct DriverMouseEventTests { @Test(arguments: [UInt64(0x100), 0x10100]) func plainClickPreservesCapsLockWithoutRequestingSystemEventFlags(baselineFlags: UInt64) throws { let baseline = DriverInputState(heldKeys: [], flags: baselineFlags) try baseline.requireNeutralBaseline() let sequence = try DriverModifierSequence(flags: 0, initialFlags: baseline.flags, heldKeys: []) #expect(sequence.pressed.isEmpty && sequence.released.isEmpty) #expect(sequence.activeFlags == baselineFlags & CGEventFlags.maskAlphaShift.rawValue) }
@Test(arguments: [CGEventType.leftMouseDown, .leftMouseDragged, .leftMouseUp, .mouseMoved]) func nativeEventsTargetTheirOwnedProcessWithoutSpoofingWindowServerAnnotations(type: CGEventType) throws { let source = try #require(CGEventSource(stateID: .hidSystemState)) let point = CGPoint(x: -40, y: 125) let event = try DriverMouseEvents.make( type, source: source, pid: 123, windowID: 456, point: point, previous: CGPoint(x: -50, y: 105), flags: CGEventFlags.maskCommand.rawValue) #expect(event.type == type && event.location == point) #expect(event.flags == .maskCommand) #expect(event.getIntegerValueField(.eventTargetUnixProcessID) == 123) #expect(event.getIntegerValueField(.mouseEventWindowUnderMousePointer) == 0) #expect(event.getIntegerValueField(.mouseEventWindowUnderMousePointerThatCanHandleThisEvent) == 0) #expect(event.getIntegerValueField(.mouseEventNumber) == 1) #expect(event.getIntegerValueField(.mouseEventClickState) == (type == .mouseMoved ? 0 : 1)) #expect(event.getIntegerValueField(.mouseEventDeltaX) == 10) #expect(event.getIntegerValueField(.mouseEventDeltaY) == 20) #expect( event.getDoubleValueField(.mouseEventPressure) == (type == .leftMouseDown || type == .leftMouseDragged ? 1 : 0)) }
@Test(arguments: [CGPoint(x: -10.4, y: 20.6), CGPoint(x: 0, y: 0), CGPoint(x: 100, y: -50)]) func deltasFollowConsecutiveSamples(delta: CGPoint) throws { let source = try #require(CGEventSource(stateID: .hidSystemState)) let previous = CGPoint(x: 200, y: 200) let event = try DriverMouseEvents.make( .leftMouseDragged, source: source, pid: 123, windowID: 456, point: CGPoint(x: previous.x + delta.x, y: previous.y + delta.y), previous: previous, flags: 0) #expect(event.getIntegerValueField(.mouseEventDeltaX) == Int64(delta.x.rounded())) #expect(event.getIntegerValueField(.mouseEventDeltaY) == Int64(delta.y.rounded())) }
@Test(arguments: [CGEventType.rightMouseDown, .keyDown, .flagsChanged]) func unrelatedEventTypesAreRejected(type: CGEventType) throws { let source = try #require(CGEventSource(stateID: .hidSystemState)) #expect(throws: DriverError.self) { try DriverMouseEvents.make( type, source: source, pid: 123, windowID: 456, point: .zero, previous: .zero, flags: 0) } }
@Test(arguments: [ DriverCommand.drag(pid: 0, windowID: 456, fromX: 0, fromY: 0, toX: 10, toY: 10, flags: 0), .drag(pid: 123, windowID: 0, fromX: 0, fromY: 0, toX: 10, toY: 10, flags: 0), ]) func nativeDragRequiresPositiveOwnership(command: DriverCommand) { #expect(throws: DriverError.self) { try command.validate() } }
@Test func wireRejectsLegacyUnownedDragRequests() { let data = Data(#"{"id":1,"command":{"drag":{"fromX":0,"fromY":0,"toX":10,"toY":10,"flags":0}}}"#.utf8) #expect(throws: (any Error).self) { try DriverWire.decodeRequest(data) } }}