Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library bindings_test; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'dart:html'; | |
| 9 import 'package:mdv/mdv.dart' as mdv; | |
| 10 import 'package:observe/observe.dart'; | |
| 11 import 'package:observe/src/microtask.dart'; | |
| 12 import 'package:polymer_expressions/polymer_expressions.dart'; | |
| 13 import 'package:unittest/html_config.dart'; | |
| 14 import 'package:unittest/unittest.dart'; | |
| 15 | |
| 16 main() { | |
| 17 mdv.initialize(); | |
| 18 useHtmlConfiguration(); | |
| 19 | |
| 20 group('cursor position tests', () { | |
| 21 var testDiv; | |
| 22 setUp(() { | |
| 23 document.body.append(testDiv = new DivElement()); | |
| 24 }); | |
| 25 | |
| 26 tearDown(() { | |
| 27 testDiv.remove(); | |
| 28 testDiv = null; | |
| 29 }); | |
| 30 | |
| 31 test('cursor position test', wrapMicrotask(() { | |
| 32 var model = new NotifyModel('abcde'); | |
| 33 var template = new Element.html( | |
| 34 '<template><input id="i1" value={{x}}></template>'); | |
| 35 testDiv.append(template.createInstance(model, new PolymerExpressions())); | |
| 36 | |
| 37 performMicrotaskCheckpoint(); | |
| 38 var el = testDiv.query("#i1"); | |
| 39 var subscription = el.onInput.listen(expectAsync1((_) { | |
| 40 performMicrotaskCheckpoint(); | |
| 41 }, count: 1)); | |
| 42 el.focus(); | |
| 43 | |
| 44 expect(el.value, 'abcde'); | |
| 45 expect(model.x, 'abcde'); | |
| 46 | |
| 47 el.selectionStart = 3; | |
| 48 el.selectionEnd = 3; | |
| 49 expect(el.selectionStart, 3); | |
| 50 expect(el.selectionEnd, 3); | |
| 51 | |
| 52 el.value = 'abc de'; | |
| 53 // Updating the input value programatically (even to the same value in | |
| 54 // Chrome) loses the selection position. | |
| 55 expect(el.selectionStart, 6); | |
| 56 expect(el.selectionEnd, 6); | |
| 57 | |
| 58 el.selectionStart = 4; | |
| 59 el.selectionEnd = 4; | |
| 60 | |
| 61 expect(model.x, 'abcde'); | |
| 62 el.dispatchEvent(new Event('input')); | |
| 63 expect(model.x, 'abc de'); | |
| 64 expect(el.value, 'abc de'); | |
| 65 | |
| 66 // But propagating observable values through reassign the value and | |
| 67 // selection will be preserved. | |
| 68 expect(el.selectionStart, 4); | |
|
Siggi Cherem (dart-lang)
2013/10/10 00:49:48
without the fix, this returns 6.
| |
| 69 expect(el.selectionEnd, 4); | |
| 70 | |
| 71 subscription.cancel(); | |
| 72 })); | |
| 73 }); | |
| 74 } | |
| 75 | |
| 76 class NotifyModel extends ChangeNotifierBase { | |
| 77 var _x; | |
| 78 NotifyModel([this._x]); | |
| 79 | |
| 80 get x => _x; | |
| 81 set x(value) { | |
| 82 _x = notifyPropertyChange(const Symbol('x'), _x, value); | |
| 83 } | |
| 84 } | |
| OLD | NEW |