OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <!-- | 2 <!-- |
3 Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 3 Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
4 for details. All rights reserved. Use of this source code is governed by a | 4 for details. All rights reserved. Use of this source code is governed by a |
5 BSD-style license that can be found in the LICENSE file. | 5 BSD-style license that can be found in the LICENSE file. |
6 --> | 6 --> |
7 <html lang="en"> | 7 <html lang="en"> |
8 <head> | 8 <head> |
9 <meta charset="utf-8"> | 9 <meta charset="utf-8"> |
10 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | 10 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
11 <title>watch_global_var_test</title> | |
12 <script type='application/javascript' src="testing.js"></script> | 11 <script type='application/javascript' src="testing.js"></script> |
13 </head> | 12 </head> |
14 <body> | 13 <body> |
15 <element name="x-my-input" extends="input"> | 14 <element name="x-my-input" extends="input"> |
16 <template></template> | 15 <template></template> |
17 <script type="application/dart"> | 16 <script type="application/dart"> |
18 import 'package:web_ui/web_ui.dart'; | 17 import 'package:web_ui/web_ui.dart'; |
19 class MyInput extends WebComponent { | 18 class MyInput extends WebComponent { |
20 int clicked; | 19 int clicked; |
21 created() { | 20 created() { |
(...skipping 11 matching lines...) Expand all Loading... |
33 Foo! | 32 Foo! |
34 <input is="x-my-input" name="a" type="radio" value="Bar" bind-value="name"> | 33 <input is="x-my-input" name="a" type="radio" value="Bar" bind-value="name"> |
35 Bar! | 34 Bar! |
36 </form> | 35 </form> |
37 <pre>You picked {{name}}. Final value should be 'Bar'</pre> | 36 <pre>You picked {{name}}. Final value should be 'Bar'</pre> |
38 <script type="application/dart"> | 37 <script type="application/dart"> |
39 import 'dart:html'; | 38 import 'dart:html'; |
40 import 'package:web_ui/web_ui.dart'; | 39 import 'package:web_ui/web_ui.dart'; |
41 import 'package:unittest/unittest.dart'; | 40 import 'package:unittest/unittest.dart'; |
42 | 41 |
43 var name = 'Bar'; | 42 @observable var name = 'Bar'; |
44 var foo = queryAll('input')[0]; | 43 final foo = queryAll('input')[0]; |
45 var bar = queryAll('input')[1]; | 44 final bar = queryAll('input')[1]; |
46 | 45 |
47 main() { | 46 main() { |
48 useShadowDom = false; | 47 useShadowDom = false; |
49 | 48 |
50 expect(foo.checked, false, reason: 'watchers not run yet.'); | 49 expect(foo.checked, false, reason: 'watchers not run yet.'); |
51 expect(bar.checked, false, reason: 'watchers not run yet.'); | 50 expect(bar.checked, false, reason: 'watchers not run yet.'); |
52 | 51 |
53 window.setTimeout(() { | 52 window.setTimeout(() { |
54 expect(foo.checked, false, reason: 'bar picked.'); | 53 expect(foo.checked, false, reason: 'bar picked.'); |
55 expect(bar.checked, true, reason: 'bar picked.'); | 54 expect(bar.checked, true, reason: 'bar picked.'); |
56 expect(name, 'Bar'); | 55 expect(name, 'Bar'); |
57 | 56 |
58 name = 'Nothing'; | 57 name = 'Nothing'; |
59 dispatch(); | 58 deliverChangesSync(); |
60 expect(foo.checked, false, reason: 'nothing picked.'); | 59 expect(foo.checked, false, reason: 'nothing picked.'); |
61 expect(bar.checked, false, reason: 'nothing picked.'); | 60 expect(bar.checked, false, reason: 'nothing picked.'); |
62 expect(name, 'Nothing'); | 61 expect(name, 'Nothing'); |
63 | 62 |
64 name = 'Foo'; | 63 name = 'Foo'; |
65 dispatch(); | 64 deliverChangesSync(); |
66 expect(foo.checked, true, reason: 'foo picked.'); | 65 expect(foo.checked, true, reason: 'foo picked.'); |
67 expect(bar.checked, false, reason: 'foo picked.'); | 66 expect(bar.checked, false, reason: 'foo picked.'); |
68 expect(name, 'Foo'); | 67 expect(name, 'Foo'); |
69 | 68 |
70 expect(foo.xtag.clicked, 0); | 69 expect(foo.xtag.clicked, 0); |
71 expect(bar.xtag.clicked, 0); | 70 expect(bar.xtag.clicked, 0); |
72 bar.dispatchEvent(new MouseEvent('click', detail: 1)); | 71 bar.dispatchEvent(new MouseEvent('click', detail: 1)); |
73 expect(name, 'Bar', reason: 'bar clicked.'); | 72 expect(name, 'Bar', reason: 'bar clicked.'); |
74 expect(foo.checked, false, reason: 'bar clicked.'); | 73 expect(foo.checked, false, reason: 'bar clicked.'); |
75 expect(bar.checked, true, reason: 'bar clicked.'); | 74 expect(bar.checked, true, reason: 'bar clicked.'); |
76 expect(foo.xtag.clicked, 0); | 75 expect(foo.xtag.clicked, 0); |
77 expect(bar.xtag.clicked, 1); | 76 expect(bar.xtag.clicked, 1); |
78 | 77 |
79 foo.checked = true; | 78 foo.checked = true; |
80 expect(bar.checked, false, reason: 'only one can be checked.'); | 79 expect(bar.checked, false, reason: 'only one can be checked.'); |
81 expect(foo.checked, true, reason: 'explicitly set this.'); | 80 expect(foo.checked, true, reason: 'explicitly set this.'); |
82 // It would be nice if this was "Foo". | 81 // It would be nice if this was "Foo". |
83 expect(name, 'Bar', reason: 'DOM checked does not fire event.'); | 82 expect(name, 'Bar', reason: 'DOM checked does not fire event.'); |
84 | 83 |
85 window.setTimeout(() => window.postMessage('done', '*'), 0); | 84 window.setImmediate(() => window.postMessage('done', '*')); |
86 }, 0); | 85 }, 0); |
87 } | 86 } |
88 </script> | 87 </script> |
89 </body> | 88 </body> |
90 </html> | 89 </html> |
OLD | NEW |