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

Side by Side Diff: tests/compiler/dart2js_native/native_field_rename_2_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 // A native method prevents other members from having that name, including 5 // A native method prevents other members from having that name, including
6 // fields. However, native fields keep their name. The implication: a getter 6 // fields. However, native fields keep their name. The implication: a getter
7 // for the field must be based on the field's name, not the field's jsname. 7 // for the field must be based on the field's name, not the field's jsname.
8 8
9 import "package:expect/expect.dart"; 9 import 'native_testing.dart';
10 import 'dart:_js_helper' show Native, JSName;
11 10
12 abstract class I { 11 abstract class I {
13 int key; 12 int key;
14 } 13 }
15 14
16 @Native("A") 15 @Native("A")
17 class A implements I { 16 class A implements I {
18 int key; // jsname is 'key' 17 int key; // jsname is 'key'
19 int getKey() => key; 18 int getKey() => key;
20 } 19 }
(...skipping 19 matching lines...) Expand all
40 void setup() native """ 39 void setup() native """
41 // This code is all inside 'setup' and so not accesible from the global scope. 40 // This code is all inside 'setup' and so not accesible from the global scope.
42 function A(){ this.key = 111; } 41 function A(){ this.key = 111; }
43 A.prototype.getKey = function(){return this.key;}; 42 A.prototype.getKey = function(){return this.key;};
44 43
45 function X(){} 44 function X(){}
46 X.prototype.key = function(){return 666;}; 45 X.prototype.key = function(){return 666;};
47 46
48 makeA = function(){return new A}; 47 makeA = function(){return new A};
49 makeX = function(){return new X}; 48 makeX = function(){return new X};
49
50 self.nativeConstructor(A);
51 self.nativeConstructor(X);
50 """; 52 """;
51 53
52 testDynamic() { 54 testDynamic() {
53 var things = [makeA(), new B(), makeX()]; 55 var a = confuse(makeA());
54 var a = things[0]; 56 var b = confuse(new B());
55 var b = things[1]; 57 var x = confuse(makeX());
56 var x = things[2];
57 58
58 Expect.equals(111, a.key); 59 Expect.equals(111, a.key);
59 Expect.equals(222, b.key); 60 Expect.equals(222, b.key);
60 Expect.equals(111, a.getKey()); 61 Expect.equals(111, a.getKey());
61 Expect.equals(222, b.getKey()); 62 Expect.equals(222, b.getKey());
62 63
63 Expect.equals(666, x.native_key_method()); 64 Expect.equals(666, x.native_key_method());
64 Expect.equals(666, x.key()); 65 Expect.equals(666, x.key());
65 var fn = x.key; 66 var fn = x.key;
66 Expect.equals(666, fn()); 67 Expect.equals(666, fn());
(...skipping 17 matching lines...) Expand all
84 X x = makeX(); 85 X x = makeX();
85 86
86 Expect.equals(666, x.native_key_method()); 87 Expect.equals(666, x.native_key_method());
87 Expect.equals(111, a.key); 88 Expect.equals(111, a.key);
88 Expect.equals(222, b.key); 89 Expect.equals(222, b.key);
89 Expect.equals(111, a.getKey()); 90 Expect.equals(111, a.getKey());
90 Expect.equals(222, b.getKey()); 91 Expect.equals(222, b.getKey());
91 } 92 }
92 93
93 main() { 94 main() {
95 nativeTesting();
94 setup(); 96 setup();
95 97
96 testTyped(); 98 testTyped();
97 testPartial(); 99 testPartial();
98 testDynamic(); 100 testDynamic();
99 } 101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698