3 <script src=
"../http/tests/inspector/inspector-test.js"></script>
4 <script src=
"utilities-test.js"></script>
8 function dumpTextNodesAsString(node
)
11 function dumpTextNode(node
)
13 var str
= node
.textContent
;
14 if (node
.parentElement
.className
)
15 result
+= "[" + str
+ "]";
20 function dumpElement(element
)
22 for (var i
= 0; i
< element
.childNodes
.length
; i
++)
23 dumpNode(element
.childNodes
[i
]);
26 function dumpNode(node
)
28 if (node
.nodeType
=== Node
.TEXT_NODE
)
30 else if (node
.nodeType
=== Node
.ELEMENT_NODE
)
39 function performTestForElement(element
, ranges
)
42 InspectorTest
.addResult("--------- Running test: ----------");
43 WebInspector
.highlightRangesWithStyleClass(element
, ranges
, "highlighted", changes
);
44 InspectorTest
.addResult("After highlight: " + dumpTextNodesAsString(element
));
45 WebInspector
.revertDomChanges(changes
);
46 InspectorTest
.addResult("After revert: " + dumpTextNodesAsString(element
));
47 WebInspector
.applyDomChanges(changes
);
48 InspectorTest
.addResult("After apply: " + dumpTextNodesAsString(element
));
51 function textElement(strings
)
53 var element
= document
.createElement("div");
54 for (var i
= 0; i
< strings
.length
; i
++) {
55 var span
= document
.createElement("span");
56 span
.textContent
= strings
[i
];
57 element
.appendChild(span
);
62 function range(offset
, length
)
64 return new WebInspector
.SourceRange(offset
, length
);
67 performTestForElement(textElement(["function"]), [range(0, 8)]); // Highlight whole text node.
68 performTestForElement(textElement(["function"]), [range(0, 7)]); // Highlight only text node beginning.
69 performTestForElement(textElement(["function"]), [range(1, 7)]); // Highlight only text node ending.
70 performTestForElement(textElement(["function"]), [range(1, 6)]); // Highlight in the middle of text node.
72 performTestForElement(textElement(["function", " ", "functionName"]), [range(0, 21)]); // Highlight all text in 3 text nodes.
73 performTestForElement(textElement(["function", " ", "functionName"]), [range(0, 20)]); // Highlight all text in 3 text nodes except for the last character.
74 performTestForElement(textElement(["function", " ", "functionName"]), [range(1, 20)]); // Highlight all text in 3 text nodes except for the first character.
75 performTestForElement(textElement(["function", " ", "functionName"]), [range(1, 19)]); // Highlight all text in 3 text nodes except for the first and the last characters.
76 performTestForElement(textElement(["function", " ", "functionName"]), [range(7, 3)]); // Highlight like that "functio[n f]unctionName"
78 performTestForElement(textElement(["function", " ", "functionName"]), [range(0, 1), range(8, 1), range(9, 1)]); // Highlight first characters in text nodes.
79 performTestForElement(textElement(["function", " ", "functionName"]), [range(7, 1), range(8, 1), range(20, 1)]); // Highlight last characters in text node.
80 performTestForElement(textElement(["function", " ", "functionName"]), [range(0, 1), range(7, 3), range(20, 1)]); // Highlight like that: "[f]unctio[n f]unctionNam[e]"
81 InspectorTest
.completeTest();
85 <body onload=
"runTest()">
86 <p>Tests how utilities functions highlight text and then revert/re-apply highlighting changes.
</p>
87 <a href=
"https://bugs.webkit.org/show_bug.cgi?id=70244">Bug
70244</a>