blob: e8852ad05d45957b61badbdc2cd462f885e73845 [file] [log] [blame]
<html>
<head>
<script src="../../http/tests/inspector/resources/protocol-test.js"></script>
<script>
function test()
{
var nodes;
InspectorProtocol.eventHandler["DOM.setChildNodes"] = setChildNodes;
enableLayerTreeAgent();
function enableLayerTreeAgent(result)
{
step({
name: "Enable the LayerTree agent",
command: "LayerTree.enable",
parameters: {},
callback: getDocument
});
};
function getDocument()
{
// We must first get the document so that later on we may get sensible nodeIds.
step({
name: "Get the Document",
command: "DOM.getDocument",
parameters: {},
callback: getLayerTree
});
};
function getLayerTree(result)
{
step({
name: "Get the layer tree",
command: "LayerTree.layersForNode",
parameters: {"nodeId": result.root.nodeId},
callback: gotLayerTree
});
};
function gotLayerTree(result)
{
var anonymousLayers = result.layers.filter(function (layer) {
return layer.isAnonymous;
});
logTestName("Check layers");
assert("Expected number of anonymous layers", anonymousLayers.length, 1);
assert("The sole anonymous layer has a non-zero node id", anonymousLayers[0].nodeId !== 0, true);
assert("The sole anonymous layer has a :first-letter pseudo-element", anonymousLayers[0].pseudoElement === "first-letter", true);
var node;
var nodeId = anonymousLayers[0].nodeId;
for (var i = 0, count = nodes.length; i < count; ++i) {
if (nodes[i].nodeId === nodeId) {
node = nodes[i];
break;
}
}
logTestName("Check node");
assert("Node was found", !!node, true);
assert("Node has expected localName", node.localName, "p");
assert("Node has id", node.attributes[0], "id");
assert("Node has expected id", node.attributes[1], "first-letter");
ProtocolTest.completeTest();
};
function setChildNodes (messageObject) {
nodes = messageObject.params.nodes;
};
function step(test)
{
if (test.callback)
logTestName(test.name);
runCommand(test);
};
function logTestName(name)
{
ProtocolTest.log("\n=== " + name + " ===\n");
};
function runCommand(command)
{
InspectorProtocol.sendCommand(command.command, command.parameters, function(messageObject) {
if (messageObject.hasOwnProperty("error")) {
ProtocolTest.log("FAIL: " + messageObject.error.message + " (" + messageObject.error.code + ")");
ProtocolTest.completeTest();
return;
}
if (command.name)
ProtocolTest.log("PASS");
if (command.callback)
command.callback(messageObject.result);
});
};
function assert(name, actual, expected)
{
if (expected === actual)
ProtocolTest.log("PASS: " + name + ".");
else
ProtocolTest.log("FAIL: " + name + ". Expected " + expected + " but got " + actual);
};
};
window.addEventListener("DOMContentLoaded", function()
{
runTest();
}, false);
</script>
<style type="text/css">
#first-letter::first-letter {
float: left;
-webkit-transform: translateZ(0);
}
</style>
</head>
<body>
<p id="first-letter">This is a test</p>
</body>
</html>