| OLD | NEW |
| (Empty) |
| 1 <html> | |
| 2 <head> | |
| 3 <script type="text/javascript" src="../../http/tests/inspector-protocol/resource
s/inspector-protocol-test.js"></script> | |
| 4 <script> | |
| 5 | |
| 6 function createFrame() | |
| 7 { | |
| 8 var frame = document.createElement("iframe"); | |
| 9 frame.src = "../resources/blank.html"; | |
| 10 frame.id = "iframe"; | |
| 11 document.body.appendChild(frame); | |
| 12 return new Promise((resolve) => frame.onload = resolve); | |
| 13 } | |
| 14 | |
| 15 function createCraftedFrame() | |
| 16 { | |
| 17 var frame = document.createElement("iframe"); | |
| 18 frame.src = "../resources/blank.html"; | |
| 19 frame.id = "crafted-iframe"; | |
| 20 document.body.appendChild(frame); | |
| 21 frame.contentDocument.write("<div>crafted</div>"); | |
| 22 frame.contentDocument.close(); | |
| 23 } | |
| 24 | |
| 25 function test() | |
| 26 { | |
| 27 InspectorTest.evaluate = function(expression) | |
| 28 { | |
| 29 InspectorTest.sendCommandOrDie("Runtime.evaluate", {expression: expressi
on}); | |
| 30 } | |
| 31 | |
| 32 InspectorTest.fail = function(message) | |
| 33 { | |
| 34 InspectorTest.log(message); | |
| 35 InspectorTest.completeTest(); | |
| 36 } | |
| 37 | |
| 38 InspectorTest.sendCommand("Runtime.enable", {}); | |
| 39 | |
| 40 function pageContextCreated() | |
| 41 { | |
| 42 InspectorTest.log("Page context was created"); | |
| 43 InspectorTest.log("Create new frame"); | |
| 44 InspectorTest.sendCommandPromise("Runtime.evaluate", {expression: "creat
eFrame()", awaitPromise: true}) | |
| 45 .then(() => navigateFrame()); | |
| 46 } | |
| 47 | |
| 48 var frameExecutionContextId = 0; | |
| 49 | |
| 50 function frameContextCreated(executionContextId) | |
| 51 { | |
| 52 InspectorTest.log("Frame context was created"); | |
| 53 frameExecutionContextId = executionContextId; | |
| 54 } | |
| 55 | |
| 56 function navigateFrame() | |
| 57 { | |
| 58 InspectorTest.log("Navigate frame"); | |
| 59 InspectorTest.evaluate("window.frames[0].location = \"resources/runtime-
events-iframe.html\""); | |
| 60 } | |
| 61 | |
| 62 function frameContextDestroyedBeforeNavigation(executionContextId) | |
| 63 { | |
| 64 if (frameExecutionContextId !== executionContextId) { | |
| 65 InspectorTest.fail("Execution context with id = " + executionContext
Id + " was destroyed, but iframe's executionContext had id = " + frameExecutionC
ontextId + " before navigation"); | |
| 66 return; | |
| 67 } | |
| 68 InspectorTest.log("Frame's context was destroyed"); | |
| 69 frameExecutionContextId = 0; | |
| 70 } | |
| 71 | |
| 72 function frameContextCreatedAfterNavigation(executionContextId) | |
| 73 { | |
| 74 InspectorTest.log("Frame context was created"); | |
| 75 frameExecutionContextId = executionContextId; | |
| 76 InspectorTest.log("Remove frame"); | |
| 77 InspectorTest.evaluate("document.querySelector(\"#iframe\").remove()"); | |
| 78 } | |
| 79 | |
| 80 function frameContextDestroyedAfterFrameRemoved(executionContextId) | |
| 81 { | |
| 82 if (frameExecutionContextId !== executionContextId) { | |
| 83 InspectorTest.fail("Deleted frame had execution context with id = "
+ frameExecutionContextId + " , but executionContext with id = " + executionCont
extId + " was removed"); | |
| 84 return; | |
| 85 } | |
| 86 InspectorTest.log("Frame's context was destroyed"); | |
| 87 InspectorTest.log("Create new crafted frame"); | |
| 88 InspectorTest.evaluate("createCraftedFrame()"); | |
| 89 } | |
| 90 | |
| 91 function craftedFrameContextCreated(executionContextId) | |
| 92 { | |
| 93 InspectorTest.log("Crafted frame context was created"); | |
| 94 frameExecutionContextId = executionContextId; | |
| 95 InspectorTest.log("Remove crafted frame"); | |
| 96 InspectorTest.evaluate("document.querySelector(\"#crafted-iframe\").remo
ve()"); | |
| 97 } | |
| 98 | |
| 99 function craftedFrameContextDestroyedAfterFrameRemoved(executionContextId) | |
| 100 { | |
| 101 if (frameExecutionContextId !== executionContextId) { | |
| 102 InspectorTest.fail("Deleted frame had execution context with id = "
+ frameExecutionContextId + " , but executionContext with id = " + executionCont
extId + " was removed"); | |
| 103 return; | |
| 104 } | |
| 105 InspectorTest.log("Crafted frame's context was destroyed"); | |
| 106 InspectorTest.completeTest(); | |
| 107 } | |
| 108 | |
| 109 var contextCreationCounter = 0; | |
| 110 | |
| 111 InspectorTest.eventHandler["Runtime.executionContextCreated"] = function(mes
sageObject) | |
| 112 { | |
| 113 contextCreationCounter++; | |
| 114 var executionContextId = messageObject.params.context.id; | |
| 115 switch (contextCreationCounter) { | |
| 116 case 1: | |
| 117 pageContextCreated(); | |
| 118 break; | |
| 119 case 2: | |
| 120 frameContextCreated(executionContextId); | |
| 121 break; | |
| 122 case 3: | |
| 123 frameContextCreatedAfterNavigation(executionContextId); | |
| 124 break; | |
| 125 case 4: | |
| 126 craftedFrameContextCreated(executionContextId); | |
| 127 break; | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 var contextDestructionCounter = 0; | |
| 132 InspectorTest.eventHandler["Runtime.executionContextDestroyed"] = function(m
essageObject) | |
| 133 { | |
| 134 contextDestructionCounter++; | |
| 135 var executionContextId = messageObject.params.executionContextId; | |
| 136 switch (contextDestructionCounter) { | |
| 137 case 1: | |
| 138 frameContextDestroyedBeforeNavigation(executionContextId); | |
| 139 break; | |
| 140 case 2: | |
| 141 frameContextDestroyedAfterFrameRemoved(executionContextId); | |
| 142 break; | |
| 143 case 3: | |
| 144 craftedFrameContextDestroyedAfterFrameRemoved(executionContextId); | |
| 145 break; | |
| 146 } | |
| 147 } | |
| 148 | |
| 149 } | |
| 150 </script> | |
| 151 </head> | |
| 152 <body onload="runTest()"> | |
| 153 </body> | |
| 154 </html> | |
| OLD | NEW |