fix: allow recording outside protected fields
This commit is contained in:
@@ -425,6 +425,35 @@ struct HungTranscriptionTests {
|
||||
@Suite("dictationStartRefusal")
|
||||
struct DictationStartRefusalTests {
|
||||
|
||||
@Test func backgroundSecureKeyboardInputDoesNotBlockOrdinaryFieldRecording() {
|
||||
#expect(dictationStartRefusal(modelReady: true, isRecording: false,
|
||||
isBusy: false, secureInputActive: true,
|
||||
focusedInputProtected: false) == nil)
|
||||
}
|
||||
|
||||
@Test func actualProtectedFieldBlocksEvenWithoutGlobalKeyboardFlag() {
|
||||
for globalSecureInput in [false, true] {
|
||||
#expect(dictationStartRefusal(modelReady: true, isRecording: false,
|
||||
isBusy: false, secureInputActive: globalSecureInput,
|
||||
focusedInputProtected: true) == .secureInputActive)
|
||||
}
|
||||
}
|
||||
|
||||
@Test func ordinaryFieldRetainsModelAndBusyGuards() {
|
||||
#expect(dictationStartRefusal(modelReady: false, isRecording: false,
|
||||
isBusy: false, secureInputActive: true,
|
||||
focusedInputProtected: false) == .modelNotReady)
|
||||
#expect(dictationStartRefusal(modelReady: false, isRecording: false,
|
||||
isBusy: false, secureInputActive: true,
|
||||
modelWarming: true, focusedInputProtected: false) == nil)
|
||||
#expect(dictationStartRefusal(modelReady: true, isRecording: true,
|
||||
isBusy: false, secureInputActive: true,
|
||||
focusedInputProtected: false) == .alreadyRecording)
|
||||
#expect(dictationStartRefusal(modelReady: true, isRecording: false,
|
||||
isBusy: true, secureInputActive: true,
|
||||
focusedInputProtected: false) == .transcriptionInFlight)
|
||||
}
|
||||
|
||||
/// Защищённый ввод: запись не стартует, причина названа — звонит отказ.
|
||||
@Test func secureInputBlocksRecording() {
|
||||
#expect(dictationStartRefusal(modelReady: true,
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import AppKit
|
||||
import ApplicationServices
|
||||
import Testing
|
||||
|
||||
@testable import IrizDictate
|
||||
|
||||
@Suite("Защита поля не равна глобальной защите клавиатуры")
|
||||
@MainActor
|
||||
struct FocusedInputProtectionTests {
|
||||
private func protection(role: String? = "AXTextField",
|
||||
roleError: AXError = .success,
|
||||
subrole: String? = nil,
|
||||
subroleError: AXError = .attributeUnsupported,
|
||||
protected: Bool? = nil,
|
||||
protectedError: AXError = .attributeUnsupported) -> Bool? {
|
||||
Permissions.inputProtection { attribute in
|
||||
switch attribute as String {
|
||||
case kAXRoleAttribute:
|
||||
return (roleError, role.map { $0 as CFString })
|
||||
case kAXSubroleAttribute:
|
||||
return (subroleError, subrole.map { $0 as CFString })
|
||||
case NSAccessibility.Attribute.containsProtectedContent.rawValue:
|
||||
return (protectedError, protected.map { NSNumber(value: $0) })
|
||||
default:
|
||||
Issue.record("Неожиданный запрос атрибута: \(attribute)")
|
||||
return (.attributeUnsupported, nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test func парольЗащищёнПриЛюбомГлобальномФлаге() {
|
||||
let focused = protection(subrole: kAXSecureTextFieldSubrole, subroleError: .success)
|
||||
#expect(focused == true)
|
||||
for global in [false, true] {
|
||||
#expect(dictationInputIsProtected(secureInputActive: global, focusedInputProtected: focused))
|
||||
}
|
||||
}
|
||||
|
||||
@Test func защищённоеСодержимоеНеТребуетПарольнойПодроли() {
|
||||
#expect(protection(role: "AXTextArea", protected: true, protectedError: .success) == true)
|
||||
#expect(protection(subroleError: .cannotComplete,
|
||||
protected: true, protectedError: .success) == true)
|
||||
#expect(protection(roleError: .cannotComplete,
|
||||
protected: true, protectedError: .success) == true)
|
||||
#expect(protection(roleError: .cannotComplete,
|
||||
subrole: kAXSecureTextFieldSubrole, subroleError: .success) == true)
|
||||
}
|
||||
|
||||
@Test func обычноеПолеИОкноНеБлокируютсяФоновымФлагом() {
|
||||
for role in ["AXTextField", "AXTextArea", "AXWindow"] {
|
||||
let focused = protection(role: role)
|
||||
#expect(focused == false)
|
||||
#expect(!dictationInputIsProtected(secureInputActive: true, focusedInputProtected: focused))
|
||||
}
|
||||
#expect(protection(role: "AXWindow", subrole: "AXStandardWindow", subroleError: .success,
|
||||
protected: false, protectedError: .success) == false)
|
||||
#expect(protection(subroleError: .noValue, protectedError: .noValue) == false)
|
||||
}
|
||||
|
||||
@Test func ошибкаИОтсутствующаяРольОставляютСостояниеНеизвестным() {
|
||||
for error: AXError in [.cannotComplete, .invalidUIElement, .attributeUnsupported, .noValue] {
|
||||
#expect(protection(roleError: error) == nil)
|
||||
}
|
||||
#expect(protection(role: nil) == nil)
|
||||
#expect(protection(role: "") == nil)
|
||||
#expect(protection(subroleError: .cannotComplete) == nil)
|
||||
#expect(protection(protectedError: .cannotComplete) == nil)
|
||||
#expect(protection(subroleError: .success) == nil)
|
||||
#expect(protection(protectedError: .success) == nil)
|
||||
#expect(dictationInputIsProtected(secureInputActive: true, focusedInputProtected: nil))
|
||||
#expect(!dictationInputIsProtected(secureInputActive: false, focusedInputProtected: nil))
|
||||
}
|
||||
|
||||
@Test func запросОграниченМетаданнымиБезЗначенияИВыделения() {
|
||||
var requested: [String] = []
|
||||
let result = Permissions.inputProtection { attribute in
|
||||
let name = attribute as String
|
||||
requested.append(name)
|
||||
if name == kAXRoleAttribute { return (.success, "AXTextArea" as CFString) }
|
||||
return (.attributeUnsupported, nil)
|
||||
}
|
||||
#expect(result == false)
|
||||
#expect(requested == [kAXRoleAttribute, kAXSubroleAttribute,
|
||||
NSAccessibility.Attribute.containsProtectedContent.rawValue])
|
||||
#expect(!requested.contains(kAXValueAttribute))
|
||||
#expect(!requested.contains(kAXSelectedTextAttribute))
|
||||
}
|
||||
}
|
||||
@@ -168,6 +168,47 @@ struct HotkeyAutomatonTests {
|
||||
#expect(result.suppress)
|
||||
}
|
||||
|
||||
@Test func readinessIsLazyForEveryToggleRecordingRoute() {
|
||||
let routes: [(CGKeyCode, HotkeyTransitionAction, HotkeyTransitionAction)] = [
|
||||
(96, .press, .release),
|
||||
(97, .pressPrompt, .releasePrompt),
|
||||
(98, .pressTranslation, .releaseTranslation),
|
||||
]
|
||||
for (keycode, start, stop) in routes {
|
||||
var state = HotkeyTransitionState()
|
||||
var readinessCalls = 0
|
||||
func ready() -> Bool {
|
||||
readinessCalls += 1
|
||||
return true
|
||||
}
|
||||
func send(_ type: CGEventType, _ keycode: CGKeyCode,
|
||||
isRecording: Bool = false) -> HotkeyTransitionResult {
|
||||
state.transition(for: keyEvent(type, keycode),
|
||||
hotkey: hotkeyChoice(forKeycode: 96),
|
||||
historyHotkey: hotkeyChoice(forKeycode: 100),
|
||||
promptHotkey: hotkeyChoice(forKeycode: 97),
|
||||
promptHotkeyEnabled: true,
|
||||
translationHotkey: hotkeyChoice(forKeycode: 98),
|
||||
translationHotkeyEnabled: true,
|
||||
triggerMode: .toggle,
|
||||
isRecording: isRecording,
|
||||
canStartRecording: ready())
|
||||
}
|
||||
#expect(send(.keyDown, 0).actions.isEmpty)
|
||||
#expect(send(.keyUp, 0).actions.isEmpty)
|
||||
#expect(send(.keyDown, 100).actions == [.showHistory])
|
||||
_ = send(.keyUp, 100)
|
||||
#expect(readinessCalls == 0)
|
||||
|
||||
#expect(send(.keyDown, keycode).actions == [start])
|
||||
#expect(readinessCalls == 1)
|
||||
_ = send(.keyUp, keycode, isRecording: true)
|
||||
#expect(readinessCalls == 1)
|
||||
#expect(send(.keyDown, keycode, isRecording: true).actions == [stop])
|
||||
#expect(readinessCalls == 1)
|
||||
}
|
||||
}
|
||||
|
||||
@Test func toggleReleaseIsNoOpButSuppressed() {
|
||||
var state = HotkeyTransitionState()
|
||||
_ = state.transition(for: flagsChanged(54, .maskCommand),
|
||||
|
||||
Reference in New Issue
Block a user