Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector / elements / edit / set-outer-html-test.js
blob656926cc5d1425255542c61e74eba524f4a2466c
1 var initialize_SetOuterHTMLTest = function() {
3 InspectorTest.events = [];
4 InspectorTest.containerId;
6 InspectorTest.setUpTestSuite = function(next)
8     InspectorTest.expandElementsTree(step1);
10     function step1()
11     {
12         InspectorTest.selectNodeWithId("container", step2);
13     }
15     function step2(node)
16     {
17         InspectorTest.containerId = node.id;
18         InspectorTest.DOMAgent.getOuterHTML(InspectorTest.containerId, step3);
19     }
21     function step3(error, text)
22     {
23         InspectorTest.containerText = text;
25         for (var key in WebInspector.DOMModel.Events) {
26             var eventName = WebInspector.DOMModel.Events[key];
27             InspectorTest.domModel.addEventListener(eventName, InspectorTest.recordEvent.bind(InspectorTest, eventName));
28         }
30         next();
31     }
34 InspectorTest.recordEvent = function(eventName, event)
36     if (!event.data || event.type === WebInspector.DOMModel.Events.MarkersChanged)
37         return;
38     var node = event.data.node || event.data;
39     var parent = event.data.parent;
40     for (var currentNode = parent || node; currentNode; currentNode = currentNode.parentNode) {
41         if (currentNode.getAttribute("id") === "output")
42             return;
43     }
44     InspectorTest.events.push("Event " + eventName + ": " + node.nodeName());
47 InspectorTest.patchOuterHTML = function(pattern, replacement, next)
49     InspectorTest.addResult("Replacing '" + pattern + "' with '" + replacement + "'\n");
50     InspectorTest.setOuterHTML(InspectorTest.containerText.replace(pattern, replacement), next);
53 InspectorTest.patchOuterHTMLUseUndo = function(pattern, replacement, next)
55     InspectorTest.addResult("Replacing '" + pattern + "' with '" + replacement + "'\n");
56     InspectorTest.setOuterHTMLUseUndo(InspectorTest.containerText.replace(pattern, replacement), next);
59 InspectorTest.setOuterHTML = function(newText, next)
61     InspectorTest.innerSetOuterHTML(newText, false, bringBack);
63     function bringBack()
64     {
65         InspectorTest.addResult("\nBringing things back\n");
66         InspectorTest.innerSetOuterHTML(InspectorTest.containerText, true, next);
67     }
70 InspectorTest.setOuterHTMLUseUndo = function(newText, next)
72     InspectorTest.innerSetOuterHTML(newText, false, bringBack);
74     function bringBack()
75     {
76         InspectorTest.addResult("\nBringing things back\n");
77         InspectorTest.domModel.undo(InspectorTest._dumpOuterHTML.bind(InspectorTest, true, next));
78     }
81 InspectorTest.innerSetOuterHTML = function(newText, last, next)
83     InspectorTest.DOMAgent.setOuterHTML(InspectorTest.containerId, newText, InspectorTest._dumpOuterHTML.bind(InspectorTest, last, next));
86 InspectorTest._dumpOuterHTML = function(last, next)
88     InspectorTest.RuntimeAgent.evaluate("document.getElementById(\"identity\").wrapperIdentity", dumpIdentity);
89     function dumpIdentity(error, result)
90     {
91         InspectorTest.addResult("Wrapper identity: " + result.value);
92         InspectorTest.events.sort();
93         for (var i = 0; i < InspectorTest.events.length; ++i)
94             InspectorTest.addResult(InspectorTest.events[i]);
95         InspectorTest.events = [];
96     }
98     InspectorTest.DOMAgent.getOuterHTML(InspectorTest.containerId, callback);
100     function callback(error, text)
101     {
102         InspectorTest.addResult("==========8<==========");
103         InspectorTest.addResult(text);
104         InspectorTest.addResult("==========>8==========");
105         if (last)
106             InspectorTest.addResult("\n\n\n");
107         next();
108     }