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
|
<!doctype html>
<html id="root" class="g">
<head>
<meta charset="utf-8">
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<style>
.no-match {
display: block;
}
.g {
display: grid;
}
.s {
display: subgrid;
}
.gi {
display: inline-grid;
}
.pseudo-grid::after {
content: "after";
display: grid;
}
#a_display_contents_element {
display: contents;
}
</style>
<script>
"use strict";
SimpleTest.waitForExplicitFinish();
function testTargetsAreInElements(targets, elements) {
let c = 0;
for (let target of targets) {
if (c >= elements.length) {
ok(false, "We shouldn't have more targets than elements found.");
break;
}
let element = elements[c];
let isMatching = target.assert ? target.assert(element) : (target.id == element.id);
let test_function = (target.todo ? todo : ok);
test_function(isMatching, "Should find " + target.message + ".");
// Only move to the next element in the elements if this one was a match.
// This handles the case of an unexpected element showing up, and prevents
// cascading errors in that case. If we've instead screwed up the target
// list, then we will get cascading errors.
if (isMatching) {
++c;
}
}
// Make sure we don't have any extra elements after going through all the targets.
is(c, elements.length, "We shouldn't have more elements than we have targets.");
}
function runTests() {
// Part 1: Look for all the grid elements starting from the document root.
let elementsFromRoot = document.documentElement.getElementsWithGrid();
// Check that the expected elements were returned.
// Targets are provided in order we expect them to appear.
// Has to end in a non-todo element in order for testing logic to work.
let targetsFromRoot = [
{id: "root", message: "root with display:grid"},
{id: "a", message: "'plain' grid container with display:grid"},
{id: "b", message: "display:subgrid inside display:grid (to be fixed in Bug 1240834)", todo: true},
{id: "c", message: "'plain' grid container with display:inline-grid"},
{id: "d", message: "display:subgrid inside display:inline-grid (to be fixed in Bug 1240834)", todo: true},
{id: "e", message: "grid container with visibility:hidden"},
{id: "f", message: "grid container inside an element"},
{id: "g", message: "overflow:scroll grid container"},
{id: "h", message: "button as a grid container"},
{id: "i", message: "fieldset as a grid container"},
{id: "k1", message: "grid container containing a grid container"},
{id: "k2", message: "grid container inside a grid container"},
{id: "l", message: "grid container inside a display: contents element"},
{id: "m-in-shadow", message: "grid container inside shadow DOM"},
{
assert: element => element.tagName === "_moz_generated_content_after" && element.parentElement.id === "n",
message: "grid container inside pseudo element"
},
];
is(elementsFromRoot.length, 13, "Found expected number of elements within document root.");
testTargetsAreInElements(targetsFromRoot, elementsFromRoot);
// Part 2: Look for all the grid elements starting from a non-root element.
let elementsFromNonRoot = document.getElementById("a_non_root_element").getElementsWithGrid();
let targetsFromNonRoot = [
{id: "f", message: "grid container inside an element (from non-root element)"},
];
is(elementsFromNonRoot.length, 1, "Found expected number of elements from non-root element.");
testTargetsAreInElements(targetsFromNonRoot, elementsFromNonRoot);
// Part 3: Look for all the grid elements starting from a non-root, display contents element.
const elementsFromNonRootDisplayContent = document.getElementById("a_display_contents_element").getElementsWithGrid();
const targetsFromDisplayContentsRoot = [
{id: "l", message: "grid container inside a display: contents element"},
];
is(elementsFromNonRootDisplayContent.length, 1, "Found expected number of elements from non-root element.");
testTargetsAreInElements(targetsFromDisplayContentsRoot, elementsFromNonRootDisplayContent);
SimpleTest.finish();
}
</script>
<script>
// Define custom element
class Custom extends HTMLElement {
constructor() {
super();
const shadow = this.attachShadow({ mode: "open" });
const wrapper = document.createElement("div");
wrapper.setAttribute("id", "m-in-shadow");
wrapper.classList.add("in-shadow");
const style = document.createElement("style");
style.textContent = `.in-shadow { display: grid; }`;
shadow.append(style, wrapper);
}
}
// Define the new element
customElements.define("custom-el", Custom);
</script>
</head>
<body onLoad="runTests();">
<div id="a" class="g">
<div class="no-match"></div>
<div id="b" class="s"></div>
</div>
<div class="no-match"></div>
<div id="c" class="gi">
<div id="d" class="s"></div>
</div>
<div id="e" class="g" style="visibility:hidden"></div>
<div id="a_non_root_element"><div id="f" class="g"></div></div>
<div class="no-match"></div>
<div id="g" style="overflow:scroll" class="g"></div>
<button id="h" class="g"></button>
<fieldset id="i" class="g"></fieldset>
<div id="a_display_none_element" style="display:none"><div id="j" class="g"></div></div>
<div id="k1" class="g"><div id="k2" class="g"></div></div>
<div id="a_display_contents_element">
<div id="l" class="g"></div>
</div>
<custom-el id="m"></custom-el>
<div id="n" class="pseudo-grid"></div>
</body>
</html>
|