| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <script src="../../http/tests/inspector/inspector-test.js"></script> | 3 <script src="../../http/tests/inspector/inspector-test.js"></script> |
| 4 <script src="editor-test.js"></script> | 4 <script src="editor-test.js"></script> |
| 5 <script> | 5 <script> |
| 6 function codeSnippet() { | 6 function codeSnippet() { |
| 7 return document.getElementById("codeSnippet").textContent; | 7 return document.getElementById("codeSnippet").textContent; |
| 8 } | 8 } |
| 9 | 9 |
| 10 function test() | 10 function test() |
| 11 { | 11 { |
| 12 var textEditor = InspectorTest.createTestEditor(); | 12 var textEditor = InspectorTest.createTestEditor(); |
| 13 textEditor.setMimeType("text/javascript"); | 13 textEditor.setMimeType("text/javascript"); |
| 14 textEditor.setReadOnly(false); | 14 textEditor.setReadOnly(true); |
| 15 textEditor.element.focus(); | 15 textEditor.element.focus(); |
| 16 InspectorTest.evaluateInPage("codeSnippet();", onCodeSnippet); | 16 InspectorTest.evaluateInPage("codeSnippet();", onCodeSnippet); |
| 17 | 17 |
| 18 var codeLines; |
| 19 |
| 18 function onCodeSnippet(result) | 20 function onCodeSnippet(result) |
| 19 { | 21 { |
| 20 var codeLines = result.value; | 22 codeLines = result.value; |
| 21 textEditor.setText(codeLines); | 23 textEditor.setText(codeLines); |
| 22 InspectorTest.runTestSuite(testSuite); | 24 InspectorTest.runTestSuite(testSuite); |
| 23 } | 25 } |
| 24 | 26 |
| 25 function nextOccurrence(times) | 27 function nextOccurrence(times) |
| 26 { | 28 { |
| 27 for (var i = 0; i < times; ++i) | 29 for (var i = 0; i < times; ++i) |
| 28 textEditor._selectNextOccurrenceController.selectNextOccurrence(); | 30 InspectorTest.fakeKeyEvent(textEditor, "D", ["ctrlKey"]); |
| 29 } | 31 } |
| 30 | 32 |
| 31 function undoLastSelection() | 33 function undoLastSelection(times) |
| 32 { | 34 { |
| 33 textEditor._selectNextOccurrenceController.undoLastSelection(); | 35 for (var i = 0; i < times; ++i) |
| 36 InspectorTest.fakeKeyEvent(textEditor, "U", ["ctrlKey"]); |
| 34 } | 37 } |
| 35 | 38 |
| 36 function lineSelection(line, from, to) | 39 function lineSelection(line, from, to) |
| 37 { | 40 { |
| 38 if (typeof to !== "number") | 41 if (typeof to !== "number") |
| 39 to = from; | 42 to = from; |
| 40 InspectorTest.setLineSelections(textEditor, [ | 43 InspectorTest.setLineSelections(textEditor, [ |
| 41 { line: line, from: from, to: to } | 44 { line: line, from: from, to: to } |
| 42 ]); | 45 ]); |
| 43 } | 46 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 64 lineSelection(2, 13); | 67 lineSelection(2, 13); |
| 65 nextOccurrence(3); | 68 nextOccurrence(3); |
| 66 InspectorTest.dumpSelectionStats(textEditor); | 69 InspectorTest.dumpSelectionStats(textEditor); |
| 67 next(); | 70 next(); |
| 68 }, | 71 }, |
| 69 | 72 |
| 70 function testUndoLastAddedSelection(next) | 73 function testUndoLastAddedSelection(next) |
| 71 { | 74 { |
| 72 lineSelection(2, 13); | 75 lineSelection(2, 13); |
| 73 nextOccurrence(3); | 76 nextOccurrence(3); |
| 74 undoLastSelection(); | 77 undoLastSelection(1); |
| 75 InspectorTest.dumpSelectionStats(textEditor); | 78 InspectorTest.dumpSelectionStats(textEditor); |
| 76 next(); | 79 next(); |
| 77 }, | 80 }, |
| 81 |
| 82 function testUndoAllAddedSelections(next) |
| 83 { |
| 84 lineSelection(2, 13); |
| 85 nextOccurrence(3); |
| 86 undoLastSelection(3); |
| 87 InspectorTest.dumpSelectionStats(textEditor); |
| 88 next(); |
| 89 }, |
| 90 |
| 91 function testUndoToPreviousSelectionGroup(next) |
| 92 { |
| 93 lineSelection(2, 13); |
| 94 nextOccurrence(2); |
| 95 lineSelection(2, 51); |
| 96 nextOccurrence(2); |
| 97 undoLastSelection(4); |
| 98 InspectorTest.dumpSelectionStats(textEditor); |
| 99 next(); |
| 100 }, |
| 78 | 101 |
| 79 function testUndoSelectionPreservesFullWordState(next) | 102 function testUndoSelectionPreservesFullWordState(next) |
| 80 { | 103 { |
| 81 lineSelection(2, 51); | 104 lineSelection(2, 51); |
| 82 nextOccurrence(3); | 105 nextOccurrence(3); |
| 83 undoLastSelection(); | 106 undoLastSelection(1); |
| 84 nextOccurrence(1); | 107 nextOccurrence(1); |
| 85 InspectorTest.dumpSelectionStats(textEditor); | 108 InspectorTest.dumpSelectionStats(textEditor); |
| 86 var lastSelection = textEditor.selections().pop(); | 109 var lastSelection = textEditor.selections().pop(); |
| 87 InspectorTest.addResult("Last selection: " + lastSelection.toString(
)); | 110 InspectorTest.addResult("Last selection: " + lastSelection.toString(
)); |
| 88 next(); | 111 next(); |
| 89 }, | 112 }, |
| 90 | 113 |
| 91 function testUndoSelectionPreservesPartialSelection(next) | 114 function testUndoSelectionPreservesPartialSelection(next) |
| 92 { | 115 { |
| 93 lineSelection(2, 48, 52); | 116 lineSelection(2, 48, 52); |
| 94 nextOccurrence(2); | 117 nextOccurrence(2); |
| 95 undoLastSelection(); | 118 undoLastSelection(1); |
| 96 nextOccurrence(1); | 119 nextOccurrence(1); |
| 97 InspectorTest.dumpSelectionStats(textEditor); | 120 InspectorTest.dumpSelectionStats(textEditor); |
| 98 var lastSelection = textEditor.selections().pop(); | 121 var lastSelection = textEditor.selections().pop(); |
| 99 InspectorTest.addResult("Last selection: " + lastSelection.toString(
)); | 122 InspectorTest.addResult("Last selection: " + lastSelection.toString(
)); |
| 100 next(); | 123 next(); |
| 101 }, | 124 }, |
| 102 | 125 |
| 103 function testTwoCloseWords(next) | 126 function testTwoCloseWords(next) |
| 104 { | 127 { |
| 105 lineSelection(17, 45); | 128 lineSelection(17, 45); |
| 106 nextOccurrence(5); | 129 nextOccurrence(5); |
| 107 InspectorTest.dumpSelectionStats(textEditor); | 130 InspectorTest.dumpSelectionStats(textEditor); |
| 108 next(); | 131 next(); |
| 109 }, | 132 }, |
| 133 |
| 134 function testReadOnlyIsPreserved(next) |
| 135 { |
| 136 lineSelection(2, 13); |
| 137 nextOccurrence(3); |
| 138 undoLastSelection(1); |
| 139 InspectorTest.fakeKeyEvent(textEditor, "enter", []); |
| 140 |
| 141 InspectorTest.evaluateInPage("codeSnippet();", function(result) { |
| 142 |
| 143 InspectorTest.assertTrue(result.value === codeLines); |
| 144 InspectorTest.dumpSelectionStats(textEditor); |
| 145 next(); |
| 146 }); |
| 147 } |
| 110 ]; | 148 ]; |
| 111 } | 149 } |
| 112 | 150 |
| 113 </script> | 151 </script> |
| 114 </head> | 152 </head> |
| 115 | 153 |
| 116 <body onload="runTest();"> | 154 <body onload="runTest();"> |
| 117 <p> | 155 <p> |
| 118 This test verifies Ctrl-D functionality, which selects next occurrence of word. | 156 This test verifies Ctrl-D functionality, which selects next occurrence of word,
and Ctrl-U functionality, which undos the last selection. |
| 119 </p> | 157 </p> |
| 120 | 158 |
| 121 <pre id="codeSnippet"> | 159 <pre id="codeSnippet"> |
| 122 function wordData() { | 160 function wordData() { |
| 123 return { | 161 return { |
| 124 original: $(".entry.original > .input").text(), | 162 original: $(".entry.original > .input").text(), |
| 125 translation: $(".entry.translation > .input").text(), | 163 translation: $(".entry.translation > .input").text(), |
| 126 tags: $(".active-tags > .tagcloud > .tag").toArray().map(function(value)
{ return value.textContent; }) | 164 tags: $(".active-tags > .tagcloud > .tag").toArray().map(function(value)
{ return value.textContent; }) |
| 127 }; | 165 }; |
| 128 } | 166 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 141 } | 179 } |
| 142 }) | 180 }) |
| 143 .fail(function(obj, err, errDescr) { | 181 .fail(function(obj, err, errDescr) { |
| 144 stub.failure("Error: " + errDescr); | 182 stub.failure("Error: " + errDescr); |
| 145 }) | 183 }) |
| 146 } | 184 } |
| 147 </pre> | 185 </pre> |
| 148 | 186 |
| 149 </body> | 187 </body> |
| 150 </html> | 188 </html> |
| OLD | NEW |