e1db1e394119c7c93b4c6689549afdcdf092c5e1
[WebKit-https.git] / LayoutTests / inspector / elements / set-outer-html-test.js
1 var initialize_SetOuterHTMLTest = function() {
2
3 InspectorTest.events = [];
4 InspectorTest.containerId;
5
6 InspectorTest.setUpTestSuite = function(next)
7 {
8     InspectorTest.expandElementsTree(step1);
9
10     function step1()
11     {
12         InspectorTest.selectNodeWithId("container", step2);
13     }
14
15     function step2(node)
16     {
17         InspectorTest.containerId = node.id;
18         DOMAgent.getOuterHTML(InspectorTest.containerId, step3);
19     }
20
21     function step3(error, text)
22     {
23         InspectorTest.containerText = text;
24
25         for (var key in WebInspector.DOMAgent.Events) {
26             var eventName = WebInspector.DOMAgent.Events[key];
27             WebInspector.domAgent.addEventListener(eventName, InspectorTest.recordEvent.bind(InspectorTest, eventName));
28         }
29
30         next();
31     }
32 }
33
34 InspectorTest.recordEvent = function(eventName, event)
35 {
36     var node = event.data.node || event.data;
37     var parent = event.data.parent;
38     for (var currentNode = parent || node; currentNode; currentNode = currentNode.parentNode) {
39         if (currentNode.getAttribute("id") === "output")
40             return;
41     }
42     InspectorTest.events.push("Event " + eventName + ": " + node.nodeName());
43 }
44
45 InspectorTest.patchOuterHTML = function(pattern, replacement, next)
46 {
47    InspectorTest.addResult("Replacing '" + pattern + "' with '" + replacement + "'\n");
48    InspectorTest.setOuterHTML(InspectorTest.containerText.replace(pattern, replacement), next);
49 }
50
51 InspectorTest.setOuterHTML = function(newText, next)
52 {
53     InspectorTest.innerSetOuterHTML(newText, false, bringBack);
54
55     function bringBack()
56     {
57         InspectorTest.addResult("\nBringing things back\n");
58         InspectorTest.innerSetOuterHTML(InspectorTest.containerText, true, next);
59     }
60 }
61
62 InspectorTest.innerSetOuterHTML = function(newText, last, next)
63 {
64     DOMAgent.setOuterHTML(InspectorTest.containerId, newText, dumpOuterHTML);
65
66     function dumpOuterHTML()
67     {
68         RuntimeAgent.evaluate("document.getElementById(\"identity\").wrapperIdentity", dumpIdentity);
69         function dumpIdentity(error, result)
70         {
71             InspectorTest.addResult("Wrapper identity: " + result.value);
72             InspectorTest.events.sort();
73             for (var i = 0; i < InspectorTest.events.length; ++i)
74                 InspectorTest.addResult(InspectorTest.events[i]);
75             InspectorTest.events = [];
76         }
77
78         DOMAgent.getOuterHTML(InspectorTest.containerId, callback);
79
80         function callback(error, text)
81         {
82             InspectorTest.addResult("==========8<==========");
83             InspectorTest.addResult(text);
84             InspectorTest.addResult("==========>8==========");
85             if (last)
86                 InspectorTest.addResult("\n\n\n");
87             next();
88         }
89     }
90 }
91
92 };