OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 'native_testing.dart'; | 5 import 'native_testing.dart'; |
6 | 6 |
7 // Test to see if novel HTML tags are interpreted as HTMLElement. | 7 // Test to see if novel HTML tags are interpreted as HTMLElement. |
8 | 8 |
9 @Native("HTMLElement") | 9 @Native("HTMLElement") |
10 class Element { | 10 class Element { |
11 String dartMethod(int x) => 'dartMethod(${nativeMethod(x+1)})'; | 11 String dartMethod(int x) => 'dartMethod(${nativeMethod(x+1)})'; |
12 String nativeMethod(int x) native ; | 12 String nativeMethod(int x) native; |
13 } | 13 } |
14 | 14 |
15 makeE() native ; | 15 makeE() native; |
16 makeF() native ; | 16 makeF() native; |
17 | 17 |
18 void setup() native """ | 18 void setup() native """ |
19 // A novel HTML element. | 19 // A novel HTML element. |
20 function HTMLGoofyElement(){} | 20 function HTMLGoofyElement(){} |
21 HTMLGoofyElement.prototype.nativeMethod = function(a) { | 21 HTMLGoofyElement.prototype.nativeMethod = function(a) { |
22 return 'Goofy.nativeMethod(' + a + ')'; | 22 return 'Goofy.nativeMethod(' + a + ')'; |
23 }; | 23 }; |
24 makeE = function(){return new HTMLGoofyElement}; | 24 makeE = function(){return new HTMLGoofyElement}; |
25 | 25 |
26 // A non-HTML element with a misleading name. | 26 // A non-HTML element with a misleading name. |
(...skipping 13 matching lines...) Expand all Loading... |
40 var e = makeE(); | 40 var e = makeE(); |
41 Expect.equals('Goofy.nativeMethod(10)', e.nativeMethod(10)); | 41 Expect.equals('Goofy.nativeMethod(10)', e.nativeMethod(10)); |
42 Expect.equals('dartMethod(Goofy.nativeMethod(11))', e.dartMethod(10)); | 42 Expect.equals('dartMethod(Goofy.nativeMethod(11))', e.dartMethod(10)); |
43 | 43 |
44 var f = makeF(); | 44 var f = makeF(); |
45 Expect.throws(() => f.nativeMethod(20), (e) => e is NoSuchMethodError, | 45 Expect.throws(() => f.nativeMethod(20), (e) => e is NoSuchMethodError, |
46 'fake HTML Element must not run Dart method on native class'); | 46 'fake HTML Element must not run Dart method on native class'); |
47 Expect.throws(() => f.dartMethod(20), (e) => e is NoSuchMethodError, | 47 Expect.throws(() => f.dartMethod(20), (e) => e is NoSuchMethodError, |
48 'fake HTML Element must not run native method on native class'); | 48 'fake HTML Element must not run native method on native class'); |
49 } | 49 } |
OLD | NEW |