layout/style/test/test_flexbox_order_table.html

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=799775
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <meta charset="utf-8">
michael@0 8 <title>Test for Bug 799775</title>
michael@0 9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <script type="application/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
michael@0 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 12 <style type="text/css">
michael@0 13
michael@0 14 div.ref {
michael@0 15 display: none;
michael@0 16 height: 30px;
michael@0 17 }
michael@0 18
michael@0 19 refA, refB, refC {
michael@0 20 display: block;
michael@0 21 float: left;
michael@0 22 }
michael@0 23
michael@0 24 div#a, div#b, div#c {
michael@0 25 display: table;
michael@0 26 }
michael@0 27
michael@0 28 div#a, refA {
michael@0 29 background: lightgreen;
michael@0 30 width: 20px;
michael@0 31 height: 30px;
michael@0 32 }
michael@0 33 div#b, refB {
michael@0 34 background: orange;
michael@0 35 width: 30px;
michael@0 36 height: 30px;
michael@0 37 }
michael@0 38 div#c, refC {
michael@0 39 background: blue;
michael@0 40 width: 50px;
michael@0 41 height: 30px;
michael@0 42 }
michael@0 43 div#flexContainer {
michael@0 44 display: flex;
michael@0 45 width: 100px;
michael@0 46 height: 30px;
michael@0 47 }
michael@0 48 div#flexContainerParent {
michael@0 49 display: none;
michael@0 50 }
michael@0 51 </style>
michael@0 52 </head>
michael@0 53 <body>
michael@0 54 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=799775">Mozilla Bug 799775</a>
michael@0 55 <div id="display">
michael@0 56
michael@0 57 <!-- Reference cases (display:none; only shown during initRefSnapshots) -->
michael@0 58 <div id="references">
michael@0 59 <div class="ref" id="abc"><refA></refA><refB></refB><refC></refC></div>
michael@0 60 <div class="ref" id="acb"><refA></refA><refC></refC><refB></refB></div>
michael@0 61 <div class="ref" id="bac"><refB></refB><refA></refA><refC></refC></div>
michael@0 62 <div class="ref" id="bca"><refB></refB><refC></refC><refA></refA></div>
michael@0 63 <div class="ref" id="cab"><refC></refC><refA></refA><refB></refB></div>
michael@0 64 <div class="ref" id="cba"><refC></refC><refB></refB><refA></refA></div>
michael@0 65 </div>
michael@0 66
michael@0 67 <div id="flexContainerParent">
michael@0 68 <!-- The flex container that we'll be testing
michael@0 69 (its parent is display:none initially) -->
michael@0 70 <div id="flexContainer">
michael@0 71 <div id="a"></div>
michael@0 72 <div id="b"></div>
michael@0 73 <div id="c"></div>
michael@0 74 </div>
michael@0 75 </div>
michael@0 76
michael@0 77 </div>
michael@0 78 <pre id="test">
michael@0 79 <script type="application/javascript;version=1.7">
michael@0 80 "use strict";
michael@0 81
michael@0 82 /** Test for Bug 799775 **/
michael@0 83
michael@0 84 /* This testcase ensures that we honor the "order" property when ordering
michael@0 85 * tables as flex items within a flex container.
michael@0 86 *
michael@0 87 * Note: The items in this testcase don't overlap, so this testcase does _not_
michael@0 88 * test paint ordering. It only tests horizontal ordering in a flex container.
michael@0 89 */
michael@0 90
michael@0 91 // DATA
michael@0 92 // ----
michael@0 93
michael@0 94 // This will store snapshots of our reference divs
michael@0 95 var gRefSnapshots = {};
michael@0 96
michael@0 97 // These are the sets of 'order' values that we'll test.
michael@0 98 // The first three values in each array are the 'order' values that we'll
michael@0 99 // assign to elements a, b, and c (respectively). The final value in each
michael@0 100 // array is the ID of the expected reference rendering.
michael@0 101 var gOrderTestcases = [
michael@0 102 // The 6 basic permutations:
michael@0 103 [ 1, 2, 3, "abc"],
michael@0 104 [ 1, 3, 2, "acb"],
michael@0 105 [ 2, 1, 3, "bac"],
michael@0 106 [ 2, 3, 1, "cab"],
michael@0 107 [ 3, 1, 2, "bca"],
michael@0 108 [ 3, 2, 1, "cba"],
michael@0 109
michael@0 110 // Test negative values
michael@0 111 [ 1, -5, -2, "bca"],
michael@0 112 [ -50, 0, -2, "acb"],
michael@0 113
michael@0 114 // Non-integers should be ignored.
michael@0 115 // (So, they'll leave their div with the initial 'order' value, which is 0.)
michael@0 116 [ 1, 1.5, 2, "bac"],
michael@0 117 [ 2.5, 3.4, 1, "abc"],
michael@0 118 [ 0.5, 1, 1.5, "acb"],
michael@0 119
michael@0 120 // Decimal values that happen to be equal to integers (e.g. "3.0") are still
michael@0 121 // <numbers>, and are _not_ <integers>.
michael@0 122 // Source: http://www.w3.org/TR/CSS21/syndata.html#value-def-integer
michael@0 123 // (So, they'll leave their div with the initial 'order' value, which is 0.)
michael@0 124 // (NOTE: We have to use quotes around "3.0" and "2.0" to be sure JS doesn't
michael@0 125 // coerce them into integers before we get a chance to set them in CSS.)
michael@0 126 [ "3.0", "2.0", "1.0", "abc"],
michael@0 127 [ 3, "2.0", 1, "bca"],
michael@0 128 ];
michael@0 129
michael@0 130 // FUNCTIONS
michael@0 131 // ---------
michael@0 132
michael@0 133 function initRefSnapshots() {
michael@0 134 var refIds = ["abc", "acb", "bac", "bca", "cab", "cba"];
michael@0 135 refIds.forEach(function(aRefId) {
michael@0 136 var elem = document.getElementById(aRefId);
michael@0 137 elem.style.display = "block";
michael@0 138 gRefSnapshots[aRefId] = snapshotWindow(window, false);
michael@0 139 elem.style.display = "";
michael@0 140 });
michael@0 141 }
michael@0 142
michael@0 143 function complainIfSnapshotsDiffer(aSnap1, aSnap2, aMsg) {
michael@0 144 var compareResult = compareSnapshots(aSnap1, aSnap2, true);
michael@0 145 ok(compareResult[0], "flex container rendering should match expected (" + aMsg +")");
michael@0 146 if (!compareResult[0]) {
michael@0 147 todo(false, "TESTCASE: " + compareResult[1]);
michael@0 148 todo(false, "REFERENCE: "+ compareResult[2]);
michael@0 149 }
michael@0 150 }
michael@0 151
michael@0 152 function runOrderTestcase(aOrderTestcase) {
michael@0 153 // Sanity-check
michael@0 154 ok(Array.isArray(aOrderTestcase), "expecting testcase to be an array");
michael@0 155 is(aOrderTestcase.length, 4, "expecting testcase to have 4 elements");
michael@0 156
michael@0 157 document.getElementById("a").style.order = aOrderTestcase[0];
michael@0 158 document.getElementById("b").style.order = aOrderTestcase[1];
michael@0 159 document.getElementById("c").style.order = aOrderTestcase[2];
michael@0 160
michael@0 161 var snapshot = snapshotWindow(window, false);
michael@0 162 complainIfSnapshotsDiffer(snapshot, gRefSnapshots[aOrderTestcase[3]],
michael@0 163 aOrderTestcase);
michael@0 164
michael@0 165 // Clean up
michael@0 166 document.getElementById("a").style.order = "";
michael@0 167 document.getElementById("b").style.order = "";
michael@0 168 document.getElementById("c").style.order = "";
michael@0 169 }
michael@0 170
michael@0 171 // Main Function
michael@0 172 function main() {
michael@0 173 initRefSnapshots();
michael@0 174
michael@0 175 // un-hide the flex container's parent
michael@0 176 var flexContainerParent = document.getElementById("flexContainerParent");
michael@0 177 flexContainerParent.style.display = "block";
michael@0 178
michael@0 179 // Initial sanity-check: should be in expected document order
michael@0 180 var initialSnapshot = snapshotWindow(window, false);
michael@0 181 complainIfSnapshotsDiffer(initialSnapshot, gRefSnapshots["abc"],
michael@0 182 "initial flex container rendering, no 'order' value yet");
michael@0 183
michael@0 184 // OK, now we run our tests
michael@0 185 gOrderTestcases.forEach(runOrderTestcase);
michael@0 186
michael@0 187 // Re-hide the flex container at the end
michael@0 188 flexContainerParent.style.display = "";
michael@0 189 }
michael@0 190
michael@0 191 main();
michael@0 192
michael@0 193 </script>
michael@0 194 </pre>
michael@0 195 </body>
michael@0 196 </html>

mercurial