| 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 created_callback_test; |
| 6 import 'package:unittest/unittest.dart'; |
| 7 import 'package:unittest/html_config.dart'; |
| 8 import 'dart:html'; |
| 9 |
| 10 class A extends HtmlElement { |
| 11 static final tag = 'x-a'; |
| 12 factory A() => new Element.tag(tag); |
| 13 |
| 14 static int createdInvocations = 0; |
| 15 |
| 16 void onCreated() { |
| 17 createdInvocations++; |
| 18 } |
| 19 } |
| 20 |
| 21 class B extends HtmlElement { |
| 22 static final tag = 'x-b'; |
| 23 factory B() => new Element.tag(tag); |
| 24 } |
| 25 |
| 26 class C extends HtmlElement { |
| 27 static final tag = 'x-c'; |
| 28 factory C() => new Element.tag(tag); |
| 29 |
| 30 static int createdInvocations = 0; |
| 31 static var div; |
| 32 |
| 33 void onCreated() { |
| 34 createdInvocations++; |
| 35 |
| 36 if (this.id != 'u') { |
| 37 return; |
| 38 } |
| 39 |
| 40 var t = div.query('#t'); |
| 41 var v = div.query('#v'); |
| 42 var w = div.query('#w'); |
| 43 |
| 44 expect(query('x-b:not(:unresolved)'), this); |
| 45 expect(queryAll(':unresolved'), [v, w]); |
| 46 |
| 47 // As per: |
| 48 // http://www.w3.org/TR/2013/WD-custom-elements-20130514/#serializing-and-pa
rsing |
| 49 // creation order is t, u, v, w (postorder). |
| 50 expect(t is C, isTrue); |
| 51 // Note, this is different from JavaScript where this would be false. |
| 52 expect(v is C, isTrue); |
| 53 } |
| 54 } |
| 55 |
| 56 main() { |
| 57 useHtmlConfiguration(); |
| 58 |
| 59 // Adapted from Blink's |
| 60 // fast/dom/custom/created-callback test. |
| 61 |
| 62 test('transfer created callback', () { |
| 63 document.register(A.tag, A); |
| 64 var x = new A(); |
| 65 expect(A.createdInvocations, 1); |
| 66 }); |
| 67 |
| 68 test(':unresolved and created callback timing', () { |
| 69 document.register(B.tag, B); |
| 70 document.register(C.tag, C); |
| 71 |
| 72 var div = new DivElement(); |
| 73 C.div = div; |
| 74 div.innerHtml = """ |
| 75 <x-c id="t"></x-c> |
| 76 <x-b id="u"></x-b> |
| 77 <x-c id="v"></x-c> |
| 78 <x-b id="w"></x-b> |
| 79 """; |
| 80 |
| 81 expect(C.createdInvocations, 2); |
| 82 expect(div.query('#w') is B, isTrue); |
| 83 }); |
| 84 |
| 85 // TODO(vsm): Port additional test from upstream here: |
| 86 // http://src.chromium.org/viewvc/blink/trunk/LayoutTests/fast/dom/custom/crea
ted-callback.html?r1=156141&r2=156185 |
| 87 } |
| OLD | NEW |