Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: tests/compiler/dart2js_native/native_method_rename2_frog_test.dart

Issue 2379173002: Add native_testing library to mock @Native classes (Closed)
Patch Set: xxx Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Test the feature where the native string declares the native method's name. 5 // Test the feature where the native string declares the native method's name.
6 6
7 import "package:expect/expect.dart"; 7 import "native_testing.dart";
8 import 'dart:_js_helper' show Native, JSName;
9 8
10 @Native("A") 9 @Native("A")
11 class A { 10 class A {
12 @JSName('fooA') 11 @JSName('fooA')
13 int foo() native ; 12 int foo() native ;
14 } 13 }
15 14
16 @Native("B") 15 @Native("B")
17 class B extends A { 16 class B extends A {
18 @JSName('fooB') 17 @JSName('fooB')
(...skipping 16 matching lines...) Expand all
35 } 34 }
36 } 35 }
37 function A(){} 36 function A(){}
38 A.prototype.fooA = function(){return 100;}; 37 A.prototype.fooA = function(){return 100;};
39 function B(){} 38 function B(){}
40 inherits(B, A); 39 inherits(B, A);
41 B.prototype.fooB = function(){return 200;}; 40 B.prototype.fooB = function(){return 200;};
42 41
43 makeA = function(){return new A}; 42 makeA = function(){return new A};
44 makeB = function(){return new B}; 43 makeB = function(){return new B};
44
45 self.nativeConstructor(A);
46 self.nativeConstructor(B);
45 """; 47 """;
46 48
47 testDynamic() { 49 testDynamic() {
48 var things = [makeA(), makeB()]; 50 var things = [makeA(), makeB()];
49 var a = things[0]; 51 var a = things[0];
50 var b = things[1]; 52 var b = things[1];
51 53
52 Expect.equals(100, a.foo()); 54 Expect.equals(100, a.foo());
53 Expect.equals(200, b.foo()); 55 Expect.equals(200, b.foo());
54 56
(...skipping 14 matching lines...) Expand all
69 71
70 testTyped() { 72 testTyped() {
71 A a = makeA(); 73 A a = makeA();
72 B b = makeB(); 74 B b = makeB();
73 75
74 Expect.equals(100, a.foo()); 76 Expect.equals(100, a.foo());
75 Expect.equals(200, b.foo()); 77 Expect.equals(200, b.foo());
76 } 78 }
77 79
78 main() { 80 main() {
81 nativeTesting();
79 setup(); 82 setup();
80 83
81 testDynamic(); 84 testDynamic();
82 testTyped(); 85 testTyped();
83 } 86 }
84 87
85 expectNoSuchMethod(action, note) { 88 expectNoSuchMethod(action, note) {
86 bool caught = false; 89 bool caught = false;
87 try { 90 try {
88 action(); 91 action();
89 } catch (ex) { 92 } catch (ex) {
90 caught = true; 93 caught = true;
91 Expect.isTrue(ex is NoSuchMethodError, note); 94 Expect.isTrue(ex is NoSuchMethodError, note);
92 } 95 }
93 Expect.isTrue(caught, note); 96 Expect.isTrue(caught, note);
94 } 97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698