73 lines
2.3 KiB
C#
73 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Paca.Browser.Autofill;
|
|
using Xunit;
|
|
|
|
namespace Paca.Tests.Browser;
|
|
|
|
public class ChromeAutofillManagerTests
|
|
{
|
|
[Fact]
|
|
public void AutofillManager_Saves_And_Retrieves_Profiles()
|
|
{
|
|
var tempFile = Path.Combine(Path.GetTempPath(), $"autofill_test_{Guid.NewGuid():N}.json");
|
|
try
|
|
{
|
|
var manager = new ChromeAutofillManager(tempFile);
|
|
var profile = new AutofillProfile(
|
|
Id: "prof-1",
|
|
FullName: "홍길동",
|
|
Email: "gildong@example.com",
|
|
PhoneNumber: "010-1234-5678",
|
|
StreetAddress: "테헤란로 123",
|
|
City: "서울",
|
|
PostalCode: "06234",
|
|
Country: "KR"
|
|
);
|
|
|
|
manager.SaveProfile(profile);
|
|
Assert.Single(manager.Profiles);
|
|
Assert.Equal("홍길동", manager.Profiles[0].FullName);
|
|
|
|
// Reload from persistence
|
|
var manager2 = new ChromeAutofillManager(tempFile);
|
|
Assert.Single(manager2.Profiles);
|
|
Assert.Equal("gildong@example.com", manager2.Profiles[0].Email);
|
|
}
|
|
finally
|
|
{
|
|
if (File.Exists(tempFile)) File.Delete(tempFile);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void AutofillManager_Matches_Input_Fields_Correctly()
|
|
{
|
|
var manager = new ChromeAutofillManager();
|
|
var profile = new AutofillProfile(
|
|
Id: "prof-2",
|
|
FullName: "김철수",
|
|
Email: "chulsoo@example.com",
|
|
PhoneNumber: "010-9876-5432",
|
|
StreetAddress: "판교역로 235",
|
|
City: "성남",
|
|
PostalCode: "13494",
|
|
Country: "KR"
|
|
);
|
|
manager.SaveProfile(profile);
|
|
|
|
// Given form input field names
|
|
var suggestionsEmail = manager.SuggestValues("email");
|
|
Assert.NotEmpty(suggestionsEmail);
|
|
Assert.Equal("chulsoo@example.com", suggestionsEmail[0].Value);
|
|
|
|
var suggestionsName = manager.SuggestValues("username");
|
|
Assert.NotEmpty(suggestionsName);
|
|
Assert.Equal("김철수", suggestionsName[0].Value);
|
|
|
|
var suggestionsPhone = manager.SuggestValues("tel");
|
|
Assert.NotEmpty(suggestionsPhone);
|
|
Assert.Equal("010-9876-5432", suggestionsPhone[0].Value);
|
|
}
|
|
}
|