test(core/browser/platform): 26 extreme RED/GREEN TDD cycles and full regression hardening (3,235 PASS)
This commit is contained in:
parent
bcd242691f
commit
8677853822
100 changed files with 4814 additions and 333 deletions
|
|
@ -0,0 +1,104 @@
|
|||
using System;
|
||||
using Paca.Core.Platform;
|
||||
using Paca.Core.QuickActions;
|
||||
using Xunit;
|
||||
|
||||
namespace Paca.Tests.Core;
|
||||
|
||||
public class ClipboardAndEncoderSecurityExtremeRedTests
|
||||
{
|
||||
private readonly QuickActionClipboardDetector _detector = new();
|
||||
|
||||
[Theory]
|
||||
[InlineData("---")]
|
||||
[InlineData("----")]
|
||||
[InlineData("+++")]
|
||||
[InlineData("***")]
|
||||
[InlineData("///")]
|
||||
[InlineData("+ - * /")]
|
||||
[InlineData("(+)")]
|
||||
[InlineData("====")]
|
||||
public void QuickActionClipboardDetector_NonMathSymbols_DoesNotDetectAsMathExpression(string input)
|
||||
{
|
||||
var result = _detector.DetectIntent(input);
|
||||
Assert.NotEqual(ClipboardIntentType.Expression, result.IntentType);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("12 + 34")]
|
||||
[InlineData("100 / 5")]
|
||||
[InlineData("(3 + 4) * 2")]
|
||||
[InlineData("2 ^ 8")]
|
||||
[InlineData("50 * 1.1")]
|
||||
public void QuickActionClipboardDetector_ValidArithmetic_DetectsAsExpression(string input)
|
||||
{
|
||||
var result = _detector.DetectIntent(input);
|
||||
Assert.Equal(ClipboardIntentType.Expression, result.IntentType);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("https://evil.com/login?ref=youtube.com")]
|
||||
[InlineData("https://phishing.org/index.html?redirect=twitter.com")]
|
||||
[InlineData("https://attacker.site/steal?feed=tiktok.com")]
|
||||
[InlineData("https://notyoutube.com/watch?v=123")]
|
||||
public void QuickActionClipboardDetector_PhishingDomainQuery_DoesNotDetectAsMediaDownload(string input)
|
||||
{
|
||||
var result = _detector.DetectIntent(input);
|
||||
Assert.NotEqual(ClipboardIntentType.MediaDownload, result.IntentType);
|
||||
Assert.Equal(ClipboardIntentType.BrowseUrl, result.IntentType);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("https://www.youtube.com/watch?v=dQw4w9WgXcQ")]
|
||||
[InlineData("https://x.com/user/status/123456")]
|
||||
[InlineData("https://stream.example.com/playlist.m3u8")]
|
||||
[InlineData("https://video.example.com/movie.mp4")]
|
||||
public void QuickActionClipboardDetector_RealMediaUrls_DetectsAsMediaDownload(string input)
|
||||
{
|
||||
var result = _detector.DetectIntent(input);
|
||||
Assert.Equal(ClipboardIntentType.MediaDownload, result.IntentType);
|
||||
}
|
||||
|
||||
private sealed class LocalMockRunner : IProcessRunner
|
||||
{
|
||||
public Task<ProcessResult> RunAsync(ProcessSpec spec, Action<string, string>? onLine, System.Threading.CancellationToken ct) =>
|
||||
Task.FromResult(new ProcessResult(0, "", ""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HardwareEncoderDetector_NullCapabilities_SafelyFallsBackToSoftwareCodecs()
|
||||
{
|
||||
var detector = new HardwareEncoderDetector(new LocalMockRunner());
|
||||
|
||||
Assert.Equal("libx264", detector.GetBestH264Encoder(null!));
|
||||
Assert.Equal("libx265", detector.GetBestHevcEncoder(null!));
|
||||
Assert.Equal("libsvtav1", detector.GetBestAv1Encoder(null!));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HardwareEncoderDetector_BuildEncodingArgs_NullOrWhitespaceEncoder_DefaultsToLibx264()
|
||||
{
|
||||
var args = HardwareEncoderDetector.BuildEncodingArgs(null!, 23, "fast");
|
||||
Assert.Contains("-c:v", args);
|
||||
Assert.Contains("libx264", args);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HardwareEncoderDetector_BuildEncodingArgs_NullPreset_DefaultsToFast()
|
||||
{
|
||||
var args = HardwareEncoderDetector.BuildEncodingArgs("libx264", 23, null!);
|
||||
Assert.Contains("-preset", args);
|
||||
Assert.Contains("fast", args);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-10, 0)]
|
||||
[InlineData(100, 63)]
|
||||
public void HardwareEncoderDetector_BuildEncodingArgs_CrfClamping_ClampsBetweenZeroAnd63(int inputCrf, int expectedCrf)
|
||||
{
|
||||
var args = HardwareEncoderDetector.BuildEncodingArgs("libx264", inputCrf, "fast");
|
||||
var crfIdx = Array.IndexOf(args, "-crf");
|
||||
Assert.True(crfIdx >= 0);
|
||||
Assert.Equal(expectedCrf.ToString(), args[crfIdx + 1]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue