| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Classes and methods for running HTML tests. | 6 * Classes and methods for running HTML tests. |
| 7 * | 7 * |
| 8 * HTML tests are valid HTML files whose names end in _htmltest.html, and that | 8 * HTML tests are valid HTML files whose names end in _htmltest.html, and that |
| 9 * contain annotations specifying the scripts in the test and the | 9 * contain annotations specifying the scripts in the test and the |
| 10 * messages the test should post to its window, in order to pass. | 10 * messages the test should post to its window, in order to pass. |
| 11 */ | 11 */ |
| 12 library html_test; | 12 library html_test; |
| 13 | 13 |
| 14 import "dart:convert"; | 14 import "dart:convert"; |
| 15 import "dart:io"; | 15 import "dart:io"; |
| 16 | 16 |
| 17 import "path.dart"; | 17 import "path.dart"; |
| 18 import "test_suite.dart"; | 18 import "test_suite.dart"; |
| 19 import "utils.dart"; | 19 import "utils.dart"; |
| 20 | 20 |
| 21 RegExp htmlAnnotation = | 21 RegExp htmlAnnotation = |
| 22 new RegExp("START_HTML_DART_TEST([\\s\\S]*?)END_HTML_DART_TEST"); | 22 new RegExp("START_HTML_DART_TEST([\\s\\S]*?)END_HTML_DART_TEST"); |
| 23 | 23 |
| 24 HtmlTestInformation getInformation(String filename) { | 24 HtmlTestInformation getInformation(String filename) { |
| 25 if (!filename.endsWith("_htmltest.html")) { | 25 if (!filename.endsWith("_htmltest.html")) { |
| 26 DebugLogger.warning("File $filename is not an HTML test." | 26 DebugLogger.warning("File $filename is not an HTML test." |
| 27 " Should end in _htmltest.html."); | 27 " Should end in _htmltest.html."); |
| 28 return null; | 28 return null; |
| 29 } | 29 } |
| 30 String contents = new File(filename).readAsStringSync(); | 30 |
| 31 var contents = new File(filename).readAsStringSync(); |
| 31 var match = htmlAnnotation.firstMatch(contents); | 32 var match = htmlAnnotation.firstMatch(contents); |
| 32 if (match == null) return null; | 33 if (match == null) return null; |
| 34 |
| 33 var annotation = JSON.decode(match[1]); | 35 var annotation = JSON.decode(match[1]); |
| 34 if (annotation is! Map || | 36 if (annotation is! Map || |
| 35 annotation['expectedMessages'] is! List || | 37 annotation['expectedMessages'] is! List || |
| 36 annotation['scripts'] is! List) { | 38 annotation['scripts'] is! List) { |
| 37 DebugLogger.warning("File $filename does not have expected annotation." | 39 DebugLogger.warning("File $filename does not have expected annotation." |
| 38 " Should have {'scripts':[...], 'expectedMessages':[...]}"); | 40 " Should have {'scripts':[...], 'expectedMessages':[...]}"); |
| 39 return null; | 41 return null; |
| 40 } | 42 } |
| 41 return new HtmlTestInformation(new Path(filename), | 43 |
| 42 annotation['expectedMessages'], annotation['scripts']); | 44 return new HtmlTestInformation( |
| 45 new Path(filename), |
| 46 new List<String>.from(annotation['expectedMessages'] as List), |
| 47 new List<String>.from(annotation['scripts'] as List)); |
| 43 } | 48 } |
| 44 | 49 |
| 45 String getContents(HtmlTestInformation info, bool compileToJS) { | 50 String getContents(HtmlTestInformation info, bool compileToJS) { |
| 46 String contents = new File(info.filePath.toNativePath()).readAsStringSync(); | 51 String contents = new File(info.filePath.toNativePath()).readAsStringSync(); |
| 47 contents = contents.replaceFirst(htmlAnnotation, ''); | 52 contents = contents.replaceFirst(htmlAnnotation, ''); |
| 48 if (compileToJS) { | 53 if (compileToJS) { |
| 49 for (String script in info.scripts) { | 54 for (String script in info.scripts) { |
| 50 if (dartExtension.hasMatch(script)) { | 55 if (dartExtension.hasMatch(script)) { |
| 51 String jsScript = script.replaceFirst(dartExtension, '.js'); | 56 String jsScript = script.replaceFirst(dartExtension, '.js'); |
| 52 String tag = '<script src="$script" type="application/dart">'; | 57 String tag = '<script src="$script" type="application/dart">'; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 68 </head><body> | 73 </head><body> |
| 69 <h1>Failing HTML test</h1> | 74 <h1>Failing HTML test</h1> |
| 70 $message | 75 $message |
| 71 <script> | 76 <script> |
| 72 throw "HTML test failed: $message"; | 77 throw "HTML test failed: $message"; |
| 73 </script> | 78 </script> |
| 74 </body> | 79 </body> |
| 75 </html> | 80 </html> |
| 76 '''; | 81 '''; |
| 77 } | 82 } |
| OLD | NEW |