<!DOCTYPE html>
<html>
<style>
.container {
    position: relative;
    background-color: pink;
    outline: 1px solid red;
    display: inline-block;
}
.flexbox {
    display: flex;
    background-color: grey;
    width: 100px;
    height: 100px;
}
.title {
    margin-top: 1em;
}
.ltr {
    direction: ltr;
}
.rtl {
    direction: rtl;
}
.horizontal-tb {
    writing-mode: horizontal-tb;
}
.vertical-rl {
    writing-mode: vertical-rl;
}
.vertical-lr {
    writing-mode: vertical-lr;
}
.row {
    flex-flow: row;    
}
.row-reverse {
    flex-flow: row-reverse;
}
.column {
    flex-flow: column;
}
.column-reverse {
    flex-flow: column-reverse;
}
.flexbox > :nth-child(1) {
    background-color: blue;
}
</style>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../../resources/check-layout-th.js"></script>
<body onload="checkLayout('.flexbox')">
<div id=log></div>

<script>
function positionAsString(position)
{
    return 'data-offset-x="' + position[0] + '" data-offset-y="' + position[1] + '"';
}

function sizeAsString(size)
{
    return 'data-expected-width="' + size[0] + '" data-expected-height="' + size[1] + '"';
}

var containerSize = [100, 100];

var expectations = {
    'horizontal-tb': {
        rtl: [-5, 0],
        ltr: [0, 0],
        'rtl-column-reverse': [-5, -5],
        'ltr-column-reverse': [0, -5],
    },
    'vertical-lr': {
        rtl: [0, -5],
        ltr: [0, 0],
        'rtl-column-reverse': [-5, -5],
        'ltr-column-reverse': [-5, 0],
    },
    'vertical-rl': {
        rtl: [-5, -5],
        ltr: [-5, 0],
        'rtl-column-reverse': [0, -5],
        'ltr-column-reverse': [0, 0],
    }
}

var writingModes = ['horizontal-tb', 'vertical-lr', 'vertical-rl'];
var flexFlows = ['row', 'column', 'row-reverse', 'column-reverse'];
var directions = ['rtl', 'ltr'];

writingModes.forEach(function(writingMode) {
    flexFlows.forEach(function(flexFlow) {
        directions.forEach(function(direction) {
            var flexboxClassName = writingMode + ' ' + direction + ' ' + flexFlow;
            var title = document.createElement('div');
            title.className = 'title';
            title.innerHTML = flexboxClassName;
            document.body.appendChild(title);

            var container = document.createElement('div');
            container.className = 'container';
            container.setAttribute('data-expected-width', containerSize[0]);
            container.setAttribute('data-expected-height', containerSize[1]);

            var flowDirection = direction;
            // row-reverse is the same as flipping the writing direction.
            if (flexFlow == "row-reverse")
                flowDirection = direction == "rtl" ? "ltr" : "rtl";
            else if (flexFlow == "column-reverse")
                flowDirection = direction + "-column-reverse";

            container.innerHTML = '\n<div class="flexbox ' + flexboxClassName + '" ' + sizeAsString(containerSize) + '>\n' +
                '<div style="flex: 1 0 auto; width: 105px; height: 105px;" ' + sizeAsString([105, 105])  + ' ' + positionAsString(expectations[writingMode][flowDirection]) + '></div>\n' +
            '</div>\n';

            document.body.appendChild(container);   
        })
    })
})
</script>
</body>
</html>
