layout/style/test/test_flexbox_order.html

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

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

mercurial