Commit dc8cd4da authored by pfeldman@chromium.org's avatar pfeldman@chromium.org
Browse files

2011-02-15 Pavel Feldman <pfeldman@chromium.org>

        Reviewed by Yury Semikhatsky.

        Web Inspector: implement DOM agent tests.
        https://bugs.webkit.org/show_bug.cgi?id=54459

        * http/tests/inspector/elements-test.js:
        (initialize_ElementTest.InspectorTest.expandedNodeWithId.callback):
        (initialize_ElementTest.InspectorTest.expandedNodeWithId):
        (initialize_ElementTest.InspectorTest.dumpElementsTree):
        (initialize_ElementTest.InspectorTest.dumpElementsTree.print):
        (initialize_ElementTest.InspectorTest.expandElementsTree):
        (initialize_ElementTest.InspectorTest.expandElementsTree.mycallback):
        (initialize_ElementTest.InspectorTest.dumpDOMAgentTree):
        (initialize_ElementTest):
        * http/tests/inspector/extensions-resources-redirect-expected.txt:
        * http/tests/inspector/inspector-test.js:
        (initialize_InspectorTest.InspectorTest.addResult.clearResults):
        (initialize_InspectorTest.InspectorTest.runTestSuite.runner):
        (initialize_InspectorTest.InspectorTest.runTestSuite):
        (output):
        (clearOutput):
        * inspector/debugger/dom-breakpoints.html:
        * inspector/elements/elements-panel-limited-children-expected.txt:
        * inspector/elements/elements-panel-rewrite-href.html:
        * inspector/elements/elements-panel-structure-expected.txt:
        * inspector/elements/elements-panel-structure.html:
        * inspector/elements/elements-panel-xhtml-structure-expected.txt:
        * inspector/elements/elements-panel-xhtml-structure.xhtml:
        * inspector/elements/insert-node-collapsed-expected.txt: Added.
        * inspector/elements/insert-node-collapsed.html: Added.
        * inspector/elements/insert-node-expected.txt: Added.
        * inspector/elements/insert-node.html: Added.
        * inspector/elements/modify-chardata-expected.txt: Added.
        * inspector/elements/modify-chardata.html: Added.
        * inspector/elements/mutate-unknown-node-expected.txt: Added.
        * inspector/elements/mutate-unknown-node.html: Added.
        * inspector/elements/remove-node-expected.txt: Added.
        * inspector/elements/remove-node.html: Added.
        * inspector/elements/set-attribute.html: Added.
        * inspector/extensions/extensions-expected.txt:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@78576 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 56d51b48
2011-02-15 Pavel Feldman <pfeldman@chromium.org>
Reviewed by Yury Semikhatsky.
Web Inspector: implement DOM agent tests.
https://bugs.webkit.org/show_bug.cgi?id=54459
* http/tests/inspector/elements-test.js:
(initialize_ElementTest.InspectorTest.expandedNodeWithId.callback):
(initialize_ElementTest.InspectorTest.expandedNodeWithId):
(initialize_ElementTest.InspectorTest.dumpElementsTree):
(initialize_ElementTest.InspectorTest.dumpElementsTree.print):
(initialize_ElementTest.InspectorTest.expandElementsTree):
(initialize_ElementTest.InspectorTest.expandElementsTree.mycallback):
(initialize_ElementTest.InspectorTest.dumpDOMAgentTree):
(initialize_ElementTest):
* http/tests/inspector/extensions-resources-redirect-expected.txt:
* http/tests/inspector/inspector-test.js:
(initialize_InspectorTest.InspectorTest.addResult.clearResults):
(initialize_InspectorTest.InspectorTest.runTestSuite.runner):
(initialize_InspectorTest.InspectorTest.runTestSuite):
(output):
(clearOutput):
* inspector/debugger/dom-breakpoints.html:
* inspector/elements/elements-panel-limited-children-expected.txt:
* inspector/elements/elements-panel-rewrite-href.html:
* inspector/elements/elements-panel-structure-expected.txt:
* inspector/elements/elements-panel-structure.html:
* inspector/elements/elements-panel-xhtml-structure-expected.txt:
* inspector/elements/elements-panel-xhtml-structure.xhtml:
* inspector/elements/insert-node-collapsed-expected.txt: Added.
* inspector/elements/insert-node-collapsed.html: Added.
* inspector/elements/insert-node-expected.txt: Added.
* inspector/elements/insert-node.html: Added.
* inspector/elements/modify-chardata-expected.txt: Added.
* inspector/elements/modify-chardata.html: Added.
* inspector/elements/mutate-unknown-node-expected.txt: Added.
* inspector/elements/mutate-unknown-node.html: Added.
* inspector/elements/remove-node-expected.txt: Added.
* inspector/elements/remove-node.html: Added.
* inspector/elements/set-attribute.html: Added.
* inspector/extensions/extensions-expected.txt:
2011-02-15 Mario Sanchez Prada <msanchez@igalia.com>
 
