3 <script type=
"text/javascript" src=
"../../http/tests/inspector-protocol/inspector-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
);
21 InspectorTest
.enableLayerTreeAgent(gotInitialLayerTree
);
23 function gotInitialLayerTree(layers
)
25 initialLayers
= layers
;
26 InspectorTest
.setLayerTreeChangeCallback(gotModifiedLayerTree
);
28 InspectorTest
.sendCommand("Runtime.evaluate", {"expression": "addCompositedLayer()"});
31 function gotModifiedLayerTree(layers
)
33 modifiedLayers
= layers
;
35 var mutations
= layerMutations(initialLayers
, modifiedLayers
);
36 var newLayer
= mutations
.additions
[0];
38 InspectorTest
.sendCommand("DOM.pushNodesByBackendIdsToFrontend", {"backendNodeIds": [newLayer
.backendNodeId
]}, InspectorTest
.wrapCallback(gotNodeId
));
41 function gotNodeId(result
)
43 InspectorTest
.sendCommand("DOM.getAttributes", {"nodeId": result
.nodeIds
[0]}, InspectorTest
.wrapCallback(gotNodeAttributes
));
46 function gotNodeAttributes(result
)
48 var attributes
= attributesDictionaryFromArray(result
.attributes
);
49 if (attributes
.id
!== "last-element")
50 InspectorTest
.log("FAIL: Did not obtain the expected element for the last inserted layer.");
52 dumpLayers(initialLayers
);
53 dumpLayers(modifiedLayers
);
54 InspectorTest
.log("DONE!");
55 InspectorTest
.completeTest();
58 function layerMutations(oldLayers
, newLayers
)
60 function layerIdMap(layer
) {
64 var oldLayerIds
= oldLayers
.map(layerIdMap
);
65 var newLayerIds
= newLayers
.map(layerIdMap
);
68 additions
: newLayers
.filter(function (layer
) {
69 return (oldLayerIds
.indexOf(layer
.layerId
) === -1);
71 removals
: oldLayers
.filter(function (layer
) {
72 return (newLayerIds
.indexOf(layer
.layerId
) === -1);
77 function attributesDictionaryFromArray(attributes
)
80 for (var i
= 0, count
= attributes
.length
; i
< count
; i
+= 2) {
81 dictionary
[attributes
[i
]] = attributes
[i
+ 1];
86 function dumpLayers(layers
)
88 // Keep "internal" layers out for better stability.
89 layers
= layers
.filter(function(layer
) { return !!layer
.backendNodeId
; });
90 function replacer(key
, value
)
93 if (["layerId", "parentLayerId", "backendNodeId", "paintCount"].indexOf(key
) >= 0)
96 // some values differ based on port, but the ones we most
97 // care about will always be less or equal 100.
98 if ((key
=== "width" || key
=== "height") && value
> 100)
104 InspectorTest
.log("\n" + JSON
.stringify(layers
, replacer
, " "));
108 window
.addEventListener("DOMContentLoaded", function () {
113 <style type=
"text/css">
124 background-color: black
;
132 background-color: blue
;
133 transform: translateZ
(0);
138 transform: translateZ
(0);
145 <div class=
"regular"></div>
147 <div class=
"composited">
148 <div class=
"composited"></div>
151 <div class=
"regular offset">
152 <div class=
"composited"></div>