layout/style/test/flexbox_layout_testcases.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 sw=2 sts=2 et: */
michael@0 3
michael@0 4 /*
michael@0 5 * This Source Code is subject to the terms of the Mozilla Public License
michael@0 6 * version 2.0 (the "License"). You can obtain a copy of the License at
michael@0 7 * http://mozilla.org/MPL/2.0/.
michael@0 8 */
michael@0 9
michael@0 10 /**
michael@0 11 * For the purposes of this test, flex items are specified as a hash with a
michael@0 12 * hash-entry for each CSS property that is to be set. In these per-property
michael@0 13 * entries, the key is the property-name, and the value can be either of the
michael@0 14 * following:
michael@0 15 * (a) the property's specified value (which indicates that we don't need to
michael@0 16 * bother checking the computed value of this particular property)
michael@0 17 * ...OR...
michael@0 18 * (b) an array with 2-3 entries...
michael@0 19 * [specifiedValue, expectedComputedValue (, epsilon) ]
michael@0 20 * ...which indicates that the property's computed value should be
michael@0 21 * checked. The array's first entry (for the specified value) may be
michael@0 22 * null; this means that no value should be explicitly specified for this
michael@0 23 * property. The second entry is the property's expected computed
michael@0 24 * value. The third (optional) entry is an epsilon value, which allows for
michael@0 25 * fuzzy equality when testing the computed value.
michael@0 26 *
michael@0 27 * To allow these testcases to be re-used in both horizontal and vertical
michael@0 28 * flex containers, we specify "width"/"min-width"/etc. using the aliases
michael@0 29 * "_main-size", "_min-main-size", etc. The test code can map these
michael@0 30 * placeholder names to their corresponding property-names using the maps
michael@0 31 * defined below -- gRowPropertyMapping, gColumnPropertyMapping, etc.
michael@0 32 *
michael@0 33 * If the testcase needs to customize its flex container at all (e.g. by
michael@0 34 * specifying a custom container-size), it can do so by including a hash
michael@0 35 * called "container_properties", with propertyName:propertyValue mappings.
michael@0 36 * (This hash can use aliased property-names like "_main-size" as well.)
michael@0 37 */
michael@0 38
michael@0 39 // The standard main-size we'll use for our flex container when setting up
michael@0 40 // the testcases defined below:
michael@0 41 var gDefaultFlexContainerSize = "200px";
michael@0 42
michael@0 43 // Left-to-right versions of placeholder property-names used in
michael@0 44 // testcases below:
michael@0 45 var gRowPropertyMapping =
michael@0 46 {
michael@0 47 "_main-size": "width",
michael@0 48 "_min-main-size": "min-width",
michael@0 49 "_max-main-size": "max-width",
michael@0 50 "_border-main-start-width": "border-left-width",
michael@0 51 "_border-main-end-width": "border-right-width",
michael@0 52 "_padding-main-start": "padding-left",
michael@0 53 "_padding-main-end": "padding-right",
michael@0 54 "_margin-main-start": "margin-left",
michael@0 55 "_margin-main-end": "margin-right"
michael@0 56 };
michael@0 57
michael@0 58 // Right-to-left versions of placeholder property-names used in
michael@0 59 // testcases below:
michael@0 60 var gRowReversePropertyMapping =
michael@0 61 {
michael@0 62 "_main-size": "width",
michael@0 63 "_min-main-size": "min-width",
michael@0 64 "_max-main-size": "max-width",
michael@0 65 "_border-main-start-width": "border-right-width",
michael@0 66 "_border-main-end-width": "border-left-width",
michael@0 67 "_padding-main-start": "padding-right",
michael@0 68 "_padding-main-end": "padding-left",
michael@0 69 "_margin-main-start": "margin-right",
michael@0 70 "_margin-main-end": "margin-left"
michael@0 71 };
michael@0 72
michael@0 73 // Top-to-bottom versions of placeholder property-names used in
michael@0 74 // testcases below:
michael@0 75 var gColumnPropertyMapping =
michael@0 76 {
michael@0 77 "_main-size": "height",
michael@0 78 "_min-main-size": "min-height",
michael@0 79 "_max-main-size": "max-height",
michael@0 80 "_border-main-start-width": "border-top-width",
michael@0 81 "_border-main-end-width": "border-bottom-width",
michael@0 82 "_padding-main-start": "padding-top",
michael@0 83 "_padding-main-end": "padding-bottom",
michael@0 84 "_margin-main-start": "margin-top",
michael@0 85 "_margin-main-end": "margin-bottom"
michael@0 86 };
michael@0 87
michael@0 88 // Bottom-to-top versions of placeholder property-names used in
michael@0 89 // testcases below:
michael@0 90 var gColumnReversePropertyMapping =
michael@0 91 {
michael@0 92 "_main-size": "height",
michael@0 93 "_min-main-size": "min-height",
michael@0 94 "_max-main-size": "max-height",
michael@0 95 "_border-main-start-width": "border-bottom-width",
michael@0 96 "_border-main-end-width": "border-top-width",
michael@0 97 "_padding-main-start": "padding-bottom",
michael@0 98 "_padding-main-end": "padding-top",
michael@0 99 "_margin-main-start": "margin-bottom",
michael@0 100 "_margin-main-end": "margin-top"
michael@0 101 };
michael@0 102
michael@0 103 // The list of actual testcase definitions:
michael@0 104 var gFlexboxTestcases =
michael@0 105 [
michael@0 106 // No flex properties specified --> should just use 'width' for sizing
michael@0 107 {
michael@0 108 items:
michael@0 109 [
michael@0 110 { "_main-size": [ "40px", "40px" ] },
michael@0 111 { "_main-size": [ "65px", "65px" ] },
michael@0 112 ]
michael@0 113 },
michael@0 114 // flex-basis is specified:
michael@0 115 {
michael@0 116 items:
michael@0 117 [
michael@0 118 { "flex-basis": "50px",
michael@0 119 "_main-size": [ null, "50px" ]
michael@0 120 },
michael@0 121 {
michael@0 122 "flex-basis": "20px",
michael@0 123 "_main-size": [ null, "20px" ]
michael@0 124 },
michael@0 125 ]
michael@0 126 },
michael@0 127 // flex-basis is *large* -- sum of flex-basis values is > flex container size:
michael@0 128 // (w/ 0 flex-shrink so we don't shrink):
michael@0 129 {
michael@0 130 items:
michael@0 131 [
michael@0 132 {
michael@0 133 "flex": "0 0 150px",
michael@0 134 "_main-size": [ null, "150px" ]
michael@0 135 },
michael@0 136 {
michael@0 137 "flex": "0 0 90px",
michael@0 138 "_main-size": [ null, "90px" ]
michael@0 139 },
michael@0 140 ]
michael@0 141 },
michael@0 142 // flex-basis is *large* -- each flex-basis value is > flex container size:
michael@0 143 // (w/ 0 flex-shrink so we don't shrink):
michael@0 144 {
michael@0 145 items:
michael@0 146 [
michael@0 147 {
michael@0 148 "flex": "0 0 250px",
michael@0 149 "_main-size": [ null, "250px" ]
michael@0 150 },
michael@0 151 {
michael@0 152 "flex": "0 0 400px",
michael@0 153 "_main-size": [ null, "400px" ]
michael@0 154 },
michael@0 155 ]
michael@0 156 },
michael@0 157 // flex-basis has percentage value:
michael@0 158 {
michael@0 159 items:
michael@0 160 [
michael@0 161 {
michael@0 162 "flex-basis": "30%",
michael@0 163 "_main-size": [ null, "60px" ]
michael@0 164 },
michael@0 165 {
michael@0 166 "flex-basis": "45%",
michael@0 167 "_main-size": [ null, "90px" ]
michael@0 168 },
michael@0 169 ]
michael@0 170 },
michael@0 171 // flex-basis has calc(percentage) value:
michael@0 172 {
michael@0 173 items:
michael@0 174 [
michael@0 175 {
michael@0 176 "flex-basis": "calc(20%)",
michael@0 177 "_main-size": [ null, "40px" ]
michael@0 178 },
michael@0 179 {
michael@0 180 "flex-basis": "calc(80%)",
michael@0 181 "_main-size": [ null, "160px" ]
michael@0 182 },
michael@0 183 ]
michael@0 184 },
michael@0 185 // flex-basis has calc(percentage +/- length) value:
michael@0 186 {
michael@0 187 items:
michael@0 188 [
michael@0 189 {
michael@0 190 "flex-basis": "calc(10px + 20%)",
michael@0 191 "_main-size": [ null, "50px" ]
michael@0 192 },
michael@0 193 {
michael@0 194 "flex-basis": "calc(60% - 1px)",
michael@0 195 "_main-size": [ null, "119px" ]
michael@0 196 },
michael@0 197 ]
michael@0 198 },
michael@0 199 // flex-grow is specified:
michael@0 200 {
michael@0 201 items:
michael@0 202 [
michael@0 203 {
michael@0 204 "flex": "1",
michael@0 205 "_main-size": [ null, "60px" ]
michael@0 206 },
michael@0 207 {
michael@0 208 "flex": "2",
michael@0 209 "_main-size": [ null, "120px" ]
michael@0 210 },
michael@0 211 {
michael@0 212 "flex": "0 20px",
michael@0 213 "_main-size": [ null, "20px" ]
michael@0 214 }
michael@0 215 ]
michael@0 216 },
michael@0 217 // Same ratio as prev. testcase; making sure we handle float inaccuracy
michael@0 218 {
michael@0 219 items:
michael@0 220 [
michael@0 221 {
michael@0 222 "flex": "100000",
michael@0 223 "_main-size": [ null, "60px" ]
michael@0 224 },
michael@0 225 {
michael@0 226 "flex": "200000",
michael@0 227 "_main-size": [ null, "120px" ]
michael@0 228 },
michael@0 229 {
michael@0 230 "flex": "0.000001 20px",
michael@0 231 "_main-size": [ null, "20px" ]
michael@0 232 }
michael@0 233 ]
michael@0 234 },
michael@0 235 // Same ratio as prev. testcase, but with items cycled and w/
michael@0 236 // "flex: none" & explicit size instead of "flex: 0 20px"
michael@0 237 {
michael@0 238 items:
michael@0 239 [
michael@0 240 {
michael@0 241 "flex": "none",
michael@0 242 "_main-size": [ "20px", "20px" ]
michael@0 243 },
michael@0 244 {
michael@0 245 "flex": "1",
michael@0 246 "_main-size": [ null, "60px" ]
michael@0 247 },
michael@0 248 {
michael@0 249 "flex": "2",
michael@0 250 "_main-size": [ null, "120px" ]
michael@0 251 }
michael@0 252 ]
michael@0 253 },
michael@0 254
michael@0 255 // ...and now with flex-grow:[huge] to be sure we handle infinite float values
michael@0 256 // gracefully.
michael@0 257 {
michael@0 258 items:
michael@0 259 [
michael@0 260 {
michael@0 261 "flex": "9999999999999999999999999999999999999999999999999999999",
michael@0 262 "_main-size": [ null, "200px" ]
michael@0 263 },
michael@0 264 ]
michael@0 265 },
michael@0 266 {
michael@0 267 items:
michael@0 268 [
michael@0 269 {
michael@0 270 "flex": "9999999999999999999999999999999999999999999999999999999",
michael@0 271 "_main-size": [ null, "50px" ]
michael@0 272 },
michael@0 273 {
michael@0 274 "flex": "9999999999999999999999999999999999999999999999999999999",
michael@0 275 "_main-size": [ null, "50px" ]
michael@0 276 },
michael@0 277 {
michael@0 278 "flex": "9999999999999999999999999999999999999999999999999999999",
michael@0 279 "_main-size": [ null, "50px" ]
michael@0 280 },
michael@0 281 {
michael@0 282 "flex": "9999999999999999999999999999999999999999999999999999999",
michael@0 283 "_main-size": [ null, "50px" ]
michael@0 284 },
michael@0 285 ]
michael@0 286 },
michael@0 287 {
michael@0 288 items:
michael@0 289 [
michael@0 290 {
michael@0 291 "flex": "99999999999999999999999999999999999",
michael@0 292 "_main-size": [ null, "50px" ]
michael@0 293 },
michael@0 294 {
michael@0 295 "flex": "99999999999999999999999999999999999",
michael@0 296 "_main-size": [ null, "50px" ]
michael@0 297 },
michael@0 298 {
michael@0 299 "flex": "99999999999999999999999999999999999",
michael@0 300 "_main-size": [ null, "50px" ]
michael@0 301 },
michael@0 302 {
michael@0 303 "flex": "99999999999999999999999999999999999",
michael@0 304 "_main-size": [ null, "50px" ]
michael@0 305 },
michael@0 306 ]
michael@0 307 },
michael@0 308
michael@0 309 // And now, some testcases to check that we handle float accumulation error
michael@0 310 // gracefully.
michael@0 311
michael@0 312 // First, a testcase with just a custom-sized huge container, to be sure we'll
michael@0 313 // be able to handle content on that scale, in the subsequent more-complex
michael@0 314 // testcases:
michael@0 315 {
michael@0 316 container_properties:
michael@0 317 {
michael@0 318 "_main-size": "9000000px"
michael@0 319 },
michael@0 320 items:
michael@0 321 [
michael@0 322 {
michael@0 323 "flex": "1",
michael@0 324 "_main-size": [ null, "9000000px" ]
michael@0 325 },
michael@0 326 ]
michael@0 327 },
michael@0 328 // ...and now with two flex items dividing up that container's huge size:
michael@0 329 {
michael@0 330 container_properties:
michael@0 331 {
michael@0 332 "_main-size": "9000000px"
michael@0 333 },
michael@0 334 items:
michael@0 335 [
michael@0 336 {
michael@0 337 "flex": "2",
michael@0 338 "_main-size": [ null, "6000000px" ]
michael@0 339 },
michael@0 340 {
michael@0 341 "flex": "1",
michael@0 342 "_main-size": [ null, "3000000px" ]
michael@0 343 },
michael@0 344 ]
michael@0 345 },
michael@0 346
michael@0 347 // OK, now to actually test accumulation error. Below, we have six flex items
michael@0 348 // splitting up the container's size, with huge differences between flex
michael@0 349 // weights. For simplicity, I've set up the weights so that they sum exactly
michael@0 350 // to the container's size in px. So 1 unit of flex *should* get you 1px.
michael@0 351 //
michael@0 352 // NOTE: The expected computed "_main-size" values for the flex items below
michael@0 353 // appear to add up to more than their container's size, which would suggest
michael@0 354 // that they overflow their container unnecessarily. But they don't actually
michael@0 355 // overflow -- this discrepancy is simply because Gecko's code for reporting
michael@0 356 // computed-sizes rounds to 6 significant figures (in particular, the method
michael@0 357 // (nsTSubstring_CharT::AppendFloat() does this). Internally, in app-units,
michael@0 358 // the child frames' main-sizes add up exactly to the container's main-size,
michael@0 359 // as you'd hope & expect.
michael@0 360 {
michael@0 361 container_properties:
michael@0 362 {
michael@0 363 "_main-size": "9000000px"
michael@0 364 },
michael@0 365 items:
michael@0 366 [
michael@0 367 {
michael@0 368 "flex": "3000000",
michael@0 369 "_main-size": [ null, "3000000px" ]
michael@0 370 },
michael@0 371 {
michael@0 372 "flex": "1",
michael@0 373 "_main-size": [ null, "1px" ]
michael@0 374 },
michael@0 375 {
michael@0 376 "flex": "1",
michael@0 377 "_main-size": [ null, "1px" ]
michael@0 378 },
michael@0 379 {
michael@0 380 "flex": "2999999",
michael@0 381 // NOTE: Expected value is off slightly, from float error when
michael@0 382 // resolving flexible lengths & when generating computed value string:
michael@0 383 "_main-size": [ null, "3000000px" ]
michael@0 384 },
michael@0 385 {
michael@0 386 "flex": "2999998",
michael@0 387 // NOTE: Expected value is off slightly, from float error when
michael@0 388 // resolving flexible lengths & when generating computed value string:
michael@0 389 "_main-size": [ null, "3000000px" ]
michael@0 390 },
michael@0 391 {
michael@0 392 "flex": "1",
michael@0 393 "_main-size": [ null, "1px", 0.2 ]
michael@0 394 },
michael@0 395 ]
michael@0 396 },
michael@0 397 // Same flex items as previous testcase, but now reordered such that the items
michael@0 398 // with tiny flex weights are all listed last:
michael@0 399 {
michael@0 400 container_properties:
michael@0 401 {
michael@0 402 "_main-size": "9000000px"
michael@0 403 },
michael@0 404 items:
michael@0 405 [
michael@0 406 {
michael@0 407 "flex": "3000000",
michael@0 408 "_main-size": [ null, "3000000px" ]
michael@0 409 },
michael@0 410 {
michael@0 411 "flex": "2999999",
michael@0 412 // NOTE: Expected value is off slightly, from float error when
michael@0 413 // resolving flexible lengths & when generating computed value string:
michael@0 414 "_main-size": [ null, "3000000px" ]
michael@0 415 },
michael@0 416 {
michael@0 417 "flex": "2999998",
michael@0 418 // NOTE: Expected value is off slightly, from float error when
michael@0 419 // resolving flexible lengths & when generating computed value string:
michael@0 420 "_main-size": [ null, "3000000px" ]
michael@0 421 },
michael@0 422 {
michael@0 423 "flex": "1",
michael@0 424 "_main-size": [ null, "1px", 0.2 ]
michael@0 425 },
michael@0 426 {
michael@0 427 "flex": "1",
michael@0 428 "_main-size": [ null, "1px", 0.2 ]
michael@0 429 },
michael@0 430 {
michael@0 431 "flex": "1",
michael@0 432 "_main-size": [ null, "1px", 0.2 ]
michael@0 433 },
michael@0 434 ]
michael@0 435 },
michael@0 436 // Same flex items as previous testcase, but now reordered such that the items
michael@0 437 // with tiny flex weights are all listed first:
michael@0 438 {
michael@0 439 container_properties:
michael@0 440 {
michael@0 441 "_main-size": "9000000px"
michael@0 442 },
michael@0 443 items:
michael@0 444 [
michael@0 445 {
michael@0 446 "flex": "1",
michael@0 447 // NOTE: Expected value is off slightly, from float error when
michael@0 448 // resolving flexible lengths:
michael@0 449 "_main-size": [ null, "1px", 0.2 ]
michael@0 450 },
michael@0 451 {
michael@0 452 "flex": "1",
michael@0 453 // NOTE: Expected value is off slightly, from float error when
michael@0 454 // resolving flexible lengths:
michael@0 455 "_main-size": [ null, "1px", 0.2 ]
michael@0 456 },
michael@0 457 {
michael@0 458 "flex": "1",
michael@0 459 // NOTE: Expected value is off slightly, from float error when
michael@0 460 // resolving flexible lengths:
michael@0 461 "_main-size": [ null, "1px", 0.2 ]
michael@0 462 },
michael@0 463 {
michael@0 464 "flex": "3000000",
michael@0 465 "_main-size": [ null, "3000000px" ]
michael@0 466 },
michael@0 467 {
michael@0 468 "flex": "2999999",
michael@0 469 // NOTE: Expected value is off slightly, from float error when
michael@0 470 // resolving flexible lengths & when generating computed value string:
michael@0 471 "_main-size": [ null, "3000000px" ]
michael@0 472 },
michael@0 473 {
michael@0 474 "flex": "2999998",
michael@0 475 // NOTE: Expected value is off slightly, from float error when
michael@0 476 // resolving flexible lengths & when generating computed value string:
michael@0 477 "_main-size": [ null, "3000000px" ]
michael@0 478 },
michael@0 479 ]
michael@0 480 },
michael@0 481
michael@0 482 // Trying "flex: auto" (== "1 1 auto") w/ a mix of flex-grow/flex-basis values
michael@0 483 {
michael@0 484 items:
michael@0 485 [
michael@0 486 {
michael@0 487 "flex": "auto",
michael@0 488 "_main-size": [ null, "45px" ]
michael@0 489 },
michael@0 490 {
michael@0 491 "flex": "2",
michael@0 492 "_main-size": [ null, "90px" ]
michael@0 493 },
michael@0 494 {
michael@0 495 "flex": "20px 1 0",
michael@0 496 "_main-size": [ null, "65px" ]
michael@0 497 }
michael@0 498 ]
michael@0 499 },
michael@0 500 // Same as previous, but with items cycled & different syntax
michael@0 501 {
michael@0 502 items:
michael@0 503 [
michael@0 504 {
michael@0 505 "flex": "20px",
michael@0 506 "_main-size": [ null, "65px" ]
michael@0 507 },
michael@0 508 {
michael@0 509 "flex": "1",
michael@0 510 "_main-size": [ null, "45px" ]
michael@0 511 },
michael@0 512 {
michael@0 513 "flex": "2",
michael@0 514 "_main-size": [ null, "90px" ]
michael@0 515 }
michael@0 516 ]
michael@0 517 },
michael@0 518 {
michael@0 519 items:
michael@0 520 [
michael@0 521 {
michael@0 522 "flex": "2",
michael@0 523 "_main-size": [ null, "100px" ],
michael@0 524 "border": "0px dashed",
michael@0 525 "_border-main-start-width": [ "5px", "5px" ],
michael@0 526 "_border-main-end-width": [ "15px", "15px" ],
michael@0 527 "_margin-main-start": [ "22px", "22px" ],
michael@0 528 "_margin-main-end": [ "8px", "8px" ]
michael@0 529 },
michael@0 530 {
michael@0 531 "flex": "1",
michael@0 532 "_main-size": [ null, "50px" ],
michael@0 533 "_margin-main-start": [ "auto", "0px" ],
michael@0 534 "_padding-main-end": [ "auto", "0px" ],
michael@0 535 }
michael@0 536 ]
michael@0 537 },
michael@0 538 // Test negative flexibility:
michael@0 539
michael@0 540 // Basic testcase: just 1 item (relying on initial "flex-shrink: 1") --
michael@0 541 // should shrink to container size.
michael@0 542 {
michael@0 543 items:
michael@0 544 [
michael@0 545 { "_main-size": [ "400px", "200px" ] },
michael@0 546 ],
michael@0 547 },
michael@0 548 // ...and now with a "flex" specification and a different flex-shrink value:
michael@0 549 {
michael@0 550 items:
michael@0 551 [
michael@0 552 {
michael@0 553 "flex": "4 2 250px",
michael@0 554 "_main-size": [ null, "200px" ]
michael@0 555 },
michael@0 556 ],
michael@0 557 },
michael@0 558 // ...and now with multiple items, which all shrink proportionally (by 50%)
michael@0 559 // to fit to the container, since they have the same (initial) flex-shrink val
michael@0 560 {
michael@0 561 items:
michael@0 562 [
michael@0 563 { "_main-size": [ "80px", "40px" ] },
michael@0 564 { "_main-size": [ "40px", "20px" ] },
michael@0 565 { "_main-size": [ "30px", "15px" ] },
michael@0 566 { "_main-size": [ "250px", "125px" ] },
michael@0 567 ]
michael@0 568 },
michael@0 569 // ...and now with positive flexibility specified. (should have no effect, so
michael@0 570 // everything still shrinks by the same proportion, since the flex-shrink
michael@0 571 // values are all the same).
michael@0 572 {
michael@0 573 items:
michael@0 574 [
michael@0 575 {
michael@0 576 "flex": "4 3 100px",
michael@0 577 "_main-size": [ null, "80px" ]
michael@0 578 },
michael@0 579 {
michael@0 580 "flex": "5 3 50px",
michael@0 581 "_main-size": [ null, "40px" ]
michael@0 582 },
michael@0 583 {
michael@0 584 "flex": "0 3 100px",
michael@0 585 "_main-size": [ null, "80px" ]
michael@0 586 }
michael@0 587 ]
michael@0 588 },
michael@0 589 // ...and now with *different* flex-shrink values:
michael@0 590 {
michael@0 591 items:
michael@0 592 [
michael@0 593 {
michael@0 594 "flex": "4 2 50px",
michael@0 595 "_main-size": [ null, "30px" ]
michael@0 596 },
michael@0 597 {
michael@0 598 "flex": "5 3 50px",
michael@0 599 "_main-size": [ null, "20px" ]
michael@0 600 },
michael@0 601 {
michael@0 602 "flex": "0 0 150px",
michael@0 603 "_main-size": [ null, "150px" ]
michael@0 604 }
michael@0 605 ]
michael@0 606 },
michael@0 607 // Same ratio as prev. testcase; making sure we handle float inaccuracy
michael@0 608 {
michael@0 609 items:
michael@0 610 [
michael@0 611 {
michael@0 612 "flex": "4 20000000 50px",
michael@0 613 "_main-size": [ null, "30px" ]
michael@0 614 },
michael@0 615 {
michael@0 616 "flex": "5 30000000 50px",
michael@0 617 "_main-size": [ null, "20px" ]
michael@0 618 },
michael@0 619 {
michael@0 620 "flex": "0 0.0000001 150px",
michael@0 621 "_main-size": [ null, "150px" ]
michael@0 622 }
michael@0 623 ]
michael@0 624 },
michael@0 625 // Another "different flex-shrink values" testcase:
michael@0 626 {
michael@0 627 items:
michael@0 628 [
michael@0 629 {
michael@0 630 "flex": "4 2 115px",
michael@0 631 "_main-size": [ null, "69px" ]
michael@0 632 },
michael@0 633 {
michael@0 634 "flex": "5 1 150px",
michael@0 635 "_main-size": [ null, "120px" ]
michael@0 636 },
michael@0 637 {
michael@0 638 "flex": "1 4 30px",
michael@0 639 "_main-size": [ null, "6px" ]
michael@0 640 },
michael@0 641 {
michael@0 642 "flex": "1 0 5px",
michael@0 643 "_main-size": [ null, "5px" ]
michael@0 644 },
michael@0 645 ]
michael@0 646 },
michael@0 647
michael@0 648 // ...and now with min-size (clamping the effects of flex-shrink on one item):
michael@0 649 {
michael@0 650 items:
michael@0 651 [
michael@0 652 {
michael@0 653 "flex": "4 5 75px",
michael@0 654 "_min-main-size": "50px",
michael@0 655 "_main-size": [ null, "50px" ],
michael@0 656 },
michael@0 657 {
michael@0 658 "flex": "5 5 100px",
michael@0 659 "_main-size": [ null, "62.5px" ]
michael@0 660 },
michael@0 661 {
michael@0 662 "flex": "0 4 125px",
michael@0 663 "_main-size": [ null, "87.5px" ]
michael@0 664 }
michael@0 665 ]
michael@0 666 },
michael@0 667
michael@0 668 // Test a min-size that's much larger than initial preferred size, but small
michael@0 669 // enough that our flexed size pushes us over it:
michael@0 670 {
michael@0 671 items:
michael@0 672 [
michael@0 673 {
michael@0 674 "flex": "auto",
michael@0 675 "_min-main-size": "110px",
michael@0 676 "_main-size": [ "50px", "125px" ]
michael@0 677 },
michael@0 678 {
michael@0 679 "flex": "auto",
michael@0 680 "_main-size": [ null, "75px" ]
michael@0 681 }
michael@0 682 ]
michael@0 683 },
michael@0 684
michael@0 685 // Test a min-size that's much larger than initial preferred size, and is
michael@0 686 // even larger than our positively-flexed size, so that we have to increase it
michael@0 687 // (as a 'min violation') after we've flexed.
michael@0 688 {
michael@0 689 items:
michael@0 690 [
michael@0 691 {
michael@0 692 "flex": "auto",
michael@0 693 "_min-main-size": "150px",
michael@0 694 "_main-size": [ "50px", "150px" ]
michael@0 695 },
michael@0 696 {
michael@0 697 "flex": "auto",
michael@0 698 "_main-size": [ null, "50px" ]
michael@0 699 }
michael@0 700 ]
michael@0 701 },
michael@0 702
michael@0 703 // Test min-size on multiple items simultaneously:
michael@0 704 {
michael@0 705 items:
michael@0 706 [
michael@0 707 {
michael@0 708 "flex": "auto",
michael@0 709 "_min-main-size": "20px",
michael@0 710 "_main-size": [ null, "20px" ]
michael@0 711 },
michael@0 712 {
michael@0 713 "flex": "9 auto",
michael@0 714 "_min-main-size": "150px",
michael@0 715 "_main-size": [ "50px", "180px" ]
michael@0 716 },
michael@0 717 ]
michael@0 718 },
michael@0 719 {
michael@0 720 items:
michael@0 721 [
michael@0 722 {
michael@0 723 "flex": "1 1 0px",
michael@0 724 "_min-main-size": "90px",
michael@0 725 "_main-size": [ null, "90px" ]
michael@0 726 },
michael@0 727 {
michael@0 728 "flex": "1 1 0px",
michael@0 729 "_min-main-size": "80px",
michael@0 730 "_main-size": [ null, "80px" ]
michael@0 731 },
michael@0 732 {
michael@0 733 "flex": "1 1 40px",
michael@0 734 "_main-size": [ null, "30px" ]
michael@0 735 }
michael@0 736 ]
michael@0 737 },
michael@0 738
michael@0 739 // Test a case where _min-main-size will be violated on different items in
michael@0 740 // successive iterations of the "resolve the flexible lengths" loop
michael@0 741 {
michael@0 742 items:
michael@0 743 [
michael@0 744 {
michael@0 745 "flex": "1 2 100px",
michael@0 746 "_min-main-size": "90px",
michael@0 747 "_main-size": [ null, "90px" ]
michael@0 748 },
michael@0 749 {
michael@0 750 "flex": "1 1 100px",
michael@0 751 "_min-main-size": "70px",
michael@0 752 "_main-size": [ null, "70px" ]
michael@0 753 },
michael@0 754 {
michael@0 755 "flex": "1 1 100px",
michael@0 756 "_main-size": [ null, "40px" ]
michael@0 757 }
michael@0 758 ]
michael@0 759 },
michael@0 760
michael@0 761 // Test some cases that have a min-size violation on one item and a
michael@0 762 // max-size violation on another:
michael@0 763
michael@0 764 // Here, both items initially grow to 100px. That violates both
michael@0 765 // items' sizing constraints (it's smaller than the min-size and larger than
michael@0 766 // the max-size), so we clamp both of them and sum the clamping-differences:
michael@0 767 //
michael@0 768 // (130px - 100px) + (50px - 100px) = (30px) + (-50px) = -20px
michael@0 769 //
michael@0 770 // This sum is negative, so (per spec) we freeze the item that had its
michael@0 771 // max-size violated (the second one) and restart the algorithm. This time,
michael@0 772 // all the available space (200px - 50px = 150px) goes to the not-yet-frozen
michael@0 773 // first item, and that puts it above its min-size, so all is well.
michael@0 774 {
michael@0 775 items:
michael@0 776 [
michael@0 777 {
michael@0 778 "flex": "auto",
michael@0 779 "_min-main-size": "130px",
michael@0 780 "_main-size": [ null, "150px" ]
michael@0 781 },
michael@0 782 {
michael@0 783 "flex": "auto",
michael@0 784 "_max-main-size": "50px",
michael@0 785 "_main-size": [ null, "50px" ]
michael@0 786 },
michael@0 787 ]
michael@0 788 },
michael@0 789
michael@0 790 // As above, both items initially grow to 100px, and that violates both items'
michael@0 791 // constraints. However, now the sum of the clamping differences is:
michael@0 792 //
michael@0 793 // (130px - 100px) + (80px - 100px) = (30px) + (-20px) = 10px
michael@0 794 //
michael@0 795 // This sum is positive, so (per spec) we freeze the item that had its
michael@0 796 // min-size violated (the first one) and restart the algorithm. This time,
michael@0 797 // all the available space (200px - 130px = 70px) goes to the not-yet-frozen
michael@0 798 // second item, and that puts it below its max-size, so all is well.
michael@0 799 {
michael@0 800 items:
michael@0 801 [
michael@0 802 {
michael@0 803 "flex": "auto",
michael@0 804 "_min-main-size": "130px",
michael@0 805 "_main-size": [ null, "130px" ]
michael@0 806 },
michael@0 807 {
michael@0 808 "flex": "auto",
michael@0 809 "_max-main-size": "80px",
michael@0 810 "_main-size": [ null, "70px" ]
michael@0 811 },
michael@0 812 ]
michael@0 813 },
michael@0 814
michael@0 815 // As above, both items initially grow to 100px, and that violates both items'
michael@0 816 // constraints. So we clamp both items and sum the clamping differences to
michael@0 817 // see what to do next. The sum is:
michael@0 818 //
michael@0 819 // (80px - 100px) + (120px - 100px) = (-20px) + (20px) = 0px
michael@0 820 //
michael@0 821 // Per spec, if the sum is 0, we're done -- we leave both items at their
michael@0 822 // clamped sizes.
michael@0 823 {
michael@0 824 items:
michael@0 825 [
michael@0 826 {
michael@0 827 "flex": "auto",
michael@0 828 "_max-main-size": "80px",
michael@0 829 "_main-size": [ null, "80px" ]
michael@0 830 },
michael@0 831 {
michael@0 832 "flex": "auto",
michael@0 833 "_min-main-size": "120px",
michael@0 834 "_main-size": [ null, "120px" ]
michael@0 835 },
michael@0 836 ]
michael@0 837 },
michael@0 838 ];

mercurial