namespace ElectronNET.IntegrationTests.Tests
{
    using ElectronNET.Common;
    using ElectronNET.IntegrationTests.Common;

    [Collection("ElectronCollection")]
    public class CookiesTests : IntegrationTestBase
    {
        public CookiesTests(ElectronFixture fx) : base(fx)
        {
        }

        [IntegrationFact(Skip = "Cookie set/get requires navigation to domain; skipping until test harness serves page")]
        public async Task Cookie_set_get_remove_sequence()
        {
            var session = this.MainWindow.WebContents.Session;
            var changed = false;
            session.Cookies.OnChanged += (cookie, cause, removed) => changed = true;
            // Navigate to example.com so cookie domain matches
            await this.MainWindow.WebContents.LoadURLAsync("https://example.com");
            // Set via renderer for now
            await this.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("document.cookie='integration_cookie=1;path=/';");
            await Task.Delay(500.ms());
            changed.Should().BeTrue();
        }
    }
}