4 Test InspectorUtils.GetOverflowingChildrenOfElement in various cases
8 <title>Test InspectorUtils.GetOverflowingChildrenOfElement
</title>
9 <script src=
"chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
11 /*
"e" is our custom tag name for
"element" */
13 background: lightgray;
14 display: inline-block;
23 /*
"c" is our custom tag name for
"child" */
42 SimpleTest
.waitForExplicitFinish();
43 const InspectorUtils
= SpecialPowers
.InspectorUtils
;
46 {id
: "no_children", expected
: 0},
47 {id
: "one_child_no_overflow", expected
: 0},
48 {id
: "margin_left_overflow", expected
: 1},
49 {id
: "transform_overflow", expected
: 1},
50 {id
: "nested_overflow", expected
: 1},
51 {id
: "intermediate_overflow", expected
: 1},
52 {id
: "multiple_overflow_at_different_depths", expected
: 2},
56 // Assign each child element to an inner id so each of them can be identified for testing.
57 Array
.from(document
.getElementsByTagName('c')).forEach((e
, i
) => {e
.id
= `inner${i}`});
59 for (const {id
, expected
} of CASES
) {
60 info(`Checking element id ${id}.`);
62 const element
= document
.getElementById(id
);
64 ok(false, `Expected to find element with id ${id}.`);
67 const overflowing_children
= InspectorUtils
.getOverflowingChildrenOfElement(element
);
69 is(overflowing_children
.length
, expected
, `${id} has the expected number of children.`);
71 // Check that each child has the "target" class. Otherwise, we're getting the
72 // wrong children. We don't check each child with a test function, because we
73 // don't want to needlessly inflate the number of test functions in the log.
74 // But if we find a child that *doesn't* have the class "target", we report
75 // that as a test failure.
76 for (const child
of overflowing_children
) {
77 // child is a Node, but not necessarily an Element. We want to get the containing
78 // Element so that we can use its classList, tagName, and id properties.
80 if (child
.nodeType
!== Node
.ELEMENT_NODE
) {
81 e
= child
.parentElement
;
83 if (!e
.classList
.contains("target")) {
84 ok(false, `${id} is reporting this unexpected child as a target: ${e.tagName} id=${e.id}`);
91 window
.onload
= runTests
;
94 <body onload=
"runTests()">
96 <e id=
"no_children"></e>
98 <e id=
"one_child_no_overflow">
102 <e id=
"margin_left_overflow">
103 <c class=
"target" style=
"margin-left:100px">abcd
</c>
106 <e id=
"transform_overflow">
107 <c class=
"target" style=
"transform: translate(50px)">abcd
</c>
110 <e id=
"nested_overflow">
112 <c class=
"target" style=
"margin-left:100px">abcd
</c>
116 <e id=
"intermediate_overflow">
117 <c class=
"fixedSize target" style=
"margin-left:100px">
122 <e id=
"multiple_overflow_at_different_depths">
123 <c class=
"fixedSize target" style=
"margin-left:100px">
126 <c style=
"margin-left:100px">
127 <c class=
"target">abcd
</c>