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

Side by Side Diff: tests/compiler/dart2js_native/native_property_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 // Properties on hidden native classes. 5 // Properties on hidden native classes.
6 6
7 import "package:expect/expect.dart"; 7 import 'native_testing.dart';
8 import "dart:_js_helper";
9 import 'dart:_foreign_helper' show JS;
10 8
11 @Native("A") 9 @Native("A")
12 class A { 10 class A {
13 11
14 // Setters and getters should be similar to these methods: 12 // Setters and getters should be similar to these methods:
15 int getX() => JS('int', '#._x', this); 13 int getX() => JS('int', '#._x', this);
16 void setX(int value) { JS('void', '#._x = #', this, value); } 14 void setX(int value) { JS('void', '#._x = #', this, value); }
17 15
18 int get X() native; 16 int get X() native;
19 set X(int value) native; 17 set X(int value) native;
20 18
21 int get Y() native; 19 int get Y() native;
22 set Y(int value) native; 20 set Y(int value) native;
23 21
24 int get Z => JS('int', '#._z', this); 22 int get Z => JS('int', '#._z', this);
25 set Z(int value) { JS('void', '#._z = #', this, value); } 23 set Z(int value) { JS('void', '#._z = #', this, value); }
26 } 24 }
27 25
28 A makeA() native; 26 A makeA() native;
29 27
30 void setup() native """ 28 void setup() native """
31 function A() {} 29 function A() {}
32 30
33 Object.defineProperty(A.prototype, "X", { 31 Object.defineProperty(A.prototype, "X", {
34 get: function () { return this._x; }, 32 get: function () { return this._x; },
35 set: function (v) { this._x = v; } 33 set: function (v) { this._x = v; }
36 }); 34 });
37 35
38 makeA = function(){return new A;}; 36 makeA = function(){return new A;};
37
38 self.nativeConstructor(A);
39 """; 39 """;
40 40
41 41
42 main() { 42 main() {
43 nativeTesting();
43 setup(); 44 setup();
44 45
45 var a = makeA(); 46 var a = makeA();
46 47
47 a.setX(5); 48 a.setX(5);
48 Expect.equals(5, a.getX()); 49 Expect.equals(5, a.getX());
49 50
50 a.X = 10; 51 a.X = 10;
51 a.Y = 20; 52 a.Y = 20;
52 a.Z = 30; 53 a.Z = 30;
53 54
54 Expect.equals(10, a.X); 55 Expect.equals(10, a.X);
55 Expect.equals(20, a.Y); 56 Expect.equals(20, a.Y);
56 Expect.equals(30, a.Z); 57 Expect.equals(30, a.Z);
58
59 confuse(a).setX(6);
60 Expect.equals(6, confuse(a).getX());
61
62 Expect.equals(6, confuse(a).X);
63 Expect.equals(20, confuse(a).Y);
64 Expect.equals(30, confuse(a).Z);
57 } 65 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js_native/native_null_frog_test.dart ('k') | tests/compiler/dart2js_native/native_testing.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698