OLD | NEW |
1 library HiddenDom1Test; | 1 library HiddenDom1Test; |
| 2 |
2 import 'package:unittest/unittest.dart'; | 3 import 'package:unittest/unittest.dart'; |
3 import 'package:unittest/html_config.dart'; | 4 import 'package:unittest/html_config.dart'; |
4 import 'dart:html'; | 5 import 'dart:html'; |
5 | 6 |
6 // Test that the dart:html API does not leak native jsdom methods: | 7 // Test that the dart:html API does not leak native jsdom methods: |
7 // onfocus setter. | 8 // onfocus setter. |
8 | 9 |
9 main() { | 10 main() { |
10 useHtmlConfiguration(); | 11 useHtmlConfiguration(); |
11 | 12 |
12 test('test1', () { | 13 test('test1', () { |
13 document.body.children.add(new Element.html(r''' | 14 document.body.children.add(new Element.html(r''' |
14 <div id='div1'> | 15 <div id='div1'> |
15 Hello World! | 16 Hello World! |
16 </div>''')); | 17 </div>''')); |
17 Element e = document.query('#div1'); | 18 Element e = document.query('#div1'); |
18 expect(e, isNotNull); | 19 expect(e, isNotNull); |
19 | 20 |
20 checkNoSuchMethod(() { confuse(e).onfocus = null; }); | 21 checkNoSuchMethod(() { |
| 22 confuse(e).onfocus = null; |
| 23 }); |
21 }); | 24 }); |
22 | |
23 } | 25 } |
24 | 26 |
25 class Decoy { | 27 class Decoy { |
26 void set onfocus(x) { throw 'dead code'; } | 28 void set onfocus(x) { |
| 29 throw 'dead code'; |
| 30 } |
27 } | 31 } |
28 | 32 |
29 confuse(x) => opaqueTrue() ? x : (opaqueTrue() ? new Object() : new Decoy()); | 33 confuse(x) => opaqueTrue() ? x : (opaqueTrue() ? new Object() : new Decoy()); |
30 | 34 |
31 /** Returns [:true:], but in a way that confuses the compiler. */ | 35 /** Returns [:true:], but in a way that confuses the compiler. */ |
32 opaqueTrue() => true; // Expand as needed. | 36 opaqueTrue() => true; // Expand as needed. |
33 | 37 |
34 checkNoSuchMethod(action()) { | 38 checkNoSuchMethod(action()) { |
35 var ex = null; | 39 var ex = null; |
36 try { | 40 try { |
37 action(); | 41 action(); |
38 } catch (e) { | 42 } catch (e) { |
39 ex = e; | 43 ex = e; |
40 } | 44 } |
41 if (ex == null) | 45 if (ex == null) |
42 expect(false, isTrue, reason: 'Action should have thrown exception'); | 46 expect(false, isTrue, reason: 'Action should have thrown exception'); |
43 | 47 |
44 expect(ex, isNoSuchMethodError); | 48 expect(ex, isNoSuchMethodError); |
45 } | 49 } |
OLD | NEW |