| // Copyright 2017 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| (async function() { |
| TestRunner.addResult(`This test verifies Ctrl-D functionality, which selects next occurrence of word.\n`); |
| await TestRunner.loadModule('sources_test_runner'); |
| await TestRunner.showPanel('sources'); |
| await TestRunner.loadHTML(` |
| <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> |
| `); |
| await TestRunner.dumpInspectedPageElementText('#codeSnippet'); |
| await TestRunner.evaluateInPagePromise(` |
| function codeSnippet() { |
| return document.getElementById("codeSnippet").textContent; |
| } |
| `); |
| |
| var textEditor = SourcesTestRunner.createTestEditor(); |
| textEditor.setMimeType('text/javascript'); |
| textEditor.setReadOnly(false); |
| textEditor.element.focus(); |
| TestRunner.evaluateInPage('codeSnippet();', onCodeSnippet); |
| |
| function onCodeSnippet(result) { |
| var codeLines = result; |
| textEditor.setText(codeLines); |
| TestRunner.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; |
| SourcesTestRunner.setLineSelections(textEditor, [{line: line, from: from, to: to}]); |
| } |
| |
| var testSuite = [ |
| function testCursorInTheWordStart(next) { |
| lineSelection(8, 0); |
| nextOccurrence(1); |
| SourcesTestRunner.dumpSelectionStats(textEditor); |
| next(); |
| }, |
| |
| function testCursorInTheWordEnd(next) { |
| lineSelection(8, 8); |
| nextOccurrence(1); |
| SourcesTestRunner.dumpSelectionStats(textEditor); |
| next(); |
| }, |
| |
| function testNonWordSelection(next) { |
| lineSelection(18, 12, 14); |
| nextOccurrence(8); |
| SourcesTestRunner.dumpSelectionStats(textEditor); |
| next(); |
| }, |
| |
| function testNonWordSelection2(next) { |
| lineSelection(17, 30, 33); |
| nextOccurrence(8); |
| SourcesTestRunner.dumpSelectionStats(textEditor); |
| next(); |
| }, |
| |
| function testNonWordSelection3(next) { |
| SourcesTestRunner.setLineSelections(textEditor, [ |
| {line: 14, from: 15, to: 25}, |
| {line: 16, column: 21}, |
| {line: 17, from: 42, to: 47}, |
| ]); |
| var selections = textEditor.selections(); |
| nextOccurrence(3); |
| SourcesTestRunner.dumpSelectionStats(textEditor); |
| next(); |
| }, |
| |
| function testNonWordSelection4(next) { |
| SourcesTestRunner.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); |
| SourcesTestRunner.dumpSelectionStats(textEditor); |
| next(); |
| }, |
| |
| function testTriggerWordSearchInMixedCase(next) { |
| SourcesTestRunner.setLineSelections(textEditor, [{line: 9, from: 10, to: 25}, {line: 14, column: 33}]); |
| nextOccurrence(5); |
| SourcesTestRunner.dumpSelectionStats(textEditor); |
| next(); |
| }, |
| ]; |
| })(); |