| <!DOCTYPE html> |
| <html> |
| <head> |
| |
| <!-- This test is symlinked and run from a different location to test site isolated behaviors. Attempt to find the test driver from two possible places. --> |
| <script src="../../http/tests/inspector/resources/inspector-test.js"></script> |
| <script src="../../../../../inspector/resources/inspector-test.js"></script> |
| |
| <script> |
| let worker; |
| |
| function createWorker() { |
| worker = new Worker("../worker/resources/worker-1.js"); |
| } |
| |
| function terminateWorker() { |
| worker.terminate(); |
| } |
| |
| let iframe; |
| |
| function appendIframe() { |
| iframe = document.createElement("iframe"); |
| document.body.append(iframe); |
| } |
| |
| function removeIframe() { |
| iframe.remove(); |
| } |
| |
| function test() |
| { |
| function dumpTargets() { |
| let targetList = WI.targets.map((x) => `Target - ${String(x.type)} - ${x.displayName}`); |
| InspectorTest.log(targetList.sort().join("\n")); |
| } |
| |
| let suite = InspectorTest.createAsyncSuite("TargetManager"); |
| |
| suite.addTestCase({ |
| name: "TargetManager.MainTarget", |
| description: "We should always have the main target.", |
| async test() { |
| if (WI.isSiteIsolationEnabled()) |
| InspectorTest.expectEqual(WI.targets.length, 2, "With site isolation, targets list should always start out with the main page target and the main frame target."); |
| else |
| InspectorTest.expectEqual(WI.targets.length, 1, "Without site isolation, targets list should always start out with the main page target only."); |
| |
| InspectorTest.assert(WI.targets === WI.targetManager.targets); |
| InspectorTest.expectThat(WI.targets.includes(WI.mainTarget), "Target list should always contain the main page target."); |
| InspectorTest.expectNotNull(WI.mainTarget.executionContext, "Main target should have an ExecutionContext."); |
| InspectorTest.expectEqual(WI.mainTarget.RuntimeAgent, WI.pageTarget.RuntimeAgent, "Main target should have the page target's RuntimeAgent."); |
| dumpTargets(); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "TargetManager.WorkerTarget.Create", |
| description: "Creating a Worker should create a new Worker Target.", |
| async test() { |
| InspectorTest.evaluateInPage("createWorker()"); |
| let event = await WI.targetManager.awaitEvent(WI.TargetManager.Event.TargetAdded); |
| let target = event.data.target; |
| InspectorTest.assert(target instanceof WI.WorkerTarget); |
| InspectorTest.expectEqual(target.type, WI.TargetType.Worker, "Added Target should have Worker type."); |
| InspectorTest.expectNotNull(target.executionContext, "Added Target should have an ExecutionContext."); |
| InspectorTest.expectNotNull(target.RuntimeAgent, "Added Target should have a RuntimeAgent."); |
| InspectorTest.expectNotEqual(target.RuntimeAgent, RuntimeAgent, "Added Target RuntimeAgent should not be the global RuntimeAgent."); |
| dumpTargets(); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "TargetManager.WorkerTarget.Remove", |
| description: "Removing a Worker should remove the Worker Target.", |
| async test() { |
| InspectorTest.evaluateInPage("terminateWorker()"); |
| let event = await WI.targetManager.awaitEvent(WI.TargetManager.Event.TargetRemoved); |
| let target = event.data.target; |
| InspectorTest.assert(target instanceof WI.WorkerTarget); |
| InspectorTest.expectEqual(target.type, WI.TargetType.Worker, "Removed Target should have Worker type."); |
| dumpTargets(); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "TargetManager.FrameTarget.Create", |
| description: "Appending an iframe should create a new Frame Target under site isolation.", |
| async test() { |
| InspectorTest.evaluateInPage("appendIframe()"); |
| if (WI.isSiteIsolationEnabled()) { |
| let event = await WI.targetManager.awaitEvent(WI.TargetManager.Event.TargetAdded); |
| let target = event.data.target; |
| InspectorTest.assert(target instanceof WI.FrameTarget); |
| InspectorTest.expectEqual(target.type, WI.TargetType.Frame, "Added Target should have Frame type."); |
| } |
| // FIXME: <https://webkit.org/b/298977> Consider giving meaningful names to frame targets so we can distinguish them. |
| dumpTargets(); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "TargetManager.FrameTarget.Remove", |
| description: "Removing an iframe should remove the Frame Target under site isolation.", |
| async test() { |
| InspectorTest.evaluateInPage("removeIframe()"); |
| if (WI.isSiteIsolationEnabled()) { |
| let event = await WI.targetManager.awaitEvent(WI.TargetManager.Event.TargetRemoved); |
| let target = event.data.target; |
| InspectorTest.assert(target instanceof WI.FrameTarget); |
| InspectorTest.expectEqual(target.type, WI.TargetType.Frame, "Removed Target should have Frame type."); |
| } |
| dumpTargets(); |
| } |
| }); |
| |
| suite.runTestCasesAndFinish(); |
| } |
| </script> |
| </head> |
| <body onload="runTest()"> |
| <p>Test for TargetManager and other global WI.Target objects.</p> |
| </body> |
| </html> |