| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // SharedOptions=--package-root=sdk/lib/_internal/ | 5 // SharedOptions=--package-root=sdk/lib/_internal/ |
| 6 | 6 |
| 7 // Test that cursor positions are correctly updated after adding new content. | 7 // Test that cursor positions are correctly updated after adding new content. |
| 8 | 8 |
| 9 import 'test_try.dart'; | 9 import 'test_try.dart'; |
| 10 | 10 |
| 11 void main() { | 11 void main() { |
| 12 InteractionManager interaction = mockTryDartInteraction(); | 12 InteractionManager interaction = mockTryDartInteraction(); |
| 13 | 13 |
| 14 TestCase twoLines = |
| 15 new TestCase('Test adding two lines programmatically.', () { |
| 16 clearEditorPaneWithoutNotifications(); |
| 17 mainEditorPane.appendText('\n\n'); |
| 18 Text text = mainEditorPane.firstChild; |
| 19 window.getSelection().collapse(text, 1); |
| 20 checkSelectionIsCollapsed(text, 1); |
| 21 }, checkAtBeginningOfSecondLine); |
| 22 |
| 14 runTests(<TestCase>[ | 23 runTests(<TestCase>[ |
| 24 twoLines, |
| 15 | 25 |
| 16 new TestCase('Test adding two lines programmatically.', () { | 26 new TestCase('Test adding a new text node.', () { |
| 17 clearEditorPaneWithoutNotifications(); | 27 // This test relies on the previous test leaving two lines. |
| 18 mainEditorPane.appendText('\n\n'); | 28 Text text = new Text('fisk'); |
| 19 Text text = mainEditorPane.firstChild; | 29 window.getSelection().getRangeAt(0).insertNode(text); |
| 20 window.getSelection().collapse(text, 1); | 30 window.getSelection().collapse(text, text.length); |
| 21 checkSelectionIsCollapsed(text, 1); | 31 checkSelectionIsCollapsed(text, text.length); |
| 22 }, checkAtBeginningOfSecondLine), | 32 }, checkAtEndOfSecondLineWithFisk), |
| 33 |
| 34 twoLines, |
| 35 |
| 36 new TestCase('Test adding a new wrapped text node.', () { |
| 37 // This test relies on the previous test leaving two lines. |
| 38 Text text = new Text('fisk'); |
| 39 Node node = new SpanElement()..append(text); |
| 40 window.getSelection().getRangeAt(0).insertNode(node); |
| 41 window.getSelection().collapse(text, text.length); |
| 42 checkSelectionIsCollapsed(text, text.length); |
| 43 }, checkAtEndOfSecondLineWithFisk), |
| 23 | 44 |
| 24 new TestCase('Test adding a new line with mock key event.', () { | 45 new TestCase('Test adding a new line with mock key event.', () { |
| 25 clearEditorPaneWithoutNotifications(); | 46 clearEditorPaneWithoutNotifications(); |
| 26 checkSelectionIsCollapsed(mainEditorPane, 0); | 47 checkSelectionIsCollapsed(mainEditorPane, 0); |
| 27 simulateEnterKeyDown(interaction); | 48 simulateEnterKeyDown(interaction); |
| 28 }, checkAtBeginningOfSecondLine), | 49 }, checkAtBeginningOfSecondLine), |
| 29 | 50 |
| 30 ]); | 51 ]); |
| 31 } | 52 } |
| 32 | 53 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 46 Expect.equals( | 67 Expect.equals( |
| 47 expectedLineCount, mainEditorPane.nodes.length, | 68 expectedLineCount, mainEditorPane.nodes.length, |
| 48 'mainEditorPane.nodes.length'); | 69 'mainEditorPane.nodes.length'); |
| 49 } | 70 } |
| 50 | 71 |
| 51 void checkAtBeginningOfSecondLine() { | 72 void checkAtBeginningOfSecondLine() { |
| 52 checkLineCount(2); | 73 checkLineCount(2); |
| 53 checkSelectionIsCollapsed(mainEditorPane.nodes[1].firstChild, 0); | 74 checkSelectionIsCollapsed(mainEditorPane.nodes[1].firstChild, 0); |
| 54 } | 75 } |
| 55 | 76 |
| 77 void checkAtEndOfSecondLineWithFisk() { |
| 78 checkLineCount(2); |
| 79 SpanElement secondLine = mainEditorPane.nodes[1]; |
| 80 Text text = secondLine.firstChild.firstChild; |
| 81 Expect.stringEquals('fisk', text.text); |
| 82 Expect.equals(4, text.length); |
| 83 Text newline = secondLine.firstChild.nextNode; |
| 84 Expect.equals(newline, secondLine.lastChild); |
| 85 checkSelectionIsCollapsed(newline, 0); |
| 86 } |
| 87 |
| 56 class MockKeyboardEvent extends KeyEvent { | 88 class MockKeyboardEvent extends KeyEvent { |
| 57 final int keyCode; | 89 final int keyCode; |
| 58 | 90 |
| 59 MockKeyboardEvent(String type, {int keyCode}) | 91 MockKeyboardEvent(String type, {int keyCode}) |
| 60 : this.keyCode = keyCode, | 92 : this.keyCode = keyCode, |
| 61 super.wrap(new KeyEvent(type, keyCode: keyCode)); | 93 super.wrap(new KeyEvent(type, keyCode: keyCode)); |
| 62 | 94 |
| 63 bool getModifierState(String keyArgument) => false; | 95 bool getModifierState(String keyArgument) => false; |
| 64 } | 96 } |
| OLD | NEW |