| 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 "dart:_js_helper"; |
| 6 import "package:expect/expect.dart"; |
| 6 | 7 |
| 7 // Test to see if novel HTML tags are interpreted as HTMLElement. | 8 // Test to see if novel HTML tags are interpreted as HTMLElement. |
| 8 | 9 |
| 9 @Native("HTMLElement") | 10 @Native("HTMLElement") |
| 10 class Element { | 11 class Element { |
| 11 String dartMethod(int x) => 'dartMethod(${nativeMethod(x+1)})'; | 12 String dartMethod(int x) => 'dartMethod(${nativeMethod(x+1)})'; |
| 12 String nativeMethod(int x) native ; | 13 String nativeMethod(int x) native ; |
| 13 } | 14 } |
| 14 | 15 |
| 15 makeE() native ; | 16 makeE() native ; |
| 16 makeF() native ; | 17 makeF() native ; |
| 17 | 18 |
| 18 void setup() native """ | 19 void setup() native """ |
| 19 // A novel HTML element. | 20 // A novel HTML element. |
| 20 function HTMLGoofyElement(){} | 21 function HTMLGoofyElement(){} |
| 21 HTMLGoofyElement.prototype.nativeMethod = function(a) { | 22 HTMLGoofyElement.prototype.nativeMethod = function(a) { |
| 22 return 'Goofy.nativeMethod(' + a + ')'; | 23 return 'Goofy.nativeMethod(' + a + ')'; |
| 23 }; | 24 }; |
| 24 makeE = function(){return new HTMLGoofyElement}; | 25 makeE = function(){return new HTMLGoofyElement}; |
| 25 | 26 |
| 26 // A non-HTML element with a misleading name. | 27 // A non-HTML element with a misleading name. |
| 27 function HTMLFakeyElement(){} | 28 function HTMLFakeyElement(){} |
| 28 HTMLFakeyElement.prototype.nativeMethod = function(a) { | 29 HTMLFakeyElement.prototype.nativeMethod = function(a) { |
| 29 return 'Fakey.nativeMethod(' + a + ')'; | 30 return 'Fakey.nativeMethod(' + a + ')'; |
| 30 }; | 31 }; |
| 31 makeF = function(){return new HTMLFakeyElement}; | 32 makeF = function(){return new HTMLFakeyElement}; |
| 32 | 33 |
| 33 self.nativeConstructor(HTMLGoofyElement); | 34 // Make the HTMLGoofyElement look like a real host object. |
| 35 var theRealObjectToString = Object.prototype.toString; |
| 36 Object.prototype.toString = function() { |
| 37 if (this instanceof HTMLGoofyElement) return '[object HTMLGoofyElement]'; |
| 38 return theRealObjectToString.call(this); |
| 39 } |
| 34 """; | 40 """; |
| 35 | 41 |
| 36 main() { | 42 main() { |
| 37 nativeTesting(); | |
| 38 setup(); | 43 setup(); |
| 39 | 44 |
| 40 var e = makeE(); | 45 var e = makeE(); |
| 41 Expect.equals('Goofy.nativeMethod(10)', e.nativeMethod(10)); | 46 Expect.equals('Goofy.nativeMethod(10)', e.nativeMethod(10)); |
| 42 Expect.equals('dartMethod(Goofy.nativeMethod(11))', e.dartMethod(10)); | 47 Expect.equals('dartMethod(Goofy.nativeMethod(11))', e.dartMethod(10)); |
| 43 | 48 |
| 44 var f = makeF(); | 49 var f = makeF(); |
| 45 Expect.throws(() => f.nativeMethod(20), (e) => e is NoSuchMethodError, | 50 Expect.throws(() => f.nativeMethod(20), (e) => e is NoSuchMethodError, |
| 46 'fake HTML Element must not run Dart method on native class'); | 51 'fake HTML Element must not run Dart method on native class'); |
| 47 Expect.throws(() => f.dartMethod(20), (e) => e is NoSuchMethodError, | 52 Expect.throws(() => f.dartMethod(20), (e) => e is NoSuchMethodError, |
| 48 'fake HTML Element must not run native method on native class'); | 53 'fake HTML Element must not run native method on native class'); |
| 49 } | 54 } |
| OLD | NEW |