Chromium Code Reviews| 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. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 var match = htmlAnnotation.firstMatch(contents); | 31 var match = htmlAnnotation.firstMatch(contents); |
| 32 if (match == null) return null; | 32 if (match == null) return null; |
| 33 var annotation = JSON.decode(match[1]); | 33 var annotation = JSON.decode(match[1]); |
| 34 if (annotation is! Map || | 34 if (annotation is! Map || |
| 35 annotation['expectedMessages'] is! List || | 35 annotation['expectedMessages'] is! List || |
| 36 annotation['scripts'] is! List) { | 36 annotation['scripts'] is! List) { |
| 37 DebugLogger.warning("File $filename does not have expected annotation." | 37 DebugLogger.warning("File $filename does not have expected annotation." |
| 38 " Should have {'scripts':[...], 'expectedMessages':[...]}"); | 38 " Should have {'scripts':[...], 'expectedMessages':[...]}"); |
| 39 return null; | 39 return null; |
| 40 } | 40 } |
| 41 return new HtmlTestInformation(new Path(filename), | 41 return new HtmlTestInformation( |
| 42 annotation['expectedMessages'], annotation['scripts']); | 42 new Path(filename), |
| 43 annotation['expectedMessages'] as List<String>, | |
|
Siggi Cherem (dart-lang)
2017/05/30 20:48:39
It seems this could fail in strong mode: the under
Bob Nystrom
2017/05/30 21:01:46
Ah, yes. Good catch. Fixed.
| |
| 44 annotation['scripts'] as List<String>); | |
| 43 } | 45 } |
| 44 | 46 |
| 45 String getContents(HtmlTestInformation info, bool compileToJS) { | 47 String getContents(HtmlTestInformation info, bool compileToJS) { |
| 46 String contents = new File(info.filePath.toNativePath()).readAsStringSync(); | 48 String contents = new File(info.filePath.toNativePath()).readAsStringSync(); |
| 47 contents = contents.replaceFirst(htmlAnnotation, ''); | 49 contents = contents.replaceFirst(htmlAnnotation, ''); |
| 48 if (compileToJS) { | 50 if (compileToJS) { |
| 49 for (String script in info.scripts) { | 51 for (String script in info.scripts) { |
| 50 if (dartExtension.hasMatch(script)) { | 52 if (dartExtension.hasMatch(script)) { |
| 51 String jsScript = script.replaceFirst(dartExtension, '.js'); | 53 String jsScript = script.replaceFirst(dartExtension, '.js'); |
| 52 String tag = '<script src="$script" type="application/dart">'; | 54 String tag = '<script src="$script" type="application/dart">'; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 68 </head><body> | 70 </head><body> |
| 69 <h1>Failing HTML test</h1> | 71 <h1>Failing HTML test</h1> |
| 70 $message | 72 $message |
| 71 <script> | 73 <script> |
| 72 throw "HTML test failed: $message"; | 74 throw "HTML test failed: $message"; |
| 73 </script> | 75 </script> |
| 74 </body> | 76 </body> |
| 75 </html> | 77 </html> |
| 76 '''; | 78 '''; |
| 77 } | 79 } |
| OLD | NEW |