blob: e5871810f7eefc85e7384f8eb3c399f118d7eab7 [file] [log] [blame]
<html>
<head>
<script type="text/javascript" src="resources/protocol-test.js"></script>
<script>
var frame;
function appendIframe()
{
frame = document.createElement("iframe");
frame.src = "http://localhost:8000/inspector-protocol/resources/slow-test-page.html";
document.body.appendChild(frame);
}
function removeIframe()
{
frame.remove();
}
function test()
{
/*
Testing that the Node ID can be retrieved before the onload event is triggered:
1. Create an iframe and point it to a page with a slow-loading image.
2. Wait until the JS context is created in the iframe.
3. Use the JS contet to identify the "window.document" object inside the iframe.
4. Use the JS object to retrieve the DOM agent nodeid for the document node.
*/
InspectorTest.eventHandler["Page.frameStartedLoading"] = step2_onFrameStartedLoading;
InspectorTest.eventHandler["Runtime.executionContextCreated"] = step3_onExecutionContextCreated;
InspectorTest.eventHandler["Page.loadEventFired"] = onLoadEventFired;
var targetFrameId = null;
function step1_bootstrap() {
InspectorTest.log("step1_bootstrap");
// Enable the frame events.
InspectorTest.sendCommand("Page.enable", {}, function() {
// Enable the Runtime.executionContextCreated event.
InspectorTest.sendCommand("Runtime.enable", {}, function() {
// Initialize the DOM agent.
InspectorTest.sendCommand("DOM.getDocument", {}, function() {
InspectorTest.log("Main document loaded");
// Add the iframe to the DOM.
InspectorTest.sendCommand("Runtime.evaluate", { "expression": "appendIframe()" });
});
});
});
}
function step2_onFrameStartedLoading(response)
{
InspectorTest.log("step2_onFrameStartedLoading");
targetFrameId = response.params.frameId;
}
function step3_onExecutionContextCreated(event)
{
var frameId = event.params.context.frameId;
if (frameId !== targetFrameId)
return;
InspectorTest.log("step3_onExecutionContextCreated: Requesting document from iframe's context.");
InspectorTest.sendCommand("Runtime.evaluate", {
"expression": "document",
"objectGroup": "console",
"includeCommandLineAPI": false,
"contextId": event.params.context.id,
"doNotPauseOnExceptionsAndMuteConsole": false,
"returnByValue": false,
"generatePreview": false
}, callback);
function callback(response)
{
var objectId = response.result.result.objectId;
InspectorTest.log("Received script object for iframe's document node");
step4_requestNode(frameId, objectId);
}
}
function step4_requestNode(frameId, objectId)
{
function callback(response)
{
InspectorTest.log(response.result.nodeId ? "PASS: Received node for iframe's document node" : "FAIL: Iframe's document node is not available");
completeTest();
}
InspectorTest.log("step4_requestNode: Requesting DOM node for iframe's document node");
InspectorTest.sendCommand("DOM.requestNode", { objectId: objectId }, callback);
}
function completeTest()
{
InspectorTest.log("Test finished");
// Stop loading the iframe to avoid timing out the test.
InspectorTest.sendCommand("Runtime.evaluate", { "expression": "removeIframe()" });
InspectorTest.completeTest();
}
function onLoadEventFired()
{
// We should finish the test before this event is triggered.
// If you see this in the output, then the slow-image is not loaded correctly in the iframe.
InspectorTest.log("FAIL: Iframe load event fired before the test finished.");
}
step1_bootstrap()
}
</script>
</head>
<body onload="runTest()">
</body>
</html>