Phase 0 (T1-3/4/7/9/11): find bar w/ native Find API + search engine + site zoom + force reload + F11, wired into MainWindow, E2E smoke (39 tests)

This commit is contained in:
Yun Chan 2026-08-15 12:14:35 +09:00
parent 470c9267f2
commit 00a822eaeb
11 changed files with 584 additions and 18 deletions

View file

@ -0,0 +1,71 @@
using System.Windows;
using System.Windows.Threading;
using Microsoft.Web.WebView2.Core;
using VideoDownloader.Tests.Infrastructure;
namespace VideoDownloader.Tests.E2E;
/// <summary>
/// E2E: 실제 WebView2 + 네이티브 Find API(CoreWebView2.Find) 검증(T1-3).
/// WebView2 런타임 위에서 매치 카운트/활성 인덱스가 실제로 발생하는지 확인한다.
/// </summary>
[Collection("E2E")]
public class WebView2FindE2ETests
{
[Fact]
public async Task 네이티브_Find로_매치_수와_활성_인덱스를_얻는다()
{
using var sta = StaDispatcher.Start();
var udf = Path.Combine(Path.GetTempPath(), $"vd_e2e_{Guid.NewGuid():N}");
var result = await sta.InvokeAsync(async () =>
{
var window = new Window();
var browser = new Microsoft.Web.WebView2.Wpf.WebView2();
window.Content = browser;
window.Show();
var env = await CoreWebView2Environment.CreateAsync(userDataFolder: udf);
await browser.EnsureCoreWebView2Async(env);
var cv = browser.CoreWebView2;
cv.Settings.AreDefaultScriptDialogsEnabled = false;
var html = "<html><body><p>hello world hello brave hello</p></body></html>";
cv.NavigateToString(html);
await WaitUntilNavCompleted(cv);
// 네이티브 Find API — SuppressDefaultFindDialog 로 자체 UI 전제 검증
int matchCount = -1, activeIndex = -1;
cv.Find.MatchCountChanged += (_, _) => matchCount = cv.Find.MatchCount;
cv.Find.ActiveMatchIndexChanged += (_, _) => activeIndex = cv.Find.ActiveMatchIndex;
var options = env.CreateFindOptions();
options.FindTerm = "hello";
options.ShouldHighlightAllMatches = true;
options.SuppressDefaultFindDialog = true;
await cv.Find.StartAsync(options);
await Wait.Until(() => Task.FromResult(matchCount), c => c > 0, 10000);
var countAfterStart = matchCount;
cv.Find.FindNext();
await Wait.Until(() => Task.FromResult(activeIndex), i => i >= 1, 10000);
cv.Find.Stop();
window.Close();
return (countAfterStart, activeIndex);
});
try { Directory.Delete(udf, true); } catch { }
Assert.Equal(3, result.countAfterStart);
Assert.True(result.activeIndex >= 1, $"활성 인덱스가 진행되지 않음: {result.activeIndex}");
}
private static Task WaitUntilNavCompleted(CoreWebView2 cv)
{
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
EventHandler<CoreWebView2NavigationCompletedEventArgs>? h = null;
h = (_, _) => { cv.NavigationCompleted -= h; tcs.TrySetResult(); };
cv.NavigationCompleted += h;
return tcs.Task.WaitAsync(TimeSpan.FromSeconds(15));
}
}