Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Unified Diff: test/runner/browser/runner_test.dart

Issue 1087303004: Add support for user-defined HTML files. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pubspec.yaml ('k') | test/runner/pub_serve_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/runner/browser/runner_test.dart
diff --git a/test/runner/browser/runner_test.dart b/test/runner/browser/runner_test.dart
index dadf54917a57eaee32991c70cf490f31421a95a5..60ec848c71b4fc567e5cee3adf566e7788a48a65 100644
--- a/test/runner/browser/runner_test.dart
+++ b/test/runner/browser/runner_test.dart
@@ -115,6 +115,125 @@ void main() {
expect(result.exitCode, equals(1));
});
+ test("a custom HTML file has no script tag", () {
+ var testPath = p.join(_sandbox, "test.dart");
+ new File(testPath).writeAsStringSync("void main(arg) {}");
+
+ new File(p.join(_sandbox, "test.html")).writeAsStringSync("""
+<html>
+<head>
+ <link rel="x-dart-test" href="test.dart">
+</head>
+</html>
+""");
+
+ var relativePath = p.relative(testPath, from: _sandbox);
+ var result = _runUnittest(["-p", "dartium", "test.dart"]);
+ expect(result.stdout, allOf([
+ contains('-1: load error'),
+ contains(
+ 'Failed to load "$relativePath": '
+ '"${p.withoutExtension(relativePath)}.html" must contain '
+ '<script src="packages/test/dart.js"></script>.\n')
+ ]));
+ expect(result.exitCode, equals(1));
+ });
+
+ test("a custom HTML file has no link", () {
+ var testPath = p.join(_sandbox, "test.dart");
+ new File(testPath).writeAsStringSync("void main(arg) {}");
+
+ new File(p.join(_sandbox, "test.html")).writeAsStringSync("""
+<html>
+<head>
+ <script src="packages/test/dart.js"></script>
+</head>
+</html>
+""");
+
+ var result = _runUnittest(["-p", "dartium", "test.dart"]);
+ expect(result.stdout, allOf([
+ contains('-1: load error'),
+ contains(
+ 'Failed to load "${p.relative(testPath, from: _sandbox)}": '
+ 'Expected exactly 1 <link rel="x-dart-test"> in test.html, '
+ 'found 0.\n')
+ ]));
+ expect(result.exitCode, equals(1));
+ });
+
+ test("a custom HTML file has too many links", () {
+ var testPath = p.join(_sandbox, "test.dart");
+ new File(testPath).writeAsStringSync("void main(arg) {}");
+
+ new File(p.join(_sandbox, "test.html")).writeAsStringSync("""
+<html>
+<head>
+ <link rel='x-dart-test' href='test.dart'>
+ <link rel='x-dart-test' href='test.dart'>
+ <script src="packages/test/dart.js"></script>
+</head>
+</html>
+""");
+
+ var result = _runUnittest(["-p", "dartium", "test.dart"]);
+ expect(result.stdout, allOf([
+ contains('-1: load error'),
+ contains(
+ 'Failed to load "${p.relative(testPath, from: _sandbox)}": '
+ 'Expected exactly 1 <link rel="x-dart-test"> in test.html, '
+ 'found 2.\n')
+ ]));
+ expect(result.exitCode, equals(1));
+ });
+
+ test("a custom HTML file has no href in the link", () {
+ var testPath = p.join(_sandbox, "test.dart");
+ new File(testPath).writeAsStringSync("void main(arg) {}");
+
+ new File(p.join(_sandbox, "test.html")).writeAsStringSync("""
+<html>
+<head>
+ <link rel='x-dart-test'>
+ <script src="packages/test/dart.js"></script>
+</head>
+</html>
+""");
+
+ var result = _runUnittest(["-p", "dartium", "test.dart"]);
+ expect(result.stdout, allOf([
+ contains('-1: load error'),
+ contains(
+ 'Failed to load "${p.relative(testPath, from: _sandbox)}": '
+ 'Expected <link rel="x-dart-test"> in test.html to have an '
+ '"href" attribute.\n')
+ ]));
+ expect(result.exitCode, equals(1));
+ });
+
+ test("a custom HTML file has an invalid test URL", () {
+ var testPath = p.join(_sandbox, "test.dart");
+ new File(testPath).writeAsStringSync("void main(arg) {}");
+
+ new File(p.join(_sandbox, "test.html")).writeAsStringSync("""
+<html>
+<head>
+ <link rel='x-dart-test' href='wrong.dart'>
+ <script src="packages/test/dart.js"></script>
+</head>
+</html>
+""");
+
+ var result = _runUnittest(["-p", "dartium", "test.dart"]);
+ expect(result.stdout, allOf([
+ contains('-1: load error'),
+ contains(
+ 'Failed to load "${p.relative(testPath, from: _sandbox)}": '
+ 'Failed to load script at ')
+ ]));
+ expect(result.exitCode, equals(1));
+ });
+
// TODO(nweiz): test what happens when a test file is unreadable once issue
// 15078 is fixed.
});
@@ -178,6 +297,44 @@ void main() {
var result = _runUnittest(["-p", "chrome", "-p", "vm", "test.dart"]);
expect(result.exitCode, equals(0));
});
+
+ group("with a custom HTML file", () {
+ setUp(() {
+ new File(p.join(_sandbox, "test.dart")).writeAsStringSync("""
+import 'dart:html';
+
+import 'package:test/test.dart';
+
+void main() {
+ test("success", () {
+ expect(document.query('#foo'), isNotNull);
+ });
+}
+""");
+
+ new File(p.join(_sandbox, "test.html")).writeAsStringSync("""
+<html>
+<head>
+ <link rel='x-dart-test' href='test.dart'>
+ <script src="packages/test/dart.js"></script>
+</head>
+<body>
+ <div id="foo"></div>
+</body>
+</html>
+""");
+ });
+
+ test("on content shell", () {
+ var result = _runUnittest(["-p", "content-shell", "test.dart"]);
+ expect(result.exitCode, equals(0));
+ });
+
+ test("on Chrome", () {
+ var result = _runUnittest(["-p", "chrome", "test.dart"]);
+ expect(result.exitCode, equals(0));
+ });
+ });
});
group("runs failing tests", () {
@@ -250,6 +407,45 @@ void main() {
var result = _runUnittest(["-p", "chrome", "-p", "vm", "test.dart"]);
expect(result.exitCode, equals(1));
});
+
+
+ group("with a custom HTML file", () {
+ setUp(() {
+ new File(p.join(_sandbox, "test.dart")).writeAsStringSync("""
+import 'dart:html';
+
+import 'package:test/test.dart';
+
+void main() {
+ test("failure", () {
+ expect(document.query('#foo'), isNull);
+ });
+}
+""");
+
+ new File(p.join(_sandbox, "test.html")).writeAsStringSync("""
+<html>
+<head>
+ <link rel='x-dart-test' href='test.dart'>
+ <script src="packages/test/dart.js"></script>
+</head>
+<body>
+ <div id="foo"></div>
+</body>
+</html>
+""");
+ });
+
+ test("on content shell", () {
+ var result = _runUnittest(["-p", "content-shell", "test.dart"]);
+ expect(result.exitCode, equals(1));
+ });
+
+ test("on Chrome", () {
+ var result = _runUnittest(["-p", "chrome", "test.dart"]);
+ expect(result.exitCode, equals(1));
+ });
+ });
});
test("forwards prints from the browser test", () {
« no previous file with comments | « pubspec.yaml ('k') | test/runner/pub_serve_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698