diff options
Diffstat (limited to 'testing/web-platform/tests/css/css-writing-modes/tools')
4 files changed, 253 insertions, 0 deletions
diff --git a/testing/web-platform/tests/css/css-writing-modes/tools/generators/README.md b/testing/web-platform/tests/css/css-writing-modes/tools/generators/README.md new file mode 100644 index 0000000000..9bf89de07a --- /dev/null +++ b/testing/web-platform/tests/css/css-writing-modes/tools/generators/README.md @@ -0,0 +1,24 @@ +Generators +========== + +Following test files are generated by the programs in this directory: +* orthogonal-parent-shrink-to-fit-001 + +## Setup + +1. Install node.js. +2. Change the current directory to this directory. +3. Type the following commands: +``` +npm install +``` +4. (optional) Install gulp globally so it'll be on your path: +``` +sudo npm install -g gulp +``` + +## Generate Test Files + +``` +gulp +``` diff --git a/testing/web-platform/tests/css/css-writing-modes/tools/generators/gulpfile.js b/testing/web-platform/tests/css/css-writing-modes/tools/generators/gulpfile.js new file mode 100644 index 0000000000..f364024084 --- /dev/null +++ b/testing/web-platform/tests/css/css-writing-modes/tools/generators/gulpfile.js @@ -0,0 +1,79 @@ +'use strict'; + +var browserSync = null; +var gulp = require("gulp"); +var ejs = require("gulp-ejs"); +var rename = require("gulp-rename"); +var minimist = require('minimist'); +var argv = minimist(process.argv.slice(2)); + +gulp.task("default", [ + "orthogonal-parent-shrink-to-fit", +]); + +gulp.task("test", ["browser-sync", "watch"]); + +gulp.task("watch", function () { + gulp.watch("orthogonal-parent-shrink-to-fit.ejs", ["orthogonal-parent-shrink-to-fit"]); +}); + +gulp.task("browser-sync", function () { + if (!browserSync) + browserSync = require("browser-sync"); + browserSync({ + server: { + baseDir: "../../..", + directory: true, + }, + startPath: "css-writing-modes-3/", + }); +}); + +function reload() { + if (browserSync) + browserSync.reload(); +} + +gulp.task("server", function () { + var connect = require("connect"); + var serveIndex = require("serve-index"); + var serveStatic = require("serve-static"); + var directory = "../../.."; + var port = 8000; + connect() + .use(serveIndex(directory)) + .use(serveStatic(directory)) + .listen(port); + console.log("Listening on port " + port); +}) + +gulpTaskFromTemplateWithAffixes("orthogonal-parent-shrink-to-fit", "-001", -1, 24); + +gulp.task("update", function () { + const unicodeData = require('./unicode-data.js'); + unicodeData.copyToLocal(); +}); + +function gulpTaskFromTemplateWithAffixes(name, suffix, min, lim) { + if (argv.nocombo && min < 0) + min = 0; + if (argv.nochild && lim > 0) + lim = 0; + gulp.task(name, function () { + for (var i = min; i < lim; ++i) { + gulp.src(name + ".ejs") + .pipe(ejs({ index: i })) + .pipe(rename(name + suffix + affixFromIndex(i) + ".html")) + .pipe(gulp.dest("../..")); + } + reload(); + }); +} + +function affixFromIndex(index) { + if (index < 0) + return ""; + if (index >= 26) + throw new Error("Affix index too large (" + index + ")"); + return String.fromCharCode("a".charCodeAt(0) + index); +} diff --git a/testing/web-platform/tests/css/css-writing-modes/tools/generators/orthogonal-parent-shrink-to-fit.ejs b/testing/web-platform/tests/css/css-writing-modes/tools/generators/orthogonal-parent-shrink-to-fit.ejs new file mode 100644 index 0000000000..043cbaf747 --- /dev/null +++ b/testing/web-platform/tests/css/css-writing-modes/tools/generators/orthogonal-parent-shrink-to-fit.ejs @@ -0,0 +1,127 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<% +var testlist = []; +var outers = [ + ["inline-block", '<div class="inline-block">', '</div><span class="next">ZZ</span>'], + ["float", '<div class="float">', '</div><span class="next">ZZ</span>'], + ["table-cell", '<table><tr><td>', '</td><td class="next">ZZ</td></tr></table>']]; +var middles = [ + null, + ["inline-block", '<div class="inline-block">', '</div>']]; +var targets = [ + ["block", '<div class="target">HH</div>'], + ["inline", '<span class="target">HH</span>'], + ["block with borders", '<div class="target border">HHH</div>'], + ["inline with borders", '<span class="target border">HHH</span>']]; +for (var outer of outers) { + for (var middle of middles) { + for (var target of targets) { + var title = target[0]; + var html = target[1]; + if (middle) { + title += " in " + middle[0]; + html = middle[1] + html + middle[2]; + } + title = "Shrink-to-fit " + outer[0] + " with a child of orthogonal " + title; + html = outer[1] + html + outer[2]; + testlist.push([title, html]); + } + } +} +var min, limit, title; +if (index < 0) { + min = 0; + limit = testlist.length; + title = "Shrink-to-fit with orthogonal children" +} else { + min = index; + limit = index + 1; + title = testlist[index][0]; +} +%><title>CSS Writing Modes Test: <%= title %></title> +<link rel="help" href="http://www.w3.org/TR/css-writing-modes-3/#orthogonal-flows" title="7.3. Orthogonal Flows"> +<meta name="assert" content="<%= title %>"> +<meta name="flags" content="ahem dom<%= index < 0 ? ' combo' : ''%>"> +<link rel="author" title="Koji Ishii" href="mailto:kojiishi@gmail.com"> +<link rel="reviewer" title="GĂ©rard Talbot" href="http://www.gtalbot.org/BrowserBugsSection/css21testsuite/"> <!-- 2015-12-23 --> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" /> +<style> +.test { + border:thin solid; + font:20px/1 Ahem; +} +.target { + color:blue; + height:3em; /* height: 3em is not required. IE11 and Edge12 compute height to ICB height if + not set. We want the test to focus exclusively on shrink-to-fit algorithm. */ + writing-mode:vertical-rl; +} +.border { + border-right:blue solid .5em; +} +.next { + color:orange; +} +.inline-block { + display:inline-block; +} +.float { + float:left; +} +h3 { + clear:both; +} +h3.fail { + color:red; +} +table { + border-spacing:0px; +} +td { + padding:0px; +} +</style> +<div id="log"></div> +<div id="container"> +<p>Test passes if the X-position of the <b>left</b> edge of the orange box and the <b>right</b> edge of the blue box are the same. +<p>If script is enabled, there should be one or more PASS and no FAIL. +<% for (var i = min; i < limit; ++i) { + var test = testlist[i]; +%><h3><%= (i + 1) + ": " + test[0] %></h3> +<div class="test"> + <%- test[1] %> +</div> +<% } %></div> +<script> +if (window.location.search == "?wait") { + console.log("Sleeping 5 secs for debug"); + setup({explicit_done:true}); + window.setTimeout(run, 5000); +} else { + run(); +} + +function run() { + Array.prototype.forEach.call(document.querySelectorAll(".test"), function (node) { + var title = node.previousElementSibling.textContent; + test(function () { + try { + var targetNode = node.querySelector(".target"); + var fontSize = parseFloat(getComputedStyle(targetNode).fontSize); + var targetBounds = targetNode.getBoundingClientRect(); + assert_less_than_equal(targetBounds.width, fontSize * 2.01, "writing-mode is vertical") + var nextNode = node.querySelector(".next"); + var nextBounds = nextNode.getBoundingClientRect(); + assert_equals(nextBounds.left - targetBounds.right, 0, "the left edge of the orange box touches the right edge of the blue box"); + } catch (e) { + node.previousElementSibling.classList.add("fail"); + throw e; + } + }, title); + }); + done(); +} +</script> diff --git a/testing/web-platform/tests/css/css-writing-modes/tools/generators/package.json b/testing/web-platform/tests/css/css-writing-modes/tools/generators/package.json new file mode 100644 index 0000000000..8046cf4240 --- /dev/null +++ b/testing/web-platform/tests/css/css-writing-modes/tools/generators/package.json @@ -0,0 +1,23 @@ +{ + "name": "generators", + "version": "1.0.0", + "description": "", + "main": "gulpfile.js", + "dependencies": {}, + "devDependencies": { + "browser-sync": "^2.10.1", + "connect": "^3.4.0", + "ejs": "^2.3.1", + "gulp": "^3.8.11", + "gulp-ejs": "^1.1.0", + "gulp-rename": "^1.2.2", + "minimist": "^1.1.1", + "serve-index": "^1.7.2", + "serve-static": "^1.10.0" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} |