releases/VideoDownloader.Tests/Browser/TrackerBlockTests.cs

40 lines
1.7 KiB
C#

using VideoDownloader.Browser;
namespace VideoDownloader.Tests.Browser;
/// <summary>T3-14: 추적 방지 — 블랙리스트 도메인 매칭(서브도메인 포함) + 차단 카운터.</summary>
public class TrackerBlockTests
{
[Theory]
[InlineData("https://google-analytics.com/analytics.js", true)] // 정확히 도메인
[InlineData("https://www.google-analytics.com/g/collect", true)] // 서브도메인
[InlineData("https://x.com/notgoogle-analytics.com/a", false)] // 접미사 함정 제외
[InlineData("https://doubleclick.net/instream/ad_status.js", true)]
[InlineData("https://safe.example.com/lib.js", false)] // 무관 도메인
public void Matches_블랙리스트_도메인_판정(string url, bool expected)
=> Assert.Equal(expected, new TrackerBlocklist().Matches(new Uri(url)));
[Fact]
public void 커스텀_도메인_주입_가능()
{
var bl = new TrackerBlocklist(new[] { "blocked.test" });
Assert.True(bl.Matches(new Uri("https://t.blocked.test/x.js")));
Assert.False(bl.Matches(new Uri("https://ok.com/x.js")));
}
[Fact]
public void Counter_차단_누적_도메인별_집계_변경_통지()
{
var c = new TrackerCounter();
var changed = 0;
c.Changed += () => changed++;
Assert.Equal(0, c.Total);
c.Record("https://www.google-analytics.com/a.js");
c.Record("https://google-analytics.com/b.js");
c.Record("https://scorecardresearch.com/c.js");
Assert.Equal(3, c.Total);
Assert.Equal(2, c.ByDomain["google-analytics.com"]);
Assert.Equal(1, c.ByDomain["scorecardresearch.com"]);
Assert.Equal(3, changed);
}
}