Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector-protocol / runtime / runtime-execution-contexts-events.html
blob329f35f84ba2df5ce0f89e032acfa35714463af0
1 <html>
2 <head>
3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
4 <script>
6 function createFrame()
8 var frame = document.createElement("iframe");
9 frame.src = "../resources/blank.html";
10 frame.id = "iframe";
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>");
23 function test()
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");
59 return;
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");
77 return;
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");
96 return;
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) {
109 case 1:
110 pageContextCreated();
111 break;
112 case 2:
113 frameContextCreated(executionContextId);
114 break;
115 case 3:
116 frameContextCreatedAfterNavigation(executionContextId);
117 break;
118 case 4:
119 craftedFrameContextCreated(executionContextId);
120 break;
124 var contextDestructionCounter = 0;
125 InspectorTest.eventHandler["Runtime.executionContextDestroyed"] = function(messageObject)
127 contextDestructionCounter++;
128 var executionContextId = messageObject.params.executionContextId;
129 switch (contextDestructionCounter) {
130 case 1:
131 frameContextDestroyedBeforeNavigation(executionContextId);
132 break;
133 case 2:
134 frameContextDestroyedAfterFrameRemoved(executionContextId);
135 break;
136 case 3:
137 craftedFrameContextDestroyedAfterFrameRemoved(executionContextId);
138 break;
143 </script>
144 </head>
145 <body onload="runTest()">
146 </body>
147 </html>