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