Unreviewed, test crashing because of failing ASSERT on GTK 64-bit debug bot.
var initialize_ElementTest = function() {
InspectorTest.pushAllDOM = function(callback)
{
InspectorTest.nodeWithId(/nonstring/, callback);
}
InspectorTest.nodeWithId = function(idValue, callback)
{
......@@ -37,6 +33,17 @@ InspectorTest.nodeWithId = function(idValue, callback)
WebInspector.domAgent.getChildNodesAsync(WebInspector.domAgent.document, processChildren.bind(this, true));
};
InspectorTest.expandedNodeWithId = function(idValue)
{
var result;
function callback(node)
{
result = node;
}
InspectorTest.nodeWithId(idValue, callback);
return result;
}
InspectorTest.selectNodeWithId = function(idValue, callback)
{
function mycallback(node)
......@@ -123,26 +130,77 @@ InspectorTest.dumpStyleTreeItem = function(treeItem, prefix, depth)
}
};
InspectorTest.dumpElementsTree = function()
InspectorTest.dumpElementsTree = function(rootNode)
{
function beautify(element)
{
return element.textContent.replace(/\u200b/g, "").replace(/\n/g, "").trim();
}
function print(treeItem, prefix)
{
if (treeItem.listItemElement) {
var expander;
if (treeItem.hasChildren) {
if (treeItem.expanded)
expander = "- ";
else
expander = "+ ";
} else
expander = " ";
InspectorTest.addResult(prefix + expander + beautify(treeItem.listItemElement));
}
if (!treeItem.expanded)
return;
var children = treeItem.children;
for (var i = 0; children && i < children.length - 1; ++i)
print(children[i], prefix + " ");
// Closing tag.
if (children && children.length)
print(children[children.length - 1], prefix);
}
WebInspector.panels.elements.updateModifiedNodes();
InspectorTest.addResult(WebInspector.panels.elements.treeOutline.element.textContent.replace(/\u200b/g, "").replace(/\n/g, "").replace(/</g, "\n<"));
var treeOutline = WebInspector.panels.elements.treeOutline;
print(rootNode ? treeOutline.findTreeElement(rootNode) : treeOutline, "");
};
InspectorTest.dumpLoadedDOM = function()
InspectorTest.expandElementsTree = function(callback)
{
function expand(treeItem, topLevel)
function expand(treeItem)
{
var children = treeItem.children;
for (var i = 0; children && i < children.length; ++i) {
children[i].expand();
expand(children[i], false);
expand(children[i]);
}
if (topLevel)
InspectorTest.dumpElementsTree();
}
WebInspector.panels.elements.updateModifiedNodes();
expand(WebInspector.panels.elements.treeOutline, true);
function mycallback()
{
WebInspector.panels.elements.updateModifiedNodes();
expand(WebInspector.panels.elements.treeOutline);
if (callback)
callback();
}
InspectorTest.nodeWithId(/nonstring/, mycallback);
};
InspectorTest.dumpDOMAgentTree = function()
{
function dump(node, prefix)
{
InspectorTest.addResult(prefix + node.nodeName + "[" + node.id + "]");
var children = node.children;
for (var i = 0; children && i < children.length; ++i)
dump(children[i], prefix + " ");
}
dump(WebInspector.domAgent.document, "");
};
};
\ No newline at end of file
......@@ -2,10 +2,8 @@ Tests WebInspector extension API
Page reloaded.
Started extension.
Running tests...
RUNNING TEST: extension_testGetRedirectResourceContent
content: undefined, encoding: undefined
RUNNING TEST: extension_testRedirectResourceFinished
Finished resource: http://127.0.0.1:8000/loading/resources/redirect-methods-result.php?status=302
......
......@@ -62,7 +62,7 @@ InspectorTest.addResult = function(text)
function clearResults()
{
InspectorTest.evaluateInPage("Array.prototype.forEach.call(document.body.querySelectorAll('div.output'), function(node) { node.parentNode.removeChild(node); })");
InspectorTest.evaluateInPage("clearOutput()");
}
function addResultToPage(text)
......@@ -135,45 +135,21 @@ InspectorTest.createKeyEvent = function(keyIdentifier)
return evt;
}
InspectorTest.findDOMNode = function(root, filter, callback)
InspectorTest.runTestSuite = function(testSuite)
{
var found = false;
var pendingCalls = 1;
var testSuiteTests = testSuite.slice();
if (root)
findDOMNode(root);
else
waitForDocument();
function waitForDocument()
function runner()
{
root = WebInspector.domAgent.document;
if (root)
findDOMNode(root);
else
InspectorTest._addSniffer(WebInspector, setDocument, waitForDocument);
}
function findDOMNode(node)
{
if (filter(node)) {
callback(node);
found = true;
} else
WebInspector.domAgent.getChildNodesAsync(node, processChildren);
--pendingCalls;
if (!found && !pendingCalls)
setTimeout(findDOMNode.bind(null, root), 0);
function processChildren(children)
{
pendingCalls += children ? children.length : 0;
for (var i = 0; !found && children && i < children.length; ++i)
findDOMNode(children[i]);
if (!testSuiteTests.length) {
InspectorTest.completeTest();
return;
}
var nextTestFunction = testSuiteTests.shift();
nextTestFunction(runner);
}
runner();
}
InspectorTest._addSniffer = function(receiver, methodName, override, opt_sticky)
......@@ -268,12 +244,24 @@ function didEvaluateForTestInFrontend(callId)
}, 0);
}
var outputElement;
function output(text)
{
var outputElement = document.createElement("div");
outputElement.className = "output";
outputElement.style.whiteSpace = "pre";
if (!outputElement) {
outputElement = document.createElement("div");
outputElement.className = "output";
outputElement.style.whiteSpace = "pre";
document.body.appendChild(outputElement);
}
outputElement.appendChild(document.createTextNode(text));
outputElement.appendChild(document.createElement("br"));
document.body.appendChild(outputElement);
}
function clearOutput()
{
if (outputElement) {
outputElement.parentNode.removeChild(outputElement);
outputElement = null;
}
}
......@@ -30,7 +30,7 @@ var test = function()
testInsertChild.step1 = function()
{
InspectorTest.addResult("Test that 'Subtree Modified' breakpoint is hit when appending a child.");
findDOMNodeById("rootElement", testInsertChild.step2);
InspectorTest.nodeWithId("rootElement", testInsertChild.step2);
};
testInsertChild.step2 = function(node)
{
......@@ -103,7 +103,7 @@ var test = function()
testRemoveNode.step2 = function()
{
InspectorTest.addResult("Append elementToRemove to rootElement.");
findDOMNodeById("elementToRemove", testRemoveNode.step3);
InspectorTest.nodeWithId("elementToRemove", testRemoveNode.step3);
}
testRemoveNode.step3 = function(node)
{
......@@ -123,7 +123,7 @@ var test = function()
testReload.step1 = function()
{
InspectorTest.addResult("Test that DOM breakpoints are persisted between page reloads.");
findDOMNodeById("rootElement", testReload.step2);
InspectorTest.nodeWithId("rootElement", testReload.step2);
}
testReload.step2 = function(node)
{
......@@ -143,13 +143,6 @@ var test = function()
InspectorTest.completeDebuggerTest();
}
function findDOMNodeById(id, callback)
{
InspectorTest.findDOMNode(null, function(node) {
return node.getAttribute("id") === id;
}, callback);
}
function dumpStatus(callFrames)
{
InspectorTest.captureStackTrace(callFrames);
......
......@@ -10,93 +10,55 @@
Tests that src and href element targets are rewritten properly.
=========== Loaded 5 children ===========
<html>
<head>…
</head>
<body onload="runTest()">
<div id="data">
<div id="id1">1
</div>
<div id="id2">2
</div>
<div id="id3">3
</div>
<div id="id4">4
</div>
<div id="id5">5
</div>Show All Nodes (5 More)
</div>
<p>Tests that src and href element targets are rewritten properly.
</p>
</body>
</html>
- <html>
+ <head>…</head>
- <body onload="runTest()">
- <div id="data">
<div id="id1">1</div>
<div id="id2">2</div>
<div id="id3">3</div>
<div id="id4">4</div>
<div id="id5">5</div>
Show All Nodes (5 More)
</div>
<p>Tests that src and href element targets are rewritten properly.</p>
</body>
</html>
=========== Modified children ===========
<html>
<head>…
</head>
<body onload="runTest()">
<div id="data">
<a>
</a>
<div id="id1">1
</div>
<div id="id3">3
</div>
<div id="id4">4
</div>
<div id="id5">5
</div>Show All Nodes (6 More)
</div>
<p>Tests that src and href element targets are rewritten properly.
</p>
<div class="output" style="white-space: pre; ">…
</div>
<div class="output" style="white-space: pre; ">…
</div>
</body>
</html>
- <html>
+ <head>…</head>
- <body onload="runTest()">
- <div id="data">
<a></a>
<div id="id1">1</div>
<div id="id3">3</div>
<div id="id4">4</div>
<div id="id5">5</div>
Show All Nodes (6 More)
</div>
<p>Tests that src and href element targets are rewritten properly.</p>
+ <div class="output" style="white-space: pre; ">…</div>
</body>
</html>
=========== Loaded all children ===========
<html>
<head>…
</head>
<body onload="runTest()">
<div id="data">
<a>
</a>
<div id="id1">1
</div>
<div id="id3">3
</div>
<div id="id4">4
</div>
<div id="id5">5
</div>
<div id="id6">6
</div>
<div id="id7">7
</div>
<div id="id8">8
</div>
<div id="id9">9
</div>
<div id="id10">10
</div>
<a>
</a>
</div>
<p>Tests that src and href element targets are rewritten properly.
</p>
<div class="output" style="white-space: pre; ">…
</div>
<div class="output" style="white-space: pre; ">…
</div>
<div class="output" style="white-space: pre; ">…
</div>
<div class="output" style="white-space: pre; ">…
</div>
</body>
</html>
- <html>
+ <head>…</head>
- <body onload="runTest()">
- <div id="data">
<a></a>
<div id="id1">1</div>
<div id="id3">3</div>
<div id="id4">4</div>
<div id="id5">5</div>
<div id="id6">6</div>
<div id="id7">7</div>
<div id="id8">8</div>
<div id="id9">9</div>
<div id="id10">10</div>
<a></a>
</div>
<p>Tests that src and href element targets are rewritten properly.</p>
+ <div class="output" style="white-space: pre; ">…</div>
</body>
</html>
......@@ -9,7 +9,7 @@
function test()
{
InspectorTest.pushAllDOM(step1);
InspectorTest.expandElementsTree(step1);
function step1()
{
......
Tests that elements panel shows dom tree structure.
Text
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="../../http/tests/inspector/inspector-test.js">
</script>
<script src="../../http/tests/inspector/elements-test.js">
</script>
<script>function test(){ InspectorTest.pushAllDOM(step1); function step1() { InspectorTest.dumpLoadedDOM(); InspectorTest.completeTest(); }}
</script>
</head>
<body onload="runTest()">
<p>Tests that elements panel shows dom tree structure.
</p>
<div id="level1">
<div id="level2">"Text "
<div id="level3">
</div>
</div>
</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
<script src="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/elements-test.js"></script>
- <script>
function test(){ InspectorTest.expandElementsTree(step1); function step1() { InspectorTest.dumpElementsTree(); InspectorTest.completeTest(); }}
</script>
</head>
- <body onload="runTest()">
<p>Tests that elements panel shows dom tree structure.</p>
- <div id="level1">
- <div id="level2">
"Text "
<div id="level3"></div>
</div>
</div>
</body>
</html>
......@@ -7,11 +7,11 @@
function test()
{
InspectorTest.pushAllDOM(step1);
InspectorTest.expandElementsTree(step1);
function step1()
{
InspectorTest.dumpLoadedDOM();
InspectorTest.dumpElementsTree();
InspectorTest.completeTest();
}
}
......
......@@ -4,29 +4,26 @@ Paragraph BR test
Next line
<HTML xmlns="http://www.w3.org/1999/xhtml">
<Head>
<script src="../../http/tests/inspector/inspector-test.js">
</script>
<script src="../../http/tests/inspector/elements-test.js">
</script>
<script>
<![CDATA[function test(){ InspectorTest.pushAllDOM(step1); function step1() { InspectorTest.dumpLoadedDOM(); InspectorTest.completeTest(); }}]]>
</script>
</Head>
<body onload="runTest()">
<p>"Tests that elements panel shows XML dom tree structure with closing tags for all elements."
</p>
<hr>
</hr>
<p>"Paragraph BR test"
<br>
</br>"Next line"
</p>
<![CDATA[ CData Content ]]>
<img alt="Random Image">
</img>
</body>
</HTML>
- <HTML xmlns="http://www.w3.org/1999/xhtml">
- <Head>
<script src="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/elements-test.js"></script>
- <script>
<![CDATA[function test(){ InspectorTest.expandElementsTree(step1); function step1() { InspectorTest.dumpElementsTree(); InspectorTest.completeTest(); }}]]>
</script>
</Head>
- <body onload="runTest()">
- <p>
"Tests that elements panel shows XML dom tree structure with closing tags for all elements."
</p>
<hr></hr>
- <p>
"Paragraph BR test"
<br></br>
"Next line"
</p>
<![CDATA[ CData Content ]]>
<img alt="Random Image"></img>
</body>
</HTML>
......@@ -6,11 +6,11 @@
<![CDATA[
function test()
{
InspectorTest.pushAllDOM(step1);
InspectorTest.expandElementsTree(step1);
function step1()
{
InspectorTest.dumpLoadedDOM();
InspectorTest.dumpElementsTree();
InspectorTest.completeTest();
}
}
......
Tests that elements panel updates hasChildren flag upon adding children to collapsed nodes.
========= Original ========
<div id="container"></div>
======== Appended =========
+ <div id="container"></div>