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

Side by Side Diff: tests/compiler/dart2js_native/browser_compat_1_prepatched_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 //import 'dart:_foreign_helper' show JS;
8 //import 'dart:_js_helper' show Creates, setNativeSubclassDispatchRecord;
9 6
10 // Test for dartNativeDispatchHooksTransformer, getTag hook. 7 // Test for dartNativeDispatchHooksTransformer, getTag hook.
11 8
12 @Native("T1A") 9 @Native("T1A")
13 class T1A {} 10 class T1A {}
14 11
15 @Native("T1B") 12 @Native("T1B")
16 class T1B {} 13 class T1B {}
17 14
18 @Native("T1C") 15 @Native("T1C")
(...skipping 16 matching lines...) Expand all
35 32
36 // Make constructors visible on 'window' for prepatching. 33 // Make constructors visible on 'window' for prepatching.
37 if (typeof window == "undefined") window = {} 34 if (typeof window == "undefined") window = {}
38 window.T1A = T1A; 35 window.T1A = T1A;
39 window.T1CrazyB = T1CrazyB; 36 window.T1CrazyB = T1CrazyB;
40 37
41 makeT1A = function(){return new T1A;}; 38 makeT1A = function(){return new T1A;};
42 makeT1B = function(){return new T1CrazyB;}; 39 makeT1B = function(){return new T1CrazyB;};
43 makeT1C = function(){return new T1fakeA;}; 40 makeT1C = function(){return new T1fakeA;};
44 41
42 self.nativeConstructor(T1A);
43 self.nativeConstructor(T1CrazyB);
44 self.nativeConstructor(T1fakeA);
45
45 var getTagCount = 0; 46 var getTagCount = 0;
46 getTagCallCount = function() { return getTagCount; } 47 getTagCallCount = function() { return getTagCount; }
47 48
48 function transformer1(hooks) { 49 function transformer1(hooks) {
49 var getTag = hooks.getTag; 50 var getTag = hooks.getTag;
50 51
51 function getTagNew(obj) { 52 function getTagNew(obj) {
52 ++getTagCount; 53 ++getTagCount;
53 54
54 // If something looks like a different native type we can check in advance 55 // If something looks like a different native type we can check in advance
55 // of the default algorithm. 56 // of the default algorithm.
56 if (obj instanceof T1fakeA) return "T1C"; 57 if (obj instanceof T1fakeA) return "T1C";
57 58
58 var tag = getTag(obj); 59 var tag = getTag(obj);
59 60
60 // New constructor names can be mapped here. 61 // New constructor names can be mapped here.
61 if (tag == "T1CrazyB") return "T1B"; 62 if (tag == "T1CrazyB") return "T1B";
62 63
63 return tag; 64 return tag;
64 } 65 }
65 66
66 hooks.getTag = getTagNew; 67 hooks.getTag = getTagNew;
67 } 68 }
68 69
69 dartNativeDispatchHooksTransformer = [transformer1]; 70 dartNativeDispatchHooksTransformer = [transformer1];
70 '''; 71 ''';
71 72
72 var inscrutable;
73
74 main() { 73 main() {
74 nativeTesting();
75 setup(); 75 setup();
76 inscrutable = (x) => x;
77 76
78 var t1a = makeT1A(); 77 var t1a = makeT1A();
79 var t1b = makeT1B(); 78 var t1b = makeT1B();
80 var t1c = makeT1C(); 79 var t1c = makeT1C();
81 80
82 Expect.equals(true, t1a is T1A, '$t1a is T1A'); 81 Expect.equals(true, t1a is T1A, '$t1a is T1A');
83 Expect.equals(true, t1b is T1B, '$t1b is T1B'); 82 Expect.equals(true, t1b is T1B, '$t1b is T1B');
84 Expect.equals(true, t1c is T1C, '$t1c is T1C'); 83 Expect.equals(true, t1c is T1C, '$t1c is T1C');
85 84
86 Expect.equals(2, getTagCallCount()); 85 Expect.equals(2, getTagCallCount());
87 86
88 Expect.equals(true, inscrutable(t1a) is T1A, '$t1a is T1A'); 87 Expect.equals(true, confuse(t1a) is T1A, '$t1a is T1A');
89 Expect.equals(true, inscrutable(t1b) is T1B, '$t1b is T1B'); 88 Expect.equals(true, confuse(t1b) is T1B, '$t1b is T1B');
90 Expect.equals(true, inscrutable(t1c) is T1C, '$t1c is T1C'); 89 Expect.equals(true, confuse(t1c) is T1C, '$t1c is T1C');
91 90
92 Expect.equals(2, getTagCallCount()); 91 Expect.equals(2, getTagCallCount());
93 } 92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698