package browser

import (
	"context"
	"testing"
)

func TestPrintPDF_NoCookies(t *testing.T) {
	ctx := context.Background()
	allocator, cancel := NewHeadlessAllocator(ctx)
	defer cancel()
	_, err := PrintPDF(allocator.Context, PrintPDFOptions{Address: "http://example.com"})
	if err == nil {
		t.Error("expected error when no cookies provided")
	}
}

func TestPrintPDF_Timeout(t *testing.T) {
	ctx := context.Background()

	allocator, cancel := NewHeadlessAllocator(ctx)
	defer cancel()
	// This will timeout since chromedp will not actually navigate
	_, err := PrintPDF(allocator.Context, PrintPDFOptions{
		Address: "http://unreachable.local",
	})
	if err == nil {
		t.Error("expected timeout error")
	}
}

func TestPrintPDF_GenerateGooglePDF(t *testing.T) {
	ctx := context.Background()

	allocator, cancel := NewHeadlessAllocator(ctx)
	defer cancel()
	cookies := []Cookie{{Name: "test", Value: "test", Domain: "google.com"}}
	ctx = NewCookieContext(ctx, cookies)
	pdf, err := PrintPDF(allocator.Context, PrintPDFOptions{
		Address: "https://www.google.com",
	})
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	if len(pdf) == 0 {
		t.Error("expected non-empty pdf buffer")
	}
	// os.WriteFile("test.pdf", pdf, 0644)
}
