| <html> |
| <head> |
| <script src="../../http/tests/inspector/resources/protocol-test.js"></script> |
| <script src="../../http/tests/inspector/resources/stable-id-map.js"></script> |
| <script> |
| function test() |
| { |
| let suite = ProtocolTest.createAsyncSuite("Runtime.executionContextCreated.OnEnable"); |
| |
| suite.addTestCase({ |
| name: "Runtime.executionContextCreated.OnEnable.NoDuplicates", |
| description: "Test that Runtime.enable will send executionContextCreated events only for existng main world contexts", |
| async test() { |
| let contextIdMap = new StableIdMap; |
| let frameIdMap = new StableIdMap; |
| let contextCount = 0; |
| |
| InspectorProtocol.addEventListener("Runtime.executionContextCreated", (messageObject) => { |
| let {id, isPageContext, frameId} = messageObject.params.context; |
| ProtocolTest.log(`Execution context created: id=${contextIdMap.get(id)} frameId=${frameIdMap.get(frameId)} isPageContext=${isPageContext}`) |
| ++contextCount; |
| }); |
| |
| await Promise.all([ |
| InspectorProtocol.awaitCommand({method: "Page.enable"}), |
| InspectorProtocol.awaitCommand({method: "Runtime.enable"}), |
| ]); |
| |
| ProtocolTest.expectEqual(contextCount, 2, "Should receive 2 executionContextCreated events (for main world in the main frame and the subframe)."); |
| ProtocolTest.expectEqual(contextIdMap.size, 2, "Should have 2 unique contexts."); |
| } |
| }); |
| |
| suite.runTestCasesAndFinish(); |
| } |
| </script> |
| </head> |
| <body> |
| <iframe id="subframe" src="resources/change-execution-context-identifier-subframe.html" onload="runTest()"></iframe> |
| <p>Test that exactly one Runtime.executionContextCreated event is fired for each existing context when Runtime.enable is called.</p> |
| </body> |
| </html> |