8742cb25be
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
77 lines
2.4 KiB
Go
77 lines
2.4 KiB
Go
package browser
|
|
|
|
import "testing"
|
|
|
|
// TestBuildFullPageClip cubre el nucleo puro del modo FullPage: dado el mapa de
|
|
// Page.getLayoutMetrics, construir el clip que cubre el documento entero. No
|
|
// requiere Chrome.
|
|
func TestBuildFullPageClip(t *testing.T) {
|
|
t.Run("golden: pagina larga via cssContentSize", func(t *testing.T) {
|
|
metrics := map[string]any{
|
|
"cssContentSize": map[string]any{
|
|
"x": 0.0, "y": 0.0, "width": 1280.0, "height": 8000.0,
|
|
},
|
|
}
|
|
clip, ok := buildFullPageClip(metrics)
|
|
if !ok {
|
|
t.Fatal("esperaba ok=true para cssContentSize valido")
|
|
}
|
|
if clip.Width != 1280 || clip.Height != 8000 {
|
|
t.Errorf("clip = %+v, esperaba width=1280 height=8000", clip)
|
|
}
|
|
if clip.X != 0 || clip.Y != 0 || clip.Scale != 1 {
|
|
t.Errorf("clip = %+v, esperaba x=0 y=0 scale=1", clip)
|
|
}
|
|
})
|
|
|
|
t.Run("edge: viewport pequeno (pagina corta) sigue produciendo clip valido", func(t *testing.T) {
|
|
metrics := map[string]any{
|
|
"cssContentSize": map[string]any{"width": 320.0, "height": 480.0},
|
|
}
|
|
clip, ok := buildFullPageClip(metrics)
|
|
if !ok {
|
|
t.Fatal("esperaba ok=true para pagina corta")
|
|
}
|
|
if clip.Width != 320 || clip.Height != 480 {
|
|
t.Errorf("clip = %+v, esperaba 320x480", clip)
|
|
}
|
|
})
|
|
|
|
t.Run("edge: fallback a contentSize cuando falta cssContentSize", func(t *testing.T) {
|
|
metrics := map[string]any{
|
|
"contentSize": map[string]any{"width": 1024.0, "height": 2048.0},
|
|
}
|
|
clip, ok := buildFullPageClip(metrics)
|
|
if !ok {
|
|
t.Fatal("esperaba ok=true via contentSize")
|
|
}
|
|
if clip.Width != 1024 || clip.Height != 2048 {
|
|
t.Errorf("clip = %+v, esperaba 1024x2048", clip)
|
|
}
|
|
})
|
|
|
|
t.Run("error: dimensiones cero -> ok=false (captura solo viewport)", func(t *testing.T) {
|
|
metrics := map[string]any{
|
|
"cssContentSize": map[string]any{"width": 0.0, "height": 0.0},
|
|
}
|
|
if _, ok := buildFullPageClip(metrics); ok {
|
|
t.Error("esperaba ok=false para dimensiones cero")
|
|
}
|
|
})
|
|
|
|
t.Run("error: pagina vacia (metrics sin tamano) -> ok=false", func(t *testing.T) {
|
|
if _, ok := buildFullPageClip(map[string]any{}); ok {
|
|
t.Error("esperaba ok=false para metrics vacio")
|
|
}
|
|
})
|
|
|
|
t.Run("error: width valido pero height cero -> ok=false", func(t *testing.T) {
|
|
metrics := map[string]any{
|
|
"cssContentSize": map[string]any{"width": 800.0, "height": 0.0},
|
|
}
|
|
if _, ok := buildFullPageClip(metrics); ok {
|
|
t.Error("esperaba ok=false cuando un eje es cero")
|
|
}
|
|
})
|
|
}
|