| <html> |
| <head> |
| <script src="../../http/tests/inspector/inspector-test.js"></script> |
| <script src="editor-test.js"></script> |
| <script> |
| function codeSnippet() { |
| return document.getElementById("codeSnippet").textContent; |
| } |
| |
| function test() |
| { |
| var textEditor = InspectorTest.createTestEditor(); |
| textEditor.setMimeType("text/javascript"); |
| textEditor.setReadOnly(false); |
| textEditor.element.focus(); |
| InspectorTest.evaluateInPage("codeSnippet();", onCodeSnippet); |
| |
| function onCodeSnippet(result) |
| { |
| var codeLines = result.value; |
| textEditor.setText(codeLines); |
| InspectorTest.runTestSuite(testSuite); |
| } |
| |
| function nextOccurrence(times) |
| { |
| for (var i = 0; i < times; ++i) |
| textEditor._selectNextOccurrenceController.selectNextOccurrence(); |
| } |
| |
| function undoLastSelection() |
| { |
| textEditor._selectNextOccurrenceController.undoLastSelection(); |
| } |
| |
| function lineSelection(line, from, to) |
| { |
| if (typeof to !== "number") |
| to = from; |
| InspectorTest.setLineSelections(textEditor, [ |
| { line: line, from: from, to: to } |
| ]); |
| } |
| |
| var testSuite = [ |
| function testCursorInTheWordStart(next) |
| { |
| lineSelection(8, 0); |
| nextOccurrence(1); |
| InspectorTest.dumpSelectionStats(textEditor); |
| next(); |
| }, |
| |
| function testCursorInTheWordEnd(next) |
| { |
| lineSelection(8, 8); |
| nextOccurrence(1); |
| InspectorTest.dumpSelectionStats(textEditor); |
| next(); |
| }, |
| |
| function testNonWordSelection(next) |
| { |
| lineSelection(18, 12, 14); |
| nextOccurrence(8); |
| InspectorTest.dumpSelectionStats(textEditor); |
| next(); |
| }, |
| |
| function testNonWordSelection2(next) |
| { |
| lineSelection(17, 30, 33); |
| nextOccurrence(8); |
| InspectorTest.dumpSelectionStats(textEditor); |
| next(); |
| }, |
| |
| function testNonWordSelection3(next) |
| { |
| InspectorTest.setLineSelections(textEditor, [ |
| { line: 14, from: 15, to: 25 }, |
| { line: 16, column: 21 }, |
| { line: 17, from: 42, to: 47 }, |
| ]); |
| var selections = textEditor.selections(); |
| nextOccurrence(3); |
| InspectorTest.dumpSelectionStats(textEditor); |
| next(); |
| }, |
| |
| function testNonWordSelection4(next) |
| { |
| InspectorTest.setLineSelections(textEditor, [ |
| { line: 14, from: 15, to: 25 }, |
| { line: 16, from: 21, to: 23 }, |
| { line: 17, from: 42, to: 47 }, |
| ]); |
| var selections = textEditor.selections(); |
| nextOccurrence(3); |
| InspectorTest.dumpSelectionStats(textEditor); |
| next(); |
| }, |
| |
| function testTriggerWordSearchInMixedCase(next) |
| { |
| InspectorTest.setLineSelections(textEditor, [ |
| { line: 9, from: 10, to: 25 }, |
| { line: 14, column: 33 } |
| ]); |
| nextOccurrence(5); |
| InspectorTest.dumpSelectionStats(textEditor); |
| next(); |
| }, |
| ]; |
| } |
| |
| </script> |
| </head> |
| |
| <body onload="runTest();"> |
| <p> |
| This test verifies Ctrl-D functionality, which selects next occurrence of word. |
| </p> |
| |
| <pre id="codeSnippet"> |
| function wordData() { |
| return { |
| original: $(".entry.original > .input").text(), |
| translation: $(".entry.translation > .input").text(), |
| tags: $(".active-tags > .tagcloud > .tag").toArray().map(function(value) { return value.textContent; }) |
| }; |
| } |
| |
| function submitWord(url) { |
| var stub = new App.Stub($(".content")); |
| $.post(url, wordData()) |
| .done(function() { |
| var callback = $("meta[data-callback]").attr("data-callback"); |
| if (callback) { |
| window.location = callback; |
| } else { |
| stub.success(); |
| $(".entry.original > .input").text("").focus(); |
| $(".entry.translation > .input").text(""); |
| } |
| }) |
| .fail(function(obj, err, errDescr) { |
| stub.failure("Error: " + errDescr); |
| }) |
| } |
| </pre> |
| |
| </body> |
| </html> |