fix: fullscreen detection working

This commit is contained in:
Michael Freno
2026-01-14 21:01:44 -05:00
parent 8e5f6c6715
commit f7d8470a43
5 changed files with 390 additions and 64 deletions

View File

@@ -0,0 +1,120 @@
//
// FullscreenDetectionServiceTests.swift
// GazeTests
//
// Created by ChatGPT on 1/14/26.
//
import Combine
import CoreGraphics
import XCTest
@testable import Gaze
@MainActor
final class FullscreenDetectionServiceTests: XCTestCase {
func testPermissionDeniedKeepsStateFalse() {
let mockManager = MockPermissionManager(status: ScreenCaptureAuthorizationStatus.denied)
let service = FullscreenDetectionService(permissionManager: mockManager)
let expectation = expectation(description: "No change")
expectation.isInverted = true
let cancellable = service.$isFullscreenActive
.dropFirst()
.sink { _ in
expectation.fulfill()
}
service.forceUpdate()
wait(for: [expectation], timeout: 0.5)
cancellable.cancel()
}
func testFullscreenStateBecomesTrueWhenWindowMatchesScreen() {
let mockManager = MockPermissionManager(status: ScreenCaptureAuthorizationStatus.authorized)
let environment = MockFullscreenEnvironment(
frontmostPID: 42,
windowDescriptors: [
FullscreenWindowDescriptor(
ownerPID: 42,
layer: 0,
bounds: CGRect(x: 0, y: 0, width: 1920, height: 1080)
)
],
screenFrames: [CGRect(x: 0, y: 0, width: 1920, height: 1080)]
)
let service = FullscreenDetectionService(
permissionManager: mockManager,
environmentProvider: environment
)
let expectation = expectation(description: "Fullscreen detected")
let cancellable = service.$isFullscreenActive
.dropFirst()
.sink { isActive in
if isActive {
expectation.fulfill()
}
}
service.forceUpdate()
wait(for: [expectation], timeout: 0.5)
cancellable.cancel()
}
func testFullscreenStateStaysFalseWhenWindowDoesNotMatchScreen() {
let mockManager = MockPermissionManager(status: ScreenCaptureAuthorizationStatus.authorized)
let environment = MockFullscreenEnvironment(
frontmostPID: 42,
windowDescriptors: [
FullscreenWindowDescriptor(
ownerPID: 42,
layer: 0,
bounds: CGRect(x: 100, y: 100, width: 800, height: 600)
)
],
screenFrames: [CGRect(x: 0, y: 0, width: 1920, height: 1080)]
)
let service = FullscreenDetectionService(
permissionManager: mockManager,
environmentProvider: environment
)
let expectation = expectation(description: "No fullscreen")
expectation.isInverted = true
let cancellable = service.$isFullscreenActive
.dropFirst()
.sink { isActive in
if isActive {
expectation.fulfill()
}
}
service.forceUpdate()
wait(for: [expectation], timeout: 0.5)
cancellable.cancel()
}
}
@MainActor
private final class MockPermissionManager: ScreenCapturePermissionManaging {
var authorizationStatus: ScreenCaptureAuthorizationStatus
var authorizationStatusPublisher: AnyPublisher<ScreenCaptureAuthorizationStatus, Never> {
Just(authorizationStatus).eraseToAnyPublisher()
}
init(status: ScreenCaptureAuthorizationStatus) {
self.authorizationStatus = status
}
func refreshStatus() {}
func requestAuthorizationIfNeeded() {}
func openSystemSettings() {}
}