OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 @JS() | 5 @JS() |
6 library tests.html.mirrors_js_typed_interop_test; | 6 library tests.html.mirrors_js_typed_interop_test; |
7 | 7 |
8 import 'dart:mirrors'; | 8 import 'dart:mirrors'; |
9 import 'dart:html'; | 9 import 'dart:html'; |
10 | 10 |
11 import 'package:js/js.dart'; | 11 import 'package:js/js.dart'; |
12 import 'package:unittest/unittest.dart'; | 12 import 'package:expect/minitest.dart'; |
13 import 'package:unittest/html_config.dart'; | |
14 | 13 |
15 _injectJs() { | 14 _injectJs() { |
16 document.body.append(new ScriptElement() | 15 document.body.append(new ScriptElement() |
17 ..type = 'text/javascript' | 16 ..type = 'text/javascript' |
18 ..innerHtml = r""" | 17 ..innerHtml = r""" |
19 window.foo = { | 18 window.foo = { |
20 x: 3, | 19 x: 3, |
21 z: 100, | 20 z: 100, |
22 multiplyBy2: function(arg) { return arg * 2; }, | 21 multiplyBy2: function(arg) { return arg * 2; }, |
23 }; | 22 }; |
24 """); | 23 """); |
25 } | 24 } |
26 | 25 |
27 @JS() | 26 @JS() |
28 external Foo get foo; | 27 external Foo get foo; |
29 | 28 |
30 @JS() | 29 @JS() |
31 class Foo { | 30 class Foo { |
32 external int get x; | 31 external int get x; |
33 external set x(v); | 32 external set x(v); |
34 external num multiplyBy2(num y); | 33 external num multiplyBy2(num y); |
35 } | 34 } |
36 | 35 |
37 main() { | 36 main() { |
38 _injectJs(); | 37 _injectJs(); |
39 | 38 |
40 useHtmlConfiguration(); | |
41 | |
42 test('dynamic dispatch', () { | 39 test('dynamic dispatch', () { |
43 var f = foo; | 40 var f = foo; |
44 expect(f.x, 3); | 41 expect(f.x, 3); |
45 // JsInterop methods are not accessible using reflection. | 42 // JsInterop methods are not accessible using reflection. |
46 expect(() => reflect(f).setField(#x, 123), throws); | 43 expect(() => reflect(f).setField(#x, 123), throws); |
47 expect(f.x, 3); | 44 expect(f.x, 3); |
48 }); | 45 }); |
49 } | 46 } |
OLD | NEW |