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