blob: 329f35f84ba2df5ce0f89e032acfa35714463af0 [file] [log] [blame]
<html>
<head>
<script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
<script>
function createFrame()
{
var frame = document.createElement("iframe");
frame.src = "../resources/blank.html";
frame.id = "iframe";
document.body.appendChild(frame);
}
function createCraftedFrame()
{
var frame = document.createElement("iframe");
frame.src = "../resources/blank.html";
frame.id = "crafted-iframe";
document.body.appendChild(frame);
frame.contentDocument.write("<div>crafted</div>");
}
function test()
{
InspectorTest.evaluate = function(expression)
{
InspectorTest.sendCommandOrDie("Runtime.evaluate", {expression: expression});
}
InspectorTest.fail = function(message)
{
InspectorTest.log(message);
InspectorTest.completeTest();
}
InspectorTest.sendCommand("Runtime.enable", {});
function pageContextCreated()
{
InspectorTest.log("Page context was created");
InspectorTest.log("Create new frame");
InspectorTest.evaluate("createFrame()");
}
var frameExecutionContextId = 0;
function frameContextCreated(executionContextId)
{
InspectorTest.log("Frame context was created");
frameExecutionContextId = executionContextId;
InspectorTest.log("Navigate frame");
InspectorTest.evaluate("window.frames[0].location = \"resources/runtime-events-iframe.html\"");
}
function frameContextDestroyedBeforeNavigation(executionContextId)
{
if (frameExecutionContextId !== executionContextId) {
InspectorTest.fail("Execution context with id = " + executionContextId + " was destroyed, but iframe's executionContext had id = " + frameExecutionContextId + " before navigation");
return;
}
InspectorTest.log("Frame's context was destroyed");
frameExecutionContextId = 0;
}
function frameContextCreatedAfterNavigation(executionContextId)
{
InspectorTest.log("Frame context was created");
frameExecutionContextId = executionContextId;
InspectorTest.log("Remove frame");
InspectorTest.evaluate("document.querySelector(\"#iframe\").remove()");
}
function frameContextDestroyedAfterFrameRemoved(executionContextId)
{
if (frameExecutionContextId !== executionContextId) {
InspectorTest.fail("Deleted frame had execution context with id = " + frameExecutionContextId + " , but executionContext with id = " + executionContextId + " was removed");
return;
}
InspectorTest.log("Frame's context was destroyed");
InspectorTest.log("Create new crafted frame");
InspectorTest.evaluate("createCraftedFrame()");
}
function craftedFrameContextCreated(executionContextId)
{
InspectorTest.log("Crafted frame context was created");
frameExecutionContextId = executionContextId;
InspectorTest.log("Remove crafted frame");
InspectorTest.evaluate("document.querySelector(\"#crafted-iframe\").remove()");
}
function craftedFrameContextDestroyedAfterFrameRemoved(executionContextId)
{
if (frameExecutionContextId !== executionContextId) {
InspectorTest.fail("Deleted frame had execution context with id = " + frameExecutionContextId + " , but executionContext with id = " + executionContextId + " was removed");
return;
}
InspectorTest.log("Crafted frame's context was destroyed");
InspectorTest.completeTest();
}
var contextCreationCounter = 0;
InspectorTest.eventHandler["Runtime.executionContextCreated"] = function(messageObject)
{
contextCreationCounter++;
var executionContextId = messageObject.params.context.id;
switch (contextCreationCounter) {
case 1:
pageContextCreated();
break;
case 2:
frameContextCreated(executionContextId);
break;
case 3:
frameContextCreatedAfterNavigation(executionContextId);
break;
case 4:
craftedFrameContextCreated(executionContextId);
break;
}
}
var contextDestructionCounter = 0;
InspectorTest.eventHandler["Runtime.executionContextDestroyed"] = function(messageObject)
{
contextDestructionCounter++;
var executionContextId = messageObject.params.executionContextId;
switch (contextDestructionCounter) {
case 1:
frameContextDestroyedBeforeNavigation(executionContextId);
break;
case 2:
frameContextDestroyedAfterFrameRemoved(executionContextId);
break;
case 3:
craftedFrameContextDestroyedAfterFrameRemoved(executionContextId);
break;
}
}
}
</script>
</head>
<body onload="runTest()">
</body>
</html>