mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-03 04:25:52 -05:00
Drive only the native dialog HWND owned by the tested portable
This commit is contained in:
1 parent
9c5e6c7164
commit
b03feae1ce
2 files changed
+47
-35
No files matched your search
@@ -1,24 +0,0 @@
|
||||
param([int] $AppProcessId, [string] $Filename)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
Add-Type -AssemblyName UIAutomationClient,UIAutomationTypes
|
||||
$ae = [System.Windows.Automation.AutomationElement]
|
||||
$scope = [System.Windows.Automation.TreeScope]
|
||||
$cond = [System.Windows.Automation.PropertyCondition]::new($ae::ProcessIdProperty, $AppProcessId)
|
||||
$stop = [datetime]::UtcNow.AddSeconds(40)
|
||||
do {
|
||||
$top = $ae::RootElement.FindAll($scope::Children, $cond)
|
||||
foreach ($window in $top) {
|
||||
if ($window.Current.ClassName -ne '#32770') { continue }
|
||||
$save = $window.FindFirst($scope::Descendants, [System.Windows.Automation.PropertyCondition]::new($ae::AutomationIdProperty, '1'))
|
||||
if (!$save -or $save.Current.ControlType -ne [System.Windows.Automation.ControlType]::Button) { continue }
|
||||
$edits = $window.FindAll($scope::Descendants, [System.Windows.Automation.PropertyCondition]::new($ae::ControlTypeProperty, [System.Windows.Automation.ControlType]::Edit))
|
||||
$field = $edits | Where-Object { $_.Current.AutomationId -eq '1001' -or $_.Current.Name -like 'File name*' } | Select-Object -First 1
|
||||
if (!$field) { continue }
|
||||
$field.GetCurrentPattern([System.Windows.Automation.ValuePattern]::Pattern).SetValue($Filename)
|
||||
Write-Host "Native picker '$($window.Current.Name)', confirmed '$Filename' with '$($save.Current.Name)'."
|
||||
$save.GetCurrentPattern([System.Windows.Automation.InvokePattern]::Pattern).Invoke()
|
||||
exit 0
|
||||
}
|
||||
Start-Sleep -Milliseconds 200
|
||||
} until ([datetime]::UtcNow -gt $stop)
|
||||
throw "No native file-name control in a dialog owned by process $AppProcessId."
|
||||
+47
-11
@@ -1,4 +1,6 @@
|
||||
"""Exercise Windows native file dialogs on the signed portable in an isolated hosted desktop."""
|
||||
import ctypes
|
||||
from ctypes import wintypes
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
@@ -60,17 +62,51 @@ try:
|
||||
def object_count():
|
||||
return sum(len(layer["children"]) for layer in engine("document.inspect")["layers"])
|
||||
def picker(filename, before):
|
||||
# The native dialog is on its own thread; start the PID-scoped responder before invoking the UI action.
|
||||
responder = subprocess.Popen(["powershell.exe","-NoProfile","-File",str(Path(__file__).with_name("qa-fill-save.ps1")),
|
||||
"-AppProcessId",str(process.pid),"-Filename",str(filename)])
|
||||
try:
|
||||
before()
|
||||
assert responder.wait(timeout=45)==0,filename
|
||||
wait(lambda: filename.exists() and filename.stat().st_size>0, f"Missing {filename}")
|
||||
wait(lambda: not state()["fileDialog"], "Picker did not close")
|
||||
finally:
|
||||
if responder.poll() is None:
|
||||
responder.kill()
|
||||
before()
|
||||
user=ctypes.WinDLL("user32",use_last_error=True)
|
||||
callback=ctypes.WINFUNCTYPE(wintypes.BOOL,wintypes.HWND,wintypes.LPARAM)
|
||||
user.GetClassNameW.argtypes=[wintypes.HWND,wintypes.LPWSTR,ctypes.c_int]
|
||||
user.GetWindowTextW.argtypes=[wintypes.HWND,wintypes.LPWSTR,ctypes.c_int]
|
||||
user.GetDlgCtrlID.argtypes=[wintypes.HWND]
|
||||
user.GetWindowThreadProcessId.argtypes=[wintypes.HWND,ctypes.POINTER(wintypes.DWORD)]
|
||||
user.EnumChildWindows.argtypes=[wintypes.HWND,callback,wintypes.LPARAM]
|
||||
user.EnumWindows.argtypes=[callback,wintypes.LPARAM]
|
||||
user.IsWindowVisible.argtypes=[wintypes.HWND]
|
||||
user.SendMessageW.argtypes=[wintypes.HWND,wintypes.UINT,wintypes.WPARAM,wintypes.LPARAM]
|
||||
user.SendMessageW.restype=wintypes.LPARAM
|
||||
user.PostMessageW.argtypes=[wintypes.HWND,wintypes.UINT,wintypes.WPARAM,wintypes.LPARAM]
|
||||
def controls(parent=None):
|
||||
result=[]
|
||||
@callback
|
||||
def add(hwnd,unused):
|
||||
pid=wintypes.DWORD()
|
||||
user.GetWindowThreadProcessId(hwnd,ctypes.byref(pid))
|
||||
if pid.value==process.pid and user.IsWindowVisible(hwnd):
|
||||
classname=ctypes.create_unicode_buffer(256)
|
||||
title=ctypes.create_unicode_buffer(256)
|
||||
user.GetClassNameW(hwnd,classname,len(classname))
|
||||
user.GetWindowTextW(hwnd,title,len(title))
|
||||
result.append((hwnd,classname.value,user.GetDlgCtrlID(hwnd),title.value))
|
||||
return True
|
||||
if parent:
|
||||
user.EnumChildWindows(parent,add,0)
|
||||
else:
|
||||
user.EnumWindows(add,0)
|
||||
return result
|
||||
time.sleep(1)
|
||||
print("Active app dialog", state()["fileDialog"], "top windows",controls(),flush=True)
|
||||
dialog=wait(lambda: next((c for c in controls() if c[1]=="#32770"),None),"No owned native file dialog")
|
||||
children=controls(dialog[0])
|
||||
print("Native picker",dialog[3],"controls",[(c[1],c[2],c[3]) for c in children],flush=True)
|
||||
edits=[c for c in children if c[1]=="Edit"]
|
||||
field=next((c for c in edits if c[2]==1001),edits[0] if len(edits)==1 else None)
|
||||
button=next((c for c in children if c[1]=="Button" and c[2]==1),None)
|
||||
assert field and button, (edits,button)
|
||||
name=ctypes.create_unicode_buffer(str(filename))
|
||||
assert user.SendMessageW(field[0],12,0,ctypes.addressof(name))
|
||||
assert user.PostMessageW(button[0],245,0,0)
|
||||
wait(lambda: filename.exists() and filename.stat().st_size>0, f"Missing {filename}")
|
||||
wait(lambda: not state()["fileDialog"], "Picker did not close")
|
||||
def shortcut(**mods):
|
||||
return call("ui.key",key="s",cmd=True,ctrl=True,**mods)
|
||||
call("auth",token=token)
|
||||
|
||||
Reference in new issue
Block a user