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

Side by Side Diff: tests/compiler/dart2js_native/native_method_rename3_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 // #3. The name does not get 6 // #3. The name does not get
7 7
8 import "package:expect/expect.dart"; 8 import 'native_testing.dart';
9 import 'dart:_js_helper' show Native, JSName;
10 9
11 @Native("A") 10 @Native("A")
12 class A { 11 class A {
13 @JSName('fooA') 12 @JSName('fooA')
14 int foo() native ; 13 int foo() native ;
15 } 14 }
16 15
17 @Native("B") 16 @Native("B")
18 class B extends A { 17 class B extends A {
19 @JSName('fooB') 18 @JSName('fooB')
(...skipping 22 matching lines...) Expand all
42 } 41 }
43 } 42 }
44 function A(){} 43 function A(){}
45 A.prototype.fooA = function(){return 100;}; 44 A.prototype.fooA = function(){return 100;};
46 function B(){} 45 function B(){}
47 inherits(B, A); 46 inherits(B, A);
48 B.prototype.fooB = function(){return 200;}; 47 B.prototype.fooB = function(){return 200;};
49 48
50 makeA = function(){return new A}; 49 makeA = function(){return new A};
51 makeB = function(){return new B}; 50 makeB = function(){return new B};
51
52 self.nativeConstructor(A);
53 self.nativeConstructor(B);
52 """; 54 """;
53 55
54 testDynamic() { 56 testDynamic() {
55 var things = [makeA(), makeB(), new Decoy()]; 57 var a = confuse(makeA());
56 var a = things[0]; 58 var b = confuse(makeB());
57 var b = things[1]; 59 var d = confuse(new Decoy());
58 var d = things[2];
59 60
60 Expect.equals(100, a.foo()); 61 Expect.equals(100, a.foo());
61 Expect.equals(200, b.foo()); 62 Expect.equals(200, b.foo());
62 Expect.equals(666, d.fooA()); 63 Expect.equals(666, d.fooA());
63 Expect.equals(999, d.fooB()); 64 Expect.equals(999, d.fooB());
64 65
65 expectNoSuchMethod(() { 66 expectNoSuchMethod(() {
66 a.fooA(); 67 a.fooA();
67 }, 'fooA should be invisible on A'); 68 }, 'fooA should be invisible on A');
68 Expect.equals(333, b.fooA()); 69 Expect.equals(333, b.fooA());
(...skipping 11 matching lines...) Expand all
80 B b = makeB(); 81 B b = makeB();
81 Decoy d = new Decoy(); 82 Decoy d = new Decoy();
82 83
83 Expect.equals(100, a.foo()); 84 Expect.equals(100, a.foo());
84 Expect.equals(200, b.foo()); 85 Expect.equals(200, b.foo());
85 Expect.equals(666, d.fooA()); 86 Expect.equals(666, d.fooA());
86 Expect.equals(999, d.fooB()); 87 Expect.equals(999, d.fooB());
87 } 88 }
88 89
89 main() { 90 main() {
91 nativeTesting();
90 setup(); 92 setup();
91 93
92 testDynamic(); 94 testDynamic();
93 testTyped(); 95 testTyped();
94 } 96 }
95 97
96 expectNoSuchMethod(action, note) { 98 expectNoSuchMethod(action, note) {
97 bool caught = false; 99 bool caught = false;
98 try { 100 try {
99 action(); 101 action();
100 } on NoSuchMethodError catch (ex) { 102 } on NoSuchMethodError catch (ex) {
101 caught = true; 103 caught = true;
102 Expect.isTrue(ex is NoSuchMethodError, note); 104 Expect.isTrue(ex is NoSuchMethodError, note);
103 } 105 }
104 Expect.isTrue(caught, note); 106 Expect.isTrue(caught, note);
105 } 107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698