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

Side by Side Diff: tests/compiler/dart2js_native/fake_thing_2_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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // Test that native objects cannot accidentally or maliciously be mistaken for 7 // Test that native objects cannot accidentally or maliciously be mistaken for
9 // Dart objects. 8 // Dart objects.
10 // The difference between fake_thing_test and fake_thing_2_test is the 9 // The difference between fake_thing_test and fake_thing_2_test is the
11 // presence of a used declared native class. 10 // presence of a used declared native class.
12 11
13 class Thing {} 12 class Thing {}
14 13
15 @Native("NT") 14 @Native("NT")
16 class NativeThing {} 15 class NativeThing {}
17 16
18 make1() native ; 17 make1() native ;
19 make2() native ; 18 make2() native ;
20 make3() native ; 19 make3() native ;
21 20
22 void setup() native r""" 21 void setup() native r"""
23 function A() {} 22 function A() {}
24 A.prototype.$isThing = true; 23 A.prototype.$isThing = true;
25 make1 = function(){return new A;}; 24 make1 = function(){return new A;};
26 make2 = function(){return {$isThing: true}}; 25 make2 = function(){return {$isThing: true}};
27 function NT() {} 26 function NT() {}
28 NT.prototype.$isThing = true; 27 NT.prototype.$isThing = true;
29 make3 = function(){return new NT;}; 28 make3 = function(){return new NT;};
29
30 self.nativeConstructor(NT);
30 """; 31 """;
31 32
32 var inscrutable;
33 main() { 33 main() {
34 nativeTesting();
34 setup(); 35 setup();
35 inscrutable = (x) => x;
36 36
37 var a = new Thing(); 37 var a = new Thing();
38 var b = make1(); 38 var b = make1();
39 var c = make2(); 39 var c = make2();
40 var d = make3(); 40 var d = make3();
41 Expect.isTrue(inscrutable(a) is Thing); 41 Expect.isTrue(confuse(a) is Thing);
42 Expect.isFalse(inscrutable(b) is Thing); 42 Expect.isFalse(confuse(b) is Thing);
43 Expect.isFalse(inscrutable(c) is Thing); 43 Expect.isFalse(confuse(c) is Thing);
44 Expect.isFalse(inscrutable(d) is Thing); 44 Expect.isFalse(confuse(d) is Thing);
45 } 45 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js_native/event_loop_test.dart ('k') | tests/compiler/dart2js_native/field_type2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698