Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector / elements / edit / edit-dom-test.js
blob4c804547963c1b3245bf69ba849040ee21741e8d
1 function initialize_EditDOMTests()
4 // Preload codemirror which is used for "Edit as HTML".
5 InspectorTest.preloadPanel("sources");
7 InspectorTest.doAddAttribute = function(testName, dataNodeId, attributeText, next)
9     InspectorTest.domActionTestForNodeId(testName, dataNodeId, testBody, next);
11     function testBody(node, done)
12     {
13         var editorElement = InspectorTest.editNodePart(node, "webkit-html-attribute");
14         editorElement.dispatchEvent(InspectorTest.createKeyEvent("U+0009")); // Tab
16         InspectorTest.runAfterPendingDispatches(testContinuation);
18         function testContinuation()
19         {
20             var editorElement = WebInspector.panels.elements._treeOutlines[0]._shadowRoot.getSelection().anchorNode.parentElement;
21             editorElement.textContent = attributeText;
22             editorElement.dispatchEvent(InspectorTest.createKeyEvent("Enter"));
23             InspectorTest.addSniffer(WebInspector.ElementsTreeOutline.prototype, "_updateModifiedNodes", done);
24         }
25     }
28 InspectorTest.domActionTestForNodeId = function(testName, dataNodeId, testBody, next)
30     function callback(testNode, continuation)
31     {
32         InspectorTest.selectNodeWithId(dataNodeId, continuation);
33     }
34     InspectorTest.domActionTest(testName, callback, testBody, next);
37 InspectorTest.domActionTest = function(testName, dataNodeSelectionCallback, testBody, next)
39     var testNode = InspectorTest.expandedNodeWithId(testName);
40     InspectorTest.addResult("==== before ====");
41     InspectorTest.dumpElementsTree(testNode);
43     dataNodeSelectionCallback(testNode, step0);
45     function step0(node)
46     {
47         InspectorTest.runAfterPendingDispatches(step1.bind(null, node));
48     }
50     function step1(node)
51     {
52         testBody(node, step2);
53     }
55     function step2()
56     {
57         InspectorTest.addResult("==== after ====");
58         InspectorTest.dumpElementsTree(testNode);
59         next();
60     }
63 InspectorTest.editNodePart = function(node, className)
65     var treeElement = InspectorTest.firstElementsTreeOutline().findTreeElement(node);
66     var textElement = treeElement.listItemElement.getElementsByClassName(className)[0];
67     if (!textElement && treeElement.childrenListElement)
68         textElement = treeElement.childrenListElement.getElementsByClassName(className)[0];
69     treeElement._startEditingTarget(textElement);
70     return textElement;
73 InspectorTest.editNodePartAndRun = function(node, className, newValue, step2, useSniffer)
75     var editorElement = InspectorTest.editNodePart(node, className);
76     editorElement.textContent = newValue;
77     editorElement.dispatchEvent(InspectorTest.createKeyEvent("Enter"));
78     if (useSniffer)
79         InspectorTest.addSniffer(WebInspector.ElementsTreeOutline.prototype, "_updateModifiedNodes", step2);
80     else
81         InspectorTest.runAfterPendingDispatches(step2);