Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273import ApplicationServicesimport CoreGraphicsimport Testing
@testable import ParcelPlatform
@Suite struct AppThreadSheetInventoryTests { @Test func onlyPositivelyIdentifiedDirectSheetsExtendTheWindowInventory() throws { let candidates = try AppThreadWindowLookup.includingAttachedSheets( in: [1], children: { _ in [2, 3, 4, 5] }, role: { id in switch id { case 2: "AXSheet" case 3: "AXWindow" case 4: "AXGroup" default: nil } }, onFailure: { _ in Issue.record("Unexpected traversal failure") }) #expect(candidates == [1, 2]) }
@Test func sheetsAlsoListedInAXWindowsHaveOneSnapshot() throws { let candidates = try AppThreadWindowLookup.includingAttachedSheets( in: [1, 2], children: { $0 == 1 ? [2] : [] }, role: { _ in "AXSheet" }, onFailure: { _ in Issue.record("Unexpected traversal failure") }) let identified = try AppThreadWindowLookup.identified( in: candidates, identify: { CGWindowID($0) }, onFailure: { _ in Issue.record("Unexpected failure") }) #expect(identified.map(\.id) == [1, 2]) }
@Test func aSheetWithoutNativeIdentityIsReportedRatherThanInvented() throws { let candidates = try AppThreadWindowLookup.includingAttachedSheets( in: [1], children: { _ in [2] }, role: { _ in "AXSheet" }, onFailure: { _ in Issue.record("Unexpected traversal failure") }) var failures: [AXPlatformError] = [] let identified = try AppThreadWindowLookup.identified( in: candidates, identify: { if $0 == 2 { throw AXPlatformError.noValue } return CGWindowID($0) }, onFailure: { if let error = $0 as? AXPlatformError { failures.append(error) } }) #expect(identified.map(\.id) == [1]) #expect(failures == [.noValue]) }
@Test func genuineSheetEnumerationErrorsRemainFailures() { #expect(throws: AXPlatformError.timedOut) { try AppThreadWindowLookup.includingAttachedSheets( in: [1], children: { _ throws -> [Int] in throw AXPlatformError.timedOut }, role: { _ in nil }, onFailure: { _ in Issue.record("Unexpected traversal failure") }) } } @Test func staleParentsAndChildrenDoNotHideHealthyDocumentsAndSheets() throws { for failure in [AXPlatformError.elementInvalid, .other(AXError.illegalArgument.rawValue)] { var failures: [AXPlatformError] = [] let candidates = try AppThreadWindowLookup.includingAttachedSheets( in: [1, 2], children: { parent in if parent == 1 { throw failure } return [3, 4] }, role: { child in if child == 3 { throw failure } return "AXSheet" }, onFailure: { if let error = $0 as? AXPlatformError { failures.append(error) } }) #expect(candidates == [1, 2, 4]) #expect(failures == [failure, failure]) } }
}