import XCTest @testable import FocusFixer final class WindowLocatorTests: XCTestCase { func testReturnsOwnerPIDWhenPointInsideWindow() { let windows = [ WindowInfo(ownerPID: 111, layer: 0, bounds: CGRect(x: 0, y: 0, width: 100, height: 100)) ] XCTAssertEqual(WindowLocator.ownerPID(at: CGPoint(x: 50, y: 50), in: windows), 111) } func testIgnoresNonZeroLayerWindows() { let windows = [ WindowInfo(ownerPID: 999, layer: 25, bounds: CGRect(x: 0, y: 0, width: 100, height: 100)) ] XCTAssertNil(WindowLocator.ownerPID(at: CGPoint(x: 50, y: 50), in: windows)) } func testFallsThroughToNextWindowWhenTopWindowIsWrongLayer() { let windows = [ WindowInfo(ownerPID: 1, layer: 25, bounds: CGRect(x: 0, y: 0, width: 100, height: 100)), WindowInfo(ownerPID: 2, layer: 0, bounds: CGRect(x: 0, y: 0, width: 100, height: 100)) ] XCTAssertEqual(WindowLocator.ownerPID(at: CGPoint(x: 50, y: 50), in: windows), 2) } func testReturnsFrontmostWindowInZOrder() { // Overlapping layer-0 windows: front-to-back order (as returned by // CGWindowListCopyWindowInfo) determines which owner wins. let windows = [ WindowInfo(ownerPID: 1, layer: 0, bounds: CGRect(x: 0, y: 0, width: 200, height: 200)), WindowInfo(ownerPID: 2, layer: 0, bounds: CGRect(x: 0, y: 0, width: 200, height: 200)) ] XCTAssertEqual(WindowLocator.ownerPID(at: CGPoint(x: 50, y: 50), in: windows), 1) } func testEmptyWindowListReturnsNil() { XCTAssertNil(WindowLocator.ownerPID(at: CGPoint(x: 50, y: 50), in: [])) } func testPointOutsideAllWindowsReturnsNil() { let windows = [ WindowInfo(ownerPID: 1, layer: 0, bounds: CGRect(x: 0, y: 0, width: 100, height: 100)) ] XCTAssertNil(WindowLocator.ownerPID(at: CGPoint(x: 500, y: 500), in: windows)) } }