2026-11-13 10:35:04 +08:00
|
|
|
using System.Text.Json;
|
2026-11-03 15:15:23 +00:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
foreach (var check in DashboardComboSelfTest.Check()) checks.Add(check.Key, check.Value);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception) { error = exception.ToString(); }
|
|
|
|
|
var passed = error is null && checks.Count >= 43 && checks.Values.All(value => value);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
checks["compact_view_is_single_fitted_page"] = !_dashboardScrollBar.Visible && Limit() == 0
|
|
|
|
|
&& _dashboardBody.Location == Point.Empty && _dashboardBody.Size == _dashboardView.ClientSize;
|
|
|
|
|
foreach (var (name, control) in new (string, Control)[]
|
|
|
|
|
{
|
|
|
|
|
("card", _trafficCard), ("nested_metric", _uploadMetric), ("chart", _trafficChart),
|
|
|
|
|
("nested_label", _uploadLegend), ("closed_speed_combo", _historyRangeCombo),
|
|
|
|
|
("closed_node_combo", _connectionModeCombo), ("closed_mode_combo", _routeCombo),
|
|
|
|
|
("button", _connectButton)
|
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
_dashboardScrollBar.Value = 0;
|
|
|
|
|
var oldSelection = control is DashboardCombo combo ? combo.SelectedIndex : -1;
|
|
|
|
|
checks["wheel_does_not_scroll_" + name] = !Wheel(control, -120) && _dashboardScrollBar.Value == 0
|
|
|
|
|
&& (control is not DashboardCombo selector || selector.SelectedIndex == oldSelection);
|
|
|
|
|
}
|
|
|
|
|
_dashboardScrollBar.Value = 0;
|
|
|
|
|
var halfHandled = Wheel(_trafficChart, -60);
|
|
|
|
|
var firstHalf = _dashboardScrollBar.Value;
|
|
|
|
|
checks["high_resolution_wheel_does_not_shift_fitted_page"] = !halfHandled && firstHalf == 0
|
|
|
|
|
&& !Wheel(_trafficChart, -60) && _dashboardScrollBar.Value == 0;
|
|
|
|
|
_dashboardScrollBar.Value = Limit();
|
|
|
|
|
checks["wheel_down_keeps_page_origin"] = !Wheel(_trafficChart, -240) && _dashboardScrollBar.Value == 0;
|
|
|
|
|
checks["wheel_up_keeps_page_origin"] = !Wheel(_trafficChart, 120) && _dashboardScrollBar.Value == 0;
|
|
|
|
|
_dashboardScrollBar.Value = Math.Min(137, Limit());
|
|
|
|
|
var previous = _dashboardScrollBar.Value;
|
|
|
|
|
UpdateProfile(profile, preserveSelections: true);
|
|
|
|
|
DisplayTraffic(1234, 5678, "隔离刷新");
|
|
|
|
|
LayoutDashboard();
|
|
|
|
|
checks["profile_and_metric_refresh_keep_page_origin"] = _dashboardScrollBar.Value == 0 && _dashboardBody.Top == 0;
|
|
|
|
|
ClientSize = new Size(ClientSize.Width, ClientSize.Height + ScaleLogical(20));
|
|
|
|
|
LayoutDashboard();
|
|
|
|
|
checks["resize_remains_fitted_without_scroll"] = !_dashboardScrollBar.Visible && _dashboardScrollBar.Value == 0;
|
|
|
|
|
_dashboardScrollBar.Value = Limit();
|
|
|
|
|
checks["footer_visible_without_any_scroll"] = !_dashboardView.HorizontalScroll.Visible && !_dashboardScrollBar.Visible
|
|
|
|
|
&& _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_selector_does_not_scroll_page"] = !Wheel(_historyRangeCombo, -120) && _dashboardScrollBar.Value == 0;
|
|
|
|
|
_historyRangeCombo.DroppedDown = false;
|
2026-11-13 10:35:04 +08:00
|
|
|
checks["dashboard_uses_scenic_backdrop_and_keeps_login_artwork"] = _dashboardView.DashboardArtwork
|
|
|
|
|
&& _dashboardBody.ParentArtwork && _content.LoginArtwork;
|
2026-11-03 15:15:23 +00:00
|
|
|
checks["card_surface_is_half_transparent"] = CardPanel.SurfaceAlpha == 128;
|
|
|
|
|
checks["whole_content_composition_disabled"] = !_content.ComposeChildren;
|
|
|
|
|
checks["metric_dirty_refresh_clears_previous_digits"] = CheckMetricRefreshPaint();
|
|
|
|
|
foreach (var check in CheckTailnetTrafficUi()) checks.Add(check.Key, check.Value);
|
|
|
|
|
var monitorSize = ClientSize;
|
|
|
|
|
var monitorAccounting = (_sessionUp, _sessionDown, _trafficChart.PointCount);
|
|
|
|
|
SetNodeTrafficPermission(true);
|
|
|
|
|
SetTailnetTrafficVisibility(true);
|
|
|
|
|
LayoutDashboard();
|
|
|
|
|
Application.DoEvents();
|
|
|
|
|
using (var monitorFont = Brand.Font(7.5f))
|
|
|
|
|
using (var monitorGraphics = _nodeTrafficPanel.CreateGraphics())
|
|
|
|
|
{
|
|
|
|
|
var monitorTextHeight = TextRenderer.MeasureText(monitorGraphics, "VPN002 上传", monitorFont).Height;
|
|
|
|
|
var rows = NodeTrafficPanel.TextLayout(_nodeTrafficPanel.ClientSize, DeviceDpi, monitorTextHeight);
|
|
|
|
|
checks["monitor_two_native_dpi_text_rows_fit"] = rows.Rows.All(row => row.Height >= monitorTextHeight)
|
|
|
|
|
&& !rows.Rows[0].IntersectsWith(rows.Rows[1]);
|
|
|
|
|
}
|
|
|
|
|
checks["monitor_stays_below_speed_without_resizing_window"] = ClientSize == monitorSize
|
2026-11-06 10:54:33 +00:00
|
|
|
&& _nodeTrafficPanel.Top > _speedTrendCard.Bottom && _nodeTrafficPanel.Bottom < _dailyCard.Top
|
2026-11-03 15:15:23 +00:00
|
|
|
&& !_dashboardScrollBar.Visible && _dashboardBody.Top == 0;
|
|
|
|
|
checks["monitor_does_not_overflow_other_controls"] = DashboardControlsFit();
|
|
|
|
|
checks["monitor_does_not_change_personal_proxy_accounting"] = monitorAccounting == (_sessionUp, _sessionDown, _trafficChart.PointCount);
|
|
|
|
|
SetNodeTrafficPermission(false);
|
|
|
|
|
SetTailnetTrafficVisibility(false);
|
|
|
|
|
checks["monitor_revoked_hides_and_stops_timer"] = !_nodeTrafficPanel.Visible && !_nodeTrafficTimer.Enabled;
|
2026-11-15 21:33:18 +08:00
|
|
|
|
|
|
|
|
var emptyProfile = new Profile { RouteModes = profile.RouteModes };
|
|
|
|
|
_wantConnected = true;
|
|
|
|
|
SetConnectionState(true, "已连接", "隔离刷新");
|
|
|
|
|
UpdateProfile(emptyProfile, preserveSelections: true);
|
|
|
|
|
checks["empty_node_refresh_preserves_disconnect_action"] = _connectButton.Enabled && _selectionUiConnected;
|
|
|
|
|
|
|
|
|
|
_wantConnected = false;
|
|
|
|
|
SetConnectionState(false, "未连接", "隔离刷新");
|
|
|
|
|
UpdateProfile(emptyProfile, preserveSelections: true);
|
|
|
|
|
checks["empty_node_refresh_disables_new_connection"] = !_connectButton.Enabled;
|
|
|
|
|
|
|
|
|
|
using (var attempt = new CancellationTokenSource())
|
|
|
|
|
{
|
|
|
|
|
_connectionAttemptCancellation = attempt;
|
|
|
|
|
SetBusy(true);
|
|
|
|
|
UpdateProfile(profile, preserveSelections: true);
|
|
|
|
|
checks["profile_refresh_preserves_cancel_action_during_connect"] = _connectButton.Enabled;
|
|
|
|
|
attempt.Cancel();
|
|
|
|
|
UpdateProfile(profile, preserveSelections: true);
|
|
|
|
|
checks["profile_refresh_disables_action_while_cancel_finishes"] = !_connectButton.Enabled;
|
|
|
|
|
_connectionAttemptCancellation = null;
|
|
|
|
|
}
|
|
|
|
|
SetBusy(false);
|
2026-11-03 15:15:23 +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;
|
|
|
|
|
}
|
|
|
|
|
}
|