Upstream flexbox+scrollbars+direction+writing-mode tests

R=cbiesinger@chromium.org

Change-Id: Ifc7de13e67368d273dde22ef62bf940bb6193884
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1618150
Reviewed-by: Christian Biesinger <cbiesinger@chromium.org>
Commit-Queue: Stefan Zager <szager@chromium.org>
Cr-Commit-Position: refs/heads/master@{#661514}
diff --git a/css/css-flexbox/scrollbars-auto-ref.html b/css/css-flexbox/scrollbars-auto-ref.html
new file mode 100644
index 0000000..e83ba52
--- /dev/null
+++ b/css/css-flexbox/scrollbars-auto-ref.html
@@ -0,0 +1,182 @@
+<!DOCTYPE html>
+<head>
+
+<script src="support/scrollbars.js"></script>
+
+<style>
+.horizontal-header {
+  width: 120px;
+}
+.vertical-header {
+  width: 60px;
+}
+.container-row {
+  display: flex;
+  flex-direction: row;
+  align-items: flex-start;
+  justify-content: flex-start;
+}
+.container {
+  flex: none;
+  margin: 5px;
+}
+.ltr {
+  direction: ltr;
+}
+.rtl {
+  direction: rtl;
+}
+.horizontal {
+  writing-mode: horizontal-tb;
+}
+.flipped-blocks {
+  writing-mode: vertical-rl;
+}
+.flipped-lines {
+  writing-mode: vertical-lr;
+}
+.flex {
+  border: 2px solid red;
+  overflow: auto;
+  max-width: 100px;
+  max-height: 100px;
+  white-space: nowrap;
+  font-size: 0;
+}
+.row > div, .row-reverse > div {
+  display: inline-flex;
+  margin: 3px;
+}
+.column > div, .column-reverse > div {
+  display: flex;
+}
+
+/* Adjust margins to account for collapsing. */
+.ltr.horizontal > .row > .leaf3 {
+  margin-right: 0;
+}
+.ltr.flipped-blocks > .row > .leaf3, .ltr.flipped-lines > .row > .leaf3 {
+  margin-bottom: 0;
+}
+.rtl.horizontal > .row > .leaf3 {
+  margin-left: 0;
+}
+.rtl.flipped-blocks > .row > .leaf3, .rtl.flipped-lines > .row > .leaf3 {
+  margin-top: 0;
+}
+
+.ltr.horizontal > .row-reverse > .leaf3 {
+  margin-left: 0;
+}
+.ltr.flipped-blocks > .row-reverse > .leaf3, .ltr.flipped-lines > .row-reverse > .leaf3 {
+  margin-top: 0;
+}
+.rtl.horizontal > .row-reverse > .leaf3 {
+  margin-right: 0;
+}
+.rtl.flipped-blocks > .row-reverse > .leaf3, .rtl.flipped-lines > .row-reverse > .leaf3 {
+  margin-bottom: 0;
+}
+
+.horizontal > .column > .leaf1, .horizontal > .column > .leaf2 {
+  margin: 3px 3px 6px 3px;
+}
+.horizontal > .column > .leaf3 {
+  margin: 3px;
+}
+.flipped-blocks > .column > .leaf1, .flipped-blocks > .column > .leaf2 {
+  margin: 3px 3px 3px 6px;
+}
+.flipped-blocks > .column > .leaf3 {
+  margin: 3px;
+}
+.flipped-lines > .column > .leaf1, .flipped-lines > .column > .leaf2 {
+  margin: 3px 6px 3px 3px;
+}
+.flipped-lines > .column > .leaf3 {
+  margin: 3px;
+}
+
+.horizontal > .column-reverse > .leaf1, .horizontal > .column-reverse > .leaf2 {
+  margin: 6px 3px 3px 3px;
+}
+.horizontal > .column-reverse > .leaf3 {
+  margin: 0 3px 3px 3px;
+}
+.flipped-blocks > .column-reverse > .leaf1, .flipped-blocks > .column-reverse > .leaf2 {
+  margin: 3px 6px 3px 3px;
+}
+.flipped-blocks > .column-reverse > .leaf3 {
+  margin: 3px 0 3px 3px;
+}
+.flipped-lines > .column-reverse > .leaf1, .flipped-lines > .column-reverse > .leaf2 {
+  margin: 3px 3px 3px 6px;
+}
+.flipped-lines > .column-reverse > .leaf3 {
+  margin: 3px 3px 3px 0;
+}
+
+.flex > div {
+  width: 30px;
+  height: 30px;
+  border: 2px solid blue;
+  flex-direction: column;
+  justify-content: center;
+}
+.flex > div > div {
+  font-size: 20px;
+  text-align: center;
+  flex: none;
+}
+</style>
+
+</head>
+
+<div class="container-row">
+  <div class="vertical-header ltr horizontal"></div>
+  <div class="horizontal-header ltr horizontal">ltr<br>horizontal-tb</div>
+  <div class="vertical-header ltr flipped-blocks">ltr<br>vertical-rl</div>
+  <div class="vertical-header ltr flipped-blocks">ltr<br>vertical-lr</div>
+  <div class="horizontal-header rtl horizontal">rtl<br>horizontal-tb</div>
+  <div class="vertical-header rtl flipped-blocks">rtl<br>vertical-rl</div>
+  <div class="vertical-header rtl flipped-blocks">rtl<br>vertical-lr</div>
+</div>
+
+<script>
+// Override createContentNode to emulate reverse flow direction.
+createContentNode = (flexDirection, textDirection, writingMode) => {
+  var flexNode = document.createElement("div");
+  flexNode.className = "flex " + flexDirection;
+  flexNode.title = "flex-direction: " + flexDirection + "; direction: " + textDirection + "; writing-mode: " + writingMode;
+  for (var i = 1; i < 4; i++)
+    flexNode.appendChild(createLeafNode(flexDirection.endsWith("reverse") ? 4 - i : i));
+  return flexNode;
+}
+
+flexDirections.forEach((flexDirection) => {
+  var containerRow = createContainerRow(flexDirection);
+  document.body.appendChild(containerRow);
+});
+
+// Scroll all flex containers to the emulated beginning of flow.
+var nodes = document.querySelectorAll(".ltr > .row-reverse");
+for (var i = 0; i < nodes.length; i++) {
+  nodes[i].scrollLeft = 10000;
+  nodes[i].scrollTop = 10000;
+}
+nodes = document.querySelectorAll(".rtl > .row-reverse");
+for (var i = 0; i < nodes.length; i++) {
+  nodes[i].scrollLeft = 0;
+  nodes[i].scrollTop = 0;
+}
+nodes = document.querySelectorAll(".column-reverse");
+for (var i = 0; i < nodes.length; i++) {
+  nodes[i].scrollLeft = 10000;
+  nodes[i].scrollTop = 10000;
+}
+nodes = document.querySelectorAll(".flipped-blocks > .column-reverse");
+for (var i = 0; i < nodes.length; i++) {
+  nodes[i].scrollLeft = 0;
+  nodes[i].scrollTop = 0;
+}
+</script>
diff --git a/css/css-flexbox/scrollbars-auto.html b/css/css-flexbox/scrollbars-auto.html
new file mode 100644
index 0000000..ed1ffb8
--- /dev/null
+++ b/css/css-flexbox/scrollbars-auto.html
@@ -0,0 +1,95 @@
+<!DOCTYPE html>
+<head>
+<title>Auto scrollbars inside flexbox with direction and writing-mode</title>
+<link rel="author" title="Google, Inc." href="http://www.google.com/">
+<link rel="match" href="scrollbars-auto-ref.html">
+<link rel="help" href="https://drafts.csswg.org/css-flexbox/">
+
+<script src="support/scrollbars.js"></script>
+
+<style>
+.horizontal-header {
+  width: 120px;
+}
+.vertical-header {
+  width: 60px;
+}
+.container-row {
+  display: flex;
+  flex-direction: row;
+  align-items: flex-start;
+  justify-content: flex-start;
+}
+.container {
+  flex: none;
+  margin: 5px;
+}
+.ltr {
+  direction: ltr;
+}
+.rtl {
+  direction: rtl;
+}
+.horizontal {
+  writing-mode: horizontal-tb;
+}
+.flipped-blocks {
+  writing-mode: vertical-rl;
+}
+.flipped-lines {
+  writing-mode: vertical-lr;
+}
+.flex {
+  border: 2px solid red;
+  display: flex;
+  overflow: auto;
+  max-width: 100px;
+  max-height: 100px;
+}
+.column {
+  flex-direction: column;
+}
+.column-reverse {
+  flex-direction: column-reverse;
+}
+.row {
+  flex-direction: row;
+}
+.row-reverse {
+  flex-direction: row-reverse;
+}
+.flex > .leaf1, .flex > .leaf2, .flex > .leaf3 {
+  flex: none;
+  width: 30px;
+  height: 30px;
+  border: 2px solid blue;
+  margin: 3px;
+  display: flex;
+  flex-direction: column;
+  justify-content: center;
+}
+.flex > div > div {
+  font-size: 20px;
+  text-align: center;
+  flex: none;
+}
+</style>
+
+</head>
+
+<div class="container-row">
+  <div class="vertical-header ltr horizontal"></div>
+  <div class="horizontal-header ltr horizontal">ltr<br>horizontal-tb</div>
+  <div class="vertical-header ltr flipped-blocks">ltr<br>vertical-rl</div>
+  <div class="vertical-header ltr flipped-blocks">ltr<br>vertical-lr</div>
+  <div class="horizontal-header rtl horizontal">rtl<br>horizontal-tb</div>
+  <div class="vertical-header rtl flipped-blocks">rtl<br>vertical-rl</div>
+  <div class="vertical-header rtl flipped-blocks">rtl<br>vertical-lr</div>
+</div>
+
+<script>
+flexDirections.forEach((flexDirection) => {
+  var containerRow = createContainerRow(flexDirection);
+  document.body.appendChild(containerRow);
+});
+</script>
diff --git a/css/css-flexbox/scrollbars-ref.html b/css/css-flexbox/scrollbars-ref.html
new file mode 100644
index 0000000..32bb610
--- /dev/null
+++ b/css/css-flexbox/scrollbars-ref.html
@@ -0,0 +1,182 @@
+<!DOCTYPE html>
+<head>
+
+<script src="support/scrollbars.js"></script>
+
+<style>
+.horizontal-header {
+  width: 120px;
+}
+.vertical-header {
+  width: 60px;
+}
+.container-row {
+  display: flex;
+  flex-direction: row;
+  align-items: flex-start;
+  justify-content: flex-start;
+}
+.container {
+  flex: none;
+  margin: 5px;
+}
+.ltr {
+  direction: ltr;
+}
+.rtl {
+  direction: rtl;
+}
+.horizontal {
+  writing-mode: horizontal-tb;
+}
+.flipped-blocks {
+  writing-mode: vertical-rl;
+}
+.flipped-lines {
+  writing-mode: vertical-lr;
+}
+.flex {
+  border: 2px solid red;
+  overflow: scroll;
+  max-width: 100px;
+  max-height: 100px;
+  white-space: nowrap;
+  font-size: 0;
+}
+.row > div, .row-reverse > div {
+  display: inline-flex;
+  margin: 3px;
+}
+.column > div, .column-reverse > div {
+  display: flex;
+}
+
+/* Adjust margins to account for collapsing. */
+.ltr.horizontal > .row > .leaf3 {
+  margin-right: 0;
+}
+.ltr.flipped-blocks > .row > .leaf3, .ltr.flipped-lines > .row > .leaf3 {
+  margin-bottom: 0;
+}
+.rtl.horizontal > .row > .leaf3 {
+  margin-left: 0;
+}
+.rtl.flipped-blocks > .row > .leaf3, .rtl.flipped-lines > .row > .leaf3 {
+  margin-top: 0;
+}
+
+.ltr.horizontal > .row-reverse > .leaf3 {
+  margin-left: 0;
+}
+.ltr.flipped-blocks > .row-reverse > .leaf3, .ltr.flipped-lines > .row-reverse > .leaf3 {
+  margin-top: 0;
+}
+.rtl.horizontal > .row-reverse > .leaf3 {
+  margin-right: 0;
+}
+.rtl.flipped-blocks > .row-reverse > .leaf3, .rtl.flipped-lines > .row-reverse > .leaf3 {
+  margin-bottom: 0;
+}
+
+.horizontal > .column > .leaf1, .horizontal > .column > .leaf2 {
+  margin: 3px 3px 6px 3px;
+}
+.horizontal > .column > .leaf3 {
+  margin: 3px;
+}
+.flipped-blocks > .column > .leaf1, .flipped-blocks > .column > .leaf2 {
+  margin: 3px 3px 3px 6px;
+}
+.flipped-blocks > .column > .leaf3 {
+  margin: 3px;
+}
+.flipped-lines > .column > .leaf1, .flipped-lines > .column > .leaf2 {
+  margin: 3px 6px 3px 3px;
+}
+.flipped-lines > .column > .leaf3 {
+  margin: 3px;
+}
+
+.horizontal > .column-reverse > .leaf1, .horizontal > .column-reverse > .leaf2 {
+  margin: 6px 3px 3px 3px;
+}
+.horizontal > .column-reverse > .leaf3 {
+  margin: 0 3px 3px 3px;
+}
+.flipped-blocks > .column-reverse > .leaf1, .flipped-blocks > .column-reverse > .leaf2 {
+  margin: 3px 6px 3px 3px;
+}
+.flipped-blocks > .column-reverse > .leaf3 {
+  margin: 3px 0 3px 3px;
+}
+.flipped-lines > .column-reverse > .leaf1, .flipped-lines > .column-reverse > .leaf2 {
+  margin: 3px 3px 3px 6px;
+}
+.flipped-lines > .column-reverse > .leaf3 {
+  margin: 3px 3px 3px 0;
+}
+
+.flex > div {
+  width: 30px;
+  height: 30px;
+  border: 2px solid blue;
+  flex-direction: column;
+  justify-content: center;
+}
+.flex > div > div {
+  font-size: 20px;
+  text-align: center;
+  flex: none;
+}
+</style>
+
+</head>
+
+<div class="container-row">
+  <div class="vertical-header ltr horizontal"></div>
+  <div class="horizontal-header ltr horizontal">ltr<br>horizontal-tb</div>
+  <div class="vertical-header ltr flipped-blocks">ltr<br>vertical-rl</div>
+  <div class="vertical-header ltr flipped-blocks">ltr<br>vertical-lr</div>
+  <div class="horizontal-header rtl horizontal">rtl<br>horizontal-tb</div>
+  <div class="vertical-header rtl flipped-blocks">rtl<br>vertical-rl</div>
+  <div class="vertical-header rtl flipped-blocks">rtl<br>vertical-lr</div>
+</div>
+
+<script>
+// Override createContentNode to emulate reverse flow direction.
+createContentNode = (flexDirection, textDirection, writingMode) => {
+  var flexNode = document.createElement("div");
+  flexNode.className = "flex " + flexDirection;
+  flexNode.title = "flex-direction: " + flexDirection + "; direction: " + textDirection + "; writing-mode: " + writingMode;
+  for (var i = 1; i < 4; i++)
+    flexNode.appendChild(createLeafNode(flexDirection.endsWith("reverse") ? 4 - i : i));
+  return flexNode;
+}
+
+flexDirections.forEach((flexDirection) => {
+  var containerRow = createContainerRow(flexDirection);
+  document.body.appendChild(containerRow);
+});
+
+// Scroll all flex containers to the emulated beginning of flow.
+var nodes = document.querySelectorAll(".ltr > .row-reverse");
+for (var i = 0; i < nodes.length; i++) {
+  nodes[i].scrollLeft = 10000;
+  nodes[i].scrollTop = 10000;
+}
+nodes = document.querySelectorAll(".rtl > .row-reverse");
+for (var i = 0; i < nodes.length; i++) {
+  nodes[i].scrollLeft = 0;
+  nodes[i].scrollTop = 0;
+}
+nodes = document.querySelectorAll(".column-reverse");
+for (var i = 0; i < nodes.length; i++) {
+  nodes[i].scrollLeft = 10000;
+  nodes[i].scrollTop = 10000;
+}
+nodes = document.querySelectorAll(".flipped-blocks > .column-reverse");
+for (var i = 0; i < nodes.length; i++) {
+  nodes[i].scrollLeft = 0;
+  nodes[i].scrollTop = 0;
+}
+</script>
diff --git a/css/css-flexbox/scrollbars.html b/css/css-flexbox/scrollbars.html
new file mode 100644
index 0000000..0eca05b
--- /dev/null
+++ b/css/css-flexbox/scrollbars.html
@@ -0,0 +1,95 @@
+<!DOCTYPE html>
+<head>
+<title>Scrollbars inside flexbox with direction and writing-mode</title>
+<link rel="author" title="Google, Inc." href="http://www.google.com/">
+<link rel="match" href="scrollbars-ref.html">
+<link rel="help" href="https://drafts.csswg.org/css-flexbox/">
+
+<script src="support/scrollbars.js"></script>
+
+<style>
+.horizontal-header {
+  width: 120px;
+}
+.vertical-header {
+  width: 60px;
+}
+.container-row {
+  display: flex;
+  flex-direction: row;
+  align-items: flex-start;
+  justify-content: flex-start;
+}
+.container {
+  flex: none;
+  margin: 5px;
+}
+.ltr {
+  direction: ltr;
+}
+.rtl {
+  direction: rtl;
+}
+.horizontal {
+  writing-mode: horizontal-tb;
+}
+.flipped-blocks {
+  writing-mode: vertical-rl;
+}
+.flipped-lines {
+  writing-mode: vertical-lr;
+}
+.flex {
+  border: 2px solid red;
+  display: flex;
+  overflow: scroll;
+  max-width: 100px;
+  max-height: 100px;
+}
+.column {
+  flex-direction: column;
+}
+.column-reverse {
+  flex-direction: column-reverse;
+}
+.row {
+  flex-direction: row;
+}
+.row-reverse {
+  flex-direction: row-reverse;
+}
+.flex > .leaf1, .flex > .leaf2, .flex > .leaf3 {
+  flex: none;
+  width: 30px;
+  height: 30px;
+  border: 2px solid blue;
+  margin: 3px;
+  display: flex;
+  flex-direction: column;
+  justify-content: center;
+}
+.flex > div > div {
+  font-size: 20px;
+  text-align: center;
+  flex: none;
+}
+</style>
+
+</head>
+
+<div class="container-row">
+  <div class="vertical-header ltr horizontal"></div>
+  <div class="horizontal-header ltr horizontal">ltr<br>horizontal-tb</div>
+  <div class="vertical-header ltr flipped-blocks">ltr<br>vertical-rl</div>
+  <div class="vertical-header ltr flipped-blocks">ltr<br>vertical-lr</div>
+  <div class="horizontal-header rtl horizontal">rtl<br>horizontal-tb</div>
+  <div class="vertical-header rtl flipped-blocks">rtl<br>vertical-rl</div>
+  <div class="vertical-header rtl flipped-blocks">rtl<br>vertical-lr</div>
+</div>
+
+<script>
+flexDirections.forEach((flexDirection) => {
+  var containerRow = createContainerRow(flexDirection);
+  document.body.appendChild(containerRow);
+});
+</script>
diff --git a/css/css-flexbox/support/scrollbars.js b/css/css-flexbox/support/scrollbars.js
new file mode 100644
index 0000000..5b61b49
--- /dev/null
+++ b/css/css-flexbox/support/scrollbars.js
@@ -0,0 +1,45 @@
+var flexDirections = ["row", "row-reverse", "column", "column-reverse"];
+var textDirections = ["ltr", "rtl"];
+var writingModes = ["horizontal", "flipped-blocks", "flipped-lines"];
+
+var createLeafNode = (i) => {
+  var flexItem = document.createElement("div");
+  flexItem.className = "leaf" + i;
+  var contentItem = document.createElement("div");
+  contentItem.innerHTML = i;
+  flexItem.appendChild(contentItem);
+  return flexItem;
+}
+
+var createContentNode = (flexDirection, textDirection, writingMode) => {
+  var flexNode = document.createElement("div");
+  flexNode.className = "flex " + flexDirection;
+  flexNode.title = "flex-direction: " + flexDirection + "; direction: " + textDirection + "; writing-mode: " + writingMode;
+  for (var i = 1; i < 4; i++)
+    flexNode.appendChild(createLeafNode(i));
+  var marginShim = document.createElement("div");
+  return flexNode;
+}
+
+var createContainerNode = (flexDirection, textDirection, writingMode) => {
+  var containerNode = document.createElement("div");
+  containerNode.className = "container " + textDirection + " " + writingMode;
+  containerNode.appendChild(createContentNode(flexDirection, textDirection, writingMode));
+  return containerNode;
+}
+
+var createContainerRow = (flexDirection) => {
+  var containerRow = document.createElement("div");
+  containerRow.className = "container-row";
+  var rowLabel = document.createElement("div");
+  rowLabel.className = "vertical-header horizontal " + flexDirection;
+  rowLabel.innerHTML = flexDirection;
+  containerRow.appendChild(rowLabel);
+  textDirections.forEach((textDirection) => {
+    writingModes.forEach((writingMode) => {
+      var containerNode = createContainerNode(flexDirection, textDirection, writingMode);
+      containerRow.appendChild(containerNode);
+    });
+  });
+  return containerRow;
+}