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

Side by Side Diff: tests/compiler/dart2js_native/native_field_invocation2_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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 "dart:_js_helper"; 5 import "native_testing.dart";
6 import "package:expect/expect.dart";
7 6
8 @Native("NNative") 7 @Native("NNative")
9 class NNative { 8 class NNative {
10 var status; 9 var status;
11 10
12 var f; 11 var f;
13 12
14 ClickCounter() {
15 f = wrap(g);
16 }
17
18 g(val) => "### $val ###"; 13 g(val) => "### $val ###";
19 } 14 }
20 15
21 nativeId(x) native ;
22
23 void setup() native """
24 nativeId = function(x) { return x; }
25 """;
26
27 class ClickCounter { 16 class ClickCounter {
28 var status; 17 var status;
29 18
30 var f; 19 var f;
31 20
32 ClickCounter() { 21 ClickCounter() {
33 f = wrap(g); 22 f = wrap(g);
34 } 23 }
35 24
36 g(val) => "### $val ###"; 25 g(val) => "### $val ###";
37 } 26 }
38 27
39 wrap(cb) { 28 wrap(cb) {
40 return (val) { 29 return (val) {
41 return cb("!!! $val !!!"); 30 return cb("!!! $val !!!");
42 }; 31 };
43 } 32 }
44 33
34 nativeId(x) native ;
35
36 void setup() native """
37 nativeId = function(x) { return x; }
38 """;
39
40
45 main() { 41 main() {
46 setup(); 42 setup();
47 // Make sure the ClickCounter class goes through interceptors. 43 // Make sure the ClickCounter class goes through interceptors.
48 Expect.equals("### !!! 42 !!! ###", nativeId(new ClickCounter()).f(42)); 44 Expect.equals("### !!! 42 !!! ###", nativeId(new ClickCounter()).f(42));
49 // We are interested in the direct call, where the type is known. 45 // We are interested in the direct call, where the type is known.
50 Expect.equals("### !!! 499 !!! ###", new ClickCounter().f(499)); 46 Expect.equals("### !!! 499 !!! ###", new ClickCounter().f(499));
51 } 47 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698