chromium/third_party/blink/web_tests/editing/selection/find-in-text-control.html

<p id="description" style="display: none;">
    Test for <i><a href="https://bugs.webkit.org/show_bug.cgi?id=7023">https://bugs.webkit.org/show_bug.cgi?id=7023</a> Searching in text areas</i>.
</p>
<div id="div">
    Lorem ip<textarea id="textarea">sum dolor si</textarea>t amet
    Lorem ip<input id="input: text" type="text" value="sum dolor si">t amet
    Lorem ip<input id="input: search" type="search" value="sum dolor si">t amet
    Lorem ip<input id="input: password" type="password" value="sum dolor si">t amet
</div>
<script>
    if (window.testRunner)
        testRunner.dumpAsText();

    var result = "";

    function textNodeIndex(node)
    {
        var index = 1;
        while (node = node.previousSibling) {
            if (node.nodeType == Node.TEXT_NODE)
                ++index;
        }
        return index;
    }

    function clearSelection()
    {
        getSelection().selectAllChildren(document.body);
        getSelection().empty();
    }

    function selectionLocationAsString()
    {
        if (document.activeElement.selectionStart != document.activeElement.selectionEnd)
            return document.activeElement.id + ", at offset " + document.activeElement.selectionStart;
        if (getSelection().rangeCount == 0)
            return "";
        var range = getSelection().getRangeAt(0);
        return "outer text node " + textNodeIndex(range.startContainer) + ", at offset " + range.startOffset;
    }

    function findAll(target)
    {
        var sel = getSelection();
        var ranges = [];

        clearSelection();
        document.execCommand("FindString", false, target);

        var firstMatch = selectionLocationAsString();
        if (firstMatch == "") {
            result += "Target " + target + " not matched\n";
            return;
        }

        result += "Target " + target + " matched at:\n    " + firstMatch + "\n";

        document.execCommand("FindString", false, target);
        var match = selectionLocationAsString();
        while (match !== firstMatch) {
            result += "    " + match + "\n";
            document.execCommand("FindString", false, target);
            match = selectionLocationAsString();
        }

        clearSelection();
    }

    findAll("m");
    findAll("s");
    findAll("si");
    findAll("rem");
    findAll("ipsum");
    findAll("sit");
    findAll("amet");

    document.body.appendChild(document.createElement("pre")).appendChild(document.createTextNode(result));
    document.getElementById("description").style.display = "";
</script>