3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../http/tests/inspector/elements-test.js"></script>
5 <script src="edit-dom-test.js"></script>
10 // Save time on style updates.
11 WebInspector.inspectorView.showPanel("elements");
12 WebInspector.StylesSidebarPane.prototype.update = function() {};
13 WebInspector.MetricsSidebarPane.prototype.update = function() {};
15 InspectorTest.runTestSuite([
16 function testSetUp(next)
18 InspectorTest.expandElementsTree(next);
21 function testRemove(next)
23 InspectorTest.domActionTestForNodeId("testRemove", "node-to-remove", testBody, next);
25 function testBody(node, done)
27 var treeElement = InspectorTest.firstElementsTreeOutline().findTreeElement(node);
29 InspectorTest.runAfterPendingDispatches(done);
33 function testSetNodeName(next)
35 InspectorTest.domActionTestForNodeId("testSetNodeName", "node-to-set-name", testBody, next);
37 function testBody(node, done)
39 InspectorTest.editNodePartAndRun(node, "webkit-html-tag-name", "span", done);
43 function testSetNodeNameInput(next)
45 InspectorTest.domActionTestForNodeId("testSetNodeNameInput", "node-to-set-name-input", testBody, next);
47 function testBody(node, done)
49 InspectorTest.editNodePartAndRun(node, "webkit-html-tag-name", "input", done);
53 function testSetNodeValue(next)
55 InspectorTest.domActionTestForNodeId("testSetNodeValue", "node-to-set-value", testBody, next);
57 function testBody(node, done)
59 InspectorTest.editNodePartAndRun(node, "webkit-html-text-node", " \n Edited Text \n ", done);
63 function testSetAttribute(next)
65 InspectorTest.domActionTestForNodeId("testSetAttribute", "node-to-set-attribute", testBody, next);
67 function testBody(node, done)
69 InspectorTest.editNodePartAndRun(node, "webkit-html-attribute", "bar=\"edited attribute\"", done, true);
73 function testSetScriptableAttribute(next)
75 InspectorTest.domActionTestForNodeId("testSetScriptableAttribute", "node-to-set-scriptable-attribute", testBody, next);
77 function testBody(node, done)
79 InspectorTest.editNodePartAndRun(node, "webkit-html-attribute", "onclick=\"alert(2)\"", done, true);
83 function testRemoveAttribute(next)
85 InspectorTest.domActionTestForNodeId("testRemoveAttribute", "node-to-remove-attribute", testBody, next);
87 function testBody(node, done)
89 InspectorTest.editNodePartAndRun(node, "webkit-html-attribute", "", done, true);
93 function testAddAttribute(next)
95 InspectorTest.doAddAttribute("testAddAttribute", "node-to-add-attribute", "newattr=\"new-value\"", next);
98 function testAddAttributeUnquotedValue(next)
100 InspectorTest.doAddAttribute("testAddAttributeUnquotedValue", "node-to-add-attribute-unquoted-value", "newattr=unquotedValue", next);
103 function testEditCommentAsHTML(next)
105 function commentNodeSelectionCallback(testNode, callback)
107 var childNodes = testNode.children();
108 for (var i = 0; i < childNodes.length; ++i) {
109 if (childNodes[i].nodeType() === 8) {
110 WebInspector.Revealer.reveal(childNodes[i]);
111 callback(childNodes[i]);
115 InspectorTest.addResult("Comment node not found");
116 InspectorTest.completeTest();
118 InspectorTest.domActionTest("testEditCommentAsHTML", commentNodeSelectionCallback, testBody, next);
120 function testBody(node, done)
122 var treeElement = InspectorTest.firstElementsTreeOutline().findTreeElement(node);
123 treeElement._editAsHTML();
124 InspectorTest.runAfterPendingDispatches(step2);
128 InspectorTest.addResult(treeElement._editing.codeMirror.getValue());
129 treeElement._editing.codeMirror.setValue("<div foo=\"bar-comment\">Element</div>");
130 var event = InspectorTest.createKeyEvent("Enter");
131 event.isMetaOrCtrlForTest = true;
132 treeElement._htmlEditElement.dispatchEvent(event);
133 InspectorTest.runAfterPendingDispatches(done);
138 function testEditAsHTML(next)
140 InspectorTest.domActionTestForNodeId("testEditAsHTML", "node-to-edit-as-html", testBody, next);
142 function testBody(node, done)
144 var treeElement = InspectorTest.firstElementsTreeOutline().findTreeElement(node);
145 treeElement._editAsHTML();
146 InspectorTest.runAfterPendingDispatches(step2);
150 InspectorTest.addResult(treeElement._editing.codeMirror.getValue());
151 treeElement._editing.codeMirror.setValue("<span foo=\"bar\"><span id=\"inner-span\">Span contents</span></span>");
152 var event = InspectorTest.createKeyEvent("Enter");
153 event.isMetaOrCtrlForTest = true;
154 treeElement._htmlEditElement.dispatchEvent(event);
155 InspectorTest.runAfterPendingDispatches(InspectorTest.expandElementsTree.bind(InspectorTest, done));
160 function testEditInvisibleCharsAsHTML(next)
162 InspectorTest.domActionTestForNodeId("testEditInvisibleCharsAsHTML", "node-with-invisible-chars", testBody, next);
164 function testBody(node, done)
166 var treeElement = InspectorTest.firstElementsTreeOutline().findTreeElement(node);
167 treeElement._editAsHTML();
168 InspectorTest.runAfterPendingDispatches(step2);
172 var codeMirror = treeElement._editing.codeMirror;
173 InspectorTest.addResult(codeMirror.getValue());
174 codeMirror.setValue(codeMirror.getValue().replace(/&/g, '#'));
175 var event = InspectorTest.createKeyEvent("Enter");
176 event.isMetaOrCtrlForTest = true;
177 treeElement._htmlEditElement.dispatchEvent(event);
178 InspectorTest.runAfterPendingDispatches(InspectorTest.expandElementsTree.bind(InspectorTest, done));
183 function testEditScript(next)
185 InspectorTest.domActionTestForNodeId("testEditScript", "node-to-edit-script", testBody, next);
187 function testBody(node, done)
189 InspectorTest.editNodePartAndRun(node, "webkit-html-text-node", "\n var i = 0;\n var j = 0;\n", done);
198 <body onload="runTest()">
200 Tests that user can mutate DOM by means of elements panel.
204 <div id="testRemove">
205 <div id="node-to-remove"></div>
208 <div id="testSetNodeName">
209 <div id="node-to-set-name"></div>
212 <div id="testSetNodeNameInput">
213 <div id="node-to-set-name-input"></div>
216 <div id="testSetNodeValue">
217 <div id="node-to-set-value">
222 <div id="testSetAttribute">
223 <div foo="attribute value" id="node-to-set-attribute"></div>
226 <div id="testSetScriptableAttribute">
227 <div onclick="alert(1)" id="node-to-set-scriptable-attribute"></div>
230 <div id="testRemoveAttribute">
231 <div foo="attribute value" id="node-to-remove-attribute"></div>
234 <div id="testAddAttribute">
235 <div id="node-to-add-attribute"></div>
238 <div id="testAddAttributeUnquotedValue">
239 <div id="node-to-add-attribute-unquoted-value"></div>
242 <div id="testEditAsHTML">
243 <div id="node-to-edit-as-html"><span id="span">Text</span></div>
246 <div id="testEditInvisibleCharsAsHTML">
247 <div id="node-with-invisible-chars">A B C D E‌F‍G‏H‎I</div>
250 <div id="testEditScript">
251 <script id="node-to-edit-script">
262 <div id="testEditCommentAsHTML">