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 <form> | 14 <form> |
16 <input name="a" type="radio" value="Foo" bind-value="name">Foo! | 15 <input name="a" type="radio" value="Foo" bind-value="name">Foo! |
17 <input name="a" type="radio" value="Bar" bind-value="name">Bar! | 16 <input name="a" type="radio" value="Bar" bind-value="name">Bar! |
18 </form> | 17 </form> |
19 <pre>You picked {{name}}. Final value should be 'Bar'</pre> | 18 <pre>You picked {{name}}. Final value should be 'Bar'</pre> |
20 <script type="application/dart"> | 19 <script type="application/dart"> |
21 import 'dart:html'; | 20 import 'dart:html'; |
22 import 'package:web_ui/web_ui.dart'; | 21 import 'package:web_ui/web_ui.dart'; |
23 import 'package:unittest/unittest.dart'; | 22 import 'package:unittest/unittest.dart'; |
24 | 23 |
25 var name = 'Bar'; | 24 @observable var name = 'Bar'; |
26 var foo = queryAll('input')[0]; | 25 final foo = queryAll('input')[0]; |
27 var bar = queryAll('input')[1]; | 26 final bar = queryAll('input')[1]; |
28 | 27 |
29 main() { | 28 main() { |
30 useShadowDom = false; | 29 useShadowDom = false; |
31 | 30 |
32 expect(foo.checked, false, reason: 'watchers not run yet.'); | 31 expect(foo.checked, false, reason: 'watchers not run yet.'); |
33 expect(bar.checked, false, reason: 'watchers not run yet.'); | 32 expect(bar.checked, false, reason: 'watchers not run yet.'); |
34 | 33 |
35 window.setTimeout(() { | 34 window.setTimeout(() { |
36 expect(foo.checked, false, reason: 'bar picked.'); | 35 expect(foo.checked, false, reason: 'bar picked.'); |
37 expect(bar.checked, true, reason: 'bar picked.'); | 36 expect(bar.checked, true, reason: 'bar picked.'); |
38 expect(name, 'Bar'); | 37 expect(name, 'Bar'); |
39 | 38 |
40 name = 'Nothing'; | 39 name = 'Nothing'; |
41 dispatch(); | 40 deliverChangesSync(); |
42 expect(foo.checked, false, reason: 'nothing picked.'); | 41 expect(foo.checked, false, reason: 'nothing picked.'); |
43 expect(bar.checked, false, reason: 'nothing picked.'); | 42 expect(bar.checked, false, reason: 'nothing picked.'); |
44 expect(name, 'Nothing'); | 43 expect(name, 'Nothing'); |
45 | 44 |
46 name = 'Foo'; | 45 name = 'Foo'; |
47 dispatch(); | 46 deliverChangesSync(); |
48 expect(foo.checked, true, reason: 'foo picked.'); | 47 expect(foo.checked, true, reason: 'foo picked.'); |
49 expect(bar.checked, false, reason: 'foo picked.'); | 48 expect(bar.checked, false, reason: 'foo picked.'); |
50 expect(name, 'Foo'); | 49 expect(name, 'Foo'); |
51 | 50 |
52 bar.dispatchEvent(new MouseEvent('click', detail: 1)); | 51 bar.dispatchEvent(new MouseEvent('click', detail: 1)); |
53 expect(name, 'Bar', reason: 'bar clicked.'); | 52 expect(name, 'Bar', reason: 'bar clicked.'); |
54 expect(foo.checked, false, reason: 'bar clicked.'); | 53 expect(foo.checked, false, reason: 'bar clicked.'); |
55 expect(bar.checked, true, reason: 'bar clicked.'); | 54 expect(bar.checked, true, reason: 'bar clicked.'); |
56 | 55 |
57 foo.checked = true; | 56 foo.checked = true; |
58 expect(bar.checked, false, reason: 'only one can be checked.'); | 57 expect(bar.checked, false, reason: 'only one can be checked.'); |
59 expect(foo.checked, true, reason: 'explicitly set this.'); | 58 expect(foo.checked, true, reason: 'explicitly set this.'); |
60 // It would be nice if this was "Foo". | 59 // It would be nice if this was "Foo". |
61 expect(name, 'Bar', reason: 'DOM checked does not fire event.'); | 60 expect(name, 'Bar', reason: 'DOM checked does not fire event.'); |
62 | 61 |
63 window.setTimeout(() => window.postMessage('done', '*'), 0); | 62 window.setImmediate(() => window.postMessage('done', '*')); |
64 }, 0); | 63 }, 0); |
65 } | 64 } |
66 </script> | 65 </script> |
67 </body> | 66 </body> |
68 </html> | 67 </html> |
OLD | NEW |