mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
test(chrome): compare both producers on a shadow-dom parity page
This commit is contained in:
1 parent
f58ab5f0db
commit
61be8c0788
2 files changed
+63
-18
No files matched your search
@@ -60,30 +60,41 @@ type factRow struct {
|
||||
facts elementFacts
|
||||
}
|
||||
|
||||
// parityPages are the pages both producers are compared on. Each one must
|
||||
// exercise every fact both ways on its own (requireBothPolarities), so adding a
|
||||
// page never weakens the comparison. fact-parity-shadow.html is shaped like a
|
||||
// Compose for Web app: the whole UI lives inside a shadow root, which both
|
||||
// producers have to descend into or they enumerate one node for an entire app.
|
||||
var parityPages = []string{"fact-parity.html", "fact-parity-shadow.html"}
|
||||
|
||||
func TestHierarchy_DerivesTheSameFactsAsTheWebRuntime(t *testing.T) {
|
||||
server := httptest.NewServer(http.FileServer(http.Dir("testdata")))
|
||||
defer server.Close()
|
||||
|
||||
d := New()
|
||||
defer d.Terminate(context.Background())
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
defer cancel()
|
||||
if err := d.Launch(ctx, server.URL+"/fact-parity.html", false, nil); err != nil {
|
||||
t.Fatalf("Launch: %v", err)
|
||||
}
|
||||
for _, page := range parityPages {
|
||||
t.Run(page, func(t *testing.T) {
|
||||
d := New()
|
||||
defer d.Terminate(context.Background())
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
defer cancel()
|
||||
if err := d.Launch(ctx, server.URL+"/"+page, false, nil); err != nil {
|
||||
t.Fatalf("Launch: %v", err)
|
||||
}
|
||||
|
||||
dump, err := d.Hierarchy(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("Hierarchy: %v", err)
|
||||
}
|
||||
fromDump := factsFromHierarchyDump(t, dump)
|
||||
fromWebRuntime := factsFromWebRuntime(ctx, t, d)
|
||||
dump, err := d.Hierarchy(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("Hierarchy: %v", err)
|
||||
}
|
||||
fromDump := factsFromHierarchyDump(t, dump)
|
||||
fromWebRuntime := factsFromWebRuntime(ctx, t, d)
|
||||
|
||||
requireEveryElementNamed(t, "the hierarchy dump", fromDump)
|
||||
requireEveryElementNamed(t, "the web runtime", fromWebRuntime)
|
||||
requireBothPolarities(t, fromWebRuntime)
|
||||
compareEnumeratedElements(t, fromDump, fromWebRuntime)
|
||||
compareDerivedFacts(t, fromDump, fromWebRuntime)
|
||||
requireEveryElementNamed(t, "the hierarchy dump", fromDump)
|
||||
requireEveryElementNamed(t, "the web runtime", fromWebRuntime)
|
||||
requireBothPolarities(t, fromWebRuntime)
|
||||
compareEnumeratedElements(t, fromDump, fromWebRuntime)
|
||||
compareDerivedFacts(t, fromDump, fromWebRuntime)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// factsFromHierarchyDump reads the dump the way the goja host does: parse it,
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<!doctype html>
|
||||
<html id="page">
|
||||
<head id="page-head">
|
||||
<meta id="page-charset" charset="utf-8" />
|
||||
<title id="page-title">fact parity: shadow dom</title>
|
||||
</head>
|
||||
<body id="page-body">
|
||||
<!-- Shaped like Compose for Web: one mount element owning a shadow root
|
||||
that holds the canvas plus an accessibility overlay whose nodes are
|
||||
pointer-events: none, so taps fall through to the canvas. A producer
|
||||
that stops at the shadow boundary reports this whole app as one node. -->
|
||||
<div id="host">
|
||||
<div id="host-light-child">light child, no slot to render into</div>
|
||||
</div>
|
||||
<script id="page-script">
|
||||
const root = document.getElementById("host").attachShadow({ mode: "open" });
|
||||
root.innerHTML = `
|
||||
<style id="shadow-style">
|
||||
#shadow-surface { position: absolute; inset: 0; }
|
||||
#shadow-overlay { position: absolute; inset: 0; pointer-events: none; }
|
||||
#shadow-scroller { width: 320px; height: 120px; overflow: auto; }
|
||||
#shadow-scroller-content { height: 600px; }
|
||||
</style>
|
||||
<canvas id="shadow-surface" width="420" height="640"></canvas>
|
||||
<div id="shadow-overlay">
|
||||
<button id="shadow-save">save</button>
|
||||
<button id="shadow-cancel" disabled>cancel</button>
|
||||
<input id="shadow-amount" type="text" value="10" />
|
||||
<div id="shadow-plain">plain</div>
|
||||
</div>
|
||||
<div id="shadow-scroller"><div id="shadow-scroller-content"></div></div>`;
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user