| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 library polymer.test.linter_test; | |
| 6 | |
| 7 import 'dart:convert'; | |
| 8 | |
| 9 import 'package:polymer/src/build/common.dart'; | |
| 10 import 'package:polymer/src/build/linter.dart'; | |
| 11 import 'package:polymer/src/build/messages.dart'; | |
| 12 import 'package:unittest/unittest.dart'; | |
| 13 | |
| 14 import 'common.dart'; | |
| 15 | |
| 16 void main() { | |
| 17 _testLinter('nothing to report', { | |
| 18 'a|lib/test.html': '<!DOCTYPE html><html></html>', | |
| 19 }, []); | |
| 20 | |
| 21 group('must have proper initialization imports', () { | |
| 22 _testLinter('nothing to report (no polymer use)', { | |
| 23 'a|web/test.html': '<!DOCTYPE html><html>' | |
| 24 '<script type="application/dart" src="foo.dart">' | |
| 25 '</script>' | |
| 26 '<script src="packages/browser/dart.js"></script>' | |
| 27 '</html>', | |
| 28 }, []); | |
| 29 | |
| 30 _testLinter('nothing to report (no polymer use with import)', { | |
| 31 'a|web/test.html': '<!DOCTYPE html><html>' | |
| 32 '<link rel="import" href="packages/polymer/polymer.html">' | |
| 33 '<script type="application/dart" src="foo.dart">' | |
| 34 '</script>' | |
| 35 '<script src="packages/browser/dart.js"></script>' | |
| 36 '</html>', | |
| 37 }, []); | |
| 38 | |
| 39 _testLinter('nothing to report (polymer used)', { | |
| 40 'a|web/test.html': '<!DOCTYPE html><html>' | |
| 41 '<link rel="import" href="packages/polymer/polymer.html">' | |
| 42 '<polymer-element name="x-a"></polymer-element>' | |
| 43 '<script type="application/dart" src="foo.dart">' | |
| 44 '</script>' | |
| 45 '<script src="packages/browser/dart.js"></script>' | |
| 46 '</html>', | |
| 47 }, []); | |
| 48 | |
| 49 _testLinter('nothing to report (polymer imported transitively)', { | |
| 50 'a|lib/lib.html': '<!DOCTYPE html><html>' | |
| 51 '<link rel="import" href="../../packages/polymer/polymer.html">', | |
| 52 'a|web/test.html': '<!DOCTYPE html><html>' | |
| 53 '<link rel="import" href="packages/a/lib.html">' | |
| 54 '<polymer-element name="x-a"></polymer-element>' | |
| 55 '<script type="application/dart" src="foo.dart">' | |
| 56 '</script>' | |
| 57 '<script src="packages/browser/dart.js"></script>' | |
| 58 '</html>', | |
| 59 }, []); | |
| 60 | |
| 61 test('usePolymerHtmlMessage looks right', () { | |
| 62 _check(int i, String url) { | |
| 63 expect(_usePolymerHtmlMessage(i), | |
| 64 contains('<link rel="import" href="$url">')); | |
| 65 } | |
| 66 _check(0, 'packages/polymer/polymer.html'); | |
| 67 _check(1, '../packages/polymer/polymer.html'); | |
| 68 _check(2, '../../packages/polymer/polymer.html'); | |
| 69 _check(3, '../../../packages/polymer/polymer.html'); | |
| 70 }); | |
| 71 | |
| 72 _testLinter('missing polymer.html in web', { | |
| 73 'a|web/test.html': '<!DOCTYPE html><html>\n' | |
| 74 '<polymer-element name="x-a"></polymer-element>' | |
| 75 '<script type="application/dart" src="foo.dart">' | |
| 76 '</script>' | |
| 77 '<script src="packages/browser/dart.js"></script>' | |
| 78 '</html>', | |
| 79 }, [ | |
| 80 'warning: ${_usePolymerHtmlMessage(0)} ' | |
| 81 '(web/test.html 1 0)', | |
| 82 ]); | |
| 83 | |
| 84 _testLinter('missing polymer.html in web/foo', { | |
| 85 'a|web/foo/test.html': '<!DOCTYPE html><html>\n' | |
| 86 '<polymer-element name="x-a"></polymer-element>' | |
| 87 '<script type="application/dart" src="foo.dart">' | |
| 88 '</script>' | |
| 89 '<script src="packages/browser/dart.js"></script>' | |
| 90 '</html>', | |
| 91 }, [ | |
| 92 'warning: ${_usePolymerHtmlMessage(1)} ' | |
| 93 '(web/foo/test.html 1 0)', | |
| 94 ]); | |
| 95 | |
| 96 _testLinter('missing polymer.html in lib', { | |
| 97 'a|lib/test.html': '<!DOCTYPE html><html>\n' | |
| 98 '<polymer-element name="x-a"></polymer-element>' | |
| 99 '<script type="application/dart" src="foo.dart">' | |
| 100 '</script>' | |
| 101 '<script src="packages/browser/dart.js"></script>' | |
| 102 '</html>', | |
| 103 }, [ | |
| 104 'warning: ${_usePolymerHtmlMessage(2)} ' | |
| 105 '(lib/test.html 1 0)', | |
| 106 ]); | |
| 107 | |
| 108 _testLinter('missing polymer.html in lib/foo/bar', { | |
| 109 'a|lib/foo/bar/test.html': '<!DOCTYPE html><html>\n' | |
| 110 '<polymer-element name="x-a"></polymer-element>' | |
| 111 '<script type="application/dart" src="foo.dart">' | |
| 112 '</script>' | |
| 113 '<script src="packages/browser/dart.js"></script>' | |
| 114 '</html>', | |
| 115 }, [ | |
| 116 'warning: ${_usePolymerHtmlMessage(4)} ' | |
| 117 '(lib/foo/bar/test.html 1 0)', | |
| 118 ]); | |
| 119 | |
| 120 _testLinter('missing Dart code', { | |
| 121 'a|web/test.html': '<!DOCTYPE html><html>' | |
| 122 '<link rel="import" href="packages/polymer/polymer.html">' | |
| 123 '<script src="packages/browser/dart.js"></script>' | |
| 124 '</html>', | |
| 125 }, [ | |
| 126 'warning: ${MISSING_INIT_POLYMER.snippet}', | |
| 127 ]); | |
| 128 | |
| 129 _testLinter('nothing to report, experimental with no Dart code', { | |
| 130 'a|web/test.html': '<!DOCTYPE html><html>' | |
| 131 '<link rel="import" ' | |
| 132 'href="packages/polymer/polymer_experimental.html">' | |
| 133 '<script src="packages/browser/dart.js"></script>' | |
| 134 '</html>', | |
| 135 }, []); | |
| 136 | |
| 137 _testLinter('experimental cannot have Dart code in main document', { | |
| 138 'a|web/test.html': '<!DOCTYPE html><html>' | |
| 139 '<link rel="import" ' | |
| 140 'href="packages/polymer/polymer_experimental.html">\n' | |
| 141 '<script type="application/dart" src="foo.dart">' | |
| 142 '</script>' | |
| 143 '<script src="packages/browser/dart.js"></script>' | |
| 144 '</html>', | |
| 145 }, [ | |
| 146 'warning: ${NO_DART_SCRIPT_AND_EXPERIMENTAL.snippet} ' | |
| 147 '(web/test.html 1 0)', | |
| 148 ]); | |
| 149 | |
| 150 _testLinter('missing Dart code and polymer.html', { | |
| 151 'a|web/test.html': '<!DOCTYPE html><html></html>', | |
| 152 }, [ | |
| 153 'warning: ${MISSING_INIT_POLYMER.snippet}', | |
| 154 ]); | |
| 155 | |
| 156 _testLinter('dart_support unnecessary', { | |
| 157 'a|web/test.html': '<!DOCTYPE html><html>' | |
| 158 '<script src="packages/web_components/dart_support.js"></script>' | |
| 159 '<link rel="import" href="../../packages/polymer/polymer.html">' | |
| 160 '<polymer-element name="x-a"></polymer-element>' | |
| 161 '<script type="application/dart" src="foo.dart">' | |
| 162 '</script>' | |
| 163 '<script src="packages/browser/dart.js"></script>' | |
| 164 '</html>', | |
| 165 }, [ | |
| 166 'warning: ${DART_SUPPORT_NO_LONGER_REQUIRED.snippet} ' | |
| 167 '(web/test.html 0 21)' | |
| 168 ]); | |
| 169 | |
| 170 _testLinter('webcomponents unnecessary', { | |
| 171 'a|web/test.html': '<!DOCTYPE html><html>' | |
| 172 '$WEB_COMPONENTS_JS_TAG' | |
| 173 '<script type="application/dart" src="foo.dart">' | |
| 174 '</script>' | |
| 175 '</html>', | |
| 176 }, [ | |
| 177 'warning: ${WEB_COMPONENTS_NO_LONGER_REQUIRED.snippet} ' | |
| 178 '(web/test.html 0 21)' | |
| 179 ]); | |
| 180 | |
| 181 | |
| 182 _testLinter('platform.js -> webcomponents.js', { | |
| 183 'a|web/test.html': | |
| 184 '<!DOCTYPE html><html>' | |
| 185 '$PLATFORM_JS_TAG' | |
| 186 '<script type="application/dart" src="foo.dart">' | |
| 187 '</script>' | |
| 188 '</html>', | |
| 189 }, [ | |
| 190 'warning: ${PLATFORM_JS_RENAMED.snippet} ' | |
| 191 '(web/test.html 0 21)' | |
| 192 ]); | |
| 193 | |
| 194 }); | |
| 195 | |
| 196 group('single script tag per document', () { | |
| 197 _testLinter('two top-level tags', { | |
| 198 'a|web/test.html': '<!DOCTYPE html><html>' | |
| 199 '<link rel="import" href="packages/polymer/polymer.html">' | |
| 200 '<script type="application/dart" src="a.dart">' | |
| 201 '</script>\n' | |
| 202 '<script type="application/dart" src="b.dart">' | |
| 203 '</script>' | |
| 204 '<script src="packages/browser/dart.js"></script>', | |
| 205 }, [ | |
| 206 'warning: ${ONLY_ONE_TAG.snippet} (web/test.html 1 0)', | |
| 207 ]); | |
| 208 | |
| 209 _testLinter('two top-level tags, non entrypoint', { | |
| 210 'a|lib/test.html': '<!DOCTYPE html><html>' | |
| 211 '<script type="application/dart" src="a.dart">' | |
| 212 '</script>\n' | |
| 213 '<script type="application/dart" src="b.dart">' | |
| 214 '</script>' | |
| 215 '<script src="packages/browser/dart.js"></script>' | |
| 216 }, [ | |
| 217 'warning: ${ONLY_ONE_TAG.snippet} (lib/test.html 1 0)', | |
| 218 ]); | |
| 219 | |
| 220 _testLinter('tags inside elements', { | |
| 221 'a|web/test.html': '<!DOCTYPE html><html>' | |
| 222 '<link rel="import" href="packages/polymer/polymer.html">' | |
| 223 '<polymer-element name="x-a">' | |
| 224 '<script type="application/dart" src="a.dart">' | |
| 225 '</script>' | |
| 226 '</polymer-element>\n' | |
| 227 '<script type="application/dart" src="b.dart">' | |
| 228 '</script>' | |
| 229 '<script src="packages/browser/dart.js"></script>', | |
| 230 }, [ | |
| 231 'warning: ${ONLY_ONE_TAG.snippet} (web/test.html 1 0)', | |
| 232 ]); | |
| 233 }); | |
| 234 | |
| 235 group('doctype warning', () { | |
| 236 _testLinter('in web', { | |
| 237 'a|web/test.html': '<html></html>', | |
| 238 }, [ | |
| 239 'warning: (from html5lib) Unexpected start tag (html). ' | |
| 240 'Expected DOCTYPE. (web/test.html 0 0)', | |
| 241 'warning: ${MISSING_INIT_POLYMER.snippet}', | |
| 242 ]); | |
| 243 | |
| 244 _testLinter('in lib', { | |
| 245 'a|lib/test.html': '<html></html>', | |
| 246 }, []); | |
| 247 }); | |
| 248 | |
| 249 group('duplicate polymer-elements,', () { | |
| 250 _testLinter('same file', { | |
| 251 'a|lib/test.html': '''<html> | |
| 252 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 253 <polymer-element name="x-a"></polymer-element> | |
| 254 <polymer-element name="x-a"></polymer-element> | |
| 255 </html>'''.replaceAll(' ', ''), | |
| 256 }, [ | |
| 257 'warning: ${DUPLICATE_DEFINITION.create( | |
| 258 {'name': 'x-a', 'second': ''}).snippet} (lib/test.html 2 0)', | |
| 259 'warning: ${DUPLICATE_DEFINITION.create( | |
| 260 {'name': 'x-a', 'second': ' (second definition).'}).snippet} ' | |
| 261 '(lib/test.html 3 0)', | |
| 262 ]); | |
| 263 | |
| 264 _testLinter('other file', { | |
| 265 'a|lib/b.html': '''<html> | |
| 266 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 267 <polymer-element name="x-a"></polymer-element> | |
| 268 </html>'''.replaceAll(' ', ''), | |
| 269 'a|lib/test.html': '''<html> | |
| 270 <link rel="import" href="b.html"> | |
| 271 <polymer-element name="x-a"></polymer-element> | |
| 272 </html>'''.replaceAll(' ', ''), | |
| 273 }, [ | |
| 274 'warning: ${DUPLICATE_DEFINITION.create( | |
| 275 {'name': 'x-a', 'second': ''}).snippet} (lib/b.html 2 0)', | |
| 276 'warning: ${DUPLICATE_DEFINITION.create( | |
| 277 {'name': 'x-a', 'second': ' (second definition).'}).snippet} ' | |
| 278 '(lib/test.html 2 0)', | |
| 279 ]); | |
| 280 | |
| 281 _testLinter('non existing file', { | |
| 282 'a|lib/test.html': '''<html> | |
| 283 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 284 <link rel="import" href="b.html"> | |
| 285 <polymer-element name="x-a"></polymer-element> | |
| 286 </html>'''.replaceAll(' ', ''), | |
| 287 }, [ | |
| 288 'warning: ${IMPORT_NOT_FOUND.create( | |
| 289 {'path': 'lib/b.html', 'package': 'a'}).snippet} ' | |
| 290 '(lib/test.html 2 0)' | |
| 291 ]); | |
| 292 | |
| 293 _testLinter('other package', { | |
| 294 'b|lib/b.html': '''<html> | |
| 295 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 296 <polymer-element name="x-a"></polymer-element> | |
| 297 </html>'''.replaceAll(' ', ''), | |
| 298 'a|lib/test.html': '''<html> | |
| 299 <link rel="import" href="../../packages/b/b.html"> | |
| 300 <polymer-element name="x-a"></polymer-element> | |
| 301 </html>'''.replaceAll(' ', ''), | |
| 302 }, [ | |
| 303 'warning: ${DUPLICATE_DEFINITION.create( | |
| 304 {'name': 'x-a', 'second': ''}).snippet} (package:b/b.html 2 0)', | |
| 305 'warning: ${DUPLICATE_DEFINITION.create( | |
| 306 {'name': 'x-a', 'second': ' (second definition).'}).snippet} ' | |
| 307 '(lib/test.html 2 0)', | |
| 308 ]); | |
| 309 }); | |
| 310 | |
| 311 _testLinter('bad link-rel tag (href missing)', { | |
| 312 'a|lib/test.html': '''<html> | |
| 313 <link rel="import"> | |
| 314 <link rel="stylesheet"> | |
| 315 <link rel="foo"> | |
| 316 <link rel="import" href=""> | |
| 317 </html>'''.replaceAll(' ', ''), | |
| 318 }, [ | |
| 319 'warning: ${MISSING_HREF.create({'rel': 'import'}).snippet} ' | |
| 320 '(lib/test.html 1 0)', | |
| 321 'warning: ${MISSING_HREF.create({'rel': 'stylesheet'}).snippet} ' | |
| 322 '(lib/test.html 2 0)', | |
| 323 'warning: ${MISSING_HREF.create({'rel': 'import'}).snippet} ' | |
| 324 '(lib/test.html 4 0)', | |
| 325 ]); | |
| 326 | |
| 327 _testLinter('<element> is not supported', { | |
| 328 'a|lib/test.html': '''<html> | |
| 329 <element name="x-a"></element> | |
| 330 </html>'''.replaceAll(' ', ''), | |
| 331 }, [ | |
| 332 'warning: ${ELEMENT_DEPRECATED_EONS_AGO.snippet} (lib/test.html 1 0)' | |
| 333 ]); | |
| 334 | |
| 335 _testLinter('do not nest <polymer-element>', { | |
| 336 'a|lib/test.html': '''<html> | |
| 337 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 338 <polymer-element name="x-a"> | |
| 339 <template><div> | |
| 340 <polymer-element name="b"></polymer-element> | |
| 341 </div></template> | |
| 342 </polymer-element> | |
| 343 </html>'''.replaceAll(' ', ''), | |
| 344 }, [ | |
| 345 'error: ${NESTED_POLYMER_ELEMENT.snippet} (lib/test.html 4 4)' | |
| 346 ]); | |
| 347 | |
| 348 _testLinter('do put import inside <polymer-element>', { | |
| 349 'a|lib/b.html': '<html></html>', | |
| 350 'a|lib/test.html': '''<html> | |
| 351 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 352 <polymer-element name="x-a"> | |
| 353 <link rel="import" href="b.html"> | |
| 354 <template><div> | |
| 355 </div></template> | |
| 356 </polymer-element> | |
| 357 </html>'''.replaceAll(' ', ''), | |
| 358 }, [ | |
| 359 'error: ${NO_IMPORT_WITHIN_ELEMENT.snippet} (lib/test.html 3 2)' | |
| 360 ]); | |
| 361 | |
| 362 _testLinter('need a name for <polymer-element>', { | |
| 363 'a|lib/test.html': '''<html> | |
| 364 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 365 <polymer-element></polymer-element> | |
| 366 </html>'''.replaceAll(' ', ''), | |
| 367 }, [ | |
| 368 'error: ${MISSING_TAG_NAME.snippet} (lib/test.html 2 0)' | |
| 369 ]); | |
| 370 | |
| 371 _testLinter('name for <polymer-element> should have dashes', { | |
| 372 'a|lib/test.html': '''<html> | |
| 373 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 374 <polymer-element name="a"></polymer-element> | |
| 375 </html>'''.replaceAll(' ', ''), | |
| 376 }, [ | |
| 377 'error: ${INVALID_TAG_NAME.create({'name': 'a'}).snippet} ' | |
| 378 '(lib/test.html 2 0)' | |
| 379 ]); | |
| 380 | |
| 381 _testLinter('extend is a valid element or existing tag', { | |
| 382 'a|lib/test.html': '''<html> | |
| 383 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 384 <polymer-element name="x-a" extends="li"></polymer-element> | |
| 385 </html>'''.replaceAll(' ', ''), | |
| 386 }, []); | |
| 387 | |
| 388 _testLinter('extend is a valid element or existing tag', { | |
| 389 'a|lib/test.html': '''<html> | |
| 390 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 391 <polymer-element name="x-a" extends="x-b"></polymer-element> | |
| 392 </html>'''.replaceAll(' ', ''), | |
| 393 }, [ | |
| 394 'warning: ${CUSTOM_ELEMENT_NOT_FOUND.create({'tag': 'x-b'}).snippet} ' | |
| 395 '(lib/test.html 2 0)' | |
| 396 ]); | |
| 397 | |
| 398 | |
| 399 group('script type matches code', () { | |
| 400 _testLinter('top-level, .dart url', { | |
| 401 'a|lib/test.html': '''<html> | |
| 402 <script src="foo.dart"></script> | |
| 403 </html>'''.replaceAll(' ', ''), | |
| 404 }, [ | |
| 405 'warning: Wrong script type, expected type="application/dart".' | |
| 406 ' (lib/test.html 1 0)' | |
| 407 ]); | |
| 408 | |
| 409 _testLinter('in polymer-element, .dart url', { | |
| 410 'a|lib/test.html': '''<html> | |
| 411 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 412 <polymer-element name="x-a"> | |
| 413 <script src="foo.dart"></script> | |
| 414 </polymer-element> | |
| 415 </html>'''.replaceAll(' ', ''), | |
| 416 }, [ | |
| 417 'warning: ${EXPECTED_DART_MIME_TYPE.snippet} (lib/test.html 3 0)' | |
| 418 ]); | |
| 419 | |
| 420 _testLinter('in polymer-element, .js url', { | |
| 421 'a|lib/test.html': '''<html> | |
| 422 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 423 <polymer-element name="x-a"> | |
| 424 <script src="foo.js"></script> | |
| 425 </polymer-element> | |
| 426 </html>'''.replaceAll(' ', ''), | |
| 427 }, []); | |
| 428 | |
| 429 _testLinter('in polymer-element, inlined', { | |
| 430 'a|lib/test.html': '''<html> | |
| 431 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 432 <polymer-element name="x-a"> | |
| 433 <script>foo...</script> | |
| 434 </polymer-element> | |
| 435 </html>'''.replaceAll(' ', ''), | |
| 436 }, []); | |
| 437 | |
| 438 _testLinter('top-level, dart type & .dart url', { | |
| 439 'a|lib/test.html': '''<html> | |
| 440 <script type="application/dart" src="foo.dart"></script> | |
| 441 </html>'''.replaceAll(' ', ''), | |
| 442 }, []); | |
| 443 | |
| 444 _testLinter('top-level, dart type & .js url', { | |
| 445 'a|lib/test.html': '''<html> | |
| 446 <script type="application/dart" src="foo.js"></script> | |
| 447 </html>'''.replaceAll(' ', ''), | |
| 448 }, [ | |
| 449 'warning: ${EXPECTED_DART_EXTENSION.snippet} (lib/test.html 1 0)' | |
| 450 ]); | |
| 451 }); | |
| 452 | |
| 453 _testLinter('script tags should have at least src url or inline code', { | |
| 454 'a|lib/test.html': '''<html> | |
| 455 <script type="application/dart"></script> | |
| 456 </html>'''.replaceAll(' ', ''), | |
| 457 }, [ | |
| 458 'warning: ${SCRIPT_TAG_SEEMS_EMPTY.snippet} (lib/test.html 1 0)' | |
| 459 ]); | |
| 460 | |
| 461 _testLinter('script tags should have only src url or inline code', { | |
| 462 'a|lib/test.html': '''<html> | |
| 463 <script type="application/dart" src="foo.dart">more</script> | |
| 464 </html>'''.replaceAll(' ', ''), | |
| 465 }, [ | |
| 466 'warning: ${FOUND_BOTH_SCRIPT_SRC_AND_TEXT.snippet} (lib/test.html 1 0)' | |
| 467 ]); | |
| 468 | |
| 469 group('event handlers', () { | |
| 470 _testLinter('no longer warn about inline onfoo (Javascript)', { | |
| 471 'a|lib/test.html': '''<html><body> | |
| 472 <div onfoo="something"></div> | |
| 473 '''.replaceAll(' ', ''), | |
| 474 }, []); | |
| 475 | |
| 476 _testLinter('no longer warn about on-foo for auto-binding templates', { | |
| 477 'a|lib/test.html': '''<html><body> | |
| 478 <template is="auto-binding-dart"> | |
| 479 <div on-foo="{{something}}"></div> | |
| 480 <template> | |
| 481 <div>foo</div> | |
| 482 </template> | |
| 483 <div on-foo="{{something}}"></div> | |
| 484 </template> | |
| 485 '''.replaceAll(' ', ''), | |
| 486 }, []); | |
| 487 | |
| 488 _testLinter('on-foo is only supported in polymer elements', { | |
| 489 'a|lib/test.html': '''<html><body> | |
| 490 <div on-foo="{{something}}"></div> | |
| 491 '''.replaceAll(' ', ''), | |
| 492 }, [ | |
| 493 'warning: ${EVENT_HANDLERS_ONLY_WITHIN_POLYMER.snippet} ' | |
| 494 '(lib/test.html 1 5)' | |
| 495 ]); | |
| 496 | |
| 497 _testLinter('on-foo uses the {{ binding }} syntax', { | |
| 498 'a|lib/test.html': '''<html><body> | |
| 499 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 500 <polymer-element name="x-a"><div on-foo="bar"></div> | |
| 501 </polymer-element> | |
| 502 '''.replaceAll(' ', ''), | |
| 503 }, [ | |
| 504 'warning: ${INVALID_EVENT_HANDLER_BODY.create( | |
| 505 {'value': 'bar', 'name': 'on-foo'}).snippet} (lib/test.html 2 33)' | |
| 506 ]); | |
| 507 | |
| 508 _testLinter('on-foo is not an expression', { | |
| 509 'a|lib/test.html': '''<html><body> | |
| 510 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 511 <polymer-element name="x-a"><div on-foo="{{bar()}}"></div> | |
| 512 </polymer-element> | |
| 513 '''.replaceAll(' ', ''), | |
| 514 }, [ | |
| 515 'warning: ${INVALID_EVENT_HANDLER_BODY.create( | |
| 516 {'value': '{{bar()}}', 'name': 'on-foo'}).snippet} ' | |
| 517 '(lib/test.html 2 33)' | |
| 518 ]); | |
| 519 | |
| 520 _testLinter('on-foo can\'t be empty', { | |
| 521 'a|lib/test.html': '''<html><body> | |
| 522 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 523 <polymer-element name="x-a"><div on-foo="{{}}"></div> | |
| 524 </polymer-element> | |
| 525 '''.replaceAll(' ', ''), | |
| 526 }, [ | |
| 527 'warning: ${INVALID_EVENT_HANDLER_BODY.create( | |
| 528 {'value': '{{}}', 'name': 'on-foo'}).snippet} (lib/test.html 2 33)' | |
| 529 ]); | |
| 530 | |
| 531 _testLinter('on-foo can\'t be just space', { | |
| 532 'a|lib/test.html': '''<html><body> | |
| 533 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 534 <polymer-element name="x-a"><div on-foo="{{ }}"></div> | |
| 535 </polymer-element> | |
| 536 '''.replaceAll(' ', ''), | |
| 537 }, [ | |
| 538 'warning: ${INVALID_EVENT_HANDLER_BODY.create( | |
| 539 {'value': '{{ }}', 'name': 'on-foo'}).snippet} (lib/test.html 2 33)' | |
| 540 ]); | |
| 541 | |
| 542 _testLinter('on-foo-bar is supported as a custom event name', { | |
| 543 'a|lib/test.html': '''<html><body> | |
| 544 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 545 <polymer-element name="x-a"><div on-foo-bar="{{quux}}"></div> | |
| 546 </polymer-element> | |
| 547 '''.replaceAll(' ', ''), | |
| 548 }, []); | |
| 549 }); | |
| 550 | |
| 551 group('using custom tags', () { | |
| 552 _testLinter('tag exists (x-tag)', { | |
| 553 'a|lib/test.html': '<x-foo></x-foo>', | |
| 554 }, [ | |
| 555 'warning: ${CUSTOM_ELEMENT_NOT_FOUND.create({'tag': 'x-foo'}).snippet} ' | |
| 556 '(lib/test.html 0 0)' | |
| 557 ]); | |
| 558 | |
| 559 _testLinter('tag exists (type extension)', { | |
| 560 'a|lib/test.html': '<div is="x-foo"></div>', | |
| 561 }, [ | |
| 562 'warning: ${CUSTOM_ELEMENT_NOT_FOUND.create({'tag': 'x-foo'}).snippet} ' | |
| 563 '(lib/test.html 0 0)' | |
| 564 ]); | |
| 565 | |
| 566 _testLinter('tag exists (internally defined in code)', { | |
| 567 'a|lib/test.html': '<div is="auto-binding-dart"></div>', | |
| 568 }, []); | |
| 569 | |
| 570 _testLinter('used correctly (no base tag)', { | |
| 571 'a|lib/test.html': ''' | |
| 572 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 573 <polymer-element name="x-a"></polymer-element> | |
| 574 <x-a></x-a> | |
| 575 '''.replaceAll(' ', ''), | |
| 576 }, []); | |
| 577 | |
| 578 _testLinter('used incorrectly (no base tag)', { | |
| 579 'a|lib/test.html': ''' | |
| 580 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 581 <polymer-element name="x-a"></polymer-element> | |
| 582 <div is="x-a"></div> | |
| 583 '''.replaceAll(' ', ''), | |
| 584 }, [ | |
| 585 'warning: ${BAD_INSTANTIATION_BOGUS_BASE_TAG.create( | |
| 586 {'tag': 'x-a', 'base': 'div'}).snippet} (lib/test.html 2 0)' | |
| 587 ]); | |
| 588 | |
| 589 _testLinter('used incorrectly, imported def (no base tag)', { | |
| 590 'a|lib/b.html': ''' | |
| 591 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 592 <polymer-element name="x-a"></polymer-element>''', | |
| 593 'a|lib/test.html': ''' | |
| 594 <link rel="import" href="b.html"> | |
| 595 <div is="x-a"></div> | |
| 596 '''.replaceAll(' ', ''), | |
| 597 }, [ | |
| 598 'warning: ${BAD_INSTANTIATION_BOGUS_BASE_TAG.create( | |
| 599 {'tag': 'x-a', 'base': 'div'}).snippet} (lib/test.html 1 0)' | |
| 600 ]); | |
| 601 | |
| 602 _testLinter('used correctly (base tag)', { | |
| 603 'a|lib/b.html': ''' | |
| 604 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 605 <polymer-element name="x-a" extends="div"> | |
| 606 </polymer-element> | |
| 607 '''.replaceAll(' ', ''), | |
| 608 'a|lib/test.html': ''' | |
| 609 <link rel="import" href="b.html"> | |
| 610 <div is="x-a"></div> | |
| 611 '''.replaceAll(' ', ''), | |
| 612 }, []); | |
| 613 | |
| 614 _testLinter('used incorrectly (missing base tag)', { | |
| 615 'a|lib/b.html': ''' | |
| 616 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 617 <polymer-element name="x-a" extends="div"> | |
| 618 </polymer-element> | |
| 619 '''.replaceAll(' ', ''), | |
| 620 'a|lib/test.html': ''' | |
| 621 <link rel="import" href="b.html"> | |
| 622 <x-a></x-a> | |
| 623 '''.replaceAll(' ', ''), | |
| 624 }, [ | |
| 625 'warning: ${BAD_INSTANTIATION_MISSING_BASE_TAG.create( | |
| 626 {'tag': 'x-a', 'base': 'div'}).snippet} (lib/test.html 1 0)' | |
| 627 ]); | |
| 628 | |
| 629 _testLinter('used incorrectly (wrong base tag)', { | |
| 630 'a|lib/b.html': ''' | |
| 631 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 632 <polymer-element name="x-a" extends="div"> | |
| 633 </polymer-element> | |
| 634 '''.replaceAll(' ', ''), | |
| 635 'a|lib/test.html': ''' | |
| 636 <link rel="import" href="b.html"> | |
| 637 <span is="x-a"></span> | |
| 638 '''.replaceAll(' ', ''), | |
| 639 }, [ | |
| 640 'warning: ${BAD_INSTANTIATION_WRONG_BASE_TAG.create( | |
| 641 {'tag': 'x-a', 'base': 'div'}).snippet} (lib/test.html 1 0)' | |
| 642 ]); | |
| 643 | |
| 644 _testLinter('used incorrectly (wrong base tag, transitive)', { | |
| 645 'a|lib/c.html': ''' | |
| 646 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 647 <polymer-element name="x-c" extends="li"> | |
| 648 </polymer-element> | |
| 649 <polymer-element name="x-b" extends="x-c"> | |
| 650 </polymer-element> | |
| 651 '''.replaceAll(' ', ''), | |
| 652 'a|lib/b.html': ''' | |
| 653 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 654 <link rel="import" href="c.html"> | |
| 655 <polymer-element name="x-a" extends="x-b"> | |
| 656 </polymer-element> | |
| 657 '''.replaceAll(' ', ''), | |
| 658 'a|lib/test.html': ''' | |
| 659 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 660 <link rel="import" href="b.html"> | |
| 661 <span is="x-a"></span> | |
| 662 '''.replaceAll(' ', ''), | |
| 663 }, [ | |
| 664 'warning: ${BAD_INSTANTIATION_WRONG_BASE_TAG.create( | |
| 665 {'tag': 'x-a', 'base': 'li'}).snippet} (lib/test.html 2 0)' | |
| 666 ]); | |
| 667 | |
| 668 _testLinter('FOUC warning works', { | |
| 669 'a|web/a.html': ''' | |
| 670 <!DOCTYPE html> | |
| 671 <html><body> | |
| 672 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 673 <polymer-element name="my-element" noscript></polymer-element> | |
| 674 <my-element>hello!</my-element> | |
| 675 <script type="application/dart"> | |
| 676 export "package:polymer/init.dart"; | |
| 677 </script> | |
| 678 </body></html> | |
| 679 ''', | |
| 680 'a|web/b.html': ''' | |
| 681 <!DOCTYPE html> | |
| 682 <html><body> | |
| 683 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 684 <polymer-element name="my-element" noscript></polymer-element> | |
| 685 <div><my-element>hello!</my-element></div> | |
| 686 <script type="application/dart"> | |
| 687 export "package:polymer/init.dart"; | |
| 688 </script> | |
| 689 </body></html> | |
| 690 ''', | |
| 691 'a|web/c.html': ''' | |
| 692 <!DOCTYPE html> | |
| 693 <html unresolved><body> | |
| 694 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 695 <polymer-element name="my-element" noscript></polymer-element> | |
| 696 <my-element>hello!</my-element> | |
| 697 <script type="application/dart"> | |
| 698 export "package:polymer/init.dart"; | |
| 699 </script> | |
| 700 </body></html> | |
| 701 ''' | |
| 702 }, [ | |
| 703 'warning: ${POSSIBLE_FUOC.snippet} (web/a.html 4 14)', | |
| 704 'warning: ${POSSIBLE_FUOC.snippet} (web/b.html 4 19)', | |
| 705 'warning: ${POSSIBLE_FUOC.snippet} (web/c.html 4 14)', | |
| 706 ]); | |
| 707 | |
| 708 _testLinter('FOUC, no false positives.', { | |
| 709 // Parent has unresolved attribute. | |
| 710 'a|web/a.html': ''' | |
| 711 <!DOCTYPE html> | |
| 712 <html><body> | |
| 713 <div unresolved> | |
| 714 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 715 <polymer-element name="my-element" noscript></polymer-element> | |
| 716 <my-element>hello!</my-element> | |
| 717 </div> | |
| 718 <script type="application/dart"> | |
| 719 export "package:polymer/init.dart"; | |
| 720 </script> | |
| 721 </body></html> | |
| 722 ''', | |
| 723 // Body has unresolved attribute. | |
| 724 'a|web/b.html': ''' | |
| 725 <!DOCTYPE html> | |
| 726 <html><body unresolved> | |
| 727 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 728 <polymer-element name="my-element" noscript></polymer-element> | |
| 729 <my-element>hello!</my-element> | |
| 730 <script type="application/dart"> | |
| 731 export "package:polymer/init.dart"; | |
| 732 </script> | |
| 733 </body></html> | |
| 734 ''', | |
| 735 // Inside polymer-element tags its fine. | |
| 736 'a|web/c.html': ''' | |
| 737 <!DOCTYPE html> | |
| 738 <html><body> | |
| 739 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 740 <polymer-element name="my-element" noscript></polymer-element> | |
| 741 <polymer-element name="foo-element"> | |
| 742 <template><my-element>hello!</my-element></template> | |
| 743 </polymer-element> | |
| 744 <script type="application/dart"> | |
| 745 export "package:polymer/init.dart"; | |
| 746 </script> | |
| 747 </body></html> | |
| 748 ''', | |
| 749 // Empty custom elements are fine. | |
| 750 'a|web/d.html': ''' | |
| 751 <!DOCTYPE html> | |
| 752 <html><body> | |
| 753 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 754 <polymer-element name="my-element" noscript></polymer-element> | |
| 755 <my-element></my-element> | |
| 756 <script type="application/dart"> | |
| 757 export "package:polymer/init.dart"; | |
| 758 </script> | |
| 759 </body></html> | |
| 760 ''', | |
| 761 // Entry points only! | |
| 762 'a|lib/a.html': ''' | |
| 763 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 764 <polymer-element name="my-element" noscript></polymer-element> | |
| 765 <my-element>hello!</my-element> | |
| 766 ''', | |
| 767 }, []); | |
| 768 }); | |
| 769 | |
| 770 group('custom attributes', () { | |
| 771 _testLinter('foo-bar is no longer supported in attributes', { | |
| 772 'a|lib/test.html': '''<html><body> | |
| 773 <link rel="import" href="../../packages/polymer/polymer.html"> | |
| 774 <polymer-element name="x-a" attributes="foo-bar"> | |
| 775 </polymer-element> | |
| 776 '''.replaceAll(' ', ''), | |
| 777 }, [ | |
| 778 'warning: ${NO_DASHES_IN_CUSTOM_ATTRIBUTES.create( | |
| 779 {'name': 'foo-bar', 'alternative': '"fooBar" or "foobar"'}) | |
| 780 .snippet} (lib/test.html 2 28)' | |
| 781 ]); | |
| 782 }); | |
| 783 | |
| 784 _testLinter("namespaced attributes don't cause an internal error", { | |
| 785 'a|lib/test.html': '''<html><body> | |
| 786 <svg xmlns="http://www.w3.org/2000/svg" width="520" height="350"> | |
| 787 </svg> | |
| 788 '''.replaceAll(' ', ''), | |
| 789 }, []); | |
| 790 | |
| 791 group('output logs to file', () { | |
| 792 final outputLogsPhases = [[new Linter( | |
| 793 new TransformOptions(injectBuildLogsInOutput: true, | |
| 794 releaseMode: false))]]; | |
| 795 | |
| 796 testPhases("logs are output to file", outputLogsPhases, { | |
| 797 'a|web/test.html': '<!DOCTYPE html><html>\n' | |
| 798 '<polymer-element name="x-a"></polymer-element>' | |
| 799 '<script type="application/dart" src="foo.dart">' | |
| 800 '</script>' | |
| 801 '<script src="packages/browser/dart.js"></script>' | |
| 802 '</html>', | |
| 803 }, { | |
| 804 'a|web/test.html._buildLogs.1': | |
| 805 '{"polymer#3":[{' | |
| 806 '"level":"Warning",' | |
| 807 '"message":{' | |
| 808 '"id":"polymer#3",' | |
| 809 '"snippet":"${_usePolymerHtmlMessage(0).replaceAll('"','\\"')}"' | |
| 810 '},' | |
| 811 '"span":{' | |
| 812 '"start":{' | |
| 813 '"url":"web/test.html",' | |
| 814 '"offset":22,' | |
| 815 '"line":1,' | |
| 816 '"column":0' | |
| 817 '},' | |
| 818 '"end":{' | |
| 819 '"url":"web/test.html",' | |
| 820 '"offset":50,' | |
| 821 '"line":1,' | |
| 822 '"column":28' | |
| 823 '},' | |
| 824 '"text":"<polymer-element name=\\"x-a\\">"' | |
| 825 '}' | |
| 826 '}]}', | |
| 827 }, [ | |
| 828 // Logs should still make it to barback too. | |
| 829 'warning: ${_usePolymerHtmlMessage(0)} (web/test.html 1 0)', | |
| 830 ]); | |
| 831 }); | |
| 832 } | |
| 833 | |
| 834 _usePolymerHtmlMessage(int i) { | |
| 835 var prefix = '../' * i; | |
| 836 return USE_POLYMER_HTML.create({'reachOutPrefix': prefix}).snippet; | |
| 837 } | |
| 838 | |
| 839 _testLinter(String name, Map inputFiles, List outputMessages, | |
| 840 [bool solo = false]) { | |
| 841 var outputFiles = {}; | |
| 842 if (outputMessages.every((m) => m.startsWith('warning:'))) { | |
| 843 inputFiles.forEach((k, v) => outputFiles[k] = v); | |
| 844 } | |
| 845 if (outputMessages.isEmpty) { | |
| 846 var linter = new Linter(new TransformOptions()); | |
| 847 testPhases(name, [[linter]], inputFiles, outputFiles, outputMessages, solo); | |
| 848 } else { | |
| 849 testLogOutput( | |
| 850 (options) => new Linter(options), name, inputFiles, outputFiles, | |
| 851 outputMessages, solo); | |
| 852 } | |
| 853 } | |
| OLD | NEW |