Skip to content

Truly independent web browser

LibWeb: Stop the percentage-height quirk at an unresolvable height

sideshowbarkerd95dab03c072
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
index 34657a7590e..49c8ccf7920 100644
--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
@@ -1404,6 +1404,10 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
})
} else if quirks_body_block.is_some() {
quirks_body_block
+ } else if !style.height().is_auto() && !metrics.has_definite_block_size() {
+ // NB: A height that can't be resolved, such as a percentage of an indefinite size, behaves as auto, but
+ // step 3 still ends the search at the element. So its block size leaves percentages no basis.
+ None
} else if !style.height().is_auto()
|| facts.is_absolutely_positioned()
|| !facts.is_block_container()
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/quirks/reference/percentage-height-quirk-excludes-flex-grid-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/quirks/reference/percentage-height-quirk-excludes-flex-grid-001-ref.html
new file mode 100644
index 00000000000..29f8e26a67f
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/quirks/reference/percentage-height-quirk-excludes-flex-grid-001-ref.html
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Reference: Percent height quirk does not traverse flex/grid containers</title>
+ <link rel="author" title="Daniel Holbert" href="mailto:[email protected]">
+ <link rel="author" href="https://mozilla.org" title="Mozilla">
+ <style>
+ .fixed-height-outer {
+ height: 80px;
+ border: 1px solid gray;
+ margin-bottom: 5px;
+ }
+
+ .row-flex {
+ display: flex;
+ flex-direction: row
+ }
+
+ .column-flex {
+ display: flex;
+ flex-direction: column
+ }
+
+ .grid {
+ display: grid;
+ }
+
+ .container {
+ border: 3px solid black;
+ }
+
+ .pct {
+ height: 75%;
+ min-height: 10px;
+ width: 50px;
+ display: inline-block;
+ vertical-align: top;
+ background: purple;
+ }
+ .px {
+ height: 50px;
+ width: 50px;
+ display: inline-block;
+ vertical-align: top;
+ background: blue
+ }
+ </style>
+</head>
+<body>
+ <div class="fixed-height-outer">
+ <div class="container column-flex">
+ <div>
+ <div class="pct"></div>
+ <div class="px"></div>
+ </div>
+ </div>
+ </div>
+ <div class="fixed-height-outer">
+ <div class="container row-flex">
+ <div>
+ <div class="pct"></div>
+ <div class="px"></div>
+ </div>
+ </div>
+ </div>
+ <div class="fixed-height-outer">
+ <div class="container grid">
+ <div>
+ <div class="pct"></div>
+ <div class="px"></div>
+ </div>
+ </div>
+ </div>
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/quirks/reference/percentage-height-quirk-excludes-flex-grid-002-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/quirks/reference/percentage-height-quirk-excludes-flex-grid-002-ref.html
new file mode 100644
index 00000000000..c63bc0efa85
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/quirks/reference/percentage-height-quirk-excludes-flex-grid-002-ref.html
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Reference case: Percent height quirk applies for percent heights on flex/grid containers</title>
+ <link rel="author" title="Daniel Holbert" href="mailto:[email protected]">
+ <link rel="author" href="https://mozilla.org" title="Mozilla">
+ <link rel="mismatch" href="percentage-height-quirk-excludes-flex-grid-002-notref.html">
+ <style>
+ .fixed-height-outer {
+ height: 80px;
+ border: 1px solid gray;
+ margin-bottom: 5px;
+ }
+
+ .row-flex {
+ display: flex;
+ flex-direction: row
+ }
+
+ .column-flex {
+ display: flex;
+ flex-direction: column
+ }
+
+ .grid {
+ display: grid;
+ }
+
+ .pct {
+ height: 75%;
+ min-height: 10px;
+ width: 50px;
+ background: purple;
+ }
+ </style>
+</head>
+<body>
+ <div class="fixed-height-outer">
+ <div class="column-flex pct"></div>
+ </div>
+ <div class="fixed-height-outer">
+ <div class="row-flex pct"></div>
+ </div>
+ <div class="fixed-height-outer">
+ <div class="grid pct"></div>
+ </div>
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/quirks/percentage-height-quirk-excludes-flex-grid-001.html b/Tests/LibWeb/Ref/input/wpt-import/quirks/percentage-height-quirk-excludes-flex-grid-001.html
new file mode 100644
index 00000000000..458d427a8b9
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/quirks/percentage-height-quirk-excludes-flex-grid-001.html
@@ -0,0 +1,78 @@
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Test: Percent height quirk does not traverse flex/grid containers</title>
+ <link rel="author" title="Daniel Holbert" href="mailto:[email protected]">
+ <link rel="author" href="https://mozilla.org" title="Mozilla">
+ <link rel="help" href="https://quirks.spec.whatwg.org/#the-percentage-height-calculation-quirk">
+ <link rel="match" href="../../../expected/wpt-import/quirks/reference/percentage-height-quirk-excludes-flex-grid-001-ref.html">
+ <meta name="assert" content="This quirk is specific to block boxes and table wrapper boxes; if it hits another type of box, it doesn't traverse further. So this file should look the same whether in quirks or standards mode.">
+ <style>
+ .fixed-height-outer {
+ height: 80px;
+ border: 1px solid gray;
+ margin-bottom: 5px;
+ }
+
+ .row-flex {
+ display: flex;
+ flex-direction: row
+ }
+
+ .column-flex {
+ display: flex;
+ flex-direction: column
+ }
+
+ .grid {
+ display: grid;
+ }
+
+ .container {
+ border: 3px solid black;
+ }
+
+ .pct {
+ height: 75%;
+ min-height: 10px;
+ width: 50px;
+ display: inline-block;
+ vertical-align: top;
+ background: purple;
+ }
+ .px {
+ height: 50px;
+ width: 50px;
+ display: inline-block;
+ vertical-align: top;
+ background: blue
+ }
+ </style>
+</head>
+<body>
+ <div class="fixed-height-outer">
+ <div class="container column-flex">
+ <div>
+ <div class="pct"></div>
+ <div class="px"></div>
+ </div>
+ </div>
+ </div>
+ <div class="fixed-height-outer">
+ <div class="container row-flex">
+ <div>
+ <div class="pct"></div>
+ <div class="px"></div>
+ </div>
+ </div>
+ </div>
+ <div class="fixed-height-outer">
+ <div class="container grid">
+ <div>
+ <div class="pct"></div>
+ <div class="px"></div>
+ </div>
+ </div>
+ </div>
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/quirks/percentage-height-quirk-excludes-flex-grid-002.html b/Tests/LibWeb/Ref/input/wpt-import/quirks/percentage-height-quirk-excludes-flex-grid-002.html
new file mode 100644
index 00000000000..6f2175150ab
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/quirks/percentage-height-quirk-excludes-flex-grid-002.html
@@ -0,0 +1,56 @@
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Test: Percent height quirk applies for percent heights on flex/grid containers</title>
+ <link rel="author" title="Daniel Holbert" href="mailto:[email protected]">
+ <link rel="author" href="https://mozilla.org" title="Mozilla">
+ <link rel="help" href="https://quirks.spec.whatwg.org/#the-percentage-height-calculation-quirk">
+ <link rel="match" href="../../../expected/wpt-import/quirks/reference/percentage-height-quirk-excludes-flex-grid-002-ref.html">
+ <meta name="assert" content="This quirk only starts differentiating by box-type when looking at the containing block of the percent-height thing. So, the quirk applies to percent-heights on flex/grid containers, when the ancestors are all blocks up to the nearest definite height.">
+ <style>
+ .fixed-height-outer {
+ height: 80px;
+ border: 1px solid gray;
+ margin-bottom: 5px;
+ }
+
+ .row-flex {
+ display: flex;
+ flex-direction: row
+ }
+
+ .column-flex {
+ display: flex;
+ flex-direction: column
+ }
+
+ .grid {
+ display: grid;
+ }
+
+ .pct {
+ height: 75%;
+ min-height: 10px;
+ width: 50px;
+ background: purple;
+ }
+ </style>
+</head>
+<body>
+ <div class="fixed-height-outer">
+ <div>
+ <div class="column-flex pct"></div>
+ </div>
+ </div>
+ <div class="fixed-height-outer">
+ <div>
+ <div class="row-flex pct"></div>
+ </div>
+ </div>
+ <div class="fixed-height-outer">
+ <div>
+ <div class="grid pct"></div>
+ </div>
+ </div>
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/quirks/percentage-height-quirk-excludes-flex-grid-003.html b/Tests/LibWeb/Ref/input/wpt-import/quirks/percentage-height-quirk-excludes-flex-grid-003.html
new file mode 100644
index 00000000000..85f82cf4ab1
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/quirks/percentage-height-quirk-excludes-flex-grid-003.html
@@ -0,0 +1,90 @@
+<!-- quirks-mode -->
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Test: Percent height quirk does not traverse flex/grid containers</title>
+ <link rel="author" title="Daniel Holbert" href="mailto:[email protected]">
+ <link rel="author" title="Ting-Yu Lin" href="mailto:[email protected]">
+ <link rel="author" href="https://mozilla.org" title="Mozilla">
+ <link rel="help" href="https://quirks.spec.whatwg.org/#the-percentage-height-calculation-quirk">
+ <link rel="match" href="../../../expected/wpt-import/quirks/reference/percentage-height-quirk-excludes-flex-grid-001-ref.html">
+ <meta name="assert" content="This quirk is specific to block boxes and table wrapper boxes; if it hits another type of box, it doesn't traverse further. So this file should look the same whether in quirks or standards mode.">
+ <style>
+ .fixed-height-outer {
+ height: 80px;
+ border: 1px solid gray;
+ margin-bottom: 5px;
+ }
+
+ .row-flex {
+ display: flex;
+ flex-direction: row
+ }
+
+ .column-flex {
+ display: flex;
+ flex-direction: column
+ }
+
+ .grid {
+ display: grid;
+ }
+
+ .container {
+ border: 3px solid black;
+ }
+
+ .pct {
+ height: 75%;
+ min-height: 10px;
+ width: 50px;
+ display: inline-block;
+ vertical-align: top;
+ background: purple;
+ }
+ .px {
+ height: 50px;
+ width: 50px;
+ display: inline-block;
+ vertical-align: top;
+ background: blue
+ }
+ </style>
+</head>
+<body>
+ <!-- This test is similar to
+ percentage-height-quirk-excludes-flex-grid-001.html, but with an
+ intermediate block between the percent-height element and the flex/grid
+ item. -->
+ <div class="fixed-height-outer">
+ <div class="container column-flex">
+ <div>
+ <div>
+ <div class="pct"></div>
+ <div class="px"></div>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="fixed-height-outer">
+ <div class="container row-flex">
+ <div>
+ <div>
+ <div class="pct"></div>
+ <div class="px"></div>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="fixed-height-outer">
+ <div class="container grid">
+ <div>
+ <div>
+ <div class="pct"></div>
+ <div class="px"></div>
+ </div>
+ </div>
+ </div>
+ </div>
+</body>
+</html>
diff --git a/Tests/LibWeb/Text/expected/Layout/quirks-percentage-height-inside-percentage-height-flex-item.txt b/Tests/LibWeb/Text/expected/Layout/quirks-percentage-height-inside-percentage-height-flex-item.txt
new file mode 100644
index 00000000000..564c6b4f092
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/Layout/quirks-percentage-height-inside-percentage-height-flex-item.txt
@@ -0,0 +1,7 @@
+BackCompat
+in-flex-item: 100
+in-column-flex-item: 100
+in-block: 600
+in-flex-item-with-definite-height: 50
+in-block-resolved-through-the-quirk: 300
+in-flex-item-with-fixed-height: 40
diff --git a/Tests/LibWeb/Text/expected/wpt-import/quirks/percentage-height-calculation.txt b/Tests/LibWeb/Text/expected/wpt-import/quirks/percentage-height-calculation.txt
new file mode 100644
index 00000000000..b76e810e2f4
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/quirks/percentage-height-calculation.txt
@@ -0,0 +1,59 @@
+Harness status: OK
+
+Found 53 tests
+
+47 Pass
+6 Fail
+Pass The percentage height calculation quirk, #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, #test { height:50% }<div id=test></div>
+Pass The percentage height calculation quirk, #test { height:25% }<div id=test></div>
+Pass The percentage height calculation quirk, #test { height:12.5% }<div id=test></div>
+Pass The percentage height calculation quirk, #test { height:100% }<div><div id=test></div></div>
+Pass The percentage height calculation quirk, <img id=test src="{png}" height=100%>
+Pass The percentage height calculation quirk, <img id=test src="{png}" height=100% border=10>
+Pass The percentage height calculation quirk, <table id=test height=100%><tr><td></table>
+Pass The percentage height calculation quirk, #foo { height:100px } #test { height:100% }<div id=foo><div><div id=test></div></div></div>
+Pass The percentage height calculation quirk, #foo { height:100px } #grid { display:grid } #test { height:100% }<div id=foo><div id=grid><div id=test></div></div></div>
+Pass The percentage height calculation quirk, #foo { height:100px } #grid { display:inline-grid } #test { height:100% }<div id=foo><div id=grid><div id=test></div></div></div>
+Pass The percentage height calculation quirk, #foo { height:100px } #flex { display:flex } #test { height:100% }<div id=foo><div id=flex><div id=test></div></div></div>
+Pass The percentage height calculation quirk, #foo { height:100px } #flex { display:inline-flex } #test { height:100% }<div id=foo><div id=flex><div id=test></div></div></div>
+Pass The percentage height calculation quirk, #foo { position:absolute } #test { height:100% }<div id=foo><div><div id=test></div></div></div>
+Pass The percentage height calculation quirk, #foo { position:relative } #test { height:100% }<div id=foo><div><div id=test></div></div></div>
+Pass The percentage height calculation quirk, #foo { position:sticky } #test { height:100% }<div id=foo><div><div id=test></div></div></div>
+Pass The percentage height calculation quirk, #foo { height:100px } #test { height:100%; position:absolute }<div id=foo><div><div id=test></div></div></div>
+Pass The percentage height calculation quirk, #foo { height:100px } #test { height:100%; position:fixed }<div id=foo><div><div id=test></div></div></div>
+Pass The percentage height calculation quirk, #foo { height:100px } #test { height:100%; position:relative }<div id=foo><div><div id=test></div></div></div>
+Pass The percentage height calculation quirk, #foo { height:100px } #test { height:calc(100% + 1px) }<div id=foo><div id=test></div></div>
+Fail The percentage height calculation quirk, #foo { height:100px } #test { height:5px; height:calc(100% + 1px) }<div id=foo><div><div id=test></div></div></div>
+Pass The percentage height calculation quirk, html { display:inline } #test { height:100% }<div id=test></div>
+Fail The percentage height calculation quirk, html { margin:10px } body { display:inline } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, body { margin:0 } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, body { margin:0; padding:10px } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, body { margin:0; border:10px solid } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, html { margin:10px } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, html { padding:10px } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, html { border:10px solid } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, html { position:absolute } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, body { position:absolute } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, html { height:100%; margin:10px } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, html { height:100%; padding:10px } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, html { height:100%; border:10px solid } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, body { height:100%; margin:10px } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, body { height:100%; padding:10px } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, body { height:100%; border:10px solid } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, html { position:absolute; height:100%; margin:10px } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, html { position:absolute; height:100%; padding:10px } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, html { position:absolute; height:100%; border:10px solid } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, body { margin:99px 0 } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, body { margin:110px 0 } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, html, body { border:10px none } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, html, body { border:10px hidden } #test { height:100% }<div id=test></div>
+Pass The percentage height calculation quirk, <html xmlns="{html}"><head><style>#test { height:100% }</style></head><body><div id="test"/></body></html>
+Pass The percentage height calculation quirk, <html xmlns="{html}"><head><style>#test { height:100% }</style></head><body/><div id="test"/></html>
+Pass The percentage height calculation quirk, <html xmlns="{html}"><head><style>#test { height:100% }</style></head><span><body><div id="test"/></body></span></html>
+Fail The percentage height calculation quirk, <html xmlns="{html}"><head><style>#test { height:100% }</style></head><body><body><div id="test"/></body></body></html>
+Fail The percentage height calculation quirk, <html><head xmlns="{html}"><style>#test { height:100% }</style></head><body xmlns="{html}"><div id="test"/></body></html>
+Fail The percentage height calculation quirk, <div xmlns="{html}"><head><style>#test { height:100% }</style></head><body><div id="test"/></body></div>
+Pass The percentage height calculation quirk, <html xmlns="{html}"><head><style>#test { height:100% }</style></head><body xmlns=""><div xmlns="{html}" id="test"/></body></html>
+Fail The percentage height calculation quirk, <HTML xmlns="{html}"><head><style>#test { height:100% }</style></head><body><div id="test"/></body></HTML>
+Pass The percentage height calculation quirk, <html xmlns="{html}"><head><style>#test { height:100% }</style></head><BODY><div id="test"/></BODY></html>
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/Layout/quirks-percentage-height-inside-percentage-height-flex-item.html b/Tests/LibWeb/Text/input/Layout/quirks-percentage-height-inside-percentage-height-flex-item.html
new file mode 100644
index 00000000000..3c28c572cda
--- /dev/null
+++ b/Tests/LibWeb/Text/input/Layout/quirks-percentage-height-inside-percentage-height-flex-item.html
@@ -0,0 +1,29 @@
+<!DOCTYPE quirks>
+<script src="../include.js"></script>
+<style>
+ body { margin: 0; }
+ .flex { display: flex; }
+ .pct { height: 100%; }
+ .content { height: 100px; }
+</style>
+<!-- In quirks mode, a percentage height inside a box whose own percentage height can't be resolved behaves as auto, as
+ it does in standards mode: The percentage-height calculation quirk stops at that box. -->
+<div class="flex"><div class="pct"><div class="pct" id="in-flex-item"><div class="content"></div></div></div></div>
+<div class="flex" style="flex-direction: column"><div class="pct"><div class="pct" id="in-column-flex-item"><div class="content"></div></div></div></div>
+<div><div class="pct"><div class="pct" id="in-block"><div class="content"></div></div></div></div>
+<div class="flex" style="height: 50px"><div class="pct"><div class="pct" id="in-flex-item-with-definite-height"><div class="content"></div></div></div></div>
+<div style="height: 50%"><div class="pct" id="in-block-resolved-through-the-quirk"></div></div>
+<div class="flex"><div style="height: 40px"><div class="pct" id="in-flex-item-with-fixed-height"></div></div></div>
+<script>
+ function run(report) {
+ report(document.compatMode);
+ for (const element of document.querySelectorAll("[id]:not(#out)"))
+ report(`${element.id}: ${element.getBoundingClientRect().height}`);
+ }
+</script>
+<script>
+ if (window.asyncTest)
+ asyncTest(done => addEventListener("load", () => { run(println); done(); }));
+ else
+ addEventListener("load", () => { run(line => console.log(line)); window.engineCompareDone = true; });
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/quirks/percentage-height-calculation.html b/Tests/LibWeb/Text/input/wpt-import/quirks/percentage-height-calculation.html
new file mode 100644
index 00000000000..052c052209c
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/quirks/percentage-height-calculation.html
@@ -0,0 +1,171 @@
+<!doctype html>
+<html>
+ <head>
+ <title>The percentage height calculation quirk</title>
+ <script src="../resources/testharness.js"></script>
+ <script src="../resources/testharnessreport.js"></script>
+ <style> iframe { width:20px; height:200px } </style>
+ </head>
+ <body>
+ <div id=log></div>
+ <iframe id=quirks></iframe>
+ <iframe id=almost></iframe>
+ <iframe id=standards></iframe>
+ <img id="preload">
+ <script>
+ var png = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==";
+ // Ensure png is loaded and cached before we run the tests. Otherwise
+ // the tests that use it may run while it's not fully loaded and get <img>
+ // fallback layout (i.e., not an image with a 1x1 intrinsic size).
+ document.getElementById('preload').src = png;
+ setup({explicit_done:true});
+
+ var png = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==";
+ var preload = new Image();
+ preload.src = png;
+
+ onload = function() {
+ var html = "<style id=style></style>";
+ var a_doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
+ var s_doctype = '<!DOCTYPE HTML>';
+ var q = document.getElementById('quirks').contentWindow;
+ var a = document.getElementById('almost').contentWindow;
+ var s = document.getElementById('standards').contentWindow;
+ q.document.open();
+ q.document.write(html);
+ q.document.close();
+ a.document.open();
+ a.document.write(a_doctype + html);
+ a.document.close();
+ s.document.open();
+ s.document.write(s_doctype + html);
+ s.document.close();
+ [q, a, s].forEach(function(win) {
+ ['style', 'test'].forEach(function(id) {
+ Object.getPrototypeOf(win).__defineGetter__(id, function() { return win.document.getElementById(id); });
+ });
+ });
+
+ function imagesLoaded() {
+ const promises = [];
+ for (const testWindow of [q, a, s]) {
+ for (const img of testWindow.document.images) {
+ promises.push(new Promise(resolve => img.addEventListener("load", resolve, {once: true})));
+ }
+ }
+ return Promise.all(promises);
+ }
+
+ var tests = [
+ {style:'#test { height:100% }', body:'<div id=test></div>', q:184, s:0},
+ {style:'#test { height:50% }', body:'<div id=test></div>', q:92, s:0},
+ {style:'#test { height:25% }', body:'<div id=test></div>', q:46, s:0},
+ {style:'#test { height:12.5% }', body:'<div id=test></div>', q:23, s:0},
+ {style:'#test { height:100% }', body:'<div><div id=test></div></div>', q:184, s:0},
+ {style:'', body:'<img id=test src="{png}" height=100%>', q:184, s:1},
+ {style:'', body:'<img id=test src="{png}" height=100% border=10>', q:184, s:1},
+ {style:'', body:'<table id=test height=100%><tr><td></table>', q:184, s:6},
+ {style:'#foo { height:100px } #test { height:100% }', body:'<div id=foo><div><div id=test></div></div></div>', q:100, s:0},
+ {style:'#foo { height:100px } #grid { display:grid } #test { height:100% }', body:'<div id=foo><div id=grid><div id=test></div></div></div>', q:0, s:0},
+ {style:'#foo { height:100px } #grid { display:inline-grid } #test { height:100% }', body:'<div id=foo><div id=grid><div id=test></div></div></div>', q:0, s:0},
+ {style:'#foo { height:100px } #flex { display:flex } #test { height:100% }', body:'<div id=foo><div id=flex><div id=test></div></div></div>', q:0, s:0},
+ {style:'#foo { height:100px } #flex { display:inline-flex } #test { height:100% }', body:'<div id=foo><div id=flex><div id=test></div></div></div>', q:0, s:0},
+ {style:'#foo { position:absolute } #test { height:100% }', body:'<div id=foo><div><div id=test></div></div></div>', q:0, s:0},
+ {style:'#foo { position:relative } #test { height:100% }', body:'<div id=foo><div><div id=test></div></div></div>', q:184, s:0},
+ {style:'#foo { position:sticky } #test { height:100% }', body:'<div id=foo><div><div id=test></div></div></div>', q:184, s:0},
+ {style:'#foo { height:100px } #test { height:100%; position:absolute }', body:'<div id=foo><div><div id=test></div></div></div>', q:200, s:200},
+ {style:'#foo { height:100px } #test { height:100%; position:fixed }', body:'<div id=foo><div><div id=test></div></div></div>', q:200, s:200},
+ {style:'#foo { height:100px } #test { height:100%; position:relative }', body:'<div id=foo><div><div id=test></div></div></div>', q:100, s:0},
+ {style:'#foo { height:100px } #test { height:calc(100% + 1px) }', body:'<div id=foo><div id=test></div></div>', q:101, s:101},
+ {style:'#foo { height:100px } #test { height:5px; height:calc(100% + 1px) }', body:'<div id=foo><div><div id=test></div></div></div>', q:0, s:0},
+ {style:'html { display:inline } #test { height:100% }', body:'<div id=test></div>', q:184, s:0}, // display:inline on root has no effect
+ {style:'html { margin:10px } body { display:inline } #test { height:100% }', body:'<div id=test></div>', q:180, s:0},
+ {style:'body { margin:0 } #test { height:100% }', body:'<div id=test></div>', q:200, s:0},
+ {style:'body { margin:0; padding:10px } #test { height:100% }', body:'<div id=test></div>', q:180, s:0},
+ {style:'body { margin:0; border:10px solid } #test { height:100% }', body:'<div id=test></div>', q:180, s:0},
+ {style:'html { margin:10px } #test { height:100% }', body:'<div id=test></div>', q:164, s:0},
+ {style:'html { padding:10px } #test { height:100% }', body:'<div id=test></div>', q:164, s:0},
+ {style:'html { border:10px solid } #test { height:100% }', body:'<div id=test></div>', q:164, s:0},
+ {style:'html { position:absolute } #test { height:100% }', body:'<div id=test></div>', q:0, s:0},
+ {style:'body { position:absolute } #test { height:100% }', body:'<div id=test></div>', q:0, s:0},
+ {style:'html { height:100%; margin:10px } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
+ {style:'html { height:100%; padding:10px } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
+ {style:'html { height:100%; border:10px solid } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
+ {style:'body { height:100%; margin:10px } #test { height:100% }', body:'<div id=test></div>', q:200, s:0},
+ {style:'body { height:100%; padding:10px } #test { height:100% }', body:'<div id=test></div>', q:200, s:0},
+ {style:'body { height:100%; border:10px solid } #test { height:100% }', body:'<div id=test></div>', q:200, s:0},
+ {style:'html { position:absolute; height:100%; margin:10px } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
+ {style:'html { position:absolute; height:100%; padding:10px } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
+ {style:'html { position:absolute; height:100%; border:10px solid } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
+ {style:'body { margin:99px 0 } #test { height:100% }', body:'<div id=test></div>', q:2, s:0},
+ {style:'body { margin:110px 0 } #test { height:100% }', body:'<div id=test></div>', q:0, s:0},
+ {style:'html, body { border:10px none } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
+ {style:'html, body { border:10px hidden } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
+ ];
+
+ tests.forEach(function(t) {
+ promise_test(async function() {
+ // Hide scrollbars in all subdocuments so that a horizontal
+ // scrollbar doesn't appear and upset our calculations.
+ var style = t.style.replace(/\{png\}/g, png) + " html { overflow:hidden; }";
+ var body = t.body.replace(/\{png\}/g, png);
+ q.style.textContent = style;
+ a.style.textContent = style;
+ s.style.textContent = style;
+ q.document.body.innerHTML = body;
+ a.document.body.innerHTML = body;
+ s.document.body.innerHTML = body;
+ await imagesLoaded();
+
+ assert_equals(q.getComputedStyle(q.test).height,
+ t.q + 'px',
+ 'quirks mode');
+ assert_equals(a.getComputedStyle(a.test).height,
+ t.s + 'px',
+ 'almost standards mode');
+ assert_equals(s.getComputedStyle(s.test).height,
+ t.s + 'px',
+ 'standards mode');
+ }, document.title+', '+t.style+t.body);
+ });
+
+ var xml_tests = [
+ {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style></head><body><div id="test"/></body></html>', q:184, s:0},
+ {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style></head><body/><div id="test"/></html>', q:200, s:0},
+ {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style></head><span><body><div id="test"/></body></span></html>', q:200, s:0},
+ {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style></head><body><body><div id="test"/></body></body></html>', q:200, s:0},
+ {input:'<html><head xmlns="{html}"><style>#test { height:100% }</style></head><body xmlns="{html}"><div id="test"/></body></html>', q:184, s:0},
+ {input:'<div xmlns="{html}"><head><style>#test { height:100% }</style></head><body><div id="test"/></body></div>', q:184, s:0},
+ {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style></head><body xmlns=""><div xmlns="{html}" id="test"/></body></html>', q:200, s:0},
+ {input:'<HTML xmlns="{html}"><head><style>#test { height:100% }</style></head><body><div id="test"/></body></HTML>', q:184, s:0},
+ {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style></head><BODY><div id="test"/></BODY></html>', q:200, s:0},
+ ];
+
+ var parser = new DOMParser();
+
+ xml_tests.forEach(function(t) {
+ promise_test(async function() {
+ var input = t.input.replace(/\{html\}/g, 'http://www.w3.org/1999/xhtml')
+ .replace(/\{png\}/g, png);
+ var root = parser.parseFromString(input, 'text/xml').documentElement;
+ q.document.replaceChild(root.cloneNode(true), q.document.documentElement);
+ a.document.replaceChild(root.cloneNode(true), a.document.documentElement);
+ s.document.replaceChild(root, s.document.documentElement);
+ await imagesLoaded();
+ assert_equals(q.getComputedStyle(q.test).height,
+ t.q + 'px',
+ 'quirks mode');
+ assert_equals(a.getComputedStyle(a.test).height,
+ t.s + 'px',
+ 'almost standards mode');
+ assert_equals(s.getComputedStyle(s.test).height,
+ t.s + 'px',
+ 'standards mode');
+ }, document.title+', '+t.input);
+ });
+
+ done();
+ }
+ </script>
+ </body>
+</html>