| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library test.src.task.html_test; | 5 library analyzer.test.src.task.html_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/source.dart'; | 7 import 'package:analyzer/src/generated/source.dart'; |
| 8 import 'package:analyzer/src/task/html.dart'; | 8 import 'package:analyzer/src/task/html.dart'; |
| 9 import 'package:analyzer/task/general.dart'; | 9 import 'package:analyzer/task/general.dart'; |
| 10 import 'package:analyzer/task/html.dart'; | 10 import 'package:analyzer/task/html.dart'; |
| 11 import 'package:analyzer/task/model.dart'; | 11 import 'package:analyzer/task/model.dart'; |
| 12 import 'package:html/dom.dart'; | 12 import 'package:html/dom.dart'; |
| 13 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 13 import 'package:unittest/unittest.dart'; | 14 import 'package:unittest/unittest.dart'; |
| 14 | 15 |
| 15 import '../../reflective_tests.dart'; | |
| 16 import '../../utils.dart'; | 16 import '../../utils.dart'; |
| 17 import '../context/abstract_context.dart'; | 17 import '../context/abstract_context.dart'; |
| 18 | 18 |
| 19 main() { | 19 main() { |
| 20 initializeTestEnvironment(); | 20 initializeTestEnvironment(); |
| 21 runReflectiveTests(DartScriptsTaskTest); | 21 defineReflectiveTests(DartScriptsTaskTest); |
| 22 runReflectiveTests(HtmlErrorsTaskTest); | 22 defineReflectiveTests(HtmlErrorsTaskTest); |
| 23 runReflectiveTests(ParseHtmlTaskTest); | 23 defineReflectiveTests(ParseHtmlTaskTest); |
| 24 } | 24 } |
| 25 | 25 |
| 26 isInstanceOf isDartScriptsTask = new isInstanceOf<DartScriptsTask>(); | 26 isInstanceOf isDartScriptsTask = new isInstanceOf<DartScriptsTask>(); |
| 27 isInstanceOf isHtmlErrorsTask = new isInstanceOf<HtmlErrorsTask>(); | 27 isInstanceOf isHtmlErrorsTask = new isInstanceOf<HtmlErrorsTask>(); |
| 28 isInstanceOf isParseHtmlTask = new isInstanceOf<ParseHtmlTask>(); | 28 isInstanceOf isParseHtmlTask = new isInstanceOf<ParseHtmlTask>(); |
| 29 | 29 |
| 30 @reflectiveTest | 30 @reflectiveTest |
| 31 class DartScriptsTaskTest extends AbstractContextTest { | 31 class DartScriptsTaskTest extends AbstractContextTest { |
| 32 test_buildInputs() { | 32 test_buildInputs() { |
| 33 Source source = newSource('/test.html'); | 33 Source source = newSource('/test.html'); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 </body> | 170 </body> |
| 171 </html>'''); | 171 </html>'''); |
| 172 computeResult(target, REFERENCED_LIBRARIES, matcher: isDartScriptsTask); | 172 computeResult(target, REFERENCED_LIBRARIES, matcher: isDartScriptsTask); |
| 173 expect(outputs[REFERENCED_LIBRARIES], hasLength(1)); | 173 expect(outputs[REFERENCED_LIBRARIES], hasLength(1)); |
| 174 expect(outputs[DART_SCRIPTS], hasLength(0)); | 174 expect(outputs[DART_SCRIPTS], hasLength(0)); |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 @reflectiveTest | 178 @reflectiveTest |
| 179 class HtmlErrorsTaskTest extends AbstractContextTest { | 179 class HtmlErrorsTaskTest extends AbstractContextTest { |
| 180 fail_perform_htmlErrors() { |
| 181 AnalysisTarget target = newSource( |
| 182 '/test.html', |
| 183 r''' |
| 184 <html> |
| 185 <head> |
| 186 <title>test page</not-title> |
| 187 </head> |
| 188 <body> |
| 189 Test |
| 190 </body> |
| 191 </html> |
| 192 '''); |
| 193 computeResult(target, HTML_ERRORS, matcher: isHtmlErrorsTask); |
| 194 expect(outputs[HTML_ERRORS], hasLength(1)); |
| 195 } |
| 196 |
| 180 test_constructor() { | 197 test_constructor() { |
| 181 Source source = newSource('/test.html'); | 198 Source source = newSource('/test.html'); |
| 182 HtmlErrorsTask task = new HtmlErrorsTask(context, source); | 199 HtmlErrorsTask task = new HtmlErrorsTask(context, source); |
| 183 expect(task, isNotNull); | 200 expect(task, isNotNull); |
| 184 expect(task.context, context); | 201 expect(task.context, context); |
| 185 expect(task.target, source); | 202 expect(task.target, source); |
| 186 } | 203 } |
| 187 | 204 |
| 188 test_createTask() { | 205 test_createTask() { |
| 189 Source source = newSource('/test.html'); | 206 Source source = newSource('/test.html'); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 216 void buttonPressed() { | 233 void buttonPressed() { |
| 217 </script> | 234 </script> |
| 218 </head> | 235 </head> |
| 219 <body>Test</body> | 236 <body>Test</body> |
| 220 </html> | 237 </html> |
| 221 '''); | 238 '''); |
| 222 computeResult(target, HTML_ERRORS, matcher: isHtmlErrorsTask); | 239 computeResult(target, HTML_ERRORS, matcher: isHtmlErrorsTask); |
| 223 expect(outputs[HTML_ERRORS], hasLength(1)); | 240 expect(outputs[HTML_ERRORS], hasLength(1)); |
| 224 } | 241 } |
| 225 | 242 |
| 226 test_perform_htmlErrors() { | |
| 227 AnalysisTarget target = newSource( | |
| 228 '/test.html', | |
| 229 r''' | |
| 230 <html> | |
| 231 <head> | |
| 232 <title>test page</not-title> | |
| 233 </head> | |
| 234 <body> | |
| 235 Test | |
| 236 </body> | |
| 237 </html> | |
| 238 '''); | |
| 239 computeResult(target, HTML_ERRORS, matcher: isHtmlErrorsTask); | |
| 240 expect(outputs[HTML_ERRORS], hasLength(1)); | |
| 241 } | |
| 242 | |
| 243 test_perform_noErrors() { | 243 test_perform_noErrors() { |
| 244 AnalysisTarget target = newSource( | 244 AnalysisTarget target = newSource( |
| 245 '/test.html', | 245 '/test.html', |
| 246 r''' | 246 r''' |
| 247 <!DOCTYPE html> | 247 <!DOCTYPE html> |
| 248 <html> | 248 <html> |
| 249 <head> | 249 <head> |
| 250 <title>test page</title> | 250 <title>test page</title> |
| 251 </head> | 251 </head> |
| 252 <body> | 252 <body> |
| 253 Test | 253 Test |
| 254 </body> | 254 </body> |
| 255 </html> | 255 </html> |
| 256 '''); | 256 '''); |
| 257 computeResult(target, HTML_ERRORS, matcher: isHtmlErrorsTask); | 257 computeResult(target, HTML_ERRORS, matcher: isHtmlErrorsTask); |
| 258 expect(outputs[HTML_ERRORS], isEmpty); | 258 expect(outputs[HTML_ERRORS], isEmpty); |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 | 261 |
| 262 @reflectiveTest | 262 @reflectiveTest |
| 263 class ParseHtmlTaskTest extends AbstractContextTest { | 263 class ParseHtmlTaskTest extends AbstractContextTest { |
| 264 test_buildInputs() { | 264 test_buildInputs() { |
| 265 Source source = newSource('/test.html'); | 265 Source source = newSource('/test.html'); |
| 266 Map<String, TaskInput> inputs = ParseHtmlTask.buildInputs(source); | 266 Map<String, TaskInput> inputs = ParseHtmlTask.buildInputs(source); |
| 267 expect(inputs, isNotNull); | 267 expect(inputs, isNotNull); |
| 268 expect(inputs.keys, unorderedEquals([ParseHtmlTask.CONTENT_INPUT_NAME])); | 268 expect( |
| 269 inputs.keys, |
| 270 unorderedEquals([ |
| 271 ParseHtmlTask.CONTENT_INPUT_NAME, |
| 272 ParseHtmlTask.MODIFICATION_TIME_INPUT |
| 273 ])); |
| 269 } | 274 } |
| 270 | 275 |
| 271 test_constructor() { | 276 test_constructor() { |
| 272 Source source = newSource('/test.html'); | 277 Source source = newSource('/test.html'); |
| 273 ParseHtmlTask task = new ParseHtmlTask(context, source); | 278 ParseHtmlTask task = new ParseHtmlTask(context, source); |
| 274 expect(task, isNotNull); | 279 expect(task, isNotNull); |
| 275 expect(task.context, context); | 280 expect(task.context, context); |
| 276 expect(task.target, source); | 281 expect(task.target, source); |
| 277 } | 282 } |
| 278 | 283 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 296 } | 301 } |
| 297 | 302 |
| 298 test_perform() { | 303 test_perform() { |
| 299 String code = r''' | 304 String code = r''' |
| 300 <!DOCTYPE html> | 305 <!DOCTYPE html> |
| 301 <html> | 306 <html> |
| 302 <head> | 307 <head> |
| 303 <title>test page</title> | 308 <title>test page</title> |
| 304 </head> | 309 </head> |
| 305 <body> | 310 <body> |
| 306 <h1 Test> | 311 <h1 myAttr='my value'>Test</h1> |
| 307 </body> | 312 </body> |
| 308 </html> | 313 </html> |
| 309 '''; | 314 '''; |
| 310 AnalysisTarget target = newSource('/test.html', code); | 315 AnalysisTarget target = newSource('/test.html', code); |
| 311 computeResult(target, HTML_DOCUMENT); | 316 computeResult(target, HTML_DOCUMENT); |
| 312 expect(task, isParseHtmlTask); | 317 expect(task, isParseHtmlTask); |
| 313 expect(outputs[HTML_DOCUMENT], isNotNull); | 318 expect(outputs[HTML_DOCUMENT_ERRORS], isEmpty); |
| 314 expect(outputs[HTML_DOCUMENT_ERRORS], isNotEmpty); | 319 // HTML_DOCUMENT |
| 320 { |
| 321 Document document = outputs[HTML_DOCUMENT]; |
| 322 expect(document, isNotNull); |
| 323 // verify that attributes are not lower-cased |
| 324 Element element = document.body.getElementsByTagName('h1').single; |
| 325 expect(element.attributes['myAttr'], 'my value'); |
| 326 } |
| 315 // LINE_INFO | 327 // LINE_INFO |
| 316 { | 328 { |
| 317 LineInfo lineInfo = outputs[LINE_INFO]; | 329 LineInfo lineInfo = outputs[LINE_INFO]; |
| 318 expect(lineInfo, isNotNull); | 330 expect(lineInfo, isNotNull); |
| 319 { | 331 { |
| 320 int offset = code.indexOf('<!DOCTYPE'); | 332 int offset = code.indexOf('<!DOCTYPE'); |
| 321 LineInfo_Location location = lineInfo.getLocation(offset); | 333 LineInfo_Location location = lineInfo.getLocation(offset); |
| 322 expect(location.lineNumber, 1); | 334 expect(location.lineNumber, 1); |
| 323 expect(location.columnNumber, 1); | 335 expect(location.columnNumber, 1); |
| 324 } | 336 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 expect(bodyElement.localName, 'body'); | 371 expect(bodyElement.localName, 'body'); |
| 360 // actual nodes | 372 // actual nodes |
| 361 expect(bodyElement.nodes, hasLength(4)); | 373 expect(bodyElement.nodes, hasLength(4)); |
| 362 expect((bodyElement.nodes[0] as Element).localName, 'div'); | 374 expect((bodyElement.nodes[0] as Element).localName, 'div'); |
| 363 expect((bodyElement.nodes[2] as Element).localName, 'span'); | 375 expect((bodyElement.nodes[2] as Element).localName, 'span'); |
| 364 } | 376 } |
| 365 // it's OK to don't have DOCTYPE | 377 // it's OK to don't have DOCTYPE |
| 366 expect(outputs[HTML_DOCUMENT_ERRORS], isEmpty); | 378 expect(outputs[HTML_DOCUMENT_ERRORS], isEmpty); |
| 367 } | 379 } |
| 368 } | 380 } |
| OLD | NEW |