OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import 'dart:html' as dom; | 5 import 'dart:html' as dom; |
6 | 6 |
7 import 'package:expect/minitest.dart'; | 7 import 'package:expect/minitest.dart'; |
8 | 8 |
9 // Not defined in dom.Window. | 9 // Not defined in dom.Window. |
10 foo(x) => x; | 10 foo(x) => x; |
11 | 11 |
12 class Unused { | 12 class Unused { |
13 foo(x) => 'not $x'; | 13 foo(x) => 'not $x'; |
14 } | 14 } |
15 | 15 |
16 int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1)); | 16 int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1)); |
17 | 17 |
18 main() { | 18 main() { |
19 var things = <dynamic>[new Unused(), dom.window]; | 19 var things = <dynamic>[new Unused(), dom.window]; |
20 | 20 |
21 test('windowNonMethod', () { | 21 test('windowNonMethod', () { |
22 var win = things[inscrutable(1)]; | 22 var win = things[inscrutable(1)]; |
23 final message = foo("Hello World"); | 23 final message = foo("Hello World"); |
24 expect(() => win.foo(message), throwsNoSuchMethodError); | 24 expect(() => win.foo(message), throwsNoSuchMethodError); |
25 }); | 25 }); |
26 | 26 |
27 test('foo', () { | 27 test('foo', () { |
28 var win = things[inscrutable(0)]; | 28 var win = things[inscrutable(0)]; |
29 String x = win.foo('bar'); | 29 String x = win.foo('bar'); |
30 expect(x, 'not bar'); | 30 expect(x, 'not bar'); |
31 }); | 31 }); |
32 | 32 |
33 // Use dom.window directly in case the compiler does type inference. | 33 // Use dom.window directly in case the compiler does type inference. |
34 test('windowNonMethod2', () { | 34 test('windowNonMethod2', () { |
35 final message = foo("Hello World"); | 35 final message = foo("Hello World"); |
36 expect(() => (dom.window as dynamic).foo(message), | 36 expect(() => (dom.window as dynamic).foo(message), throwsNoSuchMethodError); |
37 throwsNoSuchMethodError); | 37 }); |
38 }); | |
39 } | 38 } |
OLD | NEW |