package browser

import (
	"encoding/json"
	"strings"
	"testing"
)

func TestCdpHarRecord_nilConn(t *testing.T) {
	if _, err := CdpHarRecord(nil, nil, 0); err == nil {
		t.Fatal("expected error on nil conn")
	}
}

func TestCdpHarRecord_emptyHarStructure(t *testing.T) {
	// Construir un HAR vacio manualmente y verificar que serializa a la
	// estructura HAR 1.2 esperada (campos top-level).
	var har HarLog
	har.Log.Version = "1.2"
	har.Log.Creator.Name = "test"
	har.Log.Creator.Version = "0"
	har.Log.Pages = []any{}
	har.Log.Entries = []HarEntry{}

	out, err := json.Marshal(har)
	if err != nil {
		t.Fatalf("marshal: %v", err)
	}
	s := string(out)
	for _, want := range []string{`"log":`, `"version":"1.2"`, `"creator":`, `"entries":[]`} {
		if !strings.Contains(s, want) {
			t.Errorf("missing %q in: %s", want, s)
		}
	}
}
