Srujan Gaddam | 1d44ef0 | 2020-04-03 00:36:56 +0000 | [diff] [blame] | 1 | // Copyright (c) 2020, 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 | |
Srujan Gaddam | 1d44ef0 | 2020-04-03 00:36:56 +0000 | [diff] [blame] | 5 | import 'dart:html'; |
| 6 | |
| 7 | import 'package:expect/minitest.dart'; |
| 8 | |
| 9 | // Test that the dart:html API does not leak native jsdom methods: |
| 10 | // onfocus setter. |
| 11 | |
| 12 | main() { |
| 13 | test('test1', () { |
Srujan Gaddam | 5b24820 | 2020-04-06 20:41:14 +0000 | [diff] [blame] | 14 | document.body!.children.add(new Element.html(r''' |
Srujan Gaddam | 1d44ef0 | 2020-04-03 00:36:56 +0000 | [diff] [blame] | 15 | <div id='div1'> |
| 16 | Hello World! |
| 17 | </div>''')); |
Srujan Gaddam | 5b24820 | 2020-04-06 20:41:14 +0000 | [diff] [blame] | 18 | Element? e = document.querySelector('#div1'); |
Srujan Gaddam | 1d44ef0 | 2020-04-03 00:36:56 +0000 | [diff] [blame] | 19 | expect(e, isNotNull); |
| 20 | |
| 21 | expect(() { |
Srujan Gaddam | 5b24820 | 2020-04-06 20:41:14 +0000 | [diff] [blame] | 22 | confuse(e!).onfocus = null; |
Srujan Gaddam | 1d44ef0 | 2020-04-03 00:36:56 +0000 | [diff] [blame] | 23 | }, throwsNoSuchMethodError); |
| 24 | }); |
| 25 | } |
| 26 | |
| 27 | class Decoy { |
| 28 | void set onfocus(x) { |
| 29 | throw 'dead code'; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | confuse(x) => opaqueTrue() ? x : (opaqueTrue() ? new Object() : new Decoy()); |
| 34 | |
| 35 | /** Returns `true`, but in a way that confuses the compiler. */ |
| 36 | opaqueTrue() => true; // Expand as needed. |