3 <script type="text/javascript" src="../../http/tests/inspector-protocol/resources/protocol-test.js"></script>
4 <script type="text/javascript" src="layer-protocol-test.js"></script>
5 <script type="text/javascript">
7 function addCompositedLayer()
9 var element = document.createElement("div");
10 element.className = "composited";
11 element.id = "last-element";
12 document.body.appendChild(element);
13 if (window.testRunner)
23 InspectorTest.enableLayerTreeAgent(gotInitialLayerTree);
25 function gotInitialLayerTree(layers)
27 initialLayers = layers;
28 InspectorTest.setLayerTreeChangeCallback(gotModifiedLayerTree);
30 InspectorTest.sendCommand("Runtime.evaluate", {"expression": "addCompositedLayer()"});
33 function gotModifiedLayerTree(layers)
35 modifiedLayers = layers;
37 var mutations = layerMutations(initialLayers, modifiedLayers);
38 var newLayer = mutations.additions[0];
40 InspectorTest.sendCommand("DOM.getAttributes", {"nodeId": newLayer.nodeId}, InspectorTest.wrapCallback(gotNodeAttributes));
43 function gotNodeAttributes(result)
45 var attributes = attributesDictionaryFromArray(result.attributes);
46 if (attributes.id !== "last-element")
47 InspectorTest.log("FAIL: Did not obtain the expected element for the last inserted layer.");
49 dumpLayers(initialLayers);
50 dumpLayers(modifiedLayers);
51 InspectorTest.log("DONE!");
52 InspectorTest.completeTest();
55 function layerMutations(oldLayers, newLayers)
57 function layerIdMap(layer) {
61 var oldLayerIds = oldLayers.map(layerIdMap);
62 var newLayerIds = newLayers.map(layerIdMap);
65 additions: newLayers.filter(function (layer) {
66 return (oldLayerIds.indexOf(layer.layerId) === -1);
68 removals: oldLayers.filter(function (layer) {
69 return (newLayerIds.indexOf(layer.layerId) === -1);
74 function attributesDictionaryFromArray(attributes)
77 for (var i = 0, count = attributes.length; i < count; i += 2) {
78 dictionary[attributes[i]] = attributes[i + 1];
83 function dumpLayers(layers)
85 // Keep "internal" layers out for better stability.
86 layers = layers.filter(function(layer) { return !!layer.nodeId; });
87 function replacer(key, value)
90 if (["layerId", "parentLayerId", "nodeId", "paintCount"].indexOf(key) >= 0)
93 // some values differ based on port, but the ones we most
94 // care about will always be less or equal 100.
95 if ((key === "width" || key === "height") && value > 100)
101 InspectorTest.log("\n" + JSON.stringify(layers, replacer, " "));
105 window.addEventListener("DOMContentLoaded", function () {
110 <style type="text/css">
121 background-color: black;
129 background-color: blue;
130 -webkit-transform: translateZ(0);
135 -webkit-transform: translateZ(0);
142 <div class="regular"></div>
144 <div class="composited">
145 <div class="composited"></div>
148 <div class="regular offset">
149 <div class="composited"></div>