Repository navigation
Expand file tree
/
Copy pathenginejs_test.go
More file actions
593 lines (539 loc) · 20.8 KB
/
Copy pathenginejs_test.go
File metadata and controls
593 lines (539 loc) · 20.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
// Copyright (c) the go-webengine/engine authors.
// SPDX-License-Identifier: BSD-3-Clause
package engine
import (
"context"
"image"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
"github.com/go-webengine/engine/dom"
)
// TestJSMutationReflectedInLayout proves the script pass runs BEFORE the cascade
// and layout: a script that injects many paragraphs makes the laid-out page
// materially taller than the same document rendered with JS disabled.
func TestJSMutationReflectedInLayout(t *testing.T) {
var sb strings.Builder
sb.WriteString(`<html><head><title>t</title></head><body><div id="app"></div>`)
sb.WriteString(`<script>
var html='';
for (var i=0;i<40;i++){ html += '<p>line number '+i+' with some words to wrap</p>'; }
document.getElementById('app').innerHTML = html;
</script></body></html>`)
src := sb.String()
vp := image.Rect(0, 0, 400, 300)
eOn := New()
_, infoOn, err := eOn.RenderHTML(context.Background(), src, "https://example.com/", vp)
if err != nil {
t.Fatal(err)
}
eOff := New()
eOff.DisableJS = true
_, infoOff, err := eOff.RenderHTML(context.Background(), src, "https://example.com/", vp)
if err != nil {
t.Fatal(err)
}
if infoOn.ContentHeight <= infoOff.ContentHeight {
t.Fatalf("JS-injected content should grow the page: on=%d off=%d",
infoOn.ContentHeight, infoOff.ContentHeight)
}
}
// TestJSClientJSSignalStyled proves the client-js signal reaches the cascade:
// a rule gated on .client-js changes the body background only when JS runs.
func TestJSClientJSSignalStyled(t *testing.T) {
src := `<html class="client-nojs"><head><title>t</title>
<style>
body { background-color: rgb(10,20,30); }
html.client-js body { background-color: rgb(200,100,50); }
</style></head><body>hi</body></html>`
vp := image.Rect(0, 0, 100, 50)
on := renderTopLeft(t, New(), src, vp)
off := func() [3]uint8 {
e := New()
e.DisableJS = true
return renderTopLeft(t, e, src, vp)
}()
if on != [3]uint8{200, 100, 50} {
t.Fatalf("client-js rule should apply with JS on, got %v", on)
}
if off != [3]uint8{10, 20, 30} {
t.Fatalf("no-JS fallback should apply with JS off, got %v", off)
}
}
// TestDisableJSDeterministic confirms DisableJS leaves the no-JS fallback in
// place (the html keeps client-nojs; no client-js is added).
func TestDisableJSDeterministic(t *testing.T) {
src := `<html class="client-nojs"><head><title>t</title></head>` +
`<body><script>document.documentElement.className='changed'</script></body></html>`
e := New()
e.DisableJS = true
// Render must succeed and not run the script (which would rename the class).
_, _, err := e.RenderHTML(context.Background(), src, "https://example.com/", image.Rect(0, 0, 50, 50))
if err != nil {
t.Fatal(err)
}
}
// TestEnableDoneSignalStopsSettleEarly proves the settle loop honors a page's
// own __webengineDone() signal. It reuses TestSettleFixpointCap's own
// self-replicating script chain (dynamic_test.go) — one generation per
// settle pass, already proven to reach data-d="4" (one pre-loop pass plus
// the three maxSettlePasses-bounded loop passes) — and has each generation
// call __webengineDone() once n reaches 2. With EnableDoneSignal on, the
// loop must break right after that generation, leaving data-d="2" rather
// than running the chain out to "4". With EnableDoneSignal left at its
// default (false), __webengineDone is never installed (the chain's own
// typeof guard skips calling it), so the exact same page must still reach
// "4" — proving the feature is a true no-op for a caller not using it.
func TestEnableDoneSignalStopsSettleEarly(t *testing.T) {
src := `<html><head></head><body><script>
var code = "var b=document.body; var n=(+(b.getAttribute('data-d')||'0'))+1;" +
"b.setAttribute('data-d',''+n);" +
"if (n>=2 && typeof __webengineDone==='function'){__webengineDone(n);}" +
"var s=document.createElement('script'); s.textContent=b.getAttribute('data-code'); b.appendChild(s);";
document.body.setAttribute('data-code', code);
var s=document.createElement('script'); s.textContent=code; document.body.appendChild(s);
</script></body></html>`
vp := image.Rect(0, 0, 200, 200)
on := New()
on.EnableDoneSignal = true
doc, _ := renderDoc(t, on, src, context.Background(), vp)
if got, _ := dom.Find(doc.Root, "body").Attribute("data-d"); got != "2" {
t.Fatalf("data-d = %q, want %q (settle should stop right after __webengineDone fires)", got, "2")
}
off := New()
doc2, _ := renderDoc(t, off, src, context.Background(), vp)
if got, _ := dom.Find(doc2.Root, "body").Attribute("data-d"); got != "4" {
t.Fatalf("data-d = %q, want %q (EnableDoneSignal default must not change behaviour)", got, "4")
}
}
// TestJSInjectedLinkInHitMap proves the JavaScript pass runs on the
// RenderWithLinks path too: a script that appends an <a href> to the body makes
// that anchor appear in the returned hit-map, and with JS disabled it does not.
func TestJSInjectedLinkInHitMap(t *testing.T) {
src := `<html><head><title>t</title></head><body>` +
`<script>
var a = document.createElement('a');
a.setAttribute('href', '/injected');
a.textContent = 'go here now';
document.body.appendChild(a);
</script></body></html>`
vp := image.Rect(0, 0, 400, 300)
on := New()
_, _, links, err := on.RenderDocumentFromHTML(t, src, "https://example.com/", vp)
if err != nil {
t.Fatal(err)
}
if len(links) != 1 || links[0].Href != "https://example.com/injected" {
t.Fatalf("JS-injected anchor should appear in the hit-map, got %+v", links)
}
if links[0].Rect.Empty() {
t.Error("injected link rect is empty")
}
off := New()
off.DisableJS = true
_, _, offLinks, err := off.RenderDocumentFromHTML(t, src, "https://example.com/", vp)
if err != nil {
t.Fatal(err)
}
if len(offLinks) != 0 {
t.Fatalf("with JS disabled the anchor must not exist: %+v", offLinks)
}
}
// TestJSTitleReflectedInRenderInfo proves a script that sets document.title is
// reflected in RenderInfo.Title on both the plain and the with-links paths.
func TestJSTitleReflectedInRenderInfo(t *testing.T) {
src := `<html><head><title>old</title></head><body>` +
`<script>document.title = 'new title';</script></body></html>`
vp := image.Rect(0, 0, 200, 100)
_, info, err := New().RenderHTML(context.Background(), src, "https://example.com/", vp)
if err != nil {
t.Fatal(err)
}
if info.Title != "new title" {
t.Fatalf("RenderDocument title = %q, want %q", info.Title, "new title")
}
root, err := parseDoc(src)
if err != nil {
t.Fatal(err)
}
_, wl, _, err := New().RenderDocumentWithLinks(context.Background(), root, vp)
if err != nil {
t.Fatal(err)
}
if wl.Title != "new title" {
t.Fatalf("RenderDocumentWithLinks title = %q, want %q", wl.Title, "new title")
}
}
// TestEnableWorkerStreamingDeliversUnsolicitedMessages proves
// Engine.EnableWorkerStreaming's own core contract — confirmed directly by
// go-wasmcontainers (engine#342's own peer, not a hypothetical): a Worker
// that streams UNSOLICITED messages over real wall-clock time (not merely a
// reply within one postMessage call, which js.Worker already delivered
// before this round) is actually seen by main, while main keeps running its
// own timers concurrently — the exact "worker streams N unsolicited
// messages while main keeps running timers" shape the peer's own probe
// checks for. Without EnableWorkerStreaming, the settle loop would stop the
// instant the main script's single pass (registering onmessage, starting
// its own timer chain) produces no further layout change, and NONE of the
// worker's 100 messages would ever be observed.
func TestEnableWorkerStreamingDeliversUnsolicitedMessages(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`
var n = 0;
function tick() {
n++;
postMessage(n);
if (n < 100) setTimeout(tick, 2);
}
tick();
`))
}))
defer srv.Close()
src := `<html><head><title>t</title></head><body><script>
var w = new Worker('` + srv.URL + `/worker.js');
var mainTicks = 0;
function mainTick() {
mainTicks++;
document.body.setAttribute('data-main-ticks', String(mainTicks));
setTimeout(mainTick, 3);
}
mainTick();
w.onmessage = function(e) {
document.body.setAttribute('data-got', String(e.data));
if (e.data >= 100) { __webengineDone(); }
};
</script></body></html>`
doc, err := parseDoc(src)
if err != nil {
t.Fatal(err)
}
e := New()
e.EnableWorkerStreaming = true
e.EnableDoneSignal = true
e.JSTimeout = 5 * time.Second
vp := image.Rect(0, 0, 200, 100)
if _, _, err := e.RenderDocument(context.Background(), doc, vp); err != nil {
t.Fatal(err)
}
body := dom.Find(doc.Root, "body")
if got, _ := body.Attribute("data-got"); got != "100" {
t.Fatalf("data-got = %q, want %q (not every streamed message was delivered)", got, "100")
}
if ticks, _ := body.Attribute("data-main-ticks"); ticks == "" || ticks == "0" {
t.Fatalf("data-main-ticks = %q, want a positive count (main's own timers were starved)", ticks)
}
}
// TestEnableWorkerStreamingOffLeavesStreamingWorkerUnseen is the control for
// the test above: with the feature left at its default (false), the SAME
// page's streamed messages are NOT fully delivered (the settle loop still
// stops at its old DOM-change fixpoint), proving the new mode is additive —
// a caller not using it keeps today's exact behaviour.
func TestEnableWorkerStreamingOffLeavesStreamingWorkerUnseen(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`
var n = 0;
function tick() {
n++;
postMessage(n);
if (n < 100) setTimeout(tick, 2);
}
tick();
`))
}))
defer srv.Close()
src := `<html><head><title>t</title></head><body><script>
var w = new Worker('` + srv.URL + `/worker.js');
w.onmessage = function(e) {
document.body.setAttribute('data-got', String(e.data));
};
</script></body></html>`
doc, err := parseDoc(src)
if err != nil {
t.Fatal(err)
}
e := New()
vp := image.Rect(0, 0, 200, 100)
if _, _, err := e.RenderDocument(context.Background(), doc, vp); err != nil {
t.Fatal(err)
}
body := dom.Find(doc.Root, "body")
if got, _ := body.Attribute("data-got"); got == "100" {
t.Fatalf("data-got = %q: the control page should NOT fully observe the stream without EnableWorkerStreaming", got)
}
}
// TestSetIntervalPollsRepeatedlyWithWorkerStreaming reproduces, and proves
// fixed, go-wasmcontainers' own reported v0.27.1 symptom ("only 1/100"
// messages observed): their page used setInterval to periodically check
// "has everything arrived yet", and setInterval firing only once (this
// engine's own pre-existing, undocumented-to-them simplification) meant that
// check ran exactly once, very early, reporting a stale count rather than
// the real one. With setInterval now genuinely repeating (paced by real
// wall-clock time, not bursting), a worker streaming messages over real time
// and a page polling for completion via setInterval must now see the true,
// final count.
func TestSetIntervalPollsRepeatedlyWithWorkerStreaming(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`
var n = 0;
function tick() {
n++;
postMessage(n);
if (n < 20) setTimeout(tick, 2);
}
tick();
`))
}))
defer srv.Close()
src := `<html><head><title>t</title></head><body><script>
var w = new Worker('` + srv.URL + `/worker.js');
var received = 0;
w.onmessage = function(e) { received = e.data; };
var checks = 0;
var pollId = setInterval(function() {
checks++;
document.body.setAttribute('data-checks', String(checks));
document.body.setAttribute('data-received-at-done', String(received));
if (received >= 20) {
clearInterval(pollId);
__webengineDone();
}
}, 5);
</script></body></html>`
doc, err := parseDoc(src)
if err != nil {
t.Fatal(err)
}
e := New()
e.EnableWorkerStreaming = true
e.EnableDoneSignal = true
e.JSTimeout = 3 * time.Second
vp := image.Rect(0, 0, 200, 100)
if _, _, err := e.RenderDocument(context.Background(), doc, vp); err != nil {
t.Fatal(err)
}
body := dom.Find(doc.Root, "body")
receivedAtDone, _ := body.Attribute("data-received-at-done")
checks, _ := body.Attribute("data-checks")
if receivedAtDone != "20" {
t.Fatalf("data-received-at-done = %q, want %q (checks=%q) — setInterval should have kept polling until the real count arrived", receivedAtDone, "20", checks)
}
if checks == "1" {
t.Fatal("setInterval only checked once — it should have polled repeatedly until the worker finished streaming")
}
}
// TestRealTimeTimersHonorSafetyNetDelay reproduces, and proves fixed, the
// real root cause behind go-wasmcontainers' OWN e2e probe reporting "only
// 1/100 messages in 15 s" even after the setInterval fix: their page's
// safety-net `setTimeout(giveUp, 15000)` — racing a worker's own streamed
// messages, the exact "near-immediate retry vs. much-later give-up timer"
// idiom drainTimers' own doc comment describes — fired almost instantly
// (confirmed directly: a standalone reproduction of their exact scripts
// completed in 3.68ms, not 15 real seconds) rather than waiting its own
// requested delay, because only a repeating setInterval's OWN repeats had
// real wall-clock gating before this fix — a plain one-shot setTimeout's
// first (and only) firing did not. With RealTimeTimers now also gating a
// job's first firing (mapped from EnableWorkerStreaming), the safety net
// must wait its real delay, letting the worker's own faster stream finish
// first.
func TestRealTimeTimersHonorSafetyNetDelay(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`
var i = 0;
(function tick() { postMessage(i++); if (i < 20) setTimeout(tick, 5); })();
`))
}))
defer srv.Close()
src := `<html><head><title>t</title></head><body><script>
var w = new Worker('` + srv.URL + `/worker.js');
var got = 0;
var safetyFired = false;
setTimeout(function() {
safetyFired = true;
document.body.setAttribute('data-safety-fired', 'true');
document.body.setAttribute('data-got-at-safety', String(got));
__webengineDone();
}, 2000);
w.onmessage = function(e) {
got = e.data + 1;
if (got >= 20 && !safetyFired) {
document.body.setAttribute('data-done-early', 'true');
__webengineDone();
}
};
</script></body></html>`
doc, err := parseDoc(src)
if err != nil {
t.Fatal(err)
}
e := New()
e.EnableWorkerStreaming = true
e.EnableDoneSignal = true
e.JSTimeout = 5 * time.Second
vp := image.Rect(0, 0, 200, 100)
start := time.Now()
if _, _, err := e.RenderDocument(context.Background(), doc, vp); err != nil {
t.Fatal(err)
}
elapsed := time.Since(start)
body := dom.Find(doc.Root, "body")
if got, _ := body.Attribute("data-safety-fired"); got == "true" {
gotAt, _ := body.Attribute("data-got-at-safety")
t.Fatalf("the 2s safety-net timeout fired after only %v, before the worker's own ~100ms stream finished (got %s/20 messages) — a one-shot setTimeout's first firing is not honouring its own real delay", elapsed, gotAt)
}
if got, _ := body.Attribute("data-done-early"); got != "true" {
t.Fatalf("data-done-early = %q, want %q — the stream should have finished well before the 2s safety net", got, "true")
}
if elapsed > time.Second {
t.Fatalf("render took %v, want well under the 2s safety net (the stream itself needs only ~100ms of real time)", elapsed)
}
}
// TestAtomicsWaitWokenByNotifyAcrossWorkers proves M3's own core contract
// (issue #343): a SharedArrayBuffer created on main, shared with a Worker via
// postMessage, backs a real cross-goroutine Atomics.wait/notify handshake —
// the worker's own real goroutine genuinely blocks in Atomics.wait (deferred
// via setTimeout(fn, 0) so it runs on the worker's own ticker, never inline
// inside the message handler — see deliver's own doc comment for why that
// matters: doing it synchronously would deadlock against main's later
// Atomics.notify call).
//
// The worker tells main it is ABOUT to wait (postMessage('waiting')) in the
// exact same synchronous callback as the Atomics.wait call right after it,
// with no yield point in between — so by the time main's own handler for
// that message runs and calls Atomics.notify, the worker is GUARANTEED to
// already be blocked (this engine's own timer queue has no real wall-clock
// pacing WITHIN one drain burst — see drainTimers' own doc comment — so a
// plain setTimeout-based delay cannot be used to approximate "the worker
// should be waiting by now" reliably; this handshake needs no such timing
// assumption at all). Confirms the woken wait observes the NEW value through
// the SAME underlying memory (not a copy).
func TestAtomicsWaitWokenByNotifyAcrossWorkers(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`
var view;
onmessage = function(e) {
view = new Int32Array(e.data);
setTimeout(function() {
postMessage('waiting');
var r = Atomics.wait(view, 0, 0, 5000);
postMessage(r + ':' + Atomics.load(view, 0));
}, 0);
};
`))
}))
defer srv.Close()
src := `<html><head><title>t</title></head><body><script>
var sab = new SharedArrayBuffer(4);
var view = new Int32Array(sab);
Atomics.store(view, 0, 0);
var w = new Worker('` + srv.URL + `/worker.js');
var notified = false;
w.onmessage = function(e) {
if (e.data === 'waiting' && !notified) {
notified = true;
Atomics.store(view, 0, 42);
Atomics.notify(view, 0);
return;
}
document.body.setAttribute('data-reply', String(e.data));
__webengineDone();
};
w.postMessage(sab);
</script></body></html>`
doc, err := parseDoc(src)
if err != nil {
t.Fatal(err)
}
e := New()
e.EnableWorkerStreaming = true
e.EnableDoneSignal = true
e.JSTimeout = 5 * time.Second
// SharedArrayBuffer/Atomics are gated on cross-origin isolation (a real
// browser denies both without COOP/COEP) — this test builds its own
// Document (parseDoc, no real HTTP response headers to check), so it
// uses the Engine-level escape hatch rather than fabricating headers.
e.ForceCrossOriginIsolated = true
vp := image.Rect(0, 0, 200, 100)
if _, _, err := e.RenderDocument(context.Background(), doc, vp); err != nil {
t.Fatal(err)
}
body := dom.Find(doc.Root, "body")
if got, _ := body.Attribute("data-reply"); got != "ok:42" {
t.Fatalf("data-reply = %q, want %q (wait should be woken by notify and see the new, shared value)", got, "ok:42")
}
}
// TestAtomicsWaitAcrossWorkersTimesOut is the control: with nobody ever
// calling Atomics.notify, the worker's own Atomics.wait must time out on its
// own short timeout rather than hang forever (or hang the render out to
// JSTimeout).
func TestAtomicsWaitAcrossWorkersTimesOut(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`
var view;
onmessage = function(e) {
view = new Int32Array(e.data);
setTimeout(function() {
var r = Atomics.wait(view, 0, 0, 100);
postMessage(r);
}, 0);
};
`))
}))
defer srv.Close()
src := `<html><head><title>t</title></head><body><script>
var sab = new SharedArrayBuffer(4);
var w = new Worker('` + srv.URL + `/worker.js');
w.onmessage = function(e) {
document.body.setAttribute('data-reply', String(e.data));
__webengineDone();
};
w.postMessage(sab);
</script></body></html>`
doc, err := parseDoc(src)
if err != nil {
t.Fatal(err)
}
e := New()
e.EnableWorkerStreaming = true
e.EnableDoneSignal = true
e.JSTimeout = 5 * time.Second
e.ForceCrossOriginIsolated = true
vp := image.Rect(0, 0, 200, 100)
if _, _, err := e.RenderDocument(context.Background(), doc, vp); err != nil {
t.Fatal(err)
}
body := dom.Find(doc.Root, "body")
if got, _ := body.Attribute("data-reply"); got != "timed-out" {
t.Fatalf("data-reply = %q, want %q", got, "timed-out")
}
}
// RenderDocumentFromHTML parses src and renders it with the with-links pipeline,
// a small offline convenience for the JS hit-map tests.
func (e *Engine) RenderDocumentFromHTML(t *testing.T, src, baseURL string, vp image.Rectangle) (*image.RGBA, *RenderInfo, []Link, error) {
t.Helper()
doc, err := parseDoc(src)
if err != nil {
return nil, nil, nil, err
}
doc.URL = baseURL
return e.RenderDocumentWithLinks(context.Background(), doc, vp)
}
// parseDoc parses src into a Document with a placeholder URL.
func parseDoc(src string) (*Document, error) {
root, err := dom.Parse(src)
if err != nil {
return nil, err
}
return &Document{URL: "https://example.com/", Title: dom.Title(root), Root: root, HTML: src}, nil
}
// renderTopLeft renders src and returns the top-left pixel's RGB.
func renderTopLeft(t *testing.T, e *Engine, src string, vp image.Rectangle) [3]uint8 {
t.Helper()
img, _, err := e.RenderHTML(context.Background(), src, "https://example.com/", vp)
if err != nil {
t.Fatal(err)
}
i := img.PixOffset(1, 1)
return [3]uint8{img.Pix[i], img.Pix[i+1], img.Pix[i+2]}
}