2026-10-13 04:32:04 +00:00
|
|
|
using System.Text.Json;
|
|
|
|
|
|
|
|
|
|
namespace UCVL.VPNPlus;
|
|
|
|
|
|
|
|
|
|
internal static class DashboardInteractionSelfTest
|
|
|
|
|
{
|
|
|
|
|
internal static int Run()
|
|
|
|
|
{
|
|
|
|
|
var checks = new Dictionary<string, bool>();
|
|
|
|
|
string? error = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using var form = new MainForm(preview: true, uiOnly: true) { Opacity = 0, ShowInTaskbar = false };
|
|
|
|
|
foreach (var check in form.CheckDashboardInteraction()) checks.Add(check.Key, check.Value);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception) { error = exception.ToString(); }
|
2026-10-13 07:29:03 +00:00
|
|
|
var passed = error is null && checks.Count >= 43 && checks.Values.All(value => value);
|
2026-10-13 04:32:04 +00:00
|
|
|
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "dashboard-interaction-self-test.json"),
|
|
|
|
|
JsonSerializer.Serialize(new { passed, checks, error, scope = "owned synthetic WinForms fixture; no physical user-input or production acceptance claim",
|
|
|
|
|
network_modified = false, installed_client_modified = false, credentials_loaded = false }, new JsonSerializerOptions { WriteIndented = true }));
|
|
|
|
|
return passed ? 0 : 28;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal sealed partial class MainForm
|
|
|
|
|
{
|
|
|
|
|
internal Dictionary<string, bool> CheckDashboardInteraction()
|
|
|
|
|
{
|
|
|
|
|
var checks = new Dictionary<string, bool>();
|
|
|
|
|
var profile = new Profile
|
|
|
|
|
{
|
|
|
|
|
DisplayName = "滚动测试", Email = "fixture@example.invalid",
|
|
|
|
|
Nodes = [new NodeInfo { Slug = "fixture", Name = "测试节点" }],
|
|
|
|
|
RouteModes = [new RouteModeInfo { Id = "smart", Name = "AI 智能代理" }]
|
|
|
|
|
};
|
|
|
|
|
Show();
|
|
|
|
|
ShowDashboard(profile);
|
|
|
|
|
_refreshTimer.Stop();
|
|
|
|
|
Size = MinimumSize;
|
|
|
|
|
PerformLayout();
|
|
|
|
|
LayoutDashboard();
|
|
|
|
|
Application.DoEvents();
|
|
|
|
|
int Limit() => Math.Max(0, _dashboardScrollBar.Maximum - _dashboardScrollBar.LargeChange + 1);
|
|
|
|
|
bool Wheel(Control target, int delta, Point? screenPoint = null)
|
|
|
|
|
{
|
|
|
|
|
var screen = screenPoint ?? _dashboardView.PointToScreen(new Point(20, 20));
|
|
|
|
|
var packedPoint = unchecked((int)((ushort)screen.X | (uint)(ushort)screen.Y << 16));
|
|
|
|
|
var packedDelta = unchecked((int)((uint)(ushort)(short)delta << 16));
|
|
|
|
|
var message = Message.Create(target.Handle, 0x20a, (IntPtr)packedDelta, (IntPtr)packedPoint);
|
|
|
|
|
return Application.FilterMessage(ref message);
|
|
|
|
|
}
|
2026-10-22 05:43:39 +00:00
|
|
|
checks["compact_view_is_single_fitted_page"] = !_dashboardScrollBar.Visible && Limit() == 0
|
|
|
|
|
&& _dashboardBody.Location == Point.Empty && _dashboardBody.Size == _dashboardView.ClientSize;
|
2026-10-13 04:32:04 +00:00
|
|
|
foreach (var (name, control) in new (string, Control)[]
|
|
|
|
|
{
|
|
|
|
|
("card", _trafficCard), ("nested_metric", _uploadMetric), ("chart", _trafficChart),
|
2026-10-22 05:43:39 +00:00
|
|
|
("nested_label", _uploadLegend), ("closed_speed_combo", _historyRangeCombo),
|
2026-10-13 04:32:04 +00:00
|
|
|
("closed_node_combo", _connectionModeCombo), ("closed_mode_combo", _routeCombo),
|
|
|
|
|
("button", _connectButton)
|
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
_dashboardScrollBar.Value = 0;
|
|
|
|
|
var oldSelection = control is ComboBox combo ? combo.SelectedIndex : -1;
|
2026-10-22 05:43:39 +00:00
|
|
|
checks["wheel_does_not_scroll_" + name] = !Wheel(control, -120) && _dashboardScrollBar.Value == 0
|
2026-10-13 04:32:04 +00:00
|
|
|
&& (control is not ComboBox selector || selector.SelectedIndex == oldSelection);
|
|
|
|
|
}
|
|
|
|
|
_dashboardScrollBar.Value = 0;
|
|
|
|
|
var halfHandled = Wheel(_trafficChart, -60);
|
|
|
|
|
var firstHalf = _dashboardScrollBar.Value;
|
2026-10-22 05:43:39 +00:00
|
|
|
checks["high_resolution_wheel_does_not_shift_fitted_page"] = !halfHandled && firstHalf == 0
|
|
|
|
|
&& !Wheel(_trafficChart, -60) && _dashboardScrollBar.Value == 0;
|
2026-10-13 04:32:04 +00:00
|
|
|
_dashboardScrollBar.Value = Limit();
|
2026-10-22 05:43:39 +00:00
|
|
|
checks["wheel_down_keeps_page_origin"] = !Wheel(_trafficChart, -240) && _dashboardScrollBar.Value == 0;
|
|
|
|
|
checks["wheel_up_keeps_page_origin"] = !Wheel(_trafficChart, 120) && _dashboardScrollBar.Value == 0;
|
2026-10-13 04:32:04 +00:00
|
|
|
_dashboardScrollBar.Value = Math.Min(137, Limit());
|
|
|
|
|
var previous = _dashboardScrollBar.Value;
|
|
|
|
|
UpdateProfile(profile, preserveSelections: true);
|
|
|
|
|
DisplayTraffic(1234, 5678, "隔离刷新");
|
|
|
|
|
LayoutDashboard();
|
2026-10-22 05:43:39 +00:00
|
|
|
checks["profile_and_metric_refresh_keep_page_origin"] = _dashboardScrollBar.Value == 0 && _dashboardBody.Top == 0;
|
2026-10-13 04:32:04 +00:00
|
|
|
ClientSize = new Size(ClientSize.Width, ClientSize.Height + ScaleLogical(20));
|
|
|
|
|
LayoutDashboard();
|
2026-10-22 05:43:39 +00:00
|
|
|
checks["resize_remains_fitted_without_scroll"] = !_dashboardScrollBar.Visible && _dashboardScrollBar.Value == 0;
|
2026-10-13 04:32:04 +00:00
|
|
|
_dashboardScrollBar.Value = Limit();
|
2026-10-22 05:43:39 +00:00
|
|
|
checks["footer_visible_without_any_scroll"] = !_dashboardView.HorizontalScroll.Visible && !_dashboardScrollBar.Visible
|
2026-10-13 04:32:04 +00:00
|
|
|
&& _footer.RectangleToScreen(_footer.ClientRectangle).Bottom <= _dashboardView.RectangleToScreen(_dashboardView.ClientRectangle).Bottom;
|
|
|
|
|
previous = _dashboardScrollBar.Value;
|
|
|
|
|
checks["header_pointer_does_not_scroll_dashboard"] = !Wheel(_trafficChart, -120, _brandHeader.PointToScreen(new Point(20, 20)))
|
|
|
|
|
&& _dashboardScrollBar.Value == previous;
|
|
|
|
|
using (var other = new Form())
|
|
|
|
|
checks["other_window_messages_not_captured"] = !Wheel(other, -120) && _dashboardScrollBar.Value == previous;
|
|
|
|
|
_dashboardScrollBar.Value = 0;
|
|
|
|
|
_historyRangeCombo.DroppedDown = true;
|
|
|
|
|
checks["open_combo_keeps_native_wheel_navigation"] = !Wheel(_historyRangeCombo, -120) && _dashboardScrollBar.Value == 0;
|
|
|
|
|
_historyRangeCombo.DroppedDown = false;
|
|
|
|
|
checks["dashboard_reuses_full_login_artwork"] = _dashboardView.LoginArtwork && _dashboardBody.ParentArtwork;
|
|
|
|
|
checks["card_surface_is_half_transparent"] = CardPanel.SurfaceAlpha == 128;
|
|
|
|
|
checks["whole_content_composition_disabled"] = !_content.ComposeChildren;
|
|
|
|
|
checks["metric_dirty_refresh_clears_previous_digits"] = CheckMetricRefreshPaint();
|
2026-10-13 07:29:03 +00:00
|
|
|
foreach (var check in CheckTailnetTrafficUi()) checks.Add(check.Key, check.Value);
|
2026-10-13 04:32:04 +00:00
|
|
|
ShowLogin();
|
|
|
|
|
checks["hidden_dashboard_does_not_consume_login_wheel"] = !Wheel(_loginText, -120);
|
|
|
|
|
RequestExit();
|
|
|
|
|
return checks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool CheckMetricRefreshPaint()
|
|
|
|
|
{
|
|
|
|
|
// Repaint only an owned control into a deliberately dirty backing
|
|
|
|
|
// surface. This checks the real WM_PRINTCLIENT path, not OnPaint alone.
|
|
|
|
|
using var parent = new ScenicPanel { LoginArtwork = true, Size = new Size(700, 500) };
|
|
|
|
|
using var card = new CardPanel { Bounds = new Rectangle(30, 150, 500, 170), MetricBand = true };
|
|
|
|
|
using var metric = new MetricCard("本次代理流量", DashboardIcon.Document)
|
|
|
|
|
{ Embedded = true, Bounds = new Rectangle(30, 40, 250, 85) };
|
|
|
|
|
parent.Controls.Add(card);
|
|
|
|
|
card.Controls.Add(metric);
|
|
|
|
|
_ = parent.Handle; _ = card.Handle; _ = metric.Handle;
|
|
|
|
|
using var actual = new Bitmap(metric.Width, metric.Height);
|
|
|
|
|
void Print()
|
|
|
|
|
{
|
|
|
|
|
using var graphics = Graphics.FromImage(actual);
|
|
|
|
|
var hdc = graphics.GetHdc();
|
|
|
|
|
try { ChromeNative.SendMessage(metric.Handle, 0x318, hdc, (IntPtr)(0x4 | 0x8)); }
|
|
|
|
|
finally { graphics.ReleaseHdc(hdc); }
|
|
|
|
|
}
|
|
|
|
|
metric.SetBytes(1_073_741_824, hint: "本次连接累计");
|
|
|
|
|
Print();
|
|
|
|
|
using var expected = new Bitmap(actual);
|
|
|
|
|
for (var iteration = 0; iteration < 5; iteration++)
|
|
|
|
|
{
|
|
|
|
|
metric.SetBytes(999_999_999_999, hint: "旧数据应清除");
|
|
|
|
|
Print();
|
|
|
|
|
metric.SetBytes(1_073_741_824, hint: "本次连接累计");
|
|
|
|
|
Print();
|
|
|
|
|
for (var y = 0; y < actual.Height; y++)
|
|
|
|
|
for (var x = 0; x < actual.Width; x++)
|
|
|
|
|
if (actual.GetPixel(x, y) != expected.GetPixel(x, y)) return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|