Files
sdk/utils/testrunner/html_wrap_task.dart
T
gram@google.com a1eecbbc65 Added support for layout render tests. These use expected values for the text render output from DumpRenderTree. When running a test in DRT the testrunner will see if there is a file with a .render extension in the same directory as the test file and with the same base file name. If so it will do additional checks of the rendered layout.
Here is a simple example test:

#library('sample');
#import('dart:html');
#import('pkg:unittest/unittest.dart');

main() {
  group('foo', () {
    test('test 1', () {
      document.body.nodes.add(new Element.html("<p>Test 1</p>"));
    });
    test('test 2', () {
      document.body.nodes.add(new Element.html("<p>Test 2</p>"));
    });
  });
}

And a sample matching .render file:

[foo test 1]
RenderBlock {P} at (0,0) size 284x20
  RenderText {#text} at (0,0) size 38x19
    text run at (0,0) width 38: "Test 1"
[foo test 2]
RenderBlock {P} at (0,0) size 284x20
  RenderText {#text} at (0,0) size 38x19
    text run at (0,0) width 38: "Test 2"

Note that the render content is only the content inside the <body> element, not including the body element itself.

testrunner can generate render files itself if you use the --generate-renders flag.

Also in this change - rename Configuration.log to trace, to avoid clash with the math log() function.
Review URL: https://chromiumcodereview.appspot.com//10914049

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@11994 260f80e4-7a28-3924-810f-c04153c831b5
2012-09-06 21:51:24 +00:00

150 lines
4.1 KiB
Dart

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/**
* A pipeline task to create a HTML/CSS wrapper for a test so it can run in DRT.
*/
class HtmlWrapTask extends PipelineTask {
final String _testFileTemplate;
final String _htmlSourceFileTemplate;
final String _htmlDestFileTemplate;
final String _cssSourceFileTemplate;
final String _cssDestFileTemplate;
HtmlWrapTask(this._testFileTemplate, this._htmlSourceFileTemplate,
this._htmlDestFileTemplate, this._cssSourceFileTemplate,
this._cssDestFileTemplate);
void execute(Path testfile, List stdout, List stderr, bool logging,
Function exitHandler) {
var testname = expandMacros(_testFileTemplate, testfile);
// If the test already has a corresponding HTML file we copy that,
// else we create a new wrapper.
var htmlSourceName = expandMacros(_htmlSourceFileTemplate, testfile);
var htmlDestName = expandMacros(_htmlDestFileTemplate, testfile);
var cssSourceName = expandMacros(_cssSourceFileTemplate, testfile);
var cssDestName = expandMacros(_cssDestFileTemplate, testfile);
var htmlMaster = new File(htmlSourceName);
if (htmlMaster.existsSync()) {
if (logging) {
stdout.add('Copying $htmlSourceName to $htmlDestName');
}
copyFile(htmlSourceName, htmlDestName);
} else {
if (logging) {
stdout.add('Creating wrapper $htmlDestName');
}
var p = new Path(testname);
var runtime = config.runtime;
var isLayout = isLayoutRenderTest(testname) || config.generateRenders;
StringBuffer sbuf = new StringBuffer();
sbuf.add("""
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>$testname</title>
<link rel="stylesheet" href="${p.filenameWithoutExtension}.css">
<script type='text/javascript'>
// We check the search part of the URL for making sure we only do
// this in the parent if in layout tests.
if (window.testRunner && window.location.search == '') {
function handleMessage(m) {
if (m.data == 'done') {
window.testRunner.notifyDone();
}
}
window.testRunner.waitUntilDone();
if (!$isLayout) {
window.testRunner.dumpAsText();
}
window.addEventListener("message", handleMessage, false);
}
""");
if (runtime == 'drt-dart') {
sbuf.add("if (navigator.webkitStartDart) navigator.webkitStartDart();");
}
sbuf.add("""
</script>
</head>
<body>
""");
if (!isLayout) {
sbuf.add("""
<h1>$testname</h1>
<div id="container"></div>
<pre id='console'></pre>
""");
}
sbuf.add("<script type='");
var prefix = flattenPath(p.directoryPath.toString());
if (runtime == 'drt-dart') {
sbuf.add("application/dart' src='${prefix}_${p.filename}'>");
} else {
sbuf.add("text/javascript' "
"src='${prefix}_${p.filenameWithoutExtension}.js'>");
}
sbuf.add("""
</script>
<script
src="http://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js">
</script>
</body>
</html>
""");
createFile(htmlDestName, sbuf.toString());
}
var cssMaster = new File(cssSourceName);
if (cssMaster.existsSync()) {
if (logging) {
stdout.add('Copying $cssSourceName to $cssDestName');
}
copyFile(cssSourceName, cssDestName);
} else {
if (logging) {
stdout.add('Creating $cssDestName');
}
createFile(cssDestName, """
body {
background-color: #F8F8F8;
font-family: 'Open Sans', sans-serif;
font-size: 14px;
font-weight: normal;
line-height: 1.2em;
margin: 15px;
}
p {
color: #333;
}
#container {
width: 100%;
height: 400px;
position: relative;
border: 1px solid #ccc;
background-color: #fff;
}
#text {
font-size: 24pt;
text-align: center;
margin-top: 140px;
}
""");
}
exitHandler(0);
}
void cleanup(Path testfile, List stdout, List stderr,
bool logging, bool keepFiles) {
deleteFiles([_htmlDestFileTemplate, _cssDestFileTemplate], testfile,
logging, keepFiles, stdout);
}
}