676d96e594c965f50bc9e032655073fc2a380eed
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / elements / edit-dom-test.js
1 function initialize_EditDOMTests()
2 {
3
4 InspectorTest.doAddAttribute = function(testName, dataNodeId, attributeText, next)
5 {
6     InspectorTest.domActionTestForNodeId(testName, dataNodeId, testBody, next);
7
8     function testBody(node, done)
9     {
10         var editorElement = InspectorTest.editNodePart(node, "webkit-html-attribute");
11         editorElement.dispatchEvent(InspectorTest.createKeyEvent("U+0009")); // Tab
12
13         InspectorTest.runAfterPendingDispatches(testContinuation);
14
15         function testContinuation()
16         {
17             var editorElement = window.getSelection().anchorNode.parentElement;
18             editorElement.textContent = attributeText;
19             editorElement.dispatchEvent(InspectorTest.createKeyEvent("Enter"));
20             InspectorTest.addSniffer(WebInspector.ElementsTreeUpdater.prototype, "_updateModifiedNodes", done);
21         }
22     }
23 }
24
25 InspectorTest.domActionTestForNodeId = function(testName, dataNodeId, testBody, next)
26 {
27     function callback(testNode, continuation)
28     {
29         InspectorTest.selectNodeWithId(dataNodeId, continuation);
30     }
31     InspectorTest.domActionTest(testName, callback, testBody, next);
32 }
33
34 InspectorTest.domActionTest = function(testName, dataNodeSelectionCallback, testBody, next)
35 {
36     var testNode = InspectorTest.expandedNodeWithId(testName);
37     InspectorTest.addResult("==== before ====");
38     InspectorTest.dumpElementsTree(testNode);
39
40     dataNodeSelectionCallback(testNode, step0);
41
42     function step0(node)
43     {
44         InspectorTest.runAfterPendingDispatches(step1.bind(null, node));
45     }
46
47     function step1(node)
48     {
49         testBody(node, step2);
50     }
51
52     function step2()
53     {
54         InspectorTest.addResult("==== after ====");
55         InspectorTest.dumpElementsTree(testNode);
56         next();
57     }
58 }
59
60 InspectorTest.editNodePart = function(node, className)
61 {
62     var treeElement = InspectorTest.firstElementsTreeOutline().findTreeElement(node);
63     var textElement = treeElement.listItemElement.getElementsByClassName(className)[0];
64     if (!textElement && treeElement.childrenListElement)
65         textElement = treeElement.childrenListElement.getElementsByClassName(className)[0];
66     treeElement._startEditingTarget(textElement);
67     return textElement;
68 }
69
70 InspectorTest.editNodePartAndRun = function(node, className, newValue, step2, useSniffer)
71 {
72     var editorElement = InspectorTest.editNodePart(node, className);
73     editorElement.textContent = newValue;
74     editorElement.dispatchEvent(InspectorTest.createKeyEvent("Enter"));
75     if (useSniffer)
76         InspectorTest.addSniffer(WebInspector.ElementsTreeUpdater.prototype, "_updateModifiedNodes", step2);
77     else
78         InspectorTest.runAfterPendingDispatches(step2);
79 }
80
81 }