3 <script type=
"text/javascript" src=
"../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
8 var frame
= document
.createElement("iframe");
9 frame
.src
= "../resources/blank.html";
11 document
.body
.appendChild(frame
);
14 function createCraftedFrame()
16 var frame
= document
.createElement("iframe");
17 frame
.src
= "../resources/blank.html";
18 frame
.id
= "crafted-iframe";
19 document
.body
.appendChild(frame
);
20 frame
.contentDocument
.write("<div>crafted</div>");
25 InspectorTest
.evaluate = function(expression
)
27 InspectorTest
.sendCommandOrDie("Runtime.evaluate", {expression
: expression
});
30 InspectorTest
.fail = function(message
)
32 InspectorTest
.log(message
);
33 InspectorTest
.completeTest();
36 InspectorTest
.sendCommand("Runtime.enable", {});
38 function pageContextCreated()
40 InspectorTest
.log("Page context was created");
41 InspectorTest
.log("Create new frame");
42 InspectorTest
.evaluate("createFrame()");
45 var frameExecutionContextId
= 0;
47 function frameContextCreated(executionContextId
)
49 InspectorTest
.log("Frame context was created");
50 frameExecutionContextId
= executionContextId
;
51 InspectorTest
.log("Navigate frame");
52 InspectorTest
.evaluate("window.frames[0].location = \"resources/runtime-events-iframe.html\"");
55 function frameContextDestroyedBeforeNavigation(executionContextId
)
57 if (frameExecutionContextId
!== executionContextId
) {
58 InspectorTest
.fail("Execution context with id = " + executionContextId
+ " was destroyed, but iframe's executionContext had id = " + frameExecutionContextId
+ " before navigation");
61 InspectorTest
.log("Frame's context was destroyed");
62 frameExecutionContextId
= 0;
65 function frameContextCreatedAfterNavigation(executionContextId
)
67 InspectorTest
.log("Frame context was created");
68 frameExecutionContextId
= executionContextId
;
69 InspectorTest
.log("Remove frame");
70 InspectorTest
.evaluate("document.querySelector(\"#iframe\").remove()");
73 function frameContextDestroyedAfterFrameRemoved(executionContextId
)
75 if (frameExecutionContextId
!== executionContextId
) {
76 InspectorTest
.fail("Deleted frame had execution context with id = " + frameExecutionContextId
+ " , but executionContext with id = " + executionContextId
+ " was removed");
79 InspectorTest
.log("Frame's context was destroyed");
80 InspectorTest
.log("Create new crafted frame");
81 InspectorTest
.evaluate("createCraftedFrame()");
84 function craftedFrameContextCreated(executionContextId
)
86 InspectorTest
.log("Crafted frame context was created");
87 frameExecutionContextId
= executionContextId
;
88 InspectorTest
.log("Remove crafted frame");
89 InspectorTest
.evaluate("document.querySelector(\"#crafted-iframe\").remove()");
92 function craftedFrameContextDestroyedAfterFrameRemoved(executionContextId
)
94 if (frameExecutionContextId
!== executionContextId
) {
95 InspectorTest
.fail("Deleted frame had execution context with id = " + frameExecutionContextId
+ " , but executionContext with id = " + executionContextId
+ " was removed");
98 InspectorTest
.log("Crafted frame's context was destroyed");
99 InspectorTest
.completeTest();
102 var contextCreationCounter
= 0;
104 InspectorTest
.eventHandler
["Runtime.executionContextCreated"] = function(messageObject
)
106 contextCreationCounter
++;
107 var executionContextId
= messageObject
.params
.context
.id
;
108 switch (contextCreationCounter
) {
110 pageContextCreated();
113 frameContextCreated(executionContextId
);
116 frameContextCreatedAfterNavigation(executionContextId
);
119 craftedFrameContextCreated(executionContextId
);
124 var contextDestructionCounter
= 0;
125 InspectorTest
.eventHandler
["Runtime.executionContextDestroyed"] = function(messageObject
)
127 contextDestructionCounter
++;
128 var executionContextId
= messageObject
.params
.executionContextId
;
129 switch (contextDestructionCounter
) {
131 frameContextDestroyedBeforeNavigation(executionContextId
);
134 frameContextDestroyedAfterFrameRemoved(executionContextId
);
137 craftedFrameContextDestroyedAfterFrameRemoved(executionContextId
);
145 <body onload=
"runTest()">