Ship the Files Markdown startup retry and apply word-boundary checks to all snippet triggers.
544 lines
26 KiB
PowerShell
544 lines
26 KiB
PowerShell
param(
|
|
[Parameter(Mandatory)][string]$Executable,
|
|
[string]$Screenshot,
|
|
[string]$SearchScreenshot,
|
|
[string]$Node = 'node',
|
|
[string]$LanFixture
|
|
)
|
|
$ErrorActionPreference = 'Stop'
|
|
Add-Type @"
|
|
using System;
|
|
using System.Text;
|
|
using System.Runtime.InteropServices;
|
|
public static class MarkdownUi {
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
struct PropertyKey {
|
|
public Guid Format;
|
|
public uint Id;
|
|
}
|
|
[StructLayout(LayoutKind.Explicit, Size = 24)]
|
|
struct PropertyValue {
|
|
[FieldOffset(0)] public ushort Type;
|
|
[FieldOffset(8)] public IntPtr Text;
|
|
}
|
|
[ComImport, Guid("886d8eeb-8cf2-4446-8d02-cdba1dbdcf99"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
|
interface IPropertyStore {
|
|
void GetCount(out uint count);
|
|
void GetAt(uint index, out PropertyKey key);
|
|
void GetValue(ref PropertyKey key, out PropertyValue value);
|
|
}
|
|
[DllImport("shell32.dll", PreserveSig = false)]
|
|
static extern void SHGetPropertyStoreForWindow(IntPtr window, ref Guid iid, out IPropertyStore store);
|
|
[DllImport("ole32.dll")] static extern int PropVariantClear(ref PropertyValue value);
|
|
|
|
public static string TaskbarProperty(IntPtr window, uint property) {
|
|
var iid = typeof(IPropertyStore).GUID;
|
|
var key = new PropertyKey { Format = new Guid("9f4c2855-9f79-4b39-a8d0-e1d42de1d5f3"), Id = property };
|
|
SHGetPropertyStoreForWindow(window, ref iid, out var store);
|
|
try {
|
|
store.GetValue(ref key, out var value);
|
|
try { return value.Type == 31 ? Marshal.PtrToStringUni(value.Text) : null; }
|
|
finally { PropVariantClear(ref value); }
|
|
} finally { Marshal.ReleaseComObject(store); }
|
|
}
|
|
|
|
[DllImport("user32.dll", CharSet=CharSet.Unicode)] public static extern IntPtr FindWindowEx(IntPtr parent, IntPtr after, string type, string title);
|
|
[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr window, out uint pid);
|
|
[DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr window);
|
|
[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
|
|
[DllImport("user32.dll")] static extern bool SetForegroundWindow(IntPtr window);
|
|
[DllImport("user32.dll")] static extern void keybd_event(byte key, byte scan, uint flags, UIntPtr extra);
|
|
public static void Activate(IntPtr window) {
|
|
if (GetForegroundWindow() == window) return;
|
|
keybd_event(0x12,0,0,UIntPtr.Zero);
|
|
keybd_event(0x12,0,2,UIntPtr.Zero);
|
|
SetForegroundWindow(window);
|
|
}
|
|
public static void CycleWindow(bool reverse = false) {
|
|
keybd_event(0x11,0,0,UIntPtr.Zero);
|
|
if (reverse) keybd_event(0x10,0,0,UIntPtr.Zero);
|
|
keybd_event(0x09,0,0,UIntPtr.Zero);
|
|
keybd_event(0x09,0,2,UIntPtr.Zero);
|
|
if (reverse) keybd_event(0x10,0,2,UIntPtr.Zero);
|
|
keybd_event(0x11,0,2,UIntPtr.Zero);
|
|
}
|
|
[DllImport("user32.dll")] public static extern IntPtr GetDlgItem(IntPtr window, int id);
|
|
[DllImport("user32.dll", CharSet=CharSet.Unicode)] public static extern int GetWindowText(IntPtr window, StringBuilder title, int capacity);
|
|
[DllImport("user32.dll", EntryPoint="SendMessageW")] public static extern IntPtr Send(IntPtr window, uint msg, IntPtr w, IntPtr l);
|
|
[DllImport("user32.dll", EntryPoint="SendMessageW", CharSet=CharSet.Unicode)] public static extern IntPtr SendText(IntPtr window, uint msg, IntPtr w, string l);
|
|
[DllImport("user32.dll")] public static extern bool PostMessage(IntPtr window, uint msg, IntPtr w, IntPtr l);
|
|
}
|
|
"@
|
|
|
|
function Wait-For([string]$Name, [scriptblock]$Check) {
|
|
for ($i=0; $i -lt 150; $i++) {
|
|
$value = & $Check
|
|
if ($value) { return $value }
|
|
Start-Sleep -Milliseconds 100
|
|
}
|
|
throw "Timed out waiting for $Name"
|
|
}
|
|
|
|
function Find-Window([string]$Class, [string]$Title = '', [IntPtr]$Except = 0) {
|
|
$window = [IntPtr]::Zero
|
|
while (($window = [MarkdownUi]::FindWindowEx(0,$window,$Class,[NullString]::Value)) -ne [IntPtr]::Zero) {
|
|
[uint32]$pidFound = 0
|
|
[void][MarkdownUi]::GetWindowThreadProcessId($window,[ref]$pidFound)
|
|
if ($pidFound -ne $process.Id -or $window -eq $Except -or ![MarkdownUi]::IsWindowVisible($window)) { continue }
|
|
$buffer = [Text.StringBuilder]::new(2048)
|
|
[void][MarkdownUi]::GetWindowText($window,$buffer,$buffer.Capacity)
|
|
if ($buffer.ToString() -like "*$Title*") { return $window }
|
|
}
|
|
}
|
|
|
|
function Post($Window, $Message, $Key) {
|
|
if (![MarkdownUi]::PostMessage($Window,$Message,$Key,0)) { throw 'Could not drive the Files window.' }
|
|
}
|
|
|
|
function Open-File($File, $Key) {
|
|
$row = [MarkdownUi]::SendText($panel,0x1A2,-1,$File)
|
|
if ($row.ToInt64() -lt 0) { throw "Missing row $File" }
|
|
[void][MarkdownUi]::Send($panel,0x186,$row,0)
|
|
Post $panel 0x100 $Key
|
|
}
|
|
|
|
function Browser($Scenario, $Image = '', $Title = '') {
|
|
& $Node (Join-Path $PSScriptRoot 'files_markdown_browser.mjs') $port $Scenario $Image $Title
|
|
if ($LASTEXITCODE) { throw "WebView2 verification failed for $Scenario" }
|
|
}
|
|
|
|
function Wait-Foreground($Window) {
|
|
$buffer = [Text.StringBuilder]::new(2048)
|
|
[void][MarkdownUi]::GetWindowText($Window,$buffer,$buffer.Capacity)
|
|
[void](Wait-For "foreground window $buffer" { [MarkdownUi]::GetForegroundWindow() -eq $Window })
|
|
}
|
|
|
|
function Scintilla($Window) {
|
|
[MarkdownUi]::FindWindowEx($Window,0,'Scintilla',[NullString]::Value)
|
|
}
|
|
|
|
function Assert-ReopenedMarkdown($Window, $File) {
|
|
try { Browser 'reopen' '' $File }
|
|
finally {
|
|
if ([MarkdownUi]::IsWindowVisible((Scintilla $Window))) { throw "$File opened as raw text." }
|
|
}
|
|
}
|
|
|
|
function Close-Preview($Window) {
|
|
Post $Window 0x10 0
|
|
[void](Wait-For 'the Markdown preview to close' { ![MarkdownUi]::IsWindowVisible($Window) })
|
|
}
|
|
|
|
function Assert-TextWindowAppearance($Window, [string]$Mode) {
|
|
$identity = "HrynCo.KSwitcher.Files.$Mode"
|
|
$resource = if($Mode -eq 'Editor') { ',-104' } else { ',-103' }
|
|
[void](Wait-For "the $Mode taskbar group" { [MarkdownUi]::TaskbarProperty($Window,5) -ceq $identity })
|
|
$taskbarIcon = [MarkdownUi]::TaskbarProperty($Window,3)
|
|
if (!$taskbarIcon -or !$taskbarIcon.EndsWith($resource)) {
|
|
throw "$Mode taskbar icon was '$taskbarIcon'."
|
|
}
|
|
$small = [MarkdownUi]::Send($Window,0x7f,0,0)
|
|
$large = [MarkdownUi]::Send($Window,0x7f,1,0)
|
|
if (!$small.ToInt64() -or !$large.ToInt64() -or $small -eq $large) {
|
|
throw "$Mode must expose both a small title-bar icon and a large switcher icon."
|
|
}
|
|
@{ Small = $small; Large = $large }
|
|
}
|
|
|
|
function Append-Character($Control, [char]$Character) {
|
|
[void][MarkdownUi]::Send($Control,2318,0,0)
|
|
[void][MarkdownUi]::Send($Control,0x102,[int]$Character,0)
|
|
}
|
|
|
|
function Answer-Save($Button) {
|
|
$dialog = Wait-For 'the save confirmation' {
|
|
$candidate = Find-Window '#32770'
|
|
if ($candidate -and [MarkdownUi]::GetDlgItem($candidate,7) -ne [IntPtr]::Zero) { $candidate }
|
|
}
|
|
Post $dialog 0x111 $Button
|
|
[void](Wait-For 'the save confirmation to close' { ![MarkdownUi]::IsWindowVisible($dialog) })
|
|
}
|
|
|
|
$source = Split-Path (Resolve-Path -LiteralPath $Executable)
|
|
$root = Join-Path ([IO.Path]::GetTempPath()) ('ks-markdown-test-' + [Guid]::NewGuid().ToString('N'))
|
|
$app = Join-Path $root 'app'
|
|
$docs = Join-Path $root 'docs'
|
|
$profileCaptured = $false
|
|
$profile = [Microsoft.Win32.Registry]::CurrentUser.CreateSubKey('Software\KSwitcher\Files')
|
|
$saved = @{}
|
|
$profileValues = 'LeftPath','RightPath','LeftCursor','RightCursor','WindowPlacement','OptionsLocation'
|
|
$process = $null
|
|
$flags = $env:WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS
|
|
$data = $env:WEBVIEW2_USER_DATA_FOLDER
|
|
try {
|
|
New-Item -ItemType Directory -Path $app,$docs,"$docs\child","$docs\images" | Out-Null
|
|
Copy-Item -LiteralPath $Executable,"$source\WebView2Loader.dll","$source\terminal" -Destination $app -Recurse
|
|
$fixture = @'
|
|
# Перегляд Markdown
|
|
|
|
| Header |
|
|
| ------ |
|
|
| Cell |
|
|
| <span id="nowrap-cell" style="white-space: nowrap; color: red; position: fixed" onclick="void 0">In Development</span> |
|
|
|
|
<table id="html-table">
|
|
<caption>Raw HTML table</caption>
|
|
<tr><th colspan="2">Priority</th></tr>
|
|
<tr><td><strong>Highest</strong></td><td>—</td></tr>
|
|
</table>
|
|
|
|
- [ ] Pending
|
|
- [x] Complete
|
|
|
|
## Збіг пошуку
|
|
|
|
Рядок для **збіг пошуку**.
|
|
|
|

|
|

|
|
<img alt="HTML relative image" src="images/tiny%20image.png">
|
|
<a href="child/Other.md#target-heading">Child</a>
|
|
|
|
~~~mermaid
|
|
flowchart TD
|
|
A[Render target] -->|Transition| B[Result]
|
|
~~~
|
|
|
|
~~~mermaid
|
|
this is not a diagram
|
|
~~~
|
|
|
|
~~~js
|
|
const value = 42;
|
|
~~~
|
|
|
|
<iframe src="https://example.invalid">Raw HTML</iframe>
|
|
'@
|
|
$original = Join-Path $docs 'Preview.md'
|
|
[IO.File]::WriteAllText($original,$fixture)
|
|
[IO.File]::WriteAllText("$docs\Reopen.md",'# Reopened Markdown')
|
|
[IO.File]::WriteAllText("$docs\Second.md",'# Second Markdown')
|
|
$childText = '# Linked Markdown' + "`n`n" + (("Filler paragraph.`n`n") * 60) + '## Target heading'
|
|
[IO.File]::WriteAllText("$docs\child\Other.md",$childText)
|
|
[IO.File]::WriteAllText("$docs\Plain.txt",'Plain text')
|
|
$largeFile = [IO.File]::Create("$docs\Large.md")
|
|
try {
|
|
$line = [Text.Encoding]::UTF8.GetBytes(("# Large Markdown file`n" * 1024))
|
|
while ($largeFile.Length -le 8MB) { $largeFile.Write($line,0,$line.Length) }
|
|
} finally { $largeFile.Dispose() }
|
|
[IO.File]::WriteAllBytes("$docs\images\tiny image.png",[Convert]::FromBase64String(
|
|
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jBo0AAAAASUVORK5CYII='))
|
|
foreach ($name in $profileValues) {
|
|
if ($name -in $profile.GetValueNames()) {
|
|
$saved[$name] = @($profile.GetValue($name),$profile.GetValueKind($name))
|
|
}
|
|
}
|
|
$profileCaptured = $true
|
|
$profile.SetValue('LeftPath',$docs)
|
|
$profile.SetValue('RightPath',$docs)
|
|
foreach ($name in 'LeftCursor','RightCursor','WindowPlacement','OptionsLocation') { $profile.DeleteValue($name,$false) }
|
|
|
|
$listener = [Net.Sockets.TcpListener]::new([Net.IPAddress]::Loopback,0)
|
|
$listener.Start()
|
|
$port = $listener.LocalEndpoint.Port
|
|
$listener.Stop()
|
|
$env:WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS = "--remote-debugging-port=$port --disable-background-networking"
|
|
$env:WEBVIEW2_USER_DATA_FOLDER = Join-Path $root 'webview'
|
|
$process = Start-Process -FilePath (Join-Path $app (Split-Path -Leaf $Executable)) -PassThru -WindowStyle Normal
|
|
$main = Wait-For 'Files' { Find-Window 'KSwitcher.Files' }
|
|
[MarkdownUi]::Activate($main)
|
|
$panel = [MarkdownUi]::GetDlgItem($main,102)
|
|
|
|
$previewScript = Join-Path $app 'terminal\markdown.js'
|
|
$originalScript = [IO.File]::ReadAllText($previewScript)
|
|
try {
|
|
# Let the page load without sending the ready message until Files starts a new WebView.
|
|
[IO.File]::WriteAllText($previewScript,"document.documentElement.dataset.startup = 'stalled';")
|
|
Open-File 'Reopen.md' 0x72
|
|
$window = Wait-For 'the stalled Markdown viewer' { Find-Window 'KSwitcher.Files.Text' 'Reopen.md' }
|
|
Browser 'startup-stalled'
|
|
} finally { [IO.File]::WriteAllText($previewScript,$originalScript) }
|
|
Assert-ReopenedMarkdown $window 'Reopen.md'
|
|
Close-Preview $window
|
|
Write-Output 'Verified that the same viewer renders Markdown after a stalled WebView2 startup.'
|
|
|
|
Open-File 'Reopen.md' 0x72
|
|
$window = Wait-For 'the Markdown viewer before early close' { Find-Window 'KSwitcher.Files.Text' 'Reopen.md' }
|
|
Close-Preview $window
|
|
foreach ($file in 'Reopen.md','Second.md','Reopen.md','Second.md','Reopen.md','Second.md') {
|
|
Open-File $file 0x72
|
|
$window = Wait-For "the reopened $file viewer" { Find-Window 'KSwitcher.Files.Text' $file }
|
|
Assert-ReopenedMarkdown $window $file
|
|
Close-Preview $window
|
|
}
|
|
Write-Output 'Verified six immediate Markdown reopens after closing the initial preview during startup.'
|
|
|
|
Open-File 'Preview.md' 0x72
|
|
$window = Wait-For 'the Markdown viewer' { Find-Window 'KSwitcher.Files.Text' 'Viewer' }
|
|
$viewerIcons = Assert-TextWindowAppearance $window 'Viewer'
|
|
if ([MarkdownUi]::IsWindowVisible((Scintilla $window))) {
|
|
throw 'F3 showed the source text while starting the Markdown preview.'
|
|
}
|
|
Browser 'render' $Screenshot
|
|
Post $window 0x111 3
|
|
Browser 'search-menu'
|
|
Browser 'search' $SearchScreenshot
|
|
Post $main 0x111 133
|
|
$options = Wait-For 'the shared Files Options dialog' { Find-Window '#32770' 'KSwitcher Files Options' }
|
|
[void][MarkdownUi]::SendText([MarkdownUi]::GetDlgItem($options,270),0x0C,0,'Markdown')
|
|
[void](Wait-For 'the Markdown settings section' { [MarkdownUi]::IsWindowVisible([MarkdownUi]::GetDlgItem($options,374)) })
|
|
foreach($field in @(@(374,'1200'),@(376,'Georgia'),@(379,'18'))){
|
|
[void][MarkdownUi]::SendText([MarkdownUi]::GetDlgItem($options,$field[0]),0x0C,0,$field[1])
|
|
}
|
|
Post $options 0x111 1
|
|
[void](Wait-For 'Options to close after saving Markdown settings' { ![MarkdownUi]::IsWindowVisible($options) })
|
|
Browser 'appearance-width'
|
|
|
|
Post $main 0x111 133
|
|
$options = Wait-For 'reopened Files Options' { Find-Window '#32770' 'KSwitcher Files Options' }
|
|
if (![MarkdownUi]::IsWindowVisible([MarkdownUi]::GetDlgItem($options,374))) {
|
|
throw 'Files Options did not restore its last section.'
|
|
}
|
|
[void][MarkdownUi]::SendText([MarkdownUi]::GetDlgItem($options,374),0x0C,0,'0')
|
|
Post $options 0x111 2
|
|
[void](Wait-For 'Options to close on Cancel' { ![MarkdownUi]::IsWindowVisible($options) })
|
|
Browser 'appearance-width'
|
|
|
|
Post $main 0x111 133
|
|
$options = Wait-For 'Files Options after Cancel' { Find-Window '#32770' 'KSwitcher Files Options' }
|
|
if (![MarkdownUi]::IsWindowVisible([MarkdownUi]::GetDlgItem($options,374))) {
|
|
throw 'Cancel did not preserve the last Options section.'
|
|
}
|
|
[void][MarkdownUi]::SendText([MarkdownUi]::GetDlgItem($options,374),0x0C,0,'0')
|
|
Post $options 0x111 1
|
|
[void](Wait-For 'Options to close after saving full width' { ![MarkdownUi]::IsWindowVisible($options) })
|
|
Browser 'appearance-full'
|
|
Write-Output 'Verified live Markdown width and font settings, Cancel and reopening the last Options section.'
|
|
Browser 'toggle-first-task'
|
|
$checkedFixture=$fixture.Replace('- [ ] Pending','- [x] Pending')
|
|
[void](Wait-For 'Markdown checkbox saved to the source file' { [IO.File]::ReadAllText($original) -ceq $checkedFixture })
|
|
Browser 'close'
|
|
[void](Wait-For 'the initial preview to close' { ![MarkdownUi]::IsWindowVisible($window) })
|
|
[MarkdownUi]::Activate($main)
|
|
Wait-Foreground $main
|
|
Open-File 'Preview.md' 0x72
|
|
$window=Wait-For 'the reopened Markdown preview' { Find-Window 'KSwitcher.Files.Text' 'Viewer' }
|
|
Browser 'first-task-checked'
|
|
Browser 'toggle-first-task'
|
|
[void](Wait-For 'the unchecked Markdown marker to save' { [IO.File]::ReadAllText($original) -ceq $fixture })
|
|
[IO.File]::WriteAllText($original,($fixture.Replace('Перегляд Markdown','Зміна на диску')))
|
|
Browser 'Зміна на диску' '' 'Preview.md'
|
|
$replacement = Join-Path $docs 'Preview-replacement.md'
|
|
[IO.File]::WriteAllText($replacement,$fixture)
|
|
[IO.File]::Move($replacement,$original,$true)
|
|
Browser 'Перегляд Markdown' '' 'Preview.md'
|
|
if ((Find-Window 'KSwitcher.Files.Text' 'Preview.md') -ne $window) { throw 'Reload changed windows.' }
|
|
Browser 'edit'
|
|
$editor = Wait-For 'F6 in WebView2 to open the editor' { Find-Window 'KSwitcher.Files.Text' 'Editor' }
|
|
if ($editor -ne $window) { throw 'F6 changed windows.' }
|
|
$editorIcons = Assert-TextWindowAppearance $window 'Editor'
|
|
if ($editorIcons.Small -eq $viewerIcons.Small -or $editorIcons.Large -eq $viewerIcons.Large) {
|
|
throw 'F6 did not replace both viewer icons with editor icons.'
|
|
}
|
|
[MarkdownUi]::Activate($window)
|
|
Wait-Foreground $window
|
|
[MarkdownUi]::CycleWindow()
|
|
Wait-Foreground $main
|
|
[MarkdownUi]::CycleWindow()
|
|
Wait-Foreground $window
|
|
Write-Output 'Verified Ctrl+Tab between Files and the Markdown editor.'
|
|
$control = Scintilla $window
|
|
if ([MarkdownUi]::Send($control,2140,0,0).ToInt64()) { throw 'The editor is read-only.' }
|
|
Append-Character $control 'X'
|
|
Post $control 0x100 0x75
|
|
Answer-Save 2
|
|
if ((Find-Window 'KSwitcher.Files.Text' 'Editor') -ne $window -or ![MarkdownUi]::Send($control,2159,0,0).ToInt64()) {
|
|
throw 'Cancel lost unsaved changes.'
|
|
}
|
|
Post $control 0x100 0x75
|
|
Answer-Save 7
|
|
Browser 'Перегляд Markdown'
|
|
$viewerIcons = Assert-TextWindowAppearance $window 'Viewer'
|
|
if ($viewerIcons.Small -eq $editorIcons.Small -or $viewerIcons.Large -eq $editorIcons.Large) {
|
|
throw 'F6 did not restore both viewer icons.'
|
|
}
|
|
if ([IO.File]::ReadAllText($original) -cne $fixture) { throw 'Discard changed the Markdown file.' }
|
|
Browser 'ctrl-follow'
|
|
if ((Find-Window 'KSwitcher.Files.Text' 'Preview.md') -ne $window -or (Find-Window 'KSwitcher.Files.Text' 'Other.md')) {
|
|
throw 'Ctrl+click navigated without tabs.'
|
|
}
|
|
Browser 'shift-follow'
|
|
$child = Wait-For 'the Shift+click Markdown window' { Find-Window 'KSwitcher.Files.Text' 'Other.md' $window }
|
|
[void](Assert-TextWindowAppearance $child 'Viewer')
|
|
Browser 'Linked Markdown' '' 'Other.md'
|
|
[MarkdownUi]::Activate($child)
|
|
Wait-Foreground $child
|
|
Browser 'cycle' '' 'Other.md'
|
|
Wait-Foreground $main
|
|
[MarkdownUi]::CycleWindow()
|
|
Wait-Foreground $window
|
|
Browser 'cycle' '' 'Preview.md'
|
|
Wait-Foreground $child
|
|
Browser 'cycle-reverse' '' 'Other.md'
|
|
Wait-Foreground $window
|
|
Browser 'edit' '' 'Preview.md'
|
|
[void](Wait-For 'the first window to switch to Editor' { Find-Window 'KSwitcher.Files.Text' 'Editor' })
|
|
[MarkdownUi]::CycleWindow($true)
|
|
Wait-Foreground $main
|
|
[MarkdownUi]::CycleWindow($true)
|
|
Wait-Foreground $child
|
|
Write-Output 'Verified backward Ctrl+Shift+Tab cycling through three windows and wrapping at Files.'
|
|
Browser 'close' '' 'Other.md'
|
|
[void](Wait-For 'Ctrl+W to close the Shift+click window' { ![MarkdownUi]::IsWindowVisible($child) })
|
|
Post (Scintilla $window) 0x100 0x75
|
|
Browser 'Перегляд Markdown' '' 'Preview.md'
|
|
Browser 'follow'
|
|
if ((Wait-For 'the in-place Markdown viewer' { Find-Window 'KSwitcher.Files.Text' 'Other.md' }) -ne $window) {
|
|
throw 'A normal click did not stay in the same window.'
|
|
}
|
|
Browser 'Linked Markdown' '' 'Other.md'
|
|
Browser 'mouse-back' '' 'Other.md'
|
|
Browser 'Перегляд Markdown' '' 'Preview.md'
|
|
Browser 'mouse-forward' '' 'Preview.md'
|
|
Browser 'Linked Markdown' '' 'Other.md'
|
|
Browser 'back' '' 'Other.md'
|
|
Browser 'Перегляд Markdown' '' 'Preview.md'
|
|
Browser 'forward' '' 'Preview.md'
|
|
Browser 'Linked Markdown' '' 'Other.md'
|
|
Browser 'close' '' 'Other.md'
|
|
[void](Wait-For 'the Markdown viewers to close' { !(Find-Window 'KSwitcher.Files.Text') })
|
|
|
|
Open-File 'Preview.md' 0x73
|
|
$window = Wait-For 'F4 to open the Markdown editor' { Find-Window 'KSwitcher.Files.Text' 'Editor' }
|
|
[void](Assert-TextWindowAppearance $window 'Editor')
|
|
Write-Output 'Verified F3/F4 icons, separate taskbar groups and regrouping when the same window switches modes with F6.'
|
|
$control = Scintilla $window
|
|
Append-Character $control 'Y'
|
|
Post $control 0x100 0x75
|
|
Answer-Save 6
|
|
Browser 'Перегляд Markdown'
|
|
Browser 'appearance-full'
|
|
if (![IO.File]::ReadAllText($original).EndsWith('Y')) { throw 'F6 rendered before saving.' }
|
|
Post $window 0x10 0
|
|
[void](Wait-For 'the saved Markdown viewer to close' { !(Find-Window 'KSwitcher.Files.Text') })
|
|
|
|
Open-File 'Preview.md' 0x73
|
|
$window = Wait-For 'the editor before a save conflict' { Find-Window 'KSwitcher.Files.Text' 'Editor' }
|
|
$control = Scintilla $window
|
|
Append-Character $control 'Z'
|
|
[IO.File]::Move($original,"$docs\replaced.md")
|
|
[IO.File]::WriteAllText($original,'An external replacement')
|
|
Post $control 0x100 0x75
|
|
Answer-Save 6
|
|
$errorDialog = Wait-For 'a save conflict error' {
|
|
$candidate = Find-Window '#32770'
|
|
if ($candidate -and [MarkdownUi]::GetDlgItem($candidate,1) -ne [IntPtr]::Zero) { $candidate }
|
|
}
|
|
Post $errorDialog 0x111 1
|
|
if ((Find-Window 'KSwitcher.Files.Text' 'Editor') -ne $window -or
|
|
[MarkdownUi]::Send($control,2140,0,0).ToInt64() -or
|
|
[IO.File]::ReadAllText($original) -cne 'An external replacement') {
|
|
throw 'The failed save left editing mode or overwrote an externally replaced file.'
|
|
}
|
|
Post $control 0x100 0x75
|
|
Answer-Save 7
|
|
Browser 'external-replacement'
|
|
Browser 'close'
|
|
[void](Wait-For 'the conflict fixture to close' { !(Find-Window 'KSwitcher.Files.Text') })
|
|
|
|
Open-File 'Plain.txt' 0x72
|
|
$window = Wait-For 'plain-text viewer' { Find-Window 'KSwitcher.Files.Text' 'Viewer' }
|
|
$control = Scintilla $window
|
|
[void](Wait-For 'plain-text read-only view' { [MarkdownUi]::Send($control,2140,0,0).ToInt64() })
|
|
Post $control 0x100 0x75
|
|
[void](Wait-For 'F6 plain-text editor' { !( [MarkdownUi]::Send($control,2140,0,0).ToInt64() ) })
|
|
Post $control 0x100 0x75
|
|
[void](Wait-For 'F6 plain-text viewer' { [MarkdownUi]::Send($control,2140,0,0).ToInt64() })
|
|
Post $window 0x10 0
|
|
[void](Wait-For 'plain-text viewer to close' { !(Find-Window 'KSwitcher.Files.Text') })
|
|
Open-File 'Large.md' 0x72
|
|
$window = Wait-For 'large Markdown text fallback' { Find-Window 'KSwitcher.Files.Text' 'Large.md' }
|
|
$control = Scintilla $window
|
|
if (![MarkdownUi]::IsWindowVisible($control) -or ![MarkdownUi]::Send($control,2140,0,0).ToInt64()) {
|
|
throw 'Large Markdown did not open in the text viewer.'
|
|
}
|
|
Post $window 0x10 0
|
|
[void](Wait-For 'large-file viewer to close' { !(Find-Window 'KSwitcher.Files.Text') })
|
|
$previewPage = Join-Path $app 'terminal\markdown.html'
|
|
[IO.File]::Move($previewPage,"$previewPage.disabled")
|
|
try {
|
|
Open-File 'Preview.md' 0x72
|
|
$window = Wait-For 'text fallback without preview assets' { Find-Window 'KSwitcher.Files.Text' 'Preview.md' }
|
|
$control = Scintilla $window
|
|
if (![MarkdownUi]::IsWindowVisible($control) -or ![MarkdownUi]::Send($control,2140,0,0).ToInt64()) {
|
|
throw 'Markdown did not open in the text viewer when preview assets were missing.'
|
|
}
|
|
} finally { [IO.File]::Move("$previewPage.disabled",$previewPage) }
|
|
Write-Output 'Verified Markdown rendering, Mermaid, task checkboxes, local relative resources, F3/F4, F6 Save/Discard/Cancel/save failure and text fallback.'
|
|
if ($LanFixture) {
|
|
Post $window 0x10 0
|
|
Post $main 0x10 0
|
|
if (!$process.WaitForExit(5000)) { throw 'Files did not close before the LAN check.' }
|
|
[IO.File]::WriteAllText($original,$fixture)
|
|
$lanExe = Join-Path $app 'KSwitcherFilesMarkdownLanFixture.exe'
|
|
Copy-Item -LiteralPath $LanFixture -Destination $lanExe
|
|
$env:WEBVIEW2_USER_DATA_FOLDER = Join-Path $root 'lan-webview'
|
|
$process = Start-Process -FilePath $lanExe -ArgumentList ('"{0}"' -f $original) -PassThru -WindowStyle Normal
|
|
$window = Wait-For 'the LAN Markdown viewer' { Find-Window 'KSwitcher.Files.Text' 'Loopback peer' }
|
|
[void](Assert-TextWindowAppearance $window 'Viewer')
|
|
Browser 'render'
|
|
Browser 'toggle-first-task'
|
|
[void](Wait-For 'Markdown checkbox uploaded to the LAN peer' { [IO.File]::ReadAllText($original) -ceq $checkedFixture })
|
|
Browser 'search'
|
|
Browser 'edit'
|
|
if ((Wait-For 'LAN F6 editor' { Find-Window 'KSwitcher.Files.Text' 'Editor' }) -ne $window) {
|
|
throw 'LAN F6 changed windows.'
|
|
}
|
|
[void](Assert-TextWindowAppearance $window 'Editor')
|
|
$control = Scintilla $window
|
|
Append-Character $control 'L'
|
|
Post $control 0x100 0x75
|
|
Browser 'Перегляд Markdown'
|
|
if (![IO.File]::ReadAllText($original).EndsWith('L')) { throw 'F6 rendered before uploading the LAN edit.' }
|
|
Browser 'follow'
|
|
if ((Wait-For 'the in-place LAN Markdown viewer' { Find-Window 'KSwitcher.Files.Text' 'Other.md' }) -ne $window) {
|
|
throw 'A LAN link did not stay in the same window.'
|
|
}
|
|
Browser 'Linked Markdown' '' 'Other.md'
|
|
Browser 'back' '' 'Other.md'
|
|
Browser 'Перегляд Markdown' '' 'Preview.md'
|
|
Browser 'forward' '' 'Preview.md'
|
|
Browser 'Linked Markdown' '' 'Other.md'
|
|
Browser 'close' '' 'Other.md'
|
|
if (!$process.WaitForExit(5000) -or $process.ExitCode) { throw 'The LAN fixture did not close normally.' }
|
|
Write-Output 'Verified Markdown, Mermaid, relative links/images and F6 saving through an authenticated loopback LAN connection.'
|
|
}
|
|
} finally {
|
|
if ($process -and !$process.HasExited) {
|
|
Stop-Process -Id $process.Id
|
|
[void]$process.WaitForExit(5000)
|
|
}
|
|
$env:WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS = $flags
|
|
$env:WEBVIEW2_USER_DATA_FOLDER = $data
|
|
if ($profileCaptured) {
|
|
foreach ($name in $profileValues) {
|
|
if ($saved.ContainsKey($name)) { $profile.SetValue($name,$saved[$name][0],$saved[$name][1]) }
|
|
else { $profile.DeleteValue($name,$false) }
|
|
}
|
|
}
|
|
$profile.Dispose()
|
|
if (Test-Path -LiteralPath $root) {
|
|
$resolved = (Resolve-Path -LiteralPath $root).Path
|
|
$temp = (Resolve-Path -LiteralPath ([IO.Path]::GetTempPath())).Path.TrimEnd('\')
|
|
if ((Split-Path -Parent $resolved) -eq $temp -and (Split-Path -Leaf $resolved) -like 'ks-markdown-test-*') {
|
|
for ($attempt=0; $attempt -lt 40 -and (Test-Path -LiteralPath $resolved); ++$attempt) {
|
|
try { Remove-Item -LiteralPath $resolved -Recurse -Force }
|
|
catch {
|
|
if ($attempt -eq 39) { throw }
|
|
Start-Sleep -Milliseconds 250
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|