summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-grid/support/grid-child-utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/css/css-grid/support/grid-child-utils.js')
-rw-r--r--testing/web-platform/tests/css/css-grid/support/grid-child-utils.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/testing/web-platform/tests/css/css-grid/support/grid-child-utils.js b/testing/web-platform/tests/css/css-grid/support/grid-child-utils.js
new file mode 100644
index 0000000000..5e0c5caad1
--- /dev/null
+++ b/testing/web-platform/tests/css/css-grid/support/grid-child-utils.js
@@ -0,0 +1,45 @@
+// Any copyright is dedicated to the Public Domain.
+// https://creativecommons.org/publicdomain/zero/1.0/
+
+const gridChildHelperRow = "row";
+const gridChildHelperCol = "col";
+
+// Helper for building testcases for grid-template-* with a child div in
+// multiple positions. Prop is expected to be one of gridChildHelperRow or
+// gridChildHelperCol, to select testing grid rows or grid columns,
+// respectively.
+// The child div is found by the id of 'child'.
+function GridChildHelper(prop, style){
+ this.child = document.getElementById("child");
+ this.style = style;
+ this.prop = prop;
+}
+
+// Runs a test for computed values on the property the helper object was
+// constructed with. The childStyle is used for choosing the grid row/column
+// of the child div.
+// expected is passed as-is to the computed value test.
+// The child style is appended to the test name in such a way that different
+// tests for the same parent style but different child style values will have
+// different test names.
+GridChildHelper.prototype.runTest = function(childStyle, expected) {
+ 'use strict';
+ const childProps = {
+ [gridChildHelperCol]:"gridColumn",
+ [gridChildHelperRow]:"gridRow"
+ };
+ const childProp = childProps[this.prop];
+
+ const parentProps = {
+ [gridChildHelperCol]:"grid-template-columns",
+ [gridChildHelperRow]:"grid-template-rows"
+ };
+ const parentProp = parentProps[this.prop];
+
+ const oldChildStyle = this.child[childProp];
+ this.child.style[childProp] = childStyle;
+
+ test_computed_value(parentProp, this.style, expected, childProp + " = " + childStyle);
+
+ this.child[childProp] = oldChildStyle;
+}