package server
import (
"context"
"io"
"net/http"
"net/http/httptest"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"time"
)
func TestProjectionMetadataChromium(t *testing.T) {
if os.Getenv("PAGESWIKI_BROWSER_TEST") != "1" {
t.Skip("opt-in Chromium")
}
for _, mode := range []string{"pdf", "archive", "comic", "failed"} {
t.Run(mode, func(t *testing.T) {
s, token, domain := configFixture(t)
pdfOutput := "Pages: 3\n"
if mode == "failed" {
pdfOutput = "Pages: 10001\n"
}
stubMetadataCommands(t, pdfOutput, "Path = page-1.png\nSize = 1\n\nPath = page-2.png\nSize = 1\n\nPath =
.png\nSize = 1\n\n")
path, contentType := "/document.pdf", "application/pdf"
if mode == "archive" || mode == "comic" {
path, contentType = "/document.7z", "application/x-7z-compressed"
}
saveMetadataDocument(t, s, domain, path, contentType)
s.mux.HandleFunc(path, s.handleSemanticRoute)
s.mux.HandleFunc("/v/pdf-page", s.handlePDFPage)
s.mux.HandleFunc("/v/archive", s.handleArchiveEntry)
script, err := os.ReadFile("internal/server/testdata/projection-metadata.js")
if err != nil {
t.Fatal(err)
}
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.Host = "localhost"
r.Header.Set("Authorization", "Bearer "+token)
if r.URL.Query().Get("entry") != "" || (r.URL.Path == "/v/pdf-page" && r.URL.Query().Get("metadata") == "") {
w.Header().Set("Content-Type", "image/svg+xml")
_, _ = io.WriteString(w, ``)
return
}
if r.URL.Path == path {
recorder := httptest.NewRecorder()
s.withAuthorization(s.mux).ServeHTTP(recorder, r)
for key, values := range recorder.Header() {
w.Header()[key] = values
}
w.WriteHeader(recorder.Code)
_, _ = io.WriteString(w, strings.Replace(recorder.Body.String(), "