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
.StylesSidebarPane
.prototype.update = function() {};
12 WebInspector
.MetricsSidebarPane
.prototype.update = function() {};
14 InspectorTest
.runTestSuite([
15 function testSetUp(next
)
17 InspectorTest
.expandElementsTree(next
);
20 function testRemove(next
)
22 InspectorTest
.domActionTestForNodeId("testRemove", "node-to-remove", testBody
, next
);
24 function testBody(node
, done
)
26 var treeElement
= InspectorTest
.firstElementsTreeOutline().findTreeElement(node
);
28 InspectorTest
.runAfterPendingDispatches(done
);
32 function testSetNodeName(next
)
34 InspectorTest
.domActionTestForNodeId("testSetNodeName", "node-to-set-name", testBody
, next
);
36 function testBody(node
, done
)
38 InspectorTest
.editNodePartAndRun(node
, "webkit-html-tag-name", "span", done
);
42 function testSetNodeNameInput(next
)
44 InspectorTest
.domActionTestForNodeId("testSetNodeNameInput", "node-to-set-name-input", testBody
, next
);
46 function testBody(node
, done
)
48 InspectorTest
.editNodePartAndRun(node
, "webkit-html-tag-name", "input", done
);
52 function testSetNodeValue(next
)
54 InspectorTest
.domActionTestForNodeId("testSetNodeValue", "node-to-set-value", testBody
, next
);
56 function testBody(node
, done
)
58 InspectorTest
.editNodePartAndRun(node
, "webkit-html-text-node", " \n Edited Text \n ", done
);
62 function testSetAttribute(next
)
64 InspectorTest
.domActionTestForNodeId("testSetAttribute", "node-to-set-attribute", testBody
, next
);
66 function testBody(node
, done
)
68 InspectorTest
.editNodePartAndRun(node
, "webkit-html-attribute", "bar=\"edited attribute\"", done
, true);
72 function testSetScriptableAttribute(next
)
74 InspectorTest
.domActionTestForNodeId("testSetScriptableAttribute", "node-to-set-scriptable-attribute", testBody
, next
);
76 function testBody(node
, done
)
78 InspectorTest
.editNodePartAndRun(node
, "webkit-html-attribute", "onclick=\"alert(2)\"", done
, true);
82 function testRemoveAttribute(next
)
84 InspectorTest
.domActionTestForNodeId("testRemoveAttribute", "node-to-remove-attribute", testBody
, next
);
86 function testBody(node
, done
)
88 InspectorTest
.editNodePartAndRun(node
, "webkit-html-attribute", "", done
, true);
92 function testAddAttribute(next
)
94 InspectorTest
.doAddAttribute("testAddAttribute", "node-to-add-attribute", "newattr=\"new-value\"", next
);
97 function testAddAttributeUnquotedValue(next
)
99 InspectorTest
.doAddAttribute("testAddAttributeUnquotedValue", "node-to-add-attribute-unquoted-value", "newattr=unquotedValue", next
);
102 function testEditCommentAsHTML(next
)
104 function commentNodeSelectionCallback(testNode
, callback
)
106 var childNodes
= testNode
.children();
107 for (var i
= 0; i
< childNodes
.length
; ++i
) {
108 if (childNodes
[i
].nodeType() === 8) {
109 WebInspector
.Revealer
.reveal(childNodes
[i
]);
110 callback(childNodes
[i
]);
114 InspectorTest
.addResult("Comment node not found");
115 InspectorTest
.completeTest();
117 InspectorTest
.domActionTest("testEditCommentAsHTML", commentNodeSelectionCallback
, testBody
, next
);
119 function testBody(node
, done
)
121 var treeOutline
= InspectorTest
.firstElementsTreeOutline();
122 var treeElement
= treeOutline
.findTreeElement(node
);
123 treeOutline
.toggleEditAsHTML(node
);
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 treeOutline
= InspectorTest
.firstElementsTreeOutline();
145 var treeElement
= treeOutline
.findTreeElement(node
);
146 treeOutline
.toggleEditAsHTML(node
);
147 InspectorTest
.runAfterPendingDispatches(step2
);
151 InspectorTest
.addResult(treeElement
._editing
.codeMirror
.getValue());
152 treeElement
._editing
.codeMirror
.setValue("<span foo=\"bar\"><span id=\"inner-span\">Span contents</span></span>");
153 var event
= InspectorTest
.createKeyEvent("Enter");
154 event
.isMetaOrCtrlForTest
= true;
155 treeElement
._htmlEditElement
.dispatchEvent(event
);
156 InspectorTest
.runAfterPendingDispatches(InspectorTest
.expandElementsTree
.bind(InspectorTest
, done
));
161 function testEditInvisibleCharsAsHTML(next
)
163 InspectorTest
.domActionTestForNodeId("testEditInvisibleCharsAsHTML", "node-with-invisible-chars", testBody
, next
);
165 function testBody(node
, done
)
167 var treeOutline
= InspectorTest
.firstElementsTreeOutline();
168 var treeElement
= treeOutline
.findTreeElement(node
);
169 treeOutline
.toggleEditAsHTML(node
);
170 InspectorTest
.runAfterPendingDispatches(step2
);
174 var codeMirror
= treeElement
._editing
.codeMirror
;
175 InspectorTest
.addResult(codeMirror
.getValue());
176 codeMirror
.setValue(codeMirror
.getValue().replace(/&/g
, '#'));
177 var event
= InspectorTest
.createKeyEvent("Enter");
178 event
.isMetaOrCtrlForTest
= true;
179 treeElement
._htmlEditElement
.dispatchEvent(event
);
180 InspectorTest
.runAfterPendingDispatches(InspectorTest
.expandElementsTree
.bind(InspectorTest
, done
));
185 function testEditScript(next
)
187 InspectorTest
.domActionTestForNodeId("testEditScript", "node-to-edit-script", testBody
, next
);
189 function testBody(node
, done
)
191 InspectorTest
.editNodePartAndRun(node
, "webkit-html-text-node", "var i = 0;\n var j = 0;\n", done
);
195 function testEditSVGAttribute(next
)
197 InspectorTest
.domActionTestForNodeId("testEditSVG", "node-to-edit-svg-attribute", testBody
, next
);
199 function testBody(node
, done
)
201 var treeOutline
= InspectorTest
.firstElementsTreeOutline();
202 var treeElement
= treeOutline
.findTreeElement(node
);
203 treeOutline
.toggleEditAsHTML(node
);
204 InspectorTest
.runAfterPendingDispatches(step2
);
208 var value
= treeElement
._editing
.codeMirror
.getValue();
209 InspectorTest
.addResult(value
);
210 treeElement
._editing
.codeMirror
.setValue(value
.replace("100", "110"));
211 var event
= InspectorTest
.createKeyEvent("Enter");
212 event
.isMetaOrCtrlForTest
= true;
213 treeElement
._htmlEditElement
.dispatchEvent(event
);
214 InspectorTest
.runAfterPendingDispatches(InspectorTest
.expandElementsTree
.bind(InspectorTest
, done
));
224 <body onload=
"runTest()">
226 Tests that user can mutate DOM by means of elements panel.
230 <div id=
"testRemove">
231 <div id=
"node-to-remove"></div>
234 <div id=
"testSetNodeName">
235 <div id=
"node-to-set-name"></div>
238 <div id=
"testSetNodeNameInput">
239 <div id=
"node-to-set-name-input"></div>
242 <div id=
"testSetNodeValue">
243 <div id=
"node-to-set-value">
248 <div id=
"testSetAttribute">
249 <div foo=
"attribute value" id=
"node-to-set-attribute"></div>
252 <div id=
"testSetScriptableAttribute">
253 <div onclick=
"alert(1)" id=
"node-to-set-scriptable-attribute"></div>
256 <div id=
"testRemoveAttribute">
257 <div foo=
"attribute value" id=
"node-to-remove-attribute"></div>
260 <div id=
"testAddAttribute">
261 <div id=
"node-to-add-attribute"></div>
264 <div id=
"testAddAttributeUnquotedValue">
265 <div id=
"node-to-add-attribute-unquoted-value"></div>
268 <div id=
"testEditAsHTML">
269 <div id=
"node-to-edit-as-html"><span id=
"span">Text
</span></div>
272 <div id=
"testEditInvisibleCharsAsHTML">
273 <div id=
"node-with-invisible-chars">A
B
 C
 D
 E
‌F
‍G
‏H
‎I
</div>
276 <div id=
"testEditScript">
277 <script id=
"node-to-edit-script">
288 <div id=
"testEditSVG">
289 <svg id=
"node-to-edit-svg-attribute" xmlns:
xlink=
"test" width=
"100">
293 <div id=
"testEditCommentAsHTML">