Web Inspector: highlight occurences of word in DefaultTextEditor
[WebKit-https.git] / LayoutTests / inspector / editor / text-editor-highlight-token.html
1 <html>
2 <head>
3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="editor-test.js"></script>
5 <script>
6 function test()
7 {
8     function findElement(collection, elem) {
9         for(var i = 0; i < collection.length; ++i)
10             if (collection[i] === elem)
11                 return i;
12         return null;
13     }
14
15     var steps = [step2, step1]; // reversed order
16     function selectionChangeListener()
17     {
18         if (steps.length)
19             steps.pop().call();
20     }
21
22     var textEditorDelegate = new WebInspector.TextEditorDelegate();
23     textEditorDelegate.selectionChanged = selectionChangeListener;
24
25     var textEditor = InspectorTest.createTestEditor(undefined, undefined, textEditorDelegate);
26     textEditor.setReadOnly(false);
27     textEditor.setText(findElement.toString());
28     textEditor.element.focus();
29
30     InspectorTest.addResult("=========== TextEditor text ==========");
31     InspectorTest.addResult(textEditor.text());
32
33     InspectorTest.addResult("=========== Before selecting element ===========");
34     InspectorTest.dumpEditorHTML(textEditor, true);
35
36     var range = new WebInspector.TextRange(0, 21, 0, 31);
37     textEditor.setSelection(range);
38
39     function step1()
40     {
41         InspectorTest.addResult("=========== After selecting '" + textEditor._textModel.copyRange(range) + "' ===========");
42         InspectorTest.dumpEditorHTML(textEditor, true);
43         range = new WebInspector.TextRange(0, 33, 0, 37);
44         textEditor.setSelection(range);
45     }
46
47     function step2()
48     {
49         InspectorTest.addResult("=========== After selecting '" + textEditor._textModel.copyRange(range) + "' ===========");
50         InspectorTest.dumpEditorHTML(textEditor, true);
51         InspectorTest.completeTest();
52     }
53
54 }
55
56 </script>
57 </head>
58
59 <body onload="runTest();">
60 <p>
61 This test checks text editor token highlight functionality.
62 </p>
63 </body>
64 </html>