# cookies.test --
#
# Tests cookie engine behavior, cookie injection, and cookie sharing.
#
# Copyright (c) 2024-2026 Massimo Manghi
#
# SPDX-License-Identifier: TCL
#
# See the file "license.terms" at the top level of this distribution
# for information on usage and redistribution of this file, and for the
# complete disclaimer of warranties and limitation of liability.
#
# Portions of this file were drafted or revised with AI assistance
# under the direction and review of Massimo Manghi

package require tcltest
namespace import ::tcltest::*

source [file join [file dirname [file normalize [info script]]] support.tcl]
source [file join [file dirname [file normalize [info script]]] http_common.tcl]

::tclcurl::test::load_package

test cookies-1.1 {cookies stay on one easy handle and are not shared implicitly} -constraints http_server -body {
    ::tclcurl::test::transport_cookies_isolated ::tclcurl::test::server::base_url {}
} -result {1 1}

test cookies-1.2 {share cookies lets a second easy handle reuse cookies set by the first} -constraints http_server -body {
    ::tclcurl::test::transport_cookies_shared ::tclcurl::test::server::base_url {}
} -result {1 1}

test cookies-1.3 {-cookielist injects a cookie into the easy handle cookie engine} -constraints http_server -body {
    ::tclcurl::test::transport_cookielist_inject ::tclcurl::test::server::base_url {}
} -result {0 1 1}

test cookies-1.4 {-cookielist FLUSH writes in-memory cookies to the -cookiejar file} -constraints http_server -body {
    ::tclcurl::test::transport_cookielist_flush ::tclcurl::test::server::base_url {}
} -result {1 1}

test cookies-1.5 {-cookiesession ignores session cookies loaded from -cookiefile} -constraints http_server -body {
    ::tclcurl::test::transport_cookiesession ::tclcurl::test::server::base_url {}
} -result {1 1}

cleanupTests
