973a1a0219
This includes Fasta, tools and observatory, so the checked-in SDK must have the lower-case constants. Change-Id: I8380ad041ad058f7d02ae19caccfecd434d13d75 Reviewed-on: https://dart-review.googlesource.com/50201 Commit-Queue: Lasse R.H. Nielsen <lrn@google.com> Reviewed-by: Leaf Petersen <leafp@google.com>
83 lines
2.5 KiB
Dart
83 lines
2.5 KiB
Dart
// Copyright (c) 2014, 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.
|
|
|
|
/**
|
|
* Classes and methods for running HTML tests.
|
|
*
|
|
* HTML tests are valid HTML files whose names end in _htmltest.html, and that
|
|
* contain annotations specifying the scripts in the test and the
|
|
* messages the test should post to its window, in order to pass.
|
|
*/
|
|
library html_test;
|
|
|
|
import "dart:convert";
|
|
import "dart:io";
|
|
|
|
import "path.dart";
|
|
import "test_suite.dart";
|
|
import "utils.dart";
|
|
|
|
RegExp htmlAnnotation =
|
|
new RegExp("START_HTML_DART_TEST([\\s\\S]*?)END_HTML_DART_TEST");
|
|
|
|
HtmlTestInformation getInformation(String filename) {
|
|
if (!filename.endsWith("_htmltest.html")) {
|
|
DebugLogger.warning("File $filename is not an HTML test."
|
|
" Should end in _htmltest.html.");
|
|
return null;
|
|
}
|
|
|
|
var contents = new File(filename).readAsStringSync();
|
|
var match = htmlAnnotation.firstMatch(contents);
|
|
if (match == null) return null;
|
|
|
|
var annotation = jsonDecode(match[1]);
|
|
if (annotation is! Map ||
|
|
annotation['expectedMessages'] is! List ||
|
|
annotation['scripts'] is! List) {
|
|
DebugLogger.warning("File $filename does not have expected annotation."
|
|
" Should have {'scripts':[...], 'expectedMessages':[...]}");
|
|
return null;
|
|
}
|
|
|
|
return new HtmlTestInformation(
|
|
new Path(filename),
|
|
new List<String>.from(annotation['expectedMessages'] as List),
|
|
new List<String>.from(annotation['scripts'] as List));
|
|
}
|
|
|
|
String getContents(HtmlTestInformation info, bool compileToJS) {
|
|
String contents = new File(info.filePath.toNativePath()).readAsStringSync();
|
|
contents = contents.replaceFirst(htmlAnnotation, '');
|
|
if (compileToJS) {
|
|
for (String script in info.scripts) {
|
|
if (dartExtension.hasMatch(script)) {
|
|
String jsScript = script.replaceFirst(dartExtension, '.js');
|
|
String tag = '<script src="$script" type="application/dart">';
|
|
String jsTag = '<script src="$jsScript">';
|
|
contents = contents.replaceAll(tag, jsTag);
|
|
}
|
|
}
|
|
}
|
|
return contents;
|
|
}
|
|
|
|
String makeFailingHtmlFile(String message) {
|
|
return '''
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<script>window.parent.dispatchEvent(new Event('detect_errors'));</script>
|
|
<title>Failing HTML test</title>
|
|
</head><body>
|
|
<h1>Failing HTML test</h1>
|
|
$message
|
|
<script>
|
|
throw "HTML test failed: $message";
|
|
</script>
|
|
</body>
|
|
</html>
|
|
''';
|
|
}
|