OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 | |
6 // Test that the proper one-shot interceptor is used for different | 5 // Test that the proper one-shot interceptor is used for different |
7 // combinations of named arguments. | 6 // combinations of named arguments. |
8 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
9 | 8 |
10 // Use dart:html to get interceptors into play. | 9 // Use dart:html to get interceptors into play. |
11 import "dart:html"; | 10 import "dart:html"; |
12 | 11 |
13 // [createFragment] has the same signature as in [Element]. | 12 // [createFragment] has the same signature as in [Element]. |
14 class Other { | 13 class Other { |
15 createFragment(html, {validator, treeSanitizer}) { | 14 createFragment(html, {validator, treeSanitizer}) { |
16 int result = 0; | 15 int result = 0; |
17 result += validator == null ? 0 : 2; | 16 result += validator == null ? 0 : 2; |
18 result += treeSanitizer == null ? 0 : 1; | 17 result += treeSanitizer == null ? 0 : 1; |
19 return result; | 18 return result; |
20 } | 19 } |
21 } | 20 } |
22 | 21 |
23 @NoInline() | 22 @NoInline() |
24 bool wontTell(bool x) => x; | 23 bool wontTell(bool x) => x; |
25 | 24 |
26 | |
27 // Ensure that we use the interceptor only once per context so that we | 25 // Ensure that we use the interceptor only once per context so that we |
28 // actually get a one-shot interceptor. This is a little brittle... | 26 // actually get a one-shot interceptor. This is a little brittle... |
29 @NoInline() | 27 @NoInline() |
30 testA(thing) { | 28 testA(thing) { |
31 Expect.equals(0, thing.createFragment(null)); | 29 Expect.equals(0, thing.createFragment(null)); |
32 } | 30 } |
33 | 31 |
34 @NoInline() | 32 @NoInline() |
35 testB(thing) { | 33 testB(thing) { |
36 Expect.equals(2, thing.createFragment(null, validator: 1)); | 34 Expect.equals(2, thing.createFragment(null, validator: 1)); |
37 } | 35 } |
38 | 36 |
39 @NoInline() | 37 @NoInline() |
40 testC(thing) { | 38 testC(thing) { |
41 Expect.equals(1, thing.createFragment(null, treeSanitizer: 1)); | 39 Expect.equals(1, thing.createFragment(null, treeSanitizer: 1)); |
42 } | 40 } |
43 | 41 |
44 @NoInline() | 42 @NoInline() |
45 testD(thing) { | 43 testD(thing) { |
46 Expect.equals(3, thing.createFragment(null, validator: 1, treeSanitizer: 1)); | 44 Expect.equals(3, thing.createFragment(null, validator: 1, treeSanitizer: 1)); |
47 } | 45 } |
48 | 46 |
49 main () { | 47 main() { |
50 // Ensure we get interceptors into play. | 48 // Ensure we get interceptors into play. |
51 var thing = wontTell(true) ? new Other() : new DivElement(); | 49 var thing = wontTell(true) ? new Other() : new DivElement(); |
52 testA(thing); | 50 testA(thing); |
53 testB(thing); | 51 testB(thing); |
54 testC(thing); | 52 testC(thing); |
55 testD(thing); | 53 testD(thing); |
56 } | 54 } |
OLD | NEW |