Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 library bindings_test; | 5 library bindings_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 | 9 |
| 10 import 'package:observe/observe.dart'; | 10 import 'package:observe/observe.dart'; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 }); | 75 }); |
| 76 return completer.future; | 76 return completer.future; |
| 77 }); | 77 }); |
| 78 | 78 |
| 79 test('should preserve the cursor position', () { | 79 test('should preserve the cursor position', () { |
| 80 var model = new NotifyModel('abcde'); | 80 var model = new NotifyModel('abcde'); |
| 81 var template = templateBind(new Element.html( | 81 var template = templateBind(new Element.html( |
| 82 '<template><input id="i1" value={{x}}></template>')); | 82 '<template><input id="i1" value={{x}}></template>')); |
| 83 testDiv.append(template.createInstance(model, new PolymerExpressions())); | 83 testDiv.append(template.createInstance(model, new PolymerExpressions())); |
| 84 | 84 |
| 85 var el; | |
| 85 return new Future(() { | 86 return new Future(() { |
| 86 var el = testDiv.query("#i1"); | 87 el = testDiv.query("#i1"); |
| 87 var subscription = el.onInput.listen(expectAsync((_) {}, count: 1)); | 88 var subscription = el.onInput.listen(expectAsync((_) {}, count: 1)); |
| 88 el.focus(); | 89 el.focus(); |
| 89 | 90 |
| 90 expect(el.value, 'abcde'); | 91 expect(el.value, 'abcde'); |
| 91 expect(model.x, 'abcde'); | 92 expect(model.x, 'abcde'); |
| 92 | 93 |
| 93 el.selectionStart = 3; | 94 el.selectionStart = 3; |
| 94 el.selectionEnd = 3; | 95 el.selectionEnd = 3; |
| 95 expect(el.selectionStart, 3); | 96 expect(el.selectionStart, 3); |
| 96 expect(el.selectionEnd, 3); | 97 expect(el.selectionEnd, 3); |
| 97 | 98 |
| 98 el.value = 'abc de'; | 99 el.value = 'abc de'; |
| 99 // Updating the input value programatically (even to the same value in | 100 // Updating the input value programatically (even to the same value in |
| 100 // Chrome) loses the selection position. | 101 // Chrome) loses the selection position. |
| 101 expect(el.selectionStart, 6); | 102 expect(el.selectionStart, 6); |
| 102 expect(el.selectionEnd, 6); | 103 expect(el.selectionEnd, 6); |
| 103 | 104 |
| 104 el.selectionStart = 4; | 105 el.selectionStart = 4; |
| 105 el.selectionEnd = 4; | 106 el.selectionEnd = 4; |
| 106 | 107 |
| 107 expect(model.x, 'abcde'); | 108 expect(model.x, 'abcde'); |
| 108 el.dispatchEvent(new Event('input')); | 109 el.dispatchEvent(new Event('input')); |
| 109 expect(model.x, 'abc de'); | 110 expect(model.x, 'abc de'); |
| 110 expect(el.value, 'abc de'); | 111 expect(el.value, 'abc de'); |
| 111 | 112 |
| 112 // But propagating observable values through reassign the value and | 113 // But propagating observable values through reassign the value and |
| 113 // selection will be preserved. | 114 // selection will be preserved. |
| 114 expect(el.selectionStart, 4); | 115 expect(el.selectionStart, 4); |
| 115 expect(el.selectionEnd, 4); | 116 expect(el.selectionEnd, 4); |
| 116 | |
| 117 subscription.cancel(); | 117 subscription.cancel(); |
| 118 }).then(_nextMicrotask).then((_) { | |
|
Jennifer Messerly
2014/05/07 19:30:46
fyi -- I wonder if we should use requestAnimationF
Siggi Cherem (dart-lang)
2014/05/07 19:58:15
Good idea. PTAL
| |
| 119 expect(el.selectionStart, 4); | |
| 120 expect(el.selectionEnd, 4); | |
| 118 }); | 121 }); |
| 119 }); | 122 }); |
| 120 | 123 |
| 121 | 124 |
| 122 test('detects changes to ObservableMap keys/values', () { | 125 test('detects changes to ObservableMap keys/values', () { |
| 123 var map = new ObservableMap.from({'a': 1, 'b': 2}); | 126 var map = new ObservableMap.from({'a': 1, 'b': 2}); |
| 124 var template = templateBind(new Element.html('<template>' | 127 var template = templateBind(new Element.html('<template>' |
| 125 '<template repeat="{{k in x.keys}}">{{k}}:{{x[k]}},</template>' | 128 '<template repeat="{{k in x.keys}}">{{k}}:{{x[k]}},</template>' |
| 126 '</template>')); | 129 '</template>')); |
| 127 var model = new NotifyModel(map); | 130 var model = new NotifyModel(map); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 146 @reflectable | 149 @reflectable |
| 147 class NotifyModel extends ChangeNotifier { | 150 class NotifyModel extends ChangeNotifier { |
| 148 var _x; | 151 var _x; |
| 149 NotifyModel([this._x]); | 152 NotifyModel([this._x]); |
| 150 | 153 |
| 151 get x => _x; | 154 get x => _x; |
| 152 set x(value) { | 155 set x(value) { |
| 153 _x = notifyPropertyChange(#x, _x, value); | 156 _x = notifyPropertyChange(#x, _x, value); |
| 154 } | 157 } |
| 155 } | 158 } |
| OLD | NEW |